How to test with Mocha and Chai that a call at the kill() function of a Smart Contract (i.e., which does the selfdestruct) has gone right?

  • 1
    you can emit an event an check it in the test or call a function after selfdestruct and check for exception – Badr Bellaj Jul 13 '18 at 8:25
  • I tried to catch the exception with github.com/OpenZeppelin/openzeppelin-solidity/blob/master/test/…, but when I try to call a function (after the kill function) i got 'Error: Attempting to run transaction which calls a contract function, but recipient address 0x345ca3e014aaf5dca488057592ee47305d9b3e10 is not a contract address' – Bruce Wayne Jul 13 '18 at 9:03
  • as the contract is destructed you can no more call its functions hence the exception – Badr Bellaj Jul 13 '18 at 10:13

You can confirm that the bytecode has been zeroed out. Use the web3.eth.getCode(yourContractAddress) explained here.

  • before selfdestruct, you get the proper code, like 0x6040...
  • after selfdestruct, you get 0x

Of course, as mentioned by Ignacio and Badr, you can, and should, also test that the side actions have been executed correctly:

  • the expected event was emitted
  • the correct recipient received the balance

You can check if the funds of the contract have been sent to the given address.


Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.