embark/dapps/tests/app/test/another_storage_spec.js

67 lines
1.9 KiB
JavaScript
Raw Normal View History

2018-06-07 20:14:42 +00:00
/*global contract, config, it, web3*/
2018-06-01 14:48:29 +00:00
const assert = require('assert');
2018-06-07 20:14:42 +00:00
const AnotherStorage = require('Embark/contracts/AnotherStorage');
const SimpleStorage = require('Embark/contracts/SimpleStorage');
2018-06-01 14:48:29 +00:00
let accounts, defaultAccount;
const numAddresses = 10;
2018-06-01 14:48:29 +00:00
config({
blockchain: {
2018-06-06 19:33:48 +00:00
"accounts": [
{
"mnemonic": "example exile argue silk regular smile grass bomb merge arm assist farm",
balance: "5ether",
numAddresses: 10
2018-06-06 19:33:48 +00:00
}
2018-07-31 10:01:52 +00:00
]
2018-06-06 19:33:48 +00:00
},
2018-06-01 14:48:29 +00:00
contracts: {
deploy: {
"SimpleStorage": {
args: [100]
},
"AnotherStorage": {
args: ["$SimpleStorage"]
}
2018-06-01 14:48:29 +00:00
}
}
}, (err, theAccounts) => {
accounts = theAccounts;
defaultAccount = accounts[0];
2018-06-01 14:48:29 +00:00
});
contract("AnotherStorage", function() {
2018-01-05 20:10:47 +00:00
this.timeout(0);
2017-02-10 00:38:02 +00:00
it("should have got the default account in the describe", function () {
assert.strictEqual(defaultAccount, accounts[0]);
});
2018-06-08 17:10:47 +00:00
it("should have account with balance", async function() {
const balance = await web3.eth.getBalance(accounts[0]);
2018-06-08 17:10:47 +00:00
assert.ok(parseInt(balance, 10) > 4900000000000000000);
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`);
}
});
2018-04-17 18:48:31 +00:00
it("set SimpleStorage address", async function() {
let result = await AnotherStorage.methods.simpleStorageAddress().call();
assert.equal(result.toString(), SimpleStorage.options.address);
2017-02-10 00:38:02 +00:00
});
2018-06-10 16:11:34 +00:00
it("set SimpleStorage address with alternative syntax", async function() {
let result = await AnotherStorage.simpleStorageAddress();
assert.equal(result.toString(), SimpleStorage.options.address);
});
2017-02-10 00:38:02 +00:00
});