2016-10-15 19:54:19 +00:00
|
|
|
/*globals describe, it*/
|
2018-04-17 19:07:00 +00:00
|
|
|
const Config = require('../lib/core/config.js');
|
|
|
|
const Plugins = require('../lib/core/plugins.js');
|
|
|
|
const assert = require('assert');
|
|
|
|
const TestLogger = require('../lib/tests/test_logger.js');
|
2016-10-15 19:54:19 +00:00
|
|
|
|
2018-04-17 19:07:00 +00:00
|
|
|
describe('embark.Config', function () {
|
2017-03-29 15:37:30 +00:00
|
|
|
let config = new Config({
|
2016-10-15 19:54:19 +00:00
|
|
|
env: 'myenv',
|
|
|
|
configDir: './test/test1/config/'
|
|
|
|
});
|
2017-01-29 06:28:01 +00:00
|
|
|
config.plugins = new Plugins({plugins: {}});
|
2018-04-17 19:07:00 +00:00
|
|
|
config.logger = new TestLogger({});
|
2016-10-15 19:54:19 +00:00
|
|
|
|
2018-04-17 19:07:00 +00:00
|
|
|
describe('#loadBlockchainConfigFile', function () {
|
|
|
|
it('should load blockchain config correctly', function () {
|
2016-10-15 19:54:19 +00:00
|
|
|
config.loadBlockchainConfigFile();
|
2017-03-29 15:37:30 +00:00
|
|
|
let expectedConfig = {
|
2017-03-01 04:40:40 +00:00
|
|
|
"enabled": true,
|
2016-10-15 19:54:19 +00:00
|
|
|
"networkType": "custom",
|
|
|
|
"genesisBlock": "config/development/genesis.json",
|
|
|
|
"datadir": ".embark/development/datadir",
|
|
|
|
"mineWhenNeeded": true,
|
|
|
|
"nodiscover": true,
|
|
|
|
"rpcHost": "localhost",
|
|
|
|
"rpcPort": 8545,
|
|
|
|
"rpcCorsDomain": "http://localhost:8000",
|
|
|
|
"account": {
|
|
|
|
"password": "config/development/password"
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
assert.deepEqual(config.blockchainConfig, expectedConfig);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-04-17 19:07:00 +00:00
|
|
|
describe('#loadContractsConfigFile', function () {
|
|
|
|
it('should load contract config correctly', function () {
|
|
|
|
config.loadContractsConfigFile();
|
|
|
|
let expectedConfig = {
|
|
|
|
versions: {'web3.js': '1.0.0-beta', solc: '0.4.17'},
|
|
|
|
deployment: {host: 'localhost', port: 8545, type: 'rpc'},
|
|
|
|
dappConnection: ['$WEB3', 'localhost:8545'],
|
|
|
|
"gas": "auto",
|
|
|
|
"contracts": {
|
|
|
|
"SimpleStorage": {
|
|
|
|
"args": [100],
|
|
|
|
"gas": 123456
|
|
|
|
},
|
|
|
|
"Token": {
|
|
|
|
"args": [200]
|
2016-10-15 19:54:19 +00:00
|
|
|
}
|
2018-04-17 19:07:00 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
assert.deepEqual(config.contractsConfig, expectedConfig);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#getExternalContractUrl', function () {
|
|
|
|
it('should get the right url for a https://github file', function () {
|
2018-04-19 14:05:11 +00:00
|
|
|
const fileObj = config.getExternalContractUrl(
|
2018-04-17 19:07:00 +00:00
|
|
|
{file: 'https://github.com/embark-framework/embark/blob/master/test_app/app/contracts/simple_storage.sol'}
|
|
|
|
);
|
2018-04-19 14:05:11 +00:00
|
|
|
assert.deepEqual(fileObj,
|
|
|
|
{
|
|
|
|
filePath: 'embark-framework/embark/master/test_app/app/contracts/simple_storage.sol',
|
|
|
|
url: 'https://raw.githubusercontent.com/embark-framework/embark/master/test_app/app/contracts/simple_storage.sol'
|
|
|
|
});
|
2018-04-17 19:07:00 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should fail for a malformed https://github file', function () {
|
2018-04-19 14:05:11 +00:00
|
|
|
const fileObj = config.getExternalContractUrl(
|
2018-04-17 19:07:00 +00:00
|
|
|
{file: 'https://github/embark-framework/embark/blob/master/test_app/app/contracts/simple_storage.sol'}
|
|
|
|
);
|
2018-04-19 14:05:11 +00:00
|
|
|
assert.strictEqual(fileObj, null);
|
2018-04-17 19:07:00 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should get the right url for a git:// file with no branch #', function () {
|
2018-04-19 14:05:11 +00:00
|
|
|
const fileObj = config.getExternalContractUrl(
|
2018-04-17 19:07:00 +00:00
|
|
|
{file: 'git://github.com/status-im/contracts/contracts/identity/ERC725.sol'}
|
|
|
|
);
|
2018-04-19 14:05:11 +00:00
|
|
|
assert.deepEqual(fileObj,
|
|
|
|
{
|
|
|
|
filePath: 'status-im/contracts/master/contracts/identity/ERC725.sol',
|
|
|
|
url: 'https://raw.githubusercontent.com/status-im/contracts/master/contracts/identity/ERC725.sol'
|
|
|
|
});
|
2018-04-17 19:07:00 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should get the right url for a git:// file with a branch #', function () {
|
2018-04-19 14:05:11 +00:00
|
|
|
const fileObj = config.getExternalContractUrl(
|
2018-04-17 19:07:00 +00:00
|
|
|
{file: 'git://github.com/status-im/contracts/contracts/identity/ERC725.sol#myBranch'}
|
|
|
|
);
|
2018-04-19 14:05:11 +00:00
|
|
|
assert.deepEqual(fileObj,
|
|
|
|
{
|
|
|
|
filePath: 'status-im/contracts/myBranch/contracts/identity/ERC725.sol',
|
|
|
|
url: 'https://raw.githubusercontent.com/status-im/contracts/myBranch/contracts/identity/ERC725.sol'
|
|
|
|
});
|
2018-04-17 19:07:00 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should fail when the git:// file is malformed', function () {
|
2018-04-19 14:05:11 +00:00
|
|
|
const fileObj = config.getExternalContractUrl(
|
2018-04-17 19:07:00 +00:00
|
|
|
{file: 'git://github.com/identity/ERC725.sol#myBranch'}
|
|
|
|
);
|
2018-04-19 14:05:11 +00:00
|
|
|
assert.strictEqual(fileObj, null);
|
2018-04-17 19:07:00 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should get the right url with a github.com file without branch #', function () {
|
2018-04-19 14:05:11 +00:00
|
|
|
const fileObj = config.getExternalContractUrl(
|
2018-04-17 19:07:00 +00:00
|
|
|
{file: 'github.com/status-im/contracts/contracts/identity/ERC725.sol'}
|
|
|
|
);
|
2018-04-19 14:05:11 +00:00
|
|
|
assert.deepEqual(fileObj,
|
|
|
|
{
|
|
|
|
filePath: 'status-im/contracts/master/contracts/identity/ERC725.sol',
|
|
|
|
url: 'https://raw.githubusercontent.com/status-im/contracts/master/contracts/identity/ERC725.sol'
|
|
|
|
});
|
2018-04-17 19:07:00 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should get the right url with a github.com file with branch #', function () {
|
2018-04-19 14:05:11 +00:00
|
|
|
const fileObj = config.getExternalContractUrl(
|
2018-04-17 19:07:00 +00:00
|
|
|
{file: 'github.com/status-im/contracts/contracts/identity/ERC725.sol#theBranch'}
|
|
|
|
);
|
2018-04-19 14:05:11 +00:00
|
|
|
assert.deepEqual(fileObj,
|
|
|
|
{
|
|
|
|
filePath: 'status-im/contracts/theBranch/contracts/identity/ERC725.sol',
|
|
|
|
url: 'https://raw.githubusercontent.com/status-im/contracts/theBranch/contracts/identity/ERC725.sol'
|
|
|
|
});
|
2018-04-17 19:07:00 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should fail with a malformed github.com url', function () {
|
2018-04-19 14:05:11 +00:00
|
|
|
const fileObj = config.getExternalContractUrl(
|
2018-04-17 19:07:00 +00:00
|
|
|
{file: 'github/status-im/contracts/contracts/identity/ERC725.sol#theBranch'}
|
|
|
|
);
|
2018-04-19 14:05:11 +00:00
|
|
|
assert.strictEqual(fileObj, null);
|
2018-04-17 19:07:00 +00:00
|
|
|
});
|
2016-10-15 19:54:19 +00:00
|
|
|
|
2018-04-17 19:07:00 +00:00
|
|
|
it('should succeed with a generic http url', function () {
|
2018-04-19 14:05:11 +00:00
|
|
|
const fileObj = config.getExternalContractUrl(
|
2018-04-17 19:07:00 +00:00
|
|
|
{file: 'http://myurl.com/myFile.sol'}
|
|
|
|
);
|
2018-04-19 14:05:11 +00:00
|
|
|
assert.deepEqual(fileObj, {
|
|
|
|
filePath: 'myFile.sol',
|
|
|
|
url: 'http://myurl.com/myFile.sol'
|
|
|
|
});
|
2016-10-15 19:54:19 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-04-18 13:07:39 +00:00
|
|
|
describe('#loadExternalContractsFiles', function () {
|
2018-04-18 16:09:42 +00:00
|
|
|
it('should create the right list of files and download', function () {
|
2018-04-18 13:07:39 +00:00
|
|
|
config.contractsFiles = [];
|
|
|
|
config.contractsConfig.contracts = [
|
|
|
|
{
|
|
|
|
file: 'https://github.com/embark-framework/embark/blob/master/test_app/app/contracts/simple_storage.sol'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
file: 'github.com/status-im/contracts/contracts/identity/ERC725.sol'
|
|
|
|
}
|
|
|
|
];
|
2018-04-18 16:09:42 +00:00
|
|
|
const expected = [
|
|
|
|
{
|
2018-04-18 18:56:18 +00:00
|
|
|
"filename": ".embark/contracts/simple_storage.sol",
|
2018-04-18 16:09:42 +00:00
|
|
|
"type": "http",
|
|
|
|
"path": "https://raw.githubusercontent.com/embark-framework/embark/master/test_app/app/contracts/simple_storage.sol",
|
|
|
|
"basedir": "",
|
|
|
|
"resolver": undefined
|
|
|
|
},
|
|
|
|
{
|
2018-04-18 18:56:18 +00:00
|
|
|
"filename": ".embark/contracts/ERC725.sol",
|
2018-04-18 16:09:42 +00:00
|
|
|
"type": "http",
|
|
|
|
"path": "https://raw.githubusercontent.com/status-im/contracts/master/contracts/identity/ERC725.sol",
|
|
|
|
"basedir": "",
|
|
|
|
"resolver": undefined
|
|
|
|
}
|
|
|
|
];
|
|
|
|
config.loadExternalContractsFiles();
|
|
|
|
assert.deepEqual(config.contractsFiles, expected);
|
2018-04-18 13:07:39 +00:00
|
|
|
});
|
|
|
|
});
|
2016-10-15 19:54:19 +00:00
|
|
|
});
|