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] = {
|
||||
args: [],
|
||||
types: ['file'],
|
||||
gasPrice: this.blockchainConfig.gas_price,
|
||||
gasLimit: this.blockchainConfig.gas_limit,
|
||||
gasPrice: this.blockchainConfig.gasPrice,
|
||||
gasLimit: this.blockchainConfig.gasLimit,
|
||||
compiled: contract
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: move this
|
||||
// determine full contract list
|
||||
|
||||
// will be a combination between compiled contracts and the ones in config
|
||||
|
||||
for(className in contractsConfig) {
|
||||
var contractConfig = contractsConfig[className];
|
||||
|
||||
var contract;
|
||||
contract = this.contractDB[className];
|
||||
if (contract === undefined) {
|
||||
contract = {};
|
||||
contract = {
|
||||
args: [],
|
||||
types: ['file'],
|
||||
gasPrice: this.blockchainConfig.gasPrice,
|
||||
gasLimit: this.blockchainConfig.gasLimit,
|
||||
compiled: contract
|
||||
}
|
||||
this.contractDB[className] = contract;
|
||||
}
|
||||
|
||||
contract.gasPrice = contract.gasPrice || contractConfig.gas_price;
|
||||
contract.gasLimit = contract.gasLimit || contractConfig.gas_limit;
|
||||
contract.args = contractConfig.args;
|
||||
contract.gasPrice = contractConfig.gas_price || contract.gasPrice;
|
||||
contract.gasLimit = contractConfig.gas_limit || contract.gasLimit;
|
||||
contract.args = contractConfig.args || [];
|
||||
|
||||
if (contractConfig.instanceOf === undefined) {
|
||||
if (contractConfig.instanceOf !== undefined) {
|
||||
contract.types.push('instance');
|
||||
contract.instanceOf = contractConfig.instanceOf;
|
||||
contract.compiled = all_compiled_contracts[contractConfig.instanceOf];
|
||||
}
|
||||
|
||||
if (this.all_contracts.indexOf(className) < 0) {
|
||||
|
|
106
test/deploy.js
106
test/deploy.js
|
@ -3,52 +3,90 @@ var Deploy = require('../lib/deploy.js');
|
|||
var Compiler = require('../lib/compiler.js');
|
||||
var assert = require('assert');
|
||||
|
||||
describe('embark.deploy', function() {
|
||||
var files = [
|
||||
'test/support/contracts/wallet.sol',
|
||||
'test/support/contracts/simple_storage.sol',
|
||||
'test/support/contracts/another_storage.sol',
|
||||
'test/support/contracts/wallets.sol'
|
||||
];
|
||||
var _blockchainConfig = (new Config.Blockchain()).loadConfigFile('test/support/blockchain.yml');
|
||||
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('test/support/arguments.yml');
|
||||
contractsConfig.init(files);
|
||||
var deploy = new Deploy('development', files, blockchainConfig, contractsConfig);
|
||||
contractsConfig.loadConfigFile(config.contracts);
|
||||
contractsConfig.init(config.files);
|
||||
compiler.init('development');
|
||||
return new Deploy('development', config.files, blockchainConfig, contractsConfig);
|
||||
}
|
||||
|
||||
describe('#deploy_contracts', function() {
|
||||
compiler.init('development');
|
||||
deploy.deploy_contracts("development");
|
||||
describe('embark.deploy', function() {
|
||||
|
||||
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];
|
||||
describe('contracts as arguments to other contracts', function() {
|
||||
var files = [
|
||||
'test/support/contracts/wallet.sol',
|
||||
'test/support/contracts/simple_storage.sol',
|
||||
'test/support/contracts/another_storage.sol',
|
||||
'test/support/contracts/wallets.sol'
|
||||
];
|
||||
|
||||
assert.equal(deploy.deployedContracts.hasOwnProperty(className), true);
|
||||
}
|
||||
var deploy = setDeployConfig({
|
||||
files: files,
|
||||
blockchain: 'test/support/blockchain.yml',
|
||||
contracts: 'test/support/arguments.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);
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#generate_abi_file', function() {
|
||||
deploy.deployedContracts = {
|
||||
"SimpleStorage": "0x123",
|
||||
"AnotherStorage": "0x234"
|
||||
}
|
||||
deploy.contractDB = {
|
||||
"SimpleStorage": {compiled: {info: {abiDefinition: 123}}},
|
||||
"AnotherStorage": {compiled: {info: {abiDefinition: 234}}}
|
||||
}
|
||||
|
||||
it("should deploy contracts", function() {
|
||||
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');");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#generate_abi_file', function() {
|
||||
deploy.deployedContracts = {
|
||||
"SimpleStorage": "0x123",
|
||||
"AnotherStorage": "0x234"
|
||||
}
|
||||
deploy.contractDB = {
|
||||
"SimpleStorage": {compiled: {info: {abiDefinition: 123}}},
|
||||
"AnotherStorage": {compiled: {info: {abiDefinition: 234}}}
|
||||
}
|
||||
describe('contracts instances', function() {
|
||||
var files = [
|
||||
'test/support/contracts/simple_storage.sol'
|
||||
];
|
||||
|
||||
it("should deploy contracts", function() {
|
||||
compiler.init('development');
|
||||
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');");
|
||||
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