3

Post Byzantium, when I am testing contract functions, some either (1) return a transaction object/receipt with a status field, while others (2) fail and revert.

Checking for 1) transaction object returned

assert(txReceipt.receipt.status === 0)

Checking for 2) error thrown

contract.someMethodThatWillFail(params)
  .then(
    () => assert.throw('should not have reached here'),
    e => assert.isAtLeast(e.message.indexOf('revert'), 0)
)

What determines if method will behave as (1) vs. (2)? (other than trial and error)

I've tried violating require()'s and modifiers on functions, and I don't see a pattern of whether or not that function will result in 1 vs 2.

2

Figured it out, pretty obvious come to think of it. The transaction receipt only returns the status after the transaction has been mined.

So scenario (1) happens after the transaction has been mined, but (2) can be checked immediately after calling the function, even before the transaction is mined.

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.