-
Notifications
You must be signed in to change notification settings - Fork 370
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-355] Write ArgumentTests #234
Merged
mirathewhite
merged 7 commits into
circlefin:multi-issuer
from
mirathewhite:argumentTests
Oct 24, 2018
+213
−1
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
cbb0555
use compact state representation and getters for FiatToken
mirathewhite 97199fe
export fiatTokenEmptyState
mirathewhite 475de90
Fixed bug: removed Accounts.upgraderAccount since it was causing dupl…
mirathewhite a156895
adding ArgumentTests
mirathewhite bc47ddb
reverting unchanged files
mirathewhite 5b4aa37
fixed test 006
mirathewhite e5907ce
merging
mirathewhite File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,212 @@ | ||
var MintController = artifacts.require('minting/MintController'); | ||
var MasterMinter = artifacts.require('minting/MasterMinter'); | ||
var MintController = artifacts.require('minting/MintController'); | ||
var MasterMinter = artifacts.require('minting/MasterMinter'); | ||
var FiatToken = artifacts.require('FiatTokenV1'); | ||
|
||
var BigNumber = require('bignumber.js'); | ||
var tokenUtils = require('./../TokenTestUtils'); | ||
var checkMINTp0 = tokenUtils.checkMINTp0; | ||
var expectRevert = tokenUtils.expectRevert; | ||
var expectJump = tokenUtils.expectJump; | ||
var bigZero = tokenUtils.bigZero; | ||
var maxAmount = tokenUtils.maxAmount; | ||
|
||
var clone = require('clone'); | ||
|
||
var mintUtils = require('./MintControllerUtils.js'); | ||
var AccountUtils = require('./../AccountUtils.js'); | ||
var Accounts = AccountUtils.Accounts; | ||
var getAccountState = AccountUtils.getAccountState; | ||
var MintControllerState = AccountUtils.MintControllerState; | ||
var initializeTokenWithProxyAndMintController = mintUtils.initializeTokenWithProxyAndMintController; | ||
var checkMintControllerState = mintUtils.checkMintControllerState; | ||
|
||
var zeroAddress = "0x0000000000000000000000000000000000000000"; | ||
var maxAmount = "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"; | ||
|
||
async function run_tests_MintController(newToken, accounts) { | ||
run_MINT_tests(newToken, MintController, accounts); | ||
} | ||
|
||
async function run_tests_MasterMinter(newToken, accounts) { | ||
run_MINT_tests(newToken, MasterMinter, accounts); | ||
} | ||
|
||
async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { | ||
|
||
beforeEach('Make fresh token contract', async function () { | ||
rawToken = await newToken(); | ||
tokenConfig = await initializeTokenWithProxyAndMintController(rawToken, MintControllerArtifact); | ||
token = tokenConfig.token; | ||
mintController = tokenConfig.mintController; | ||
expectedMintControllerState = clone(tokenConfig.customState); | ||
expectedTokenState = [{ 'variable': 'masterMinter', 'expectedValue': mintController.address }]; | ||
}); | ||
|
||
it('arg000 transferOwnership(msg.sender) works', async function () { | ||
await mintController.transferOwnership(Accounts.mintOwnerAccount, {from: Accounts.mintOwnerAccount}); | ||
await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); | ||
}); | ||
|
||
it('arg001 transferOwnership(0) reverts', async function () { | ||
await expectRevert(mintController.transferOwnership(zeroAddress, {from: Accounts.mintOwnerAccount})); | ||
}); | ||
|
||
it('arg002 transferOwnership(owner) works', async function () { | ||
await mintController.transferOwnership(Accounts.mintOwnerAccount, {from: Accounts.mintOwnerAccount}); | ||
await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); | ||
}); | ||
|
||
it('arg003 configureController(0, M) works', async function () { | ||
await mintController.configureController(zeroAddress, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); | ||
await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); | ||
|
||
// need to manually check mintController.controllers[0] because this is not a predefined account | ||
var actualMinter = await mintController.controllers(zeroAddress); | ||
assert.equal(Accounts.minterAccount, actualMinter); | ||
}); | ||
|
||
it('arg004 configureController(msg.sender, M) works', async function () { | ||
await mintController.configureController(Accounts.mintOwnerAccount, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); | ||
expectedMintControllerState.controllers['mintOwnerAccount'] = Accounts.minterAccount; | ||
await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); | ||
}); | ||
|
||
it('arg005 configureController(M, M) works', async function () { | ||
await mintController.configureController(Accounts.minterAccount, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); | ||
expectedMintControllerState.controllers['minterAccount'] = Accounts.minterAccount; | ||
await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); | ||
}); | ||
|
||
it('arg006 configureController(C, 0) throws', async function () { | ||
await expectRevert(mintController.configureController(Accounts.controller1Account, zeroAddress, {from: Accounts.mintOwnerAccount})); | ||
}); | ||
|
||
it('arg007 removeController(0) works', async function () { | ||
// expect no changes | ||
await mintController.removeController(zeroAddress, {from: Accounts.mintOwnerAccount}); | ||
await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); | ||
|
||
// now make 0 a controller | ||
await mintController.configureController(zeroAddress, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); | ||
var actualMinter = await mintController.controllers(zeroAddress); | ||
assert.equal(Accounts.minterAccount, actualMinter); | ||
|
||
// remove 0 | ||
await mintController.removeController(zeroAddress, {from: Accounts.mintOwnerAccount}); | ||
await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); | ||
actualMinter = await mintController.controllers(zeroAddress); | ||
assert.equal(zeroAddress, zeroAddress); | ||
}); | ||
|
||
it('arg008 setMinterManager(0) works', async function () { | ||
await mintController.setMinterManager(zeroAddress, {from: Accounts.mintOwnerAccount}); | ||
expectedMintControllerState.minterManager = zeroAddress; | ||
await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); | ||
}); | ||
|
||
it('arg009 setMinterManager(oldMinterManager) works', async function () { | ||
await mintController.setMinterManager(token.address, {from: Accounts.mintOwnerAccount}); | ||
expectedMintControllerState.minterManager = token.address; | ||
await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); | ||
}); | ||
|
||
it('arg010 setMinterManager(user_account) works', async function () { | ||
await mintController.setMinterManager(Accounts.arbitraryAccount, {from: Accounts.mintOwnerAccount}); | ||
expectedMintControllerState.minterManager = Accounts.arbitraryAccount; | ||
await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); | ||
}); | ||
|
||
it('arg011 setMinterManager(newToken) works', async function () { | ||
var newToken = await FiatToken.new(); | ||
await mintController.setMinterManager(newToken.address, {from: Accounts.mintOwnerAccount}); | ||
expectedMintControllerState.minterManager = newToken.address; | ||
await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); | ||
}); | ||
|
||
it('arg012 configureMinter(0) sets allowance to 0', async function () { | ||
await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); | ||
await mintController.configureMinter(0, {from: Accounts.controller1Account}); | ||
|
||
expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; | ||
expectedTokenState.push( | ||
{ 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, | ||
{ 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(0) } | ||
); | ||
await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); | ||
}); | ||
|
||
it('arg013 configureMinter(oldAllowance) makes no changes', async function () { | ||
var oldAllowance = 64738; | ||
await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); | ||
await mintController.configureMinter(oldAllowance, {from: Accounts.controller1Account}); | ||
await mintController.configureMinter(oldAllowance, {from: Accounts.controller1Account}); | ||
|
||
expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; | ||
expectedTokenState.push( | ||
{ 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, | ||
{ 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(oldAllowance) } | ||
); | ||
await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); | ||
}); | ||
|
||
it('arg014 configureMinter(MAX) works', async function () { | ||
await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); | ||
await mintController.configureMinter(maxAmount, {from: Accounts.controller1Account}); | ||
|
||
expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; | ||
expectedTokenState.push( | ||
{ 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, | ||
{ 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(maxAmount) } | ||
); | ||
await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); | ||
}); | ||
|
||
it('arg015 incrementMinterAllowance(0) makes no changes to allowance', async function () { | ||
var amount = 897; | ||
await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); | ||
await mintController.configureMinter(amount, {from: Accounts.controller1Account}); | ||
await mintController.incrementMinterAllowance(0, {from: Accounts.controller1Account}); | ||
|
||
expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; | ||
expectedTokenState.push( | ||
{ 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, | ||
{ 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount) } | ||
); | ||
await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); | ||
}); | ||
|
||
it('arg016 incrementMinterAllowance(oldAllowance) doubles the allowance', async function () { | ||
var amount = 897; | ||
await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); | ||
await mintController.configureMinter(amount, {from: Accounts.controller1Account}); | ||
await mintController.incrementMinterAllowance(amount, {from: Accounts.controller1Account}); | ||
|
||
expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; | ||
expectedTokenState.push( | ||
{ 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, | ||
{ 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(2*amount) } | ||
); | ||
await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); | ||
}); | ||
|
||
it('arg017 incrementMinterAllowance(MAX) throws', async function () { | ||
var amount = 1; | ||
await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); | ||
await mintController.configureMinter(amount, {from: Accounts.controller1Account}); | ||
await expectJump(mintController.incrementMinterAllowance(maxAmount, {from: Accounts.controller1Account})); | ||
}); | ||
|
||
it('arg018 incrementMinterAlllowance(BIG) throws', async function () { | ||
await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); | ||
await mintController.configureMinter(maxAmount, {from: Accounts.controller1Account}); | ||
await expectJump(mintController.incrementMinterAllowance(1, {from: Accounts.controller1Account})); | ||
}); | ||
|
||
} | ||
|
||
var testWrapper = require('./../TestWrapper'); | ||
testWrapper.execute('MINTp0_ArgumentTests MintController', run_tests_MintController); | ||
testWrapper.execute('MINTp0_ArgumentTests MasterMinter', run_tests_MasterMinter); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is always true, no?