0

I'm testing a very primitive contract using mapping.

contract PhysicalContract {
    
    uint numContracts;
    
    mapping (address => uint) contracts_test;

    function newDeal(address adr, uint value) public{

        contracts_test[adr] = value; 

        numContracts++;
    }
}

The variable numContracts is successfully updated when I call newDeal(..) but not the mapping contracts_test.. It keeps desperately empty.

enter image description here

Any help would be greatly appreciated - Thanks

2

I am not sure how you test it but I wrote a function that shows it is actually not empty.

pragma solidity ^0.5.9;  
    
contract PhysicalContract {
      
    uint numContracts;    
    mapping (address => uint) contracts_test;
    
    function newDeal(address adr, uint value) public {
        contracts_test[adr] = value; 
        numContracts++;
    }
        
    function indexE(address adr) public returns (uint) {
        return contracts_test[adr];
    }
}

Using REMIX editor, I first use newDeal to add values. Based on the address I use, I can return the corresponding uint of contracts_test.

4
  • Hi, Yes - you're right - it;s actually working fine when I test it on Remix. But when I test it externally on Ganache, it doesnt show anything - I guess it's maybe a visualization issue on the Ganache contract inspector. – Julien Regnault Jan 5 at 23:37
  • 1
    It's hard to say without seeing it. I would appreciate it if you can accept the answer. – Emrah Sarıboz Jan 6 at 3:10
  • thanks - Yes - I confirm, the problem comes from the Truffle contract inspector - it doesnt reflect correctly the mapping – Julien Regnault Jan 6 at 11:54
  • You are welcome! – Emrah Sarıboz Jan 6 at 14:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.