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.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');
|
||||||
|
|
|
@ -36,6 +36,12 @@ Deploy.prototype.deploy_contracts = function(env) {
|
||||||
className = all_contracts[k];
|
className = all_contracts[k];
|
||||||
contract = this.contractDB[className];
|
contract = this.contractDB[className];
|
||||||
|
|
||||||
|
if (contract.address !== undefined) {
|
||||||
|
this.deployedContracts[className] = contract.address;
|
||||||
|
|
||||||
|
console.log("contract " + className + " at " + contractAddress);
|
||||||
|
}
|
||||||
|
else {
|
||||||
contractObject = web3.eth.contract(contract.compiled.info.abiDefinition);
|
contractObject = web3.eth.contract(contract.compiled.info.abiDefinition);
|
||||||
|
|
||||||
realArgs = [];
|
realArgs = [];
|
||||||
|
@ -57,11 +63,13 @@ Deploy.prototype.deploy_contracts = function(env) {
|
||||||
});
|
});
|
||||||
|
|
||||||
contractAddress = contractObject["new"].apply(contractObject, contractParams).address;
|
contractAddress = contractObject["new"].apply(contractObject, contractParams).address;
|
||||||
|
|
||||||
this.deployedContracts[className] = contractAddress;
|
this.deployedContracts[className] = contractAddress;
|
||||||
|
|
||||||
console.log("address is " + contractAddress);
|
console.log("address is " + contractAddress);
|
||||||
console.log("deployed " + className + " at " + contractAddress);
|
console.log("deployed " + className + " at " + contractAddress);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -24,18 +24,17 @@ describe('embark.deploy', function() {
|
||||||
'test/support/contracts/wallets.sol'
|
'test/support/contracts/wallets.sol'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
describe('#deploy_contracts', function() {
|
||||||
var deploy = setDeployConfig({
|
var deploy = setDeployConfig({
|
||||||
files: files,
|
files: files,
|
||||||
blockchain: 'test/support/blockchain.yml',
|
blockchain: 'test/support/blockchain.yml',
|
||||||
contracts: 'test/support/arguments.yml'
|
contracts: 'test/support/arguments.yml'
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#deploy_contracts', function() {
|
|
||||||
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'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
describe('#deploy_contracts', function() {
|
||||||
var deploy = setDeployConfig({
|
var deploy = setDeployConfig({
|
||||||
files: files,
|
files: files,
|
||||||
blockchain: 'test/support/blockchain.yml',
|
blockchain: 'test/support/blockchain.yml',
|
||||||
contracts: 'test/support/instances.yml'
|
contracts: 'test/support/instances.yml'
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#deploy_contracts', function() {
|
|
||||||
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');
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -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