support specifying a contract address

This commit is contained in:
Iuri Matias 2015-07-06 08:19:25 -04:00
parent ea2a162d4b
commit fe8b8e805e
4 changed files with 90 additions and 35 deletions

View File

@ -104,6 +104,7 @@ ContractsConfig.prototype.compileContracts = function(env) {
contract.gasPrice = contractConfig.gas_price || contract.gasPrice; contract.gasPrice = contractConfig.gas_price || contract.gasPrice;
contract.gasLimit = contractConfig.gas_limit || contract.gasLimit; contract.gasLimit = contractConfig.gas_limit || contract.gasLimit;
contract.args = contractConfig.args || []; contract.args = contractConfig.args || [];
contract.address = contractConfig.address;
if (contractConfig.instanceOf !== undefined) { if (contractConfig.instanceOf !== undefined) {
contract.types.push('instance'); contract.types.push('instance');

View File

@ -36,31 +36,39 @@ Deploy.prototype.deploy_contracts = function(env) {
className = all_contracts[k]; className = all_contracts[k];
contract = this.contractDB[className]; contract = this.contractDB[className];
contractObject = web3.eth.contract(contract.compiled.info.abiDefinition); if (contract.address !== undefined) {
this.deployedContracts[className] = contract.address;
realArgs = []; console.log("contract " + className + " at " + contractAddress);
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);
}
} }
else {
contractObject = web3.eth.contract(contract.compiled.info.abiDefinition);
contractParams = realArgs; realArgs = [];
contractParams.push({ for (var l = 0; l < contract.args.length; l++) {
from: primaryAddress, arg = contract.args[l];
data: contract.compiled.code, if (arg[0] === "$") {
gas: contract.gasLimit, realArgs.push(this.deployedContracts[arg.substr(1)]);
gasPrice: contract.gasPrice } else {
}); realArgs.push(arg);
}
}
contractAddress = contractObject["new"].apply(contractObject, contractParams).address; contractParams = realArgs;
this.deployedContracts[className] = contractAddress; contractParams.push({
from: primaryAddress,
data: contract.compiled.code,
gas: contract.gasLimit,
gasPrice: contract.gasPrice
});
console.log("address is " + contractAddress); contractAddress = contractObject["new"].apply(contractObject, contractParams).address;
console.log("deployed " + className + " at " + contractAddress);
this.deployedContracts[className] = contractAddress;
console.log("address is " + contractAddress);
console.log("deployed " + className + " at " + contractAddress);
}
} }
}; };

View File

@ -24,18 +24,17 @@ describe('embark.deploy', function() {
'test/support/contracts/wallets.sol' 'test/support/contracts/wallets.sol'
]; ];
var deploy = setDeployConfig({
files: files,
blockchain: 'test/support/blockchain.yml',
contracts: 'test/support/arguments.yml'
});
describe('#deploy_contracts', function() { describe('#deploy_contracts', function() {
var deploy = setDeployConfig({
files: files,
blockchain: 'test/support/blockchain.yml',
contracts: 'test/support/arguments.yml'
});
deploy.deploy_contracts("development"); deploy.deploy_contracts("development");
it("should deploy contracts", function() { it("should deploy contracts", function() {
var all_contracts = ['Wallet', 'SimpleStorage', 'AnotherStorage', 'Wallets']; var all_contracts = ['Wallet', 'SimpleStorage', 'AnotherStorage', 'Wallets'];
for(var i=0; i < all_contracts; i++) { for(var i=0; i < all_contracts.length; i++) {
var className = all_contracts[i]; var className = all_contracts[i];
assert.equal(deploy.deployedContracts.hasOwnProperty(className), true); assert.equal(deploy.deployedContracts.hasOwnProperty(className), true);
@ -45,6 +44,11 @@ describe('embark.deploy', function() {
}); });
describe('#generate_abi_file', function() { describe('#generate_abi_file', function() {
var deploy = setDeployConfig({
files: files,
blockchain: 'test/support/blockchain.yml',
contracts: 'test/support/arguments.yml'
});
deploy.deployedContracts = { deploy.deployedContracts = {
"SimpleStorage": "0x123", "SimpleStorage": "0x123",
"AnotherStorage": "0x234" "AnotherStorage": "0x234"
@ -67,18 +71,17 @@ describe('embark.deploy', function() {
'test/support/contracts/simple_storage.sol' 'test/support/contracts/simple_storage.sol'
]; ];
var deploy = setDeployConfig({
files: files,
blockchain: 'test/support/blockchain.yml',
contracts: 'test/support/instances.yml'
});
describe('#deploy_contracts', function() { describe('#deploy_contracts', function() {
var deploy = setDeployConfig({
files: files,
blockchain: 'test/support/blockchain.yml',
contracts: 'test/support/instances.yml'
});
deploy.deploy_contracts("development"); deploy.deploy_contracts("development");
it("should deploy contracts", function() { it("should deploy contracts", function() {
var all_contracts = ['Wallet', 'SimpleStorage', 'AnotherStorage', 'Wallets']; var all_contracts = ['SimpleStorage', 'BarStorage', 'FooStorage'];
for(var i=0; i < all_contracts; i++) { for(var i=0; i < all_contracts.length; i++) {
var className = all_contracts[i]; var className = all_contracts[i];
assert.equal(deploy.deployedContracts.hasOwnProperty(className), true); assert.equal(deploy.deployedContracts.hasOwnProperty(className), true);
@ -89,4 +92,34 @@ describe('embark.deploy', function() {
}); });
describe('contracts with addresses defined', function() {
var files = [
'test/support/contracts/simple_storage.sol'
];
describe('#deploy_contracts', function() {
var deploy = setDeployConfig({
files: files,
blockchain: 'test/support/blockchain.yml',
contracts: 'test/support/address.yml'
});
deploy.deploy_contracts("development");
it("should not deploy contracts with addresses defined", function() {
var expected_deploys = ['SimpleStorage', 'BarStorage', 'FooStorage'];
for(var i=0; i < expected_deploys.length; i++) {
var className = expected_deploys[i];
assert.equal(deploy.deployedContracts.hasOwnProperty(className), true);
}
assert.equal(deploy.deployedContracts['SimpleStorage'], '0x123');
assert.equal(deploy.deployedContracts['BarStorage'], '0x234');
});
});
});
}); });

13
test/support/address.yml Normal file
View File

@ -0,0 +1,13 @@
development:
SimpleStorage:
address: 0x123
args:
- 100
BarStorage:
address: 0x234
instanceOf: SimpleStorage
FooStorage:
instanceOf: SimpleStorage
args:
- 200
staging: