Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CENT-361] Modify TokenTestUtils function buildExpectedState/getActualState #228

Merged
merged 9 commits into from
Oct 24, 2018
32 changes: 20 additions & 12 deletions test/AccountUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,34 @@ 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]
upgraderAccount: "0x2f560290fef1b3ada194b6aa9c40aa71f8e95598" // accounts[14] upgraderAccount is alias for proxyOwnerAccount
};

// named list of known private keys
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 All @@ -42,7 +42,6 @@ var AccountPrivateKeys = {
controller2PrivateKey: "9b9c613a36396172eab2d34d72331c8ca83a358781883a535d2941f66db07b24", // accounts[12]
issuerOwnerPrivateKey: "0874049f95d55fb76916262dc70571701b5c4cc5900c0691af75f1a8a52c8268", // accounts[13]
proxyOwnerAccount: "21d7212f3b4e5332fd465877b64926e3532653e2798a11255a46f533852dfe46", // accounts[14]
upgraderAccount: "21d7212f3b4e5332fd465877b64926e3532653e2798a11255a46f533852dfe46" // accounts[14]
};

// Returns an object with all named account values set to the default value
Expand Down Expand Up @@ -112,11 +111,20 @@ async function checkState(_tokens, _customVars, emptyState, getActualState, acco
// returns an object containing the results of calling mappingQuery on each account
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: mappingQuery -> accountQuery

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

// 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
20 changes: 10 additions & 10 deletions test/ExtendedPositiveTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ async function run_tests(newToken, accounts) {

it('ept001 should changeAdmin while paused', async function () {
await token.pause({ from: Accounts.pauserAccount });
await proxy.changeAdmin(Accounts.arbitraryAccount, { from: Accounts.upgraderAccount });
await proxy.changeAdmin(Accounts.arbitraryAccount, { from: Accounts.proxyOwnerAccount });
var result = [
{ 'variable': 'paused', 'expectedValue': true },
{ 'variable': 'upgrader', 'expectedValue': Accounts.arbitraryAccount},
{ 'variable': 'proxyOwner', 'expectedValue': Accounts.arbitraryAccount},
];
await checkVariables([token], [result]);
});
Expand Down Expand Up @@ -121,11 +121,11 @@ async function run_tests(newToken, accounts) {
// Blacklisted

it('ept013 should changeAdmin when msg.sender blacklisted', async function () {
await token.blacklist(Accounts.upgraderAccount, { from: Accounts.blacklisterAccount });
await proxy.changeAdmin(Accounts.arbitraryAccount, { from: Accounts.upgraderAccount });
await token.blacklist(Accounts.proxyOwnerAccount, { from: Accounts.blacklisterAccount });
await proxy.changeAdmin(Accounts.arbitraryAccount, { from: Accounts.proxyOwnerAccount });
var result = [
{ 'variable': 'isAccountBlacklisted.upgraderAccount', 'expectedValue': true },
{ 'variable': 'upgrader', 'expectedValue': Accounts.arbitraryAccount },
{ 'variable': 'isAccountBlacklisted.proxyOwnerAccount', 'expectedValue': true },
{ 'variable': 'proxyOwner', 'expectedValue': Accounts.arbitraryAccount },
];
await checkVariables([token], [result]);
});
Expand Down Expand Up @@ -217,14 +217,14 @@ async function run_tests(newToken, accounts) {
});

it('ept022 should upgrade when msg.sender blacklisted', async function () {
await token.blacklist(Accounts.upgraderAccount, { from: Accounts.blacklisterAccount });
await token.blacklist(Accounts.proxyOwnerAccount, { from: Accounts.blacklisterAccount });
var newRawToken = await UpgradedFiatToken.new();
var tokenConfig = await upgradeTo(proxy, newRawToken);
var newToken = tokenConfig.token;

var newToken_result = [
{ 'variable': 'proxiedTokenAddress', 'expectedValue': newRawToken.address },
{ 'variable': 'isAccountBlacklisted.upgraderAccount', 'expectedValue': true },
{ 'variable': 'isAccountBlacklisted.proxyOwnerAccount', 'expectedValue': true },
];
await checkVariables([newToken], [newToken_result]);
});
Expand Down Expand Up @@ -256,10 +256,10 @@ async function run_tests(newToken, accounts) {

it('ept025 should changeAdmin to blacklisted address', async function () {
await token.blacklist(Accounts.arbitraryAccount, { from: Accounts.blacklisterAccount });
await proxy.changeAdmin(Accounts.arbitraryAccount, { from: Accounts.upgraderAccount });
await proxy.changeAdmin(Accounts.arbitraryAccount, { from: Accounts.proxyOwnerAccount });
var result = [
{ 'variable': 'isAccountBlacklisted.arbitraryAccount', 'expectedValue': true },
{ 'variable': 'upgrader', 'expectedValue': Accounts.arbitraryAccount },
{ 'variable': 'proxyOwner', 'expectedValue': Accounts.arbitraryAccount },
];
await checkVariables([token], [result]);
});
Expand Down
50 changes: 25 additions & 25 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 @@ -170,14 +170,14 @@ async function run_tests(newToken, accounts) {

await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount });
await token.configureMinter(Accounts.arbitraryAccount, amount, { from: Accounts.masterMinterAccount });
await token.mint(Accounts.pauserAccount, mintAmount1, { from: Accounts.minterAccount });
await token.mint(Accounts.pauserAccount, mintAmount2, { from: Accounts.arbitraryAccount });
await token.mint(Accounts.arbitraryAccount2, mintAmount1, { from: Accounts.minterAccount });
await token.mint(Accounts.arbitraryAccount2, mintAmount2, { from: Accounts.arbitraryAccount });
var customVars = [
{ 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true },
{ 'variable': 'isAccountMinter.arbitraryAccount', 'expectedValue': true },
{ 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - mintAmount1) },
{ 'variable': 'minterAllowance.arbitraryAccount', 'expectedValue': new BigNumber(amount - mintAmount2) },
{ 'variable': 'balances.pauserAccount', 'expectedValue': new BigNumber(mintAmount1 + mintAmount2) },
{ 'variable': 'balances.arbitraryAccount2', 'expectedValue': new BigNumber(mintAmount1 + mintAmount2) },
{ 'variable': 'totalSupply', 'expectedValue': new BigNumber(mintAmount1 + mintAmount2) },
];
await checkVariables([token], [customVars]);
Expand All @@ -189,13 +189,13 @@ async function run_tests(newToken, accounts) {

await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount });
await token.configureMinter(Accounts.arbitraryAccount, amount, { from: Accounts.masterMinterAccount });
await token.mint(Accounts.pauserAccount, mintAmount1, { from: Accounts.minterAccount });
await token.mint(Accounts.pauserAccount, mintAmount2, { from: Accounts.arbitraryAccount });
await token.mint(Accounts.arbitraryAccount2, mintAmount1, { from: Accounts.minterAccount });
await token.mint(Accounts.arbitraryAccount2, mintAmount2, { from: Accounts.arbitraryAccount });
await token.removeMinter(Accounts.arbitraryAccount, { from: Accounts.masterMinterAccount });
var customVars = [
{ 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true },
{ 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - mintAmount1) },
{ 'variable': 'balances.pauserAccount', 'expectedValue': new BigNumber(mintAmount1 + mintAmount2) },
{ 'variable': 'balances.arbitraryAccount2', 'expectedValue': new BigNumber(mintAmount1 + mintAmount2) },
{ 'variable': 'totalSupply', 'expectedValue': new BigNumber(mintAmount1 + mintAmount2) },
];
await checkVariables([token], [customVars]);
Expand Down Expand Up @@ -230,16 +230,16 @@ async function run_tests(newToken, accounts) {

await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount });
await token.configureMinter(Accounts.arbitraryAccount, 0, { from: Accounts.masterMinterAccount });
await token.mint(Accounts.pauserAccount, mintAmount, { from: Accounts.minterAccount });
await token.mint(Accounts.arbitraryAccount2, mintAmount, { from: Accounts.minterAccount });
var customVars = [
{ 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true },
{ 'variable': 'isAccountMinter.arbitraryAccount', 'expectedValue': true },
{ 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - mintAmount) },
{ 'variable': 'balances.pauserAccount', 'expectedValue': new BigNumber(mintAmount) },
{ 'variable': 'balances.arbitraryAccount2', 'expectedValue': new BigNumber(mintAmount) },
{ 'variable': 'totalSupply', 'expectedValue': new BigNumber(mintAmount) },
];
await expectRevert(token.mint(Accounts.pauserAccount, mintAmount, { from: Accounts.arbitraryAccount }));
//await expectRevert(token.mint(Accounts.pauserAccount, 0, { from: Accounts.arbitraryAccount }));
await expectRevert(token.mint(Accounts.arbitraryAccount2, mintAmount, { from: Accounts.arbitraryAccount }));
//await expectRevert(token.mint(Accounts.arbitraryAccount2, 0, { from: Accounts.arbitraryAccount }));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment can be deleted

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

await checkVariables([token], [customVars]);
});

Expand Down Expand Up @@ -267,28 +267,28 @@ async function run_tests(newToken, accounts) {
await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount });
await token.configureMinter(Accounts.arbitraryAccount, amount, { from: Accounts.masterMinterAccount });
await token.blacklist(Accounts.minterAccount, { from: Accounts.blacklisterAccount });
await token.mint(Accounts.pauserAccount, mintAmount, { from: Accounts.arbitraryAccount });
await token.mint(Accounts.arbitraryAccount2, mintAmount, { from: Accounts.arbitraryAccount });
var customVars = [
{ 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true },
{ 'variable': 'isAccountMinter.arbitraryAccount', 'expectedValue': true },
{ 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount) },
{ 'variable': 'minterAllowance.arbitraryAccount', 'expectedValue': new BigNumber(amount - mintAmount) },
{ 'variable': 'isAccountBlacklisted.minterAccount', 'expectedValue': true },
{ 'variable': 'totalSupply', 'expectedValue': new BigNumber(mintAmount) },
{ 'variable': 'balances.pauserAccount', 'expectedValue': new BigNumber(mintAmount) },
{ 'variable': 'balances.arbitraryAccount2', 'expectedValue': new BigNumber(mintAmount) },
];
await expectRevert(token.mint(Accounts.pauserAccount, mintAmount, { from: Accounts.minterAccount }));
await expectRevert(token.mint(Accounts.arbitraryAccount2, mintAmount, { from: Accounts.minterAccount }));
await checkVariables([token], [customVars]);

await token.unBlacklist(Accounts.minterAccount, { from: Accounts.blacklisterAccount });
await token.mint(Accounts.pauserAccount, mintAmount, { from: Accounts.minterAccount });
await token.mint(Accounts.arbitraryAccount2, mintAmount, { from: Accounts.minterAccount });
var customVars = [
{ 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true },
{ 'variable': 'isAccountMinter.arbitraryAccount', 'expectedValue': true },
{ 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - mintAmount) },
{ 'variable': 'minterAllowance.arbitraryAccount', 'expectedValue': new BigNumber(amount - mintAmount) },
{ 'variable': 'totalSupply', 'expectedValue': new BigNumber(mintAmount + mintAmount) },
{ 'variable': 'balances.pauserAccount', 'expectedValue': new BigNumber(mintAmount + mintAmount) },
{ 'variable': 'balances.arbitraryAccount2', 'expectedValue': new BigNumber(mintAmount + mintAmount) },
];
await checkVariables([token], [customVars]);
});
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 @@ -522,10 +522,10 @@ async function run_tests(newToken, accounts) {
];
await checkVariables([token], [customVars]);

await token.transfer(Accounts.pauserAccount, maxAmount, {from: Accounts.arbitraryAccount});
await token.transfer(Accounts.arbitraryAccount2, maxAmount, {from: Accounts.arbitraryAccount});
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 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
Loading