From cedf1e8a486bb5621902f60af81d0f2e1a1623e6 Mon Sep 17 00:00:00 2001 From: Peter Murray Date: Mon, 22 Jan 2018 09:35:27 -0500 Subject: [PATCH 1/8] Fix for trufflesuite/ganache-cli#354 - evm_mine returns true in the result to ensure valid JSON_RPC response. --- lib/subproviders/geth_api_double.js | 4 +++- test/mining.js | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/subproviders/geth_api_double.js b/lib/subproviders/geth_api_double.js index ee3203a3f9..9205ca0c9c 100644 --- a/lib/subproviders/geth_api_double.js +++ b/lib/subproviders/geth_api_double.js @@ -469,7 +469,9 @@ GethApiDouble.prototype.evm_increaseTime = function(seconds, callback) { }; GethApiDouble.prototype.evm_mine = function(callback) { - this.state.processBlocks(1, callback); + this.state.processBlocks(1, function(err) { + callback(err, true); + }); }; GethApiDouble.prototype.debug_traceTransaction = function(tx_hash, params, callback) { diff --git a/test/mining.js b/test/mining.js index 5142ec6227..43e31211aa 100644 --- a/test/mining.js +++ b/test/mining.js @@ -111,9 +111,10 @@ describe("Mining", function() { jsonrpc: "2.0", method: "evm_mine", id: new Date().getTime() - }, function(err) { + }, function(err, result) { if (err) return reject(err); - accept(); + if(result.result !== true) return reject(new Error("evm_mine should return result = true:" + JSON.stringify(result))) + accept(result); }) }); } From 372f3c24e7404d922dd4837c9754abff9e751e77 Mon Sep 17 00:00:00 2001 From: Ben Burns Date: Tue, 23 Jan 2018 15:03:37 +1300 Subject: [PATCH 2/8] since we no longer have any breaking changes, switch beta to patch release --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 365dc3485f..ec0c5caf2c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "ganache-core", - "version": "3.0.0-beta.0", + "version": "2.1.0-beta.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 0fea96c9b9..9d17dc2196 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ganache-core", - "version": "3.0.0-beta.0", + "version": "2.1.0-beta.0", "main": "./index.js", "directories": { "lib": "./lib" From f82f436da010d39526fdb6960a0e47b3b1f6b061 Mon Sep 17 00:00:00 2001 From: Peter Murray Date: Tue, 23 Jan 2018 14:24:57 -0500 Subject: [PATCH 3/8] Per https://github.com/trufflesuite/ganache-cli/issues/354#issuecomment-359614745 --- lib/subproviders/geth_api_double.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/subproviders/geth_api_double.js b/lib/subproviders/geth_api_double.js index 9205ca0c9c..50e097f9ed 100644 --- a/lib/subproviders/geth_api_double.js +++ b/lib/subproviders/geth_api_double.js @@ -470,7 +470,7 @@ GethApiDouble.prototype.evm_increaseTime = function(seconds, callback) { GethApiDouble.prototype.evm_mine = function(callback) { this.state.processBlocks(1, function(err) { - callback(err, true); + callback(err, '0x0'); }); }; From 9a691a0a1899672808133c61ddd3586ab28d01af Mon Sep 17 00:00:00 2001 From: Peter Murray Date: Tue, 23 Jan 2018 14:28:03 -0500 Subject: [PATCH 4/8] updated test --- test/mining.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/mining.js b/test/mining.js index 43e31211aa..1e33a27cc5 100644 --- a/test/mining.js +++ b/test/mining.js @@ -113,7 +113,7 @@ describe("Mining", function() { id: new Date().getTime() }, function(err, result) { if (err) return reject(err); - if(result.result !== true) return reject(new Error("evm_mine should return result = true:" + JSON.stringify(result))) + if(result.result !== '0x0') return reject(new Error("evm_mine should return result = '0x0':" + JSON.stringify(result))) accept(result); }) }); From cdc223fb0aeb414ba8639aa0f8f50e6ee41d6875 Mon Sep 17 00:00:00 2001 From: Ben Burns Date: Tue, 23 Jan 2018 14:59:19 +1300 Subject: [PATCH 5/8] Revert default value of vmErrorsOnRPCResponse to true to avoid breaking change --- README.md | 2 +- lib/provider.js | 13 +++++-------- test/accounts.js | 8 -------- test/bad_input.js | 2 -- test/mining.js | 1 - test/requests.js | 3 --- test/runtime_errors.js | 2 -- test/stability.js | 2 -- 8 files changed, 6 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index f0c4345868..d778d8dd55 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ Both `.provider()` and `.server()` take a single object which allows you to spec * `"db_path"`: `String` - Specify a path to a directory to save the chain database. If a database already exists, that chain will be initialized instead of creating a new one. * `"db"`: `Object` - Specify an alternative database instance, for instance [MemDOWN](https://github.com/level/memdown). * `"ws"`: Enable a websocket server. This is `true` by default. -* `"vmErrorsOnRPCResponse"`: Whether to report runtime errors from EVM code as RPC errors. This is `false` by default to replicate the error reporting behavior of the major clients. +* `"vmErrorsOnRPCResponse"`: Whether to report runtime errors from EVM code as RPC errors. This is `true` by default to replicate the error reporting behavior of previous versions of ganache. # IMPLEMENTED METHODS diff --git a/lib/provider.js b/lib/provider.js index 7d753d8a1d..b4c80b3d9d 100644 --- a/lib/provider.js +++ b/lib/provider.js @@ -17,17 +17,14 @@ function Provider(options) { const self = this; EventEmitter.call(this); - if (options == null) { - options = {}; - } - - if (options.logger == null) { - options.logger = { + const defaultOptions = { + vmErrorsOnRPCResponse: true, + logger: { log: function() {} - }; + } } - this.options = options; + this.options = Object.assign({}, defaultOptions, options); var gethApiDouble = new GethApiDouble(Object.assign({}, options, { _provider: self })); diff --git a/test/accounts.js b/test/accounts.js index c19a021d7f..25a88c634a 100644 --- a/test/accounts.js +++ b/test/accounts.js @@ -11,7 +11,6 @@ describe("Accounts", function() { var web3 = new Web3(); web3.setProvider(Ganache.provider({ mnemonic: mnemonic, - vmErrorsOnRPCResponse: true })); web3.eth.getAccounts(function(err, accounts) { @@ -27,7 +26,6 @@ describe("Accounts", function() { web3.setProvider(Ganache.provider({ mnemonic: mnemonic, secure: true, - vmErrorsOnRPCResponse: true })); web3.eth.sendTransaction({ @@ -48,7 +46,6 @@ describe("Accounts", function() { mnemonic: mnemonic, secure: true, unlocked_accounts: [expected_address], - vmErrorsOnRPCResponse: true })); web3.eth.sendTransaction({ @@ -91,7 +88,6 @@ describe("Accounts", function() { mnemonic: mnemonic, secure: true, unlocked_accounts: [0, second_address], - vmErrorsOnRPCResponse: true })); // Set up: give second address some ether @@ -134,7 +130,6 @@ describe("Accounts", function() { mnemonic: mnemonic, secure: true, unlocked_accounts: [0, second_address], - vmErrorsOnRPCResponse: true })); return web3.eth.sign("some data", second_address) @@ -153,7 +148,6 @@ describe("Accounts", function() { { balance: '0x12' }, { balance: '0x13' } ], - vmErrorsOnRPCResponse: true })); web3.eth.getAccounts(function(err, result) { @@ -168,7 +162,6 @@ describe("Accounts", function() { var web3 = new Web3(); web3.setProvider(Ganache.provider({ total_accounts: 7, - vmErrorsOnRPCResponse: true })); web3.eth.getAccounts(function(err, result) { @@ -182,7 +175,6 @@ describe("Accounts", function() { var web3 = new Web3(); web3.setProvider(Ganache.provider({ default_balance_ether: 1.23456, - vmErrorsOnRPCResponse: true })); web3.eth.getAccounts(function(err, accounts) { diff --git a/test/bad_input.js b/test/bad_input.js index e087582262..dfd5a74066 100644 --- a/test/bad_input.js +++ b/test/bad_input.js @@ -146,7 +146,6 @@ var tests = function(web3) { describe("Provider:", function() { var web3 = new Web3(); web3.setProvider(Ganache.provider({ - vmErrorsOnRPCResponse: true })); tests(web3); }); @@ -158,7 +157,6 @@ describe("Server:", function(done) { before("Initialize Ganache server", function(done) { server = Ganache.server({ - vmErrorsOnRPCResponse: true }); server.listen(port, function() { web3.setProvider(new Web3.providers.HttpProvider("http://localhost:" + port)); diff --git a/test/mining.js b/test/mining.js index 1e33a27cc5..4e36980e41 100644 --- a/test/mining.js +++ b/test/mining.js @@ -12,7 +12,6 @@ process.removeAllListeners("uncaughtException"); describe("Mining", function() { var web3 = new Web3(Ganache.provider({ //logger: console, - vmErrorsOnRPCResponse: true })); var accounts; var snapshot_id; diff --git a/test/requests.js b/test/requests.js index 49dde555a1..2bac2080b1 100644 --- a/test/requests.js +++ b/test/requests.js @@ -1124,7 +1124,6 @@ describe("Provider:", function() { logger: logger, seed: "1337", // so that the runtime errors on call test passes - vmErrorsOnRPCResponse: true })); tests(web3); @@ -1146,7 +1145,6 @@ describe("HTTP Server:", function(done) { logger: logger, seed: "1337", // so that the runtime errors on call test passes - vmErrorsOnRPCResponse: true }); server.listen(port, function(err) { @@ -1173,7 +1171,6 @@ describe("WebSockets Server:", function(done) { logger: logger, seed: "1337", // so that the runtime errors on call test passes - vmErrorsOnRPCResponse: true }); server.listen(port, function(err) { var provider = new Web3WsProvider("ws://localhost:" + port); diff --git a/test/runtime_errors.js b/test/runtime_errors.js index e7cad65c28..77230557a3 100644 --- a/test/runtime_errors.js +++ b/test/runtime_errors.js @@ -12,7 +12,6 @@ process.removeAllListeners("uncaughtException"); describe("Runtime Errors", function() { var web3 = new Web3(Ganache.provider({ - vmErrorsOnRPCResponse: true })); var accounts; var ErrorContract; @@ -22,7 +21,6 @@ describe("Runtime Errors", function() { before ("initialize Web3", function(done) { web3 = new Web3() web3.setProvider(Ganache.provider({ - vmErrorsOnRPCResponse: true })) done() }); diff --git a/test/stability.js b/test/stability.js index f62d3b9603..e571b5b2d4 100644 --- a/test/stability.js +++ b/test/stability.js @@ -23,7 +23,6 @@ describe("stability", function(done) { before("Initialize the provider", function() { provider = Ganache.provider({ - vmErrorsOnRPCResponse: true }); web3.setProvider(provider); }); @@ -145,7 +144,6 @@ describe("stability", function(done) { before("initialize the provider", function() { provider = Ganache.provider({ - vmErrorsOnRPCResponse: true }); web3.setProvider(provider); }); From 6c96f9f27aa9d76285a687ac8313c9b041d0343a Mon Sep 17 00:00:00 2001 From: Ben Burns Date: Tue, 23 Jan 2018 15:03:37 +1300 Subject: [PATCH 6/8] since we no longer have any breaking changes, switch beta to patch release --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 365dc3485f..ec0c5caf2c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "ganache-core", - "version": "3.0.0-beta.0", + "version": "2.1.0-beta.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 0fea96c9b9..9d17dc2196 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ganache-core", - "version": "3.0.0-beta.0", + "version": "2.1.0-beta.0", "main": "./index.js", "directories": { "lib": "./lib" From d4b8c7e36a10ed20e951a62f532affa6b0189bbe Mon Sep 17 00:00:00 2001 From: Ben Burns Date: Wed, 24 Jan 2018 09:06:10 +1300 Subject: [PATCH 7/8] Change new mining test to use assert --- test/mining.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/mining.js b/test/mining.js index 4e36980e41..aae8ec4598 100644 --- a/test/mining.js +++ b/test/mining.js @@ -112,7 +112,7 @@ describe("Mining", function() { id: new Date().getTime() }, function(err, result) { if (err) return reject(err); - if(result.result !== '0x0') return reject(new Error("evm_mine should return result = '0x0':" + JSON.stringify(result))) + assert.notDeepEqual(result.result, "0x0", "evm_mine should return result = '0x0'"); accept(result); }) }); From 809549fea6465599037588eb10f1b3f71b4973cb Mon Sep 17 00:00:00 2001 From: Ben Burns Date: Wed, 24 Jan 2018 09:17:46 +1300 Subject: [PATCH 8/8] notDeepEqual... deepEqual... same thing, right? --- test/mining.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/mining.js b/test/mining.js index aae8ec4598..76fa667137 100644 --- a/test/mining.js +++ b/test/mining.js @@ -112,7 +112,7 @@ describe("Mining", function() { id: new Date().getTime() }, function(err, result) { if (err) return reject(err); - assert.notDeepEqual(result.result, "0x0", "evm_mine should return result = '0x0'"); + assert.deepEqual(result.result, "0x0"); accept(result); }) });