mirror of https://github.com/embarklabs/embark.git
Merge pull request #521 from embark-framework/features/warn-when-using-not-deployed-contract
show warning if dependency is not deploying
This commit is contained in:
commit
aa9d19f27e
|
@ -225,12 +225,14 @@ class ContractsManager {
|
||||||
if (arg[0] === "$") {
|
if (arg[0] === "$") {
|
||||||
self.contractDependencies[className] = self.contractDependencies[className] || [];
|
self.contractDependencies[className] = self.contractDependencies[className] || [];
|
||||||
self.contractDependencies[className].push(arg.substr(1));
|
self.contractDependencies[className].push(arg.substr(1));
|
||||||
|
self.checkDependency(className, arg.substr(1));
|
||||||
}
|
}
|
||||||
if (Array.isArray(arg)) {
|
if (Array.isArray(arg)) {
|
||||||
for (let sub_arg of arg) {
|
for (let sub_arg of arg) {
|
||||||
if (sub_arg[0] === "$") {
|
if (sub_arg[0] === "$") {
|
||||||
self.contractDependencies[className] = self.contractDependencies[className] || [];
|
self.contractDependencies[className] = self.contractDependencies[className] || [];
|
||||||
self.contractDependencies[className].push(sub_arg.substr(1));
|
self.contractDependencies[className].push(sub_arg.substr(1));
|
||||||
|
self.checkDependency(className, sub_arg.substr(1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -259,6 +261,21 @@ class ContractsManager {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkDependency(className, dependencyName) {
|
||||||
|
if (!this.contractDependencies[className]) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!this.contracts[dependencyName]) {
|
||||||
|
this.logger.warn(__('{{className}} has a dependency on {{dependencyName}}', {className, dependencyName}) +
|
||||||
|
__(', but it is not present in the contracts'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!this.contracts[dependencyName].deploy) {
|
||||||
|
this.logger.warn(__('{{className}} has a dependency on {{dependencyName}}', {className, dependencyName}) +
|
||||||
|
__(', but it is not set to deploy. It could be an interface.'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
getContract(className) {
|
getContract(className) {
|
||||||
return this.contracts[className];
|
return this.contracts[className];
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,10 +44,4 @@ contract("AnotherStorage", function() {
|
||||||
let result = await AnotherStorage.simpleStorageAddress();
|
let result = await AnotherStorage.simpleStorageAddress();
|
||||||
assert.equal(result.toString(), SimpleStorage.options.address);
|
assert.equal(result.toString(), SimpleStorage.options.address);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should set the balance correctly', async function () {
|
|
||||||
const balance = await web3.eth.getBalance(accounts[0]);
|
|
||||||
assert.ok(balance < 5000000000000000000);
|
|
||||||
assert.ok(balance > 4000000000000000000);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
/*global contract, config, it*/
|
||||||
|
const assert = require('assert');
|
||||||
|
const AnotherStorage = require('Embark/contracts/AnotherStorage');
|
||||||
|
|
||||||
|
config({
|
||||||
|
contracts: {
|
||||||
|
AnotherStorage: {
|
||||||
|
args: ['$ERC20']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
contract("AnotherStorageWithInterface", function() {
|
||||||
|
this.timeout(0);
|
||||||
|
|
||||||
|
it("sets an empty address because ERC20 is an interface", async function() {
|
||||||
|
let result = await AnotherStorage.methods.simpleStorageAddress().call();
|
||||||
|
assert.equal(result.toString(), '0x0000000000000000000000000000000000000000');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
/*global contract, config, it, embark, assert, web3*/
|
/*global contract, it, embark, assert, before*/
|
||||||
const SimpleStorage = embark.require('Embark/contracts/SimpleStorage');
|
const SimpleStorage = embark.require('Embark/contracts/SimpleStorage');
|
||||||
let accounts;
|
|
||||||
|
|
||||||
contract("SimpleStorage Deploy", function () {
|
contract("SimpleStorage Deploy", function () {
|
||||||
let SimpleStorageInstance;
|
let SimpleStorageInstance;
|
||||||
|
|
Loading…
Reference in New Issue