mirror of https://github.com/embarklabs/embark.git
take into account contract args and classname when recording contract
This commit is contained in:
parent
d5d4cb81e3
commit
39840bbd7a
|
@ -36,15 +36,15 @@ ChainManager.prototype.init = function(env, config) {
|
|||
this.currentChain = this.chainManagerConfig[chainId];
|
||||
}
|
||||
|
||||
ChainManager.prototype.addContract = function(contractName, code, address) {
|
||||
this.currentChain.contracts[sha3_256(code)] = {
|
||||
ChainManager.prototype.addContract = function(contractName, code, args, address) {
|
||||
this.currentChain.contracts[sha3_256(code + contractName + args.join(','))] = {
|
||||
name: contractName,
|
||||
address: address
|
||||
}
|
||||
}
|
||||
|
||||
ChainManager.prototype.getContract = function(code) {
|
||||
return this.currentChain.contracts[sha3_256(code)];
|
||||
ChainManager.prototype.getContract = function(contractName, code, args) {
|
||||
return this.currentChain.contracts[sha3_256(code + contractName + args.join(','))];
|
||||
}
|
||||
|
||||
ChainManager.prototype.save = function() {
|
||||
|
|
|
@ -58,6 +58,15 @@ Deploy.prototype.deploy_contracts = function(env) {
|
|||
className = all_contracts[k];
|
||||
contract = this.contractDB[className];
|
||||
|
||||
var realArgs = [];
|
||||
for (var l = 0; l < contract.args.length; l++) {
|
||||
arg = contract.args[l];
|
||||
if (arg[0] === "$") {
|
||||
realArgs.push(this.deployedContracts[arg.substr(1)]);
|
||||
} else {
|
||||
realArgs.push(arg);
|
||||
}
|
||||
}
|
||||
|
||||
if (contract.address !== undefined) {
|
||||
this.deployedContracts[className] = contract.address;
|
||||
|
@ -66,7 +75,7 @@ Deploy.prototype.deploy_contracts = function(env) {
|
|||
console.log("contract " + className + " at " + contract.address);
|
||||
}
|
||||
else {
|
||||
var chainContract = this.chainManager.getContract(contract.compiled.code);
|
||||
var chainContract = this.chainManager.getContract(className, contract.compiled.code, realArgs);
|
||||
|
||||
if (chainContract != undefined) {
|
||||
console.log("contract " + className + " is unchanged and already deployed at " + chainContract.address);
|
||||
|
@ -77,17 +86,7 @@ Deploy.prototype.deploy_contracts = function(env) {
|
|||
|
||||
contractObject = web3.eth.contract(contract.compiled.info.abiDefinition);
|
||||
|
||||
realArgs = [];
|
||||
for (var l = 0; l < contract.args.length; l++) {
|
||||
arg = contract.args[l];
|
||||
if (arg[0] === "$") {
|
||||
realArgs.push(this.deployedContracts[arg.substr(1)]);
|
||||
} else {
|
||||
realArgs.push(arg);
|
||||
}
|
||||
}
|
||||
|
||||
contractParams = realArgs;
|
||||
contractParams = realArgs.slice();
|
||||
contractParams.push({
|
||||
from: primaryAddress,
|
||||
data: contract.compiled.code,
|
||||
|
@ -114,7 +113,7 @@ Deploy.prototype.deploy_contracts = function(env) {
|
|||
}
|
||||
|
||||
this.deployedContracts[className] = contractAddress;
|
||||
this.chainManager.addContract(className, contract.compiled.code, contractAddress);
|
||||
this.chainManager.addContract(className, contract.compiled.code, realArgs, contractAddress);
|
||||
this.chainManager.save();
|
||||
|
||||
console.log("deployed " + className + " at " + contractAddress);
|
||||
|
|
|
@ -15,7 +15,7 @@ describe('embark.chain_manager', function() {
|
|||
chainManager.init('development', blockchainConfig);
|
||||
|
||||
it('should initialize chain', function() {
|
||||
var chain = chainManager.chainManagerConfig['0x629e768beb87dc8c54a475d310a7196e86c97d0006e5a6d34a8217726c90223f']
|
||||
var chain = chainManager.chainManagerConfig['0xcd9c11da1e46f86ce40a38b6ef84cfdfa6ea92598a27538f0e87da6d7a5c73d5']
|
||||
assert.equal(chain != undefined, true);
|
||||
});
|
||||
});
|
||||
|
@ -23,10 +23,11 @@ describe('embark.chain_manager', function() {
|
|||
describe('#addContract', function() {
|
||||
|
||||
it('should register a contract in the chain', function() {
|
||||
chainManager.addContract("Foo", "123456", "0x123");
|
||||
chainManager.addContract("Foo", "123456", [], "0x123");
|
||||
|
||||
var chain = chainManager.chainManagerConfig['0x629e768beb87dc8c54a475d310a7196e86c97d0006e5a6d34a8217726c90223f']
|
||||
var contract = chain.contracts["d7190eb194ff9494625514b6d178c87f99c5973e28c398969d2233f2960a573e"]
|
||||
console.log(chainManager.chainManagerConfig);
|
||||
var chain = chainManager.chainManagerConfig['0xcd9c11da1e46f86ce40a38b6ef84cfdfa6ea92598a27538f0e87da6d7a5c73d5']
|
||||
var contract = chain.contracts["d5d91a8825c5c253dff531ddda2354c4014f5699b7bcbea70207cfdcb37b6c8b"]
|
||||
|
||||
assert.equal(contract.name, "Foo");
|
||||
assert.equal(contract.address, "0x123");
|
||||
|
@ -37,7 +38,7 @@ describe('embark.chain_manager', function() {
|
|||
describe('#getContract', function() {
|
||||
|
||||
it('should a contract in the chain', function() {
|
||||
var contract = chainManager.getContract("123456");
|
||||
var contract = chainManager.getContract("Foo", "123456", []);
|
||||
|
||||
assert.equal(contract.name, "Foo");
|
||||
assert.equal(contract.address, "0x123");
|
||||
|
@ -52,7 +53,7 @@ describe('embark.chain_manager', function() {
|
|||
|
||||
var chainFile = './test/support/chain_manager.json';
|
||||
var content = fs.readFileSync(chainFile).toString();
|
||||
assert.equal(content, '{"0x629e768beb87dc8c54a475d310a7196e86c97d0006e5a6d34a8217726c90223f":{"contracts":{"d7190eb194ff9494625514b6d178c87f99c5973e28c398969d2233f2960a573e":{"name":"Foo","address":"0x123"}}}}');
|
||||
assert.equal(content, '{"0xcd9c11da1e46f86ce40a38b6ef84cfdfa6ea92598a27538f0e87da6d7a5c73d5":{"contracts":{"d5d91a8825c5c253dff531ddda2354c4014f5699b7bcbea70207cfdcb37b6c8b\":{"name":"Foo","address":"0x123"}}}}');
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
var Config = require('../lib/config/config.js');
|
||||
var Deploy = require('../lib/deploy.js');
|
||||
var Compiler = require('../lib/compiler.js');
|
||||
var ChainManager = require('../lib/chain_manager.js');
|
||||
var assert = require('assert');
|
||||
var web3 = require('web3');
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"0x629e768beb87dc8c54a475d310a7196e86c97d0006e5a6d34a8217726c90223f":{"contracts":{"d7190eb194ff9494625514b6d178c87f99c5973e28c398969d2233f2960a573e":{"name":"Foo","address":"0x123"}}}}
|
||||
{"0xcd9c11da1e46f86ce40a38b6ef84cfdfa6ea92598a27538f0e87da6d7a5c73d5":{"contracts":{"d5d91a8825c5c253dff531ddda2354c4014f5699b7bcbea70207cfdcb37b6c8b":{"name":"Foo","address":"0x123"}}}}
|
Loading…
Reference in New Issue