use object assign to assign new values to contract

This commit is contained in:
Jonathan Rainville 2018-05-30 08:55:34 -04:00
parent 1176a2e8be
commit 641a77c2dc
2 changed files with 7 additions and 15 deletions

View File

@ -88,12 +88,6 @@ class Test {
next(); next();
}, },
function deploy(next) { function deploy(next) {
// self.engine.events.on('code-generator-ready', function () {
// self.engine.events.request('code-generator:contract:vanilla', function(vanillaABI) {
// console.log(vanillaABI);
// });
// });
self.engine.deployManager.gasLimit = 6000000; self.engine.deployManager.gasLimit = 6000000;
self.engine.contractsManager.gasLimit = 6000000; self.engine.contractsManager.gasLimit = 6000000;
self.engine.deployManager.fatalErrors = true; self.engine.deployManager.fatalErrors = true;
@ -106,7 +100,7 @@ class Test {
}); });
}, },
function getAccounts(next) { function getAccounts(next) {
self.web3.eth.getAccounts(function(err, accounts) { self.web3.eth.getAccounts(function (err, accounts) {
if (err) { if (err) {
return next(err); return next(err);
} }
@ -118,8 +112,8 @@ class Test {
function createContractObject(next) { function createContractObject(next) {
async.each(Object.keys(self.contracts), (contractName, eachCb) => { async.each(Object.keys(self.contracts), (contractName, eachCb) => {
const contract = self.engine.contractsManager.contracts[contractName]; const contract = self.engine.contractsManager.contracts[contractName];
self.contracts[contractName].contract = new self.web3.eth.Contract(contract.abiDefinition, contract.address, Object.assign(self.contracts[contractName], new self.web3.eth.Contract(contract.abiDefinition, contract.address,
{from: self.web3.defaultAccount, gas: 6000000}); {from: self.web3.defaultAccount, gas: 6000000}));
eachCb(); eachCb();
}, next); }, next);
} }
@ -142,9 +136,7 @@ class Test {
return this.contracts[contractName]; return this.contracts[contractName];
} }
const contract = this.engine.contractsManager.contracts[contractName]; const contract = this.engine.contractsManager.contracts[contractName];
this.contracts[contractName] = {}; this.contracts[contractName] = new this.web3.eth.Contract(contract.abiDefinition, contract.address);
// TODO find better way to update contract
this.contracts[contractName].contract = new this.web3.eth.Contract(contract.abiDefinition, contract.address);
return this.contracts[contractName]; return this.contracts[contractName];
} }
throw new Error(__('Unknown module %s', module)); throw new Error(__('Unknown module %s', module));

View File

@ -19,14 +19,14 @@ contract("SimpleStorage", function () {
}); });
it("should set constructor value", async function () { it("should set constructor value", async function () {
let result = await SimpleStorage.contract.methods.storedData().call(); let result = await SimpleStorage.methods.storedData().call();
assert.strictEqual(parseInt(result, 10), 100); assert.strictEqual(parseInt(result, 10), 100);
}); });
it("set storage value", async function () { it("set storage value", async function () {
// TODO Solve from // TODO Solve from
await SimpleStorage.contract.methods.set(150).send({from: web3.eth.defaultAccount}); await SimpleStorage.methods.set(150).send({from: web3.eth.defaultAccount});
let result = await SimpleStorage.contract.methods.get().call(); let result = await SimpleStorage.methods.get().call();
assert.strictEqual(parseInt(result, 10), 499650); assert.strictEqual(parseInt(result, 10), 499650);
}); });