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

adds et000, et015, et016, et012 #185

Merged
merged 3 commits into from
Aug 7, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
245 changes: 135 additions & 110 deletions test/EventsTests.js
Original file line number Diff line number Diff line change
@@ -1,126 +1,151 @@
var tokenUtils = require('./TokenTestUtils')
var FiatToken = artifacts.require('FiatTokenV1')
var FiatTokenProxy = artifacts.require('FiatTokenProxy')
var checkMintEvent = tokenUtils.checkMintEvent
var checkTransferEvents = tokenUtils.checkTransferEvents
var checkMinterConfiguredEvent = tokenUtils.checkMinterConfiguredEvent
var minterAccount = tokenUtils.minterAccount
var masterMinterAccount = tokenUtils.masterMinterAccount
var arbitraryAccount = tokenUtils.arbitraryAccount
var arbitraryAccount2 = tokenUtils.arbitraryAccount2
var burnerAccount = tokenUtils.burnerAccount
var blacklisterAccount = tokenUtils.blacklisterAccount
var tokenOwnerAccount = tokenUtils.tokenOwnerAccount
var pauserAccount = tokenUtils.pauserAccount
var proxyOwnerAccount = tokenUtils.proxyOwnerAccount
var name = tokenUtils.name
var symbol = tokenUtils.symbol
var currency = tokenUtils.currency
var decimals = tokenUtils.decimals


var initializeTokenWithProxy = tokenUtils.initializeTokenWithProxy
var encodeCall = tokenUtils.encodeCall

var checkApprovalEvent = tokenUtils.checkApprovalEvent
var checkBurnEvent = tokenUtils.checkBurnEvent
var checkMinterRemovedEvent = tokenUtils.checkMinterRemovedEvent
var checkBlacklistEvent = tokenUtils.checkBlacklistEvent
var checkUnblacklistEvent = tokenUtils.checkUnblacklistEvent
var checkPauserChangedEvent = tokenUtils.checkPauserChangedEvent
var checkUnpauseEvent = tokenUtils.checkUnpauseEvent
var checkTransferOwnershipEvent = tokenUtils.checkTransferOwnershipEvent
var checkUpdateMasterMinterEvent = tokenUtils.checkUpdateMasterMinterEvent
var checkBlacklisterChangedEvent = tokenUtils.checkBlacklisterChangedEvent
var checkUpgradeEvent = tokenUtils.checkUpgradeEvent
var checkAdminChangedEvent = tokenUtils.checkAdminChangedEvent
var tokenUtils = require('./TokenTestUtils');
Copy link
Contributor

Choose a reason for hiding this comment

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

For FiatToken and FiatTokenProxy could you get these from tokenUtils in the import object instead of looking up the artifacts. We want to have one place the are defined.

var FiatToken = artifacts.require('FiatTokenV1');
var FiatTokenProxy = artifacts.require('FiatTokenProxy');
var minterAccount = tokenUtils.minterAccount;
var masterMinterAccount = tokenUtils.masterMinterAccount;
var arbitraryAccount = tokenUtils.arbitraryAccount;
var arbitraryAccount2 = tokenUtils.arbitraryAccount2;
var burnerAccount = tokenUtils.burnerAccount;
var blacklisterAccount = tokenUtils.blacklisterAccount;
var tokenOwnerAccount = tokenUtils.tokenOwnerAccount;
var pauserAccount = tokenUtils.pauserAccount;
var proxyOwnerAccount = tokenUtils.proxyOwnerAccount;
var name = tokenUtils.name;
var symbol = tokenUtils.symbol;
var currency = tokenUtils.currency;
var decimals = tokenUtils.decimals;


var initializeTokenWithProxy = tokenUtils.initializeTokenWithProxy;
var encodeCall = tokenUtils.encodeCall;

var checkMintEvent = tokenUtils.checkMintEvent;
var checkMinterConfiguredEvent = tokenUtils.checkMinterConfiguredEvent;
var checkApprovalEvent = tokenUtils.checkApprovalEvent;
var checkBurnEvents = tokenUtils.checkBurnEvents;
var checkMinterRemovedEvent = tokenUtils.checkMinterRemovedEvent;
var checkBlacklistEvent = tokenUtils.checkBlacklistEvent;
var checkUnblacklistEvent = tokenUtils.checkUnblacklistEvent;
var checkPauserChangedEvent = tokenUtils.checkPauserChangedEvent;
var checkUnpauseEvent = tokenUtils.checkUnpauseEvent;
var checkTransferOwnershipEvent = tokenUtils.checkTransferOwnershipEvent;
var checkUpdateMasterMinterEvent = tokenUtils.checkUpdateMasterMinterEvent;
var checkBlacklisterChangedEvent = tokenUtils.checkBlacklisterChangedEvent;
var checkUpgradeEvent = tokenUtils.checkUpgradeEvent;
var checkAdminChangedEvent = tokenUtils.checkAdminChangedEvent;
var UpgradedFiatTokenNewFields = tokenUtils.UpgradedFiatTokenNewFields;
var checkPauseEvent = tokenUtils.checkPauseEvent;
var checkTransferEvents = tokenUtils.checkTransferEvents;

var amount = 100
var amount = 100;

async function run_tests(newToken) {

beforeEach('Make fresh token contract', async function () {
rawToken = await FiatToken.new();
var tokenConfig = await initializeTokenWithProxy(rawToken);
proxy = tokenConfig.proxy;
token = tokenConfig.token;
assert.equal(proxy.address, token.address);
})

it('should check MinterConfigured, Mint, and Transfer events', async function () {
let configureMinter = await token.configureMinter(minterAccount, amount, { from: masterMinterAccount })
checkMinterConfiguredEvent(configureMinter, minterAccount, amount)
let mint = await token.mint(arbitraryAccount, amount, {from: minterAccount})
checkMintEvent(mint, arbitraryAccount, amount, minterAccount)
})

it('should check Burn event', async function () {
await token.configureMinter(minterAccount, amount, { from: masterMinterAccount })
await token.mint(minterAccount, amount, { from: minterAccount })
let burn = await token.burn(amount, {from: minterAccount})
checkBurnEvent(burn, minterAccount, amount)
})

it('should check MinterRemoved event', async function () {
await token.configureMinter(minterAccount, amount, { from: masterMinterAccount })
let minterRemovedEvent = await token.removeMinter(minterAccount, {from: masterMinterAccount})
checkMinterRemovedEvent(minterRemovedEvent, minterAccount)
})

it('should check MasterMinterChanged event', async function () {
let updateMasterMinter = await token.updateMasterMinter(arbitraryAccount, {from: tokenOwnerAccount})
checkUpdateMasterMinterEvent(updateMasterMinter, arbitraryAccount)
})

it('should check blacklist event', async function () {
let blacklist = await token.blacklist(arbitraryAccount, { from: blacklisterAccount })
checkBlacklistEvent(blacklist, arbitraryAccount)
})

it('should check unblacklist event', async function () {
let unblacklist = await token.unBlacklist(arbitraryAccount, { from: blacklisterAccount })
checkUnblacklistEvent(unblacklist, arbitraryAccount)
})

it('should check BlacklisterChanged event', async function () {
let blacklisterChanged = await token.updateBlacklister(arbitraryAccount, {from: tokenOwnerAccount})
checkBlacklisterChangedEvent(blacklisterChanged, arbitraryAccount)
})

it('should check Upgraded event', async function () {
});

it('et000 should check MinterConfigured event', async function() {
let configureMinter = await token.configureMinter(minterAccount, amount, { from: masterMinterAccount });
checkMinterConfiguredEvent(configureMinter, minterAccount, amount);
});

it('et001 should check Mint/Transfer events', async function () {
await token.configureMinter(minterAccount, amount, { from: masterMinterAccount });
let mint = await token.mint(arbitraryAccount, amount, {from: minterAccount});
checkMintEvent(mint, arbitraryAccount, amount, minterAccount);
});

it('et002 should check Burn/Transfer events', async function () {
await token.configureMinter(minterAccount, amount, { from: masterMinterAccount });
await token.mint(minterAccount, amount, { from: minterAccount });
let burn = await token.burn(amount, {from: minterAccount});
checkBurnEvents(burn, amount, minterAccount);
});

it('et003 should check MinterRemoved event', async function () {
await token.configureMinter(minterAccount, amount, { from: masterMinterAccount });
let minterRemovedEvent = await token.removeMinter(minterAccount, {from: masterMinterAccount});
checkMinterRemovedEvent(minterRemovedEvent, minterAccount);
});

it('et004 should check MasterMinterChanged event', async function () {
let updateMasterMinter = await token.updateMasterMinter(arbitraryAccount, {from: tokenOwnerAccount});
checkUpdateMasterMinterEvent(updateMasterMinter, arbitraryAccount);
});

it('et005 should check Blacklisted event', async function () {
let blacklist = await token.blacklist(arbitraryAccount, { from: blacklisterAccount });
checkBlacklistEvent(blacklist, arbitraryAccount);
});

it('et006 should check UnBlacklisted event', async function () {
let unblacklist = await token.unBlacklist(arbitraryAccount, { from: blacklisterAccount });
checkUnblacklistEvent(unblacklist, arbitraryAccount);
});

it('et007 should check BlacklisterChanged event', async function () {
let blacklisterChanged = await token.updateBlacklister(arbitraryAccount, {from: tokenOwnerAccount});
checkBlacklisterChangedEvent(blacklisterChanged, arbitraryAccount);
});

it('et008 should check Upgraded event', async function () {
var upgradedToken = await UpgradedFiatTokenNewFields.new();
const initializeData = encodeCall('initV2', ['bool', 'address', 'uint256'], [true, pauserAccount, 12]);
let upgrade = await proxy.upgradeToAndCall(upgradedToken.address, initializeData, { from: proxyOwnerAccount })
checkUpgradeEvent(upgrade, upgradedToken.address)
})

it('should check AdminChanged event', async function () {
let adminChanged = await proxy.changeAdmin(arbitraryAccount, {from: proxyOwnerAccount})
checkAdminChangedEvent(adminChanged, proxyOwnerAccount, arbitraryAccount)
})

it('should check OwnershipTransferred event', async function () {
let transferOwnership = await token.transferOwnership(arbitraryAccount, {from: tokenOwnerAccount})
checkTransferOwnershipEvent(transferOwnership, tokenOwnerAccount, arbitraryAccount)
})

it('should check Approval event', async function () {
let approval = await token.approve(arbitraryAccount2, amount, {from: arbitraryAccount})
checkApprovalEvent(approval, arbitraryAccount, arbitraryAccount2, amount)
})

it('should check Unpause event', async function () {
let unpause = await token.unpause({from: pauserAccount})
checkUnpauseEvent(unpause)
})

it('should check PauserChanged event', async function () {
let updatePauser = await token.updatePauser(arbitraryAccount, {from: tokenOwnerAccount})
checkPauserChangedEvent(updatePauser, arbitraryAccount)
})
let upgrade = await proxy.upgradeToAndCall(upgradedToken.address, initializeData, { from: proxyOwnerAccount });
checkUpgradeEvent(upgrade, upgradedToken.address);
});

it('et009 should check AdminChanged event', async function () {
let adminChanged = await proxy.changeAdmin(arbitraryAccount, {from: proxyOwnerAccount});
checkAdminChangedEvent(adminChanged, proxyOwnerAccount, arbitraryAccount);
});

it('et010 should check OwnershipTransferred event', async function () {
let transferOwnership = await token.transferOwnership(arbitraryAccount, {from: tokenOwnerAccount});
checkTransferOwnershipEvent(transferOwnership, tokenOwnerAccount, arbitraryAccount);
});

it('et011 should check Approval event', async function () {
let approval = await token.approve(arbitraryAccount2, amount, {from: arbitraryAccount});
checkApprovalEvent(approval, arbitraryAccount, arbitraryAccount2, amount);
});

it('et012 should check Pause event', async function () {
let pause = await token.pause({from: pauserAccount});
checkPauseEvent(pause);
});

it('et013 should check Unpause event', async function () {
let unpause = await token.unpause({from: pauserAccount});
checkUnpauseEvent(unpause);
});

it('et014 should check PauserChanged event', async function () {
let updatePauser = await token.updatePauser(arbitraryAccount, {from: tokenOwnerAccount});
checkPauserChangedEvent(updatePauser, arbitraryAccount);
});

it('et015 should check Transfer event', async function () {
await token.configureMinter(minterAccount, amount, { from: masterMinterAccount });
await token.mint(arbitraryAccount, amount, {from: minterAccount});
let transfer = await token.transfer(arbitraryAccount2, amount, {from: arbitraryAccount});
checkTransferEvents(transfer, arbitraryAccount, arbitraryAccount2, amount);
});

it('et016 should check Transfer event in transferFrom', async function () {
await token.configureMinter(minterAccount, amount, { from: masterMinterAccount });
await token.mint(arbitraryAccount, amount, {from: minterAccount});
await token.approve(arbitraryAccount2, amount, {from: arbitraryAccount});
let transferFrom = await token.transferFrom(arbitraryAccount, blacklisterAccount, amount, {from: arbitraryAccount2});
checkTransferEvents(transferFrom, arbitraryAccount, blacklisterAccount, amount);
});
}

module.exports = {
run_tests: run_tests,
}
}
6 changes: 3 additions & 3 deletions test/TestWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ contract('FiatToken_LegacyTests_Upgraded', async function (accounts) {
await legacy_tests.run_tests(newUpgradedToken, accounts);
});

contract('Events_Tests', async function () {
contract('FiatToken_EventTests', async function () {
await events_tests.run_tests(newToken);
});

contract('Events_Tests', async function () {
contract('FiatToken_EventTests_Upgraded', async function () {
await events_tests.run_tests(newUpgradedToken);
})
});
9 changes: 6 additions & 3 deletions test/TokenTestUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ function checkMinterRemovedEvent(minterRemovedEvent, minter) {
assert.equal(minterRemovedEvent.logs[0].args.oldMinter, minter);
}



function checkTransferEventsWithFee(transferEvent, from, to, value, feeAmount) {
assert.equal(transferEvent.logs[0].event, 'Fee');
assert.equal(transferEvent.logs[0].args.from, from);
Expand Down Expand Up @@ -117,7 +115,6 @@ function checkUnblacklistEvent(unblacklistEvent, account) {
assert.equal(unblacklistEvent.logs[0].args._account, account);
}


function checkBlacklisterChangedEvent(blacklisterChangedEvent, blacklister) {
assert.equal(blacklisterChangedEvent.logs[0].event, 'BlacklisterChanged');
assert.equal(blacklisterChangedEvent.logs[0].args.newBlacklister, blacklister);
Expand Down Expand Up @@ -156,6 +153,10 @@ function checkTransferProxyOwnershipEvent(transferProxyOwnershipEvent, previousO
assert.equal(transferProxyOwnershipEvent.logs[0].args.newOwner, newOwner);
}

function checkPauseEvent(pause) {
assert.equal(pause.logs[0].event, 'Pause');
}

function checkUnpauseEvent(unpause) {
assert.equal(unpause.logs[0].event, 'Unpause');
}
Expand Down Expand Up @@ -902,10 +903,12 @@ module.exports = {
checkMinterConfiguredEvent: checkMinterConfiguredEvent,
checkMintEvent: checkMintEvent,
checkApprovalEvent: checkApprovalEvent,
checkBurnEvents: checkBurnEvents,
checkBurnEvent: checkBurnEvent,
checkMinterRemovedEvent: checkMinterRemovedEvent,
checkBlacklistEvent: checkBlacklistEvent,
checkUnblacklistEvent: checkUnblacklistEvent,
checkPauseEvent: checkPauseEvent,
checkUnpauseEvent: checkUnpauseEvent,
checkPauserChangedEvent: checkPauserChangedEvent,
checkTransferOwnershipEvent: checkTransferOwnershipEvent,
Expand Down