Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New matcher: expect to change balance #9

Closed
marekkirejczyk opened this issue Sep 1, 2018 · 8 comments
Closed

New matcher: expect to change balance #9

marekkirejczyk opened this issue Sep 1, 2018 · 8 comments
Labels
waffle-3.0.0 Part of the improvements for Waffle 3

Comments

@marekkirejczyk
Copy link
Contributor

marekkirejczyk commented Sep 1, 2018

Example usage:

expect(() => wallet.transfer('0xab..cd.', 200)).to.changeBalance('0xb', 200)

chained:

expect(() => wallet.transfer('0xab...cd', 200))
  .to.changeBalance('0xab...cd', -200)  
  .to.changeBalance('0xab...cd', 200);

token:

expect(() => token.transfer('0xb', 200))
  .to.changeTokenBalance(someToken, '0xb', 200);
@marekkirejczyk
Copy link
Contributor Author

Partially implemented in #24

@quezak
Copy link

quezak commented Feb 19, 2019

The matcher works nice for wallets, could you also support passing a bare address to the function? Would be useful e.g. to track balance changes on a contract address. Currently, if I try to do that, I get a runtime error: TypeError: wallet.getBalance is not a function.

Side note: could you also make the typings concrete here? Currently the arguments are wallet: any, balance: any -- I have to find out what I'm expected to pass there through trial and error or looking into the docs (which, in fact, also don't specify these types), while with proper typings it would be obvious from the start :)

@marekkirejczyk
Copy link
Contributor Author

Hi @quezak

The problem with passing bare address is that matcher don't have access to the provider. So it is either wallet or (we could implement) bare address + provider

Typing definitely can be improved. Would you create a separate issue for that?

@quezak
Copy link

quezak commented Feb 20, 2019

Thanks for the reply! Another idea: it looks much easier (and satisfies my use case) to accept Wallet | Contract -- ethers.js contracts have an address and provider field, same as wallets, so it could even use the same code.

I'll add the typings issue some time later.

@sz-piotr sz-piotr added the waffle-3.0.0 Part of the improvements for Waffle 3 label Dec 20, 2019
@sz-piotr sz-piotr mentioned this issue Dec 20, 2019
33 tasks
@gitpusha
Copy link

@quezak I second that:

Would be useful e.g. to track balance changes on a contract address

@marekkirejczyk @sz-piotr Any ETAs for new features like this ?

Thanks for the amazing tool btw!

@marekkirejczyk
Copy link
Contributor Author

Proposed variation of syntax for different ways to provide provider:

expect(() => wallet.transfer('0xab..cd.', 200)).to.changeBalance('0xab...cd', 200, provider)
expect(() => wallet.transfer('0xab..cd.', 200)).to.changeBalance(wallet, 200)
expect(() => wallet.transfer('0xab..cd.', 200)).to.changeBalance(contract, 200)

Can we skip promise and have sth like below?

expect(await wallet.transfer('0xab..cd.', 200).to.changeBalance('0xab...cd', 200, provider)

Idea 1:

Take the block number from receipt and check the balance in previous block
Pros:

  • no need for Promise

Cons:

  • what if we have more than one thing happening in the block

Idea 2:

  • explore what else is there in receipt, can we use it to explore VM state diff?

@marekkirejczyk
Copy link
Contributor Author

@quezak Contract type to change balance added in #363
To be released in 3.1.1

@marekkirejczyk
Copy link
Contributor Author

✅ Expectation for token balance
✅ Suport for Contracts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waffle-3.0.0 Part of the improvements for Waffle 3
Projects
None yet
Development

No branches or pull requests

4 participants