diff --git a/dapps/templates/boilerplate/config/blockchain.js b/dapps/templates/boilerplate/config/blockchain.js index ad95b8a28..afc71e220 100644 --- a/dapps/templates/boilerplate/config/blockchain.js +++ b/dapps/templates/boilerplate/config/blockchain.js @@ -1,124 +1,56 @@ +// This file contains only the basic configuration you need to run Embark's node +// For additional configurations, see: https://embark.status.im/docs/blockchain_configuration.html module.exports = { - // applies to all environments + // default applies to all environments default: { enabled: true, - rpcHost: "localhost", // HTTP-RPC server listening interface (default: "localhost") - rpcPort: 8545, // HTTP-RPC server listening port (default: 8545) - rpcCorsDomain: { // Domains from which to accept cross origin requests (browser enforced). This can also be a comma separated list - auto: true, // When "auto" is true, Embark will automatically set the cors to the address of the webserver - additionalCors: [] // Additional CORS domains to add to the list. If "auto" is false, only those will be added - }, - wsRPC: true, // Enable the WS-RPC server - wsOrigins: { // Same thing as "rpcCorsDomain", but for WS origins - auto: true, - additionalCors: [] - }, - wsHost: "localhost", // WS-RPC server listening interface (default: "localhost") - wsPort: 8546 // WS-RPC server listening port (default: 8546) + client: "geth" // Can be geth or parity (default:geth) + }, + development: { + clientConfig: { + miningMode: 'dev' // Mode in which the node mines. Options: dev, auto, always, off + } + }, + + privatenet: { // Accounts to use as node accounts // The order here corresponds to the order of `web3.eth.getAccounts`, so the first one is the `defaultAccount` - /*,accounts: [ + // For more account configurations, see: https://embark.status.im/docs/blockchain_accounts_configuration.html + accounts: [ { nodeAccounts: true, // Accounts use for the node numAddresses: "1", // Number of addresses/accounts (defaults to 1) - password: "config/development/devpassword" // Password file for the accounts - }, - // Below are additional accounts that will count as `nodeAccounts` in the `deployment` section of your contract config - // Those will not be unlocked in the node itself - { - privateKey: "your_private_key" - }, - { - privateKeyFile: "path/to/file", // Either a keystore or a list of keys, separated by , or ; - password: "passwordForTheKeystore" // Needed to decrypt the keystore file - }, - { - mnemonic: "12 word mnemonic", - addressIndex: "0", // Optional. The index to start getting the address - numAddresses: "1", // Optional. The number of addresses to get - hdpath: "m/44'/60'/0'/0/" // Optional. HD derivation path - } - ]*/ - }, - - // default environment, merges with the settings in default - // assumed to be the intended environment by `embark run` and `embark blockchain` - development: { - ethereumClientName: "geth", // Can be geth or parity (default:geth) - //ethereumClientBin: "geth", // path to the client binary. Useful if it is not in the global PATH - networkType: "custom", // Can be: testnet, rinkeby, livenet or custom, in which case, it will use the specified networkId - networkId: 1337, // Network id used when networkType is custom - isDev: true, // Uses and ephemeral proof-of-authority network with a pre-funded developer account, mining enabled - datadir: ".embark/development/datadir", // Data directory for the databases and keystore (Geth 1.8.15 and Parity 2.0.4 can use the same base folder, till now they does not conflict with each other) - mineWhenNeeded: true, // Uses our custom script (if isDev is false) to mine only when needed - nodiscover: true, // Disables the peer discovery mechanism (manual peer addition) - maxpeers: 0, // Maximum number of network peers (network disabled if set to 0) (default: 25) - proxy: true, // Proxy is used to present meaningful information about transactions - targetGasLimit: 8000000, // Target gas limit sets the artificial target gas floor for the blocks to mine - simulatorBlocktime: 0 // Specify blockTime in seconds for automatic mining. Default is 0 and no auto-mining. - }, - - // merges with the settings in default - // used with "embark run privatenet" and/or "embark blockchain privatenet" - privatenet: { - networkType: "custom", - networkId: 1337, - isDev: false, - datadir: ".embark/privatenet/datadir", - // -- mineWhenNeeded -- - // This options is only valid when isDev is false. - // Enabling this option uses our custom script to mine only when needed. - // Embark creates a development account for you (using `geth account new`) and funds the account. This account can be used for - // development (and even imported in to MetaMask). To enable correct usage, a password for this account must be specified - // in the `account > password` setting below. - // NOTE: once `mineWhenNeeded` is enabled, you must run an `embark reset` on your dApp before running - // `embark blockchain` or `embark run` for the first time. - mineWhenNeeded: true, - // -- genesisBlock -- - // This option is only valid when mineWhenNeeded is true (which is only valid if isDev is false). - // When enabled, geth uses POW to mine transactions as it would normally, instead of using POA as it does in --dev mode. - // On the first `embark blockchain or embark run` after this option is enabled, geth will create a new chain with a - // genesis block, which can be configured using the `genesisBlock` configuration option below. - genesisBlock: "config/privatenet/genesis.json", // Genesis block to initiate on first creation of a development node - nodiscover: true, - maxpeers: 0, - proxy: true, - accounts: [ - { - nodeAccounts: true, - password: "config/privatenet/password" // Password to unlock the account + password: "config/development/password" // Password file for the accounts } ], - targetGasLimit: 8000000, - simulatorBlocktime: 0 + clientConfig: { + datadir: ".embark/privatenet/datadir", // Data directory for the databases and keystore + miningMode: 'auto', + genesisBlock: "config/privatenet/genesis.json" // Genesis block to initiate on first creation of a development node + } }, privateparitynet: { - ethereumClientName: "parity", - networkType: "custom", - networkId: 1337, - isDev: false, - genesisBlock: "config/privatenet/genesis-parity.json", // Genesis block to initiate on first creation of a development node + client: "parity", + genesisBlock: "config/privatenet/genesis-parity.json", datadir: ".embark/privatenet/datadir", - mineWhenNeeded: false, - nodiscover: true, - maxpeers: 0, - proxy: true, - accounts: [ - { - nodeAccounts: true, - password: "config/privatenet/password" - } - ], - targetGasLimit: 8000000, - simulatorBlocktime: 0 + miningMode: 'off' + }, + + externalnode: { + endpoint: "URL_OF_THE_NODE", // Endpoint of an node to connect to. Can be on localhost or on the internet + accounts: [ + { + mnemonic: "YOUR_MNEMONIC", + hdpath: "m/44'/60'/0'/0/", + numAddresses: "1" + } + ] }, - // merges with the settings in default - // used with "embark run testnet" and/or "embark blockchain testnet" testnet: { - networkType: "testnet", + networkType: "testnet", // Can be: testnet, rinkeby, livenet or custom, in which case, it will use the specified networkId syncMode: "light", accounts: [ { @@ -128,13 +60,9 @@ module.exports = { ] }, - // merges with the settings in default - // used with "embark run livenet" and/or "embark blockchain livenet" livenet: { networkType: "livenet", syncMode: "light", - rpcCorsDomain: "http://localhost:8000", - wsOrigins: "http://localhost:8000", accounts: [ { nodeAccounts: true, diff --git a/dapps/templates/boilerplate/config/contracts.js b/dapps/templates/boilerplate/config/contracts.js index a2b190c46..482a5ee1c 100644 --- a/dapps/templates/boilerplate/config/contracts.js +++ b/dapps/templates/boilerplate/config/contracts.js @@ -1,34 +1,6 @@ module.exports = { // default applies to all environments default: { - // Blockchain node to deploy the contracts - deployment: { - host: "localhost", // Host of the blockchain node - port: 8546, // Port of the blockchain node - type: "ws" // Type of connection (ws or rpc), - // Accounts to use instead of the default account to populate your wallet - // The order here corresponds to the order of `web3.eth.getAccounts`, so the first one is the `defaultAccount` - /*,accounts: [ - { - privateKey: "your_private_key", - balance: "5 ether" // You can set the balance of the account in the dev environment - // Balances are in Wei, but you can specify the unit with its name - }, - { - privateKeyFile: "path/to/file", // Either a keystore or a list of keys, separated by , or ; - password: "passwordForTheKeystore" // Needed to decrypt the keystore file - }, - { - mnemonic: "12 word mnemonic", - addressIndex: "0", // Optional. The index to start getting the address - numAddresses: "1", // Optional. The number of addresses to get - hdpath: "m/44'/60'/0'/0/" // Optional. HD derivation path - }, - { - "nodeAccounts": true // Uses the Ethereum node's accounts - } - ]*/ - }, // order of connections the dapp should connect to dappConnection: [ "$WEB3", // uses pre existing web3 object if available (e.g in Mist) @@ -49,9 +21,9 @@ module.exports = { // when not specified // - explicit will only attempt to deploy the contracts that are explicitly specified inside the // contracts section. - //strategy: 'implicit', + // strategy: 'implicit', - contracts: { + deploy: { // example: //SimpleStorage: { // args: [ 100 ] @@ -71,21 +43,17 @@ module.exports = { // merges with the settings in default // used with "embark run privatenet" - privatenet: { - }, + privatenet: {}, // merges with the settings in default // used with "embark run testnet" - testnet: { - }, + testnet: {}, // merges with the settings in default // used with "embark run livenet" - livenet: { - }, + livenet: {} // you can name an environment with specific settings and then specify with // "embark run custom_name" or "embark blockchain custom_name" - //custom_name: { - //} + // custom_name: {} }; diff --git a/dapps/templates/demo/config/blockchain.js b/dapps/templates/demo/config/blockchain.js index 356406584..afc71e220 100644 --- a/dapps/templates/demo/config/blockchain.js +++ b/dapps/templates/demo/config/blockchain.js @@ -1,124 +1,56 @@ +// This file contains only the basic configuration you need to run Embark's node +// For additional configurations, see: https://embark.status.im/docs/blockchain_configuration.html module.exports = { - // applies to all environments + // default applies to all environments default: { enabled: true, - rpcHost: "localhost", // HTTP-RPC server listening interface (default: "localhost") - rpcPort: 8545, // HTTP-RPC server listening port (default: 8545) - rpcCorsDomain: { // Domains from which to accept cross origin requests (browser enforced). This can also be a comma separated list - auto: true, // When "auto" is true, Embark will automatically set the cors to the address of the webserver - additionalCors: [] // Additional CORS domains to add to the list. If "auto" is false, only those will be added - }, - wsRPC: true, // Enable the WS-RPC server - wsOrigins: { // Same thing as "rpcCorsDomain", but for WS origins - auto: true, - additionalCors: [] - }, - wsHost: "localhost", // WS-RPC server listening interface (default: "localhost") - wsPort: 8546 // WS-RPC server listening port (default: 8546) + client: "geth" // Can be geth or parity (default:geth) + }, + development: { + clientConfig: { + miningMode: 'dev' // Mode in which the node mines. Options: dev, auto, always, off + } + }, + + privatenet: { // Accounts to use as node accounts // The order here corresponds to the order of `web3.eth.getAccounts`, so the first one is the `defaultAccount` - /*,accounts: [ + // For more account configurations, see: https://embark.status.im/docs/blockchain_accounts_configuration.html + accounts: [ { nodeAccounts: true, // Accounts use for the node numAddresses: "1", // Number of addresses/accounts (defaults to 1) - password: "config/development/devpassword" // Password file for the accounts - }, - // Below are additional accounts that will count as `nodeAccounts` in the `deployment` section of your contract config - // Those will not be unlocked in the node itself - { - privateKey: "your_private_key" - }, - { - privateKeyFile: "path/to/file", // Either a keystore or a list of keys, separated by , or ; - password: "passwordForTheKeystore" // Needed to decrypt the keystore file - }, - { - mnemonic: "12 word mnemonic", - addressIndex: "0", // Optional. The index to start getting the address - numAddresses: "1", // Optional. The number of addresses to get - hdpath: "m/44'/60'/0'/0/" // Optional. HD derivation path - } - ]*/ - }, - - // default environment, merges with the settings in default - // assumed to be the intended environment by `embark run` and `embark blockchain` - development: { - ethereumClientName: "geth", // Can be geth or parity (default:geth) - //ethereumClientBin: "geth", // path to the client binary. Useful if it is not in the global PATH - networkType: "custom", // Can be: testnet, rinkeby, livenet or custom, in which case, it will use the specified networkId - networkId: 1337, // Network id used when networkType is custom - isDev: true, // Uses and ephemeral proof-of-authority network with a pre-funded developer account, mining enabled - datadir: ".embark/development/datadir", // Data directory for the databases and keystore (Geth 1.8.15 and Parity 2.0.4 can use the same base folder, till now they does not conflict with each other) - mineWhenNeeded: true, // Uses our custom script (if isDev is false) to mine only when needed - nodiscover: true, // Disables the peer discovery mechanism (manual peer addition) - maxpeers: 0, // Maximum number of network peers (network disabled if set to 0) (default: 25) - proxy: true, // Proxy is used to present meaningful information about transactions - targetGasLimit: 8000000, // Target gas limit sets the artificial target gas floor for the blocks to mine - simulatorBlocktime: 0 // Specify blockTime in seconds for automatic mining. Default is 0 and no auto-mining. - }, - - // merges with the settings in default - // used with "embark run privatenet" and/or "embark blockchain privatenet" - privatenet: { - networkType: "custom", - networkId: 1337, - isDev: false, - datadir: ".embark/privatenet/datadir", - // -- mineWhenNeeded -- - // This options is only valid when isDev is false. - // Enabling this option uses our custom script to mine only when needed. - // Embark creates a development account for you (using `geth account new`) and funds the account. This account can be used for - // development (and even imported in to MetaMask). To enable correct usage, a password for this account must be specified - // in the `account > password` setting below. - // NOTE: once `mineWhenNeeded` is enabled, you must run an `embark reset` on your dApp before running - // `embark blockchain` or `embark run` for the first time. - mineWhenNeeded: true, - // -- genesisBlock -- - // This option is only valid when mineWhenNeeded is true (which is only valid if isDev is false). - // When enabled, geth uses POW to mine transactions as it would normally, instead of using POA as it does in --dev mode. - // On the first `embark blockchain or embark run` after this option is enabled, geth will create a new chain with a - // genesis block, which can be configured using the `genesisBlock` configuration option below. - genesisBlock: "config/privatenet/genesis.json", // Genesis block to initiate on first creation of a development node - nodiscover: true, - maxpeers: 0, - proxy: true, - accounts: [ - { - nodeAccounts: true, - password: "config/privatenet/password" // Password to unlock the account + password: "config/development/password" // Password file for the accounts } ], - targetGasLimit: 8000000, - simulatorBlocktime: 0 + clientConfig: { + datadir: ".embark/privatenet/datadir", // Data directory for the databases and keystore + miningMode: 'auto', + genesisBlock: "config/privatenet/genesis.json" // Genesis block to initiate on first creation of a development node + } }, privateparitynet: { - ethereumClientName: "parity", - networkType: "custom", - networkId: 1337, - isDev: false, - genesisBlock: "config/privatenet/genesis-parity.json", // Genesis block to initiate on first creation of a development node + client: "parity", + genesisBlock: "config/privatenet/genesis-parity.json", datadir: ".embark/privatenet/datadir", - mineWhenNeeded: false, - nodiscover: true, - maxpeers: 0, - proxy: true, - accounts: [ - { - nodeAccounts: true, - password: "config/privatenet/password" - } - ], - targetGasLimit: 8000000, - simulatorBlocktime: 0 + miningMode: 'off' + }, + + externalnode: { + endpoint: "URL_OF_THE_NODE", // Endpoint of an node to connect to. Can be on localhost or on the internet + accounts: [ + { + mnemonic: "YOUR_MNEMONIC", + hdpath: "m/44'/60'/0'/0/", + numAddresses: "1" + } + ] }, - // merges with the settings in default - // used with "embark run testnet" and/or "embark blockchain testnet" testnet: { - networkType: "testnet", + networkType: "testnet", // Can be: testnet, rinkeby, livenet or custom, in which case, it will use the specified networkId syncMode: "light", accounts: [ { @@ -128,13 +60,9 @@ module.exports = { ] }, - // merges with the settings in default - // used with "embark run livenet" and/or "embark blockchain livenet" livenet: { networkType: "livenet", syncMode: "light", - rpcCorsDomain: "http://localhost:8000", - wsOrigins: "http://localhost:8000", accounts: [ { nodeAccounts: true, diff --git a/dapps/templates/demo/config/contracts.js b/dapps/templates/demo/config/contracts.js index 68b1e392d..4d60f5ddb 100644 --- a/dapps/templates/demo/config/contracts.js +++ b/dapps/templates/demo/config/contracts.js @@ -1,34 +1,6 @@ module.exports = { // default applies to all environments default: { - // Blockchain node to deploy the contracts - deployment: { - host: "localhost", // Host of the blockchain node - port: 8546, // Port of the blockchain node - type: "ws" // Type of connection (ws or rpc), - // Accounts to use instead of the default account to populate your wallet - // The order here corresponds to the order of `web3.eth.getAccounts`, so the first one is the `defaultAccount` - /*,accounts: [ - { - privateKey: "your_private_key", - balance: "5 ether" // You can set the balance of the account in the dev environment - // Balances are in Wei, but you can specify the unit with its name - }, - { - privateKeyFile: "path/to/file", // Either a keystore or a list of keys, separated by , or ; - password: "passwordForTheKeystore" // Needed to decrypt the keystore file - }, - { - mnemonic: "12 word mnemonic", - addressIndex: "0", // Optional. The index to start getting the address - numAddresses: "1", // Optional. The number of addresses to get - hdpath: "m/44'/60'/0'/0/" // Optional. HD derivation path - }, - { - "nodeAccounts": true // Uses the Ethereum node's accounts - } - ]*/ - }, // order of connections the dapp should connect to dappConnection: [ "$WEB3", // uses pre existing web3 object if available (e.g in Mist) @@ -49,9 +21,9 @@ module.exports = { // when not specified // - explicit will only attempt to deploy the contracts that are explicitly specified inside the // contracts section. - //strategy: 'implicit', + // strategy: 'implicit', - contracts: { + deploy: { SimpleStorage: { fromIndex: 0, args: [100] @@ -71,21 +43,17 @@ module.exports = { // merges with the settings in default // used with "embark run privatenet" - privatenet: { - }, + privatenet: {}, // merges with the settings in default // used with "embark run testnet" - testnet: { - }, + testnet: {}, // merges with the settings in default // used with "embark run livenet" - livenet: { - }, + livenet: {} // you can name an environment with specific settings and then specify with // "embark run custom_name" or "embark blockchain custom_name" - //custom_name: { - //} + // custom_name: {} }; diff --git a/dapps/templates/simple/contracts.js b/dapps/templates/simple/contracts.js index 14eb0f041..a0ccc9436 100644 --- a/dapps/templates/simple/contracts.js +++ b/dapps/templates/simple/contracts.js @@ -1,34 +1,6 @@ module.exports = { // default applies to all environments default: { - // Blockchain node to deploy the contracts - deployment: { - host: "localhost", // Host of the blockchain node - port: 8546, // Port of the blockchain node - type: "ws" // Type of connection (ws or rpc), - // Accounts to use instead of the default account to populate your wallet. - // The order here corresponds to the order of `web3.eth.getAccounts`, so the first one is the `defaultAccount` - /*,accounts: [ - { - privateKey: "your_private_key", - balance: "5 ether" // You can set the balance of the account in the dev environment - // Balances are in Wei, but you can specify the unit with its name - }, - { - privateKeyFile: "path/to/file", // Either a keystore or a list of keys, separated by , or ; - password: "passwordForTheKeystore" // Needed to decrypt the keystore file - }, - { - mnemonic: "12 word mnemonic", - addressIndex: "0", // Optional. The index to start getting the address - numAddresses: "1", // Optional. The number of addresses to get - hdpath: "m/44'/60'/0'/0/" // Optional. HD derivation path - }, - { - "nodeAccounts": true // Uses the Ethereum node's accounts - } - ]*/ - }, // order of connections the dapp should connect to dappConnection: [ "$WEB3", // uses pre existing web3 object if available (e.g in Mist) @@ -49,13 +21,13 @@ module.exports = { // when not specified // - explicit will only attempt to deploy the contracts that are explicitly specified inside the // contracts section. - //strategy: 'implicit', + // strategy: 'implicit', - contracts: { - // example: - //SimpleStorage: { - // args: [ 100 ] - //} + deploy: { + // SimpleStorage: { + // fromIndex: 0, + // args: [100] + // } } }, @@ -71,21 +43,17 @@ module.exports = { // merges with the settings in default // used with "embark run privatenet" - privatenet: { - }, + privatenet: {}, // merges with the settings in default // used with "embark run testnet" - testnet: { - }, + testnet: {}, // merges with the settings in default // used with "embark run livenet" - livenet: { - }, + livenet: {} // you can name an environment with specific settings and then specify with // "embark run custom_name" or "embark blockchain custom_name" - //custom_name: { - //} + // custom_name: {} }; diff --git a/dapps/tests/app/config/blockchain.js b/dapps/tests/app/config/blockchain.js new file mode 100644 index 000000000..93c090f6e --- /dev/null +++ b/dapps/tests/app/config/blockchain.js @@ -0,0 +1,84 @@ +// This file contains only the basic configuration you need to run Embark's node +// For additional configurations, see: https://embark.status.im/docs/blockchain_configuration.html +module.exports = { + // default applies to all environments + default: { + enabled: true, + client: "geth" // Can be geth or parity (default:geth) + }, + + development: { + clientConfig: { + miningMode: 'dev' // Mode in which the node mines. Options: dev, auto, always, off + }, + "accounts": [ + { + "mnemonic": "example exile argue silk regular smile grass bomb merge arm assist farm", + "balance": "5 ether" + } + ] + }, + + privatenet: { + // Accounts to use as node accounts + // The order here corresponds to the order of `web3.eth.getAccounts`, so the first one is the `defaultAccount` + // For more account configurations, see: https://embark.status.im/docs/blockchain_accounts_configuration.html + accounts: [ + { + nodeAccounts: true, // Accounts use for the node + numAddresses: "1", // Number of addresses/accounts (defaults to 1) + password: "config/development/password" // Password file for the accounts + } + ], + clientConfig: { + datadir: ".embark/privatenet/datadir", // Data directory for the databases and keystore + miningMode: 'auto', + genesisBlock: "config/privatenet/genesis.json" // Genesis block to initiate on first creation of a development node + } + }, + + privateparitynet: { + client: "parity", + genesisBlock: "config/privatenet/genesis-parity.json", + datadir: ".embark/privatenet/datadir", + miningMode: 'off' + }, + + externalnode: { + endpoint: "URL_OF_THE_NODE", // Endpoint of an node to connect to. Can be on localhost or on the internet + accounts: [ + { + mnemonic: "YOUR_MNEMONIC", + hdpath: "m/44'/60'/0'/0/", + numAddresses: "1" + } + ] + }, + + testnet: { + networkType: "testnet", // Can be: testnet, rinkeby, livenet or custom, in which case, it will use the specified networkId + syncMode: "light", + accounts: [ + { + nodeAccounts: true, + password: "config/testnet/password" + } + ] + }, + + livenet: { + networkType: "livenet", + syncMode: "light", + accounts: [ + { + nodeAccounts: true, + password: "config/livenet/password" + } + ] + } + + // you can name an environment with specific settings and then specify with + // "embark run custom_name" or "embark blockchain custom_name" + //custom_name: { + //} +}; diff --git a/dapps/tests/app/config/blockchain.json b/dapps/tests/app/config/blockchain.json deleted file mode 100644 index fd4f0a514..000000000 --- a/dapps/tests/app/config/blockchain.json +++ /dev/null @@ -1,62 +0,0 @@ -{ - "default": { - "enabled": true, - "rpcHost": "localhost", - "rpcPort": 8545, - "rpcCorsDomain": "auto", - "wsRPC": true, - "wsHost": "localhost", - "wsPort": 8546, - "wsOrigins": "auto" - }, - "development": { - "networkType": "custom", - "networkId": "1337", - "isDev": true, - "datadir": ".embark/development/datadir", - "mineWhenNeeded": true, - "nodiscover": true, - "maxpeers": 0, - "targetGasLimit": 8000000, - "proxy": true - }, - "privatenet": { - "networkType": "custom", - "networkId": "1337", - "isDev": false, - "genesisBlock": "config/privatenet/genesis.json", - "datadir": ".embark/privatenet/datadir", - "mineWhenNeeded": true, - "nodiscover": true, - "maxpeers": 0, - "account": { - "numAccounts": 3, - "balance": "5 ether", - "password": "config/privatenet/password" - }, - "targetGasLimit": 8000000, - "proxy": true - }, - "testnet": { - "networkType": "testnet", - "syncMode": "fast", - "account": { - "password": "config/ropsten/password" - } - }, - "rinkeby": { - "networkType": "rinkeby", - "syncMode": "fast", - "account": { - "password": "config/rinkeby/password" - } - }, - "livenet": { - "networkType": "livenet", - "rpcCorsDomain": "http://localhost:8000", - "wsOrigins": "http://localhost:8000", - "account": { - "password": "config/livenet/password" - } - } -} diff --git a/dapps/tests/app/config/contracts.js b/dapps/tests/app/config/contracts.js index 04e369392..d7804d560 100644 --- a/dapps/tests/app/config/contracts.js +++ b/dapps/tests/app/config/contracts.js @@ -1,16 +1,5 @@ module.exports = { default: { - deployment: { - host: "localhost", - port: 8546, - type: "ws", - accounts: [ - { - mnemonic: "example exile argue silk regular smile grass bomb merge arm assist farm", - balance: "5 ether" - } - ] - }, dappConnection: [ "ws://localhost:8546", "http://localhost:8550", @@ -19,7 +8,7 @@ module.exports = { "$WEB3" ], gas: "auto", - contracts: { + deploy: { Ownable: { deploy: false }, @@ -88,7 +77,7 @@ module.exports = { ] }, development: { - contracts: { + deploy: { MyToken2: { instanceOf: "Token", args: [2000] diff --git a/dapps/tests/app/test/another_storage_spec.js b/dapps/tests/app/test/another_storage_spec.js index b77632b01..cf39cef1e 100644 --- a/dapps/tests/app/test/another_storage_spec.js +++ b/dapps/tests/app/test/another_storage_spec.js @@ -6,7 +6,7 @@ const SimpleStorage = require('Embark/contracts/SimpleStorage'); let accounts; config({ - deployment: { + blockchain: { "accounts": [ { "mnemonic": "example exile argue silk regular smile grass bomb merge arm assist farm", @@ -15,11 +15,13 @@ config({ ] }, contracts: { - "SimpleStorage": { - args: [100] - }, - "AnotherStorage": { - args: ["$SimpleStorage"] + deploy: { + "SimpleStorage": { + args: [100] + }, + "AnotherStorage": { + args: ["$SimpleStorage"] + } } } }, (err, theAccounts) => { diff --git a/dapps/tests/app/test/array_references_spec.js b/dapps/tests/app/test/array_references_spec.js index c6f18e646..4aafc786d 100644 --- a/dapps/tests/app/test/array_references_spec.js +++ b/dapps/tests/app/test/array_references_spec.js @@ -5,19 +5,21 @@ const MyToken2 = require('Embark/contracts/MyToken2'); config({ contracts: { - "Token": { - deploy: false, - args: [1000] - }, - "MyToken2": { - instanceOf: "Token", - args: [2000] - }, - "SomeContract": { - "args": [ - ["$MyToken2", "$accounts[0]"], - 100 - ] + deploy: { + "Token": { + deploy: false, + args: [1000] + }, + "MyToken2": { + instanceOf: "Token", + args: [2000] + }, + "SomeContract": { + "args": [ + ["$MyToken2", "$accounts[0]"], + 100 + ] + } } } }); diff --git a/dapps/tests/app/test/config_spec.js b/dapps/tests/app/test/config_spec.js index aba39e462..884e62ea2 100644 --- a/dapps/tests/app/test/config_spec.js +++ b/dapps/tests/app/test/config_spec.js @@ -7,7 +7,7 @@ let gasPrice = 1; let accounts; config({ - deployment: { + blockchain: { accounts: [ // you can configure custom accounts with a custom balance // see https://embark.status.im/docs/contracts_testing.html#Configuring-accounts @@ -18,22 +18,24 @@ config({ ] }, contracts: { - "Token": { - deploy: false, - args: [1000] - }, - "MyToken2": { - instanceOf: "Token", - args: [2000] - }, - "SomeContract": { - "args": [ - ["$MyToken2", "$accounts[0]"], - 100 - ] - }, - "SimpleStorage": { - args: [100] + deploy: { + "Token": { + deploy: false, + args: [1000] + }, + "MyToken2": { + instanceOf: "Token", + args: [2000] + }, + "SomeContract": { + "args": [ + ["$MyToken2", "$accounts[0]"], + 100 + ] + }, + "SimpleStorage": { + args: [100] + } } } }, (_err, web3_accounts) => { diff --git a/dapps/tests/app/test/embarkJS_spec.js b/dapps/tests/app/test/embarkJS_spec.js index a880b24f7..b25cd2797 100644 --- a/dapps/tests/app/test/embarkJS_spec.js +++ b/dapps/tests/app/test/embarkJS_spec.js @@ -5,8 +5,10 @@ const EmbarkJS = require('Embark/EmbarkJS'); config({ contracts: { - "SimpleStorage": { - args: [100] + deploy: { + "SimpleStorage": { + args: [100] + } } } }); diff --git a/dapps/tests/app/test/interface_spec.js b/dapps/tests/app/test/interface_spec.js index ab9e51cef..d00a63764 100644 --- a/dapps/tests/app/test/interface_spec.js +++ b/dapps/tests/app/test/interface_spec.js @@ -4,8 +4,10 @@ const AnotherStorage = require('Embark/contracts/AnotherStorage'); config({ contracts: { - AnotherStorage: { - args: ['$ERC20'] + deploy: { + AnotherStorage: { + args: ['$ERC20'] + } } } }); diff --git a/dapps/tests/app/test/lib_test_spec.js b/dapps/tests/app/test/lib_test_spec.js index fe2a2729a..9865e6f9c 100644 --- a/dapps/tests/app/test/lib_test_spec.js +++ b/dapps/tests/app/test/lib_test_spec.js @@ -4,12 +4,12 @@ const Test2 = require('Embark/contracts/Test2'); config({ contracts: { - "Test2": { - }, - "ZAMyLib": { - }, - "ZAMyLib2": { - "deploy": true + deploy: { + "Test2": {}, + "ZAMyLib": {}, + "ZAMyLib2": { + "deploy": true + } } } }); diff --git a/dapps/tests/app/test/namesystem_spec.js b/dapps/tests/app/test/namesystem_spec.js index aa4024000..839de2ab6 100644 --- a/dapps/tests/app/test/namesystem_spec.js +++ b/dapps/tests/app/test/namesystem_spec.js @@ -6,16 +6,18 @@ const EmbarkJS = require('Embark/EmbarkJS'); config({ contracts: { - "Token": { - deploy: false, - args: [1000] - }, - "MyToken": { - instanceOf: "Token" - }, - "MyToken2": { - instanceOf: "Token", - args: [2000] + deploy: { + "Token": { + deploy: false, + args: [1000] + }, + "MyToken": { + instanceOf: "Token" + }, + "MyToken2": { + instanceOf: "Token", + args: [2000] + } } } }); diff --git a/dapps/tests/app/test/plugin_storage_spec.js b/dapps/tests/app/test/plugin_storage_spec.js index 623ec3cce..ef63d9b54 100644 --- a/dapps/tests/app/test/plugin_storage_spec.js +++ b/dapps/tests/app/test/plugin_storage_spec.js @@ -5,11 +5,13 @@ const SimpleStorage = require('Embark/contracts/SimpleStorage'); config({ contracts: { - "SimpleStorage": { - args: [100] - }, - "PluginStorage": { - args: ["$SimpleStorage"] + deploy: { + "SimpleStorage": { + args: [100] + }, + "PluginStorage": { + args: ["$SimpleStorage"] + } } } }); diff --git a/dapps/tests/app/test/simple_storage_spec.js b/dapps/tests/app/test/simple_storage_spec.js index 797342914..1d0b70007 100644 --- a/dapps/tests/app/test/simple_storage_spec.js +++ b/dapps/tests/app/test/simple_storage_spec.js @@ -5,9 +5,11 @@ const {Utils} = require('Embark/EmbarkJS'); config({ contracts: { - "SimpleStorage": { - args: [100], - onDeploy: ["SimpleStorage.methods.setRegistar('$SimpleStorage').send()"] + deploy: { + "SimpleStorage": { + args: [100], + onDeploy: ["SimpleStorage.methods.setRegistar('$SimpleStorage').send()"] + } } } }, (err, theAccounts) => { diff --git a/dapps/tests/app/test/token_spec.js b/dapps/tests/app/test/token_spec.js index 8ac8b07f2..0d19879f9 100644 --- a/dapps/tests/app/test/token_spec.js +++ b/dapps/tests/app/test/token_spec.js @@ -9,43 +9,45 @@ const SomeContract = require('Embark/contracts/SomeContract'); config({ contracts: { - ZAMyLib: {}, - SimpleStorage: { - args: [100] - }, - AnotherStorage: { - args: ["$SimpleStorage"] - }, - Token: { - deploy: false, - args: [1000] - }, - MyToken: { - instanceOf: "Token" - }, - MyToken2: { - instanceOf: "Token", - args: [2000] - }, - AlreadyDeployedToken: { - address: "0xCAFECAFECAFECAFECAFECAFECAFECAFECAFECAFE", - instanceOf: "Token" - }, - Test: { - onDeploy: ["Test.methods.changeAddress('$MyToken').send()", "Test.methods.changeENS('embark.eth').send()"] - }, - ContractArgs: { - args: { - initialValue: 123, - _addresses: ["$MyToken2", "$SimpleStorage"] + deploy: { + ZAMyLib: {}, + SimpleStorage: { + args: [100] + }, + AnotherStorage: { + args: ["$SimpleStorage"] + }, + Token: { + deploy: false, + args: [1000] + }, + MyToken: { + instanceOf: "Token" + }, + MyToken2: { + instanceOf: "Token", + args: [2000] + }, + AlreadyDeployedToken: { + address: "0xCAFECAFECAFECAFECAFECAFECAFECAFECAFECAFE", + instanceOf: "Token" + }, + Test: { + onDeploy: ["Test.methods.changeAddress('$MyToken').send()", "Test.methods.changeENS('embark.eth').send()"] + }, + ContractArgs: { + args: { + initialValue: 123, + _addresses: ["$MyToken2", "$SimpleStorage"] + } + }, + SomeContract: { + deployIf: "await MyToken.methods.isAvailable().call()", + args: [ + ["$MyToken2", "$SimpleStorage"], + 100 + ] } - }, - SomeContract: { - deployIf: "await MyToken.methods.isAvailable().call()", - args: [ - ["$MyToken2", "$SimpleStorage"], - 100 - ] } } }); diff --git a/dapps/tests/contracts/contracts.json b/dapps/tests/contracts/contracts.json index 253b36b80..bc5660501 100644 --- a/dapps/tests/contracts/contracts.json +++ b/dapps/tests/contracts/contracts.json @@ -3,11 +3,6 @@ "versions": { "solc": "0.4.24" }, - "deployment": { - "host": "localhost", - "port": 8545, - "type": "rpc" - }, "dappConnection": [ "$WEB3", "ws://localhost:8546", @@ -16,7 +11,7 @@ "http://localhost:8550" ], "gas": "auto", - "contracts": { + "deploy": { "Ownable": { "deploy": false }, @@ -73,7 +68,7 @@ ] }, "development": { - "contracts": { + "deploy": { "MyToken2": { "instanceOf": "Token", "args": [2000] diff --git a/dapps/tests/contracts/test/another_storage_spec.js b/dapps/tests/contracts/test/another_storage_spec.js index 5125f782c..638ac494c 100644 --- a/dapps/tests/contracts/test/another_storage_spec.js +++ b/dapps/tests/contracts/test/another_storage_spec.js @@ -6,11 +6,13 @@ let accounts; config({ contracts: { - "SimpleStorage": { - args: [100] - }, - "AnotherStorage": { - args: ["$SimpleStorage", "embark.eth"] + deploy: { + "SimpleStorage": { + args: [100] + }, + "AnotherStorage": { + args: ["$SimpleStorage", "embark.eth"] + } } } }, (err, accs) => { diff --git a/dapps/tests/contracts/test/array_references_spec.js b/dapps/tests/contracts/test/array_references_spec.js index ca11c3bb9..e53f516b2 100644 --- a/dapps/tests/contracts/test/array_references_spec.js +++ b/dapps/tests/contracts/test/array_references_spec.js @@ -6,22 +6,24 @@ const MyToken2 = require('Embark/contracts/MyToken2'); config({ contracts: { - "SimpleStorage": { - args: [100] - }, - "Token": { - deploy: false, - args: [1000] - }, - "MyToken2": { - instanceOf: "Token", - args: [2000] - }, - "SomeContract": { - "args": [ - ["$MyToken2", "$SimpleStorage"], - 100 - ] + deploy: { + "SimpleStorage": { + args: [100] + }, + "Token": { + deploy: false, + args: [1000] + }, + "MyToken2": { + instanceOf: "Token", + args: [2000] + }, + "SomeContract": { + "args": [ + ["$MyToken2", "$SimpleStorage"], + 100 + ] + } } } }); diff --git a/dapps/tests/contracts/test/lib_test_spec.js b/dapps/tests/contracts/test/lib_test_spec.js index fe2a2729a..9865e6f9c 100644 --- a/dapps/tests/contracts/test/lib_test_spec.js +++ b/dapps/tests/contracts/test/lib_test_spec.js @@ -4,12 +4,12 @@ const Test2 = require('Embark/contracts/Test2'); config({ contracts: { - "Test2": { - }, - "ZAMyLib": { - }, - "ZAMyLib2": { - "deploy": true + deploy: { + "Test2": {}, + "ZAMyLib": {}, + "ZAMyLib2": { + "deploy": true + } } } }); diff --git a/dapps/tests/contracts/test/simple_storage_spec.js b/dapps/tests/contracts/test/simple_storage_spec.js index 42b5cd2b0..aac5a4813 100644 --- a/dapps/tests/contracts/test/simple_storage_spec.js +++ b/dapps/tests/contracts/test/simple_storage_spec.js @@ -4,8 +4,10 @@ const SimpleStorage = require('Embark/contracts/SimpleStorage'); config({ contracts: { - "SimpleStorage": { - args: [100] + deploy: { + "SimpleStorage": { + args: [100] + } } } }); diff --git a/dapps/tests/contracts/test/token_spec.js b/dapps/tests/contracts/test/token_spec.js index 71aab2f24..f8d931064 100644 --- a/dapps/tests/contracts/test/token_spec.js +++ b/dapps/tests/contracts/test/token_spec.js @@ -8,42 +8,44 @@ const Test = require('Embark/contracts/Test'); config({ contracts: { - ZAMyLib: {}, - SimpleStorage: { - args: [100] - }, - AnotherStorage: { - args: ["$SimpleStorage", "0xCAFECAFECAFECAFECAFECAFECAFECAFECAFECAFE"] - }, - Token: { - deploy: false, - args: [1000] - }, - MyToken: { - instanceOf: "Token" - }, - MyToken2: { - instanceOf: "Token", - args: [2000] - }, - AlreadyDeployedToken: { - address: "0xCAFECAFECAFECAFECAFECAFECAFECAFECAFECAFE", - instanceOf: "Token" - }, - Test: { - onDeploy: ["Test.methods.changeAddress('$MyToken').send()"] - }, - ContractArgs: { - args: { - initialValue: 123, - _addresses: ["$MyToken2", "$SimpleStorage"] + deploy: { + ZAMyLib: {}, + SimpleStorage: { + args: [100] + }, + AnotherStorage: { + args: ["$SimpleStorage", "0xCAFECAFECAFECAFECAFECAFECAFECAFECAFECAFE"] + }, + Token: { + deploy: false, + args: [1000] + }, + MyToken: { + instanceOf: "Token" + }, + MyToken2: { + instanceOf: "Token", + args: [2000] + }, + AlreadyDeployedToken: { + address: "0xCAFECAFECAFECAFECAFECAFECAFECAFECAFECAFE", + instanceOf: "Token" + }, + Test: { + onDeploy: ["Test.methods.changeAddress('$MyToken').send()"] + }, + ContractArgs: { + args: { + initialValue: 123, + _addresses: ["$MyToken2", "$SimpleStorage"] + } + }, + SomeContract: { + args: [ + ["$MyToken2", "$SimpleStorage"], + 100 + ] } - }, - SomeContract: { - args: [ - ["$MyToken2", "$SimpleStorage"], - 100 - ] } } }); diff --git a/packages/embark-blockchain-connector/src/index.js b/packages/embark-blockchain-connector/src/index.js index 36653924f..04fdff4f4 100644 --- a/packages/embark-blockchain-connector/src/index.js +++ b/packages/embark-blockchain-connector/src/index.js @@ -7,11 +7,12 @@ const constants = require('embark-core/constants'); const embarkJsUtils = require('embarkjs').Utils; const {bigNumberify} = require('ethers/utils/bignumber'); const RLP = require('ethers/utils/rlp'); -import { buildUrl, dappPath } from 'embark-utils'; +import {AccountParser, buildUrl, dappPath, deconstructUrl} from 'embark-utils'; const WEB3_READY = 'blockchain:ready'; const BLOCK_LIMIT = 100; +const BALANCE_10_ETHER_IN_HEX = '0x8AC7230489E80000'; // TODO: consider another name, this is the blockchain connector class BlockchainConnector { @@ -24,7 +25,6 @@ class BlockchainConnector { this.config = embark.config; this.web3 = options.web3; this.isDev = options.isDev; - this.web3Endpoint = ''; this.isWeb3Ready = false; this.wait = options.wait; this.contractsSubscriptions = []; @@ -93,7 +93,11 @@ class BlockchainConnector { return cb(); } - let {type, host, port, accounts, protocol, coverage} = this.config.contractsConfig.deployment; + if (this.config.blockchainConfig.type === 'vm') { + return this._setupVM(cb); + } + + let {type, host, port, protocol} = deconstructUrl(this.config.blockchainConfig.endpoint); if (!protocol) { protocol = (type === "rpc") ? 'http' : 'ws'; } @@ -107,67 +111,17 @@ class BlockchainConnector { this.logger.warn('Using RPC as deployment connection type is deprecated. It is recommended to use WS.'); } - if (type === 'vm') { - const sim = self._getSimulator(); - const options = Object.assign({}, self.config.contractsConfig.deployment, { - gasPrice: "0x01", - gasLimit: "0xfffffffffffff", - allowUnlimitedContractSize: coverage - }); - self.provider = sim.provider(options); - - if (coverage) { - // Here we patch the sendAsync method on the provider. The goal behind this is to force pure/constant/view calls to become - // transactions, so that we can pull in execution traces and account for those executions in code coverage. - // - // Instead of a simple call, here's what happens: - // - // 1) A transaction is sent with the same payload, and a pre-defined gas price; - // 2) We wait for the transaction to be mined by asking for the receipt; - // 3) Once we get the receipt back, we dispatch the real call and pass the original callback; - // - // This will still allow tests to get the return value from the call and run contracts unmodified. - self.provider.realSendAsync = self.provider.sendAsync.bind(self.provider); - self.provider.sendAsync = function(payload, cb) { - if(payload.method !== 'eth_call') { - return self.provider.realSendAsync(payload, cb); - } - self.events.request('reporter:toggleGasListener'); - let newParams = Object.assign({}, payload.params[0]); - let newPayload = { - id: payload.id + 1, - method: constants.blockchain.transactionMethods.eth_sendTransaction, - params: [newParams], - jsonrpc: payload.jsonrpc - }; - - self.provider.realSendAsync(newPayload, (_err, response) => { - let txHash = response.result; - self.web3.eth.getTransactionReceipt(txHash, (_err, _res) => { - self.events.request('reporter:toggleGasListener'); - self.provider.realSendAsync(payload, cb); - }); - }); - }; - } - - self.web3.setProvider(self.provider); - self._emitWeb3Ready(); - return cb(); - } - protocol = (type === "rpc") ? protocol : 'ws'; - this.web3Endpoint = buildUrl(protocol, host, port); + const web3Endpoint = buildUrl(protocol, host, port); const providerOptions = { web3: this.web3, - accountsConfig: accounts, blockchainConfig: this.config.blockchainConfig, logger: this.logger, isDev: this.isDev, type: type, - web3Endpoint: self.web3Endpoint, + web3Endpoint, events: this.events, fs: this.fs }; @@ -214,6 +168,69 @@ class BlockchainConnector { }); } + _setupVM(cb) { + const sim = this._getSimulator(); + const coverage = !!this.config.blockchainConfig.coverage; + + let accounts = null; + if (this.config.blockchainConfig.accounts) { + accounts = AccountParser.parseAccountsConfig(this.config.blockchainConfig.accounts, this.web3, dappPath()); + accounts = accounts.map((account) => { + if (!account.hexBalance) { + account.hexBalance = BALANCE_10_ETHER_IN_HEX; + } + return {balance: account.hexBalance, secretKey: account.privateKey}; + }); + } + + const options = Object.assign(this.config.blockchainConfig.endpoint ? deconstructUrl(this.config.blockchainConfig.endpoint): {}, { + gasPrice: "0x01", + gasLimit: "0xfffffffffffff", + allowUnlimitedContractSize: coverage, + accounts + }); + this.provider = sim.provider(options); + + if (coverage) { + // Here we patch the sendAsync method on the provider. The goal behind this is to force pure/constant/view calls to become + // transactions, so that we can pull in execution traces and account for those executions in code coverage. + // + // Instead of a simple call, here's what happens: + // + // 1) A transaction is sent with the same payload, and a pre-defined gas price; + // 2) We wait for the transaction to be mined by asking for the receipt; + // 3) Once we get the receipt back, we dispatch the real call and pass the original callback; + // + // This will still allow tests to get the return value from the call and run contracts unmodified. + this.provider.realSendAsync = this.provider.sendAsync.bind(this.provider); + this.provider.sendAsync = (payload, cb) => { + if(payload.method !== 'eth_call') { + return this.provider.realSendAsync(payload, cb); + } + this.events.request('reporter:toggleGasListener'); + let newParams = Object.assign({}, payload.params[0]); + let newPayload = { + id: payload.id + 1, + method: constants.blockchain.transactionMethods.eth_sendTransaction, + params: [newParams], + jsonrpc: payload.jsonrpc + }; + + this.provider.realSendAsync(newPayload, (_err, response) => { + let txHash = response.result; + this.web3.eth.getTransactionReceipt(txHash, (_err, _res) => { + this.events.request('reporter:toggleGasListener'); + this.provider.realSendAsync(payload, cb); + }); + }); + }; + } + + this.web3.setProvider(this.provider); + this._emitWeb3Ready(); + cb(); + } + _emitWeb3Ready() { this.registerWeb3Object(() => { this.isWeb3Ready = true; diff --git a/packages/embark-blockchain-connector/src/provider.js b/packages/embark-blockchain-connector/src/provider.js index 5d486c04e..09f74af3f 100644 --- a/packages/embark-blockchain-connector/src/provider.js +++ b/packages/embark-blockchain-connector/src/provider.js @@ -9,7 +9,6 @@ const ethUtil = require('ethereumjs-util'); class Provider { constructor(options) { this.web3 = options.web3; - this.accountsConfig = options.accountsConfig; this.blockchainConfig = options.blockchainConfig; this.type = options.type; this.web3Endpoint = options.web3Endpoint; @@ -74,11 +73,7 @@ class Provider { self.logger.warn('Error while getting the node\'s accounts.', err.message || err); } - self.blockchainAccounts = AccountParser.parseAccountsConfig(self.blockchainConfig.accounts, self.web3, dappPath(), self.logger, accounts); - - accounts = accounts.concat(self.blockchainAccounts); - - self.accounts = AccountParser.parseAccountsConfig(self.accountsConfig, self.web3, dappPath(), self.logger, accounts); + self.accounts = AccountParser.parseAccountsConfig(self.blockchainConfig.accounts, self.web3, dappPath(), self.logger, accounts); if (!self.accounts.length) { self.accounts = accounts; diff --git a/packages/embark-blockchain-process/src/blockchain.js b/packages/embark-blockchain-process/src/blockchain.js index 69fab8665..29bf5088d 100644 --- a/packages/embark-blockchain-process/src/blockchain.js +++ b/packages/embark-blockchain-process/src/blockchain.js @@ -34,8 +34,8 @@ var Blockchain = function(userConfig, clientClass) { this.config = { silent: this.userConfig.silent, - ethereumClientName: this.userConfig.ethereumClientName, - ethereumClientBin: this.userConfig.ethereumClientBin || this.userConfig.ethereumClientName, + client: this.userConfig.client, + ethereumClientBin: this.userConfig.ethereumClientBin || this.userConfig.client, networkType: this.userConfig.networkType || clientClass.DEFAULTS.NETWORK_TYPE, networkId: this.userConfig.networkId || clientClass.DEFAULTS.NETWORK_ID, genesisBlock: this.userConfig.genesisBlock || false, @@ -77,7 +77,7 @@ var Blockchain = function(userConfig, clientClass) { } } - if (this.userConfig === {} || this.userConfig.default || JSON.stringify(this.userConfig) === '{"ethereumClientName":"geth"}') { + if (this.userConfig === {} || this.userConfig.default || JSON.stringify(this.userConfig) === '{"client":"geth"}') { if (this.env === 'development') { this.isDev = true; } else { @@ -455,12 +455,12 @@ export function BlockchainClient(userConfig, options) { options.logger.info("===> " + __("warning: running default config on a non-development environment")); } // if client is not set in preferences, default is geth - if (!userConfig.ethereumClientName) userConfig.ethereumClientName = constants.blockchain.clients.geth; + if (!userConfig.client) userConfig.client = constants.blockchain.clients.geth; // if clientName is set, it overrides preferences - if (options.clientName) userConfig.ethereumClientName = options.clientName; + if (options.clientName) userConfig.client = options.clientName; // Choose correct client instance based on clientName let clientClass; - switch (userConfig.ethereumClientName) { + switch (userConfig.client) { case constants.blockchain.clients.geth: clientClass = GethClient; break; @@ -469,7 +469,7 @@ export function BlockchainClient(userConfig, options) { clientClass = ParityClient; break; default: - console.error(__('Unknown client "%s". Please use one of the following: %s', userConfig.ethereumClientName, Object.keys(constants.blockchain.clients).join(', '))); + console.error(__('Unknown client "%s". Please use one of the following: %s', userConfig.client, Object.keys(constants.blockchain.clients).join(', '))); process.exit(1); } userConfig.isDev = (userConfig.isDev || userConfig.default); diff --git a/packages/embark-blockchain-process/src/index.js b/packages/embark-blockchain-process/src/index.js index b0cfc2808..80d07f925 100644 --- a/packages/embark-blockchain-process/src/index.js +++ b/packages/embark-blockchain-process/src/index.js @@ -1,6 +1,6 @@ import { __ } from 'embark-i18n'; const async = require('async'); -const { normalizeInput, buildUrlFromConfig } = require('embark-utils'); +const { normalizeInput, deconstructUrl } = require('embark-utils'); const constants = require('embark-core/constants'); import { BlockchainProcessLauncher } from './blockchainProcessLauncher'; import { pingEndpoint } from './utils'; @@ -15,7 +15,6 @@ export default class BlockchainModule { this.logger = embark.logger; this.events = embark.events; this.blockchainConfig = embark.config.blockchainConfig; - this.contractsConfig = embark.config.contractsConfig; this.embark = embark; this.locale = options.locale; this.isDev = options.isDev; @@ -41,7 +40,7 @@ export default class BlockchainModule { if (!this.ipc.isServer()) return; this.ipc.on('blockchain:node', (_message, cb) => { - cb(null, buildUrlFromConfig(this.contractsConfig.deployment)); + cb(null, this.blockchainConfig.endpoint); }); } @@ -89,10 +88,10 @@ export default class BlockchainModule { }); }, function _pingEndpoint(next) { - if (!self.contractsConfig || !self.contractsConfig.deployment || !self.contractsConfig.deployment.host) { + if (!self.blockchainConfig || !self.blockchainConfig.endpoint) { return next(); } - const {host, port, type, protocol} = self.contractsConfig.deployment; + const {host, port, type, protocol} = deconstructUrl(self.blockchainConfig.endpoint); pingEndpoint(host, port, type, protocol, self.blockchainConfig.wsOrigins.split(',')[0], next); } ], function(err) { diff --git a/packages/embark-blockchain-process/src/simulator.js b/packages/embark-blockchain-process/src/simulator.js index 8c58ea386..7af4390ad 100644 --- a/packages/embark-blockchain-process/src/simulator.js +++ b/packages/embark-blockchain-process/src/simulator.js @@ -19,6 +19,7 @@ export class Simulator { let useProxy = this.blockchainConfig.proxy || false; let host = (dockerHostSwap(options.host || this.blockchainConfig.rpcHost) || defaultHost); + // TODO change this const configPort = this.contractsConfig.deployment.type === 'rpc' ? this.blockchainConfig.rpcPort : this.blockchainConfig.wsPort; let port = (options.port || configPort || 8545); port = parseInt(port, 10) + (useProxy ? constants.blockchain.servicePortOnProxy : 0); diff --git a/packages/embark-code-generator/src/index.js b/packages/embark-code-generator/src/index.js index 92f24b049..c33a0a284 100644 --- a/packages/embark-code-generator/src/index.js +++ b/packages/embark-code-generator/src/index.js @@ -172,7 +172,7 @@ class CodeGenerator { dappConnection: contractConfig.dappConnection, dappAutoEnable: contractConfig.dappAutoEnable, warnIfMetamask: this.blockchainConfig.isDev, - blockchainClient: this.blockchainConfig.ethereumClientName + blockchainClient: this.blockchainConfig.client }; this.generateArtifact(this.dappConfigs.blockchain, constants.dappArtifacts.blockchain, constants.dappArtifacts.dir, (err, path, _updated) => { callback(err, path); diff --git a/packages/embark-test-runner/src/test.js b/packages/embark-test-runner/src/test.js index 3ac2428d4..f312628f2 100644 --- a/packages/embark-test-runner/src/test.js +++ b/packages/embark-test-runner/src/test.js @@ -1,12 +1,10 @@ import { __ } from 'embark-i18n'; -import { deconstructUrl, prepareContractsConfig, AccountParser } from 'embark-utils'; +import { deconstructUrl, prepareContractsConfig, buildUrl } from 'embark-utils'; const async = require('async'); const web3Utils = require('web3-utils'); import { GAS_LIMIT } from './constants'; -const BALANCE_10_ETHER_IN_HEX = '0x8AC7230489E80000'; - class Test { constructor(options) { this.options = options || {}; @@ -64,15 +62,6 @@ class Test { } initWeb3Provider(callback) { - if (this.simOptions.accounts) { - this.simOptions.accounts = this.simOptions.accounts.map((account) => { - if (!account.hexBalance) { - account.hexBalance = BALANCE_10_ETHER_IN_HEX; - } - return {balance: account.hexBalance, secretKey: account.privateKey}; - }); - } - if (!this.simOptions.host && (this.options.node && this.options.node === 'vm')) { this.simOptions.type = 'vm'; } else if (this.simOptions.host || (this.options.node && this.options.node !== 'vm')) { @@ -87,9 +76,12 @@ class Test { Object.assign(this.simOptions, options); } - this.configObj.contractsConfig.deployment = this.simOptions; - this.configObj.contractsConfig.deployment.coverage = this.options.coverage; - this.events.request("config:contractsConfig:set", this.configObj.contractsConfig, () => { + this.configObj.blockchainConfig.endpoint = this.simOptions.host ? buildUrl(this.simOptions.protocol, this.simOptions.host, this.simOptions.port, this.simOptions.type) : null; + this.configObj.blockchainConfig.type = this.simOptions.type; + this.configObj.blockchainConfig.accounts = this.simOptions.accounts; + this.configObj.blockchainConfig.coverage = this.options.coverage; + this.logger.trace('Setting blockchain configs:', this.configObj.blockchainConfig); + this.events.request('config:blockchainConfig:set', this.configObj.blockchainConfig, () => { this.events.request('blockchain:reset', (err) => { if (err) { this.logger.error('Error restarting the blockchain connection'); @@ -137,9 +129,10 @@ class Test { } checkDeploymentOptions(options, callback) { - const self = this; let resetServices = false; - const {host, port, type, accounts} = options.deployment || {}; + const blockchainConfig = options.blockchain || {}; + const {host, port, type, protocol} = blockchainConfig.endpoint ? deconstructUrl(blockchainConfig.endpoint) : {}; + const accounts = blockchainConfig.accounts; if (host && port && !['rpc', 'ws'].includes(type)) { return callback(__("contracts config error: unknown deployment type %s", type)); @@ -155,32 +148,21 @@ class Test { resetServices = true; } - this.events.request("blockchain:get", (web3) => { - if (accounts) { - self.simOptions.accounts = AccountParser.parseAccountsConfig(accounts, web3, this.dappPath); - } else { - self.simOptions.accounts = null; + Object.assign(this.simOptions, {host, port, type, protocol}); + this.simOptions.accounts = accounts; + + if (!resetServices && !this.firstRunConfig) { + return callback(); + } + + this.initWeb3Provider((err) => { + if (err) { + return callback(err); } - - Object.assign(self.simOptions, { - host, - port, - type - }); - - if (!resetServices && !self.firstRunConfig) { - return callback(); - } - - self.initWeb3Provider((err) => { - if (err) { - return callback(err); - } - self.firstRunConfig = false; - self.events.request("blockchain:ready", () => { - self.events.request("code-generator:embarkjs:build", () => { - self.events.request("runcode:embarkjs:reset", callback); - }); + this.firstRunConfig = false; + this.events.request("blockchain:ready", () => { + this.events.request("code-generator:embarkjs:build", () => { + this.events.request("runcode:embarkjs:reset", callback); }); }); }); @@ -275,11 +257,13 @@ class Test { async _deploy(config, callback) { const self = this; + let contractConfig = config.contracts || {}; async.waterfall([ function setConfig(next) { - prepareContractsConfig(config); + contractConfig = prepareContractsConfig(contractConfig); self.events.request('config:contractsConfig:set', - {contracts: config.contracts, versions: self.versions_default}, next); + // TODO find out what versions_default is where it went + {contracts: contractConfig.contracts, versions: self.versions_default}, next); }, function getAccounts(next) { self.events.request('blockchain:getAccounts', (err, accounts) => { diff --git a/packages/embark-utils/src/index.js b/packages/embark-utils/src/index.js index 716f58479..efc9249ba 100644 --- a/packages/embark-utils/src/index.js +++ b/packages/embark-utils/src/index.js @@ -154,16 +154,20 @@ function toposort(graph) { } function deconstructUrl(endpoint) { - const matches = endpoint.match(/(ws|https?):\/\/([a-zA-Z0-9_.-]*):?([0-9]*)?/); + const matches = endpoint.match(/(wss?|https?):\/\/([a-zA-Z0-9_.-]*):?([0-9]*)?/); return { protocol: matches[1], host: matches[2], port: matches[3], - type: matches[1] === 'ws' ? 'ws' : 'rpc' + type: matches[1] === 'ws' || matches[1] === 'wss' ? 'ws' : 'rpc' }; } function prepareContractsConfig(config) { + if (config.deploy) { + config.contracts = config.deploy; + delete config.deploy; + } Object.keys(config.contracts).forEach((contractName) => { const gas = config.contracts[contractName].gas; const gasPrice = config.contracts[contractName].gasPrice; diff --git a/packages/embark/src/cmd/cmd.js b/packages/embark/src/cmd/cmd.js index d5f7423d2..f9b253082 100644 --- a/packages/embark/src/cmd/cmd.js +++ b/packages/embark/src/cmd/cmd.js @@ -2,7 +2,6 @@ import { __, setOrDetectLocale } from 'embark-i18n'; import { diagramPath } from 'embark-utils'; const program = require('commander'); const EmbarkController = require('./cmd_controller.js'); -const fs = require('../lib/core/fs.js'); let embark = new EmbarkController(); diff --git a/packages/embark/src/lib/core/config.js b/packages/embark/src/lib/core/config.js index be691c0a8..53aaa2318 100644 --- a/packages/embark/src/lib/core/config.js +++ b/packages/embark/src/lib/core/config.js @@ -23,6 +23,8 @@ import { const cloneDeep = require('lodash.clonedeep'); const { replaceZeroAddressShorthand } = AddressUtils; +import {getBlockchainDefaults, getContractDefaults} from './configDefaults'; + const DEFAULT_CONFIG_PATH = 'config/'; const PACKAGE = require('../../../package.json'); @@ -62,6 +64,11 @@ var Config = function(options) { cb(); }); + self.events.setCommandHandler("config:blockchainConfig:set", (config, cb) => { + self.blockchainConfig = config; + cb(); + }); + self.events.setCommandHandler("config:contractsFiles", (cb) => { cb(self.contractsFiles); }); @@ -217,38 +224,42 @@ Config.prototype._updateBlockchainCors = function(){ } }; -Config.prototype._mergeConfig = function(configFilePath, defaultConfig, env, enabledByDefault) { +Config.prototype._loadConfigFile = function (configFilePath, defaultConfig, enabledByDefault) { if (!configFilePath) { - let configToReturn = defaultConfig['default'] || {}; + const configToReturn = defaultConfig['default'] || {}; configToReturn.enabled = enabledByDefault || false; return configToReturn; } - - // due to embark.json; TODO: refactor this configFilePath = configFilePath.replace('.json','').replace('.js', ''); - if (!fs.existsSync(configFilePath + '.js') && !fs.existsSync(configFilePath + '.json')) { - // TODO: remove this if - if (this.logger) { - this.logger.warn(__("no config file found at %s using default config", configFilePath)); - } - return defaultConfig['default'] || {}; - } - let config; if (fs.existsSync(configFilePath + '.js')) { delete require.cache[configFilePath + '.js']; config = require(configFilePath + '.js'); - } else { + } else if (fs.existsSync(configFilePath + '.json')) { config = fs.readJSONSync(configFilePath + '.json'); + } else { + this.logger.warn(__("no config file found at %s using default config", configFilePath)); + return defaultConfig['default'] || {}; } + return config; +}; + +Config.prototype._doMergeConfig = function(config, defaultConfig, env) { let configObject = recursiveMerge(defaultConfig, config); if (env) { return recursiveMerge(configObject['default'] || {}, configObject[env]); + } else if (env !== false) { + this.logger.warn(__("No environment called %s found. Using defaults.", env)); } return configObject; }; +Config.prototype._mergeConfig = function(configFilePath, defaultConfig, env, enabledByDefault) { + const config = this._loadConfigFile(configFilePath, defaultConfig, enabledByDefault); + return this._doMergeConfig(config, defaultConfig, env, enabledByDefault); +}; + Config.prototype._getFileOrObject = function(object, filePath, property) { if (typeof object === 'object') { return object[property] ? dappPath(object[property]) : object[property]; @@ -256,21 +267,47 @@ Config.prototype._getFileOrObject = function(object, filePath, property) { return dappPath(object, filePath); }; +/*eslint complexity: ["error", 30]*/ Config.prototype.loadBlockchainConfigFile = function() { - var configObject = { - default: { - enabled: true, - ethereumClientName: constants.blockchain.clients.geth, - rpcCorsDomain: "auto", - wsOrigins: "auto", - proxy: true, - datadir: '.embark/' + this.env + '/datadir' + const blockchainDefaults = getBlockchainDefaults(this.env); + const configFilePath = this._getFileOrObject(this.configDir, 'blockchain', 'blockchain'); + + const userConfig = this._loadConfigFile(configFilePath, blockchainDefaults, true); + const envConfig = userConfig[this.env]; + + if (envConfig) { + if (envConfig.clientConfig) { + Object.assign(envConfig, envConfig.clientConfig); + delete envConfig.clientConfig; + } + switch (envConfig.miningMode) { + case 'dev': envConfig.isDev = true; break; + case 'auto': envConfig.isDev = false; envConfig.mineWhenNeeded = true; break; + case 'always': envConfig.isDev = false; envConfig.mineWhenNeeded = false; envConfig.mine = true; break; + case 'off': envConfig.isDev = false; envConfig.mineWhenNeeded = false; envConfig.mine = false; break; + default: envConfig.isDev = false; + } + if (envConfig.cors) { + const autoIndex = envConfig.cors.indexOf('auto'); + envConfig.rpcCorsDomain = {}; + envConfig.wsOrigins = {}; + if (autoIndex > -1) { + envConfig.rpcCorsDomain.auto = true; + envConfig.wsOrigins.auto = true; + envConfig.cors.splice(autoIndex, 1); + } else { + envConfig.rpcCorsDomain.auto = false; + envConfig.wsOrigins.auto = false; + } + envConfig.rpcCorsDomain.additionalCors = envConfig.cors; + envConfig.wsOrigins.additionalCors = envConfig.cors; + delete envConfig.cors; } - }; - let configFilePath = this._getFileOrObject(this.configDir, 'blockchain', 'blockchain'); + userConfig[this.env] = envConfig; + } - this.blockchainConfig = this._mergeConfig(configFilePath, configObject, this.env, true); + this.blockchainConfig = this._doMergeConfig(userConfig, blockchainDefaults, this.env); if (!configFilePath) { this.blockchainConfig.default = true; } @@ -291,6 +328,19 @@ Config.prototype.loadBlockchainConfigFile = function() { }); } + if (!this.blockchainConfig.endpoint) { + const urlConfig = (this.blockchainConfig.wsHost) ? { + host: this.blockchainConfig.wsHost, + port: this.blockchainConfig.wsPort, + type: 'ws' + } : { + host: this.blockchainConfig.rpcHost, + port: this.blockchainConfig.rpcPort, + type: 'rpc' + }; + this.blockchainConfig.endpoint = buildUrlFromConfig(urlConfig); + } + if ( !this.shownNoAccountConfigMsg && (/rinkeby|testnet|livenet/).test(this.blockchainConfig.networkType) && @@ -333,31 +383,9 @@ Config.prototype.loadBlockchainConfigFile = function() { }; Config.prototype.loadContractsConfigFile = function() { - var defaultVersions = { - "web3": "1.0.0-beta", - "solc": "0.5.0" - }; - var versions = recursiveMerge(defaultVersions, this.embarkConfig.versions || {}); + let configObject = getContractDefaults(this.embarkConfig.versions); - var configObject = { - "default": { - "versions": versions, - "deployment": { - "host": "localhost", "port": 8545, "type": "rpc" - }, - "dappConnection": [ - "$WEB3", - "localhost:8545" - ], - "dappAutoEnable": true, - "strategy": constants.deploymentStrategy.implicit, - "gas": "auto", - "contracts": { - } - } - }; - - var contractsConfigs = this.plugins.getPluginsProperty('contractsConfig', 'contractsConfigs'); + const contractsConfigs = this.plugins.getPluginsProperty('contractsConfig', 'contractsConfigs'); contractsConfigs.forEach(function(pluginConfig) { configObject = recursiveMerge(configObject, pluginConfig); }); @@ -367,13 +395,6 @@ Config.prototype.loadContractsConfigFile = function() { if (newContractsConfig.gas.match(unitRegex)) { newContractsConfig.gas = getWeiBalanceFromString(newContractsConfig.gas, web3); } - if (newContractsConfig.deployment && 'accounts' in newContractsConfig.deployment) { - newContractsConfig.deployment.accounts.forEach((account) => { - if (account.balance && account.balance.match(unitRegex)) { - account.balance = getWeiBalanceFromString(account.balance, web3); - } - }); - } newContractsConfig = prepareContractsConfig(newContractsConfig); diff --git a/packages/embark/src/lib/core/configDefaults.js b/packages/embark/src/lib/core/configDefaults.js new file mode 100644 index 000000000..a86510f6a --- /dev/null +++ b/packages/embark/src/lib/core/configDefaults.js @@ -0,0 +1,57 @@ +import {recursiveMerge} from "embark-utils"; + +const constants = require('embark-core/constants'); + +export function getBlockchainDefaults(env) { + return { + default: { + enabled: true, + client: constants.blockchain.clients.geth, + proxy: true, + datadir: `.embark/${env}/datadir`, + rpcHost: "localhost", + rpcPort: 8545, + rpcCorsDomain: { + auto: true, + additionalCors: [] + }, + wsRPC: true, + wsOrigins: { + auto: true, + additionalCors: [] + }, + wsHost: "localhost", + wsPort: 8546, + networkType: "custom", + isDev: false, + mineWhenNeeded: false, + nodiscover: true, + maxpeers: 0, + targetGasLimit: 8000000, + simulatorBlocktime: 0 + } + }; +} + +export function getContractDefaults(embarkConfigVersions) { + const defaultVersions = { + "web3": "1.0.0-beta", + "solc": "0.5.0" + }; + const versions = recursiveMerge(defaultVersions, embarkConfigVersions || {}); + + return { + "default": { + "versions": versions, + "dappConnection": [ + "$WEB3", + "localhost:8545" + ], + "dappAutoEnable": true, + "strategy": constants.deploymentStrategy.implicit, + "gas": "auto", + "deploy": { + } + } + }; +} diff --git a/packages/embark/src/test/blockchain.js b/packages/embark/src/test/blockchain.js index be6485d3e..1a3bd73b2 100644 --- a/packages/embark/src/test/blockchain.js +++ b/packages/embark/src/test/blockchain.js @@ -17,7 +17,7 @@ describe('embark.Blockchain', function() { const expectedConfig = { networkType: 'custom', genesisBlock: false, - ethereumClientName: 'geth', + client: 'geth', ethereumClientBin: 'geth', datadir: dappPath(".embark/development/datadir"), mineWhenNeeded: false, @@ -56,7 +56,7 @@ describe('embark.Blockchain', function() { let config = { networkType: 'livenet', genesisBlock: 'foo/bar/genesis.json', - ethereumClientName: 'parity', + client: 'parity', ethereumClientBin: 'parity', datadir: '/foo/datadir/', mineWhenNeeded: true, @@ -98,7 +98,7 @@ describe('embark.Blockchain', function() { let expectedConfig = { networkType: 'livenet', genesisBlock: 'foo/bar/genesis.json', - ethereumClientName: 'parity', + client: 'parity', ethereumClientBin: 'parity', datadir: '/foo/datadir/', mineWhenNeeded: true, diff --git a/packages/embark/src/test/config.js b/packages/embark/src/test/config.js index 63a0848da..37b8c2058 100644 --- a/packages/embark/src/test/config.js +++ b/packages/embark/src/test/config.js @@ -5,7 +5,6 @@ const Plugins = require('../lib/core/plugins.js'); const assert = require('assert'); const TestLogger = require('../lib/utils/test_logger'); const Events = require('../lib/core/events'); -const fs = require('../lib/core/fs'); describe('embark.Config', function () { let config = new Config({ @@ -21,23 +20,33 @@ describe('embark.Config', function () { config.loadBlockchainConfigFile(); let expectedConfig = { "enabled": true, - "ethereumClientName": "geth", - "networkType": "custom", - "genesisBlock": "config/development/genesis.json", - "datadir": ".embark/development/datadir", - "isDev": false, - "mineWhenNeeded": true, - "nodiscover": true, + "client": "geth", "proxy": true, + "datadir": ".embark/myenv/datadir", "rpcHost": "localhost", "rpcPort": 8545, - "rpcCorsDomain": "http://localhost:8000", - "wsOrigins": "auto", - "accounts": [ - { - "password": "config/development/password" - } - ] + "rpcCorsDomain": { + "auto": true, + "additionalCors": [] + }, + "wsRPC": true, + "wsOrigins": { + "auto": true, + "additionalCors": [] + }, + "wsHost": "localhost", + "wsPort": 8546, + "networkType": "custom", + "isDev": false, + "mineWhenNeeded": false, + "nodiscover": true, + "maxpeers": 0, + "targetGasLimit": 8000000, + "simulatorBlocktime": 0, + "clientMode": { + "miningMode": "auto" + }, + "endpoint": "ws://localhost:8546" }; assert.deepEqual(config.blockchainConfig, expectedConfig); @@ -46,26 +55,41 @@ describe('embark.Config', function () { it('should convert Ether units', function () { let expectedConfig = { "enabled": true, - "ethereumClientName": "geth", - "networkType": "custom", - "genesisBlock": "config/development/genesis.json", - "datadir": ".embark/development/datadir", - "isDev": false, - "targetGasLimit": "300000", - "gasPrice": "8000000", - "mineWhenNeeded": true, - "nodiscover": true, + "client": "geth", "proxy": true, + "datadir": ".embark/unitenv/datadir", "rpcHost": "localhost", "rpcPort": 8545, - "rpcCorsDomain": "http://localhost:8000", - "wsOrigins": "auto", + "rpcCorsDomain": { + "auto": true, + "additionalCors": [] + }, + "wsRPC": true, + "wsOrigins": { + "auto": true, + "additionalCors": [] + }, + "wsHost": "localhost", + "wsPort": 8546, + "networkType": "custom", + "isDev": false, + "mineWhenNeeded": false, + "nodiscover": true, + "maxpeers": 0, + "targetGasLimit": 8000000, + "simulatorBlocktime": 0, + "clientMode": { + "miningMode": "auto", + "gasPrice": "8 Mwei", + "targetGasLimit": "300 Kwei" + }, "accounts": [ { "password": "config/development/password", "balance": "3000000000000000000" } - ] + ], + "endpoint": "ws://localhost:8546" }; let config = new Config({ @@ -83,26 +107,41 @@ describe('embark.Config', function () { it('should accept unitless gas values', function () { let expectedConfig = { "enabled": true, - "ethereumClientName": "geth", - "networkType": "custom", - "genesisBlock": "config/development/genesis.json", - "datadir": ".embark/development/datadir", - "isDev": false, - "targetGasLimit": "20000000", - "gasPrice": "8000000", - "mineWhenNeeded": true, - "nodiscover": true, + "client": "geth", "proxy": true, + "datadir": ".embark/unitlessenv/datadir", "rpcHost": "localhost", "rpcPort": 8545, - "rpcCorsDomain": "http://localhost:8000", - "wsOrigins": "auto", + "rpcCorsDomain": { + "auto": true, + "additionalCors": [] + }, + "wsRPC": true, + "wsOrigins": { + "auto": true, + "additionalCors": [] + }, + "wsHost": "localhost", + "wsPort": 8546, + "networkType": "custom", + "isDev": false, + "mineWhenNeeded": false, + "nodiscover": true, + "maxpeers": 0, + "targetGasLimit": 8000000, + "simulatorBlocktime": 0, + "clientMode": { + "miningMode": "auto", + "gasPrice": "8000000", + "targetGasLimit": "20000000" + }, "accounts": [ { "password": "config/development/password", "balance": "3000000000000000000" } - ] + ], + "endpoint": "ws://localhost:8546" }; let config = new Config({ @@ -123,7 +162,6 @@ describe('embark.Config', function () { config.loadContractsConfigFile(); let expectedConfig = { versions: {'web3': '1.0.0-beta', solc: '0.5.0'}, - deployment: {host: 'localhost', port: 8545, type: 'rpc', "accounts": [{"mnemonic": "12 word mnemonic", "balance": "5000000000"}]}, dappConnection: ['$WEB3', 'localhost:8545'], dappAutoEnable: true, "gas": "400000", @@ -146,7 +184,6 @@ describe('embark.Config', function () { it('should replace occourences of `0x0` with full zero addresses', () => { let expectedConfig = { versions: {'web3': '1.0.0-beta', solc: '0.5.0'}, - deployment: {host: 'localhost', port: 8545, type: 'rpc'}, dappConnection: ['$WEB3', 'localhost:8545'], dappAutoEnable: true, "gas": "auto", diff --git a/packages/embark/src/test/test1/config/blockchain.json b/packages/embark/src/test/test1/config/blockchain.json index f267daff2..417bbbcb0 100644 --- a/packages/embark/src/test/test1/config/blockchain.json +++ b/packages/embark/src/test/test1/config/blockchain.json @@ -1,32 +1,15 @@ { "myenv": { - "networkType": "custom", - "genesisBlock": "config/development/genesis.json", - "datadir": ".embark/development/datadir", - "isDev": false, - "mineWhenNeeded": true, - "nodiscover": true, - "rpcHost": "localhost", - "rpcPort": 8545, - "rpcCorsDomain": "http://localhost:8000", - "accounts": [ - { - "password": "config/development/password" - } - ] + "clientMode": { + "miningMode": "auto" + } }, "unitenv": { - "networkType": "custom", - "genesisBlock": "config/development/genesis.json", - "datadir": ".embark/development/datadir", - "isDev": false, - "gasPrice": "8 Mwei", - "mineWhenNeeded": true, - "nodiscover": true, - "rpcHost": "localhost", - "rpcPort": 8545, - "rpcCorsDomain": "http://localhost:8000", - "targetGasLimit": "300 Kwei", + "clientMode": { + "miningMode": "auto", + "gasPrice": "8 Mwei", + "targetGasLimit": "300 Kwei" + }, "accounts": [ { "password": "config/development/password", @@ -35,17 +18,12 @@ ] }, "unitlessenv": { - "networkType": "custom", - "genesisBlock": "config/development/genesis.json", - "datadir": ".embark/development/datadir", - "isDev": false, + + "clientMode": { + "miningMode": "auto", "gasPrice": "8000000", - "mineWhenNeeded": true, - "nodiscover": true, - "rpcHost": "localhost", - "rpcPort": 8545, - "rpcCorsDomain": "http://localhost:8000", - "targetGasLimit": "20000000", + "targetGasLimit": "20000000" + }, "accounts": [ { "password": "config/development/password", @@ -54,15 +32,10 @@ ] }, "testnet": { - "networkType": "testnet", - "rpcHost": "localhost", - "rpcPort": 8545 + "networkType": "testnet" }, "livenet": { "networkType": "livenet", - "rpcHost": "localhost", - "rpcPort": 8545, - "rpcCorsDomain": "http://localhost:8000", "accounts": [ { "password": "config/development/password" @@ -70,9 +43,6 @@ ] }, "privatenet": { - "networkType": "custom", - "rpcHost": "localhost", - "rpcPort": 8545, "datadir": "yourdatadir", "networkId": "123", "nodes": [] diff --git a/packages/embark/src/test/test1/config/contracts.json b/packages/embark/src/test/test1/config/contracts.json index 0aa1d1c4e..f23b06e8d 100644 --- a/packages/embark/src/test/test1/config/contracts.json +++ b/packages/embark/src/test/test1/config/contracts.json @@ -1,7 +1,7 @@ { "default": { "gas": "auto", - "contracts": { + "deploy": { "SimpleStorage": { "args": [ 100 @@ -11,7 +11,7 @@ }, "zeroaddress": { "gas": "auto", - "contracts": { + "deploy": { "SimpleStorage": { "address": "0x0", "args": [ @@ -30,7 +30,7 @@ }, "myenv": { "gas": "400 Kwei", - "contracts": { + "deploy": { "SimpleStorage": { "gas": "123 Kwei", "gasPrice": "1 Kwei" @@ -40,14 +40,6 @@ 200 ] } - }, - "deployment": { - "accounts": [ - { - "mnemonic": "12 word mnemonic", - "balance": "5000 Mwei" - } - ] } } } diff --git a/site/source/docs/blockchain_configuration.md b/site/source/docs/blockchain_configuration.md index 66c15c279..54966ab02 100644 --- a/site/source/docs/blockchain_configuration.md +++ b/site/source/docs/blockchain_configuration.md @@ -29,7 +29,7 @@ module.exports = { wsPort: 8546 }, development: { - ethereumClientName: "geth", + client: "geth", ethereumClientBin: "geth", datadir: ".embark/development/datadir", networkType: "custom", @@ -61,7 +61,7 @@ Option | Type: `default` | Value `wsOrigins` | object | Same as `rpcCorsDomain`, but for the Websocket server `wsHost` | string: `localhost` | Same as `rpcHost`, but for the Websocket server `wsPort` | number: `8546` | Same as `rpcPort`, but for the Websocket server -`ethereumClientName` | string: `geth` | Client to use for the Ethereum node. Currently supported: `geth` and `parity` +`client` | string: `geth` | Client to use for the Ethereum node. Currently supported: `geth` and `parity` `ethereumClientBin` | string: `geth` | Path to the client binary. By default, Embark uses the client name as an executable (if it is in the PATH) `datadir` | string | Directory where to put the Node's data (eg: keystores) `networkType` | string: `custom` | Can be: `testnet`, `rinkeby`, `kovan` or custom, in which case, it will use the specified `networkId`