Skip to content

Commit

Permalink
Speeded up unit tests by removing some Accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
mirathewhite committed Oct 18, 2018
1 parent e47b95b commit 5e88595
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 105 deletions.
30 changes: 20 additions & 10 deletions test/AccountUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,25 @@ var debugLogging = false;
var assertDiff = require('assert-diff');
assertDiff.options.strict = true;

var Q = require('q');
var clone = require('clone');

// named list of all accounts
var Accounts = {
deployerAccount: "0x90f8bf6a479f320ead074411a4b0e7944ea8c9c1", // accounts[0]
arbitraryAccount: "0xffcf8fdee72ac11b5c542428b35eef5769c409f0", // accounts[1]
issuerControllerAccount: "0x22d491bde2303f2f43325b2108d26f1eaba1e32b", // accounts[2]
tokenOwnerAccount: "0xe11ba2b4d45eaed5996cd0823791e0c93114882d", // accounts[3]
// issuerControllerAccount: "0x22d491bde2303f2f43325b2108d26f1eaba1e32b", // accounts[2]
tokenOwnerAccount: "0xe11ba2b4d45eaed5996cd0823791e0c93114882d", // Accounts.arbitraryAccount
blacklisterAccount: "0xd03ea8624c8c5987235048901fb614fdca89b117", // accounts[4]
arbitraryAccount2: "0x95ced938f7991cd0dfcb48f0a06a40fa1af46ebc", // accounts[5]
masterMinterAccount: "0x3e5e9111ae8eb78fe1cc3bb8915d5d461f3ef9a9", // accounts[6]
minterAccount: "0x28a8746e75304c0780e011bed21c72cd78cd535e", // accounts[7]
pauserAccount: "0xaca94ef8bd5ffee41947b4585a84bda5a3d3da6e", // accounts[8]
mintOwnerAccount: "0x1df62f291b2e969fb0849d99d9ce41e2f137006e", // accounts[9]
mintProtectorAccount: "0x610bb1573d1046fcb8a70bbbd395754cd57c2b60", // accounts[10]
// mintProtectorAccount: "0x610bb1573d1046fcb8a70bbbd395754cd57c2b60", // accounts[10]
controller1Account: "0x855fa758c77d68a04990e992aa4dcdef899f654a", // accounts[11]
controller2Account: "0xfa2435eacf10ca62ae6787ba2fb044f8733ee843", // accounts[12]
issuerOwnerAccount: "0x64e078a8aa15a41b85890265648e965de686bae6", // accounts[13]
// controller2Account: "0xfa2435eacf10ca62ae6787ba2fb044f8733ee843", // accounts[12]
// issuerOwnerAccount: "0x64e078a8aa15a41b85890265648e965de686bae6", // accounts[13]
proxyOwnerAccount: "0x2f560290fef1b3ada194b6aa9c40aa71f8e95598", // accounts[14]
};

Expand All @@ -29,7 +30,7 @@ var AccountPrivateKeys = {
deployerPrivateKey: "4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b1d", // accounts[0]
arbitraryPrivateKey: "6cbed15c793ce57650b9877cf6fa156fbef513c4e6134f022a85b1ffdd59b2a1", // accounts[1]
issuerControllerPrivateKey: "6370fd033278c143179d81c5526140625662b8daa446c22ee2d73db3707e620c", // accounts[2]
tokenOwnerPrivateKey: "646f1ce2fdad0e6deeeb5c7e8e5543bdde65e86029e2fd9fc169899c440a7913", // accounts[3]
tokenOwnerPrivateKey: "646f1ce2fdad0e6deeeb5c7e8e5543bdde65e86029e2fd9fc169899c440a7913", // Accounts.arbitraryAccount
blacklisterPrivateKey: "add53f9a7e588d003326d1cbf9e4a43c061aadd9bc938c843a79e7b4fd2ad743", // accounts[4]
arbitrary2PrivateKey: "395df67f0c2d2d9fe1ad08d1bc8b6627011959b79c53d7dd6a3536a33ab8a4fd", // accounts[5]
masterMinterPrivateKey: "e485d098507f54e7733a205420dfddbe58db035fa577fc294ebd14db90767a52", // accounts[6]
Expand Down Expand Up @@ -110,11 +111,20 @@ async function checkState(_tokens, _customVars, emptyState, getActualState, acco
// returns an object containing the results of calling mappingQuery on each account
// E.g. {owner: value1, minter: value2}
async function getAccountState(accountQuery, accounts) {
var results = {};
for (var accountName in accounts) {
results[accountName] = await accountQuery(accounts[accountName]);
// create an array of promises
var promises = [];
for(var account in accounts) {
var promiseQuery = accountQuery(Accounts[account]);
promises.push(promiseQuery);
}
var results = await Q.allSettled(promises);
var state = {};
var u =0;
for(var account in accounts) {
state[account] = results[u].value;
++u;
}
return results;
return state;
}

function isLiteral(object) {
Expand Down
16 changes: 8 additions & 8 deletions test/MiscTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ async function run_tests(newToken, accounts) {
await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount });
await token.mint(Accounts.arbitraryAccount, mintAmount, { from: Accounts.minterAccount });

await token.approve(Accounts.pauserAccount, mintAmount, { from: Accounts.arbitraryAccount });
await token.transferFrom(Accounts.arbitraryAccount, Accounts.arbitraryAccount, mintAmount, { from: Accounts.pauserAccount });
await token.approve(Accounts.arbitraryAccount2, mintAmount, { from: Accounts.arbitraryAccount });
await token.transferFrom(Accounts.arbitraryAccount, Accounts.arbitraryAccount, mintAmount, { from: Accounts.arbitraryAccount2 });
customVars = [
{ 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true },
{ 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - mintAmount) },
Expand Down Expand Up @@ -502,12 +502,12 @@ async function run_tests(newToken, accounts) {
];
await checkVariables([token], [customVars]);

await token.approve(Accounts.pauserAccount, maxAmount, {from: Accounts.arbitraryAccount});
await token.approve(Accounts.arbitraryAccount2, maxAmount, {from: Accounts.arbitraryAccount});
customVars = [
{ 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true },
{ 'variable': 'balances.arbitraryAccount', 'expectedValue': new BigNumber(maxAmount) },
{ 'variable': 'totalSupply', 'expectedValue': new BigNumber(maxAmount) },
{ 'variable': 'allowance.arbitraryAccount.pauserAccount', 'expectedValue': new BigNumber(maxAmount) }
{ 'variable': 'allowance.arbitraryAccount.arbitraryAccount2', 'expectedValue': new BigNumber(maxAmount) }
];
await checkVariables([token], [customVars]);
});
Expand All @@ -534,19 +534,19 @@ async function run_tests(newToken, accounts) {
it('ms052 transferFrom works on amount=2^256-1', async function() {
await token.configureMinter(Accounts.minterAccount, maxAmount, { from: Accounts.masterMinterAccount });
await token.mint(Accounts.arbitraryAccount, maxAmount, { from: Accounts.minterAccount });
await token.approve(Accounts.pauserAccount, maxAmount, {from: Accounts.arbitraryAccount});
await token.approve(Accounts.arbitraryAccount2, maxAmount, {from: Accounts.arbitraryAccount});
customVars = [
{ 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true },
{ 'variable': 'balances.arbitraryAccount', 'expectedValue': new BigNumber(maxAmount) },
{ 'variable': 'totalSupply', 'expectedValue': new BigNumber(maxAmount) },
{ 'variable': 'allowance.arbitraryAccount.pauserAccount', 'expectedValue': new BigNumber(maxAmount) }
{ 'variable': 'allowance.arbitraryAccount.arbitraryAccount2', 'expectedValue': new BigNumber(maxAmount) }
];
await checkVariables([token], [customVars]);

await token.transferFrom(Accounts.arbitraryAccount, Accounts.pauserAccount, maxAmount, {from: Accounts.pauserAccount});
await token.transferFrom(Accounts.arbitraryAccount, Accounts.arbitraryAccount2, maxAmount, {from: Accounts.arbitraryAccount2});
customVars = [
{ 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true },
{ 'variable': 'balances.pauserAccount', 'expectedValue': new BigNumber(maxAmount) },
{ 'variable': 'balances.arbitraryAccount2', 'expectedValue': new BigNumber(maxAmount) },
{ 'variable': 'totalSupply', 'expectedValue': new BigNumber(maxAmount) },
];
await checkVariables([token], [customVars]);
Expand Down
40 changes: 20 additions & 20 deletions test/NegativeTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,15 @@ async function run_tests(newToken, accounts) {
await checkVariables([token], [customVars]);

await token.mint(Accounts.arbitraryAccount, 50, {from: Accounts.minterAccount});
await token.approve(Accounts.pauserAccount, 50, {from: Accounts.arbitraryAccount});
await token.approve(Accounts.arbitraryAccount2, 50, {from: Accounts.arbitraryAccount});
customVars = [
{'variable': 'isAccountMinter.minterAccount', 'expectedValue': true},
{'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - 50)},
{'variable': 'balances.arbitraryAccount', 'expectedValue': new BigNumber(50)},
{'variable': 'totalSupply', 'expectedValue': new BigNumber(50)},
{'variable': 'allowance.arbitraryAccount.pauserAccount', 'expectedValue': new BigNumber(50)}
{'variable': 'allowance.arbitraryAccount.arbitraryAccount2', 'expectedValue': new BigNumber(50)}
]
await expectRevert(token.transferFrom(Accounts.arbitraryAccount, "0x0", 50, {from: Accounts.pauserAccount}));
await expectRevert(token.transferFrom(Accounts.arbitraryAccount, "0x0", 50, {from: Accounts.arbitraryAccount2}));
await checkVariables([token], [customVars]);
});

Expand Down Expand Up @@ -185,17 +185,17 @@ async function run_tests(newToken, accounts) {
await checkVariables([token], [customVars]);

await token.mint(Accounts.blacklisterAccount, 50, {from: Accounts.minterAccount});
await token.approve(Accounts.pauserAccount, 50, {from: Accounts.blacklisterAccount});
await token.approve(Accounts.arbitraryAccount2, 50, {from: Accounts.blacklisterAccount});
await token.blacklist(Accounts.arbitraryAccount, {from: Accounts.blacklisterAccount});
customVars = [
{'variable': 'isAccountMinter.minterAccount', 'expectedValue': true},
{'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - 50)},
{'variable': 'balances.blacklisterAccount', 'expectedValue': new BigNumber(50)},
{'variable': 'totalSupply', 'expectedValue': new BigNumber(50)},
{'variable': 'allowance.blacklisterAccount.pauserAccount', 'expectedValue': new BigNumber(50)},
{'variable': 'allowance.blacklisterAccount.arbitraryAccount2', 'expectedValue': new BigNumber(50)},
{'variable': 'isAccountBlacklisted.arbitraryAccount', 'expectedValue': true}
]
await expectRevert(token.transferFrom(Accounts.blacklisterAccount, Accounts.arbitraryAccount, 50, {from: Accounts.pauserAccount}));
await expectRevert(token.transferFrom(Accounts.blacklisterAccount, Accounts.arbitraryAccount, 50, {from: Accounts.arbitraryAccount2}));
await checkVariables([token], [customVars]);
});

Expand All @@ -207,18 +207,18 @@ async function run_tests(newToken, accounts) {
]
await checkVariables([token], [customVars]);

await token.mint(Accounts.tokenOwnerAccount, 50, {from: Accounts.minterAccount});
await token.approve(Accounts.arbitraryAccount, 50, {from: Accounts.tokenOwnerAccount});
await token.mint(Accounts.arbitraryAccount2, 50, {from: Accounts.minterAccount});
await token.approve(Accounts.arbitraryAccount, 50, {from: Accounts.arbitraryAccount2});
await token.blacklist(Accounts.arbitraryAccount, {from: Accounts.blacklisterAccount});
customVars = [
{'variable': 'isAccountMinter.minterAccount', 'expectedValue': true},
{'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - 50)},
{'variable': 'balances.tokenOwnerAccount', 'expectedValue': new BigNumber(50)},
{'variable': 'balances.arbitraryAccount2', 'expectedValue': new BigNumber(50)},
{'variable': 'totalSupply', 'expectedValue': new BigNumber(50)},
{'variable': 'allowance.tokenOwnerAccount.arbitraryAccount', 'expectedValue': new BigNumber(50)},
{'variable': 'allowance.arbitraryAccount2.arbitraryAccount', 'expectedValue': new BigNumber(50)},
{'variable': 'isAccountBlacklisted.arbitraryAccount', 'expectedValue': true}
]
await expectRevert(token.transferFrom(Accounts.tokenOwnerAccount, Accounts.pauserAccount, 50, {from: Accounts.arbitraryAccount}));
await expectRevert(token.transferFrom(Accounts.arbitraryAccount2, Accounts.pauserAccount, 50, {from: Accounts.arbitraryAccount}));
await checkVariables([token], [customVars]);
});

Expand All @@ -231,17 +231,17 @@ async function run_tests(newToken, accounts) {
await checkVariables([token], [customVars]);

await token.mint(Accounts.arbitraryAccount, 50, {from: Accounts.minterAccount});
await token.approve(Accounts.tokenOwnerAccount, 50, {from: Accounts.arbitraryAccount});
await token.approve(Accounts.arbitraryAccount2, 50, {from: Accounts.arbitraryAccount});
await token.blacklist(Accounts.arbitraryAccount, {from: Accounts.blacklisterAccount});
customVars = [
{'variable': 'isAccountMinter.minterAccount', 'expectedValue': true},
{'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - 50)},
{'variable': 'balances.arbitraryAccount', 'expectedValue': new BigNumber(50)},
{'variable': 'totalSupply', 'expectedValue': new BigNumber(50)},
{'variable': 'allowance.arbitraryAccount.tokenOwnerAccount', 'expectedValue': new BigNumber(50)},
{'variable': 'allowance.arbitraryAccount.arbitraryAccount2', 'expectedValue': new BigNumber(50)},
{'variable': 'isAccountBlacklisted.arbitraryAccount', 'expectedValue': true}
]
await expectRevert(token.transferFrom(Accounts.arbitraryAccount, Accounts.pauserAccount, 50, {from: Accounts.tokenOwnerAccount}));
await expectRevert(token.transferFrom(Accounts.arbitraryAccount, Accounts.pauserAccount, 50, {from: Accounts.arbitraryAccount2}));
await checkVariables([token], [customVars]);
});

Expand All @@ -254,15 +254,15 @@ async function run_tests(newToken, accounts) {
await checkVariables([token], [customVars]);

await token.mint(Accounts.arbitraryAccount, 50, {from: Accounts.minterAccount});
await token.approve(Accounts.tokenOwnerAccount, 50, {from: Accounts.arbitraryAccount});
await token.approve(Accounts.arbitraryAccount2, 50, {from: Accounts.arbitraryAccount});
customVars = [
{'variable': 'isAccountMinter.minterAccount', 'expectedValue': true},
{'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - 50)},
{'variable': 'balances.arbitraryAccount', 'expectedValue': new BigNumber(50)},
{'variable': 'totalSupply', 'expectedValue': new BigNumber(50)},
{'variable': 'allowance.arbitraryAccount.tokenOwnerAccount', 'expectedValue': new BigNumber(50)},
{'variable': 'allowance.arbitraryAccount.arbitraryAccount2', 'expectedValue': new BigNumber(50)},
]
await expectRevert(token.transferFrom(Accounts.arbitraryAccount, Accounts.pauserAccount, 60, {from: Accounts.tokenOwnerAccount}));
await expectRevert(token.transferFrom(Accounts.arbitraryAccount, Accounts.pauserAccount, 60, {from: Accounts.arbitraryAccount2}));
await checkVariables([token], [customVars]);
});

Expand All @@ -275,17 +275,17 @@ async function run_tests(newToken, accounts) {
await checkVariables([token], [customVars]);

await token.mint(Accounts.arbitraryAccount, 50, {from: Accounts.minterAccount});
await token.approve(Accounts.tokenOwnerAccount, 50, {from: Accounts.arbitraryAccount});
await token.approve(Accounts.arbitraryAccount2, 50, {from: Accounts.arbitraryAccount});
await token.pause({from: Accounts.pauserAccount});
customVars = [
{'variable': 'isAccountMinter.minterAccount', 'expectedValue': true},
{'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - 50)},
{'variable': 'balances.arbitraryAccount', 'expectedValue': new BigNumber(50)},
{'variable': 'totalSupply', 'expectedValue': new BigNumber(50)},
{'variable': 'allowance.arbitraryAccount.tokenOwnerAccount', 'expectedValue': new BigNumber(50)},
{'variable': 'allowance.arbitraryAccount.arbitraryAccount2', 'expectedValue': new BigNumber(50)},
{'variable': 'paused', 'expectedValue': true}
]
await expectRevert(token.transferFrom(Accounts.arbitraryAccount, Accounts.pauserAccount, 50, {from: Accounts.tokenOwnerAccount}));
await expectRevert(token.transferFrom(Accounts.arbitraryAccount, Accounts.pauserAccount, 50, {from: Accounts.arbitraryAccount2}));
await checkVariables([token], [customVars]);
});

Expand Down
Loading

0 comments on commit 5e88595

Please sign in to comment.