embark/test/config.contracts.js

115 lines
4.1 KiB
JavaScript
Raw Normal View History

var Config = require('../lib/config/config.js');
2015-07-04 03:23:21 +00:00
var Compiler = require('../lib/compiler.js');
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);
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);
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);
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);
contractsConfig.loadConfigFile('test/support/contracts.yml');
2015-08-01 15:19:21 +00:00
contractsConfig.init(files, 'development');
contractsConfig.compileContracts();
});
it('add contracts to a list', function() {
assert.deepEqual(contractsConfig.all_contracts, [ "SimpleStorage", "AnotherStorage" ]);
});
});
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);
contractsConfig.loadConfigFile('test/support/arguments.yml');
2015-08-01 15:19:21 +00:00
contractsConfig.init(files, 'development');
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');
2015-08-01 15:19:21 +00:00
contractsConfig.init(files, 'development');
2015-07-04 20:52:05 +00:00
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');
2015-08-01 15:19:21 +00:00
contractsConfig.init(files, 'development');
2015-08-01 02:50:51 +00:00
contractsConfig.compileContracts('development');
});
it('add contracts to a list', function() {
assert.deepEqual(contractsConfig.all_contracts, [ "token", "Crowdsale" ]);
});
});
});
});