0

How to call a double mapping in unit tests?

Here is an extract of our contrat:

contract StackingPool {
    struct Staker {
        uint128 amount; // Amount token stake
        uint256 date; // Date of stake start
    }
    // address token => address Staker => Informations Staker
    mapping(address => mapping(address => Staker)) public stakers;
}

And the code of unit test:

Staking_i = await StakingInstance.new({from: owner});
await Staking_i.stake(stakedAmount, TokenTestAddress, {from: stacker1})
let receipt = Staking_i.methods.stakers(TokenTestAddress,stacker1).call()

My tests:

console.log("Staking_i.methods : ", Staking_i.methods);

'stakers(address,address)': [Function (anonymous)] {
    call: [Function (anonymous)],
    sendTransaction: [Function (anonymous)],
    estimateGas: [Function (anonymous)],
    request: [Function (anonymous)]
  }
console.log("Staking_i.methods.stakers(TokenTestAddress,stacker1).call() : ", Staking_i.methods.stakers(TokenTestAddress,stacker1).call() );

TypeError: Staking_i.methods.stakers is not a function
console.log("Staking_i.methods.stakers.call(TokenTestAddress,stacker1) : ", Staking_i.methods.stakers.call(TokenTestAddress,stacker1));

TypeError: Cannot read properties of undefined (reading 'call')
1
  • Can you include the test source code? It appears you are mixing truffle and web3 contracts.
    – Ismael
    Aug 9 at 2:30

0

Your Answer

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

Browse other questions tagged or ask your own question.