From 8fa7357d07aff8b9b2cb7116a9243d443e89260b Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Thu, 7 Jun 2018 19:08:18 -0400 Subject: [PATCH 1/7] fix default from and data; add single test spec --- lib/tests/test.js | 12 +++++++ .../test/simple_storage_deploy_spec.js | 33 +++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 test_apps/test_app/test/simple_storage_deploy_spec.js diff --git a/lib/tests/test.js b/lib/tests/test.js index b89739d8c..1e21442c6 100644 --- a/lib/tests/test.js +++ b/lib/tests/test.js @@ -211,12 +211,20 @@ class Test { function createContractObject(accounts, next) { async.each(Object.keys(self.engine.contractsManager.contracts), (contractName, eachCb) => { const contract = self.engine.contractsManager.contracts[contractName]; + let data; if (!self.contracts[contractName]) { self.contracts[contractName] = {}; + data = ""; + } else { + data = self.contracts[contractName].options.data; } Object.assign(self.contracts[contractName], new self.web3.eth.Contract(contract.abiDefinition, contract.deployedAddress, {from: self.web3.eth.defaultAccount, gas: 6000000})); self.contracts[contractName].address = contract.deployedAddress; + if (self.contracts[contractName].options) { + self.contracts[contractName].options.from = self.contracts[contractName].options.from || web3.eth.defaultAccount; + self.contracts[contractName].options.data = data; + } eachCb(); }, (err) => { next(err, accounts); @@ -260,6 +268,10 @@ class Test { this.contracts[contractName] = new this.web3.eth.Contract(contract.abiDefinition, contract.address, {from: this.web3.eth.defaultAccount, gas: 6000000}); this.contracts[contractName].address = contract.address; + this.contracts[contractName].options.data = contract.code; + web3.eth.getAccounts().then((accounts) => { + this.contracts[contractName].options.from = contract.from || accounts[0]; + }); return this.contracts[contractName]; } throw new Error(__('Unknown module %s', module)); diff --git a/test_apps/test_app/test/simple_storage_deploy_spec.js b/test_apps/test_app/test/simple_storage_deploy_spec.js new file mode 100644 index 000000000..b44aa0643 --- /dev/null +++ b/test_apps/test_app/test/simple_storage_deploy_spec.js @@ -0,0 +1,33 @@ +/*global contract, config, it, embark, assert, web3*/ +const SimpleStorage = embark.require('Embark/contracts/SimpleStorage'); +let accounts; + +config({ + contracts: { + "SimpleStorage": { + args: [100] + } + } +}, (err, theAccounts) => { + accounts = theAccounts; +}); + +contract("SimpleStorage Deploy", function () { + let SimpleStorageInstance; + + before(async function() { + SimpleStorageInstance = await SimpleStorage.deploy({data: SimpleStorage.options.data, arguments: [150]}).send(); + }); + + it("should set constructor value", async function () { + let result = await SimpleStorageInstance.methods.storedData().call(); + assert.strictEqual(parseInt(result, 10), 150); + }); + + it("set storage value", async function () { + await SimpleStorageInstance.methods.set(150).send(); + let result = await SimpleStorageInstance.methods.get().call(); + assert.strictEqual(parseInt(result, 10), 499650); + }); + +}); From c1590d0b4880ecb977e816944c84049a55caca2c Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Thu, 7 Jun 2018 19:57:56 -0400 Subject: [PATCH 2/7] change deploy to beforeAll, so it takes priority over the test before --- lib/tests/run_tests.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/tests/run_tests.js b/lib/tests/run_tests.js index 2496c4725..baaedd0ba 100644 --- a/lib/tests/run_tests.js +++ b/lib/tests/run_tests.js @@ -81,7 +81,9 @@ module.exports = { mocha.addFile(file); mocha.suite.timeout(0); - mocha.suite.beforeEach('Wait for deploy', (done) => { + + mocha.suite.beforeAll('Wait for deploy', (done) => { + console.dir("runnning wait for deploy"); global.embark.onReady(() => { done(); }); From 1c6df9db8d7e8618202c7787ff96885a2c8cfd39 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Thu, 7 Jun 2018 20:05:56 -0400 Subject: [PATCH 3/7] remove data parameter --- lib/tests/run_tests.js | 1 - test_apps/test_app/test/simple_storage_deploy_spec.js | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/tests/run_tests.js b/lib/tests/run_tests.js index baaedd0ba..eb31209ae 100644 --- a/lib/tests/run_tests.js +++ b/lib/tests/run_tests.js @@ -83,7 +83,6 @@ module.exports = { mocha.suite.timeout(0); mocha.suite.beforeAll('Wait for deploy', (done) => { - console.dir("runnning wait for deploy"); global.embark.onReady(() => { done(); }); diff --git a/test_apps/test_app/test/simple_storage_deploy_spec.js b/test_apps/test_app/test/simple_storage_deploy_spec.js index b44aa0643..b74acc33c 100644 --- a/test_apps/test_app/test/simple_storage_deploy_spec.js +++ b/test_apps/test_app/test/simple_storage_deploy_spec.js @@ -16,7 +16,7 @@ contract("SimpleStorage Deploy", function () { let SimpleStorageInstance; before(async function() { - SimpleStorageInstance = await SimpleStorage.deploy({data: SimpleStorage.options.data, arguments: [150]}).send(); + SimpleStorageInstance = await SimpleStorage.deploy({arguments: [150]}).send(); }); it("should set constructor value", async function () { From 402ee19722fc9da98c84c8b11ec51547f485e140 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Thu, 7 Jun 2018 20:09:07 -0400 Subject: [PATCH 4/7] default contracts fields --- lib/tests/test.js | 2 +- test_apps/test_app/test/simple_storage_deploy_spec.js | 8 +------- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/lib/tests/test.js b/lib/tests/test.js index 1e21442c6..aa0ea821b 100644 --- a/lib/tests/test.js +++ b/lib/tests/test.js @@ -126,7 +126,7 @@ class Test { }; } if (!options.contracts) { - throw new Error(__('No contracts specified in the options')); + options.contracts = {}; } self.ready = false; diff --git a/test_apps/test_app/test/simple_storage_deploy_spec.js b/test_apps/test_app/test/simple_storage_deploy_spec.js index b74acc33c..e4d24241c 100644 --- a/test_apps/test_app/test/simple_storage_deploy_spec.js +++ b/test_apps/test_app/test/simple_storage_deploy_spec.js @@ -2,13 +2,7 @@ const SimpleStorage = embark.require('Embark/contracts/SimpleStorage'); let accounts; -config({ - contracts: { - "SimpleStorage": { - args: [100] - } - } -}, (err, theAccounts) => { +config({}, (err, theAccounts) => { accounts = theAccounts; }); From edbbaa160bdfc58e7415d0bc37b18dbf79f07e4b Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Thu, 7 Jun 2018 20:11:49 -0400 Subject: [PATCH 5/7] make config params optional --- lib/tests/test.js | 4 ++++ test_apps/test_app/test/simple_storage_deploy_spec.js | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/tests/test.js b/lib/tests/test.js index aa0ea821b..4f9d10755 100644 --- a/lib/tests/test.js +++ b/lib/tests/test.js @@ -121,6 +121,10 @@ class Test { config(options, callback) { const self = this; + if (typeof(options) === 'function') { + callback = options; + options = {}; + } if (!callback) { callback = function () { }; diff --git a/test_apps/test_app/test/simple_storage_deploy_spec.js b/test_apps/test_app/test/simple_storage_deploy_spec.js index e4d24241c..0f814434d 100644 --- a/test_apps/test_app/test/simple_storage_deploy_spec.js +++ b/test_apps/test_app/test/simple_storage_deploy_spec.js @@ -2,7 +2,7 @@ const SimpleStorage = embark.require('Embark/contracts/SimpleStorage'); let accounts; -config({}, (err, theAccounts) => { +config((err, theAccounts) => { accounts = theAccounts; }); From 3db8ccd44e9bd73f0d330f203c6f83a1b7fa9b67 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Thu, 7 Jun 2018 20:13:50 -0400 Subject: [PATCH 6/7] remove unnecessary config --- test_apps/test_app/test/simple_storage_deploy_spec.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/test_apps/test_app/test/simple_storage_deploy_spec.js b/test_apps/test_app/test/simple_storage_deploy_spec.js index 0f814434d..c194dda60 100644 --- a/test_apps/test_app/test/simple_storage_deploy_spec.js +++ b/test_apps/test_app/test/simple_storage_deploy_spec.js @@ -2,10 +2,6 @@ const SimpleStorage = embark.require('Embark/contracts/SimpleStorage'); let accounts; -config((err, theAccounts) => { - accounts = theAccounts; -}); - contract("SimpleStorage Deploy", function () { let SimpleStorageInstance; From 46e085b01110f7212f50060a2effe49d2bdc543a Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Fri, 8 Jun 2018 09:40:23 -0400 Subject: [PATCH 7/7] lint is king --- lib/tests/test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/tests/test.js b/lib/tests/test.js index 4f9d10755..3dcfbf10c 100644 --- a/lib/tests/test.js +++ b/lib/tests/test.js @@ -121,7 +121,7 @@ class Test { config(options, callback) { const self = this; - if (typeof(options) === 'function') { + if (typeof (options) === 'function') { callback = options; options = {}; } @@ -226,7 +226,7 @@ class Test { {from: self.web3.eth.defaultAccount, gas: 6000000})); self.contracts[contractName].address = contract.deployedAddress; if (self.contracts[contractName].options) { - self.contracts[contractName].options.from = self.contracts[contractName].options.from || web3.eth.defaultAccount; + self.contracts[contractName].options.from = self.contracts[contractName].options.from || self.web3.eth.defaultAccount; self.contracts[contractName].options.data = data; } eachCb(); @@ -273,7 +273,7 @@ class Test { {from: this.web3.eth.defaultAccount, gas: 6000000}); this.contracts[contractName].address = contract.address; this.contracts[contractName].options.data = contract.code; - web3.eth.getAccounts().then((accounts) => { + this.web3.eth.getAccounts().then((accounts) => { this.contracts[contractName].options.from = contract.from || accounts[0]; }); return this.contracts[contractName];