2015-06-28 20:11:42 +00:00
|
|
|
var Config = require('../lib/config/config.js');
|
2015-07-04 03:23:21 +00:00
|
|
|
var Compiler = require('../lib/compiler.js');
|
2015-06-28 20:11:42 +00:00
|
|
|
var assert = require('assert');
|
|
|
|
var sinon = require('sinon');
|
|
|
|
require('mocha-sinon');
|
|
|
|
|
|
|
|
describe('embark.config.contracts', function() {
|
2015-07-04 03:23:21 +00:00
|
|
|
var _blockchainConfig = (new Config.Blockchain()).loadConfigFile('test/support/blockchain.yml');
|
|
|
|
var blockchainConfig = _blockchainConfig.config("development");
|
|
|
|
var compiler = new Compiler(_blockchainConfig);
|
2015-06-28 20:11:42 +00:00
|
|
|
|
|
|
|
describe('#loadConfigFile', function() {
|
|
|
|
it('should read and load yml file', function() {
|
2015-07-04 03:23:21 +00:00
|
|
|
var contractsConfig = new Config.Contracts(blockchainConfig, compiler);
|
2015-06-28 20:11:42 +00:00
|
|
|
contractsConfig.loadConfigFile('test/support/contracts.yml');
|
|
|
|
|
|
|
|
assert.equal(contractsConfig.contractConfig.hasOwnProperty('development'), true)
|
|
|
|
assert.equal(contractsConfig.contractConfig.hasOwnProperty('staging'), true)
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should throw exception reading invalid file', function() {
|
|
|
|
assert.throws(function() { contractsConfig.loadConfigFile('test/support/invalid.yml') }, Error);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#loadConfig', function() {
|
|
|
|
it('should load config', function() {
|
2015-07-04 03:23:21 +00:00
|
|
|
var contractsConfig = new Config.Contracts([], blockchainConfig, compiler);
|
2015-06-28 20:11:42 +00:00
|
|
|
var hsh = {
|
|
|
|
development: {},
|
|
|
|
staging: {}
|
|
|
|
};
|
|
|
|
|
|
|
|
contractsConfig.loadConfig(hsh);
|
|
|
|
|
|
|
|
assert.equal(contractsConfig.contractConfig.hasOwnProperty('development'), true)
|
|
|
|
assert.equal(contractsConfig.contractConfig.hasOwnProperty('staging'), true)
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#compileContracts', function() {
|
|
|
|
context("simple contracts", function() {
|
|
|
|
before(function() {
|
|
|
|
files = [
|
|
|
|
'test/support/contracts/simple_storage.sol',
|
|
|
|
'test/support/contracts/another_storage.sol'
|
|
|
|
]
|
2015-07-04 03:23:21 +00:00
|
|
|
contractsConfig = new Config.Contracts(blockchainConfig, compiler);
|
2015-06-28 20:11:42 +00:00
|
|
|
contractsConfig.loadConfigFile('test/support/contracts.yml');
|
2015-07-03 11:59:35 +00:00
|
|
|
contractsConfig.init(files);
|
2015-06-28 20:11:42 +00:00
|
|
|
contractsConfig.compileContracts();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('add contracts to a list', function() {
|
|
|
|
assert.deepEqual(contractsConfig.all_contracts, [ "SimpleStorage", "AnotherStorage" ]);
|
|
|
|
});
|
|
|
|
});
|
2015-07-01 23:49:49 +00:00
|
|
|
|
|
|
|
context("contracts as arguments to other contracts", function() {
|
|
|
|
before(function() {
|
|
|
|
files = [
|
|
|
|
'test/support/contracts/wallet.sol',
|
|
|
|
'test/support/contracts/simple_storage.sol',
|
|
|
|
'test/support/contracts/another_storage.sol',
|
|
|
|
'test/support/contracts/wallets.sol'
|
|
|
|
]
|
2015-07-04 03:23:21 +00:00
|
|
|
contractsConfig = new Config.Contracts(blockchainConfig, compiler);
|
2015-07-01 23:49:49 +00:00
|
|
|
contractsConfig.loadConfigFile('test/support/arguments.yml');
|
2015-07-03 11:59:35 +00:00
|
|
|
contractsConfig.init(files);
|
2015-07-01 23:49:49 +00:00
|
|
|
contractsConfig.compileContracts('development');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('add contracts to a list', function() {
|
|
|
|
assert.deepEqual(contractsConfig.all_contracts, [ "SimpleStorage", "AnotherStorage", "Wallet", "Wallets" ]);
|
|
|
|
});
|
|
|
|
});
|
2015-07-04 20:52:05 +00:00
|
|
|
|
|
|
|
context("contracts instances", function() {
|
|
|
|
before(function() {
|
|
|
|
files = [
|
|
|
|
'test/support/contracts/simple_storage.sol'
|
|
|
|
]
|
|
|
|
contractsConfig = new Config.Contracts(blockchainConfig, compiler);
|
|
|
|
contractsConfig.loadConfigFile('test/support/instances.yml');
|
|
|
|
contractsConfig.init(files);
|
|
|
|
contractsConfig.compileContracts('development');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('add contracts to a list', function() {
|
|
|
|
assert.deepEqual(contractsConfig.all_contracts, [ "SimpleStorage", "BarStorage", "FooStorage" ]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-08-01 02:50:51 +00:00
|
|
|
context("contracts as arguments to other contracts with stubs", function() {
|
|
|
|
before(function() {
|
|
|
|
files = [
|
|
|
|
'test/support/contracts/crowdsale.sol',
|
|
|
|
'test/support/contracts/token.sol'
|
|
|
|
]
|
|
|
|
contractsConfig = new Config.Contracts(blockchainConfig, compiler);
|
|
|
|
contractsConfig.loadConfigFile('test/support/arguments2.yml');
|
|
|
|
contractsConfig.init(files);
|
|
|
|
contractsConfig.compileContracts('development');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('add contracts to a list', function() {
|
|
|
|
assert.deepEqual(contractsConfig.all_contracts, [ "token", "Crowdsale" ]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-06-28 20:11:42 +00:00
|
|
|
});
|
2015-07-01 23:49:49 +00:00
|
|
|
|
2015-06-28 20:11:42 +00:00
|
|
|
});
|
|
|
|
|