Forked from xavierlepretre/expected_exception_testRPC_and_geth.js
Created
May 6, 2019 22:15
-
-
Save JCGit2018/9f79d5ef6b966f193987ae707c271856 to your computer and use it in GitHub Desktop.
When TestRPC and Geth throw, they behave in a different manner. This Gist is an example on how to cover such a situation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var expectedExceptionPromise = function (action, gasToUse) { | |
| return new Promise(function (resolve, reject) { | |
| try { | |
| resolve(action()); | |
| } catch(e) { | |
| reject(e); | |
| } | |
| }) | |
| .then(function (txn) { | |
| // https://gist.github.com/xavierlepretre/88682e871f4ad07be4534ae560692ee6 | |
| return web3.eth.getTransactionReceiptMined(txn); | |
| }) | |
| .then(function (receipt) { | |
| // We are in Geth | |
| assert.equal(receipt.gasUsed, gasToUse, "should have used all the gas"); | |
| }) | |
| .catch(function (e) { | |
| console.log(e); | |
| if ((e + "").indexOf("invalid JUMP") > -1) { | |
| // We are in TestRPC | |
| } else { | |
| throw e; | |
| } | |
| }); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment