Merge pull request #1000 from embark-framework/bug_fix/self-dep

enable self-referencing contracts in onDeploy
This commit is contained in:
Eric Mastro 2018-10-31 10:29:57 +01:00 committed by GitHub
commit 000a4fe322
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 9 deletions

View File

@ -448,6 +448,10 @@ class ContractsManager {
return; return;
} }
cmd.replace(regex, (match) => { cmd.replace(regex, (match) => {
if (match.substring(1) === contract.className) {
// Contract self-referencing. In onDeploy, it should be available
return;
}
self.contractDependencies[className] = self.contractDependencies[className] || []; self.contractDependencies[className] = self.contractDependencies[className] || [];
self.contractDependencies[className].push(match.substr(1)); self.contractDependencies[className].push(match.substr(1));
}); });

View File

@ -7,7 +7,7 @@ config({
contracts: { contracts: {
"SimpleStorage": { "SimpleStorage": {
args: [100], args: [100],
onDeploy: ["SimpleStorage.methods.setRegistar(web3.eth.defaultAccount).send()"] onDeploy: ["SimpleStorage.methods.setRegistar('$SimpleStorage').send()"]
} }
} }
}, (err, theAccounts) => { }, (err, theAccounts) => {
@ -33,9 +33,12 @@ contract("SimpleStorage", function () {
}); });
}); });
it("should set defaultAccount", async function () { it("should set to self address", async function() {
let result = await SimpleStorage.methods.registar().call(); let result = await SimpleStorage.methods.registar().call();
assert.strictEqual(result, web3.eth.defaultAccount); assert.strictEqual(result, SimpleStorage.options.address);
});
it('should have the right defaultAccount', function() {
assert.strictEqual(accounts[0], web3.eth.defaultAccount); assert.strictEqual(accounts[0], web3.eth.defaultAccount);
}); });