mirror of https://github.com/embarklabs/embark.git
enable using accounts and balances
This commit is contained in:
parent
ac631f90dc
commit
30a8263569
|
@ -6,6 +6,7 @@ const utils = require('../utils/utils');
|
|||
const constants = require('../constants');
|
||||
const Events = require('../core/events');
|
||||
const cloneDeep = require('clone-deep');
|
||||
const AccountParser = require('../contracts/accountParser');
|
||||
|
||||
function getSimulator() {
|
||||
try {
|
||||
|
@ -36,12 +37,7 @@ class Test {
|
|||
this.compiledContracts = {};
|
||||
|
||||
this.web3 = new Web3();
|
||||
if (this.simOptions.node) {
|
||||
this.web3.setProvider(new this.web3.providers.HttpProvider(this.simOptions.node));
|
||||
} else {
|
||||
this.sim = getSimulator();
|
||||
this.web3.setProvider(this.sim.provider(this.simOptions));
|
||||
}
|
||||
this.initWeb3Provider();
|
||||
|
||||
this.engine = new Engine({
|
||||
env: this.options.env || 'test',
|
||||
|
@ -55,11 +51,32 @@ class Test {
|
|||
});
|
||||
|
||||
this.versions_default = this.engine.config.contractsConfig.versions;
|
||||
const deploymentConfig = this.engine.config.contractsConfig.versions;
|
||||
// Reset contract config to nothing to make sure we deploy only what we want
|
||||
this.engine.config.contractsConfig = {contracts: {}, versions: this.versions_default};
|
||||
this.engine.config.contractsConfig = {contracts: {}, versions: this.versions_default, deployment: deploymentConfig};
|
||||
|
||||
this.engine.startService("libraryManager");
|
||||
this.engine.startService("codeRunner");
|
||||
this.initDeployServices();
|
||||
this.engine.startService("codeGenerator");
|
||||
}
|
||||
|
||||
initWeb3Provider() {
|
||||
if (this.simOptions.node) {
|
||||
this.web3.setProvider(new this.web3.providers.HttpProvider(this.simOptions.node));
|
||||
} else {
|
||||
if (this.simOptions.accounts) {
|
||||
this.simOptions.accounts = this.simOptions.accounts.map((account, index) => {
|
||||
return {balance: this.options.deployment.accounts[index].balance || 0xFFFFFFFFFFFFFFFFFF,
|
||||
secretKey: account.privateKey};
|
||||
});
|
||||
}
|
||||
this.sim = getSimulator();
|
||||
this.web3.setProvider(this.sim.provider(this.simOptions));
|
||||
}
|
||||
}
|
||||
|
||||
initDeployServices() {
|
||||
this.engine.startService("web3", {
|
||||
web3: this.web3
|
||||
});
|
||||
|
@ -67,7 +84,6 @@ class Test {
|
|||
trackContracts: false,
|
||||
ipcRole: 'client'
|
||||
});
|
||||
this.engine.startService("codeGenerator");
|
||||
}
|
||||
|
||||
init(callback) {
|
||||
|
@ -100,6 +116,13 @@ class Test {
|
|||
this.simOptions = this.options.simulatorOptions || {};
|
||||
this.ready = false;
|
||||
|
||||
if (this.options.deployment && this.options.deployment.accounts) {
|
||||
// Account setup
|
||||
this.simOptions.accounts = AccountParser.parseAccountsConfig(this.options.deployment.accounts, this.web3);
|
||||
this.initWeb3Provider();
|
||||
this.initDeployServices();
|
||||
}
|
||||
|
||||
// Reset contracts
|
||||
this.engine.contractsManager.contracts = cloneDeep(this.builtContracts);
|
||||
this.engine.contractsManager.compiledContracts = cloneDeep(this.compiledContracts);
|
||||
|
|
|
@ -4,6 +4,13 @@ const AnotherStorage = embark.require('Embark/contracts/AnotherStorage');
|
|||
const SimpleStorage = embark.require('Embark/contracts/SimpleStorage');
|
||||
|
||||
config({
|
||||
deployment: {
|
||||
"accounts": [
|
||||
{
|
||||
"mnemonic": "example exile argue silk regular smile grass bomb merge arm assist farm"
|
||||
}
|
||||
]
|
||||
},
|
||||
contracts: {
|
||||
"SimpleStorage": {
|
||||
args: [100]
|
||||
|
|
Loading…
Reference in New Issue