How to test payable/external method with waffle and ethers.js
Asked Answered
J

1

1

Here is the smart contract, written in vyper, to be tested

owner: public(address) 
name: public(String[100])
total_amount: uint256

@external
def __init__(_name: String[100]):
    self.owner = tx.origin 
    self.name = _name

@external
@payable
def donate():
#anyone can donate to the piggy bank
    self.total_amount += msg.value

@external
@view
def get_total_amount() -> uint256:
    return self.total_amount

What is the right way to test the donate() method of the smart contract with waffle and ethers.js?

Is there a sendTransaction method for ethers.js that can be called on contract's side like in this example of web3+truffle ?

Jewelry answered 16/4, 2021 at 7:37 Comment(0)
D
3

You can use the overrides parameter. It's used after all contract function arguments.

In your case, the contract function has 0 arguments so the overrides is on position 1.

let overrides = {
    value: ethers.utils.parseEther("1.0")
};
let tx = await myContract.donate(overrides);

See this issue for more details.

Demagogy answered 16/4, 2021 at 8:1 Comment(1)
Thanks for the explanation! Appreciate this!Jewelry

© 2022 - 2024 — McMap. All rights reserved.