0

I have two contracts, one returns a static value (10) I'd like to mock this value and return 2 (for instance), I'm trying with "mock" according to the documentation, but I still get 10

my test is:

describe('test', () => {
  async function setup() {
    const [sender, receiver] = new MockProvider().getWallets();
    const mockGetEtherPrice = await deployMockContract(sender, GetEtherPrice.abi);
    const contractFactory = new ContractFactory(NumbersMarketContract.abi, NumbersMarketContract.bytecode, sender);
    console.log(mockGetEtherPrice);
    const contract = await contractFactory.deploy();
    return {sender, receiver, contract, mockGetEtherPrice};
  }

  it('returns false if the wallet has less then 1000000 coins', async () => {
    const {contract, mockGetEtherPrice} = await setup();   
    await mockGetEtherPrice.mock.getPriceMocked.returns(2);
    console.log(await contract.check())
    expect(await contract.check()).to.be.equal(10);
  });

 
});

My GetEtherPrice contract is:

contract GetEtherPrice {    

    function getPrice() public pure returns(uint256){
        return getPriceMocked();
    }

    function getPriceMocked() public pure returns(uint256){
        return 10;
    }
}

In the main contract, I use 'is' to import my contract like:


contract NumbersMarketContract is GetEtherPrice
....
function check() public pure returns (uint256){
        return getPrice();
    }
monkeyUser
  • 4,301
  • 7
  • 46
  • 95

0 Answers0