mirror of https://github.com/embarklabs/embark.git
Merge pull request #1000 from embark-framework/bug_fix/self-dep
enable self-referencing contracts in onDeploy
This commit is contained in:
commit
000a4fe322
|
@ -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));
|
||||||
});
|
});
|
||||||
|
|
|
@ -7,22 +7,22 @@ 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) => {
|
||||||
accounts = theAccounts;
|
accounts = theAccounts;
|
||||||
});
|
});
|
||||||
|
|
||||||
contract("SimpleStorage", function () {
|
contract("SimpleStorage", function() {
|
||||||
this.timeout(0);
|
this.timeout(0);
|
||||||
|
|
||||||
it("should set constructor value", async function () {
|
it("should set constructor value", async function() {
|
||||||
let result = await SimpleStorage.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", function (done) {
|
it("set storage value", function(done) {
|
||||||
Utils.secureSend(web3, SimpleStorage.methods.set(150), {}, false, async function(err) {
|
Utils.secureSend(web3, SimpleStorage.methods.set(150), {}, false, async function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return done(err);
|
return done(err);
|
||||||
|
@ -33,18 +33,21 @@ 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);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should alias contract address", function () {
|
it("should alias contract address", function() {
|
||||||
assert.strictEqual(SimpleStorage.options.address, SimpleStorage.address);
|
assert.strictEqual(SimpleStorage.options.address, SimpleStorage.address);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('listens to events', function (done) {
|
it('listens to events', function(done) {
|
||||||
SimpleStorage.once('EventOnSet2', async function (error, _result) {
|
SimpleStorage.once('EventOnSet2', async function(error, _result) {
|
||||||
assert.strictEqual(error, null);
|
assert.strictEqual(error, null);
|
||||||
let result = await SimpleStorage.methods.get().call();
|
let result = await SimpleStorage.methods.get().call();
|
||||||
assert.strictEqual(parseInt(result, 10), 150);
|
assert.strictEqual(parseInt(result, 10), 150);
|
||||||
|
|
Loading…
Reference in New Issue