2018-11-29 07:12:00 +00:00
|
|
|
/*global embark, config, it, web3*/
|
2019-05-07 19:49:22 +00:00
|
|
|
const {__} = require('embark-i18n');
|
2018-11-29 07:12:00 +00:00
|
|
|
const assert = require('assert');
|
|
|
|
|
|
|
|
let gasUsedForDeploy = 0;
|
|
|
|
let gasPrice = 1;
|
|
|
|
let accounts;
|
|
|
|
|
|
|
|
config({
|
2019-08-30 20:50:20 +00:00
|
|
|
blockchain: {
|
2018-11-29 07:12:00 +00:00
|
|
|
accounts: [
|
|
|
|
// you can configure custom accounts with a custom balance
|
|
|
|
// see https://embark.status.im/docs/contracts_testing.html#Configuring-accounts
|
|
|
|
{
|
|
|
|
privateKey: "random",
|
|
|
|
balance: "100000 ether"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
contracts: {
|
2019-08-30 20:50:20 +00:00
|
|
|
deploy: {
|
|
|
|
"Token": {
|
|
|
|
deploy: false,
|
|
|
|
args: [1000]
|
|
|
|
},
|
|
|
|
"MyToken2": {
|
|
|
|
instanceOf: "Token",
|
|
|
|
args: [2000]
|
|
|
|
},
|
|
|
|
"SomeContract": {
|
|
|
|
"args": [
|
|
|
|
["$MyToken2", "$accounts[0]"],
|
|
|
|
100
|
|
|
|
]
|
|
|
|
},
|
|
|
|
"SimpleStorage": {
|
|
|
|
args: [100]
|
|
|
|
}
|
2018-11-29 07:12:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}, (_err, web3_accounts) => {
|
|
|
|
accounts = web3_accounts;
|
|
|
|
});
|
|
|
|
|
|
|
|
// must be declared outside of the 'before' block, otherwise
|
|
|
|
// the 'block:header' event does not fire
|
|
|
|
embark.events.on("block:header", (blockHeader) => {
|
|
|
|
gasUsedForDeploy += blockHeader.gasUsed;
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("Account balance", function () {
|
|
|
|
before(function (done) {
|
|
|
|
embark.events.request("blockchain:gasPrice", (err, blkGasPrice) => {
|
|
|
|
if (err) {
|
|
|
|
return next(new Error(__("could not get the gas price")));
|
|
|
|
}
|
|
|
|
gasPrice = parseInt(blkGasPrice, 10);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
it('should create an account balance from a large ether value in config', async function () {
|
|
|
|
const shouldBeWeiBN = web3.utils.toBN('100000000000000000000000');
|
|
|
|
const actualBalanceWei = await web3.eth.getBalance(accounts[0]);
|
|
|
|
const actualBalanceWeiBN = web3.utils.toBN(actualBalanceWei);
|
|
|
|
const gasUsedWeiBN = web3.utils.toBN((gasUsedForDeploy * gasPrice).toString());
|
|
|
|
const totalBalanceWeiBN = actualBalanceWeiBN.add(gasUsedWeiBN);
|
|
|
|
assert.ok(totalBalanceWeiBN.gte(shouldBeWeiBN), "Total balance (account balance + deployment costs) should be greater than or equal to 100K ether");
|
|
|
|
});
|
|
|
|
});
|