2019-10-22 13:27:22 +00:00
|
|
|
/*global embark, config, it, web3, before, describe*/
|
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
|
2020-01-19 20:19:30 +00:00
|
|
|
// see https://framework.embarklabs.io/docs/contracts_testing.html#Configuring-accounts
|
2018-11-29 07:12:00 +00:00
|
|
|
{
|
|
|
|
privateKey: "random",
|
2019-10-22 13:27:22 +00:00
|
|
|
balance: "10 ether"
|
2018-11-29 07:12:00 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
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;
|
|
|
|
});
|
|
|
|
|
2019-10-22 13:27:22 +00:00
|
|
|
describe("Account balance", function() {
|
|
|
|
before(function(done) {
|
2018-11-29 07:12:00 +00:00
|
|
|
embark.events.request("blockchain:gasPrice", (err, blkGasPrice) => {
|
|
|
|
if (err) {
|
2019-10-22 13:27:22 +00:00
|
|
|
return done(new Error(__("could not get the gas price")));
|
2018-11-29 07:12:00 +00:00
|
|
|
}
|
|
|
|
gasPrice = parseInt(blkGasPrice, 10);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2019-10-22 13:27:22 +00:00
|
|
|
|
|
|
|
it('should create an account balance from a large ether value in config', async function() {
|
|
|
|
const shouldBeWeiBN = web3.utils.toBN('1000000000000000000');
|
2018-11-29 07:12:00 +00:00
|
|
|
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");
|
|
|
|
});
|
|
|
|
});
|