2015-07-03 08:59:33 +00:00
|
|
|
var Config = require('../lib/config/config.js');
|
|
|
|
var Deploy = require('../lib/deploy.js');
|
2015-07-04 03:23:21 +00:00
|
|
|
var Compiler = require('../lib/compiler.js');
|
2015-07-03 08:59:33 +00:00
|
|
|
var assert = require('assert');
|
|
|
|
|
2015-07-04 22:59:57 +00:00
|
|
|
setDeployConfig = function(config) {
|
|
|
|
var _blockchainConfig = (new Config.Blockchain()).loadConfigFile(config.blockchain);
|
2015-07-04 03:23:21 +00:00
|
|
|
var blockchainConfig = _blockchainConfig.config("development");
|
|
|
|
var compiler = new Compiler(_blockchainConfig);
|
|
|
|
var contractsConfig = new Config.Contracts(blockchainConfig, compiler);
|
2015-07-04 22:59:57 +00:00
|
|
|
contractsConfig.loadConfigFile(config.contracts);
|
|
|
|
contractsConfig.init(config.files);
|
|
|
|
compiler.init('development');
|
|
|
|
return new Deploy('development', config.files, blockchainConfig, contractsConfig);
|
|
|
|
}
|
2015-07-03 08:59:33 +00:00
|
|
|
|
2015-07-04 22:59:57 +00:00
|
|
|
describe('embark.deploy', function() {
|
2015-07-03 08:59:33 +00:00
|
|
|
|
2015-07-04 22:59:57 +00:00
|
|
|
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'
|
|
|
|
];
|
|
|
|
|
|
|
|
describe('#deploy_contracts', function() {
|
2015-07-06 12:19:25 +00:00
|
|
|
var deploy = setDeployConfig({
|
|
|
|
files: files,
|
|
|
|
blockchain: 'test/support/blockchain.yml',
|
|
|
|
contracts: 'test/support/arguments.yml'
|
|
|
|
});
|
2015-07-04 22:59:57 +00:00
|
|
|
deploy.deploy_contracts("development");
|
|
|
|
|
|
|
|
it("should deploy contracts", function() {
|
|
|
|
var all_contracts = ['Wallet', 'SimpleStorage', 'AnotherStorage', 'Wallets'];
|
2015-07-06 12:19:25 +00:00
|
|
|
for(var i=0; i < all_contracts.length; i++) {
|
2015-07-04 22:59:57 +00:00
|
|
|
var className = all_contracts[i];
|
|
|
|
|
|
|
|
assert.equal(deploy.deployedContracts.hasOwnProperty(className), true);
|
|
|
|
}
|
|
|
|
});
|
2015-07-03 08:59:33 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
2015-07-04 22:59:57 +00:00
|
|
|
describe('#generate_abi_file', function() {
|
2015-07-06 12:19:25 +00:00
|
|
|
var deploy = setDeployConfig({
|
|
|
|
files: files,
|
|
|
|
blockchain: 'test/support/blockchain.yml',
|
|
|
|
contracts: 'test/support/arguments.yml'
|
|
|
|
});
|
2015-07-04 22:59:57 +00:00
|
|
|
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');");
|
|
|
|
});
|
|
|
|
});
|
2015-07-03 08:59:33 +00:00
|
|
|
});
|
|
|
|
|
2015-07-04 22:59:57 +00:00
|
|
|
describe('contracts instances', function() {
|
|
|
|
var files = [
|
|
|
|
'test/support/contracts/simple_storage.sol'
|
|
|
|
];
|
|
|
|
|
|
|
|
describe('#deploy_contracts', function() {
|
2015-07-06 12:19:25 +00:00
|
|
|
var deploy = setDeployConfig({
|
|
|
|
files: files,
|
|
|
|
blockchain: 'test/support/blockchain.yml',
|
|
|
|
contracts: 'test/support/instances.yml'
|
|
|
|
});
|
2015-07-04 22:59:57 +00:00
|
|
|
deploy.deploy_contracts("development");
|
|
|
|
|
|
|
|
it("should deploy contracts", function() {
|
2015-07-06 12:19:25 +00:00
|
|
|
var all_contracts = ['SimpleStorage', 'BarStorage', 'FooStorage'];
|
|
|
|
for(var i=0; i < all_contracts.length; i++) {
|
2015-07-04 22:59:57 +00:00
|
|
|
var className = all_contracts[i];
|
|
|
|
|
|
|
|
assert.equal(deploy.deployedContracts.hasOwnProperty(className), true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-07-03 08:59:33 +00:00
|
|
|
});
|
2015-07-04 22:59:57 +00:00
|
|
|
|
2015-07-03 08:59:33 +00:00
|
|
|
});
|
|
|
|
|
2015-07-06 12:19:25 +00:00
|
|
|
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');
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2015-07-03 08:59:33 +00:00
|
|
|
});
|