mirror of https://github.com/embarklabs/embark.git
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) {
|
||||||
|
|
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 Compiler = require('../lib/compiler.js');
|
||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
|
|
||||||
describe('embark.deploy', function() {
|
setDeployConfig = function(config) {
|
||||||
var files = [
|
var _blockchainConfig = (new Config.Blockchain()).loadConfigFile(config.blockchain);
|
||||||
'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');
|
|
||||||
var blockchainConfig = _blockchainConfig.config("development");
|
var blockchainConfig = _blockchainConfig.config("development");
|
||||||
var compiler = new Compiler(_blockchainConfig);
|
var compiler = new Compiler(_blockchainConfig);
|
||||||
var contractsConfig = new Config.Contracts(blockchainConfig, compiler);
|
var contractsConfig = new Config.Contracts(blockchainConfig, compiler);
|
||||||
contractsConfig.loadConfigFile('test/support/arguments.yml');
|
contractsConfig.loadConfigFile(config.contracts);
|
||||||
contractsConfig.init(files);
|
contractsConfig.init(config.files);
|
||||||
var deploy = new Deploy('development', files, blockchainConfig, contractsConfig);
|
compiler.init('development');
|
||||||
|
return new Deploy('development', config.files, blockchainConfig, contractsConfig);
|
||||||
|
}
|
||||||
|
|
||||||
describe('#deploy_contracts', function() {
|
describe('embark.deploy', function() {
|
||||||
compiler.init('development');
|
|
||||||
deploy.deploy_contracts("development");
|
|
||||||
|
|
||||||
it("should deploy contracts", function() {
|
describe('contracts as arguments to other contracts', function() {
|
||||||
var all_contracts = ['Wallet', 'SimpleStorage', 'AnotherStorage', 'Wallets'];
|
var files = [
|
||||||
for(var i=0; i < all_contracts; i++) {
|
'test/support/contracts/wallet.sol',
|
||||||
var className = all_contracts[i];
|
'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() {
|
describe('contracts instances', function() {
|
||||||
deploy.deployedContracts = {
|
var files = [
|
||||||
"SimpleStorage": "0x123",
|
'test/support/contracts/simple_storage.sol'
|
||||||
"AnotherStorage": "0x234"
|
];
|
||||||
}
|
|
||||||
deploy.contractDB = {
|
|
||||||
"SimpleStorage": {compiled: {info: {abiDefinition: 123}}},
|
|
||||||
"AnotherStorage": {compiled: {info: {abiDefinition: 234}}}
|
|
||||||
}
|
|
||||||
|
|
||||||
it("should deploy contracts", function() {
|
var deploy = setDeployConfig({
|
||||||
compiler.init('development');
|
files: files,
|
||||||
var result = deploy.generate_abi_file();
|
blockchain: 'test/support/blockchain.yml',
|
||||||
|
contracts: 'test/support/instances.yml'
|
||||||
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('#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