fix contract creation defaults; add test for contract instances
This commit is contained in:
parent
5d9f7f32da
commit
ea2a162d4b
|
@ -77,35 +77,38 @@ ContractsConfig.prototype.compileContracts = function(env) {
|
||||||
this.contractDB[className] = {
|
this.contractDB[className] = {
|
||||||
args: [],
|
args: [],
|
||||||
types: ['file'],
|
types: ['file'],
|
||||||
gasPrice: this.blockchainConfig.gas_price,
|
gasPrice: this.blockchainConfig.gasPrice,
|
||||||
gasLimit: this.blockchainConfig.gas_limit,
|
gasLimit: this.blockchainConfig.gasLimit,
|
||||||
compiled: contract
|
compiled: contract
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: move this
|
// TODO: move this
|
||||||
// determine full contract list
|
|
||||||
|
|
||||||
// will be a combination between compiled contracts and the ones in config
|
|
||||||
|
|
||||||
for(className in contractsConfig) {
|
for(className in contractsConfig) {
|
||||||
var contractConfig = contractsConfig[className];
|
var contractConfig = contractsConfig[className];
|
||||||
|
|
||||||
var contract;
|
var contract;
|
||||||
contract = this.contractDB[className];
|
contract = this.contractDB[className];
|
||||||
if (contract === undefined) {
|
if (contract === undefined) {
|
||||||
contract = {};
|
contract = {
|
||||||
|
args: [],
|
||||||
|
types: ['file'],
|
||||||
|
gasPrice: this.blockchainConfig.gasPrice,
|
||||||
|
gasLimit: this.blockchainConfig.gasLimit,
|
||||||
|
compiled: contract
|
||||||
|
}
|
||||||
this.contractDB[className] = contract;
|
this.contractDB[className] = contract;
|
||||||
}
|
}
|
||||||
|
|
||||||
contract.gasPrice = contract.gasPrice || contractConfig.gas_price;
|
contract.gasPrice = contractConfig.gas_price || contract.gasPrice;
|
||||||
contract.gasLimit = contract.gasLimit || contractConfig.gas_limit;
|
contract.gasLimit = contractConfig.gas_limit || contract.gasLimit;
|
||||||
contract.args = contractConfig.args;
|
contract.args = contractConfig.args || [];
|
||||||
|
|
||||||
if (contractConfig.instanceOf === undefined) {
|
if (contractConfig.instanceOf !== undefined) {
|
||||||
contract.types.push('instance');
|
contract.types.push('instance');
|
||||||
contract.instanceOf = contractConfig.instanceOf;
|
contract.instanceOf = contractConfig.instanceOf;
|
||||||
|
contract.compiled = all_compiled_contracts[contractConfig.instanceOf];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.all_contracts.indexOf(className) < 0) {
|
if (this.all_contracts.indexOf(className) < 0) {
|
||||||
|
|
|
@ -3,23 +3,34 @@ var Deploy = require('../lib/deploy.js');
|
||||||
var Compiler = require('../lib/compiler.js');
|
var Compiler = require('../lib/compiler.js');
|
||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
|
|
||||||
|
setDeployConfig = function(config) {
|
||||||
|
var _blockchainConfig = (new Config.Blockchain()).loadConfigFile(config.blockchain);
|
||||||
|
var blockchainConfig = _blockchainConfig.config("development");
|
||||||
|
var compiler = new Compiler(_blockchainConfig);
|
||||||
|
var contractsConfig = new Config.Contracts(blockchainConfig, compiler);
|
||||||
|
contractsConfig.loadConfigFile(config.contracts);
|
||||||
|
contractsConfig.init(config.files);
|
||||||
|
compiler.init('development');
|
||||||
|
return new Deploy('development', config.files, blockchainConfig, contractsConfig);
|
||||||
|
}
|
||||||
|
|
||||||
describe('embark.deploy', function() {
|
describe('embark.deploy', function() {
|
||||||
|
|
||||||
|
describe('contracts as arguments to other contracts', function() {
|
||||||
var files = [
|
var files = [
|
||||||
'test/support/contracts/wallet.sol',
|
'test/support/contracts/wallet.sol',
|
||||||
'test/support/contracts/simple_storage.sol',
|
'test/support/contracts/simple_storage.sol',
|
||||||
'test/support/contracts/another_storage.sol',
|
'test/support/contracts/another_storage.sol',
|
||||||
'test/support/contracts/wallets.sol'
|
'test/support/contracts/wallets.sol'
|
||||||
];
|
];
|
||||||
var _blockchainConfig = (new Config.Blockchain()).loadConfigFile('test/support/blockchain.yml');
|
|
||||||
var blockchainConfig = _blockchainConfig.config("development");
|
var deploy = setDeployConfig({
|
||||||
var compiler = new Compiler(_blockchainConfig);
|
files: files,
|
||||||
var contractsConfig = new Config.Contracts(blockchainConfig, compiler);
|
blockchain: 'test/support/blockchain.yml',
|
||||||
contractsConfig.loadConfigFile('test/support/arguments.yml');
|
contracts: 'test/support/arguments.yml'
|
||||||
contractsConfig.init(files);
|
});
|
||||||
var deploy = new Deploy('development', files, blockchainConfig, contractsConfig);
|
|
||||||
|
|
||||||
describe('#deploy_contracts', function() {
|
describe('#deploy_contracts', function() {
|
||||||
compiler.init('development');
|
|
||||||
deploy.deploy_contracts("development");
|
deploy.deploy_contracts("development");
|
||||||
|
|
||||||
it("should deploy contracts", function() {
|
it("should deploy contracts", function() {
|
||||||
|
@ -44,11 +55,38 @@ describe('embark.deploy', function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
it("should deploy contracts", function() {
|
it("should deploy contracts", function() {
|
||||||
compiler.init('development');
|
|
||||||
var result = deploy.generate_abi_file();
|
var result = deploy.generate_abi_file();
|
||||||
|
|
||||||
assert.strictEqual(result, "web3.setProvider(new web3.providers.HttpProvider('http://localhost:8101'));web3.eth.defaultAccount = web3.eth.accounts[0];var SimpleStorageAbi = 123;var SimpleStorageContract = web3.eth.contract(SimpleStorageAbi);var SimpleStorage = SimpleStorageContract.at('0x123');var AnotherStorageAbi = 234;var AnotherStorageContract = web3.eth.contract(AnotherStorageAbi);var AnotherStorage = AnotherStorageContract.at('0x234');");
|
assert.strictEqual(result, "web3.setProvider(new web3.providers.HttpProvider('http://localhost:8101'));web3.eth.defaultAccount = web3.eth.accounts[0];var SimpleStorageAbi = 123;var SimpleStorageContract = web3.eth.contract(SimpleStorageAbi);var SimpleStorage = SimpleStorageContract.at('0x123');var AnotherStorageAbi = 234;var AnotherStorageContract = web3.eth.contract(AnotherStorageAbi);var AnotherStorage = AnotherStorageContract.at('0x234');");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('contracts instances', function() {
|
||||||
|
var files = [
|
||||||
|
'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() {
|
||||||
|
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 className = all_contracts[i];
|
||||||
|
|
||||||
|
assert.equal(deploy.deployedContracts.hasOwnProperty(className), true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue