/ test / config.js
config.js
  1  /*globals describe, it*/
  2  const Config = require('../lib/core/config.js');
  3  const Plugins = require('../lib/core/plugins.js');
  4  const assert = require('assert');
  5  const TestLogger = require('../lib/utils/test_logger');
  6  const Events = require('../lib/core/events');
  7  
  8  describe('embark.Config', function () {
  9    let config = new Config({
 10      env: 'myenv',
 11      configDir: './test/test1/config/',
 12      events: new Events()
 13    });
 14    config.plugins = new Plugins({plugins: {}});
 15    config.logger = new TestLogger({});
 16  
 17    describe('#loadBlockchainConfigFile', function () {
 18      it('should load blockchain config correctly', function () {
 19        config.loadBlockchainConfigFile();
 20        let expectedConfig = {
 21          "enabled": true,
 22          "networkType": "custom",
 23          "genesisBlock": "config/development/genesis.json",
 24          "datadir": ".embark/development/datadir",
 25          "isDev": false,
 26          "mineWhenNeeded": true,
 27          "nodiscover": true,
 28          "rpcHost": "localhost",
 29          "rpcPort": 8545,
 30          "rpcCorsDomain": "http://localhost:8000",
 31          "wsOrigins": "auto",
 32          "account": {
 33            "password": "config/development/password"
 34          }
 35        };
 36  
 37        assert.deepEqual(config.blockchainConfig, expectedConfig);
 38      });
 39  
 40      it('should convert Ether units', function () {
 41        let expectedConfig = {
 42          "enabled": true,
 43          "networkType": "custom",
 44          "genesisBlock": "config/development/genesis.json",
 45          "datadir": ".embark/development/datadir",
 46          "isDev": false,
 47          "targetGasLimit": "300000",
 48          "gasPrice": "8000000",
 49          "mineWhenNeeded": true,
 50          "nodiscover": true,
 51          "rpcHost": "localhost",
 52          "rpcPort": 8545,
 53          "rpcCorsDomain": "http://localhost:8000",
 54          "wsOrigins": "auto",
 55          "account": {
 56            "password": "config/development/password",
 57            "balance": "3000000000000000000"
 58          }
 59        };
 60  
 61        let config = new Config({
 62          env: 'unitenv',
 63          configDir: './test/test1/config/',
 64          events: new Events()
 65        });
 66        config.plugins = new Plugins({plugins: {}});
 67        config.logger = new TestLogger({});
 68        config.loadBlockchainConfigFile();
 69  
 70        assert.deepEqual(config.blockchainConfig, expectedConfig);
 71      });
 72  
 73      it('should accept unitless gas values', function () {
 74        let expectedConfig = {
 75          "enabled": true,
 76          "networkType": "custom",
 77          "genesisBlock": "config/development/genesis.json",
 78          "datadir": ".embark/development/datadir",
 79          "isDev": false,
 80          "targetGasLimit": "20000000",
 81          "gasPrice": "8000000",
 82          "mineWhenNeeded": true,
 83          "nodiscover": true,
 84          "rpcHost": "localhost",
 85          "rpcPort": 8545,
 86          "rpcCorsDomain": "http://localhost:8000",
 87          "wsOrigins": "auto",
 88          "account": {
 89            "password": "config/development/password",
 90            "balance": "3000000000000000000"
 91          }
 92        };
 93  
 94        let config = new Config({
 95          env: 'unitlessenv',
 96          configDir: './test/test1/config/',
 97          events: new Events()
 98        });
 99        config.plugins = new Plugins({plugins: {}});
100        config.logger = new TestLogger({});
101        config.loadBlockchainConfigFile();
102  
103        assert.deepEqual(config.blockchainConfig, expectedConfig);
104      });
105    });
106  
107    describe('#loadContractsConfigFile', function () {
108      it('should load contract config correctly', function () {
109        config.loadContractsConfigFile();
110        let expectedConfig = {
111          versions: {'web3': '1.0.0-beta', solc: '0.4.17'},
112          deployment: {host: 'localhost', port: 8545, type: 'rpc', "accounts": [{"mnemonic": "12 word mnemonic", "balance": "5000000000"}]},
113          dappConnection: ['$WEB3', 'localhost:8545'],
114          "gas": "400000",
115          "contracts": {
116            "SimpleStorage": {
117              "args": [100],
118              "gas": "123000",
119              "gasPrice": "1000"
120            },
121            "Token": {
122              "args": [200]
123            }
124          }
125        };
126  
127        assert.deepEqual(config.contractsConfig, expectedConfig);
128      });
129    });
130  
131    describe('#loadExternalContractsFiles', function () {
132      it('should create the right list of files and download', function () {
133        config.contractsFiles = [];
134        config.contractsConfig.contracts = [
135          {
136            file: 'https://github.com/embark-framework/embark/blob/master/test_app/app/contracts/simple_storage.sol'
137          },
138          {
139            file: 'github.com/status-im/contracts/contracts/identity/ERC725.sol'
140          }
141        ];
142        const expected = [
143          {
144            "filename": ".embark/contracts/embark-framework/embark/master/test_app/app/contracts/simple_storage.sol",
145            "type": "http",
146            "path": "https://raw.githubusercontent.com/embark-framework/embark/master/test_app/app/contracts/simple_storage.sol",
147            "pluginPath": '',
148            "importRemappings": [],
149            "basedir": "",
150            "resolver": undefined,
151            "downloadedImports": false
152          },
153          {
154            "filename": ".embark/contracts/status-im/contracts/master/contracts/identity/ERC725.sol",
155            "type": "http",
156            "path": "https://raw.githubusercontent.com/status-im/contracts/master/contracts/identity/ERC725.sol",
157            "pluginPath": '',
158            "importRemappings": [],
159            "basedir": "",
160            "resolver": undefined,
161            "downloadedImports": false
162          }
163        ];
164        config.loadExternalContractsFiles();
165        assert.deepEqual(config.contractsFiles, expected);
166      });
167    });
168  });