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.
Revisions
-
xavierlepretre revised this gist
Feb 1, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -14,7 +14,7 @@ module.exports = function expectedExceptionPromise(action, gasToUse) { } }) .then(function (txObj) { return typeof txObj === "string" ? web3.eth.getTransactionReceiptMined(txObj) // regular tx hash : typeof txObj.receipt !== "undefined" ? txObj.receipt // truffle-contract function call -
xavierlepretre revised this gist
Jan 22, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -27,7 +27,7 @@ module.exports = function expectedExceptionPromise(action, gasToUse) { // We are in Geth if (typeof receipt.status !== "undefined") { // Byzantium assert.strictEqual(parseInt(receipt.status), 0, "should have reverted"); } else { // Pre Byzantium assert.equal(receipt.gasUsed, gasToUse, "should have used all the gas"); -
xavierlepretre revised this gist
Nov 18, 2017 . 1 changed file with 25 additions and 21 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ "use strict"; /** * @param {!Function.<!Promise>} action. * @param {!Number | !string | !BigNumber} gasToUse. @@ -20,26 +22,28 @@ module.exports = function expectedExceptionPromise(action, gasToUse) { ? web3.eth.getTransactionReceiptMined(txObj.transactionHash) // deployment : txObj; // Unknown last case }) .then( function (receipt) { // We are in Geth if (typeof receipt.status !== "undefined") { // Byzantium assert.strictEqual(receipt.status, "0x0", "should have reverted"); } else { // Pre Byzantium assert.equal(receipt.gasUsed, gasToUse, "should have used all the gas"); } }, function (e) { if ((e + "").indexOf("invalid JUMP") > -1 || (e + "").indexOf("out of gas") > -1 || (e + "").indexOf("invalid opcode") > -1 || (e + "").indexOf("revert") > -1) { // We are in TestRPC } else if ((e + "").indexOf("please check your gas amount") > -1) { // We are in Geth for a deployment } else { throw e; } } ); }; -
xavierlepretre revised this gist
Nov 18, 2017 . 1 changed file with 5 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,8 @@ /** * @param {!Function.<!Promise>} action. * @param {!Number | !string | !BigNumber} gasToUse. * @returns {!Promise} which throws unless it hit a valid error. */ module.exports = function expectedExceptionPromise(action, gasToUse) { return new Promise(function (resolve, reject) { try { -
xavierlepretre revised this gist
Nov 18, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -16,7 +16,7 @@ module.exports = function expectedExceptionPromise(action, gasToUse) { : txObj; // Unknown last case }) .then(function (receipt) { // We are in Geth or TestRPC if (typeof receipt.status !== "undefined") { // Byzantium assert.strictEqual(receipt.status, "0x0", "should have reverted"); -
xavierlepretre revised this gist
Nov 18, 2017 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -28,7 +28,8 @@ module.exports = function expectedExceptionPromise(action, gasToUse) { .catch(function (e) { if ((e + "").indexOf("invalid JUMP") > -1 || (e + "").indexOf("out of gas") > -1 || (e + "").indexOf("invalid opcode") > -1 || (e + "").indexOf("revert") > -1) { // We are in TestRPC } else if ((e + "").indexOf("please check your gas amount") > -1) { // We are in Geth for a deployment -
xavierlepretre revised this gist
Oct 26, 2017 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -19,7 +19,6 @@ module.exports = function expectedExceptionPromise(action, gasToUse) { // We are in Geth if (typeof receipt.status !== "undefined") { // Byzantium assert.strictEqual(receipt.status, "0x0", "should have reverted"); } else { // Pre Byzantium -
xavierlepretre revised this gist
Oct 26, 2017 . 1 changed file with 9 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -16,8 +16,15 @@ module.exports = function expectedExceptionPromise(action, gasToUse) { : txObj; // Unknown last case }) .then(function (receipt) { // We are in Geth if (typeof receipt.status !== "undefined") { // Byzantium console.log(receipt); assert.strictEqual(receipt.status, "0x0", "should have reverted"); } else { // Pre Byzantium assert.equal(receipt.gasUsed, gasToUse, "should have used all the gas"); } }) .catch(function (e) { if ((e + "").indexOf("invalid JUMP") > -1 || -
xavierlepretre revised this gist
Sep 12, 2017 . 1 changed file with 33 additions and 26 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,26 +1,33 @@ module.exports = function expectedExceptionPromise(action, gasToUse) { return new Promise(function (resolve, reject) { try { resolve(action()); } catch(e) { reject(e); } }) .then(function (txObj) { return typeof txn === "string" ? web3.eth.getTransactionReceiptMined(txObj) // regular tx hash : typeof txObj.receipt !== "undefined" ? txObj.receipt // truffle-contract function call : typeof txObj.transactionHash === "string" ? web3.eth.getTransactionReceiptMined(txObj.transactionHash) // deployment : txObj; // Unknown last case }) .then(function (receipt) { // We are in Geth or the tx wrongly passed assert.equal(receipt.gasUsed, gasToUse, "should have used all the gas"); }) .catch(function (e) { if ((e + "").indexOf("invalid JUMP") > -1 || (e + "").indexOf("out of gas") > -1 || (e + "").indexOf("invalid opcode") > -1) { // We are in TestRPC } else if ((e + "").indexOf("please check your gas amount") > -1) { // We are in Geth for a deployment } else { throw e; } }); }; -
xavierlepretre revised this gist
Aug 30, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -15,7 +15,7 @@ var expectedExceptionPromise = function (action, gasToUse) { assert.equal(receipt.gasUsed, gasToUse, "should have used all the gas"); }) .catch(function (e) { if ((e + "").indexOf("invalid JUMP") || (e + "").indexOf("out of gas") || (e + "").indexOf("invalid opcode") > -1) { // We are in TestRPC } else if ((e + "").indexOf("please check your gas amount") > -1) { // We are in Geth for a deployment -
xavierlepretre revised this gist
Aug 29, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -15,7 +15,7 @@ var expectedExceptionPromise = function (action, gasToUse) { assert.equal(receipt.gasUsed, gasToUse, "should have used all the gas"); }) .catch(function (e) { if ((e + "").indexOf("invalid JUMP") || (e + "").indexOf("out of gas" || (e + "").indexOf("invalid opcode") > -1) { // We are in TestRPC } else if ((e + "").indexOf("please check your gas amount") > -1) { // We are in Geth for a deployment -
xavierlepretre revised this gist
Oct 5, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -15,7 +15,7 @@ var expectedExceptionPromise = function (action, gasToUse) { assert.equal(receipt.gasUsed, gasToUse, "should have used all the gas"); }) .catch(function (e) { if ((e + "").indexOf("invalid JUMP") || (e + "").indexOf("out of gas") > -1) { // We are in TestRPC } else if ((e + "").indexOf("please check your gas amount") > -1) { // We are in Geth for a deployment -
xavierlepretre revised this gist
Sep 7, 2016 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -17,8 +17,8 @@ var expectedExceptionPromise = function (action, gasToUse) { .catch(function (e) { if ((e + "").indexOf("invalid JUMP") > -1) { // We are in TestRPC } else if ((e + "").indexOf("please check your gas amount") > -1) { // We are in Geth for a deployment } else { throw e; } -
xavierlepretre revised this gist
Sep 7, 2016 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -17,6 +17,8 @@ var expectedExceptionPromise = function (action, gasToUse) { .catch(function (e) { if ((e + "").indexOf("invalid JUMP") > -1) { // We are in TestRPC } else if ((e + "").indexOf("please check your gas amount") > -1) { // We are in Geth for a deployment } else { throw e; } -
xavierlepretre revised this gist
Jul 29, 2016 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -15,7 +15,6 @@ var expectedExceptionPromise = function (action, gasToUse) { assert.equal(receipt.gasUsed, gasToUse, "should have used all the gas"); }) .catch(function (e) { if ((e + "").indexOf("invalid JUMP") > -1) { // We are in TestRPC } else { -
xavierlepretre renamed this gist
Jul 29, 2016 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
xavierlepretre revised this gist
Jul 29, 2016 . 1 changed file with 25 additions and 25 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,25 +1,25 @@ 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; } }); }; -
xavierlepretre renamed this gist
Jul 21, 2016 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
xavierlepretre created this gist
Jul 21, 2016 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ new Promise(function (resolve, reject) { try { resolve(myContract.myMethod({ from: myAccount, gas: 300000 // Large number })); } catch(e) { reject(e); } }) .then(function (txn) { return web3.eth.getTransactionReceiptMined(txn); // https://gist.github.com/xavierlepretre/88682e871f4ad07be4534ae560692ee6 }) .then(function (receipt) { assert.equal(receipt.gasUsed, 300000, "should have used all the gas"); }) .then(done) .catch(function (e) { if ((e + "").indexOf("invalid JUMP") > -1) { // We are in TestRPC done(); } else { done(e); } });