embark/test/config.contracts.js

79 lines
2.8 KiB
JavaScript
Raw Normal View History

var Config = require('../lib/config/config.js');
var assert = require('assert');
var sinon = require('sinon');
var web3 = require('web3');
require('mocha-sinon');
describe('embark.config.contracts', function() {
var blockchainConfig = (new Config.Blockchain()).loadConfigFile('test/support/blockchain.yml').config("development");
describe('#loadConfigFile', function() {
it('should read and load yml file', function() {
2015-07-03 11:59:35 +00:00
var contractsConfig = new Config.Contracts(blockchainConfig, web3);
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() {
var contractsConfig = new Config.Contracts([], blockchainConfig, web3);
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-03 11:59:35 +00:00
contractsConfig = new Config.Contracts(blockchainConfig, web3);
contractsConfig.loadConfigFile('test/support/contracts.yml');
2015-07-03 11:59:35 +00:00
contractsConfig.init(files);
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-03 11:59:35 +00:00
contractsConfig = new Config.Contracts(blockchainConfig, web3);
contractsConfig.loadConfigFile('test/support/arguments.yml');
2015-07-03 11:59:35 +00:00
contractsConfig.init(files);
contractsConfig.compileContracts('development');
});
it('add contracts to a list', function() {
assert.deepEqual(contractsConfig.all_contracts, [ "SimpleStorage", "AnotherStorage", "Wallet", "Wallets" ]);
});
});
});
});