From 8fa7357d07aff8b9b2cb7116a9243d443e89260b Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Thu, 7 Jun 2018 19:08:18 -0400 Subject: [PATCH] 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); + }); + +});