From 8d311f3245d510a90407ee1d1bccfb33756fface Mon Sep 17 00:00:00 2001 From: Ben Burns Date: Wed, 22 Aug 2018 22:40:09 +0000 Subject: [PATCH 1/3] log reason string on transaction failure --- lib/statemanager.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/statemanager.js b/lib/statemanager.js index 4200058466..9783de562f 100644 --- a/lib/statemanager.js +++ b/lib/statemanager.js @@ -523,6 +523,9 @@ StateManager.prototype.printTransactionReceipt = function(tx_hash, error, callba if (error) { self.logger.log(" Runtime Error: " + error.error); + if (error.reason) { + self.logger.log(" Revert reason: " + error.reason); + } } self.logger.log(""); From f52e1abd5002c7aa9ef9983360e993b1807b001f Mon Sep 17 00:00:00 2001 From: Adibas03 Date: Sat, 25 Aug 2018 09:19:15 +0100 Subject: [PATCH 2/3] Complete removal --- lib/statemanager.js | 24 +----------------------- test/transaction_rejection.js | 12 ------------ 2 files changed, 1 insertion(+), 35 deletions(-) diff --git a/lib/statemanager.js b/lib/statemanager.js index 9783de562f..e6525788be 100644 --- a/lib/statemanager.js +++ b/lib/statemanager.js @@ -880,29 +880,7 @@ StateManager.prototype.createFakeTransactionWithCorrectNonce = function(rawTx, f `tx has nonce of: ${to.number(tx.nonce)}`)) } } - - // If we're calling a contract, check to make sure the address specified is a contract address - if (_transactionIsContractCall(rawTx)) { - self.getCode(to.hex(rawTx.to), 'latest', function(err, code) { - if (err) { - callback(err); - } else if (code === '0x0') { - callback(new TXRejectedError(`Attempting to run transaction which calls a contract function, but recipient address ${to.hex(rawTx.to)} is not a contract address`)) - } else { - callback(null, tx) - } - }); - } else { - callback(null, tx) - } + callback(null, tx) }); } - -// returns true when transaction has a non-null, non-empty to and data field -var _transactionIsContractCall = function(rawTx) { - let recipient = to.hex(rawTx.to || '0x0') - let data = to.hex(rawTx.data || '0x0') - - return recipient !== '0x0' && data !== '0x0' -} module.exports = StateManager; diff --git a/test/transaction_rejection.js b/test/transaction_rejection.js index 961b684ee2..098bdb7746 100644 --- a/test/transaction_rejection.js +++ b/test/transaction_rejection.js @@ -100,18 +100,6 @@ describe("Transaction rejection", function() { }, /sender doesn't have enough funds to send tx/, done) }); - it("should reject contract transaction if 'to' is not a contract address", function(done) { - let params = { - to: '0x0000000000000000000000001234000000000000' - } - - testTransactionForRejection( - params, - new RegExp(`Attempting to run transaction which calls a contract function, but recipient address ${params.to} is not a contract address`), - done - ) - }); - function testTransactionForRejection(paramsOverride, messageRegex, done) { let params = Object.assign({ from: accounts[0], From b12a29a05be1bfa1480469e17d691e70324f916a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=ADsli=20Kristj=C3=A1nsson?= Date: Tue, 4 Sep 2018 15:27:56 +0000 Subject: [PATCH 3/3] Fixing leading zeros for hex encoded quantities in tx #166 --- lib/utils/txhelper.js | 16 +++++++------- test/hex.js | 49 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 8 deletions(-) diff --git a/lib/utils/txhelper.js b/lib/utils/txhelper.js index f4abc5e5a5..61b6a18684 100644 --- a/lib/utils/txhelper.js +++ b/lib/utils/txhelper.js @@ -14,24 +14,24 @@ module.exports = { } var resultJSON = { hash: to.hex(tx.hash()), - nonce: to.hex(tx.nonce), + nonce: to.rpcQuantityHexString(tx.nonce), blockHash: to.hex(block.hash()), blockNumber: to.hex(block.header.number), transactionIndex: to.hex(transactionIndex), from: to.hex(tx.from), to: to.hex(tx.to), - value: to.hex(tx.value), - gas: to.hex(tx.gasLimit), - gasPrice: to.hex(tx.gasPrice), - input: to.hex(tx.data), + value: to.rpcQuantityHexString(tx.value), + gas: to.rpcQuantityHexString(tx.gasLimit), + gasPrice: to.rpcQuantityHexString(tx.gasPrice), + input: to.rpcQuantityHexString(tx.data), }; if (tx.v && tx.v.length > 0 && tx.r && tx.r.length > 0 && tx.s && tx.s.length > 0) { - resultJSON.v = to.hex(tx.v); - resultJSON.r = to.hex(tx.r); - resultJSON.s = to.hex(tx.s); + resultJSON.v = to.rpcQuantityHexString(tx.v); + resultJSON.r = to.rpcQuantityHexString(tx.r); + resultJSON.s = to.rpcQuantityHexString(tx.s); } return resultJSON; diff --git a/test/hex.js b/test/hex.js index 435d3b89c7..f2a74cc0ce 100644 --- a/test/hex.js +++ b/test/hex.js @@ -60,6 +60,18 @@ function noLeadingZeros(method, result, path) { } } +function noLeadingZerosTx(tx) { + const fields = ['nonce', 'gasPrice', 'gas', 'value', 'input']; + for (var i in fields) { + const field = fields[i] + if (typeof tx[field] === "undefined") { + assert.fail(`Field ${field} should not be undefined`) + } + assert.equal(tx[field], to.rpcQuantityHexString(tx[field]), assert `Quantity field ${field} in transaction is missing or has leading zeroes.`); + } +} + + describe("JSON-RPC Response", function() { var web3 = new Web3(); var provider = Ganache.provider(); @@ -126,4 +138,41 @@ describe("JSON-RPC Response", function() { }); }); }); + + it("should not have leading zeros in rpc tx quantity hex strings", function(done) { + var request = { + "jsonrpc": "2.0", + "method": "eth_sendTransaction", + "params": [ + { + "from": accounts[0], + "to": accounts[1], + "value": "0x100000000", + "gas": "0x015F90", + "gasPrice": "0x01", + } + ], + "id": 1 + }; + provider.sendAsync(request, function() { + // force nonce to be at least 1 (since 0 encodes to 0x0) + provider.sendAsync(request, function(err, result) { + request = { + "jsonrpc": "2.0", + "method": "eth_getTransactionByHash", + "params": [ + result.result + ], + "id": 2 + }; + + provider.sendAsync(request, function(err, result) { + + noLeadingZerosTx(result.result); + done(); + + }); + }); + }); + }); });