fix(@embark/accounts-manager): limit funding accounts to 1 at a time

This commit is contained in:
Jonathan Rainville 2019-11-06 14:45:27 -05:00
parent 776db1b7f7
commit 95b5ae48c6
2 changed files with 22 additions and 6 deletions

View File

@ -4,13 +4,15 @@ const AnotherStorage = require('Embark/contracts/AnotherStorage');
const SimpleStorage = require('Embark/contracts/SimpleStorage');
let accounts, defaultAccount;
const numAddresses = 10;
config({
blockchain: {
"accounts": [
{
"mnemonic": "example exile argue silk regular smile grass bomb merge arm assist farm",
balance: "5ether"
balance: "5ether",
numAddresses: 10
}
]
},
@ -42,6 +44,16 @@ contract("AnotherStorage", function() {
assert.ok(parseInt(balance, 10) <= 5000000000000000000);
});
it("should have the right balance for all other accounts ", async function() {
let balance;
for (let i = 1; i < numAddresses - 3; i++) {
balance = await web3.eth.getBalance(accounts[i]);
console.log('Account', i , balance);
assert.strictEqual(parseInt(balance, 10), 5000000000000000000, `Account ${i} doesn't have the balance set`);
}
});
it("set SimpleStorage address", async function() {
let result = await AnotherStorage.methods.simpleStorageAddress().call();
assert.equal(result.toString(), SimpleStorage.options.address);

View File

@ -148,12 +148,16 @@ export default class AccountsManager {
}
try {
const coinbase = await web3.eth.getCoinbase();
const fundingAccounts = this.accounts
.filter((account) => account.address)
.map((account) => {
return fundAccount(web3, account.address, coinbase, account.hexBalance);
const accts = this.accounts
.filter((account) => account.address);
async.eachLimit(accts, 1, (acct, eachCb) => {
fundAccount(web3, acct.address, coinbase, acct.hexBalance)
.then(() => {
eachCb();
})
.catch(eachCb);
});
await Promise.all([fundingAccounts]);
} catch (err) {
this.logger.error(__("Error funding accounts"), err.message || err);
}