rkalis / truffle-assertions

🛠 Assertions and utilities for testing Ethereum smart contracts with Truffle unit tests
https://kalis.me/check-events-solidity-smart-contract-test-truffle/
MIT License
154 stars 20 forks source link

How can I test the burning of a token with truffle assertions? #38

Closed damianlluch closed 3 years ago

damianlluch commented 3 years ago

Hello, I am developing my first contract professionally. I am using truffle assertions. I have doubts about how to test that a token is burnt. I understand that one option would be to verify that the owner of the token is address 0. How do I do this with truffle assertions? do I need to install another library? Another option would be to check the balance of the user or the burned token. But this is not clear to me. If someone can tell me how to do it with truffle assertions. Thanks

rkalis commented 3 years ago

Truffle-assertions only helps with specific functionality that is difficult to test without it (like events and reverts). What you want to test is possible with just the regular Truffle test framework. Your suggested methods work. You probably want to check that the balance of the user has decreased by X and the balance of address(0) has increased by X.

If you want to knowhow to do that specifically, you can check out some Truffle guides online or look at the Ethereum StackExchange, but it is out of scope for the truffle-assertions library.

One additional check you can do with truffle-assertions is check that a Transfer event has been emitted with the expected values (from user to address(0) with amount X).