support specifying a contract address
This commit is contained in:
parent
ea2a162d4b
commit
fe8b8e805e
|
@ -104,6 +104,7 @@ ContractsConfig.prototype.compileContracts = function(env) {
|
|||
contract.gasPrice = contractConfig.gas_price || contract.gasPrice;
|
||||
contract.gasLimit = contractConfig.gas_limit || contract.gasLimit;
|
||||
contract.args = contractConfig.args || [];
|
||||
contract.address = contractConfig.address;
|
||||
|
||||
if (contractConfig.instanceOf !== undefined) {
|
||||
contract.types.push('instance');
|
||||
|
|
|
@ -36,31 +36,39 @@ Deploy.prototype.deploy_contracts = function(env) {
|
|||
className = all_contracts[k];
|
||||
contract = this.contractDB[className];
|
||||
|
||||
contractObject = web3.eth.contract(contract.compiled.info.abiDefinition);
|
||||
if (contract.address !== undefined) {
|
||||
this.deployedContracts[className] = contract.address;
|
||||
|
||||
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);
|
||||
}
|
||||
console.log("contract " + className + " at " + contractAddress);
|
||||
}
|
||||
else {
|
||||
contractObject = web3.eth.contract(contract.compiled.info.abiDefinition);
|
||||
|
||||
contractParams = realArgs;
|
||||
contractParams.push({
|
||||
from: primaryAddress,
|
||||
data: contract.compiled.code,
|
||||
gas: contract.gasLimit,
|
||||
gasPrice: contract.gasPrice
|
||||
});
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
contractAddress = contractObject["new"].apply(contractObject, contractParams).address;
|
||||
this.deployedContracts[className] = contractAddress;
|
||||
contractParams = realArgs;
|
||||
contractParams.push({
|
||||
from: primaryAddress,
|
||||
data: contract.compiled.code,
|
||||
gas: contract.gasLimit,
|
||||
gasPrice: contract.gasPrice
|
||||
});
|
||||
|
||||
console.log("address is " + contractAddress);
|
||||
console.log("deployed " + className + " at " + contractAddress);
|
||||
contractAddress = contractObject["new"].apply(contractObject, contractParams).address;
|
||||
|
||||
this.deployedContracts[className] = contractAddress;
|
||||
|
||||
console.log("address is " + contractAddress);
|
||||
console.log("deployed " + className + " at " + contractAddress);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
@ -24,18 +24,17 @@ describe('embark.deploy', function() {
|
|||
'test/support/contracts/wallets.sol'
|
||||
];
|
||||
|
||||
var deploy = setDeployConfig({
|
||||
files: files,
|
||||
blockchain: 'test/support/blockchain.yml',
|
||||
contracts: 'test/support/arguments.yml'
|
||||
});
|
||||
|
||||
describe('#deploy_contracts', function() {
|
||||
var deploy = setDeployConfig({
|
||||
files: files,
|
||||
blockchain: 'test/support/blockchain.yml',
|
||||
contracts: 'test/support/arguments.yml'
|
||||
});
|
||||
deploy.deploy_contracts("development");
|
||||
|
||||
it("should deploy contracts", function() {
|
||||
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];
|
||||
|
||||
assert.equal(deploy.deployedContracts.hasOwnProperty(className), true);
|
||||
|
@ -45,6 +44,11 @@ describe('embark.deploy', function() {
|
|||
});
|
||||
|
||||
describe('#generate_abi_file', function() {
|
||||
var deploy = setDeployConfig({
|
||||
files: files,
|
||||
blockchain: 'test/support/blockchain.yml',
|
||||
contracts: 'test/support/arguments.yml'
|
||||
});
|
||||
deploy.deployedContracts = {
|
||||
"SimpleStorage": "0x123",
|
||||
"AnotherStorage": "0x234"
|
||||
|
@ -67,18 +71,17 @@ describe('embark.deploy', function() {
|
|||
'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() {
|
||||
var deploy = setDeployConfig({
|
||||
files: files,
|
||||
blockchain: 'test/support/blockchain.yml',
|
||||
contracts: 'test/support/instances.yml'
|
||||
});
|
||||
deploy.deploy_contracts("development");
|
||||
|
||||
it("should deploy contracts", function() {
|
||||
var all_contracts = ['Wallet', 'SimpleStorage', 'AnotherStorage', 'Wallets'];
|
||||
for(var i=0; i < all_contracts; i++) {
|
||||
var all_contracts = ['SimpleStorage', 'BarStorage', 'FooStorage'];
|
||||
for(var i=0; i < all_contracts.length; i++) {
|
||||
var className = all_contracts[i];
|
||||
|
||||
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');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
development:
|
||||
SimpleStorage:
|
||||
address: 0x123
|
||||
args:
|
||||
- 100
|
||||
BarStorage:
|
||||
address: 0x234
|
||||
instanceOf: SimpleStorage
|
||||
FooStorage:
|
||||
instanceOf: SimpleStorage
|
||||
args:
|
||||
- 200
|
||||
staging:
|
Loading…
Reference in New Issue