From 43add119ea3a949485b5517899fca3dff16d5911 Mon Sep 17 00:00:00 2001 From: Erik Tierney Date: Thu, 2 Aug 2018 09:38:38 -0400 Subject: [PATCH 01/74] MINT p0 contracts and test framework --- contracts/minting/Controller.sol | 60 +++++++++++ contracts/minting/MasterMinter.sol | 28 +++++ contracts/minting/MintController.sol | 98 +++++++++++++++++ test/minting/AccountUtils.js | 154 +++++++++++++++++++++++++++ test/minting/ControllerTestUtils.js | 55 ++++++++++ test/minting/MintControllerTests.js | 58 ++++++++++ test/minting/MintControllerUtils.js | 55 ++++++++++ 7 files changed, 508 insertions(+) create mode 100644 contracts/minting/Controller.sol create mode 100644 contracts/minting/MasterMinter.sol create mode 100644 contracts/minting/MintController.sol create mode 100644 test/minting/AccountUtils.js create mode 100644 test/minting/ControllerTestUtils.js create mode 100644 test/minting/MintControllerTests.js create mode 100644 test/minting/MintControllerUtils.js diff --git a/contracts/minting/Controller.sol b/contracts/minting/Controller.sol new file mode 100644 index 000000000..ded08686c --- /dev/null +++ b/contracts/minting/Controller.sol @@ -0,0 +1,60 @@ +/** +* Copyright CENTRE SECZ 2018 +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is furnished to +* do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in all +* copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +pragma solidity ^0.4.24; + +import './../Ownable.sol'; + +/** + * @title Controller + * @dev Generic implementation of the owner-controller-minter model. + * + */ +contract Controller is Ownable { + // controllers[controller]=minter + // The controller manages a single minter address. + mapping(address => address) public controllers; + + event ControllerConfigured(address indexed _controller, address indexed _minter); + + /** + * @dev ensure that the caller is the controller of a non-zero minter address + */ + modifier onlyController() { + require(controllers[msg.sender] != address(0)); + _; + } + + constructor() public { + } + + // onlyOwner functions + + /** + * @dev set the controller of a particular _minter + * To disable the controller, call configureController(_controller, address(0)) + */ + function configureController(address _controller, address _minter) onlyOwner public returns (bool) { + controllers[_controller] = _minter; + emit ControllerConfigured(_controller, _minter); + return true; + } +} \ No newline at end of file diff --git a/contracts/minting/MasterMinter.sol b/contracts/minting/MasterMinter.sol new file mode 100644 index 000000000..20809b6b9 --- /dev/null +++ b/contracts/minting/MasterMinter.sol @@ -0,0 +1,28 @@ +/** +* Copyright CENTRE SECZ 2018 +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is furnished to +* do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in all +* copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +pragma solidity ^0.4.24; + +import './MintController.sol'; + +contract MasterMinter is MintController { + +} \ No newline at end of file diff --git a/contracts/minting/MintController.sol b/contracts/minting/MintController.sol new file mode 100644 index 000000000..e46c77dc0 --- /dev/null +++ b/contracts/minting/MintController.sol @@ -0,0 +1,98 @@ +/** +* Copyright CENTRE SECZ 2018 +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is furnished to +* do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in all +* copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +pragma solidity ^0.4.24; + +import './Controller.sol'; +import 'openzeppelin-solidity/contracts/math/SafeMath.sol'; + +// make an interface instead of including FiatTokenV1 since +// FiatTokenV1 will include a different impl of Ownable +interface MintableTokenInterface { + function isMinter(address account) external view returns (bool); + function minterAllowance(address minter) external view returns (uint256); + function configureMinter(address minter, uint256 minterAllowedAmount) external returns (bool); + function removeMinter(address minter) external returns (bool); +} + +/** + * @title MintController + * @dev allows control of configure/remove minter by different addresses + * + */ +contract MintController is Controller { + using SafeMath for uint256; + + MintableTokenInterface public token; + + event TokenSet(address indexed oldToken, address indexed newToken); + event MinterModified(address indexed msgSender, address indexed minter); + + constructor(address _token) public { + token = MintableTokenInterface(_token); + } + + // onlyOwner functions + + /** + * @dev sets the token + */ + function setToken(address _newToken) onlyOwner public returns (bool) { + emit TokenSet(token, _newToken); + token = MintableTokenInterface(_newToken); + return true; + } + + // onlyController functions + + /** + * @dev remove the controller's minter. + */ + function removeMinter() onlyController public returns (bool) { + address minter = controllers[msg.sender]; + emit MinterModified(msg.sender, minter); + return token.removeMinter(minter); + } + + /** + * @dev Enables the minter and sets its allowance + */ + function configureMinter(uint256 newAllowance) onlyController public returns (bool) { + address minter = controllers[msg.sender]; + return internal_setMinterAllowance(minter, newAllowance); + } + + function incrementMinterAllowance(uint256 allowanceIncrement) onlyController public returns (bool) { + address minter = controllers[msg.sender]; + require(token.isMinter(minter)); + + uint256 currentAllowance = token.minterAllowance(minter); + uint256 newAllowance = currentAllowance.add(allowanceIncrement); + + return internal_setMinterAllowance(minter, newAllowance); + } + + // Internal functions + function internal_setMinterAllowance(address minter, uint256 newAllowance) internal returns (bool) { + emit MinterModified(msg.sender, minter); + return token.configureMinter(minter, newAllowance); + } +} \ No newline at end of file diff --git a/test/minting/AccountUtils.js b/test/minting/AccountUtils.js new file mode 100644 index 000000000..389852ff8 --- /dev/null +++ b/test/minting/AccountUtils.js @@ -0,0 +1,154 @@ +// set to true to enable verbose logging in the tests +var debugLogging = false; +var assertDiff = require('assert-diff'); +assertDiff.options.strict = true; + + +// named list of all accounts +var mcAccounts = { + mintOwnerAccount: "0x1df62f291b2e969fb0849d99d9ce41e2f137006e", // accounts[9] + mintProtectorAccount: "0x610bb1573d1046fcb8a70bbbd395754cd57c2b60", // accounts[10] + controller1Account: "0x855fa758c77d68a04990e992aa4dcdef899f654a", // accounts[11] + controller2Account: "0xfa2435eacf10ca62ae6787ba2fb044f8733ee843", // accounts[12] + issuerOwnerAccount: "0x64e078a8aa15a41b85890265648e965de686bae6", // accounts[13] + issuerControllerAccount: "0x2f560290fef1b3ada194b6aa9c40aa71f8e95598", // accounts[14] + + deployerAccount: "0x90f8bf6a479f320ead074411a4b0e7944ea8c9c1", // accounts[0] + arbitraryAccount: "0xffcf8fdee72ac11b5c542428b35eef5769c409f0", // accounts[1] + tokenOwnerAccount: "0xe11ba2b4d45eaed5996cd0823791e0c93114882d", // accounts[3] + blacklisterAccount: "0xd03ea8624c8c5987235048901fb614fdca89b117", // accounts[4] Why Multiple blacklisterAccount?? + arbitraryAccount2: "0x95ced938f7991cd0dfcb48f0a06a40fa1af46ebc", // accounts[5] + masterMinterAccount: "0x3e5e9111ae8eb78fe1cc3bb8915d5d461f3ef9a9", // accounts[6] + minterAccount: "0x28a8746e75304c0780e011bed21c72cd78cd535e", // accounts[7] + pauserAccount: "0xaca94ef8bd5ffee41947b4585a84bda5a3d3da6e", // accounts[8] +} + +// named list of known private keys +var mcAccountsPrivateKeys = { + mintOwnerPrivateKey: "b0057716d5917badaf911b193b12b910811c1497b5bada8d7711f758981c3773", // accounts[9] + mintProtectorPrivateKey: "77c5495fbb039eed474fc940f29955ed0531693cc9212911efd35dff0373153f", // accounts[10] + controller1PrivateKey: "d99b5b29e6da2528bf458b26237a6cf8655a3e3276c1cdc0de1f98cefee81c01", // accounts[11] + controller2PrivateKey: "9b9c613a36396172eab2d34d72331c8ca83a358781883a535d2941f66db07b24", // accounts[12] + issuerOwnerPrivateKey: "0874049f95d55fb76916262dc70571701b5c4cc5900c0691af75f1a8a52c8268", // accounts[13] + issuerController2PrivateKey: "21d7212f3b4e5332fd465877b64926e3532653e2798a11255a46f533852dfe46" // accounts[14] +} + +// Returns an object with all named account values set to the default value +// e.g sets {owner: 0, minter: 0,...} +function setAccountDefault(accounts, defaultValue) { + var result = {}; + for (var accountName in accounts) { + result[accountName] = defaultValue; + } + return result; +} + +// Clones a state object +function cloneState(state) { + // for each item in customVars, set the item in expectedState + var clone = {}; + for (var attr in state) { + var attrValue = state[attr]; + if(isLiteral(attrValue)) { + clone[attr] = state[attr]; + } else { + clone[attr] = cloneState(attrValue); + } + } + return clone; +} + +// return an expectedState that combines customState with the emptyState +// todo: after merge, integrate this with TokenTestUtils.js +function buildExpectedPartialState(emptyState, customState, ignoreExtraCustomVars) { + // for each item in customVars, set the item in expectedState + var expectedState = cloneState(emptyState); + + for( var variableName in customState) { + // do I ignore extra values + if(expectedState.hasOwnProperty(variableName)) { + var variableValue = customState[variableName]; + if(isLiteral(variableValue)) { + expectedState[variableName] = variableValue; + } else { + // assume variableValue is a mapping evaluated on 1 or more accounts + for(var accountName in variableValue) { + expectedState[variableName][accountName] = variableValue[accountName]; + } + } + } else if(! ignoreExtraCustomVars) { + throw new Error("variable " + variableName + " not found in expectedState"); + } + } + return expectedState; +} + +// For testing variance of specific variables from their default values. +// customVars is an array of objects of the form, +// {'variable': , 'expectedValue': } +// to reference nested variables, name variable using dot syntax, e.g. 'allowance.arbitraryAccount.minterAccount' +// emptyState: is the ideal empty state +// getActualState: async function(token, accounts) => state +// accounts: list of accounts on which to evaluate mappings +// ignoreExtraCustomVars: ignore _customVars names that are not in the emptyState +// todo: after merge, integrate this with TokenTestUtils.js +async function checkState(_tokens, _customVars, emptyState, getActualState, accounts, ignoreExtraCustomVars) { + // Iterate over array of tokens. + var numTokens = _tokens.length; + assert.equal(numTokens, _customVars.length); + var n; + for (n = 0; n < numTokens; n++) { + var token = _tokens[n]; + var customVars = _customVars[n]; + let expectedState = buildExpectedPartialState(emptyState, customVars, ignoreExtraCustomVars); + + if (debugLogging) { + console.log(util.inspect(expectedState, { showHidden: false, depth: null })) + } + + let actualState = await getActualState(token, accounts); + assertDiff.deepEqual(actualState, expectedState, "difference between expected and actual state"); + } +} + +// accountQuery: an async function that takes as input an address and +// queries the blockchain for a result +// accounts: an object containing account addresses. Eg: {owner: 0xffad9033, minter: 0x45289432} +// 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]); + } + return results; +} + +function isLiteral(object) { + if(typeof(object) == 'object' && ! object._isBigNumber) + return false; + return true; +} + +// Turns a simple literal object into a printable string +function logObject(object) { + var output = ''; + for (var property in object) { + if(isLiteral(object[property])) { + output += property + ':\n' + logObject(object[property]); + } else { + output += property + ': ' + object[property]+';\n '; + } + } + return output; +} + +module.exports = { + mcAccounts: mcAccounts, + setAccountDefault: setAccountDefault, + cloneState: cloneState, + buildExpectedPartialState: buildExpectedPartialState, + checkState: checkState, + logObject: logObject, + getAccountState: getAccountState, +} \ No newline at end of file diff --git a/test/minting/ControllerTestUtils.js b/test/minting/ControllerTestUtils.js new file mode 100644 index 000000000..17f37a98e --- /dev/null +++ b/test/minting/ControllerTestUtils.js @@ -0,0 +1,55 @@ +var BigNumber = require('bignumber.js'); +var Q = require('q'); + +// set to true to enable verbose logging in the tests +var debugLogging = false; + + +var tokenUtils = require('./../TokenTestUtils'); + +var Controller = artifacts.require('./../minting/Controller'); +var AccountUtils = require('./AccountUtils'); +var mcAccounts = AccountUtils.mcAccounts; +var setAccountDefault = AccountUtils.setAccountDefault; +var checkState = AccountUtils.checkState; +var getAccountState = AccountUtils.getAccountState; + +// Default state of Controller when it is deployed +var controllerEmptyState = { + 'owner': mcAccounts.mintOwnerAccount, + 'controllers': setAccountDefault(mcAccounts, "0x0000000000000000000000000000000000000000") +}; + +// Checks the state of an array of controller contracts +async function checkControllerState(controllers, customVars, ignoreExtraStateVariables) { + await checkState(controllers, customVars, controllerEmptyState, getActualControllerState, mcAccounts, ignoreExtraStateVariables); +} + +// Gets the actual state of the controller contract. +// Evaluates all mappings on the provided accounts. +async function getActualControllerState(controllerContract, accounts) { + // Lambda expressions for retrieving values from mappings + var controllerMappingEval = async function(accountAddress) { + return await controllerContract.controllers(accountAddress); + }; + + return Q.all([ + await controllerContract.owner.call(), + await getAccountState(controllerMappingEval, accounts), + ]).spread(function ( + owner, + controllerState, + ) { + var actualState = { + 'owner': owner, + 'controllers': controllerState, + }; + return actualState; + }) +} + +module.exports = { + controllerEmptyState: controllerEmptyState, + checkControllerState: checkControllerState, + getActualControllerState: getActualControllerState +} \ No newline at end of file diff --git a/test/minting/MintControllerTests.js b/test/minting/MintControllerTests.js new file mode 100644 index 000000000..e36eedbeb --- /dev/null +++ b/test/minting/MintControllerTests.js @@ -0,0 +1,58 @@ +var MintController = artifacts.require('minting/MintController'); + +var BigNumber = require('bignumber.js'); +var tokenUtils = require('./../TokenTestUtils'); +var checkVariables = tokenUtils.checkVariables; + +var mintUtils = require('./MintControllerUtils.js'); +var AccountUtils = require('./AccountUtils.js'); +var A = AccountUtils.mcAccounts; +var initializeTokenWithProxyAndMintController = mintUtils.initializeTokenWithProxyAndMintController; +var checkMintControllerState = mintUtils.checkMintControllerState; + +async function run_tests(newToken, accounts) { + + beforeEach('Make fresh token contract', async function () { + rawToken = await newToken(); + var tokenConfig = await initializeTokenWithProxyAndMintController(rawToken); + token = tokenConfig.token; + mintController = tokenConfig.mintController; + }); + + it('should mint through mint controller', async function () { + + var amount = 5000; + await mintController.configureController(A.controller1Account, A.minterAccount, {from: A.mintOwnerAccount}); + await mintController.configureMinter(amount, {from: A.controller1Account}); + customState = { + 'token': token.address, + 'controllers': {'controller1Account': A.minterAccount } + } + await checkMintControllerState([mintController], [customState]); + + await token.mint(A.arbitraryAccount, amount, {from: A.minterAccount}); + customVars = [ + { 'variable': 'masterMinter', 'expectedValue': mintController.address }, + { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, + { 'variable': 'balances.arbitraryAccount', 'expectedValue': new BigNumber(amount) }, + { 'variable': 'totalSupply', 'expectedValue': new BigNumber(amount)} + ]; + await checkVariables([token], [customVars]); + }); + + it('initial state', async function () { + customState = { + 'token': token.address, + }; + + await checkMintControllerState([mintController], [customState]); + }); + +} + +var testWrapper = require('./../TestWrapper'); +testWrapper.execute('MintController_Tests', run_tests); + +module.exports = { + run_tests: run_tests, +} \ No newline at end of file diff --git a/test/minting/MintControllerUtils.js b/test/minting/MintControllerUtils.js new file mode 100644 index 000000000..c158fe730 --- /dev/null +++ b/test/minting/MintControllerUtils.js @@ -0,0 +1,55 @@ +var BigNumber = require('bignumber.js'); +var bigZero = new BigNumber(0); + +var tokenUtils = require('./../TokenTestUtils'); +var initializeTokenWithProxy = tokenUtils.initializeTokenWithProxy; + +var MintController = artifacts.require('./../minting/MintController'); +var AccountUtils = require('./AccountUtils'); +var mcAccounts = AccountUtils.mcAccounts; +var setAccountDefault = AccountUtils.setAccountDefault; +var checkState = AccountUtils.checkState; +var getAccountState = AccountUtils.getAccountState; + +var ControllerUtils = require('./ControllerTestUtils'); +var checkControllerState = ControllerUtils.checkControllerState; + + +// Deploys a FiatTokenV1 with a MintController contract as the masterMinter. +// Uses the same workflow we would do in production - first deploy FiatToken then set the masterMinter. +async function initializeTokenWithProxyAndMintController(rawToken) { + var tokenConfig = await initializeTokenWithProxy(rawToken); + var mintController = await MintController.new(tokenConfig.token.address, {from:mcAccounts.mintOwnerAccount}); + await tokenConfig.token.updateMasterMinter(mintController.address, {from:tokenUtils.tokenOwnerAccount}); + var tokenConfigWithMinter = { + proxy: tokenConfig.proxy, + token: tokenConfig.token, + mintController: mintController + }; + return tokenConfigWithMinter; +} + +// Default state of MintController when it is deployed +var mintControllerEmptyState = { + 'token' : bigZero, +}; + +// Checks the state of the mintController contract +async function checkMintControllerState(mintControllers, customVars) { + await checkControllerState(mintControllers, customVars, true); + await checkState(mintControllers, customVars, mintControllerEmptyState, getActualMintControllerState, mcAccounts, true); +} + + +// Gets the actual state of the mintController contract. +// Evaluates all mappings on the provided accounts. +async function getActualMintControllerState(mintController, accounts) { + return { + 'token': await mintController.token.call() + }; +} + +module.exports = { + initializeTokenWithProxyAndMintController: initializeTokenWithProxyAndMintController, + checkMintControllerState: checkMintControllerState +} \ No newline at end of file From 207af4b3ef7fcb0d93fb8f2d87db5155c6d944db Mon Sep 17 00:00:00 2001 From: mirathewhite Date: Wed, 12 Sep 2018 12:38:03 -0400 Subject: [PATCH 02/74] Added comments, events, and modified Controller to use workers instead of minters --- contracts/minting/Controller.sol | 20 +++++++++++--------- contracts/minting/MintController.sol | 25 +++++++++++++++++++------ 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/contracts/minting/Controller.sol b/contracts/minting/Controller.sol index ded08686c..c8c2c0c4e 100644 --- a/contracts/minting/Controller.sol +++ b/contracts/minting/Controller.sol @@ -25,18 +25,18 @@ import './../Ownable.sol'; /** * @title Controller - * @dev Generic implementation of the owner-controller-minter model. + * @dev Generic implementation of the owner-controller-worker model. * */ contract Controller is Ownable { - // controllers[controller]=minter - // The controller manages a single minter address. + // controllers[controller] = worker + // The controller manages a single worker address. mapping(address => address) public controllers; - event ControllerConfigured(address indexed _controller, address indexed _minter); + event ControllerConfigured(address indexed _controller, address indexed _worker); /** - * @dev ensure that the caller is the controller of a non-zero minter address + * @dev ensure that the caller is the controller of a non-zero worker address */ modifier onlyController() { require(controllers[msg.sender] != address(0)); @@ -49,12 +49,14 @@ contract Controller is Ownable { // onlyOwner functions /** - * @dev set the controller of a particular _minter + * @dev set the controller of a particular _worker * To disable the controller, call configureController(_controller, address(0)) + * Since a controller manages a single worker, assigning it address(0) is equivalent to + * removing _controller from the list of active controllers. */ - function configureController(address _controller, address _minter) onlyOwner public returns (bool) { - controllers[_controller] = _minter; - emit ControllerConfigured(_controller, _minter); + function configureController(address _controller, address _worker) onlyOwner public returns (bool) { + controllers[_controller] = _worker; + emit ControllerConfigured(_controller, _worker); return true; } } \ No newline at end of file diff --git a/contracts/minting/MintController.sol b/contracts/minting/MintController.sol index e46c77dc0..b7fdac272 100644 --- a/contracts/minting/MintController.sol +++ b/contracts/minting/MintController.sol @@ -24,8 +24,8 @@ pragma solidity ^0.4.24; import './Controller.sol'; import 'openzeppelin-solidity/contracts/math/SafeMath.sol'; -// make an interface instead of including FiatTokenV1 since -// FiatTokenV1 will include a different impl of Ownable +// Using an interface for managing minters so that MintController +// can be used for managing minters with different contracts. interface MintableTokenInterface { function isMinter(address account) external view returns (bool); function minterAllowance(address minter) external view returns (uint256); @@ -44,7 +44,9 @@ contract MintController is Controller { MintableTokenInterface public token; event TokenSet(address indexed oldToken, address indexed newToken); - event MinterModified(address indexed msgSender, address indexed minter); + event MinterConfigured(address indexed msgSender, address indexed minter, uint256 allowance); + event MinterRemoved(address indexed msgSender, address indexed minter); + event MinterAllowanceIncrement(address indexed msgSender, address indexed minter, uint256 increment, uint256 newAllowance); constructor(address _token) public { token = MintableTokenInterface(_token); @@ -68,7 +70,7 @@ contract MintController is Controller { */ function removeMinter() onlyController public returns (bool) { address minter = controllers[msg.sender]; - emit MinterModified(msg.sender, minter); + emit MinterRemoved(msg.sender, minter); return token.removeMinter(minter); } @@ -77,22 +79,33 @@ contract MintController is Controller { */ function configureMinter(uint256 newAllowance) onlyController public returns (bool) { address minter = controllers[msg.sender]; + emit MinterConfigured(msg.sender, minter, newAllowance); return internal_setMinterAllowance(minter, newAllowance); } - function incrementMinterAllowance(uint256 allowanceIncrement) onlyController public returns (bool) { + /** + * @dev Increases the minter allowance if and only if the minter is + * currently active. The controller can safely send a signed incrementMinterAllowance() + * transaction to a minter and not worry about it being used to undo a removeMinter() + * transaction. + */ + function incrementMinterAllowance(uint256 allowanceIncrement) onlyController public returns (bool) { address minter = controllers[msg.sender]; require(token.isMinter(minter)); uint256 currentAllowance = token.minterAllowance(minter); uint256 newAllowance = currentAllowance.add(allowanceIncrement); + emit MinterAllowanceIncrement(msg.sender, minter, allowanceIncrement, newAllowance); return internal_setMinterAllowance(minter, newAllowance); } // Internal functions + + /** + * @dev Uses the MintableTokenInterface to enable the minter and set its allowance. + */ function internal_setMinterAllowance(address minter, uint256 newAllowance) internal returns (bool) { - emit MinterModified(msg.sender, minter); return token.configureMinter(minter, newAllowance); } } \ No newline at end of file From 7514170e0c50217b83145387c93c094f9b8a39a6 Mon Sep 17 00:00:00 2001 From: mirathewhite Date: Wed, 12 Sep 2018 16:20:34 -0400 Subject: [PATCH 03/74] All tests use global Accounts object from AccountUtils. --- test/ABITests.test.js | 101 +++++----- test/{minting => }/AccountUtils.js | 40 ++-- test/EventsTests.js | 96 +++++----- test/ExtendedPositiveTests.js | 171 +++++++++-------- test/FiatTokenLegacy.test.js | 193 ++++++++++---------- test/MiscTests.js | 192 ++++++++++--------- test/NegativeTests.js | 274 ++++++++++++++-------------- test/Pausable.test.js | 36 ++-- test/PositiveTests.js | 76 ++++---- test/ProxyNegativeTests.js | 55 +++--- test/ProxyPositiveTests.js | 128 ++++++------- test/TokenTestUtils.js | 229 +++++++++-------------- test/minting/ControllerTestUtils.js | 10 +- test/minting/MintControllerTests.js | 4 +- test/minting/MintControllerUtils.js | 8 +- 15 files changed, 755 insertions(+), 858 deletions(-) rename test/{minting => }/AccountUtils.js (79%) diff --git a/test/ABITests.test.js b/test/ABITests.test.js index 0c5d5d2f6..21c2cde41 100644 --- a/test/ABITests.test.js +++ b/test/ABITests.test.js @@ -16,27 +16,10 @@ var pauserRole = tokenUtils.pauserRole; var checkVariables = tokenUtils.checkVariables; var checkFailureIsExpected = tokenUtils.checkFailureIsExpected; var initializeTokenWithProxy = tokenUtils.initializeTokenWithProxy; -var deployerAccount = tokenUtils.deployerAccount; -var arbitraryAccount = tokenUtils.arbitraryAccount; -var upgraderAccount = tokenUtils.upgraderAccount; -var blacklisterAccount = tokenUtils.blacklisterAccount; -var arbitraryAccount2 = tokenUtils.arbitraryAccount2; -var masterMinterAccount = tokenUtils.masterMinterAccount; -var minterAccount = tokenUtils.minterAccount; -var pauserAccount = tokenUtils.pauserAccount; -var tokenOwnerAccount = tokenUtils.tokenOwnerAccount; -var deployerAccountPrivateKey = tokenUtils.deployerAccountPrivateKey; -var arbitraryAccountPrivateKey = tokenUtils.arbitraryAccountPrivateKey; -var tokenOwnerPrivateKey = tokenUtils.ownerAccountPrivateKey; -var upgraderAccountPrivateKey = tokenUtils.upgraderAccountPrivateKey; -var tokenOwnerPrivateKey = tokenUtils.tokenOwnerPrivateKey; -var blacklisterAccountPrivateKey = tokenUtils.blacklisterAccountPrivateKey; -var arbitraryAccount2PrivateKey = tokenUtils.arbitraryAccount2PrivateKey; -var masterMinterAccountPrivateKey = tokenUtils.masterMinterAccountPrivateKey; -var minterAccountPrivateKey = tokenUtils.minterAccountPrivateKey; -var pauserAccountPrivateKey = tokenUtils.pauserAccountPrivateKey; -var blacklisterAccountPrivateKey = tokenUtils.blacklisterAccountPrivateKey; +var AccountUtils = require('./AccountUtils'); +var Accounts = AccountUtils.Accounts; +var AccountPrivateKeys = AccountUtils.AccountPrivateKeys; var abiUtils = require('./ABIUtils'); var makeRawTransaction = abiUtils.makeRawTransaction; @@ -70,14 +53,14 @@ async function run_tests(newToken, accounts) { it('abi004 FiatToken pause() is public', async function () { let badData = functionSignature('pause()'); var tx = new Tx({ - nonce: web3.toHex(web3.eth.getTransactionCount(pauserAccount)), + nonce: web3.toHex(web3.eth.getTransactionCount(Accounts.pauserAccount)), gasPrice: web3.toHex(web3.toWei('20', 'gwei')), gasLimit: 100000, to: token.address, value: 0, data: badData, }); - var privateKey = Buffer.from(pauserAccountPrivateKey, 'hex'); + var privateKey = Buffer.from(AccountPrivateKeys.pauserPrivateKey, 'hex'); tx.sign(privateKey); var raw = '0x' + tx.serialize().toString('hex'); @@ -91,14 +74,14 @@ async function run_tests(newToken, accounts) { it('abi040 Blacklistable constructor is not a function', async function () { let badData = functionSignature('Blacklistable()'); var tx = new Tx({ - nonce: web3.toHex(web3.eth.getTransactionCount(pauserAccount)), + nonce: web3.toHex(web3.eth.getTransactionCount(Accounts.pauserAccount)), gasPrice: web3.toHex(web3.toWei('20', 'gwei')), gasLimit: 100000, to: token.address, value: 0, data: badData, }); - var privateKey = Buffer.from(pauserAccountPrivateKey, 'hex'); + var privateKey = Buffer.from(AccountPrivateKeys.pauserPrivateKey, 'hex'); tx.sign(privateKey); var raw = '0x' + tx.serialize().toString('hex'); @@ -108,14 +91,14 @@ async function run_tests(newToken, accounts) { it('abi042 Ownable constructor is not a function', async function () { let badData = functionSignature('Ownable()'); var tx = new Tx({ - nonce: web3.toHex(web3.eth.getTransactionCount(pauserAccount)), + nonce: web3.toHex(web3.eth.getTransactionCount(Accounts.pauserAccount)), gasPrice: web3.toHex(web3.toWei('20', 'gwei')), gasLimit: 100000, to: token.address, value: 0, data: badData, }); - var privateKey = Buffer.from(pauserAccountPrivateKey, 'hex'); + var privateKey = Buffer.from(AccountPrivateKeys.pauserPrivateKey, 'hex'); tx.sign(privateKey); var raw = '0x' + tx.serialize().toString('hex'); @@ -125,14 +108,14 @@ async function run_tests(newToken, accounts) { it('abi005 Pausable constructor is not a function', async function () { let badData = functionSignature('Pausable()'); var tx = new Tx({ - nonce: web3.toHex(web3.eth.getTransactionCount(pauserAccount)), + nonce: web3.toHex(web3.eth.getTransactionCount(Accounts.pauserAccount)), gasPrice: web3.toHex(web3.toWei('20', 'gwei')), gasLimit: 100000, to: token.address, value: 0, data: badData, }); - var privateKey = Buffer.from(pauserAccountPrivateKey, 'hex'); + var privateKey = Buffer.from(AccountPrivateKeys.pauserPrivateKey, 'hex'); tx.sign(privateKey); var raw = '0x' + tx.serialize().toString('hex'); @@ -142,14 +125,14 @@ async function run_tests(newToken, accounts) { it('abi043 FiatTokenProxy constructor is not a function', async function () { let badData = functionSignature('FiatTokenProxy()'); var tx = new Tx({ - nonce: web3.toHex(web3.eth.getTransactionCount(pauserAccount)), + nonce: web3.toHex(web3.eth.getTransactionCount(Accounts.pauserAccount)), gasPrice: web3.toHex(web3.toWei('20', 'gwei')), gasLimit: 100000, to: token.address, value: 0, data: badData, }); - var privateKey = Buffer.from(pauserAccountPrivateKey, 'hex'); + var privateKey = Buffer.from(AccountPrivateKeys.pauserPrivateKey, 'hex'); tx.sign(privateKey); var raw = '0x' + tx.serialize().toString('hex'); @@ -157,11 +140,11 @@ async function run_tests(newToken, accounts) { }); it('abi027 UpgradeabilityProxy constructor', async function () { - let badData = msgData('UpgradeabilityProxy(address)', arbitraryAccount); + let badData = msgData('UpgradeabilityProxy(address)', Accounts.arbitraryAccount); let raw = makeRawTransaction( badData, - arbitraryAccount, - arbitraryAccountPrivateKey, + Accounts.arbitraryAccount, + AccountPrivateKeys.arbitraryPrivateKey, token.address); await expectRevert(sendRawTransaction(raw)); }); @@ -170,18 +153,18 @@ async function run_tests(newToken, accounts) { let badData = functionSignature('Proxy()'); let raw = makeRawTransaction( badData, - arbitraryAccount, - arbitraryAccountPrivateKey, + Accounts.arbitraryAccount, + AccountPrivateKeys.arbitraryPrivateKey, token.address); await expectRevert(sendRawTransaction(raw)); }); it('abi056 Proxy _delegate is internal', async function () { - let badData = msgData('_delegate(address)', arbitraryAccount); + let badData = msgData('_delegate(address)', Accounts.arbitraryAccount); let raw = makeRawTransaction( badData, - arbitraryAccount, - arbitraryAccountPrivateKey, + Accounts.arbitraryAccount, + AccountPrivateKeys.arbitraryPrivateKey, token.address); await expectRevert(sendRawTransaction(raw)); }); @@ -190,8 +173,8 @@ async function run_tests(newToken, accounts) { let badData = functionSignature('_willFallback()'); let raw = makeRawTransaction( badData, - arbitraryAccount, - arbitraryAccountPrivateKey, + Accounts.arbitraryAccount, + AccountPrivateKeys.arbitraryPrivateKey, token.address); await expectRevert(sendRawTransaction(raw)); }); @@ -200,38 +183,38 @@ async function run_tests(newToken, accounts) { let badData = functionSignature('_fallback()'); let raw = makeRawTransaction( badData, - arbitraryAccount, - arbitraryAccountPrivateKey, + Accounts.arbitraryAccount, + AccountPrivateKeys.arbitraryPrivateKey, token.address); await expectRevert(sendRawTransaction(raw)); }); it('abi050 Upgradeability implementation is internal', async function () { - let badData = msgData('UpgradeabilityProxy(address)', arbitraryAccount); + let badData = msgData('UpgradeabilityProxy(address)', Accounts.arbitraryAccount); let raw = makeRawTransaction( badData, - arbitraryAccount, - arbitraryAccountPrivateKey, + Accounts.arbitraryAccount, + AccountPrivateKeys.arbitraryPrivateKey, token.address); await expectRevert(sendRawTransaction(raw)); }); it('abi051 AdminUpgradeabillityProxy constructor is not a function', async function () { - let badData = msgData('AdminUpgradeabillityProxy(address)', arbitraryAccount); + let badData = msgData('AdminUpgradeabillityProxy(address)', Accounts.arbitraryAccount); let raw = makeRawTransaction( badData, - arbitraryAccount, - arbitraryAccountPrivateKey, + Accounts.arbitraryAccount, + AccountPrivateKeys.arbitraryPrivateKey, token.address); await expectRevert(sendRawTransaction(raw)); }); it('abi053 AdminUpgradeabillityProxy _setAdmin is internal', async function () { - let badData = msgData('AdminUpgradeabillityProxy(address)', arbitraryAccount); + let badData = msgData('AdminUpgradeabillityProxy(address)', Accounts.arbitraryAccount); let raw = makeRawTransaction( badData, - arbitraryAccount, - arbitraryAccountPrivateKey, + Accounts.arbitraryAccount, + AccountPrivateKeys.arbitraryPrivateKey, token.address); await expectRevert(sendRawTransaction(raw)); }); @@ -239,14 +222,14 @@ async function run_tests(newToken, accounts) { it('abi041 FiatToken constructor is not a function', async function () { let badData = functionSignature('FiatToken()'); var tx = new Tx({ - nonce: web3.toHex(web3.eth.getTransactionCount(pauserAccount)), + nonce: web3.toHex(web3.eth.getTransactionCount(Accounts.pauserAccount)), gasPrice: web3.toHex(web3.toWei('20', 'gwei')), gasLimit: 100000, to: token.address, value: 0, data: badData, }); - var privateKey = Buffer.from(pauserAccountPrivateKey, 'hex'); + var privateKey = Buffer.from(AccountPrivateKeys.pauserPrivateKey, 'hex'); tx.sign(privateKey); var raw = '0x' + tx.serialize().toString('hex'); @@ -254,16 +237,16 @@ async function run_tests(newToken, accounts) { }); it('abi025 setOwner is internal', async function () { - let badData = msgData('setOwner(address)', pauserAccount); + let badData = msgData('setOwner(address)', Accounts.pauserAccount); var tx = new Tx({ - nonce: web3.toHex(web3.eth.getTransactionCount(tokenOwnerAccount)), + nonce: web3.toHex(web3.eth.getTransactionCount(Accounts.tokenOwnerAccount)), gasPrice: web3.toHex(web3.toWei('20', 'gwei')), gasLimit: 100000, to: token.address, value: 0, data: badData, }); - var privateKey = Buffer.from(tokenOwnerPrivateKey, 'hex'); + var privateKey = Buffer.from(AccountPrivateKeys.tokenOwnerPrivateKey, 'hex'); tx.sign(privateKey); var raw = '0x' + tx.serialize().toString('hex'); @@ -271,11 +254,11 @@ async function run_tests(newToken, accounts) { }); it('abi028 UpgradeabilityProxy._upgradeTo is internal', async function () { - let badData = mockStringAddressEncode('_upgradeTo(string,address)', pauserAccount); + let badData = mockStringAddressEncode('_upgradeTo(string,address)', Accounts.pauserAccount); let raw = makeRawTransaction( badData, - tokenOwnerAccount, - tokenOwnerPrivateKey, + Accounts.tokenOwnerAccount, + AccountPrivateKeys.tokenOwnerPrivateKey, token.address); await expectRevert(sendRawTransaction(raw)); }); diff --git a/test/minting/AccountUtils.js b/test/AccountUtils.js similarity index 79% rename from test/minting/AccountUtils.js rename to test/AccountUtils.js index 389852ff8..1660839e3 100644 --- a/test/minting/AccountUtils.js +++ b/test/AccountUtils.js @@ -5,33 +5,44 @@ assertDiff.options.strict = true; // named list of all accounts -var mcAccounts = { - mintOwnerAccount: "0x1df62f291b2e969fb0849d99d9ce41e2f137006e", // accounts[9] - mintProtectorAccount: "0x610bb1573d1046fcb8a70bbbd395754cd57c2b60", // accounts[10] - controller1Account: "0x855fa758c77d68a04990e992aa4dcdef899f654a", // accounts[11] - controller2Account: "0xfa2435eacf10ca62ae6787ba2fb044f8733ee843", // accounts[12] - issuerOwnerAccount: "0x64e078a8aa15a41b85890265648e965de686bae6", // accounts[13] - issuerControllerAccount: "0x2f560290fef1b3ada194b6aa9c40aa71f8e95598", // accounts[14] - +var Accounts = { deployerAccount: "0x90f8bf6a479f320ead074411a4b0e7944ea8c9c1", // accounts[0] arbitraryAccount: "0xffcf8fdee72ac11b5c542428b35eef5769c409f0", // accounts[1] + issuerControllerAccount: "0x22d491bde2303f2f43325b2108d26f1eaba1e32b", // accounts[2] tokenOwnerAccount: "0xe11ba2b4d45eaed5996cd0823791e0c93114882d", // accounts[3] - blacklisterAccount: "0xd03ea8624c8c5987235048901fb614fdca89b117", // accounts[4] Why Multiple blacklisterAccount?? + 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] + controller1Account: "0x855fa758c77d68a04990e992aa4dcdef899f654a", // accounts[11] + 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 mcAccountsPrivateKeys = { +var AccountPrivateKeys = { + deployerPrivateKey: "4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b1d", // accounts[0] + arbitraryPrivateKey: "6cbed15c793ce57650b9877cf6fa156fbef513c4e6134f022a85b1ffdd59b2a1", // accounts[1] + issuerControllerPrivateKey: "6370fd033278c143179d81c5526140625662b8daa446c22ee2d73db3707e620c", // accounts[2] + tokenOwnerPrivateKey: "646f1ce2fdad0e6deeeb5c7e8e5543bdde65e86029e2fd9fc169899c440a7913", // accounts[3] + blacklisterPrivateKey: "add53f9a7e588d003326d1cbf9e4a43c061aadd9bc938c843a79e7b4fd2ad743", // accounts[4] + arbitrary2PrivateKey: "395df67f0c2d2d9fe1ad08d1bc8b6627011959b79c53d7dd6a3536a33ab8a4fd", // accounts[5] + masterMinterPrivateKey: "e485d098507f54e7733a205420dfddbe58db035fa577fc294ebd14db90767a52", // accounts[6] + minterPrivateKeyt: "a453611d9419d0e56f499079478fd72c37b251a94bfde4d19872c44cf65386e3", // accounts[7] + pauserPrivateKey: "829e924fdf021ba3dbbc4225edfece9aca04b929d6e75613329ca6f1d31c0bb4", // accounts[8] mintOwnerPrivateKey: "b0057716d5917badaf911b193b12b910811c1497b5bada8d7711f758981c3773", // accounts[9] mintProtectorPrivateKey: "77c5495fbb039eed474fc940f29955ed0531693cc9212911efd35dff0373153f", // accounts[10] controller1PrivateKey: "d99b5b29e6da2528bf458b26237a6cf8655a3e3276c1cdc0de1f98cefee81c01", // accounts[11] controller2PrivateKey: "9b9c613a36396172eab2d34d72331c8ca83a358781883a535d2941f66db07b24", // accounts[12] issuerOwnerPrivateKey: "0874049f95d55fb76916262dc70571701b5c4cc5900c0691af75f1a8a52c8268", // accounts[13] - issuerController2PrivateKey: "21d7212f3b4e5332fd465877b64926e3532653e2798a11255a46f533852dfe46" // accounts[14] -} + proxyOwnerAccount: "21d7212f3b4e5332fd465877b64926e3532653e2798a11255a46f533852dfe46", // accounts[14] + upgraderAccount: "21d7212f3b4e5332fd465877b64926e3532653e2798a11255a46f533852dfe46" // accounts[14] +}; // Returns an object with all named account values set to the default value // e.g sets {owner: 0, minter: 0,...} @@ -144,7 +155,8 @@ function logObject(object) { } module.exports = { - mcAccounts: mcAccounts, + Accounts: Accounts, + AccountPrivateKeys: AccountPrivateKeys, setAccountDefault: setAccountDefault, cloneState: cloneState, buildExpectedPartialState: buildExpectedPartialState, diff --git a/test/EventsTests.js b/test/EventsTests.js index 3b9b3ed63..0d3c68c11 100644 --- a/test/EventsTests.js +++ b/test/EventsTests.js @@ -1,21 +1,12 @@ var tokenUtils = require('./TokenTestUtils'); var FiatToken = tokenUtils.FiatToken; var FiatTokenProxy = tokenUtils.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; @@ -37,6 +28,9 @@ var UpgradedFiatTokenNewFields = tokenUtils.UpgradedFiatTokenNewFields; var checkPauseEvent = tokenUtils.checkPauseEvent; var checkTransferEvents = tokenUtils.checkTransferEvents; +var AccountUtils = require('./AccountUtils'); +var Accounts = AccountUtils.Accounts; + var amount = 100; async function run_tests(newToken, accounts) { @@ -50,99 +44,99 @@ async function run_tests(newToken, accounts) { }); it('et000 should check MinterConfigured event', async function() { - let configureMinter = await token.configureMinter(minterAccount, amount, { from: masterMinterAccount }); - checkMinterConfiguredEvent(configureMinter, minterAccount, amount); + let configureMinter = await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); + checkMinterConfiguredEvent(configureMinter, Accounts.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); + await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); + let mint = await token.mint(Accounts.arbitraryAccount, amount, {from: Accounts.minterAccount}); + checkMintEvent(mint, Accounts.arbitraryAccount, amount, Accounts.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); + await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); + await token.mint(Accounts.minterAccount, amount, { from: Accounts.minterAccount }); + let burn = await token.burn(amount, {from: Accounts.minterAccount}); + checkBurnEvents(burn, amount, Accounts.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); + await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); + let minterRemovedEvent = await token.removeMinter(Accounts.minterAccount, {from: Accounts.masterMinterAccount}); + checkMinterRemovedEvent(minterRemovedEvent, Accounts.minterAccount); }); it('et004 should check MasterMinterChanged event', async function () { - let updateMasterMinter = await token.updateMasterMinter(arbitraryAccount, {from: tokenOwnerAccount}); - checkUpdateMasterMinterEvent(updateMasterMinter, arbitraryAccount); + let updateMasterMinter = await token.updateMasterMinter(Accounts.arbitraryAccount, {from: Accounts.tokenOwnerAccount}); + checkUpdateMasterMinterEvent(updateMasterMinter, Accounts.arbitraryAccount); }); it('et005 should check Blacklisted event', async function () { - let blacklist = await token.blacklist(arbitraryAccount, { from: blacklisterAccount }); - checkBlacklistEvent(blacklist, arbitraryAccount); + let blacklist = await token.blacklist(Accounts.arbitraryAccount, { from: Accounts.blacklisterAccount }); + checkBlacklistEvent(blacklist, Accounts.arbitraryAccount); }); it('et006 should check UnBlacklisted event', async function () { - let unblacklist = await token.unBlacklist(arbitraryAccount, { from: blacklisterAccount }); - checkUnblacklistEvent(unblacklist, arbitraryAccount); + let unblacklist = await token.unBlacklist(Accounts.arbitraryAccount, { from: Accounts.blacklisterAccount }); + checkUnblacklistEvent(unblacklist, Accounts.arbitraryAccount); }); it('et007 should check BlacklisterChanged event', async function () { - let blacklisterChanged = await token.updateBlacklister(arbitraryAccount, {from: tokenOwnerAccount}); - checkBlacklisterChangedEvent(blacklisterChanged, arbitraryAccount); + let blacklisterChanged = await token.updateBlacklister(Accounts.arbitraryAccount, {from: Accounts.tokenOwnerAccount}); + checkBlacklisterChangedEvent(blacklisterChanged, Accounts.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 }); + const initializeData = encodeCall('initV2', ['bool', 'address', 'uint256'], [true, Accounts.pauserAccount, 12]); + let upgrade = await proxy.upgradeToAndCall(upgradedToken.address, initializeData, { from: Accounts.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); + let adminChanged = await proxy.changeAdmin(Accounts.arbitraryAccount, {from: Accounts.proxyOwnerAccount}); + checkAdminChangedEvent(adminChanged, Accounts.proxyOwnerAccount, Accounts.arbitraryAccount); }); it('et010 should check OwnershipTransferred event', async function () { - let transferOwnership = await token.transferOwnership(arbitraryAccount, {from: tokenOwnerAccount}); - checkTransferOwnershipEvent(transferOwnership, tokenOwnerAccount, arbitraryAccount); + let transferOwnership = await token.transferOwnership(Accounts.arbitraryAccount, {from: Accounts.tokenOwnerAccount}); + checkTransferOwnershipEvent(transferOwnership, Accounts.tokenOwnerAccount, Accounts.arbitraryAccount); }); it('et011 should check Approval event', async function () { - let approval = await token.approve(arbitraryAccount2, amount, {from: arbitraryAccount}); - checkApprovalEvent(approval, arbitraryAccount, arbitraryAccount2, amount); + let approval = await token.approve(Accounts.arbitraryAccount2, amount, {from: Accounts.arbitraryAccount}); + checkApprovalEvent(approval, Accounts.arbitraryAccount, Accounts.arbitraryAccount2, amount); }); it('et012 should check Pause event', async function () { - let pause = await token.pause({from: pauserAccount}); + let pause = await token.pause({from: Accounts.pauserAccount}); checkPauseEvent(pause); }); it('et013 should check Unpause event', async function () { - let unpause = await token.unpause({from: pauserAccount}); + let unpause = await token.unpause({from: Accounts.pauserAccount}); checkUnpauseEvent(unpause); }); it('et014 should check PauserChanged event', async function () { - let updatePauser = await token.updatePauser(arbitraryAccount, {from: tokenOwnerAccount}); - checkPauserChangedEvent(updatePauser, arbitraryAccount); + let updatePauser = await token.updatePauser(Accounts.arbitraryAccount, {from: Accounts.tokenOwnerAccount}); + checkPauserChangedEvent(updatePauser, Accounts.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); + await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); + await token.mint(Accounts.arbitraryAccount, amount, {from: Accounts.minterAccount}); + let transfer = await token.transfer(Accounts.arbitraryAccount2, amount, {from: Accounts.arbitraryAccount}); + checkTransferEvents(transfer, Accounts.arbitraryAccount, Accounts.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); + await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); + await token.mint(Accounts.arbitraryAccount, amount, {from: Accounts.minterAccount}); + await token.approve(Accounts.arbitraryAccount2, amount, {from: Accounts.arbitraryAccount}); + let transferFrom = await token.transferFrom(Accounts.arbitraryAccount, Accounts.blacklisterAccount, amount, {from: Accounts.arbitraryAccount2}); + checkTransferEvents(transferFrom, Accounts.arbitraryAccount, Accounts.blacklisterAccount, amount); }); } diff --git a/test/ExtendedPositiveTests.js b/test/ExtendedPositiveTests.js index 621b33721..7734c3fd3 100644 --- a/test/ExtendedPositiveTests.js +++ b/test/ExtendedPositiveTests.js @@ -11,20 +11,15 @@ var name = tokenUtils.name; var symbol = tokenUtils.symbol; var currency = tokenUtils.currency; var decimals = tokenUtils.decimals; -var deployerAccount = tokenUtils.deployerAccount; -var arbitraryAccount = tokenUtils.arbitraryAccount; -var arbitraryAccount2 = tokenUtils.arbitraryAccount2; -var upgraderAccount = tokenUtils.upgraderAccount; -var tokenOwnerAccount = tokenUtils.tokenOwnerAccount; -var blacklisterAccount = tokenUtils.blacklisterAccount; -var masterMinterAccount = tokenUtils.masterMinterAccount; -var minterAccount = tokenUtils.minterAccount; -var pauserAccount = tokenUtils.pauserAccount; + var initializeTokenWithProxy = tokenUtils.initializeTokenWithProxy; var UpgradedFiatToken = tokenUtils.UpgradedFiatToken; var FiatToken = tokenUtils.FiatToken; var upgradeTo = tokenUtils.upgradeTo; +var AccountUtils = require('./AccountUtils'); +var Accounts = AccountUtils.Accounts; + var amount = 100; async function run_tests(newToken, accounts) { @@ -41,58 +36,58 @@ async function run_tests(newToken, accounts) { // Paused it('ept001 should changeAdmin while paused', async function () { - await token.pause({ from: pauserAccount }); - await proxy.changeAdmin(arbitraryAccount, { from: upgraderAccount }); + await token.pause({ from: Accounts.pauserAccount }); + await proxy.changeAdmin(Accounts.arbitraryAccount, { from: Accounts.upgraderAccount }); var result = [ { 'variable': 'paused', 'expectedValue': true }, - { 'variable': 'upgrader', 'expectedValue': arbitraryAccount}, + { 'variable': 'upgrader', 'expectedValue': Accounts.arbitraryAccount}, ]; await checkVariables([token], [result]); }); it('ept002 should updateMasterMinter while paused', async function () { - await token.pause({ from: pauserAccount }); - await token.updateMasterMinter(arbitraryAccount, { from: tokenOwnerAccount }); + await token.pause({ from: Accounts.pauserAccount }); + await token.updateMasterMinter(Accounts.arbitraryAccount, { from: Accounts.tokenOwnerAccount }); var result = [ - { 'variable': 'masterMinter', 'expectedValue': arbitraryAccount }, + { 'variable': 'masterMinter', 'expectedValue': Accounts.arbitraryAccount }, { 'variable': 'paused', 'expectedValue': true } ]; await checkVariables([token], [result]); }); it('ept003 should updateBlacklister while paused', async function () { - await token.pause({ from: pauserAccount }); - await token.updateBlacklister(arbitraryAccount, { from: tokenOwnerAccount }); + await token.pause({ from: Accounts.pauserAccount }); + await token.updateBlacklister(Accounts.arbitraryAccount, { from: Accounts.tokenOwnerAccount }); var result = [ - { 'variable': 'blacklister', 'expectedValue': arbitraryAccount }, + { 'variable': 'blacklister', 'expectedValue': Accounts.arbitraryAccount }, { 'variable': 'paused', 'expectedValue': true } ]; await checkVariables([token], [result]); }); it('ept004 should updatePauser while paused', async function () { - await token.pause({ from: pauserAccount }); - await token.updatePauser(arbitraryAccount, { from: tokenOwnerAccount }); + await token.pause({ from: Accounts.pauserAccount }); + await token.updatePauser(Accounts.arbitraryAccount, { from: Accounts.tokenOwnerAccount }); var result = [ - { 'variable': 'pauser', 'expectedValue': arbitraryAccount }, + { 'variable': 'pauser', 'expectedValue': Accounts.arbitraryAccount }, { 'variable': 'paused', 'expectedValue': true } ]; await checkVariables([token], [result]); }); it('ept005 should transferOwnership while paused', async function () { - await token.pause({ from: pauserAccount }); - await token.transferOwnership(arbitraryAccount, { from: tokenOwnerAccount }); + await token.pause({ from: Accounts.pauserAccount }); + await token.transferOwnership(Accounts.arbitraryAccount, { from: Accounts.tokenOwnerAccount }); var result = [ - { 'variable': 'tokenOwner', 'expectedValue': arbitraryAccount }, + { 'variable': 'tokenOwner', 'expectedValue': Accounts.arbitraryAccount }, { 'variable': 'paused', 'expectedValue': true } ]; await checkVariables([token], [result]); }); it('ept006 should removeMinter while paused', async function () { - await token.configureMinter(minterAccount, amount, { from: masterMinterAccount }); - await token.pause({ from: pauserAccount }); + await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); + await token.pause({ from: Accounts.pauserAccount }); var isAMinter = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount) }, @@ -100,7 +95,7 @@ async function run_tests(newToken, accounts) { ]; await checkVariables([token], [isAMinter]); - await token.removeMinter(minterAccount, { from: masterMinterAccount }); + await token.removeMinter(Accounts.minterAccount, { from: Accounts.masterMinterAccount }); var notAMinter = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': false }, { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(0) }, @@ -111,7 +106,7 @@ async function run_tests(newToken, accounts) { it('ept008 should upgrade while paused', async function() { var newRawToken = await UpgradedFiatToken.new(); - await token.pause({from: pauserAccount}); + await token.pause({from: Accounts.pauserAccount}); var tokenConfig = await upgradeTo(proxy, newRawToken); var newProxiedToken = tokenConfig.token; var newToken = newProxiedToken; @@ -126,58 +121,58 @@ async function run_tests(newToken, accounts) { // Blacklisted it('ept013 should changeAdmin when msg.sender blacklisted', async function () { - await token.blacklist(upgraderAccount, { from: blacklisterAccount }); - await proxy.changeAdmin(arbitraryAccount, { from: upgraderAccount }); + await token.blacklist(Accounts.upgraderAccount, { from: Accounts.blacklisterAccount }); + await proxy.changeAdmin(Accounts.arbitraryAccount, { from: Accounts.upgraderAccount }); var result = [ { 'variable': 'isAccountBlacklisted.upgraderAccount', 'expectedValue': true }, - { 'variable': 'upgrader', 'expectedValue': arbitraryAccount }, + { 'variable': 'upgrader', 'expectedValue': Accounts.arbitraryAccount }, ]; await checkVariables([token], [result]); }); it('ept014 should updateMasterMinter when msg.sender blacklisted', async function () { - await token.blacklist(tokenOwnerAccount, { from: blacklisterAccount }); - await token.updateMasterMinter(arbitraryAccount, { from: tokenOwnerAccount }); + await token.blacklist(Accounts.tokenOwnerAccount, { from: Accounts.blacklisterAccount }); + await token.updateMasterMinter(Accounts.arbitraryAccount, { from: Accounts.tokenOwnerAccount }); var setup = [ - { 'variable': 'masterMinter', 'expectedValue': arbitraryAccount }, + { 'variable': 'masterMinter', 'expectedValue': Accounts.arbitraryAccount }, { 'variable': 'isAccountBlacklisted.tokenOwnerAccount', 'expectedValue': true } ]; await checkVariables([token], [setup]); }); it('ept015 should updateBlacklister when msg.sender blacklisted', async function () { - await token.blacklist(tokenOwnerAccount, { from: blacklisterAccount }); - await token.updateBlacklister(arbitraryAccount, { from: tokenOwnerAccount }); + await token.blacklist(Accounts.tokenOwnerAccount, { from: Accounts.blacklisterAccount }); + await token.updateBlacklister(Accounts.arbitraryAccount, { from: Accounts.tokenOwnerAccount }); var setup = [ - { 'variable': 'blacklister', 'expectedValue': arbitraryAccount }, + { 'variable': 'blacklister', 'expectedValue': Accounts.arbitraryAccount }, { 'variable': 'isAccountBlacklisted.tokenOwnerAccount', 'expectedValue': true } ]; await checkVariables([token], [setup]); }); it('ept016 should updatePauser when msg.sender blacklisted', async function () { - await token.blacklist(tokenOwnerAccount, { from: blacklisterAccount }); - await token.updatePauser(arbitraryAccount, { from: tokenOwnerAccount }); + await token.blacklist(Accounts.tokenOwnerAccount, { from: Accounts.blacklisterAccount }); + await token.updatePauser(Accounts.arbitraryAccount, { from: Accounts.tokenOwnerAccount }); var setup = [ - { 'variable': 'pauser', 'expectedValue': arbitraryAccount }, + { 'variable': 'pauser', 'expectedValue': Accounts.arbitraryAccount }, { 'variable': 'isAccountBlacklisted.tokenOwnerAccount', 'expectedValue': true } ]; await checkVariables([token], [setup]); }); it('ept017 should transferOwnership when msg.sender blacklisted', async function () { - await token.blacklist(tokenOwnerAccount, { from: blacklisterAccount }); - await token.transferOwnership(arbitraryAccount, { from: tokenOwnerAccount }); + await token.blacklist(Accounts.tokenOwnerAccount, { from: Accounts.blacklisterAccount }); + await token.transferOwnership(Accounts.arbitraryAccount, { from: Accounts.tokenOwnerAccount }); var setup = [ - { 'variable': 'tokenOwner', 'expectedValue': arbitraryAccount }, + { 'variable': 'tokenOwner', 'expectedValue': Accounts.arbitraryAccount }, { 'variable': 'isAccountBlacklisted.tokenOwnerAccount', 'expectedValue': true } ]; await checkVariables([token], [setup]); }); it ('ept018 should pause when msg.sender blacklisted', async function() { - await token.blacklist(pauserAccount, { from: blacklisterAccount }); - await token.pause({ from: pauserAccount }); + await token.blacklist(Accounts.pauserAccount, { from: Accounts.blacklisterAccount }); + await token.pause({ from: Accounts.pauserAccount }); var setup = [ { 'variable': 'paused', 'expectedValue': true }, { 'variable': 'isAccountBlacklisted.pauserAccount', 'expectedValue': true } @@ -186,14 +181,14 @@ async function run_tests(newToken, accounts) { }); it ('ept019 should unpause when msg.sender blacklisted', async function() { - await token.pause({ from: pauserAccount }); + await token.pause({ from: Accounts.pauserAccount }); var setup = [ { 'variable': 'paused', 'expectedValue': true } ]; await checkVariables([token], [setup]); - await token.blacklist(pauserAccount, { from: blacklisterAccount }); - await token.unpause({ from: pauserAccount }); + await token.blacklist(Accounts.pauserAccount, { from: Accounts.blacklisterAccount }); + await token.unpause({ from: Accounts.pauserAccount }); setup = [ { 'variable': 'isAccountBlacklisted.pauserAccount', 'expectedValue': true } ]; @@ -201,8 +196,8 @@ async function run_tests(newToken, accounts) { }); it ('ept020 should blacklist when msg.sender blacklisted', async function() { - await token.blacklist(blacklisterAccount, { from: blacklisterAccount }); - await token.blacklist(arbitraryAccount, { from: blacklisterAccount }); + await token.blacklist(Accounts.blacklisterAccount, { from: Accounts.blacklisterAccount }); + await token.blacklist(Accounts.arbitraryAccount, { from: Accounts.blacklisterAccount }); var setup = [ { 'variable': 'isAccountBlacklisted.blacklisterAccount', 'expectedValue': true }, { 'variable': 'isAccountBlacklisted.arbitraryAccount', 'expectedValue': true } @@ -211,18 +206,18 @@ async function run_tests(newToken, accounts) { }); it ('ept021 should unBlacklist when msg.sender blacklisted', async function() { - await token.blacklist(blacklisterAccount, { from: blacklisterAccount }); + await token.blacklist(Accounts.blacklisterAccount, { from: Accounts.blacklisterAccount }); var setup = [ { 'variable': 'isAccountBlacklisted.blacklisterAccount', 'expectedValue': true } ]; await checkVariables([token], [setup]); - await token.unBlacklist(blacklisterAccount, { from: blacklisterAccount }); + await token.unBlacklist(Accounts.blacklisterAccount, { from: Accounts.blacklisterAccount }); await checkVariables([token], [[]]); }); it('ept022 should upgrade when msg.sender blacklisted', async function () { - await token.blacklist(upgraderAccount, { from: blacklisterAccount }); + await token.blacklist(Accounts.upgraderAccount, { from: Accounts.blacklisterAccount }); var newRawToken = await UpgradedFiatToken.new(); var tokenConfig = await upgradeTo(proxy, newRawToken); var newToken = tokenConfig.token; @@ -237,7 +232,7 @@ async function run_tests(newToken, accounts) { it ('ept023 should upgrade to blacklisted address', async function() { var newRawToken = await UpgradedFiatToken.new(); - await token.blacklist(newRawToken.address, { from: blacklisterAccount }); + await token.blacklist(newRawToken.address, { from: Accounts.blacklisterAccount }); var tokenConfig = await upgradeTo(proxy, newRawToken); var newProxiedToken = tokenConfig.token; var newToken = newProxiedToken; @@ -251,67 +246,67 @@ async function run_tests(newToken, accounts) { }); it('ept024 should blacklist a blacklisted address', async function () { - await token.blacklist(arbitraryAccount, { from: blacklisterAccount }); + await token.blacklist(Accounts.arbitraryAccount, { from: Accounts.blacklisterAccount }); var setup = [ { 'variable': 'isAccountBlacklisted.arbitraryAccount', 'expectedValue': true } ]; - await token.blacklist(arbitraryAccount, { from: blacklisterAccount }); + await token.blacklist(Accounts.arbitraryAccount, { from: Accounts.blacklisterAccount }); await checkVariables([token], [setup]); }); it('ept025 should changeAdmin to blacklisted address', async function () { - await token.blacklist(arbitraryAccount, { from: blacklisterAccount }); - await proxy.changeAdmin(arbitraryAccount, { from: upgraderAccount }); + await token.blacklist(Accounts.arbitraryAccount, { from: Accounts.blacklisterAccount }); + await proxy.changeAdmin(Accounts.arbitraryAccount, { from: Accounts.upgraderAccount }); var result = [ { 'variable': 'isAccountBlacklisted.arbitraryAccount', 'expectedValue': true }, - { 'variable': 'upgrader', 'expectedValue': arbitraryAccount }, + { 'variable': 'upgrader', 'expectedValue': Accounts.arbitraryAccount }, ]; await checkVariables([token], [result]); }); it('ept026 should updateMasterMinter to blacklisted address', async function () { - await token.blacklist(arbitraryAccount, { from: blacklisterAccount }); - await token.updateMasterMinter(arbitraryAccount, { from: tokenOwnerAccount }); + await token.blacklist(Accounts.arbitraryAccount, { from: Accounts.blacklisterAccount }); + await token.updateMasterMinter(Accounts.arbitraryAccount, { from: Accounts.tokenOwnerAccount }); var setup = [ - { 'variable': 'masterMinter', 'expectedValue': arbitraryAccount }, + { 'variable': 'masterMinter', 'expectedValue': Accounts.arbitraryAccount }, { 'variable': 'isAccountBlacklisted.arbitraryAccount', 'expectedValue': true } ]; await checkVariables([token], [setup]); }); it('ept027 should updateBlacklister to blacklisted address', async function () { - await token.blacklist(arbitraryAccount, { from: blacklisterAccount }); - await token.updateBlacklister(arbitraryAccount, { from: tokenOwnerAccount }); + await token.blacklist(Accounts.arbitraryAccount, { from: Accounts.blacklisterAccount }); + await token.updateBlacklister(Accounts.arbitraryAccount, { from: Accounts.tokenOwnerAccount }); var setup = [ - { 'variable': 'blacklister', 'expectedValue': arbitraryAccount }, + { 'variable': 'blacklister', 'expectedValue': Accounts.arbitraryAccount }, { 'variable': 'isAccountBlacklisted.arbitraryAccount', 'expectedValue': true } ]; await checkVariables([token], [setup]); }); it('ept028 should updatePauser to blacklisted address', async function () { - await token.blacklist(arbitraryAccount, { from: blacklisterAccount }); - await token.updatePauser(arbitraryAccount, { from: tokenOwnerAccount }); + await token.blacklist(Accounts.arbitraryAccount, { from: Accounts.blacklisterAccount }); + await token.updatePauser(Accounts.arbitraryAccount, { from: Accounts.tokenOwnerAccount }); var setup = [ - { 'variable': 'pauser', 'expectedValue': arbitraryAccount }, + { 'variable': 'pauser', 'expectedValue': Accounts.arbitraryAccount }, { 'variable': 'isAccountBlacklisted.arbitraryAccount', 'expectedValue': true } ]; await checkVariables([token], [setup]); }); it('ept029 should transferOwnership to blacklisted address', async function () { - await token.blacklist(arbitraryAccount, { from: blacklisterAccount }); - await token.transferOwnership(arbitraryAccount, { from: tokenOwnerAccount }); + await token.blacklist(Accounts.arbitraryAccount, { from: Accounts.blacklisterAccount }); + await token.transferOwnership(Accounts.arbitraryAccount, { from: Accounts.tokenOwnerAccount }); var setup = [ - { 'variable': 'tokenOwner', 'expectedValue': arbitraryAccount }, + { 'variable': 'tokenOwner', 'expectedValue': Accounts.arbitraryAccount }, { 'variable': 'isAccountBlacklisted.arbitraryAccount', 'expectedValue': true } ]; await checkVariables([token], [setup]); }); it('ept030 should configureMinter when masterMinter is blacklisted', async function () { - await token.blacklist(masterMinterAccount, { from: blacklisterAccount }); - await token.configureMinter(minterAccount, amount, { from: masterMinterAccount }); + await token.blacklist(Accounts.masterMinterAccount, { from: Accounts.blacklisterAccount }); + await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); var result = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount) }, @@ -321,8 +316,8 @@ async function run_tests(newToken, accounts) { }); it('ept032 should configureMinter when minter is blacklisted', async function () { - await token.blacklist(minterAccount, { from: blacklisterAccount }); - await token.configureMinter(minterAccount, amount, { from: masterMinterAccount }); + await token.blacklist(Accounts.minterAccount, { from: Accounts.blacklisterAccount }); + await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); var result = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount) }, @@ -332,8 +327,8 @@ async function run_tests(newToken, accounts) { }); it('ept033 should removeMinter when masterMinter is blacklisted', async function() { - await token.configureMinter(minterAccount, amount, { from: masterMinterAccount }); - await token.blacklist(masterMinterAccount, { from: blacklisterAccount }); + await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); + await token.blacklist(Accounts.masterMinterAccount, { from: Accounts.blacklisterAccount }); var customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount) }, @@ -341,7 +336,7 @@ async function run_tests(newToken, accounts) { ]; await checkVariables([token], [customVars]); - await token.removeMinter(minterAccount, { from: masterMinterAccount }); + await token.removeMinter(Accounts.minterAccount, { from: Accounts.masterMinterAccount }); customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': false }, { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(0) }, @@ -351,8 +346,8 @@ async function run_tests(newToken, accounts) { }); it('ept034 should removeMinter when minter is blacklisted', async function() { - await token.configureMinter(minterAccount, amount, { from: masterMinterAccount }); - await token.blacklist(minterAccount, { from: blacklisterAccount }); + await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); + await token.blacklist(Accounts.minterAccount, { from: Accounts.blacklisterAccount }); var customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount) }, @@ -360,7 +355,7 @@ async function run_tests(newToken, accounts) { ]; await checkVariables([token], [customVars]); - await token.removeMinter(minterAccount, { from: masterMinterAccount }); + await token.removeMinter(Accounts.minterAccount, { from: Accounts.masterMinterAccount }); customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': false }, { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(0) }, @@ -370,15 +365,15 @@ async function run_tests(newToken, accounts) { }); it('ept035 should unBlacklist while contract is paused', async function() { - await token.pause({from: pauserAccount}); - await token.blacklist(arbitraryAccount, { from: blacklisterAccount }); + await token.pause({from: Accounts.pauserAccount}); + await token.blacklist(Accounts.arbitraryAccount, { from: Accounts.blacklisterAccount }); var customVars = [ { 'variable': 'isAccountBlacklisted.arbitraryAccount', 'expectedValue': true }, { 'variable': 'paused', 'expectedValue': true}, ]; await checkVariables([token], [customVars]); - await token.unBlacklist(arbitraryAccount, { from: blacklisterAccount }); + await token.unBlacklist(Accounts.arbitraryAccount, { from: Accounts.blacklisterAccount }); customVars = [ { 'variable': 'paused', 'expectedValue': true}, ]; @@ -386,13 +381,13 @@ async function run_tests(newToken, accounts) { }); it('ept036 should blacklist while contract is paused', async function() { - await token.pause({from: pauserAccount}); + await token.pause({from: Accounts.pauserAccount}); var customVars = [ { 'variable': 'paused', 'expectedValue': true}, ]; await checkVariables([token], [customVars]); - await token.blacklist(arbitraryAccount, { from: blacklisterAccount }); + await token.blacklist(Accounts.arbitraryAccount, { from: Accounts.blacklisterAccount }); customVars = [ { 'variable': 'isAccountBlacklisted.arbitraryAccount', 'expectedValue': true }, { 'variable': 'paused', 'expectedValue': true}, @@ -401,13 +396,13 @@ async function run_tests(newToken, accounts) { }); it('ept037 should pause while contract is paused', async function() { - await token.pause({from: pauserAccount}); + await token.pause({from: Accounts.pauserAccount}); var customVars = [ { 'variable': 'paused', 'expectedValue': true}, ]; await checkVariables([token], [customVars]); - await token.pause({from: pauserAccount}); + await token.pause({from: Accounts.pauserAccount}); customVars = [ { 'variable': 'paused', 'expectedValue': true}, ]; diff --git a/test/FiatTokenLegacy.test.js b/test/FiatTokenLegacy.test.js index f4b3976d9..01a039367 100644 --- a/test/FiatTokenLegacy.test.js +++ b/test/FiatTokenLegacy.test.js @@ -16,22 +16,15 @@ var approve = tokenUtils.approve; var unBlacklist = tokenUtils.unBlacklist; var sampleTransfer = tokenUtils.sampleTransfer; var checkTransferEvents = tokenUtils.checkTransferEvents; -var deployerAccount = tokenUtils.deployerAccount; -var arbitraryAccount = tokenUtils.arbitraryAccount; -var tokenOwnerAccount = tokenUtils.tokenOwnerAccount; -var blacklisterAccount = tokenUtils.blacklisterAccount; -var arbitraryAccount2 = tokenUtils.arbitraryAccount2; -var masterMinterAccount = tokenUtils.masterMinterAccount; -var minterAccount = tokenUtils.minterAccount; -var pauserAccount = tokenUtils.pauserAccount; -var blacklisterAccount = tokenUtils.blacklisterAccount; -var proxyOwnerAccount = tokenUtils.proxyOwnerAccount; var initializeTokenWithProxy = tokenUtils.initializeTokenWithProxy; var upgradeTo = tokenUtils.upgradeTo; var UpgradedFiatToken = tokenUtils.UpgradedFiatToken; var FiatToken = tokenUtils.FiatToken; var getAdmin = tokenUtils.getAdmin; +var AccountUtils = require('./AccountUtils'); +var Accounts = AccountUtils.Accounts; + // these tests are for reference and do not track side effects on all variables async function run_tests(newToken, accounts) { @@ -49,8 +42,8 @@ async function run_tests(newToken, accounts) { }); it('should add multiple mints to a given address in address balance', async function () { - await mint(token, accounts[0], 100, minterAccount); - await mint(token, accounts[0], 200, minterAccount); + await mint(token, accounts[0], 100, Accounts.minterAccount); + await mint(token, accounts[0], 200, Accounts.minterAccount); let balance0 = await token.balanceOf(accounts[0]); assert.equal(balance0, 300); @@ -59,30 +52,30 @@ async function run_tests(newToken, accounts) { it('should fail to mint to a null address', async function () { let initialTotalSupply = await token.totalSupply(); - await expectRevert(mint(token, "0x0", 100, minterAccount)); + await expectRevert(mint(token, "0x0", 100, Accounts.minterAccount)); totalSupply = await token.totalSupply(); assert.isTrue(new BigNumber(totalSupply).isEqualTo(new BigNumber(initialTotalSupply))); - await expectRevert(mint(token, 0x0, 100, minterAccount)); + await expectRevert(mint(token, 0x0, 100, Accounts.minterAccount)); totalSupply = await token.totalSupply(); assert.isTrue(new BigNumber(totalSupply).isEqualTo(new BigNumber(initialTotalSupply))); - await expectRevert(mint(token, "0x0000000000000000000000000000000000000000", 100, minterAccount)); + await expectRevert(mint(token, "0x0000000000000000000000000000000000000000", 100, Accounts.minterAccount)); totalSupply = await token.totalSupply(); assert.isTrue(new BigNumber(totalSupply).isEqualTo(new BigNumber(initialTotalSupply))); - await expectRevert(mint(token, 0x0000000000000000000000000000000000000000, 100, minterAccount)); + await expectRevert(mint(token, 0x0000000000000000000000000000000000000000, 100, Accounts.minterAccount)); totalSupply = await token.totalSupply(); assert.isTrue(new BigNumber(totalSupply).isEqualTo(new BigNumber(initialTotalSupply))); }); it('should add multiple mints to a given address in address balance', async function () { - await mint(token, accounts[0], 100, minterAccount); - await mint(token, accounts[0], 200, minterAccount); + await mint(token, accounts[0], 100, Accounts.minterAccount); + await mint(token, accounts[0], 200, Accounts.minterAccount); let balance0 = await token.balanceOf(accounts[0]); assert.isTrue(new BigNumber(balance0).isEqualTo(new BigNumber(300))); @@ -90,9 +83,9 @@ async function run_tests(newToken, accounts) { it('should add multiple mints to total supply', async function () { let initialTotalSupply = await token.totalSupply(); - await mint(token, accounts[0], 100, minterAccount); - await mint(token, accounts[0], 400, minterAccount); - await mint(token, accounts[1], 600, minterAccount); + await mint(token, accounts[0], 100, Accounts.minterAccount); + await mint(token, accounts[0], 400, Accounts.minterAccount); + await mint(token, accounts[1], 600, Accounts.minterAccount); let totalSupply = await token.totalSupply(); assert.isTrue(new BigNumber(totalSupply).minus(new BigNumber(initialTotalSupply)).isEqualTo(new BigNumber(1100))); @@ -111,14 +104,14 @@ async function run_tests(newToken, accounts) { it('should fail to mint to blacklisted address', async function () { await blacklist(token, accounts[3]); - await expectRevert(mint(token, accounts[3], 100, minterAccount)) + await expectRevert(mint(token, accounts[3], 100, Accounts.minterAccount)) let balance0 = await token.balanceOf(accounts[0]); assert.equal(balance0, 0); }); it('should fail to mint from a non-minter call', async function () { - await mint(token, accounts[0], 400, minterAccount); + await mint(token, accounts[0], 400, Accounts.minterAccount); await expectRevert(token.mint(accounts[0], 100, { from: accounts[0] })) @@ -127,7 +120,7 @@ async function run_tests(newToken, accounts) { }); it('should complete transferFrom', async function () { - await sampleTransferFrom(token, deployerAccount, arbitraryAccount2, minterAccount); + await sampleTransferFrom(token, Accounts.deployerAccount, Accounts.arbitraryAccount2, Accounts.minterAccount); }); it('should approve', async function () { @@ -137,11 +130,11 @@ async function run_tests(newToken, accounts) { }); it('should complete sample transfer', async function () { - await sampleTransfer(token, deployerAccount, arbitraryAccount2, minterAccount); + await sampleTransfer(token, Accounts.deployerAccount, Accounts.arbitraryAccount2, Accounts.minterAccount); }); it('should complete transfer from non-owner', async function () { - await mint(token, accounts[2], 1900, minterAccount); + await mint(token, accounts[2], 1900, Accounts.minterAccount); let transfer = await token.transfer(accounts[3], 1000, { from: accounts[2] }); checkTransferEvents(transfer, accounts[2], accounts[3], 1000); @@ -155,7 +148,7 @@ async function run_tests(newToken, accounts) { it('should set allowance and balances before and after approved transfer', async function () { let allowed = await token.allowance.call(accounts[0], accounts[3]); assert.isTrue(new BigNumber(allowed).isEqualTo(new BigNumber(0))); - await mint(token, accounts[0], 500, minterAccount); + await mint(token, accounts[0], 500, Accounts.minterAccount); await token.approve(accounts[3], 100); allowed = await token.allowance.call(accounts[0], accounts[3]); assert.isTrue(new BigNumber(allowed).isEqualTo(new BigNumber(100))); @@ -173,7 +166,7 @@ async function run_tests(newToken, accounts) { it('should fail on unauthorized approved transfer and not change balances', async function () { let allowed = await token.allowance.call(accounts[0], accounts[3]); assert.isTrue(new BigNumber(allowed).isEqualTo(new BigNumber(0))); - await mint(token, accounts[0], 500, minterAccount); + await mint(token, accounts[0], 500, Accounts.minterAccount); await token.approve(accounts[3], 100); allowed = await token.allowance.call(accounts[0], accounts[3]); assert.isTrue(new BigNumber(allowed).isEqualTo(new BigNumber(100))); @@ -189,7 +182,7 @@ async function run_tests(newToken, accounts) { it('should fail on invalid approved transfer amount and not change balances', async function () { let allowed = await token.allowance.call(accounts[0], accounts[3]); assert.isTrue(new BigNumber(allowed).isEqualTo(new BigNumber(0))); - await mint(token, accounts[0], 500, minterAccount); + await mint(token, accounts[0], 500, Accounts.minterAccount); await token.approve(accounts[3], 100); allowed = await token.allowance.call(accounts[0], accounts[3]); assert.isTrue(new BigNumber(allowed).isEqualTo(new BigNumber(100))); @@ -205,7 +198,7 @@ async function run_tests(newToken, accounts) { it('should fail on invalid transfer recipient (zero-account) and not change balances', async function () { - await mint(token, accounts[0], 500, minterAccount); + await mint(token, accounts[0], 500, Accounts.minterAccount); await token.approve(accounts[3], 100); let allowed = await token.allowance.call(accounts[0], accounts[3]); assert.isTrue(new BigNumber(allowed).isEqualTo(new BigNumber(100))); @@ -221,7 +214,7 @@ async function run_tests(newToken, accounts) { assert.isTrue(new BigNumber(allowed).isEqualTo(new BigNumber(0))); let transferAmount = 650; let totalAmount = transferAmount; - await mint(token, accounts[0], totalAmount, minterAccount); + await mint(token, accounts[0], totalAmount, Accounts.minterAccount); let transfer = await token.transfer(accounts[3], transferAmount); checkTransferEvents(transfer, accounts[0], accounts[3], transferAmount); @@ -233,7 +226,7 @@ async function run_tests(newToken, accounts) { await token.allowance.call(accounts[1], accounts[4]); assert.isTrue(new BigNumber(allowed).isEqualTo(new BigNumber(0))); - await mint(token, accounts[1], totalAmount, minterAccount); + await mint(token, accounts[1], totalAmount, Accounts.minterAccount); await token.approve(accounts[4], transferAmount, { from: accounts[1] }); allowed = await token.allowance.call(accounts[1], accounts[4]); @@ -250,56 +243,56 @@ async function run_tests(newToken, accounts) { }); it('should pause and should not be able to transfer', async function () { - await mint(token, accounts[2], 1900, minterAccount); + await mint(token, accounts[2], 1900, Accounts.minterAccount); assert.equal(await token.paused.call(), false); - await token.pause({ from: pauserAccount }); + await token.pause({ from: Accounts.pauserAccount }); assert.equal(await token.paused.call(), true); - await expectRevert(sampleTransferFrom(token, deployerAccount, arbitraryAccount2, minterAccount)); + await expectRevert(sampleTransferFrom(token, Accounts.deployerAccount, Accounts.arbitraryAccount2, Accounts.minterAccount)); }); it('should pause and should not be able to transfer, then unpause and be able to transfer', async function () { - await mint(token, accounts[2], 1900, minterAccount); + await mint(token, accounts[2], 1900, Accounts.minterAccount); assert.equal(await token.paused.call(), false); - await token.pause({ from: pauserAccount }); + await token.pause({ from: Accounts.pauserAccount }); assert.equal(await token.paused.call(), true); - await expectRevert(sampleTransferFrom(token, deployerAccount, arbitraryAccount2, minterAccount)); + await expectRevert(sampleTransferFrom(token, Accounts.deployerAccount, Accounts.arbitraryAccount2, Accounts.minterAccount)); - await token.unpause({ from: pauserAccount }); + await token.unpause({ from: Accounts.pauserAccount }); assert.equal(await token.paused.call(), false); - await sampleTransferFrom(token, deployerAccount, arbitraryAccount2, minterAccount); + await sampleTransferFrom(token, Accounts.deployerAccount, Accounts.arbitraryAccount2, Accounts.minterAccount); }); it('should pause and should not be able to transferFrom', async function () { - await mint(token, accounts[2], 1900, minterAccount); + await mint(token, accounts[2], 1900, Accounts.minterAccount); assert.equal(await token.paused.call(), false); - await token.pause({ from: pauserAccount }); + await token.pause({ from: Accounts.pauserAccount }); assert.equal(await token.paused.call(), true); - await expectRevert(sampleTransfer(token, deployerAccount, arbitraryAccount2, minterAccount)); + await expectRevert(sampleTransfer(token, Accounts.deployerAccount, Accounts.arbitraryAccount2, Accounts.minterAccount)); }); it('should pause and should not be able to approve', async function () { - await mint(token, accounts[2], 1900, minterAccount); + await mint(token, accounts[2], 1900, Accounts.minterAccount); assert.equal(await token.paused.call(), false); - await token.pause({ from: pauserAccount }); + await token.pause({ from: Accounts.pauserAccount }); assert.equal(await token.paused.call(), true); await expectRevert(approve(token, accounts[2], 50, accounts[3])); }); it('should pause and should not be able to mint', async function () { - await mint(token, accounts[2], 1900, minterAccount); + await mint(token, accounts[2], 1900, Accounts.minterAccount); assert.equal(await token.paused.call(), false); - await token.pause({ from: pauserAccount }); + await token.pause({ from: Accounts.pauserAccount }); assert.equal(await token.paused.call(), true); - await expectRevert(mint(token, accounts[2], 1900, minterAccount)); + await expectRevert(mint(token, accounts[2], 1900, Accounts.minterAccount)); }); it('should try to pause with non-pauser and fail to pause', async function () { - await mint(token, accounts[2], 1900, minterAccount); + await mint(token, accounts[2], 1900, Accounts.minterAccount); assert.equal(await token.paused.call(), false); await expectRevert(token.pause({ from: accounts[0] })); @@ -308,7 +301,7 @@ async function run_tests(newToken, accounts) { }); it('should try to pause with non-pauser and fail to pause', async function () { - await mint(token, accounts[2], 1900, minterAccount); + await mint(token, accounts[2], 1900, Accounts.minterAccount); assert.equal(await token.paused.call(), false); await expectRevert(token.pause({ from: accounts[0] })); @@ -317,7 +310,7 @@ async function run_tests(newToken, accounts) { }); it('should approve and fail to transfer more than balance', async function () { - await mint(token, accounts[2], 100, minterAccount); + await mint(token, accounts[2], 100, Accounts.minterAccount); await token.approve(accounts[1], 600, { from: accounts[2] }); await expectRevert(token.transferFrom(accounts[2], accounts[1], 600, { from: accounts[1] })); @@ -327,7 +320,7 @@ async function run_tests(newToken, accounts) { }); it('should blacklist and make transfer impossible', async function () { - await mint(token, accounts[2], 1900, minterAccount); + await mint(token, accounts[2], 1900, Accounts.minterAccount); await blacklist(token, accounts[2]); await expectRevert(token.transfer(accounts[3], 600, { from: accounts[2] })); @@ -337,8 +330,8 @@ async function run_tests(newToken, accounts) { }); it('should blacklist recipient and make transfer to recipient impossible', async function () { - await mint(token, accounts[2], 1900, minterAccount); - await mint(token, accounts[9], 1600, minterAccount); + await mint(token, accounts[2], 1900, Accounts.minterAccount); + await mint(token, accounts[9], 1600, Accounts.minterAccount); await blacklist(token, accounts[2]); await expectRevert(token.transfer(accounts[2], 600, { from: accounts[9] })); @@ -353,7 +346,7 @@ async function run_tests(newToken, accounts) { let isBlacklistedBefore = await token.isBlacklisted(accounts[2]) assert.equal(isBlacklistedBefore, false); - await mint(token, accounts[2], 1900, minterAccount); + await mint(token, accounts[2], 1900, Accounts.minterAccount); await token.approve(accounts[1], 600, { from: accounts[2] }); await blacklist(token, accounts[2]); @@ -367,7 +360,7 @@ async function run_tests(newToken, accounts) { }); it('should make transferFrom impossible with the approved and blacklisted transferer', async function () { - await mint(token, accounts[2], 1900, minterAccount); + await mint(token, accounts[2], 1900, Accounts.minterAccount); await token.approve(accounts[1], 600, { from: accounts[2] }); await blacklist(token, accounts[1]); @@ -378,7 +371,7 @@ async function run_tests(newToken, accounts) { }); it('should blacklist recipient and make transfer to recipient using transferFrom impossible', async function () { - await mint(token, accounts[2], 1900, minterAccount); + await mint(token, accounts[2], 1900, Accounts.minterAccount); await token.approve(accounts[3], 600, { from: accounts[2] }); await blacklist(token, accounts[3]); @@ -389,7 +382,7 @@ async function run_tests(newToken, accounts) { }); it('should blacklist and make approve impossible', async function () { - await mint(token, accounts[1], 1900, minterAccount); + await mint(token, accounts[1], 1900, Accounts.minterAccount); await blacklist(token, accounts[1]); await expectRevert(token.approve(accounts[2], 600, { from: accounts[1] })); @@ -398,7 +391,7 @@ async function run_tests(newToken, accounts) { }); it('should make giving approval to blacklisted account impossible', async function () { - await mint(token, accounts[2], 1900, minterAccount); + await mint(token, accounts[2], 1900, Accounts.minterAccount); await blacklist(token, accounts[1]); await expectRevert(token.approve(accounts[1], 600, { from: accounts[2] })); @@ -408,7 +401,7 @@ async function run_tests(newToken, accounts) { }); it('should blacklist then unblacklist to make a transfer possible', async function () { - await mint(token, accounts[2], 1900, minterAccount); + await mint(token, accounts[2], 1900, Accounts.minterAccount); await blacklist(token, accounts[2]); await unBlacklist(token, accounts[2]); await token.transfer(accounts[3], 600, { from: accounts[2] }); @@ -419,9 +412,9 @@ async function run_tests(newToken, accounts) { }); it('should fail to blacklist with non-blacklister account', async function () { - await mint(token, accounts[2], 1900, minterAccount); + await mint(token, accounts[2], 1900, Accounts.minterAccount); - await expectRevert(token.blacklist(accounts[2], { from: pauserAccount })); + await expectRevert(token.blacklist(accounts[2], { from: Accounts.pauserAccount })); await token.transfer(accounts[3], 600, { from: accounts[2] }); let balance = await token.balanceOf(accounts[2]); @@ -431,14 +424,14 @@ async function run_tests(newToken, accounts) { }); it('should unblacklist when paused', async function () { - await mint(token, accounts[2], 1900, minterAccount); - await token.blacklist(accounts[2], { from: blacklisterAccount }); + await mint(token, accounts[2], 1900, Accounts.minterAccount); + await token.blacklist(accounts[2], { from: Accounts.blacklisterAccount }); let blacklisted = await token.isBlacklisted(accounts[2]); assert.isTrue(blacklisted); - await token.pause({ from: pauserAccount }); + await token.pause({ from: Accounts.pauserAccount }); - await token.unBlacklist(accounts[2], { from: blacklisterAccount }); + await token.unBlacklist(accounts[2], { from: Accounts.blacklisterAccount }); blacklisted = await token.isBlacklisted(accounts[2]); assert.isFalse(blacklisted); @@ -448,50 +441,50 @@ async function run_tests(newToken, accounts) { }); it('should change the minter and mint as well as fail to mint with the old minter', async function () { - let update = await token.removeMinter(minterAccount, { from: masterMinterAccount }); + let update = await token.removeMinter(Accounts.minterAccount, { from: Accounts.masterMinterAccount }); assert.equal(update.logs[0].event, 'MinterRemoved'); - assert.equal(update.logs[0].args.oldMinter, minterAccount); - update = await setMinter(token, accounts[3], 10000, { from: masterMinterAccount }); + assert.equal(update.logs[0].args.oldMinter, Accounts.minterAccount); + update = await setMinter(token, accounts[3], 10000, { from: Accounts.masterMinterAccount }); await token.mint(accounts[1], 100, { from: accounts[3] }); - await expectRevert(token.mint(accounts[1], 200, { from: minterAccount })); + await expectRevert(token.mint(accounts[1], 200, { from: Accounts.minterAccount })); - let isMinter = await token.isMinter(minterAccount); + let isMinter = await token.isMinter(Accounts.minterAccount); assert.equal(isMinter, false); let balance = await token.balanceOf(accounts[1]); assert.equal(balance, 100); }); it('should remove a minter even if the contract is paused', async function () { - await token.configureMinter(accounts[3], 200, { from: masterMinterAccount }); + await token.configureMinter(accounts[3], 200, { from: Accounts.masterMinterAccount }); let isAccountMinter = await token.isMinter(accounts[3]); assert.equal(isAccountMinter, true); - await token.pause({ from: pauserAccount }); - await token.removeMinter(accounts[3], { from: masterMinterAccount }); + await token.pause({ from: Accounts.pauserAccount }); + await token.removeMinter(accounts[3], { from: Accounts.masterMinterAccount }); isAccountMinter = await token.isMinter(accounts[3]); assert.equal(isAccountMinter, false); }); it('should pause contract even when contract is already paused', async function () { - await token.pause({ from: pauserAccount }); - await token.pause({ from: pauserAccount }); + await token.pause({ from: Accounts.pauserAccount }); + await token.pause({ from: Accounts.pauserAccount }); let isPaused = await token.paused(); assert.equal(isPaused, true); }); it('should unpause contract even when contract is already unpaused', async function () { - await token.unpause({ from: pauserAccount }); + await token.unpause({ from: Accounts.pauserAccount }); let isPaused = await token.paused(); assert.equal(isPaused, false); }); it('should fail to updateMinterAllowance from non-masterMinter', async function () { - let minterAllowanceBefore = await token.minterAllowance(minterAccount) + let minterAllowanceBefore = await token.minterAllowance(Accounts.minterAccount) assert.equal(minterAllowanceBefore, 0); - await expectRevert(token.configureMinter(minterAccount, 100, { from: tokenOwnerAccount })); + await expectRevert(token.configureMinter(Accounts.minterAccount, 100, { from: Accounts.tokenOwnerAccount })); - let minterAllowanceAfter = await token.minterAllowance(minterAccount) + let minterAllowanceAfter = await token.minterAllowance(Accounts.minterAccount) assert.equal(minterAllowanceAfter, 0); }); @@ -525,7 +518,7 @@ async function run_tests(newToken, accounts) { assert.isTrue(new BigNumber(minterBalance).isEqualTo(new BigNumber(0))); // mint tokens to burnerAddress - await mint(token, burnerAddress, amount, minterAccount); + await mint(token, burnerAddress, amount, Accounts.minterAccount); let totalSupply1 = await token.totalSupply(); let minterBalance1 = await token.balanceOf(burnerAddress); assert.isTrue(new BigNumber(totalSupply1).isEqualTo(new BigNumber(totalSupply).plus(new BigNumber(amount)))); @@ -551,7 +544,7 @@ async function run_tests(newToken, accounts) { it('should fail to burn from a blacklisted address', async function () { let burnerAddress = accounts[3]; await setMinter(token, burnerAddress, 200); - await mint(token, burnerAddress, 200, minterAccount); + await mint(token, burnerAddress, 200, Accounts.minterAccount); await blacklist(token, burnerAddress); await expectRevert(token.burn(100, { from: burnerAddress })); @@ -563,13 +556,13 @@ async function run_tests(newToken, accounts) { let burnerAddress = accounts[3]; let amount = 500; await setMinter(token, burnerAddress, 250); - await mint(token, burnerAddress, 100, minterAccount); + await mint(token, burnerAddress, 100, Accounts.minterAccount); await expectRevert(token.burn(amount, { from: burnerAddress })); }); it('should upgrade and preserve data', async function () { - await mint(token, accounts[2], 200, minterAccount); + await mint(token, accounts[2], 200, Accounts.minterAccount); let initialBalance = await token.balanceOf(accounts[2]); assert.isTrue((new BigNumber(initialBalance)).isEqualTo(new BigNumber(200))); @@ -580,8 +573,8 @@ async function run_tests(newToken, accounts) { let upgradedBalance = await newToken.balanceOf(accounts[2]); assert.isTrue((new BigNumber(upgradedBalance)).isEqualTo(new BigNumber(200))); - await newToken.configureMinter(minterAccount, 500, { from: masterMinterAccount }); - await newToken.mint(accounts[2], 200, { from: minterAccount }); + await newToken.configureMinter(Accounts.minterAccount, 500, { from: Accounts.masterMinterAccount }); + await newToken.mint(accounts[2], 200, { from: Accounts.minterAccount }); let balance = await newToken.balanceOf(accounts[2]); assert.isTrue((new BigNumber(balance)).isEqualTo(new BigNumber(400))); }); @@ -589,11 +582,11 @@ async function run_tests(newToken, accounts) { it('should updateRoleAddress for masterMinter', async function () { let address1 = accounts[7]; let address2 = accounts[6]; - await token.updateMasterMinter(address1, { from: tokenOwnerAccount }); + await token.updateMasterMinter(address1, { from: Accounts.tokenOwnerAccount }); let masterMinter1 = await token.masterMinter(); assert.equal(masterMinter1, address1); - await token.updateMasterMinter(address2, { from: tokenOwnerAccount }); + await token.updateMasterMinter(address2, { from: Accounts.tokenOwnerAccount }); let masterMinter2 = await token.masterMinter(); assert.equal(masterMinter2, address2); }); @@ -601,11 +594,11 @@ async function run_tests(newToken, accounts) { it('should updateRoleAddress for blacklister', async function () { let address1 = accounts[7]; let address2 = accounts[6]; - await token.updateBlacklister(address1, { from: tokenOwnerAccount }); + await token.updateBlacklister(address1, { from: Accounts.tokenOwnerAccount }); let blacklister1 = await token.blacklister(); assert.equal(blacklister1, address1); - await token.updateBlacklister(address2, { from: tokenOwnerAccount }); + await token.updateBlacklister(address2, { from: Accounts.tokenOwnerAccount }); let blacklister2 = await token.blacklister(); assert.equal(blacklister2, address2); }); @@ -613,26 +606,26 @@ async function run_tests(newToken, accounts) { it('should updateRoleAddress for pauser', async function () { let address1 = accounts[7]; let address2 = accounts[6]; - await token.updatePauser(address1, { from: tokenOwnerAccount }); + await token.updatePauser(address1, { from: Accounts.tokenOwnerAccount }); let pauser1 = await token.pauser(); assert.equal(pauser1, address1); - await token.updatePauser(address2, { from: tokenOwnerAccount }); + await token.updatePauser(address2, { from: Accounts.tokenOwnerAccount }); let pauser2 = await token.pauser(); assert.equal(pauser2, address2); }); it('should updateUpgraderAddress for upgrader', async function () { let upgrader = getAdmin(proxy); - assert.equal(proxyOwnerAccount, upgrader); + assert.equal(Accounts.proxyOwnerAccount, upgrader); let address1 = accounts[10]; - let updated = await proxy.changeAdmin(address1, { from: proxyOwnerAccount }); + let updated = await proxy.changeAdmin(address1, { from: Accounts.proxyOwnerAccount }); upgrader = getAdmin(proxy); assert.equal(upgrader, address1); //Test upgrade with new upgrader account - await token.configureMinter(minterAccount, 1000, {from: masterMinterAccount}); - await token.mint(accounts[2], 200, {from: minterAccount}); + await token.configureMinter(Accounts.minterAccount, 1000, {from: Accounts.masterMinterAccount}); + await token.mint(accounts[2], 200, {from: Accounts.minterAccount}); let initialBalance = await token.balanceOf(accounts[2]); assert.isTrue((new BigNumber(initialBalance)).isEqualTo(new BigNumber(200))); @@ -644,15 +637,15 @@ async function run_tests(newToken, accounts) { let upgradedBalance = await newToken.balanceOf(accounts[2]); assert.isTrue((new BigNumber(upgradedBalance)).isEqualTo(new BigNumber(200))); - await newToken.configureMinter(minterAccount, 500, { from: masterMinterAccount }); - await newToken.mint(accounts[2], 200, { from: minterAccount }); + await newToken.configureMinter(Accounts.minterAccount, 500, { from: Accounts.masterMinterAccount }); + await newToken.mint(accounts[2], 200, { from: Accounts.minterAccount }); let balance = await newToken.balanceOf(accounts[2]); assert.isTrue((new BigNumber(balance)).isEqualTo(new BigNumber(400))); }); it('should fail to updateUpgraderAddress for upgrader using non-upgrader account', async function () { let address1 = accounts[7]; - await expectRevert(proxy.changeAdmin(address1, { from: tokenOwnerAccount })); + await expectRevert(proxy.changeAdmin(address1, { from: Accounts.tokenOwnerAccount })); let upgrader = getAdmin(proxy); assert.notEqual(upgrader, address1); }); @@ -660,7 +653,7 @@ async function run_tests(newToken, accounts) { it('should updateRoleAddress for roleAddressChanger', async function () { let address1 = accounts[7]; let address2 = accounts[6]; - await token.transferOwnership(address1, { from: tokenOwnerAccount }); + await token.transferOwnership(address1, { from: Accounts.tokenOwnerAccount }); let roleAddressChanger1 = await token.owner(); assert.equal(roleAddressChanger1, address1); diff --git a/test/MiscTests.js b/test/MiscTests.js index e2e8efa50..bfeb0a9d0 100644 --- a/test/MiscTests.js +++ b/test/MiscTests.js @@ -14,18 +14,14 @@ var name = tokenUtils.name; var symbol = tokenUtils.symbol; var currency = tokenUtils.currency; var decimals = tokenUtils.decimals; -var deployerAccount = tokenUtils.deployerAccount; -var arbitraryAccount = tokenUtils.arbitraryAccount; -var arbitraryAccount2 = tokenUtils.arbitraryAccount2; -var tokenOwnerAccount = tokenUtils.tokenOwnerAccount; -var blacklisterAccount = tokenUtils.blacklisterAccount; -var masterMinterAccount = tokenUtils.masterMinterAccount; -var minterAccount = tokenUtils.minterAccount; -var pauserAccount = tokenUtils.pauserAccount; + var initializeTokenWithProxy = tokenUtils.initializeTokenWithProxy; var getInitializedV1 = tokenUtils.getInitializedV1; var FiatToken = tokenUtils.FiatToken; +var AccountUtils = require('./AccountUtils'); +var Accounts = AccountUtils.Accounts; + var maxAmount = "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"; var amount = 100; @@ -45,7 +41,7 @@ async function run_tests(newToken, accounts) { it('ms001 no payable function', async function () { var success = false; try { - await web3.eth.sendTransaction({ from: arbitraryAccount, to: token.address, value: 1 }); + await web3.eth.sendTransaction({ from: Accounts.arbitraryAccount, to: token.address, value: 1 }); } catch (e) { success = true; } @@ -56,9 +52,9 @@ async function run_tests(newToken, accounts) { it('ms002 should transfer to self has correct final balance', async function() { let mintAmount = 50; - await token.configureMinter(minterAccount, amount, { from: masterMinterAccount }); - await token.mint(arbitraryAccount, mintAmount, { from: minterAccount }); - await token.transfer(arbitraryAccount, mintAmount, { from: arbitraryAccount }); + await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); + await token.mint(Accounts.arbitraryAccount, mintAmount, { from: Accounts.minterAccount }); + await token.transfer(Accounts.arbitraryAccount, mintAmount, { from: Accounts.arbitraryAccount }); var customVars = [ { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - mintAmount) }, @@ -72,11 +68,11 @@ async function run_tests(newToken, accounts) { it('ms003 should transferFrom to self from approved account and have correct final balance', async function() { let mintAmount = 50; - await token.configureMinter(minterAccount, amount, { from: masterMinterAccount }); - await token.mint(arbitraryAccount, mintAmount, { from: minterAccount }); + await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); + await token.mint(Accounts.arbitraryAccount, mintAmount, { from: Accounts.minterAccount }); - await token.approve(pauserAccount, mintAmount, { from: arbitraryAccount }); - await token.transferFrom(arbitraryAccount, arbitraryAccount, mintAmount, { from: pauserAccount }); + await token.approve(Accounts.pauserAccount, mintAmount, { from: Accounts.arbitraryAccount }); + await token.transferFrom(Accounts.arbitraryAccount, Accounts.arbitraryAccount, mintAmount, { from: Accounts.pauserAccount }); customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - mintAmount) }, @@ -89,11 +85,11 @@ async function run_tests(newToken, accounts) { it('ms004 should transferFrom to self from approved self and have correct final balance', async function() { let mintAmount = 50; - await token.configureMinter(minterAccount, amount, { from: masterMinterAccount }); - await token.mint(arbitraryAccount, mintAmount, { from: minterAccount }); + await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); + await token.mint(Accounts.arbitraryAccount, mintAmount, { from: Accounts.minterAccount }); - await token.approve(arbitraryAccount, mintAmount, { from: arbitraryAccount }); - await token.transferFrom(arbitraryAccount, arbitraryAccount, mintAmount, { from: arbitraryAccount }); + await token.approve(Accounts.arbitraryAccount, mintAmount, { from: Accounts.arbitraryAccount }); + await token.transferFrom(Accounts.arbitraryAccount, Accounts.arbitraryAccount, mintAmount, { from: Accounts.arbitraryAccount }); customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - mintAmount) }, @@ -106,14 +102,14 @@ async function run_tests(newToken, accounts) { it('ms005 should mint to self with correct final balance', async function () { var mintAmount = 50; - await token.configureMinter(minterAccount, amount, { from: masterMinterAccount }); + await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); var customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount) } ]; await checkVariables([token], [customVars]); - await token.mint(minterAccount, mintAmount, { from: minterAccount }); + await token.mint(Accounts.minterAccount, mintAmount, { from: Accounts.minterAccount }); customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - mintAmount) }, @@ -126,15 +122,15 @@ async function run_tests(newToken, accounts) { it('ms006 should approve correct allowance for self', async function () { var mintAmount = 50; - await token.configureMinter(minterAccount, amount, { from: masterMinterAccount }); + await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); var customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount) } ]; await checkVariables([token], [customVars]); - await token.mint(arbitraryAccount, mintAmount, { from: minterAccount }); - await token.approve(arbitraryAccount, amount, { from: arbitraryAccount }); + await token.mint(Accounts.arbitraryAccount, mintAmount, { from: Accounts.minterAccount }); + await token.approve(Accounts.arbitraryAccount, amount, { from: Accounts.arbitraryAccount }); customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - mintAmount) }, @@ -146,7 +142,7 @@ async function run_tests(newToken, accounts) { }); it('ms007 should configureMinter for masterMinter', async function () { - await token.configureMinter(masterMinterAccount, amount, { from: masterMinterAccount }); + await token.configureMinter(Accounts.masterMinterAccount, amount, { from: Accounts.masterMinterAccount }); var customVars = [ { 'variable': 'isAccountMinter.masterMinterAccount', 'expectedValue': true }, { 'variable': 'minterAllowance.masterMinterAccount', 'expectedValue': new BigNumber(amount) } @@ -157,8 +153,8 @@ async function run_tests(newToken, accounts) { // Multiple Minters it('ms009 should configure two minters', async function () { - await token.configureMinter(minterAccount, amount, { from: masterMinterAccount }); - await token.configureMinter(arbitraryAccount, amount, { from: masterMinterAccount }); + await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); + await token.configureMinter(Accounts.arbitraryAccount, amount, { from: Accounts.masterMinterAccount }); var customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'isAccountMinter.arbitraryAccount', 'expectedValue': true }, @@ -172,10 +168,10 @@ async function run_tests(newToken, accounts) { var mintAmount1 = 10; var mintAmount2 = 20; - await token.configureMinter(minterAccount, amount, { from: masterMinterAccount }); - await token.configureMinter(arbitraryAccount, amount, { from: masterMinterAccount }); - await token.mint(pauserAccount, mintAmount1, { from: minterAccount }); - await token.mint(pauserAccount, mintAmount2, { from: arbitraryAccount }); + 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 }); var customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'isAccountMinter.arbitraryAccount', 'expectedValue': true }, @@ -191,11 +187,11 @@ async function run_tests(newToken, accounts) { var mintAmount1 = 10; var mintAmount2 = 20; - await token.configureMinter(minterAccount, amount, { from: masterMinterAccount }); - await token.configureMinter(arbitraryAccount, amount, { from: masterMinterAccount }); - await token.mint(pauserAccount, mintAmount1, { from: minterAccount }); - await token.mint(pauserAccount, mintAmount2, { from: arbitraryAccount }); - await token.removeMinter(arbitraryAccount, { from: masterMinterAccount }); + 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.removeMinter(Accounts.arbitraryAccount, { from: Accounts.masterMinterAccount }); var customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - mintAmount1) }, @@ -208,8 +204,8 @@ async function run_tests(newToken, accounts) { it('ms012 should configure two minters and adjust both allowances', async function () { var adjustment = 10; - await token.configureMinter(minterAccount, amount, { from: masterMinterAccount }); - await token.configureMinter(arbitraryAccount, amount, { from: masterMinterAccount }); + await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); + await token.configureMinter(Accounts.arbitraryAccount, amount, { from: Accounts.masterMinterAccount }); var customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'isAccountMinter.arbitraryAccount', 'expectedValue': true }, @@ -218,8 +214,8 @@ async function run_tests(newToken, accounts) { ]; await checkVariables([token], [customVars]); - await token.configureMinter(minterAccount, amount - adjustment, { from: masterMinterAccount }); - await token.configureMinter(arbitraryAccount, amount + adjustment, { from: masterMinterAccount }); + await token.configureMinter(Accounts.minterAccount, amount - adjustment, { from: Accounts.masterMinterAccount }); + await token.configureMinter(Accounts.arbitraryAccount, amount + adjustment, { from: Accounts.masterMinterAccount }); var customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'isAccountMinter.arbitraryAccount', 'expectedValue': true }, @@ -232,9 +228,9 @@ async function run_tests(newToken, accounts) { it('ms013 should configure two minters, one with zero allowance fails to mint', async function () { var mintAmount = 10; - await token.configureMinter(minterAccount, amount, { from: masterMinterAccount }); - await token.configureMinter(arbitraryAccount, 0, { from: masterMinterAccount }); - await token.mint(pauserAccount, mintAmount, { from: minterAccount }); + 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 }); var customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'isAccountMinter.arbitraryAccount', 'expectedValue': true }, @@ -242,17 +238,17 @@ async function run_tests(newToken, accounts) { { 'variable': 'balances.pauserAccount', 'expectedValue': new BigNumber(mintAmount) }, { 'variable': 'totalSupply', 'expectedValue': new BigNumber(mintAmount) }, ]; - await expectRevert(token.mint(pauserAccount, mintAmount, { from: arbitraryAccount })); - //await expectRevert(token.mint(pauserAccount, 0, { from: arbitraryAccount })); + await expectRevert(token.mint(Accounts.pauserAccount, mintAmount, { from: Accounts.arbitraryAccount })); + //await expectRevert(token.mint(Accounts.pauserAccount, 0, { from: Accounts.arbitraryAccount })); await checkVariables([token], [customVars]); }); it('ms014 should configure two minters and fail to mint when paused', async function () { var mintAmount = 10; - await token.configureMinter(minterAccount, amount, { from: masterMinterAccount }); - await token.configureMinter(arbitraryAccount, amount, { from: masterMinterAccount }); - await token.pause({ from: pauserAccount }); + await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); + await token.configureMinter(Accounts.arbitraryAccount, amount, { from: Accounts.masterMinterAccount }); + await token.pause({ from: Accounts.pauserAccount }); var customVars = [ { 'variable': 'paused', 'expectedValue': true }, { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, @@ -260,18 +256,18 @@ async function run_tests(newToken, accounts) { { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount) }, { 'variable': 'minterAllowance.arbitraryAccount', 'expectedValue': new BigNumber(amount) } ]; - await expectRevert(token.mint(pauserAccount, mintAmount, { from: minterAccount })); - await expectRevert(token.mint(pauserAccount, mintAmount, { from: arbitraryAccount })); + await expectRevert(token.mint(Accounts.pauserAccount, mintAmount, { from: Accounts.minterAccount })); + await expectRevert(token.mint(Accounts.pauserAccount, mintAmount, { from: Accounts.arbitraryAccount })); await checkVariables([token], [customVars]); }); it('ms015 should configure two minters, blacklist one and ensure it cannot mint, then unblacklist and ensure it can mint', async function () { var mintAmount = 10; - await token.configureMinter(minterAccount, amount, { from: masterMinterAccount }); - await token.configureMinter(arbitraryAccount, amount, { from: masterMinterAccount }); - await token.blacklist(minterAccount, { from: blacklisterAccount }); - await token.mint(pauserAccount, mintAmount, { from: arbitraryAccount }); + 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 }); var customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'isAccountMinter.arbitraryAccount', 'expectedValue': true }, @@ -281,11 +277,11 @@ async function run_tests(newToken, accounts) { { 'variable': 'totalSupply', 'expectedValue': new BigNumber(mintAmount) }, { 'variable': 'balances.pauserAccount', 'expectedValue': new BigNumber(mintAmount) }, ]; - await expectRevert(token.mint(pauserAccount, mintAmount, { from: minterAccount })); + await expectRevert(token.mint(Accounts.pauserAccount, mintAmount, { from: Accounts.minterAccount })); await checkVariables([token], [customVars]); - await token.unBlacklist(minterAccount, { from: blacklisterAccount }); - await token.mint(pauserAccount, mintAmount, { from: minterAccount }); + await token.unBlacklist(Accounts.minterAccount, { from: Accounts.blacklisterAccount }); + await token.mint(Accounts.pauserAccount, mintAmount, { from: Accounts.minterAccount }); var customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'isAccountMinter.arbitraryAccount', 'expectedValue': true }, @@ -302,10 +298,10 @@ async function run_tests(newToken, accounts) { var mintAmount2 = 20; var burnAmount = 10; - await token.configureMinter(minterAccount, amount, { from: masterMinterAccount }); - await token.configureMinter(arbitraryAccount, amount, { from: masterMinterAccount }); - await token.mint(minterAccount, mintAmount1, { from: minterAccount }); - await token.mint(arbitraryAccount, mintAmount2, { from: arbitraryAccount }); + await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); + await token.configureMinter(Accounts.arbitraryAccount, amount, { from: Accounts.masterMinterAccount }); + await token.mint(Accounts.minterAccount, mintAmount1, { from: Accounts.minterAccount }); + await token.mint(Accounts.arbitraryAccount, mintAmount2, { from: Accounts.arbitraryAccount }); var customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'isAccountMinter.arbitraryAccount', 'expectedValue': true }, @@ -317,8 +313,8 @@ async function run_tests(newToken, accounts) { ]; await checkVariables([token], [customVars]); - await token.burn(burnAmount, { from: minterAccount }); - await token.burn(burnAmount, { from: arbitraryAccount }); + await token.burn(burnAmount, { from: Accounts.minterAccount }); + await token.burn(burnAmount, { from: Accounts.arbitraryAccount }); var customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'isAccountMinter.arbitraryAccount', 'expectedValue': true }, @@ -334,23 +330,23 @@ async function run_tests(newToken, accounts) { // 0 Input it('ms018 should approve 0 token allowance with unchanged state', async function () { - await token.approve(minterAccount, 0, { from: arbitraryAccount }); + await token.approve(Accounts.minterAccount, 0, { from: Accounts.arbitraryAccount }); await checkVariables([token], [[]]); }); it('ms019 should transferFrom 0 tokens with unchanged state', async function () { - await token.transferFrom(arbitraryAccount, pauserAccount, 0, { from: arbitraryAccount2 }); + await token.transferFrom(Accounts.arbitraryAccount, Accounts.pauserAccount, 0, { from: Accounts.arbitraryAccount2 }); await checkVariables([token], [[]]); }); it('ms020 should transfer 0 tokens with unchanged state', async function () { - await token.transfer(arbitraryAccount, 0, { from: arbitraryAccount2 }); + await token.transfer(Accounts.arbitraryAccount, 0, { from: Accounts.arbitraryAccount2 }); await checkVariables([token], [[]]); }); it('ms036 should get allowance for same address', async function() { - await token.approve(arbitraryAccount, amount, {from: arbitraryAccount}); - var allowance = new BigNumber(await token.allowance(arbitraryAccount, arbitraryAccount)); + await token.approve(Accounts.arbitraryAccount, amount, {from: Accounts.arbitraryAccount}); + var allowance = new BigNumber(await token.allowance(Accounts.arbitraryAccount, Accounts.arbitraryAccount)); assert(allowance.isEqualTo(new BigNumber(amount))); }); @@ -374,31 +370,31 @@ async function run_tests(newToken, accounts) { it('ms039 should return true on mint', async function() { var mintAmount = 50; - await token.configureMinter(minterAccount, amount, { from: masterMinterAccount }); + await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); var customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount) } ]; - assert(await token.mint.call(arbitraryAccount, mintAmount, { from: minterAccount })); + assert(await token.mint.call(Accounts.arbitraryAccount, mintAmount, { from: Accounts.minterAccount })); await checkVariables([token], [customVars]); }); it('ms040 should return true on approve', async function() { - assert(await token.approve.call(minterAccount, amount, { from: arbitraryAccount })); + assert(await token.approve.call(Accounts.minterAccount, amount, { from: Accounts.arbitraryAccount })); }); it('ms041 should return true on transferFrom', async function() { let mintAmount = 50; - await token.configureMinter(minterAccount, amount, { from: masterMinterAccount }); + await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); var customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount) } ]; await checkVariables([token], [customVars]); - await token.mint(arbitraryAccount, mintAmount, { from: minterAccount }); - await token.approve(masterMinterAccount, mintAmount, { from: arbitraryAccount }); + await token.mint(Accounts.arbitraryAccount, mintAmount, { from: Accounts.minterAccount }); + await token.approve(Accounts.masterMinterAccount, mintAmount, { from: Accounts.arbitraryAccount }); customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - mintAmount) }, @@ -406,37 +402,37 @@ async function run_tests(newToken, accounts) { { 'variable': 'totalSupply', 'expectedValue': new BigNumber(mintAmount) }, { 'variable': 'allowance.arbitraryAccount.masterMinterAccount', 'expectedValue': new BigNumber(mintAmount)}, ]; - assert(await token.transferFrom.call(arbitraryAccount, pauserAccount, mintAmount, { from: masterMinterAccount })); + assert(await token.transferFrom.call(Accounts.arbitraryAccount, Accounts.pauserAccount, mintAmount, { from: Accounts.masterMinterAccount })); await checkVariables([token], [customVars]); }); it('ms042 should return true on transfer', async function() { let mintAmount = 50; - await token.configureMinter(minterAccount, amount, { from: masterMinterAccount }); + await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); var customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount) } ]; await checkVariables([token], [customVars]); - await token.mint(arbitraryAccount, mintAmount, { from: minterAccount }); + await token.mint(Accounts.arbitraryAccount, mintAmount, { from: Accounts.minterAccount }); customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - mintAmount) }, { 'variable': 'balances.arbitraryAccount', 'expectedValue': new BigNumber(mintAmount) }, { 'variable': 'totalSupply', 'expectedValue': new BigNumber(mintAmount) } ]; - assert(await token.transfer.call(pauserAccount, mintAmount, { from: arbitraryAccount })); + assert(await token.transfer.call(Accounts.pauserAccount, mintAmount, { from: Accounts.arbitraryAccount })); await checkVariables([token], [customVars]); }); it('ms043 should return true on configureMinter', async function() { - assert(await token.configureMinter.call(minterAccount, amount, { from: masterMinterAccount })); + assert(await token.configureMinter.call(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount })); }); it('ms044 should return true on removeMinter', async function() { - assert(await token.removeMinter.call(minterAccount, { from: masterMinterAccount })); + assert(await token.removeMinter.call(Accounts.minterAccount, { from: Accounts.masterMinterAccount })); }); it('ms045 initialized should be in slot 8, byte 21', async function() { @@ -446,14 +442,14 @@ async function run_tests(newToken, accounts) { it('ms046 initialized should be 0 before initialization', async function() { var rawToken = await newToken(); - var newProxy = await FiatTokenProxy.new(rawToken.address, { from: arbitraryAccount }); + var newProxy = await FiatTokenProxy.new(rawToken.address, { from: Accounts.arbitraryAccount }); var token = FiatToken.at(newProxy.address); var initialized = await getInitializedV1(token); assert.equal("0x00", initialized); }); it('ms047 configureMinter works on amount=2^256-1', async function() { - await token.configureMinter(minterAccount, maxAmount, { from: masterMinterAccount }); + await token.configureMinter(Accounts.minterAccount, maxAmount, { from: Accounts.masterMinterAccount }); var customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(maxAmount) } @@ -462,14 +458,14 @@ async function run_tests(newToken, accounts) { }); it('ms048 mint works on amount=2^256-1', async function() { - await token.configureMinter(minterAccount, maxAmount, { from: masterMinterAccount }); + await token.configureMinter(Accounts.minterAccount, maxAmount, { from: Accounts.masterMinterAccount }); var customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(maxAmount) } ]; await checkVariables([token], [customVars]); - await token.mint(arbitraryAccount, maxAmount, { from: minterAccount }); + await token.mint(Accounts.arbitraryAccount, maxAmount, { from: Accounts.minterAccount }); customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(0) }, @@ -480,8 +476,8 @@ async function run_tests(newToken, accounts) { }); it('ms049 burn on works on amount=2^256-1', async function() { - await token.configureMinter(minterAccount, maxAmount, { from: masterMinterAccount }); - await token.mint(minterAccount, maxAmount, { from: minterAccount }); + await token.configureMinter(Accounts.minterAccount, maxAmount, { from: Accounts.masterMinterAccount }); + await token.mint(Accounts.minterAccount, maxAmount, { from: Accounts.minterAccount }); customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'balances.minterAccount', 'expectedValue': new BigNumber(maxAmount) }, @@ -489,7 +485,7 @@ async function run_tests(newToken, accounts) { ]; await checkVariables([token], [customVars]); - await token.burn(maxAmount, { from: minterAccount }); + await token.burn(maxAmount, { from: Accounts.minterAccount }); customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, ]; @@ -497,8 +493,8 @@ async function run_tests(newToken, accounts) { }); it('ms050 approve works on amount=2^256-1', async function() { - await token.configureMinter(minterAccount, maxAmount, { from: masterMinterAccount }); - await token.mint(arbitraryAccount, maxAmount, { from: minterAccount }); + await token.configureMinter(Accounts.minterAccount, maxAmount, { from: Accounts.masterMinterAccount }); + await token.mint(Accounts.arbitraryAccount, maxAmount, { from: Accounts.minterAccount }); customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'balances.arbitraryAccount', 'expectedValue': new BigNumber(maxAmount) }, @@ -506,7 +502,7 @@ async function run_tests(newToken, accounts) { ]; await checkVariables([token], [customVars]); - await token.approve(pauserAccount, maxAmount, {from: arbitraryAccount}); + await token.approve(Accounts.pauserAccount, maxAmount, {from: Accounts.arbitraryAccount}); customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'balances.arbitraryAccount', 'expectedValue': new BigNumber(maxAmount) }, @@ -517,8 +513,8 @@ async function run_tests(newToken, accounts) { }); it('ms051 transfer works on amount=2^256-1', async function() { - await token.configureMinter(minterAccount, maxAmount, { from: masterMinterAccount }); - await token.mint(arbitraryAccount, maxAmount, { from: minterAccount }); + await token.configureMinter(Accounts.minterAccount, maxAmount, { from: Accounts.masterMinterAccount }); + await token.mint(Accounts.arbitraryAccount, maxAmount, { from: Accounts.minterAccount }); customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'balances.arbitraryAccount', 'expectedValue': new BigNumber(maxAmount) }, @@ -526,7 +522,7 @@ async function run_tests(newToken, accounts) { ]; await checkVariables([token], [customVars]); - await token.transfer(pauserAccount, maxAmount, {from: arbitraryAccount}); + await token.transfer(Accounts.pauserAccount, maxAmount, {from: Accounts.arbitraryAccount}); customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'balances.pauserAccount', 'expectedValue': new BigNumber(maxAmount) }, @@ -536,9 +532,9 @@ async function run_tests(newToken, accounts) { }); it('ms052 transferFrom works on amount=2^256-1', async function() { - await token.configureMinter(minterAccount, maxAmount, { from: masterMinterAccount }); - await token.mint(arbitraryAccount, maxAmount, { from: minterAccount }); - await token.approve(pauserAccount, maxAmount, {from: arbitraryAccount}); + 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}); customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'balances.arbitraryAccount', 'expectedValue': new BigNumber(maxAmount) }, @@ -547,7 +543,7 @@ async function run_tests(newToken, accounts) { ]; await checkVariables([token], [customVars]); - await token.transferFrom(arbitraryAccount, pauserAccount, maxAmount, {from: pauserAccount}); + await token.transferFrom(Accounts.arbitraryAccount, Accounts.pauserAccount, maxAmount, {from: Accounts.pauserAccount}); customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'balances.pauserAccount', 'expectedValue': new BigNumber(maxAmount) }, diff --git a/test/NegativeTests.js b/test/NegativeTests.js index 6c29fc06e..5712d23bf 100644 --- a/test/NegativeTests.js +++ b/test/NegativeTests.js @@ -12,22 +12,16 @@ var name = tokenUtils.name; var symbol = tokenUtils.symbol; var currency = tokenUtils.currency; var decimals = tokenUtils.decimals; -var deployerAccount = tokenUtils.deployerAccount; -var arbitraryAccount = tokenUtils.arbitraryAccount; -var arbitraryAccount2 = tokenUtils.arbitraryAccount2; -var tokenOwnerAccount = tokenUtils.tokenOwnerAccount; -var tokenOwnerAccount = tokenUtils.tokenOwnerAccount; -var blacklisterAccount = tokenUtils.blacklisterAccount; -var masterMinterAccount = tokenUtils.masterMinterAccount; -var minterAccount = tokenUtils.minterAccount; -var pauserAccount = tokenUtils.pauserAccount; -var proxyOwnerAccount = tokenUtils.proxyOwnerAccount; + var initializeTokenWithProxy = tokenUtils.initializeTokenWithProxy; var customInitializeTokenWithProxy = tokenUtils.customInitializeTokenWithProxy; var upgradeTo = tokenUtils.upgradeTo; var UpgradedFiatToken = tokenUtils.UpgradedFiatToken; var FiatToken = tokenUtils.FiatToken; +var AccountUtils = require('./AccountUtils'); +var Accounts = AccountUtils.Accounts; + var amount = 100; let longZero = 0x0000000000000000000000000000000000000000; let shortZero = 0x00; @@ -46,110 +40,110 @@ async function run_tests(newToken, accounts) { // Mint it('nt001 should fail to mint when paused', async function () { - await token.configureMinter(minterAccount, amount, {from: masterMinterAccount}); - await token.pause({from: pauserAccount}); + await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); + await token.pause({from: Accounts.pauserAccount}); var customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)}, {'variable': 'paused', 'expectedValue': true} ] - await expectRevert(token.mint(arbitraryAccount, 50, {from: minterAccount})); + await expectRevert(token.mint(Accounts.arbitraryAccount, 50, {from: Accounts.minterAccount})); await checkVariables([token], [customVars]); }); it('nt002 should fail to mint when msg.sender is not a minter', async function () { - //Note: minterAccount has not yet been configured as a minter - await expectRevert(token.mint(arbitraryAccount, 50, {from: minterAccount})); + //Note: Accounts.minterAccount has not yet been configured as a minter + await expectRevert(token.mint(Accounts.arbitraryAccount, 50, {from: Accounts.minterAccount})); await checkVariables([token], [[]]); }); it('nt003 should fail to mint when msg.sender is blacklisted', async function () { - await token.blacklist(minterAccount, {from: blacklisterAccount}); - await token.configureMinter(minterAccount, amount, {from: masterMinterAccount}); + await token.blacklist(Accounts.minterAccount, {from: Accounts.blacklisterAccount}); + await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); var customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)}, {'variable': 'isAccountBlacklisted.minterAccount', 'expectedValue': true} ] - await expectRevert(token.mint(arbitraryAccount, 50, {from: minterAccount})); + await expectRevert(token.mint(Accounts.arbitraryAccount, 50, {from: Accounts.minterAccount})); await checkVariables([token], [customVars]); }); it('nt004 should fail to mint when recipient is blacklisted', async function () { - await token.blacklist(arbitraryAccount, {from: blacklisterAccount}); - await token.configureMinter(minterAccount, amount, {from: masterMinterAccount}); + await token.blacklist(Accounts.arbitraryAccount, {from: Accounts.blacklisterAccount}); + await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); var customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)}, {'variable': 'isAccountBlacklisted.arbitraryAccount', 'expectedValue': true} ] - await expectRevert(token.mint(arbitraryAccount, 50, {from: minterAccount})); + await expectRevert(token.mint(Accounts.arbitraryAccount, 50, {from: Accounts.minterAccount})); await checkVariables([token], [customVars]); }); it('nt005 should fail to mint when allowance of minter is less than amount', async function () { - await token.configureMinter(minterAccount, amount - 1, {from: masterMinterAccount}); + await token.configureMinter(Accounts.minterAccount, amount - 1, {from: Accounts.masterMinterAccount}); var customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - 1)} ] - await expectRevert(token.mint(arbitraryAccount, amount, {from: minterAccount})); + await expectRevert(token.mint(Accounts.arbitraryAccount, amount, {from: Accounts.minterAccount})); await checkVariables([token], [customVars]); }); it('nt006 should fail to mint to 0x0 address', async function () { - await token.configureMinter(minterAccount, amount, {from: masterMinterAccount}); + await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); var customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)} ] - await expectRevert(token.mint("0x0", amount, {from: minterAccount})); - await expectRevert(token.mint("0x0000000000000000000000000000000000000000", amount, {from: minterAccount})); - await expectRevert(token.mint(0x0000000000000000000000000000000000000000, amount, {from: minterAccount})); + await expectRevert(token.mint("0x0", amount, {from: Accounts.minterAccount})); + await expectRevert(token.mint("0x0000000000000000000000000000000000000000", amount, {from: Accounts.minterAccount})); + await expectRevert(token.mint(0x0000000000000000000000000000000000000000, amount, {from: Accounts.minterAccount})); await checkVariables([token], [customVars]); }); // Approve it('nt008 should fail to approve when spender is blacklisted', async function () { - await token.blacklist(minterAccount, {from: blacklisterAccount}); + await token.blacklist(Accounts.minterAccount, {from: Accounts.blacklisterAccount}); var customVars = [ {'variable': 'isAccountBlacklisted.minterAccount', 'expectedValue': true}, ] - await expectRevert(token.approve(minterAccount, 100, {from: arbitraryAccount})); + await expectRevert(token.approve(Accounts.minterAccount, 100, {from: Accounts.arbitraryAccount})); await checkVariables([token], [customVars]); }); it('nt009 should fail to approve when msg.sender is blacklisted', async function () { - await token.blacklist(arbitraryAccount, {from: blacklisterAccount}); + await token.blacklist(Accounts.arbitraryAccount, {from: Accounts.blacklisterAccount}); var customVars = [ {'variable': 'isAccountBlacklisted.arbitraryAccount', 'expectedValue': true}, ] - await expectRevert(token.approve(minterAccount, 100, {from: arbitraryAccount})); + await expectRevert(token.approve(Accounts.minterAccount, 100, {from: Accounts.arbitraryAccount})); await checkVariables([token], [customVars]); }); it('nt010 should fail to approve when contract is paused', async function () { - await token.pause({from: pauserAccount}); + await token.pause({from: Accounts.pauserAccount}); var customVars = [ {'variable': 'paused', 'expectedValue': true}, ] - await expectRevert(token.approve(minterAccount, 100, {from: arbitraryAccount})); + await expectRevert(token.approve(Accounts.minterAccount, 100, {from: Accounts.arbitraryAccount})); await checkVariables([token], [customVars]); }); // TransferFrom it('nt012 should fail to transferFrom to 0x0 address', async function () { - await token.configureMinter(minterAccount, amount, {from: masterMinterAccount}); + await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); var customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)} ] await checkVariables([token], [customVars]); - await token.mint(arbitraryAccount, 50, {from: minterAccount}); - await token.approve(pauserAccount, 50, {from: arbitraryAccount}); + await token.mint(Accounts.arbitraryAccount, 50, {from: Accounts.minterAccount}); + await token.approve(Accounts.pauserAccount, 50, {from: Accounts.arbitraryAccount}); customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - 50)}, @@ -157,20 +151,20 @@ async function run_tests(newToken, accounts) { {'variable': 'totalSupply', 'expectedValue': new BigNumber(50)}, {'variable': 'allowance.arbitraryAccount.pauserAccount', 'expectedValue': new BigNumber(50)} ] - await expectRevert(token.transferFrom(arbitraryAccount, "0x0", 50, {from: pauserAccount})); + await expectRevert(token.transferFrom(Accounts.arbitraryAccount, "0x0", 50, {from: Accounts.pauserAccount})); await checkVariables([token], [customVars]); }); it('nt013 should fail to transferFrom an amount greater than balance', async function () { - await token.configureMinter(minterAccount, amount, {from: masterMinterAccount}); + await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)} ] await checkVariables([token], [customVars]); - await token.mint(arbitraryAccount, 50, {from: minterAccount}); - await token.approve(blacklisterAccount, amount, {from: arbitraryAccount}); + await token.mint(Accounts.arbitraryAccount, 50, {from: Accounts.minterAccount}); + await token.approve(Accounts.blacklisterAccount, amount, {from: Accounts.arbitraryAccount}); customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - 50)}, @@ -178,21 +172,21 @@ async function run_tests(newToken, accounts) { {'variable': 'totalSupply', 'expectedValue': new BigNumber(50)}, {'variable': 'allowance.arbitraryAccount.blacklisterAccount', 'expectedValue': new BigNumber(amount)}, ] - await expectRevert(token.transferFrom(arbitraryAccount, pauserAccount, amount, {from: blacklisterAccount})); + await expectRevert(token.transferFrom(Accounts.arbitraryAccount, Accounts.pauserAccount, amount, {from: Accounts.blacklisterAccount})); await checkVariables([token], [customVars]); }); it('nt014 should fail to transferFrom to blacklisted recipient', async function () { - await token.configureMinter(minterAccount, amount, {from: masterMinterAccount}); + await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)} ] await checkVariables([token], [customVars]); - await token.mint(blacklisterAccount, 50, {from: minterAccount}); - await token.approve(pauserAccount, 50, {from: blacklisterAccount}); - await token.blacklist(arbitraryAccount, {from: blacklisterAccount}); + await token.mint(Accounts.blacklisterAccount, 50, {from: Accounts.minterAccount}); + await token.approve(Accounts.pauserAccount, 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)}, @@ -201,21 +195,21 @@ async function run_tests(newToken, accounts) { {'variable': 'allowance.blacklisterAccount.pauserAccount', 'expectedValue': new BigNumber(50)}, {'variable': 'isAccountBlacklisted.arbitraryAccount', 'expectedValue': true} ] - await expectRevert(token.transferFrom(blacklisterAccount, arbitraryAccount, 50, {from: pauserAccount})); + await expectRevert(token.transferFrom(Accounts.blacklisterAccount, Accounts.arbitraryAccount, 50, {from: Accounts.pauserAccount})); await checkVariables([token], [customVars]); }); it('nt015 should fail to transferFrom from blacklisted msg.sender', async function () { - await token.configureMinter(minterAccount, amount, {from: masterMinterAccount}); + await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)} ] await checkVariables([token], [customVars]); - await token.mint(tokenOwnerAccount, 50, {from: minterAccount}); - await token.approve(arbitraryAccount, 50, {from: tokenOwnerAccount}); - await token.blacklist(arbitraryAccount, {from: blacklisterAccount}); + await token.mint(Accounts.tokenOwnerAccount, 50, {from: Accounts.minterAccount}); + await token.approve(Accounts.arbitraryAccount, 50, {from: Accounts.tokenOwnerAccount}); + await token.blacklist(Accounts.arbitraryAccount, {from: Accounts.blacklisterAccount}); customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - 50)}, @@ -224,21 +218,21 @@ async function run_tests(newToken, accounts) { {'variable': 'allowance.tokenOwnerAccount.arbitraryAccount', 'expectedValue': new BigNumber(50)}, {'variable': 'isAccountBlacklisted.arbitraryAccount', 'expectedValue': true} ] - await expectRevert(token.transferFrom(tokenOwnerAccount, pauserAccount, 50, {from: arbitraryAccount})); + await expectRevert(token.transferFrom(Accounts.tokenOwnerAccount, Accounts.pauserAccount, 50, {from: Accounts.arbitraryAccount})); await checkVariables([token], [customVars]); }); it('nt016 should fail to transferFrom when from is blacklisted', async function () { - await token.configureMinter(minterAccount, amount, {from: masterMinterAccount}); + await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)} ] await checkVariables([token], [customVars]); - await token.mint(arbitraryAccount, 50, {from: minterAccount}); - await token.approve(tokenOwnerAccount, 50, {from: arbitraryAccount}); - await token.blacklist(arbitraryAccount, {from: blacklisterAccount}); + await token.mint(Accounts.arbitraryAccount, 50, {from: Accounts.minterAccount}); + await token.approve(Accounts.tokenOwnerAccount, 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)}, @@ -247,20 +241,20 @@ async function run_tests(newToken, accounts) { {'variable': 'allowance.arbitraryAccount.tokenOwnerAccount', 'expectedValue': new BigNumber(50)}, {'variable': 'isAccountBlacklisted.arbitraryAccount', 'expectedValue': true} ] - await expectRevert(token.transferFrom(arbitraryAccount, pauserAccount, 50, {from: tokenOwnerAccount})); + await expectRevert(token.transferFrom(Accounts.arbitraryAccount, Accounts.pauserAccount, 50, {from: Accounts.tokenOwnerAccount})); await checkVariables([token], [customVars]); }); it('nt017 should fail to transferFrom an amount greater than allowed for msg.sender', async function () { - await token.configureMinter(minterAccount, amount, {from: masterMinterAccount}); + await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)} ] await checkVariables([token], [customVars]); - await token.mint(arbitraryAccount, 50, {from: minterAccount}); - await token.approve(tokenOwnerAccount, 50, {from: arbitraryAccount}); + await token.mint(Accounts.arbitraryAccount, 50, {from: Accounts.minterAccount}); + await token.approve(Accounts.tokenOwnerAccount, 50, {from: Accounts.arbitraryAccount}); customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - 50)}, @@ -268,21 +262,21 @@ async function run_tests(newToken, accounts) { {'variable': 'totalSupply', 'expectedValue': new BigNumber(50)}, {'variable': 'allowance.arbitraryAccount.tokenOwnerAccount', 'expectedValue': new BigNumber(50)}, ] - await expectRevert(token.transferFrom(arbitraryAccount, pauserAccount, 60, {from: tokenOwnerAccount})); + await expectRevert(token.transferFrom(Accounts.arbitraryAccount, Accounts.pauserAccount, 60, {from: Accounts.tokenOwnerAccount})); await checkVariables([token], [customVars]); }); it('nt018 should fail to transferFrom when paused', async function () { - await token.configureMinter(minterAccount, amount, {from: masterMinterAccount}); + await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); var customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)} ] await checkVariables([token], [customVars]); - await token.mint(arbitraryAccount, 50, {from: minterAccount}); - await token.approve(tokenOwnerAccount, 50, {from: arbitraryAccount}); - await token.pause({from: pauserAccount}); + await token.mint(Accounts.arbitraryAccount, 50, {from: Accounts.minterAccount}); + await token.approve(Accounts.tokenOwnerAccount, 50, {from: Accounts.arbitraryAccount}); + await token.pause({from: Accounts.pauserAccount}); customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - 50)}, @@ -291,60 +285,60 @@ async function run_tests(newToken, accounts) { {'variable': 'allowance.arbitraryAccount.tokenOwnerAccount', 'expectedValue': new BigNumber(50)}, {'variable': 'paused', 'expectedValue': true} ] - await expectRevert(token.transferFrom(arbitraryAccount, pauserAccount, 50, {from: tokenOwnerAccount})); + await expectRevert(token.transferFrom(Accounts.arbitraryAccount, Accounts.pauserAccount, 50, {from: Accounts.tokenOwnerAccount})); await checkVariables([token], [customVars]); }); // Transfer it('nt020 should fail to transfer to 0x0 address', async function () { - await token.configureMinter(minterAccount, amount, {from: masterMinterAccount}); + await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); var customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)} ] await checkVariables([token], [customVars]); - await token.mint(arbitraryAccount, 50, {from: minterAccount}); + await token.mint(Accounts.arbitraryAccount, 50, {from: Accounts.minterAccount}); 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)} ] - await expectRevert(token.transfer("0x0", 50, {from: arbitraryAccount})); + await expectRevert(token.transfer("0x0", 50, {from: Accounts.arbitraryAccount})); await checkVariables([token], [customVars]); }); it('nt021 should fail to transfer an amount greater than balance', async function () { - await token.configureMinter(minterAccount, amount, {from: masterMinterAccount}); + await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)} ] await checkVariables([token], [customVars]); - await token.mint(arbitraryAccount, 50, {from: minterAccount}); + await token.mint(Accounts.arbitraryAccount, 50, {from: Accounts.minterAccount}); var 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)} ] - await expectRevert(token.transfer(pauserAccount, amount, {from: arbitraryAccount})); + await expectRevert(token.transfer(Accounts.pauserAccount, amount, {from: Accounts.arbitraryAccount})); await checkVariables([token], [customVars]); }); it('nt022 should fail to transfer to blacklisted recipient', async function () { - await token.configureMinter(minterAccount, amount, {from: masterMinterAccount}); + await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)} ] await checkVariables([token], [customVars]); - await token.mint(tokenOwnerAccount, 50, {from: minterAccount}); - await token.blacklist(arbitraryAccount, {from: blacklisterAccount}); + await token.mint(Accounts.tokenOwnerAccount, 50, {from: Accounts.minterAccount}); + await token.blacklist(Accounts.arbitraryAccount, {from: Accounts.blacklisterAccount}); customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - 50)}, @@ -352,20 +346,20 @@ async function run_tests(newToken, accounts) { {'variable': 'totalSupply', 'expectedValue': new BigNumber(50)}, {'variable': 'isAccountBlacklisted.arbitraryAccount', 'expectedValue': true} ] - await expectRevert(token.transfer(arbitraryAccount, 50, {from: tokenOwnerAccount})); + await expectRevert(token.transfer(Accounts.arbitraryAccount, 50, {from: Accounts.tokenOwnerAccount})); await checkVariables([token], [customVars]); }); it('nt023 should fail to transfer when sender is blacklisted', async function () { - await token.configureMinter(minterAccount, amount, {from: masterMinterAccount}); + await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)} ] await checkVariables([token], [customVars]); - await token.mint(arbitraryAccount, 50, {from: minterAccount}); - await token.blacklist(arbitraryAccount, {from: blacklisterAccount}); + await token.mint(Accounts.arbitraryAccount, 50, {from: Accounts.minterAccount}); + await token.blacklist(Accounts.arbitraryAccount, {from: Accounts.blacklisterAccount}); customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - 50)}, @@ -373,20 +367,20 @@ async function run_tests(newToken, accounts) { {'variable': 'totalSupply', 'expectedValue': new BigNumber(50)}, {'variable': 'isAccountBlacklisted.arbitraryAccount', 'expectedValue': true} ] - await expectRevert(token.transfer(tokenOwnerAccount, 50, {from: arbitraryAccount})); + await expectRevert(token.transfer(Accounts.tokenOwnerAccount, 50, {from: Accounts.arbitraryAccount})); await checkVariables([token], [customVars]); }); it('nt024 should fail to transfer when paused', async function () { - await token.configureMinter(minterAccount, amount, {from: masterMinterAccount}); + await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); var customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)} ] await checkVariables([token], [customVars]); - await token.mint(arbitraryAccount, 50, {from: minterAccount}); - await token.pause({from: pauserAccount}); + await token.mint(Accounts.arbitraryAccount, 50, {from: Accounts.minterAccount}); + await token.pause({from: Accounts.pauserAccount}); customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - 50)}, @@ -394,75 +388,75 @@ async function run_tests(newToken, accounts) { {'variable': 'totalSupply', 'expectedValue': new BigNumber(50)}, {'variable': 'paused', 'expectedValue': true} ] - await expectRevert(token.transfer(tokenOwnerAccount, 50, {from: arbitraryAccount})); + await expectRevert(token.transfer(Accounts.tokenOwnerAccount, 50, {from: Accounts.arbitraryAccount})); await checkVariables([token], [customVars]); }); // ConfigureMinter it('nt026 should fail to configureMinter when sender is not masterMinter', async function () { - assert.isFalse(arbitraryAccount == masterMinterAccount); - await expectRevert(token.configureMinter(minterAccount, amount, {from: arbitraryAccount})); + assert.isFalse(Accounts.arbitraryAccount == Accounts.masterMinterAccount); + await expectRevert(token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.arbitraryAccount})); await checkVariables([token], [[]]); }); it('nt028 should fail to configureMinter when paused', async function () { - await token.pause({from: pauserAccount}); + await token.pause({from: Accounts.pauserAccount}); customVars = [ {'variable': 'paused', 'expectedValue': true} ] - await expectRevert(token.configureMinter(minterAccount, amount, {from: masterMinterAccount})); + await expectRevert(token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount})); await checkVariables([token], [customVars]); }); // RemoveMinter it('nt029 should fail to removeMinter when sender is not masterMinter', async function () { - await token.configureMinter(minterAccount, amount, {from: masterMinterAccount}); + await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); var customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)} ] - await expectRevert(token.removeMinter(minterAccount, {from: arbitraryAccount})); + await expectRevert(token.removeMinter(Accounts.minterAccount, {from: Accounts.arbitraryAccount})); await checkVariables([token], [customVars]); }); // Burn it('nt031 should fail to burn when balance is less than amount', async function () { - await token.configureMinter(minterAccount, amount, {from: masterMinterAccount}); + await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); var customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)} ] - await expectRevert(token.burn(amount, {from: minterAccount})); + await expectRevert(token.burn(amount, {from: Accounts.minterAccount})); await checkVariables([token], [customVars]); }); it('nt032 should fail to burn when amount is -1', async function () { - await token.configureMinter(minterAccount, amount, {from: masterMinterAccount}); - await token.mint(minterAccount, amount, {from: minterAccount}); + await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); + await token.mint(Accounts.minterAccount, amount, {from: Accounts.minterAccount}); var customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(0)}, {'variable': 'balances.minterAccount', 'expectedValue': new BigNumber(amount)}, {'variable': 'totalSupply', 'expectedValue': new BigNumber(amount)} ] - await expectRevert(token.burn(-1, {from: minterAccount})); + await expectRevert(token.burn(-1, {from: Accounts.minterAccount})); await checkVariables([token], [customVars]); }); it('nt033 should fail to burn when sender is blacklisted', async function () { - await token.configureMinter(minterAccount, amount, {from: masterMinterAccount}); + await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); var customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)} ] await checkVariables([token], [customVars]); - await token.mint(minterAccount, 50, {from: minterAccount}); - await token.blacklist(minterAccount, {from: blacklisterAccount}); + await token.mint(Accounts.minterAccount, 50, {from: Accounts.minterAccount}); + await token.blacklist(Accounts.minterAccount, {from: Accounts.blacklisterAccount}); customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - 50)}, @@ -470,20 +464,20 @@ async function run_tests(newToken, accounts) { {'variable': 'totalSupply', 'expectedValue': new BigNumber(50)}, {'variable': 'isAccountBlacklisted.minterAccount', 'expectedValue': true} ] - await expectRevert(token.burn(50, {from: minterAccount})); + await expectRevert(token.burn(50, {from: Accounts.minterAccount})); await checkVariables([token], [customVars]); }); it('nt034 should fail to burn when paused', async function () { - await token.configureMinter(minterAccount, amount, {from: masterMinterAccount}); + await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); var customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)} ] await checkVariables([token], [customVars]); - await token.mint(minterAccount, 50, {from: minterAccount}); - await token.pause({from: pauserAccount}); + await token.mint(Accounts.minterAccount, 50, {from: Accounts.minterAccount}); + await token.pause({from: Accounts.pauserAccount}); customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - 50)}, @@ -491,38 +485,38 @@ async function run_tests(newToken, accounts) { {'variable': 'totalSupply', 'expectedValue': new BigNumber(50)}, {'variable': 'paused', 'expectedValue': true} ] - await expectRevert(token.burn(50, {from: minterAccount})); + await expectRevert(token.burn(50, {from: Accounts.minterAccount})); await checkVariables([token], [customVars]); }); it('nt035 should fail to burn when sender is not minter', async function () { - await token.configureMinter(minterAccount, amount, {from: masterMinterAccount}); + await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); var customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)} ] await checkVariables([token], [customVars]); - await token.mint(minterAccount, 50, {from: minterAccount}); + await token.mint(Accounts.minterAccount, 50, {from: Accounts.minterAccount}); customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - 50)}, {'variable': 'balances.minterAccount', 'expectedValue': new BigNumber(50)}, {'variable': 'totalSupply', 'expectedValue': new BigNumber(50)} ] - await expectRevert(token.burn(50, {from: arbitraryAccount})); + await expectRevert(token.burn(50, {from: Accounts.arbitraryAccount})); await checkVariables([token], [customVars]); }); it('nt036 should fail to burn after removeMinter', async function () { - await token.configureMinter(minterAccount, amount, {from: masterMinterAccount}); + await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); var customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)} ] await checkVariables([token], [customVars]); - await token.mint(minterAccount, 50, {from: minterAccount}); + await token.mint(Accounts.minterAccount, 50, {from: Accounts.minterAccount}); customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - 50)}, @@ -531,63 +525,63 @@ async function run_tests(newToken, accounts) { ] await checkVariables([token], [customVars]); - await token.removeMinter(minterAccount, {from: masterMinterAccount}); + await token.removeMinter(Accounts.minterAccount, {from: Accounts.masterMinterAccount}); customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': false}, {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(0)}, {'variable': 'balances.minterAccount', 'expectedValue': new BigNumber(50)}, {'variable': 'totalSupply', 'expectedValue': new BigNumber(50)} ] - await expectRevert(token.burn(50, {from: minterAccount})); + await expectRevert(token.burn(50, {from: Accounts.minterAccount})); await checkVariables([token], [customVars]); }); // Update functions it('nt050 should fail to updatePauser when sender is not owner', async function () { - await expectRevert(token.updatePauser(arbitraryAccount, {from: pauserAccount})); + await expectRevert(token.updatePauser(Accounts.arbitraryAccount, {from: Accounts.pauserAccount})); await checkVariables([token], [[]]); }); it('nt049 should fail to updateMasterMinter when sender is not owner', async function () { - await expectRevert(token.updateMasterMinter(arbitraryAccount, {from: pauserAccount})); + await expectRevert(token.updateMasterMinter(Accounts.arbitraryAccount, {from: Accounts.pauserAccount})); await checkVariables([token], [[]]); }); it('nt048 should fail to updateBlacklister when sender is not owner', async function () { - await expectRevert(token.updateBlacklister(arbitraryAccount, {from: pauserAccount})); + await expectRevert(token.updateBlacklister(Accounts.arbitraryAccount, {from: Accounts.pauserAccount})); await checkVariables([token], [[]]); }); // Pause and Unpause it('nt040 should fail to pause when sender is not pauser', async function () { - await expectRevert(token.pause({from: arbitraryAccount})); + await expectRevert(token.pause({from: Accounts.arbitraryAccount})); await checkVariables([token], [[]]); }); it('nt041 should fail to unpause when sender is not pauser', async function () { - await token.pause({from: pauserAccount}); + await token.pause({from: Accounts.pauserAccount}); customVars = [ {'variable': 'paused', 'expectedValue': true} ] - await expectRevert(token.unpause({from: arbitraryAccount})); + await expectRevert(token.unpause({from: Accounts.arbitraryAccount})); await checkVariables([token], [customVars]); }); // Blacklist and Unblacklist it('nt042 should fail to blacklist when sender is not blacklister', async function () { - await expectRevert(token.blacklist(tokenOwnerAccount, {from: arbitraryAccount})); + await expectRevert(token.blacklist(Accounts.tokenOwnerAccount, {from: Accounts.arbitraryAccount})); await checkVariables([token], [[]]); }); it('nt043 should fail to unblacklist when sender is not blacklister', async function () { - await token.blacklist(arbitraryAccount, {from: blacklisterAccount}); + await token.blacklist(Accounts.arbitraryAccount, {from: Accounts.blacklisterAccount}); customVars = [ {'variable': 'isAccountBlacklisted.arbitraryAccount', 'expectedValue': true} ] - await expectRevert(token.unBlacklist(arbitraryAccount, {from: tokenOwnerAccount})); + await expectRevert(token.unBlacklist(Accounts.arbitraryAccount, {from: Accounts.tokenOwnerAccount})); await checkVariables([token], [customVars]); }); @@ -605,13 +599,13 @@ async function run_tests(newToken, accounts) { ]; // expectRevert on transferOwnership with wrong sender - await expectRevert(newToken.transferOwnership(arbitraryAccount, {from: arbitraryAccount2})); + await expectRevert(newToken.transferOwnership(Accounts.arbitraryAccount, {from: Accounts.arbitraryAccount2})); await checkVariables([newToken], [newToken_result]); }); it('nt055 should fail to mint when amount = 0', async function() { - await token.configureMinter(minterAccount, amount, {from: masterMinterAccount}); - await expectRevert(token.mint(pauserAccount, 0, {from: minterAccount})); + await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); + await expectRevert(token.mint(Accounts.pauserAccount, 0, {from: Accounts.minterAccount})); var customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, @@ -621,9 +615,9 @@ async function run_tests(newToken, accounts) { }); it('nt056 should fail to burn when amount = 0', async function() { - await token.configureMinter(minterAccount, amount, {from: masterMinterAccount}); - await token.mint(minterAccount, amount, {from: minterAccount}); - await expectRevert(token.burn(0, {from: minterAccount})); + await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); + await token.mint(Accounts.minterAccount, amount, {from: Accounts.minterAccount}); + await expectRevert(token.burn(0, {from: Accounts.minterAccount})); var customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, {'variable': 'balances.minterAccount', 'expectedValue': new BigNumber(amount)}, @@ -633,47 +627,47 @@ async function run_tests(newToken, accounts) { }); it('nt064 transferOwnership should fail on 0x0', async function () { - await expectRevert(token.transferOwnership(longZero, { from: tokenOwnerAccount })); - await expectRevert(token.transferOwnership(shortZero, { from: tokenOwnerAccount })); + await expectRevert(token.transferOwnership(longZero, { from: Accounts.tokenOwnerAccount })); + await expectRevert(token.transferOwnership(shortZero, { from: Accounts.tokenOwnerAccount })); }); it('nt057 updateMasterMinter should fail on 0x0', async function () { - await expectRevert(token.updateMasterMinter(longZero, { from: tokenOwnerAccount })); - await expectRevert(token.updateMasterMinter(shortZero, { from: tokenOwnerAccount })); + await expectRevert(token.updateMasterMinter(longZero, { from: Accounts.tokenOwnerAccount })); + await expectRevert(token.updateMasterMinter(shortZero, { from: Accounts.tokenOwnerAccount })); }); it('nt058 updatePauser should fail on 0x0', async function () { - await expectRevert(token.updatePauser(longZero, { from: tokenOwnerAccount })); - await expectRevert(token.updatePauser(shortZero, { from: tokenOwnerAccount })); + await expectRevert(token.updatePauser(longZero, { from: Accounts.tokenOwnerAccount })); + await expectRevert(token.updatePauser(shortZero, { from: Accounts.tokenOwnerAccount })); }); it('nt059 updateBlacklister should fail on 0x0', async function () { - await expectRevert(token.updateBlacklister(longZero, { from: tokenOwnerAccount })); - await expectRevert(token.updateBlacklister(shortZero, { from: tokenOwnerAccount })); + await expectRevert(token.updateBlacklister(longZero, { from: Accounts.tokenOwnerAccount })); + await expectRevert(token.updateBlacklister(shortZero, { from: Accounts.tokenOwnerAccount })); }); it('nt060 initialize should fail when _masterMinter is 0x0', async function () { rawToken = await newToken(); - await expectRevert(customInitializeTokenWithProxy(rawToken, longZero, pauserAccount, blacklisterAccount, tokenOwnerAccount)); - await expectRevert(customInitializeTokenWithProxy(rawToken, shortZero, pauserAccount, blacklisterAccount, tokenOwnerAccount)); + await expectRevert(customInitializeTokenWithProxy(rawToken, longZero, Accounts.pauserAccount, Accounts.blacklisterAccount, Accounts.tokenOwnerAccount)); + await expectRevert(customInitializeTokenWithProxy(rawToken, shortZero, Accounts.pauserAccount, Accounts.blacklisterAccount, Accounts.tokenOwnerAccount)); }); it('nt061 initialize should fail when _pauser is 0x0', async function () { rawToken = await newToken(); - await expectRevert(customInitializeTokenWithProxy(rawToken, masterMinterAccount, longZero, blacklisterAccount, tokenOwnerAccount)); - await expectRevert(customInitializeTokenWithProxy(rawToken, masterMinterAccount, shortZero, blacklisterAccount, tokenOwnerAccount)); + await expectRevert(customInitializeTokenWithProxy(rawToken, Accounts.masterMinterAccount, longZero, Accounts.blacklisterAccount, Accounts.tokenOwnerAccount)); + await expectRevert(customInitializeTokenWithProxy(rawToken, Accounts.masterMinterAccount, shortZero, Accounts.blacklisterAccount, Accounts.tokenOwnerAccount)); }); it('nt062 initialize should fail when _blacklister is 0x0', async function () { rawToken = await newToken(); - await expectRevert(customInitializeTokenWithProxy(rawToken, masterMinterAccount, pauserAccount, longZero, tokenOwnerAccount)); - await expectRevert(customInitializeTokenWithProxy(rawToken, masterMinterAccount, pauserAccount, shortZero, tokenOwnerAccount)); + await expectRevert(customInitializeTokenWithProxy(rawToken, Accounts.masterMinterAccount, Accounts.pauserAccount, longZero, Accounts.tokenOwnerAccount)); + await expectRevert(customInitializeTokenWithProxy(rawToken, Accounts.masterMinterAccount, Accounts.pauserAccount, shortZero, Accounts.tokenOwnerAccount)); }); it('nt063 initialize should fail when _owner is 0x0', async function () { rawToken = await newToken(); - await expectRevert(customInitializeTokenWithProxy(rawToken, masterMinterAccount, pauserAccount, blacklisterAccount, longZero)); - await expectRevert(customInitializeTokenWithProxy(rawToken, masterMinterAccount, pauserAccount, blacklisterAccount, shortZero)); + await expectRevert(customInitializeTokenWithProxy(rawToken, Accounts.masterMinterAccount, Accounts.pauserAccount, Accounts.blacklisterAccount, longZero)); + await expectRevert(customInitializeTokenWithProxy(rawToken, Accounts.masterMinterAccount, Accounts.pauserAccount, Accounts.blacklisterAccount, shortZero)); }); } diff --git a/test/Pausable.test.js b/test/Pausable.test.js index b9db8621c..adb7797e8 100644 --- a/test/Pausable.test.js +++ b/test/Pausable.test.js @@ -4,11 +4,9 @@ var Pausable = artifacts.require('Pausable'); var tokenUtils = require('./TokenTestUtils'); var BigNumber = require('bignumber.js'); var expectRevert = tokenUtils.expectRevert; -var deployerAccount = tokenUtils.deployerAccount; -var arbitraryAccount = tokenUtils.arbitraryAccount; -var pauserAccount = tokenUtils.pauserAccount; -var tokenOwnerAccount = tokenUtils.tokenOwnerAccount; +var AccountUtils = require('./AccountUtils'); +var Accounts = AccountUtils.Accounts; const should = require('chai') .use(require('chai-as-promised')) @@ -19,64 +17,64 @@ contract('PausableTests', function (accounts) { var pause; beforeEach(async function checkBefore() { pause = await Pausable.new(); - await pause.updatePauser(pauserAccount); + await pause.updatePauser(Accounts.pauserAccount); }); it('constructor owner', async function () { var actualOwner = await pause.owner.call(); - assert.equal(deployerAccount, actualOwner, "wrong owner"); + assert.equal(Accounts.deployerAccount, actualOwner, "wrong owner"); }); it('constructor pauser', async function () { var actualOwner = await pause.pauser.call(); - assert.equal(pauserAccount, actualOwner, "wrong pauser"); + assert.equal(Accounts.pauserAccount, actualOwner, "wrong pauser"); }); it('paused after pausing', async function () { await checkUnPaused(); - await pause.pause({from: pauserAccount}); + await pause.pause({from: Accounts.pauserAccount}); await checkPaused(); // should stay paused even if we call it again - await pause.pause({from: pauserAccount}); + await pause.pause({from: Accounts.pauserAccount}); await checkPaused(); - await pause.unpause({from: pauserAccount}); + await pause.unpause({from: Accounts.pauserAccount}); await checkUnPaused(); }); it('update pauser', async function() { // pause from original pauser - await pause.pause({from: pauserAccount}); + await pause.pause({from: Accounts.pauserAccount}); await checkPaused("should have paused from original pauser account"); - await pause.updatePauser(arbitraryAccount, {from: deployerAccount}); + await pause.updatePauser(Accounts.arbitraryAccount, {from: Accounts.deployerAccount}); var newPauser = await pause.pauser.call(); - assert.equal(arbitraryAccount, newPauser); + assert.equal(Accounts.arbitraryAccount, newPauser); // double check we're still paused await checkPaused("should still be paused after changing pauser"); - await pause.unpause({from: arbitraryAccount}); + await pause.unpause({from: Accounts.arbitraryAccount}); await checkUnPaused(); //original pauser shouldn't work anymore - await expectRevert(pause.pause({from:pauserAccount})); + await expectRevert(pause.pause({from:Accounts.pauserAccount})); }); it('fail to update pauser from wrong account', async function() { - await expectRevert(pause.updatePauser(arbitraryAccount, {from:arbitraryAccount})); + await expectRevert(pause.updatePauser(Accounts.arbitraryAccount, {from:Accounts.arbitraryAccount})); }); it('fail to pause from wrong account', async function() { - await expectRevert(pause.pause({from:arbitraryAccount})); + await expectRevert(pause.pause({from:Accounts.arbitraryAccount})); }); it('fail to unpause from wrong account', async function() { - await pause.pause({from: pauserAccount}); + await pause.pause({from: Accounts.pauserAccount}); await checkPaused(); - await expectRevert(pause.unpause({from:arbitraryAccount})); + await expectRevert(pause.unpause({from:Accounts.arbitraryAccount})); }); async function checkPaused(msg ) { diff --git a/test/PositiveTests.js b/test/PositiveTests.js index 8cd3afcc2..b0b26790c 100644 --- a/test/PositiveTests.js +++ b/test/PositiveTests.js @@ -11,19 +11,13 @@ var name = tokenUtils.name; var symbol = tokenUtils.symbol; var currency = tokenUtils.currency; var decimals = tokenUtils.decimals; -var deployerAccount = tokenUtils.deployerAccount; -var arbitraryAccount = tokenUtils.arbitraryAccount; -var arbitraryAccount2 = tokenUtils.arbitraryAccount2; -var upgraderAccount = tokenUtils.upgraderAccount; -var tokenOwnerAccount = tokenUtils.tokenOwnerAccount; -var blacklisterAccount = tokenUtils.blacklisterAccount; -var masterMinterAccount = tokenUtils.masterMinterAccount; -var minterAccount = tokenUtils.minterAccount; -var pauserAccount = tokenUtils.pauserAccount; -var proxyOwnerAccount = tokenUtils.proxyOwnerAccount; + var initializeTokenWithProxy = tokenUtils.initializeTokenWithProxy; var FiatToken = tokenUtils.FiatToken; +var AccountUtils = require('./AccountUtils'); +var Accounts = AccountUtils.Accounts; + var amount = 100; async function run_tests(newToken, accounts) { @@ -43,23 +37,23 @@ async function run_tests(newToken, accounts) { // Pause and Unpause it('pt011 should pause and set paused to true', async function () { - await token.pause({ from: pauserAccount }); + await token.pause({ from: Accounts.pauserAccount }); var customVars = [{ 'variable': 'paused', 'expectedValue': true }]; await checkVariables([token], [customVars]); }); it('pt006 should unpause and set paused to false', async function () { - await token.pause({ from: pauserAccount }); + await token.pause({ from: Accounts.pauserAccount }); var customVars = [{ 'variable': 'paused', 'expectedValue': true }]; await checkVariables([token], [customVars]); - await token.unpause({ from: pauserAccount }); + await token.unpause({ from: Accounts.pauserAccount }); await checkVariables([token], [[]]); }); // Approve it('pt020 should approve a spend and set allowed amount', async function () { - await token.approve(minterAccount, amount, { from: arbitraryAccount }); + await token.approve(Accounts.minterAccount, amount, { from: Accounts.arbitraryAccount }); var customVars = [ { 'variable': 'allowance.arbitraryAccount.minterAccount', 'expectedValue': new BigNumber(amount) } ]; @@ -69,7 +63,7 @@ async function run_tests(newToken, accounts) { // Blacklist and Unblacklist it('pt019 should blacklist and set blacklisted to true', async function () { - await token.blacklist(arbitraryAccount, { from: blacklisterAccount }); + await token.blacklist(Accounts.arbitraryAccount, { from: Accounts.blacklisterAccount }); var customVars = [ { 'variable': 'isAccountBlacklisted.arbitraryAccount', 'expectedValue': true } ]; @@ -77,20 +71,20 @@ async function run_tests(newToken, accounts) { }); it('pt018 should blacklist and set blacklisted to true, then unblacklist and set blacklisted to false', async function () { - await token.blacklist(arbitraryAccount, { from: blacklisterAccount }); + await token.blacklist(Accounts.arbitraryAccount, { from: Accounts.blacklisterAccount }); var customVars = [ { 'variable': 'isAccountBlacklisted.arbitraryAccount', 'expectedValue': true } ]; await checkVariables([token], [customVars]); - await token.unBlacklist(arbitraryAccount, { from: blacklisterAccount }); + await token.unBlacklist(Accounts.arbitraryAccount, { from: Accounts.blacklisterAccount }); await checkVariables([token], [[]]); }); // Configure minter it('pt015 should configureMinter, setting the minter to true and mintingAllowance to amount', async function () { - await token.configureMinter(minterAccount, amount, { from: masterMinterAccount }); + await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); var customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount) } @@ -103,14 +97,14 @@ async function run_tests(newToken, accounts) { it('pt012 should mint the amount, increasing balance of recipient by amount, increasing total supply by amount, and decreasing minterAllowed by amount', async function () { var mintAmount = 50; - await token.configureMinter(minterAccount, amount, { from: masterMinterAccount }); + await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); var customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount) } ]; await checkVariables([token], [customVars]); - await token.mint(arbitraryAccount, mintAmount, { from: minterAccount }); + await token.mint(Accounts.arbitraryAccount, mintAmount, { from: Accounts.minterAccount }); customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - mintAmount) }, @@ -124,8 +118,8 @@ async function run_tests(newToken, accounts) { var mintAmount = 11; var burnAmount = 10; - await token.configureMinter(minterAccount, mintAmount, { from: masterMinterAccount }); - await token.mint(minterAccount, mintAmount, { from: minterAccount }); + await token.configureMinter(Accounts.minterAccount, mintAmount, { from: Accounts.masterMinterAccount }); + await token.mint(Accounts.minterAccount, mintAmount, { from: Accounts.minterAccount }); var setup = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(0) }, @@ -134,7 +128,7 @@ async function run_tests(newToken, accounts) { ]; await checkVariables([token], [setup]); - await token.burn(burnAmount, { from: minterAccount }); + await token.burn(burnAmount, { from: Accounts.minterAccount }); var afterBurn = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(0) }, @@ -149,8 +143,8 @@ async function run_tests(newToken, accounts) { it('pt010 should removeMinter, setting the minter to false and minterAllowed to 0', async function () { let mintAmount = 11; - await token.configureMinter(minterAccount, amount, { from: masterMinterAccount }); - await token.mint(arbitraryAccount, mintAmount, { from: minterAccount }) + await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); + await token.mint(Accounts.arbitraryAccount, mintAmount, { from: Accounts.minterAccount }) var customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - mintAmount) }, @@ -159,7 +153,7 @@ async function run_tests(newToken, accounts) { ]; await checkVariables([token], [customVars]); - await token.removeMinter(minterAccount, { from: masterMinterAccount }); + await token.removeMinter(Accounts.minterAccount, { from: Accounts.masterMinterAccount }); customVars = [ { 'variable': 'balances.arbitraryAccount', 'expectedValue': new BigNumber(mintAmount) }, { 'variable': 'totalSupply', 'expectedValue': new BigNumber(mintAmount) } @@ -172,14 +166,14 @@ async function run_tests(newToken, accounts) { it('pt008 should transfer, reducing sender balance by amount and increasing recipient balance by amount', async function () { let mintAmount = 50; - await token.configureMinter(minterAccount, amount, { from: masterMinterAccount }); + await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); var customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount) } ]; await checkVariables([token], [customVars]); - await token.mint(arbitraryAccount, mintAmount, { from: minterAccount }); + await token.mint(Accounts.arbitraryAccount, mintAmount, { from: Accounts.minterAccount }); customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - mintAmount) }, @@ -188,7 +182,7 @@ async function run_tests(newToken, accounts) { ]; await checkVariables([token], [customVars]); - await token.transfer(pauserAccount, mintAmount, { from: arbitraryAccount }); + await token.transfer(Accounts.pauserAccount, mintAmount, { from: Accounts.arbitraryAccount }); customVars = [ { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - mintAmount) }, { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, @@ -202,14 +196,14 @@ async function run_tests(newToken, accounts) { it('pt007 should transferFrom, reducing sender balance by amount and increasing recipient balance by amount', async function () { let mintAmount = 50; - await token.configureMinter(minterAccount, amount, { from: masterMinterAccount }); + await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); var customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount) } ]; await checkVariables([token], [customVars]); - await token.mint(arbitraryAccount, mintAmount, { from: minterAccount }); + await token.mint(Accounts.arbitraryAccount, mintAmount, { from: Accounts.minterAccount }); customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - mintAmount) }, @@ -218,8 +212,8 @@ async function run_tests(newToken, accounts) { ]; await checkVariables([token], [customVars]); - await token.approve(masterMinterAccount, mintAmount, { from: arbitraryAccount }); - await token.transferFrom(arbitraryAccount, pauserAccount, mintAmount, { from: masterMinterAccount }); + await token.approve(Accounts.masterMinterAccount, mintAmount, { from: Accounts.arbitraryAccount }); + await token.transferFrom(Accounts.arbitraryAccount, Accounts.pauserAccount, mintAmount, { from: Accounts.masterMinterAccount }); customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - mintAmount) }, @@ -233,25 +227,25 @@ async function run_tests(newToken, accounts) { // Update methods it('pt004 should updateMasterMinter', async function () { - await token.updateMasterMinter(arbitraryAccount, { from: tokenOwnerAccount }); + await token.updateMasterMinter(Accounts.arbitraryAccount, { from: Accounts.tokenOwnerAccount }); var result = [ - { 'variable': 'masterMinter', 'expectedValue': arbitraryAccount } + { 'variable': 'masterMinter', 'expectedValue': Accounts.arbitraryAccount } ]; await checkVariables([token], [result]); }); it('pt005 should updateBlacklister', async function () { - await token.updateBlacklister(arbitraryAccount, { from: tokenOwnerAccount }); + await token.updateBlacklister(Accounts.arbitraryAccount, { from: Accounts.tokenOwnerAccount }); var result = [ - { 'variable': 'blacklister', 'expectedValue': arbitraryAccount } + { 'variable': 'blacklister', 'expectedValue': Accounts.arbitraryAccount } ]; await checkVariables([token], [result]); }); it('pt003 should updatePauser', async function () { - await token.updatePauser(arbitraryAccount, { from: tokenOwnerAccount }); + await token.updatePauser(Accounts.arbitraryAccount, { from: Accounts.tokenOwnerAccount }); var result = [ - { 'variable': 'pauser', 'expectedValue': arbitraryAccount } + { 'variable': 'pauser', 'expectedValue': Accounts.arbitraryAccount } ]; await checkVariables([token], [result]); }); @@ -259,9 +253,9 @@ async function run_tests(newToken, accounts) { // Transfer Ownership it('pt009 should set owner to _newOwner', async function () { - await token.transferOwnership(arbitraryAccount, { from: tokenOwnerAccount }); + await token.transferOwnership(Accounts.arbitraryAccount, { from: Accounts.tokenOwnerAccount }); var result = [ - { 'variable': 'tokenOwner', 'expectedValue': arbitraryAccount } + { 'variable': 'tokenOwner', 'expectedValue': Accounts.arbitraryAccount } ]; await checkVariables([token], [result]); }); diff --git a/test/ProxyNegativeTests.js b/test/ProxyNegativeTests.js index dfd8e833a..509293c3a 100644 --- a/test/ProxyNegativeTests.js +++ b/test/ProxyNegativeTests.js @@ -12,16 +12,6 @@ var name = tokenUtils.name; var symbol = tokenUtils.symbol; var currency = tokenUtils.currency; var decimals = tokenUtils.decimals; -var deployerAccount = tokenUtils.deployerAccount; -var arbitraryAccount = tokenUtils.arbitraryAccount; -var arbitraryAccount2 = tokenUtils.arbitraryAccount2; -var upgraderAccount = tokenUtils.upgraderAccount; -var tokenOwnerAccount = tokenUtils.tokenOwnerAccount; -var blacklisterAccount = tokenUtils.blacklisterAccount; -var masterMinterAccount = tokenUtils.masterMinterAccount; -var minterAccount = tokenUtils.minterAccount; -var pauserAccount = tokenUtils.pauserAccount; -var proxyOwnerAccount = tokenUtils.proxyOwnerAccount; var initializeTokenWithProxy = tokenUtils.initializeTokenWithProxy; var upgradeTo = tokenUtils.upgradeTo; var encodeCall = tokenUtils.encodeCall; @@ -30,6 +20,9 @@ var FiatToken = tokenUtils.FiatToken; var UpgradedFiatToken = tokenUtils.UpgradedFiatToken; var UpgradedFiatTokenNewFields = tokenUtils.UpgradedFiatTokenNewFields; +var AccountUtils = require('./AccountUtils'); +var Accounts = AccountUtils.Accounts; + var amount = 100; async function run_tests(newToken, accounts) { @@ -43,15 +36,15 @@ async function run_tests(newToken, accounts) { }); it('nut002 should fail to switch adminAccount with non-adminAccount as caller', async function () { - await expectRevert(proxy.changeAdmin(masterMinterAccount, {from: masterMinterAccount})); - assert.equal(await proxy.admin({from: proxyOwnerAccount}), proxyOwnerAccount); + await expectRevert(proxy.changeAdmin(Accounts.masterMinterAccount, {from: Accounts.masterMinterAccount})); + assert.equal(await proxy.admin({from: Accounts.proxyOwnerAccount}), Accounts.proxyOwnerAccount); customVars = []; await checkVariables([token], [customVars]); }); it('nut003 should fail to upgradeTo to null contract address', async function () { var upgradedToken = await UpgradedFiatToken.new(); - await expectRevert(proxy.upgradeTo("0x0", token, {from: proxyOwnerAccount})); + await expectRevert(proxy.upgradeTo("0x0", token, {from: Accounts.proxyOwnerAccount})); customVars = []; await checkVariables([token], [customVars]); @@ -60,37 +53,37 @@ async function run_tests(newToken, accounts) { it('nut004 should fail to upgradeToAndCall to null contract address', async function () { var upgradedToken = await UpgradedFiatToken.new(); const initializeData = encodeCall('pauser', [], []); - await expectRevert(proxy.upgradeToAndCall("0x0", initializeData, { from: proxyOwnerAccount })); + await expectRevert(proxy.upgradeToAndCall("0x0", initializeData, { from: Accounts.proxyOwnerAccount })); customVars = []; await checkVariables([token], [customVars]); }); it('nut005 should fail to initialize contract twice', async function () { - await expectRevert(token.initialize(name, symbol, currency, decimals, masterMinterAccount, pauserAccount, blacklisterAccount, tokenOwnerAccount)); + await expectRevert(token.initialize(name, symbol, currency, decimals, Accounts.masterMinterAccount, Accounts.pauserAccount, Accounts.blacklisterAccount, Accounts.tokenOwnerAccount)); customVars = []; await checkVariables([token], [customVars]); }); it('nut006 should fail to call contract function with adminAccount', async function () { - await expectRevert(token.allowance(minterAccount, arbitraryAccount, { from: proxyOwnerAccount })); + await expectRevert(token.allowance(Accounts.minterAccount, Accounts.arbitraryAccount, { from: Accounts.proxyOwnerAccount })); customVars = []; await checkVariables([token], [customVars]); }); it('nut007 should fail to call proxy function with non-adminAccount', async function () { - await expectRevert(proxy.admin({ from: masterMinterAccount })); + await expectRevert(proxy.admin({ from: Accounts.masterMinterAccount })); customVars = []; await checkVariables([token], [customVars]); }); it('nut008 shoud fail to update proxy storage if state-changing function called directly in FiatToken', async function () { - await rawToken.initialize(name, symbol, currency, decimals, masterMinterAccount, pauserAccount, blacklisterAccount, tokenOwnerAccount); - assert.equal(await rawToken.pauser(), pauserAccount); - await rawToken.updatePauser(masterMinterAccount, {from: tokenOwnerAccount}); - assert.equal(await rawToken.pauser(), masterMinterAccount); + await rawToken.initialize(name, symbol, currency, decimals, Accounts.masterMinterAccount, Accounts.pauserAccount, Accounts.blacklisterAccount, Accounts.tokenOwnerAccount); + assert.equal(await rawToken.pauser(), Accounts.pauserAccount); + await rawToken.updatePauser(Accounts.masterMinterAccount, {from: Accounts.tokenOwnerAccount}); + assert.equal(await rawToken.pauser(), Accounts.masterMinterAccount); customVars = []; await checkVariables([token], [customVars]); @@ -98,9 +91,9 @@ async function run_tests(newToken, accounts) { it('nut009 should fail to call upgradeTo with non-adminAccount', async function () { var upgradedToken = await UpgradedFiatToken.new(); - await expectRevert(proxy.upgradeTo(upgradedToken.address, {from:masterMinterAccount})); + await expectRevert(proxy.upgradeTo(upgradedToken.address, {from:Accounts.masterMinterAccount})); var finalToken = FiatToken.at(proxy.address); - var implementation = await proxy.implementation({from: proxyOwnerAccount}); + var implementation = await proxy.implementation({from: Accounts.proxyOwnerAccount}); finalToken.proxiedTokenAddress = implementation; customVars = []; @@ -109,10 +102,10 @@ async function run_tests(newToken, accounts) { it('nut010 should fail to call updateToAndCall with non-adminAccount', async function () { var upgradedToken = await UpgradedFiatTokenNewFields.new(); - const initializeData = encodeCall('initialize', ['bool', 'address', 'uint256'], [true, pauserAccount, 12]); - await expectRevert(proxy.upgradeToAndCall(upgradedToken.address, initializeData, { from: masterMinterAccount })); + const initializeData = encodeCall('initialize', ['bool', 'address', 'uint256'], [true, Accounts.pauserAccount, 12]); + await expectRevert(proxy.upgradeToAndCall(upgradedToken.address, initializeData, { from: Accounts.masterMinterAccount })); var finalToken = FiatToken.at(proxy.address); - var implementation = await proxy.implementation({from: proxyOwnerAccount}); + var implementation = await proxy.implementation({from: Accounts.proxyOwnerAccount}); finalToken.proxiedTokenAddress = implementation; customVars = []; @@ -122,13 +115,13 @@ async function run_tests(newToken, accounts) { it('nut011 should fail to upgradeToAndCall with initialize (already set variables)', async function () { let mintAmount = 50; - await token.configureMinter(minterAccount, amount, { from: masterMinterAccount }); - await token.mint(arbitraryAccount, mintAmount, { from: minterAccount }); - await token.transfer(pauserAccount, mintAmount, { from: arbitraryAccount }); + await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); + await token.mint(Accounts.arbitraryAccount, mintAmount, { from: Accounts.minterAccount }); + await token.transfer(Accounts.pauserAccount, mintAmount, { from: Accounts.arbitraryAccount }); var upgradedToken = await UpgradedFiatTokenNewFields.new(); - var data = encodeCall('initialize', ['string','string','string','uint8','address','address','address','address','bool','address','uint256'], [name, symbol, currency, decimals, masterMinterAccount, pauserAccount, blacklisterAccount, tokenOwnerAccount, true, pauserAccount, 12]); - await expectRevert(proxy.upgradeToAndCall(upgradedToken.address, data, { from: proxyOwnerAccount })); + var data = encodeCall('initialize', ['string','string','string','uint8','address','address','address','address','bool','address','uint256'], [name, symbol, currency, decimals, Accounts.masterMinterAccount, Accounts.pauserAccount, Accounts.blacklisterAccount, Accounts.tokenOwnerAccount, true, Accounts.pauserAccount, 12]); + await expectRevert(proxy.upgradeToAndCall(upgradedToken.address, data, { from: Accounts.proxyOwnerAccount })); customVars = [ { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - mintAmount) }, diff --git a/test/ProxyPositiveTests.js b/test/ProxyPositiveTests.js index b06f705a6..e03fea7eb 100644 --- a/test/ProxyPositiveTests.js +++ b/test/ProxyPositiveTests.js @@ -11,19 +11,7 @@ var name = tokenUtils.name; var symbol = tokenUtils.symbol; var currency = tokenUtils.currency; var decimals = tokenUtils.decimals; -var deployerAccount = tokenUtils.deployerAccount; -var arbitraryAccount = tokenUtils.arbitraryAccount; -var arbitraryAccount2 = tokenUtils.arbitraryAccount2; -var upgraderAccount = tokenUtils.upgraderAccount; -var upgraderAccountPrivateKey = tokenUtils.upgraderAccountPrivateKey; -var proxyOwnerAccountPrivateKey = tokenUtils.proxyOwnerAccountPrivateKey; -var tokenOwnerAccount = tokenUtils.tokenOwnerAccount; -var blacklisterAccount = tokenUtils.blacklisterAccount; -var masterMinterAccount = tokenUtils.masterMinterAccount; -var masterMinterAccountPrivateKey = tokenUtils.masterMinterAccountPrivateKey; -var minterAccount = tokenUtils.minterAccount; -var pauserAccount = tokenUtils.pauserAccount; -var proxyOwnerAccount = tokenUtils.proxyOwnerAccount; + var initializeTokenWithProxy = tokenUtils.initializeTokenWithProxy; var upgradeTo = tokenUtils.upgradeTo; var encodeCall = tokenUtils.encodeCall; @@ -39,6 +27,10 @@ var abiUtils = require('./ABIUtils'); var makeRawTransaction = abiUtils.makeRawTransaction; var sendRawTransaction = abiUtils.sendRawTransaction; +var AccountUtils = require('./AccountUtils'); +var Accounts = AccountUtils.Accounts; +var AccountPrivateKeys = AccountUtils.AccountPrivateKeys; + var amount = 100; async function run_tests(newToken, accounts) { @@ -54,12 +46,12 @@ async function run_tests(newToken, accounts) { it('upt001 should upgradeTo new contract and preserve data field values', async function () { let mintAmount = 50; - await token.configureMinter(minterAccount, amount, { from: masterMinterAccount }); - await token.mint(arbitraryAccount, mintAmount, { from: minterAccount }); - await token.transfer(pauserAccount, mintAmount, { from: arbitraryAccount }); + await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); + await token.mint(Accounts.arbitraryAccount, mintAmount, { from: Accounts.minterAccount }); + await token.transfer(Accounts.pauserAccount, mintAmount, { from: Accounts.arbitraryAccount }); var upgradedToken = await UpgradedFiatToken.new(); - var tokenConfig = await upgradeTo(proxy, upgradedToken, proxyOwnerAccount); + var tokenConfig = await upgradeTo(proxy, upgradedToken, Accounts.proxyOwnerAccount); var newToken = tokenConfig.token; customVars = [ @@ -76,19 +68,19 @@ async function run_tests(newToken, accounts) { it('upt002 should upgradeToandCall to contract with new data fields set on initVX and ensure new fields are correct and old data is preserved', async function () { let mintAmount = 50; - await token.configureMinter(minterAccount, amount, { from: masterMinterAccount }); - await token.mint(arbitraryAccount, mintAmount, { from: minterAccount }); - await token.transfer(pauserAccount, mintAmount, { from: arbitraryAccount }); + await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); + await token.mint(Accounts.arbitraryAccount, mintAmount, { from: Accounts.minterAccount }); + await token.transfer(Accounts.pauserAccount, mintAmount, { from: Accounts.arbitraryAccount }); var upgradedToken = await UpgradedFiatTokenNewFields.new(); - const initializeData = encodeCall('initV2', ['bool', 'address', 'uint256'], [true, pauserAccount, 12]); - await proxy.upgradeToAndCall(upgradedToken.address, initializeData, { from: proxyOwnerAccount }) + const initializeData = encodeCall('initV2', ['bool', 'address', 'uint256'], [true, Accounts.pauserAccount, 12]); + await proxy.upgradeToAndCall(upgradedToken.address, initializeData, { from: Accounts.proxyOwnerAccount }) newProxiedToken = await UpgradedFiatTokenNewFields.at(proxy.address); assert.equal(newProxiedToken.address, proxy.address); assert.notEqual(newProxiedToken.address, upgradedToken.address); assert.equal(await newProxiedToken.newBool(), true); - assert.equal(await newProxiedToken.newAddress(), pauserAccount); + assert.equal(await newProxiedToken.newAddress(), Accounts.pauserAccount); assert.equal((new BigNumber(12)).isEqualTo(await newProxiedToken.newUint()), true); customVars = [ @@ -105,23 +97,23 @@ async function run_tests(newToken, accounts) { it('upt003 should upgradeToAndCall to contract with new data fields set on initVX and new logic and ensure old data preserved,new logic works, and new fields correct', async function () { let mintAmount = 50; - await token.configureMinter(minterAccount, amount, { from: masterMinterAccount }); - await token.mint(arbitraryAccount, mintAmount, { from: minterAccount }); - await token.transfer(pauserAccount, mintAmount, { from: arbitraryAccount }); + await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); + await token.mint(Accounts.arbitraryAccount, mintAmount, { from: Accounts.minterAccount }); + await token.transfer(Accounts.pauserAccount, mintAmount, { from: Accounts.arbitraryAccount }); var upgradedToken = await UpgradedFiatTokenNewFieldsNewLogic.new(); - const initializeData = encodeCall('initV2', ['bool', 'address', 'uint256'], [true, pauserAccount, 12]); - await proxy.upgradeToAndCall(upgradedToken.address, initializeData, { from: proxyOwnerAccount }) + const initializeData = encodeCall('initV2', ['bool', 'address', 'uint256'], [true, Accounts.pauserAccount, 12]); + await proxy.upgradeToAndCall(upgradedToken.address, initializeData, { from: Accounts.proxyOwnerAccount }) newProxiedToken = await UpgradedFiatTokenNewFieldsNewLogic.at(proxy.address); assert.equal(newProxiedToken.address, proxy.address); assert.notEqual(newProxiedToken.address, upgradedToken.address); assert.equal(await newProxiedToken.newBool(), true); - assert.equal(await newProxiedToken.newAddress(), pauserAccount); + assert.equal(await newProxiedToken.newAddress(), Accounts.pauserAccount); assert.equal((new BigNumber(12)).isEqualTo(await newProxiedToken.newUint()), true); - await newProxiedToken.setNewAddress(masterMinterAccount); - assert.equal(await newProxiedToken.newAddress(), masterMinterAccount); + await newProxiedToken.setNewAddress(Accounts.masterMinterAccount); + assert.equal(await newProxiedToken.newAddress(), Accounts.masterMinterAccount); customVars = [ { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - mintAmount) }, @@ -136,16 +128,16 @@ async function run_tests(newToken, accounts) { it('upt008 should deploy upgraded version of contract with new data fields and without previous deployment and ensure new fields correct', async function() { var upgradedToken = await UpgradedFiatTokenNewFields.new(); - const newProxy = await FiatTokenProxy.new(upgradedToken.address, { from: proxyOwnerAccount }); + const newProxy = await FiatTokenProxy.new(upgradedToken.address, { from: Accounts.proxyOwnerAccount }); proxiedToken = await UpgradedFiatTokenNewFields.at(newProxy.address); - var data = encodeCall('initialize', ['string','string','string','uint8','address','address','address','address','bool','address','uint256'], [name, symbol, currency, decimals, masterMinterAccount, pauserAccount, blacklisterAccount, tokenOwnerAccount, true, pauserAccount, 12]); - var upgradeToRawTx = await makeRawTransaction(data, masterMinterAccount, masterMinterAccountPrivateKey, proxiedToken.address) + var data = encodeCall('initialize', ['string','string','string','uint8','address','address','address','address','bool','address','uint256'], [name, symbol, currency, decimals, Accounts.masterMinterAccount, Accounts.pauserAccount, Accounts.blacklisterAccount, Accounts.tokenOwnerAccount, true, Accounts.pauserAccount, 12]); + var upgradeToRawTx = await makeRawTransaction(data, Accounts.masterMinterAccount, AccountPrivateKeys.masterMinterPrivateKey, proxiedToken.address) await sendRawTransaction(upgradeToRawTx); assert.equal(await proxiedToken.newUint(), 12); assert.equal(await proxiedToken.newBool(), true); - assert.equal(await proxiedToken.newAddress(), pauserAccount); + assert.equal(await proxiedToken.newAddress(), Accounts.pauserAccount); customVars = [ { 'variable': 'proxiedTokenAddress', 'expectedValue': upgradedToken.address } @@ -155,19 +147,19 @@ async function run_tests(newToken, accounts) { it('upt010 should deploy upgraded version of contract with new data fields and logic without previous deployment and ensure new logic works, and new fields correct', async function() { var upgradedToken = await UpgradedFiatTokenNewFields.new(); - const newProxy = await FiatTokenProxy.new(upgradedToken.address, { from: proxyOwnerAccount }); + const newProxy = await FiatTokenProxy.new(upgradedToken.address, { from: Accounts.proxyOwnerAccount }); proxiedToken = await UpgradedFiatTokenNewFields.at(newProxy.address); - var data = encodeCall('initialize', ['string','string','string','uint8','address','address','address','address','bool','address','uint256'], [name, symbol, currency, decimals, masterMinterAccount, pauserAccount, blacklisterAccount, tokenOwnerAccount, true, pauserAccount, 12]); - var upgradeToRawTx = await makeRawTransaction(data, masterMinterAccount, masterMinterAccountPrivateKey, proxiedToken.address) + var data = encodeCall('initialize', ['string','string','string','uint8','address','address','address','address','bool','address','uint256'], [name, symbol, currency, decimals, Accounts.masterMinterAccount, Accounts.pauserAccount, Accounts.blacklisterAccount, Accounts.tokenOwnerAccount, true, Accounts.pauserAccount, 12]); + var upgradeToRawTx = await makeRawTransaction(data, Accounts.masterMinterAccount, AccountPrivateKeys.masterMinterPrivateKey, proxiedToken.address) await sendRawTransaction(upgradeToRawTx); assert.equal(await proxiedToken.newUint(), 12); assert.equal(await proxiedToken.newBool(), true); - assert.equal(await proxiedToken.newAddress(), pauserAccount); + assert.equal(await proxiedToken.newAddress(), Accounts.pauserAccount); - await newProxiedToken.setNewAddress(masterMinterAccount); - assert.equal(await newProxiedToken.newAddress(), masterMinterAccount); + await newProxiedToken.setNewAddress(Accounts.masterMinterAccount); + assert.equal(await newProxiedToken.newAddress(), Accounts.masterMinterAccount); customVars = [ { 'variable': 'proxiedTokenAddress', 'expectedValue': upgradedToken.address } @@ -176,9 +168,9 @@ async function run_tests(newToken, accounts) { }); it('upt004 should update proxy adminAccount with previous adminAccount', async function () { - await proxy.changeAdmin(masterMinterAccount, {from: proxyOwnerAccount}); + await proxy.changeAdmin(Accounts.masterMinterAccount, {from: Accounts.proxyOwnerAccount}); customVars = [ - { 'variable': 'upgrader', 'expectedValue': masterMinterAccount}, + { 'variable': 'upgrader', 'expectedValue': Accounts.masterMinterAccount}, ] await checkVariables([token], [customVars]); }); @@ -186,16 +178,16 @@ async function run_tests(newToken, accounts) { it('upt005 should receive Transfer event on transfer when proxied after upgrade', async function () { let mintAmount = 50; - await token.configureMinter(minterAccount, amount, { from: masterMinterAccount }); - await token.mint(arbitraryAccount, mintAmount + 1, { from: minterAccount }); - await token.transfer(pauserAccount, mintAmount, { from: arbitraryAccount }); + await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); + await token.mint(Accounts.arbitraryAccount, mintAmount + 1, { from: Accounts.minterAccount }); + await token.transfer(Accounts.pauserAccount, mintAmount, { from: Accounts.arbitraryAccount }); var upgradedToken = await UpgradedFiatToken.new(); - var tokenConfig = await upgradeTo(proxy, upgradedToken, proxyOwnerAccount); + var tokenConfig = await upgradeTo(proxy, upgradedToken, Accounts.proxyOwnerAccount); var newToken = tokenConfig.token; - transfer = await newToken.transfer(pauserAccount, 1, { from: arbitraryAccount}); - validateTransferEvent(transfer, arbitraryAccount, pauserAccount, 1); + transfer = await newToken.transfer(Accounts.pauserAccount, 1, { from: Accounts.arbitraryAccount}); + validateTransferEvent(transfer, Accounts.arbitraryAccount, Accounts.pauserAccount, 1); customVars = [ { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - mintAmount - 1) }, @@ -209,9 +201,9 @@ async function run_tests(newToken, accounts) { }); it('upt006 should upgrade while paused and upgraded contract should be paused as a result; then unpause should unpause contract', async function () { - await token.pause({from: pauserAccount}); + await token.pause({from: Accounts.pauserAccount}); var upgradedToken = await UpgradedFiatToken.new(); - var tokenConfig = await upgradeTo(proxy, upgradedToken, proxyOwnerAccount); + var tokenConfig = await upgradeTo(proxy, upgradedToken, Accounts.proxyOwnerAccount); var newToken = tokenConfig.token; customVars = [ @@ -220,7 +212,7 @@ async function run_tests(newToken, accounts) { ]; await checkVariables([newToken], [customVars]); - await newToken.unpause({from:pauserAccount}); + await newToken.unpause({from:Accounts.pauserAccount}); customVars2 = [ { 'variable': 'proxiedTokenAddress', 'expectedValue': upgradedToken.address } @@ -231,11 +223,11 @@ async function run_tests(newToken, accounts) { it('upt007 should upgrade contract to original address', async function () { let mintAmount = 50; - await token.configureMinter(minterAccount, amount, { from: masterMinterAccount }); - await token.mint(arbitraryAccount, mintAmount, { from: minterAccount }); - await token.transfer(pauserAccount, mintAmount, { from: arbitraryAccount }); + await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); + await token.mint(Accounts.arbitraryAccount, mintAmount, { from: Accounts.minterAccount }); + await token.transfer(Accounts.pauserAccount, mintAmount, { from: Accounts.arbitraryAccount }); - var tokenConfig = await upgradeTo(proxy, rawToken, proxyOwnerAccount); + var tokenConfig = await upgradeTo(proxy, rawToken, Accounts.proxyOwnerAccount); var sameToken = tokenConfig.token; sameToken.proxiedTokenAddress = rawToken.address; @@ -250,15 +242,15 @@ async function run_tests(newToken, accounts) { }); it('upt009 should check that admin is set correctly by proxy constructor', async function() { - assert.equal(await getAdmin(token), upgraderAccount); + assert.equal(await getAdmin(token), Accounts.upgraderAccount); }); it('upt011 should upgradeToAndCall while paused and upgraded contract should be paused as a result', async function () { - await token.pause({from: pauserAccount}); + await token.pause({from: Accounts.pauserAccount}); var upgradedToken = await UpgradedFiatTokenNewFields.new(); - const initializeData = encodeCall('initV2', ['bool', 'address', 'uint256'], [true, pauserAccount, 12]); - await proxy.upgradeToAndCall(upgradedToken.address, initializeData, { from: proxyOwnerAccount }) + const initializeData = encodeCall('initV2', ['bool', 'address', 'uint256'], [true, Accounts.pauserAccount, 12]); + await proxy.upgradeToAndCall(upgradedToken.address, initializeData, { from: Accounts.proxyOwnerAccount }) newProxiedToken = await UpgradedFiatTokenNewFields.at(proxy.address); assert.equal(newProxiedToken.address, proxy.address); assert.notEqual(newProxiedToken.address, upgradedToken.address); @@ -271,11 +263,11 @@ async function run_tests(newToken, accounts) { }); it('upt012 should upgradeToAndCall while upgrader is blacklisted', async function () { - await token.blacklist(proxyOwnerAccount, {from: blacklisterAccount}); + await token.blacklist(Accounts.proxyOwnerAccount, {from: Accounts.blacklisterAccount}); var upgradedToken = await UpgradedFiatTokenNewFields.new(); - const initializeData = encodeCall('initV2', ['bool', 'address', 'uint256'], [true, pauserAccount, 12]); - await proxy.upgradeToAndCall(upgradedToken.address, initializeData, { from: proxyOwnerAccount }) + const initializeData = encodeCall('initV2', ['bool', 'address', 'uint256'], [true, Accounts.pauserAccount, 12]); + await proxy.upgradeToAndCall(upgradedToken.address, initializeData, { from: Accounts.proxyOwnerAccount }) newProxiedToken = await UpgradedFiatTokenNewFields.at(proxy.address); customVars = [ @@ -287,10 +279,10 @@ async function run_tests(newToken, accounts) { it('upt013 should upgradeToAndCall while new logic is blacklisted', async function () { var upgradedToken = await UpgradedFiatTokenNewFields.new(); - await token.blacklist(upgradedToken.address, {from: blacklisterAccount}); + await token.blacklist(upgradedToken.address, {from: Accounts.blacklisterAccount}); - const initializeData = encodeCall('initV2', ['bool', 'address', 'uint256'], [true, pauserAccount, 12]); - await proxy.upgradeToAndCall(upgradedToken.address, initializeData, { from: proxyOwnerAccount }) + const initializeData = encodeCall('initV2', ['bool', 'address', 'uint256'], [true, Accounts.pauserAccount, 12]); + await proxy.upgradeToAndCall(upgradedToken.address, initializeData, { from: Accounts.proxyOwnerAccount }) newProxiedToken = await UpgradedFiatTokenNewFields.at(proxy.address); customVars = [ @@ -301,9 +293,9 @@ async function run_tests(newToken, accounts) { it('upt014 should upgradeTo while new logic is blacklisted', async function () { var upgradedToken = await UpgradedFiatToken.new(); - await token.blacklist(upgradedToken.address, {from: blacklisterAccount}); + await token.blacklist(upgradedToken.address, {from: Accounts.blacklisterAccount}); - var tokenConfig = await upgradeTo(proxy, upgradedToken, proxyOwnerAccount); + var tokenConfig = await upgradeTo(proxy, upgradedToken, Accounts.proxyOwnerAccount); var newToken = tokenConfig.token; customVars = [ diff --git a/test/TokenTestUtils.js b/test/TokenTestUtils.js index 1dfea915f..28a3ece28 100644 --- a/test/TokenTestUtils.js +++ b/test/TokenTestUtils.js @@ -18,36 +18,10 @@ var UpgradedFiatTokenNewFields = artifacts.require('FiatTokenV2NewFieldsTest'); var UpgradedFiatTokenNewFieldsNewLogic = artifacts.require('FiatTokenV2NewFieldsNewLogicTest'); var FiatTokenProxy = artifacts.require('FiatTokenProxy'); +var AccountUtils = require('./AccountUtils'); +var Accounts = AccountUtils.Accounts; // TODO: test really big numbers Does this still have to be done?? -var deployerAccount = "0x90f8bf6a479f320ead074411a4b0e7944ea8c9c1"; // accounts[0] -var arbitraryAccount = "0xffcf8fdee72ac11b5c542428b35eef5769c409f0"; // accounts[1] -var arbitraryAccountPrivateKey = "6cbed15c793ce57650b9877cf6fa156fbef513c4e6134f022a85b1ffdd59b2a1"; // accounts[1]; -var tokenOwnerAccount = "0xe11ba2b4d45eaed5996cd0823791e0c93114882d"; // accounts[3] -var blacklisterAccount = "0xd03ea8624c8c5987235048901fb614fdca89b117"; // accounts[4] Why Multiple blacklisterAccount?? -var arbitraryAccount2 = "0x95ced938f7991cd0dfcb48f0a06a40fa1af46ebc"; // accounts[5] -var masterMinterAccount = "0x3e5e9111ae8eb78fe1cc3bb8915d5d461f3ef9a9"; // accounts[6] -var minterAccount = "0x28a8746e75304c0780e011bed21c72cd78cd535e"; // accounts[7] -var pauserAccount = "0xaca94ef8bd5ffee41947b4585a84bda5a3d3da6e"; // accounts[8] -//var blacklisterAccount = "0x1df62f291b2e969fb0849d99d9ce41e2f137006e"; // accounts[9] - -var proxyOwnerAccount = "0x2f560290fef1b3ada194b6aa9c40aa71f8e95598"; // accounts[14] -var upgraderAccount = proxyOwnerAccount; // accounts[14] - -var deployerAccountPrivateKey = "4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b1d"; // accounts[0] -var arbitraryAccountPrivateKey = "6cbed15c793ce57650b9877cf6fa156fbef513c4e6134f022a85b1ffdd59b2a1"; // accounts[1]; -var upgraderAccountPrivateKey = "6370fd033278c143179d81c5526140625662b8daa446c22ee2d73db3707e620c"; // accounts[2] -var proxyOwnerAccountPrivateKey = "21d7212f3b4e5332fd465877b64926e3532653e2798a11255a46f533852dfe46;" //accounts[14] -var tokenOwnerPrivateKey = "646f1ce2fdad0e6deeeb5c7e8e5543bdde65e86029e2fd9fc169899c440a7913"; // accounts[3] -var blacklisterAccountPrivateKey = "add53f9a7e588d003326d1cbf9e4a43c061aadd9bc938c843a79e7b4fd2ad743"; // accounts[4] -var arbitraryAccount2PrivateKey = "395df67f0c2d2d9fe1ad08d1bc8b6627011959b79c53d7dd6a3536a33ab8a4fd"; // accounts[5] -var masterMinterAccountPrivateKey = "e485d098507f54e7733a205420dfddbe58db035fa577fc294ebd14db90767a52"; // accounts[6] -var minterAccountPrivateKey = "a453611d9419d0e56f499079478fd72c37b251a94bfde4d19872c44cf65386e3"; // accounts[7] -var pauserAccountPrivateKey = "829e924fdf021ba3dbbc4225edfece9aca04b929d6e75613329ca6f1d31c0bb4"; // accounts[9] -var proxyOwnerAccountPrivateKey = "21d7212f3b4e5332fd465877b64926e3532653e2798a11255a46f533852dfe46"; // accounts[14] -var upgraderAccountPrivateKey = proxyOwnerAccountPrivateKey; -//var blacklisterAccountPrivateKey = "b0057716d5917badaf911b193b12b910811c1497b5bada8d7711f758981c3773"; // accounts[9] - var adminSlot = "0x10d6a54a4754c8869d6886b5f5d7fbfa5b4522237ea5c60d11bc4e7a1ff9390b"; var implSlot = "0x7050c9e0f4ca769c69bd3a8ef740bc37934f8e2c036e5a723fd8ee048ed3f8c3"; const should = require('chai') @@ -200,13 +174,13 @@ function buildExpectedState(token, customVars) { 'symbol': symbol, 'currency': currency, 'decimals': new BigNumber(decimals), - 'masterMinter': masterMinterAccount, - 'pauser': pauserAccount, - 'blacklister': blacklisterAccount, - 'tokenOwner': tokenOwnerAccount, + 'masterMinter': Accounts.masterMinterAccount, + 'pauser': Accounts.pauserAccount, + 'blacklister': Accounts.blacklisterAccount, + 'tokenOwner': Accounts.tokenOwnerAccount, 'proxiedTokenAddress': token.proxiedTokenAddress, 'initializedV1': trueInStorageFormat, - 'upgrader': proxyOwnerAccount, + 'upgrader': Accounts.proxyOwnerAccount, 'balances': { 'arbitraryAccount': bigZero, 'masterMinterAccount': bigZero, @@ -350,7 +324,7 @@ async function checkVariables(_tokens, _customVars) { assertDiff.deepEqual(actualState, expectedState, "difference between expected and actual state"); // Check that sum of individual balances equals totalSupply - var accounts = [arbitraryAccount, masterMinterAccount, minterAccount, pauserAccount, blacklisterAccount, tokenOwnerAccount, upgraderAccount]; + var accounts = [Accounts.arbitraryAccount, Accounts.masterMinterAccount, Accounts.minterAccount, Accounts.pauserAccount, Accounts.blacklisterAccount, Accounts.tokenOwnerAccount, Accounts.upgraderAccount]; var balanceSum = bigZero; var x; for (x = 0; x < accounts.length; x++) { @@ -375,84 +349,84 @@ async function getActualState(token) { await getImplementation(token), await getAdmin(token), await getInitializedV1(token), - await token.balanceOf(arbitraryAccount), - await token.balanceOf(masterMinterAccount), - await token.balanceOf(minterAccount), - await token.balanceOf(pauserAccount), - await token.balanceOf(blacklisterAccount), - await token.balanceOf(tokenOwnerAccount), - await token.balanceOf(upgraderAccount), - await token.allowance(arbitraryAccount, masterMinterAccount), - await token.allowance(arbitraryAccount, minterAccount), - await token.allowance(arbitraryAccount, pauserAccount), - await token.allowance(arbitraryAccount, blacklisterAccount), - await token.allowance(arbitraryAccount, tokenOwnerAccount), - await token.allowance(arbitraryAccount, arbitraryAccount), - await token.allowance(arbitraryAccount, upgraderAccount), - await token.allowance(masterMinterAccount, arbitraryAccount), - await token.allowance(masterMinterAccount, minterAccount), - await token.allowance(masterMinterAccount, pauserAccount), - await token.allowance(masterMinterAccount, blacklisterAccount), - await token.allowance(masterMinterAccount, tokenOwnerAccount), - await token.allowance(masterMinterAccount, masterMinterAccount), - await token.allowance(masterMinterAccount, upgraderAccount), - await token.allowance(minterAccount, arbitraryAccount), - await token.allowance(minterAccount, masterMinterAccount), - await token.allowance(minterAccount, pauserAccount), - await token.allowance(minterAccount, blacklisterAccount), - await token.allowance(minterAccount, tokenOwnerAccount), - await token.allowance(minterAccount, minterAccount), - await token.allowance(minterAccount, upgraderAccount), - await token.allowance(pauserAccount, arbitraryAccount), - await token.allowance(pauserAccount, masterMinterAccount), - await token.allowance(pauserAccount, minterAccount), - await token.allowance(pauserAccount, blacklisterAccount), - await token.allowance(pauserAccount, tokenOwnerAccount), - await token.allowance(pauserAccount, pauserAccount), - await token.allowance(pauserAccount, upgraderAccount), - await token.allowance(blacklisterAccount, arbitraryAccount), - await token.allowance(blacklisterAccount, masterMinterAccount), - await token.allowance(blacklisterAccount, minterAccount), - await token.allowance(blacklisterAccount, pauserAccount), - await token.allowance(blacklisterAccount, tokenOwnerAccount), - await token.allowance(blacklisterAccount, blacklisterAccount), - await token.allowance(blacklisterAccount, upgraderAccount), - await token.allowance(tokenOwnerAccount, arbitraryAccount), - await token.allowance(tokenOwnerAccount, masterMinterAccount), - await token.allowance(tokenOwnerAccount, minterAccount), - await token.allowance(tokenOwnerAccount, pauserAccount), - await token.allowance(tokenOwnerAccount, blacklisterAccount), - await token.allowance(tokenOwnerAccount, tokenOwnerAccount), - await token.allowance(tokenOwnerAccount, upgraderAccount), - await token.allowance(upgraderAccount, arbitraryAccount), - await token.allowance(upgraderAccount, masterMinterAccount), - await token.allowance(upgraderAccount, minterAccount), - await token.allowance(upgraderAccount, pauserAccount), - await token.allowance(upgraderAccount, blacklisterAccount), - await token.allowance(upgraderAccount, tokenOwnerAccount), - await token.allowance(upgraderAccount, upgraderAccount), + await token.balanceOf(Accounts.arbitraryAccount), + await token.balanceOf(Accounts.masterMinterAccount), + await token.balanceOf(Accounts.minterAccount), + await token.balanceOf(Accounts.pauserAccount), + await token.balanceOf(Accounts.blacklisterAccount), + await token.balanceOf(Accounts.tokenOwnerAccount), + await token.balanceOf(Accounts.upgraderAccount), + await token.allowance(Accounts.arbitraryAccount, Accounts.masterMinterAccount), + await token.allowance(Accounts.arbitraryAccount, Accounts.minterAccount), + await token.allowance(Accounts.arbitraryAccount, Accounts.pauserAccount), + await token.allowance(Accounts.arbitraryAccount, Accounts.blacklisterAccount), + await token.allowance(Accounts.arbitraryAccount, Accounts.tokenOwnerAccount), + await token.allowance(Accounts.arbitraryAccount, Accounts.arbitraryAccount), + await token.allowance(Accounts.arbitraryAccount, Accounts.upgraderAccount), + await token.allowance(Accounts.masterMinterAccount, Accounts.arbitraryAccount), + await token.allowance(Accounts.masterMinterAccount, Accounts.minterAccount), + await token.allowance(Accounts.masterMinterAccount, Accounts.pauserAccount), + await token.allowance(Accounts.masterMinterAccount, Accounts.blacklisterAccount), + await token.allowance(Accounts.masterMinterAccount, Accounts.tokenOwnerAccount), + await token.allowance(Accounts.masterMinterAccount, Accounts.masterMinterAccount), + await token.allowance(Accounts.masterMinterAccount, Accounts.upgraderAccount), + await token.allowance(Accounts.minterAccount, Accounts.arbitraryAccount), + await token.allowance(Accounts.minterAccount, Accounts.masterMinterAccount), + await token.allowance(Accounts.minterAccount, Accounts.pauserAccount), + await token.allowance(Accounts.minterAccount, Accounts.blacklisterAccount), + await token.allowance(Accounts.minterAccount, Accounts.tokenOwnerAccount), + await token.allowance(Accounts.minterAccount, Accounts.minterAccount), + await token.allowance(Accounts.minterAccount, Accounts.upgraderAccount), + await token.allowance(Accounts.pauserAccount, Accounts.arbitraryAccount), + await token.allowance(Accounts.pauserAccount, Accounts.masterMinterAccount), + await token.allowance(Accounts.pauserAccount, Accounts.minterAccount), + await token.allowance(Accounts.pauserAccount, Accounts.blacklisterAccount), + await token.allowance(Accounts.pauserAccount, Accounts.tokenOwnerAccount), + await token.allowance(Accounts.pauserAccount, Accounts.pauserAccount), + await token.allowance(Accounts.pauserAccount, Accounts.upgraderAccount), + await token.allowance(Accounts.blacklisterAccount, Accounts.arbitraryAccount), + await token.allowance(Accounts.blacklisterAccount, Accounts.masterMinterAccount), + await token.allowance(Accounts.blacklisterAccount, Accounts.minterAccount), + await token.allowance(Accounts.blacklisterAccount, Accounts.pauserAccount), + await token.allowance(Accounts.blacklisterAccount, Accounts.tokenOwnerAccount), + await token.allowance(Accounts.blacklisterAccount, Accounts.blacklisterAccount), + await token.allowance(Accounts.blacklisterAccount, Accounts.upgraderAccount), + await token.allowance(Accounts.tokenOwnerAccount, Accounts.arbitraryAccount), + await token.allowance(Accounts.tokenOwnerAccount, Accounts.masterMinterAccount), + await token.allowance(Accounts.tokenOwnerAccount, Accounts.minterAccount), + await token.allowance(Accounts.tokenOwnerAccount, Accounts.pauserAccount), + await token.allowance(Accounts.tokenOwnerAccount, Accounts.blacklisterAccount), + await token.allowance(Accounts.tokenOwnerAccount, Accounts.tokenOwnerAccount), + await token.allowance(Accounts.tokenOwnerAccount, Accounts.upgraderAccount), + await token.allowance(Accounts.upgraderAccount, Accounts.arbitraryAccount), + await token.allowance(Accounts.upgraderAccount, Accounts.masterMinterAccount), + await token.allowance(Accounts.upgraderAccount, Accounts.minterAccount), + await token.allowance(Accounts.upgraderAccount, Accounts.pauserAccount), + await token.allowance(Accounts.upgraderAccount, Accounts.blacklisterAccount), + await token.allowance(Accounts.upgraderAccount, Accounts.tokenOwnerAccount), + await token.allowance(Accounts.upgraderAccount, Accounts.upgraderAccount), await token.totalSupply(), - await token.isBlacklisted(arbitraryAccount), - await token.isBlacklisted(masterMinterAccount), - await token.isBlacklisted(minterAccount), - await token.isBlacklisted(pauserAccount), - await token.isBlacklisted(blacklisterAccount), - await token.isBlacklisted(tokenOwnerAccount), - await token.isBlacklisted(upgraderAccount), - await token.isMinter(arbitraryAccount), - await token.isMinter(masterMinterAccount), - await token.isMinter(minterAccount), - await token.isMinter(pauserAccount), - await token.isMinter(blacklisterAccount), - await token.isMinter(tokenOwnerAccount), - await token.isMinter(upgraderAccount), - await token.minterAllowance(arbitraryAccount), - await token.minterAllowance(masterMinterAccount), - await token.minterAllowance(minterAccount), - await token.minterAllowance(pauserAccount), - await token.minterAllowance(blacklisterAccount), - await token.minterAllowance(tokenOwnerAccount), - await token.minterAllowance(upgraderAccount), + await token.isBlacklisted(Accounts.arbitraryAccount), + await token.isBlacklisted(Accounts.masterMinterAccount), + await token.isBlacklisted(Accounts.minterAccount), + await token.isBlacklisted(Accounts.pauserAccount), + await token.isBlacklisted(Accounts.blacklisterAccount), + await token.isBlacklisted(Accounts.tokenOwnerAccount), + await token.isBlacklisted(Accounts.upgraderAccount), + await token.isMinter(Accounts.arbitraryAccount), + await token.isMinter(Accounts.masterMinterAccount), + await token.isMinter(Accounts.minterAccount), + await token.isMinter(Accounts.pauserAccount), + await token.isMinter(Accounts.blacklisterAccount), + await token.isMinter(Accounts.tokenOwnerAccount), + await token.isMinter(Accounts.upgraderAccount), + await token.minterAllowance(Accounts.arbitraryAccount), + await token.minterAllowance(Accounts.masterMinterAccount), + await token.minterAllowance(Accounts.minterAccount), + await token.minterAllowance(Accounts.pauserAccount), + await token.minterAllowance(Accounts.blacklisterAccount), + await token.minterAllowance(Accounts.tokenOwnerAccount), + await token.minterAllowance(Accounts.upgraderAccount), await token.paused() ]).spread(function ( name, @@ -667,7 +641,7 @@ async function getActualState(token) { } async function setMinter(token, minter, amount) { - let update = await token.configureMinter(minter, amount, { from: masterMinterAccount }); + let update = await token.configureMinter(minter, amount, { from: Accounts.masterMinterAccount }); assert.equal(update.logs[0].event, 'MinterConfigured'); assert.equal(update.logs[0].args.minter, minter); assert.equal(update.logs[0].args.minterAllowedAmount, amount); @@ -700,12 +674,12 @@ async function mintRaw(token, to, amount, minter) { } async function blacklist(token, account) { - let blacklist = await token.blacklist(account, { from: blacklisterAccount }); + let blacklist = await token.blacklist(account, { from: Accounts.blacklisterAccount }); checkBlacklistEvent(blacklist, account); } async function unBlacklist(token, account) { - let unblacklist = await token.unBlacklist(account, { from: blacklisterAccount }); + let unblacklist = await token.unBlacklist(account, { from: Accounts.blacklisterAccount }); checkUnblacklistEvent(unblacklist, account); } @@ -818,11 +792,11 @@ function validateTransferEvent(transferEvent, from, to, value) { } async function initializeTokenWithProxy(rawToken) { - return customInitializeTokenWithProxy(rawToken, masterMinterAccount, pauserAccount, blacklisterAccount, tokenOwnerAccount); + return customInitializeTokenWithProxy(rawToken, Accounts.masterMinterAccount, Accounts.pauserAccount, Accounts.blacklisterAccount, Accounts.tokenOwnerAccount); } async function customInitializeTokenWithProxy(rawToken, _masterMinter, _pauser, _blacklister, _owner) { - const proxy = await FiatTokenProxy.new(rawToken.address, { from: proxyOwnerAccount }) + const proxy = await FiatTokenProxy.new(rawToken.address, { from: Accounts.proxyOwnerAccount }) proxiedToken = await FiatToken.at(proxy.address); await proxiedToken.initialize(name, symbol, currency, decimals, _masterMinter, _pauser, _blacklister, _owner); proxiedToken.proxiedTokenAddress = rawToken.address; @@ -838,7 +812,7 @@ async function customInitializeTokenWithProxy(rawToken, _masterMinter, _pauser, async function upgradeTo(proxy, upgradedToken, proxyUpgraderAccount) { if (proxyUpgraderAccount == null) { - proxyUpgraderAccount = proxyOwnerAccount; + proxyUpgraderAccount = Accounts.proxyOwnerAccount; } await proxy.upgradeTo(upgradedToken.address, { from: proxyUpgraderAccount }); proxiedToken = await FiatToken.at(proxy.address); @@ -971,26 +945,5 @@ module.exports = { expectJump: expectJump, encodeCall: encodeCall, getInitializedV1: getInitializedV1, - deployerAccount: deployerAccount, - arbitraryAccount: arbitraryAccount, - tokenOwnerAccount: tokenOwnerAccount, - arbitraryAccount2: arbitraryAccount2, - masterMinterAccount: masterMinterAccount, - minterAccount: minterAccount, - pauserAccount: pauserAccount, - blacklisterAccount: blacklisterAccount, - proxyOwnerAccount: proxyOwnerAccount, - proxyOwnerAccountPrivateKey: proxyOwnerAccountPrivateKey, - upgraderAccount: upgraderAccount, getAdmin: getAdmin, - arbitraryAccountPrivateKey, - upgraderAccountPrivateKey, - proxyOwnerAccountPrivateKey, - tokenOwnerPrivateKey, - blacklisterAccountPrivateKey, - arbitraryAccount2PrivateKey, - masterMinterAccountPrivateKey, - minterAccountPrivateKey, - pauserAccountPrivateKey, - deployerAccountPrivateKey }; diff --git a/test/minting/ControllerTestUtils.js b/test/minting/ControllerTestUtils.js index 17f37a98e..d11520538 100644 --- a/test/minting/ControllerTestUtils.js +++ b/test/minting/ControllerTestUtils.js @@ -8,21 +8,21 @@ var debugLogging = false; var tokenUtils = require('./../TokenTestUtils'); var Controller = artifacts.require('./../minting/Controller'); -var AccountUtils = require('./AccountUtils'); -var mcAccounts = AccountUtils.mcAccounts; +var AccountUtils = require('./../AccountUtils'); +var Accounts = AccountUtils.Accounts; var setAccountDefault = AccountUtils.setAccountDefault; var checkState = AccountUtils.checkState; var getAccountState = AccountUtils.getAccountState; // Default state of Controller when it is deployed var controllerEmptyState = { - 'owner': mcAccounts.mintOwnerAccount, - 'controllers': setAccountDefault(mcAccounts, "0x0000000000000000000000000000000000000000") + 'owner': Accounts.mintOwnerAccount, + 'controllers': setAccountDefault(Accounts, "0x0000000000000000000000000000000000000000") }; // Checks the state of an array of controller contracts async function checkControllerState(controllers, customVars, ignoreExtraStateVariables) { - await checkState(controllers, customVars, controllerEmptyState, getActualControllerState, mcAccounts, ignoreExtraStateVariables); + await checkState(controllers, customVars, controllerEmptyState, getActualControllerState, Accounts, ignoreExtraStateVariables); } // Gets the actual state of the controller contract. diff --git a/test/minting/MintControllerTests.js b/test/minting/MintControllerTests.js index e36eedbeb..136d577aa 100644 --- a/test/minting/MintControllerTests.js +++ b/test/minting/MintControllerTests.js @@ -5,8 +5,8 @@ var tokenUtils = require('./../TokenTestUtils'); var checkVariables = tokenUtils.checkVariables; var mintUtils = require('./MintControllerUtils.js'); -var AccountUtils = require('./AccountUtils.js'); -var A = AccountUtils.mcAccounts; +var AccountUtils = require('./../AccountUtils.js'); +var A = AccountUtils.Accounts; var initializeTokenWithProxyAndMintController = mintUtils.initializeTokenWithProxyAndMintController; var checkMintControllerState = mintUtils.checkMintControllerState; diff --git a/test/minting/MintControllerUtils.js b/test/minting/MintControllerUtils.js index c158fe730..84af20a06 100644 --- a/test/minting/MintControllerUtils.js +++ b/test/minting/MintControllerUtils.js @@ -5,8 +5,8 @@ var tokenUtils = require('./../TokenTestUtils'); var initializeTokenWithProxy = tokenUtils.initializeTokenWithProxy; var MintController = artifacts.require('./../minting/MintController'); -var AccountUtils = require('./AccountUtils'); -var mcAccounts = AccountUtils.mcAccounts; +var AccountUtils = require('./../AccountUtils'); +var Accounts = AccountUtils.Accounts; var setAccountDefault = AccountUtils.setAccountDefault; var checkState = AccountUtils.checkState; var getAccountState = AccountUtils.getAccountState; @@ -19,7 +19,7 @@ var checkControllerState = ControllerUtils.checkControllerState; // Uses the same workflow we would do in production - first deploy FiatToken then set the masterMinter. async function initializeTokenWithProxyAndMintController(rawToken) { var tokenConfig = await initializeTokenWithProxy(rawToken); - var mintController = await MintController.new(tokenConfig.token.address, {from:mcAccounts.mintOwnerAccount}); + var mintController = await MintController.new(tokenConfig.token.address, {from:Accounts.mintOwnerAccount}); await tokenConfig.token.updateMasterMinter(mintController.address, {from:tokenUtils.tokenOwnerAccount}); var tokenConfigWithMinter = { proxy: tokenConfig.proxy, @@ -37,7 +37,7 @@ var mintControllerEmptyState = { // Checks the state of the mintController contract async function checkMintControllerState(mintControllers, customVars) { await checkControllerState(mintControllers, customVars, true); - await checkState(mintControllers, customVars, mintControllerEmptyState, getActualMintControllerState, mcAccounts, true); + await checkState(mintControllers, customVars, mintControllerEmptyState, getActualMintControllerState, Accounts, true); } From 8131df8c057212b77f5af9dbddddaeb29cea5901 Mon Sep 17 00:00:00 2001 From: mirathewhite Date: Thu, 13 Sep 2018 09:37:18 -0400 Subject: [PATCH 04/74] replacing use of tokenUtils.tokenOwnerAccount with Accounts.tokenOwnerAccont --- test/minting/MintControllerUtils.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/minting/MintControllerUtils.js b/test/minting/MintControllerUtils.js index 84af20a06..a327953ec 100644 --- a/test/minting/MintControllerUtils.js +++ b/test/minting/MintControllerUtils.js @@ -7,7 +7,6 @@ var initializeTokenWithProxy = tokenUtils.initializeTokenWithProxy; var MintController = artifacts.require('./../minting/MintController'); var AccountUtils = require('./../AccountUtils'); var Accounts = AccountUtils.Accounts; -var setAccountDefault = AccountUtils.setAccountDefault; var checkState = AccountUtils.checkState; var getAccountState = AccountUtils.getAccountState; @@ -20,7 +19,7 @@ var checkControllerState = ControllerUtils.checkControllerState; async function initializeTokenWithProxyAndMintController(rawToken) { var tokenConfig = await initializeTokenWithProxy(rawToken); var mintController = await MintController.new(tokenConfig.token.address, {from:Accounts.mintOwnerAccount}); - await tokenConfig.token.updateMasterMinter(mintController.address, {from:tokenUtils.tokenOwnerAccount}); + await tokenConfig.token.updateMasterMinter(mintController.address, {from:Accounts.tokenOwnerAccount}); var tokenConfigWithMinter = { proxy: tokenConfig.proxy, token: tokenConfig.token, From 630a87c3f915e696ea414455a71912bf6766dbfb Mon Sep 17 00:00:00 2001 From: mirathewhite Date: Thu, 13 Sep 2018 10:53:01 -0400 Subject: [PATCH 05/74] Add more unit tests --- test/minting/MintControllerTests.js | 99 ++++++++++++++++++++++++++++- 1 file changed, 98 insertions(+), 1 deletion(-) diff --git a/test/minting/MintControllerTests.js b/test/minting/MintControllerTests.js index 136d577aa..965b50dcf 100644 --- a/test/minting/MintControllerTests.js +++ b/test/minting/MintControllerTests.js @@ -3,6 +3,7 @@ var MintController = artifacts.require('minting/MintController'); var BigNumber = require('bignumber.js'); var tokenUtils = require('./../TokenTestUtils'); var checkVariables = tokenUtils.checkVariables; +var expectRevert = tokenUtils.expectRevert; var mintUtils = require('./MintControllerUtils.js'); var AccountUtils = require('./../AccountUtils.js'); @@ -20,7 +21,6 @@ async function run_tests(newToken, accounts) { }); it('should mint through mint controller', async function () { - var amount = 5000; await mintController.configureController(A.controller1Account, A.minterAccount, {from: A.mintOwnerAccount}); await mintController.configureMinter(amount, {from: A.controller1Account}); @@ -48,6 +48,103 @@ async function run_tests(newToken, accounts) { await checkMintControllerState([mintController], [customState]); }); + it('only owner configures controller', async function () { + await expectRevert(mintController.configureController(A.controller1Account, A.minterAccount, {from: A.minterAccount})); + }); + + it('sets token', async function () { + await mintController.setToken(mintController.address, {from: A.mintOwnerAccount}); + }); + + it('only owner sets token', async function () { + await expectRevert(mintController.setToken(mintController.address, {from: A.minterAccount})); + }); + + it('remove minter', async function() { + // create a minter + var amount = 500; + await mintController.configureController(A.controller1Account, A.minterAccount, {from: A.mintOwnerAccount}); + await mintController.configureMinter(amount, {from: A.controller1Account}); + customState = { + 'token': token.address, + 'controllers': {'controller1Account': A.minterAccount } + } + await checkMintControllerState([mintController], [customState]); + customVars = [ + { 'variable': 'masterMinter', 'expectedValue': mintController.address }, + { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount) }, + ]; + await checkVariables([token], [customVars]); + + // remove minter + await mintController.removeMinter({from: A.controller1Account}); + await checkMintControllerState([mintController], [customState]); + customVars = [ + { 'variable': 'masterMinter', 'expectedValue': mintController.address }, + ]; + await checkVariables([token], [customVars]); + }); + + it('only controller removes a minter', async function () { + await expectRevert(mintController.removeMinter({from: A.controller1Account})); + }); + + it('only controller configures a minter', async function () { + await expectRevert(mintController.configureMinter(0, {from: A.controller1Account})); + }); + + it('increment minter allowance', async function () { + // configure controller & minter + var amount = 500; + await mintController.configureController(A.controller1Account, A.minterAccount, {from: A.mintOwnerAccount}); + await mintController.configureMinter(amount, {from: A.controller1Account}); + customState = { + 'token': token.address, + 'controllers': {'controller1Account': A.minterAccount } + } + await checkMintControllerState([mintController], [customState]); + customVars = [ + { 'variable': 'masterMinter', 'expectedValue': mintController.address }, + { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount) }, + ]; + await checkVariables([token], [customVars]); + + // increment minter allowance + await mintController.incrementMinterAllowance(amount, {from: A.controller1Account}); + await checkMintControllerState([mintController], [customState]); + customVars = [ + { 'variable': 'masterMinter', 'expectedValue': mintController.address }, + { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount*2) }, + ]; + await checkVariables([token], [customVars]); + }); + + it('only controller increments allowance', async function () { + await expectRevert(mintController.incrementMinterAllowance(0, {from: A.controller1Account})); + }); + + it('only active minters can have allowance incremented', async function () { + // configure controller but not minter + var amount = 500; + await mintController.configureController(A.controller1Account, A.minterAccount, {from: A.mintOwnerAccount}); + customState = { + 'token': token.address, + 'controllers': {'controller1Account': A.minterAccount } + } + await checkMintControllerState([mintController], [customState]); + customVars = [ + { 'variable': 'masterMinter', 'expectedValue': mintController.address }, + ]; + await checkVariables([token], [customVars]); + + // increment minter allowance + await expectRevert(mintController.incrementMinterAllowance(amount, {from: A.controller1Account})); + }); + + } var testWrapper = require('./../TestWrapper'); From 0f002ec3c2ae6e5ddb14e47a731e22f0295930ed Mon Sep 17 00:00:00 2001 From: mirathewhite Date: Fri, 14 Sep 2018 11:42:23 -0400 Subject: [PATCH 06/74] replacing A. with Accounts. for code clarity --- test/minting/MintControllerTests.js | 44 ++++++++++++++--------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/test/minting/MintControllerTests.js b/test/minting/MintControllerTests.js index 965b50dcf..10a9c43cb 100644 --- a/test/minting/MintControllerTests.js +++ b/test/minting/MintControllerTests.js @@ -7,7 +7,7 @@ var expectRevert = tokenUtils.expectRevert; var mintUtils = require('./MintControllerUtils.js'); var AccountUtils = require('./../AccountUtils.js'); -var A = AccountUtils.Accounts; +var Accounts = AccountUtils.Accounts; var initializeTokenWithProxyAndMintController = mintUtils.initializeTokenWithProxyAndMintController; var checkMintControllerState = mintUtils.checkMintControllerState; @@ -22,15 +22,15 @@ async function run_tests(newToken, accounts) { it('should mint through mint controller', async function () { var amount = 5000; - await mintController.configureController(A.controller1Account, A.minterAccount, {from: A.mintOwnerAccount}); - await mintController.configureMinter(amount, {from: A.controller1Account}); + await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + await mintController.configureMinter(amount, {from: Accounts.controller1Account}); customState = { 'token': token.address, - 'controllers': {'controller1Account': A.minterAccount } + 'controllers': {'controller1Account': Accounts.minterAccount } } await checkMintControllerState([mintController], [customState]); - await token.mint(A.arbitraryAccount, amount, {from: A.minterAccount}); + await token.mint(Accounts.arbitraryAccount, amount, {from: Accounts.minterAccount}); customVars = [ { 'variable': 'masterMinter', 'expectedValue': mintController.address }, { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, @@ -49,25 +49,25 @@ async function run_tests(newToken, accounts) { }); it('only owner configures controller', async function () { - await expectRevert(mintController.configureController(A.controller1Account, A.minterAccount, {from: A.minterAccount})); + await expectRevert(mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.minterAccount})); }); it('sets token', async function () { - await mintController.setToken(mintController.address, {from: A.mintOwnerAccount}); + await mintController.setToken(mintController.address, {from: Accounts.mintOwnerAccount}); }); it('only owner sets token', async function () { - await expectRevert(mintController.setToken(mintController.address, {from: A.minterAccount})); + await expectRevert(mintController.setToken(mintController.address, {from: Accounts.minterAccount})); }); it('remove minter', async function() { // create a minter var amount = 500; - await mintController.configureController(A.controller1Account, A.minterAccount, {from: A.mintOwnerAccount}); - await mintController.configureMinter(amount, {from: A.controller1Account}); + await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + await mintController.configureMinter(amount, {from: Accounts.controller1Account}); customState = { 'token': token.address, - 'controllers': {'controller1Account': A.minterAccount } + 'controllers': {'controller1Account': Accounts.minterAccount } } await checkMintControllerState([mintController], [customState]); customVars = [ @@ -78,7 +78,7 @@ async function run_tests(newToken, accounts) { await checkVariables([token], [customVars]); // remove minter - await mintController.removeMinter({from: A.controller1Account}); + await mintController.removeMinter({from: Accounts.controller1Account}); await checkMintControllerState([mintController], [customState]); customVars = [ { 'variable': 'masterMinter', 'expectedValue': mintController.address }, @@ -87,21 +87,21 @@ async function run_tests(newToken, accounts) { }); it('only controller removes a minter', async function () { - await expectRevert(mintController.removeMinter({from: A.controller1Account})); + await expectRevert(mintController.removeMinter({from: Accounts.controller1Account})); }); it('only controller configures a minter', async function () { - await expectRevert(mintController.configureMinter(0, {from: A.controller1Account})); + await expectRevert(mintController.configureMinter(0, {from: Accounts.controller1Account})); }); it('increment minter allowance', async function () { // configure controller & minter var amount = 500; - await mintController.configureController(A.controller1Account, A.minterAccount, {from: A.mintOwnerAccount}); - await mintController.configureMinter(amount, {from: A.controller1Account}); + await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + await mintController.configureMinter(amount, {from: Accounts.controller1Account}); customState = { 'token': token.address, - 'controllers': {'controller1Account': A.minterAccount } + 'controllers': {'controller1Account': Accounts.minterAccount } } await checkMintControllerState([mintController], [customState]); customVars = [ @@ -112,7 +112,7 @@ async function run_tests(newToken, accounts) { await checkVariables([token], [customVars]); // increment minter allowance - await mintController.incrementMinterAllowance(amount, {from: A.controller1Account}); + await mintController.incrementMinterAllowance(amount, {from: Accounts.controller1Account}); await checkMintControllerState([mintController], [customState]); customVars = [ { 'variable': 'masterMinter', 'expectedValue': mintController.address }, @@ -123,16 +123,16 @@ async function run_tests(newToken, accounts) { }); it('only controller increments allowance', async function () { - await expectRevert(mintController.incrementMinterAllowance(0, {from: A.controller1Account})); + await expectRevert(mintController.incrementMinterAllowance(0, {from: Accounts.controller1Account})); }); it('only active minters can have allowance incremented', async function () { // configure controller but not minter var amount = 500; - await mintController.configureController(A.controller1Account, A.minterAccount, {from: A.mintOwnerAccount}); + await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); customState = { 'token': token.address, - 'controllers': {'controller1Account': A.minterAccount } + 'controllers': {'controller1Account': Accounts.minterAccount } } await checkMintControllerState([mintController], [customState]); customVars = [ @@ -141,7 +141,7 @@ async function run_tests(newToken, accounts) { await checkVariables([token], [customVars]); // increment minter allowance - await expectRevert(mintController.incrementMinterAllowance(amount, {from: A.controller1Account})); + await expectRevert(mintController.incrementMinterAllowance(amount, {from: Accounts.controller1Account})); }); From 3db7a989460574fdc977ac6b21ad8cc8d202c344 Mon Sep 17 00:00:00 2001 From: mirathewhite Date: Fri, 14 Sep 2018 11:39:21 -0400 Subject: [PATCH 07/74] changing token to minterManager and MintableTokenInterface to MinterManagerInteface --- contracts/minting/MintController.sol | 28 ++++++++++++++-------------- test/minting/MintControllerTests.js | 4 ++-- test/minting/MintControllerUtils.js | 4 ++-- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/contracts/minting/MintController.sol b/contracts/minting/MintController.sol index b7fdac272..ad49f4587 100644 --- a/contracts/minting/MintController.sol +++ b/contracts/minting/MintController.sol @@ -26,7 +26,7 @@ import 'openzeppelin-solidity/contracts/math/SafeMath.sol'; // Using an interface for managing minters so that MintController // can be used for managing minters with different contracts. -interface MintableTokenInterface { +interface MinterManagementInterface { function isMinter(address account) external view returns (bool); function minterAllowance(address minter) external view returns (uint256); function configureMinter(address minter, uint256 minterAllowedAmount) external returns (bool); @@ -41,25 +41,25 @@ interface MintableTokenInterface { contract MintController is Controller { using SafeMath for uint256; - MintableTokenInterface public token; + MinterManagementInterface public minterManager; - event TokenSet(address indexed oldToken, address indexed newToken); + event MinterManagerSet(address indexed oldMinterManager, address indexed newMinterManager); event MinterConfigured(address indexed msgSender, address indexed minter, uint256 allowance); event MinterRemoved(address indexed msgSender, address indexed minter); event MinterAllowanceIncrement(address indexed msgSender, address indexed minter, uint256 increment, uint256 newAllowance); - constructor(address _token) public { - token = MintableTokenInterface(_token); + constructor(address _minterManager) public { + minterManager = MinterManagementInterface(_minterManager); } // onlyOwner functions /** - * @dev sets the token + * @dev sets the minterManager */ - function setToken(address _newToken) onlyOwner public returns (bool) { - emit TokenSet(token, _newToken); - token = MintableTokenInterface(_newToken); + function setMinterManager(address _newMinterManager) onlyOwner public returns (bool) { + emit MinterManagerSet(minterManager, _newMinterManager); + minterManager = MinterManagementInterface(_newMinterManager); return true; } @@ -71,7 +71,7 @@ contract MintController is Controller { function removeMinter() onlyController public returns (bool) { address minter = controllers[msg.sender]; emit MinterRemoved(msg.sender, minter); - return token.removeMinter(minter); + return minterManager.removeMinter(minter); } /** @@ -91,9 +91,9 @@ contract MintController is Controller { */ function incrementMinterAllowance(uint256 allowanceIncrement) onlyController public returns (bool) { address minter = controllers[msg.sender]; - require(token.isMinter(minter)); + require(minterManager.isMinter(minter)); - uint256 currentAllowance = token.minterAllowance(minter); + uint256 currentAllowance = minterManager.minterAllowance(minter); uint256 newAllowance = currentAllowance.add(allowanceIncrement); emit MinterAllowanceIncrement(msg.sender, minter, allowanceIncrement, newAllowance); @@ -103,9 +103,9 @@ contract MintController is Controller { // Internal functions /** - * @dev Uses the MintableTokenInterface to enable the minter and set its allowance. + * @dev Uses the MinterManagementInterface to enable the minter and set its allowance. */ function internal_setMinterAllowance(address minter, uint256 newAllowance) internal returns (bool) { - return token.configureMinter(minter, newAllowance); + return minterManager.configureMinter(minter, newAllowance); } } \ No newline at end of file diff --git a/test/minting/MintControllerTests.js b/test/minting/MintControllerTests.js index 10a9c43cb..9f0b18edb 100644 --- a/test/minting/MintControllerTests.js +++ b/test/minting/MintControllerTests.js @@ -25,7 +25,7 @@ async function run_tests(newToken, accounts) { await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); await mintController.configureMinter(amount, {from: Accounts.controller1Account}); customState = { - 'token': token.address, + 'minterManager': token.address, 'controllers': {'controller1Account': Accounts.minterAccount } } await checkMintControllerState([mintController], [customState]); @@ -42,7 +42,7 @@ async function run_tests(newToken, accounts) { it('initial state', async function () { customState = { - 'token': token.address, + 'minterManager': token.address, }; await checkMintControllerState([mintController], [customState]); diff --git a/test/minting/MintControllerUtils.js b/test/minting/MintControllerUtils.js index a327953ec..46188b4ef 100644 --- a/test/minting/MintControllerUtils.js +++ b/test/minting/MintControllerUtils.js @@ -30,7 +30,7 @@ async function initializeTokenWithProxyAndMintController(rawToken) { // Default state of MintController when it is deployed var mintControllerEmptyState = { - 'token' : bigZero, + 'minterManager' : bigZero, }; // Checks the state of the mintController contract @@ -44,7 +44,7 @@ async function checkMintControllerState(mintControllers, customVars) { // Evaluates all mappings on the provided accounts. async function getActualMintControllerState(mintController, accounts) { return { - 'token': await mintController.token.call() + 'minterManager': await mintController.minterManager.call() }; } From e33452e141689640dcba9388477516a5b86fdd58 Mon Sep 17 00:00:00 2001 From: mirathewhite Date: Fri, 14 Sep 2018 14:54:25 -0400 Subject: [PATCH 08/74] updated new unit tests to use minterManager instead of token --- test/minting/MintControllerTests.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/minting/MintControllerTests.js b/test/minting/MintControllerTests.js index 9f0b18edb..f72c30b63 100644 --- a/test/minting/MintControllerTests.js +++ b/test/minting/MintControllerTests.js @@ -53,11 +53,11 @@ async function run_tests(newToken, accounts) { }); it('sets token', async function () { - await mintController.setToken(mintController.address, {from: Accounts.mintOwnerAccount}); + await mintController.setMinterManager(mintController.address, {from: Accounts.mintOwnerAccount}); }); it('only owner sets token', async function () { - await expectRevert(mintController.setToken(mintController.address, {from: Accounts.minterAccount})); + await expectRevert(mintController.setMinterManager(mintController.address, {from: Accounts.minterAccount})); }); it('remove minter', async function() { @@ -66,7 +66,7 @@ async function run_tests(newToken, accounts) { await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); await mintController.configureMinter(amount, {from: Accounts.controller1Account}); customState = { - 'token': token.address, + 'minterManager': token.address, 'controllers': {'controller1Account': Accounts.minterAccount } } await checkMintControllerState([mintController], [customState]); @@ -100,7 +100,7 @@ async function run_tests(newToken, accounts) { await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); await mintController.configureMinter(amount, {from: Accounts.controller1Account}); customState = { - 'token': token.address, + 'minterManager': token.address, 'controllers': {'controller1Account': Accounts.minterAccount } } await checkMintControllerState([mintController], [customState]); @@ -131,7 +131,7 @@ async function run_tests(newToken, accounts) { var amount = 500; await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); customState = { - 'token': token.address, + 'minterManager': token.address, 'controllers': {'controller1Account': Accounts.minterAccount } } await checkMintControllerState([mintController], [customState]); From d00ca6c6208adea7285dcae75489e891385cde94 Mon Sep 17 00:00:00 2001 From: mirathewhite Date: Mon, 17 Sep 2018 11:50:03 -0400 Subject: [PATCH 09/74] Add remove controller --- contracts/minting/Controller.sol | 10 ++++++++++ test/minting/MintControllerTests.js | 20 ++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/contracts/minting/Controller.sol b/contracts/minting/Controller.sol index c8c2c0c4e..fec46a8f8 100644 --- a/contracts/minting/Controller.sol +++ b/contracts/minting/Controller.sol @@ -34,6 +34,7 @@ contract Controller is Ownable { mapping(address => address) public controllers; event ControllerConfigured(address indexed _controller, address indexed _worker); + event ControllerRemoved(address indexed _controller); /** * @dev ensure that the caller is the controller of a non-zero worker address @@ -59,4 +60,13 @@ contract Controller is Ownable { emit ControllerConfigured(_controller, _worker); return true; } + + /** + * @dev disables a controller by setting its worker to address(0); + */ + function removeController(address _controller) onlyOwner public returns (bool) { + controllers[_controller] = address(0); + emit ControllerRemoved(_controller); + return true; + } } \ No newline at end of file diff --git a/test/minting/MintControllerTests.js b/test/minting/MintControllerTests.js index 10a9c43cb..1b7a4a1c7 100644 --- a/test/minting/MintControllerTests.js +++ b/test/minting/MintControllerTests.js @@ -52,6 +52,26 @@ async function run_tests(newToken, accounts) { await expectRevert(mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.minterAccount})); }); + it('remove controller', async function () { + var amount = 5000; + await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + customState = { + 'token': token.address, + 'controllers': {'controller1Account': Accounts.minterAccount } + } + await checkMintControllerState([mintController], [customState]); + + await mintController.removeController(Accounts.controller1Account, {from: Accounts.mintOwnerAccount}); + customState = { + 'token': token.address + }; + await checkMintControllerState([mintController], [customState]); + }); + + it('only owner can remove controller', async function () { + await expectRevert(mintController.removeController(Accounts.controller1Account, {from: Accounts.minterAccount})); + }); + it('sets token', async function () { await mintController.setToken(mintController.address, {from: Accounts.mintOwnerAccount}); }); From 4478bb44feb57f4f2a9e896f531eec91265b1fae Mon Sep 17 00:00:00 2001 From: mirathewhite Date: Tue, 18 Sep 2018 09:29:34 -0400 Subject: [PATCH 10/74] fixing failed 'remove controller' --- test/minting/MintControllerTests.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/minting/MintControllerTests.js b/test/minting/MintControllerTests.js index f12415163..fb03fad80 100644 --- a/test/minting/MintControllerTests.js +++ b/test/minting/MintControllerTests.js @@ -56,14 +56,14 @@ async function run_tests(newToken, accounts) { var amount = 5000; await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); customState = { - 'token': token.address, + 'minterManager': token.address, 'controllers': {'controller1Account': Accounts.minterAccount } } await checkMintControllerState([mintController], [customState]); await mintController.removeController(Accounts.controller1Account, {from: Accounts.mintOwnerAccount}); customState = { - 'token': token.address + 'minterManager': token.address }; await checkMintControllerState([mintController], [customState]); }); From 9cab5eeaf199abc5d6c7b6f9632b897bf3776d63 Mon Sep 17 00:00:00 2001 From: mirathewhite Date: Thu, 20 Sep 2018 09:52:36 -0400 Subject: [PATCH 11/74] add ControllerState object to ControllerTestUtils.js --- test/minting/ControllerTestUtils.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/test/minting/ControllerTestUtils.js b/test/minting/ControllerTestUtils.js index d11520538..f6b710b5d 100644 --- a/test/minting/ControllerTestUtils.js +++ b/test/minting/ControllerTestUtils.js @@ -14,11 +14,16 @@ var setAccountDefault = AccountUtils.setAccountDefault; var checkState = AccountUtils.checkState; var getAccountState = AccountUtils.getAccountState; +var ControllerState(owner, controllers) { + this.owner = owner; + this.controllers = controllers; + this.checkState = checkControllerState; +} + // Default state of Controller when it is deployed -var controllerEmptyState = { - 'owner': Accounts.mintOwnerAccount, - 'controllers': setAccountDefault(Accounts, "0x0000000000000000000000000000000000000000") -}; +var controllerEmptyState = ControllerState( + Accounts.mintOwnerAccount, + setAccountDefault(Accounts, "0x0000000000000000000000000000000000000000")); // Checks the state of an array of controller contracts async function checkControllerState(controllers, customVars, ignoreExtraStateVariables) { From 7dc6d8f28fc614344663c94b54d4ffd4dae0f84d Mon Sep 17 00:00:00 2001 From: mirathewhite Date: Thu, 20 Sep 2018 16:05:56 -0400 Subject: [PATCH 12/74] checkVariables takes as input either FiatTokenV1 or MintController --- test/AccountUtils.js | 27 ++++++++++--- test/TokenTestUtils.js | 33 ++++++++------- test/minting/ControllerTestUtils.js | 19 ++++----- test/minting/MintControllerTests.js | 62 +++++++++-------------------- test/minting/MintControllerUtils.js | 47 ++++++++++++---------- 5 files changed, 94 insertions(+), 94 deletions(-) diff --git a/test/AccountUtils.js b/test/AccountUtils.js index 1660839e3..f7a8bf950 100644 --- a/test/AccountUtils.js +++ b/test/AccountUtils.js @@ -60,7 +60,7 @@ function cloneState(state) { var clone = {}; for (var attr in state) { var attrValue = state[attr]; - if(isLiteral(attrValue)) { + if(typeof(attrValue) != 'object') { clone[attr] = state[attr]; } else { clone[attr] = cloneState(attrValue); @@ -143,15 +143,30 @@ function isLiteral(object) { // Turns a simple literal object into a printable string function logObject(object) { - var output = ''; + internal_logObject(object, 0); +} + +function internal_logObject(object, stackHeight){ + if(stackHeight > 2) return; + for (var property in object) { - if(isLiteral(object[property])) { - output += property + ':\n' + logObject(object[property]); + var value = object[property]; + if(typeof(value) == 'function') { + console.log("function " + property + "\n"); + } else if(Array.isArray(value)) { + console.log("array " + property); + logObject(value); + } else if(typeof(value) == 'object') { + if(value == null) console.log("object: " + null); + else if(value._isBigNumber) console.log("BigNum: " + value ); + else { + console.log("object " + property + ':\n'); + logObject(value); + } } else { - output += property + ': ' + object[property]+';\n '; + console.log("value " + property + ': ' + value+';\n '); } } - return output; } module.exports = { diff --git a/test/TokenTestUtils.js b/test/TokenTestUtils.js index 28a3ece28..cf9c632c5 100644 --- a/test/TokenTestUtils.js +++ b/test/TokenTestUtils.js @@ -315,23 +315,28 @@ async function checkVariables(_tokens, _customVars) { for (n = 0; n < numTokens; n++) { var token = _tokens[n]; var customVars = _customVars[n]; - let expectedState = buildExpectedState(token, customVars); - if (debugLogging) { - console.log(util.inspect(expectedState, { showHidden: false, depth: null })) - } - let actualState = await getActualState(token); - assertDiff.deepEqual(actualState, expectedState, "difference between expected and actual state"); + if(! Array.isArray(customVars)) { + await customVars.checkState(token); + } else { + let expectedState = buildExpectedState(token, customVars); + if (debugLogging) { + console.log(util.inspect(expectedState, { showHidden: false, depth: null })) + } - // Check that sum of individual balances equals totalSupply - var accounts = [Accounts.arbitraryAccount, Accounts.masterMinterAccount, Accounts.minterAccount, Accounts.pauserAccount, Accounts.blacklisterAccount, Accounts.tokenOwnerAccount, Accounts.upgraderAccount]; - var balanceSum = bigZero; - var x; - for (x = 0; x < accounts.length; x++) { - balanceSum = balanceSum.plus(new BigNumber(await token.balanceOf(accounts[x]))); + let actualState = await getActualState(token); + assertDiff.deepEqual(actualState, expectedState, "difference between expected and actual state"); + + // Check that sum of individual balances equals totalSupply + var accounts = [Accounts.arbitraryAccount, Accounts.masterMinterAccount, Accounts.minterAccount, Accounts.pauserAccount, Accounts.blacklisterAccount, Accounts.tokenOwnerAccount, Accounts.upgraderAccount]; + var balanceSum = bigZero; + var x; + for (x = 0; x < accounts.length; x++) { + balanceSum = balanceSum.plus(new BigNumber(await token.balanceOf(accounts[x]))); + } + var totalSupply = new BigNumber(await token.totalSupply()) + assert(balanceSum.isEqualTo(totalSupply)); } - var totalSupply = new BigNumber(await token.totalSupply()) - assert(balanceSum.isEqualTo(totalSupply)); } } diff --git a/test/minting/ControllerTestUtils.js b/test/minting/ControllerTestUtils.js index f6b710b5d..236dcefc9 100644 --- a/test/minting/ControllerTestUtils.js +++ b/test/minting/ControllerTestUtils.js @@ -14,20 +14,21 @@ var setAccountDefault = AccountUtils.setAccountDefault; var checkState = AccountUtils.checkState; var getAccountState = AccountUtils.getAccountState; -var ControllerState(owner, controllers) { +function ControllerState(owner, controllers) { this.owner = owner; this.controllers = controllers; this.checkState = checkControllerState; } // Default state of Controller when it is deployed -var controllerEmptyState = ControllerState( +var controllerEmptyState = new ControllerState( Accounts.mintOwnerAccount, - setAccountDefault(Accounts, "0x0000000000000000000000000000000000000000")); + setAccountDefault(Accounts, "0x0000000000000000000000000000000000000000") +); // Checks the state of an array of controller contracts -async function checkControllerState(controllers, customVars, ignoreExtraStateVariables) { - await checkState(controllers, customVars, controllerEmptyState, getActualControllerState, Accounts, ignoreExtraStateVariables); +async function checkControllerState(controller, customState) { + await checkState(controller, customState, controllerEmptyState, getActualControllerState, Accounts, true); } // Gets the actual state of the controller contract. @@ -45,12 +46,8 @@ async function getActualControllerState(controllerContract, accounts) { owner, controllerState, ) { - var actualState = { - 'owner': owner, - 'controllers': controllerState, - }; - return actualState; - }) + return new ControllerState(owner, controllerState); + }); } module.exports = { diff --git a/test/minting/MintControllerTests.js b/test/minting/MintControllerTests.js index fb03fad80..ab34d6299 100644 --- a/test/minting/MintControllerTests.js +++ b/test/minting/MintControllerTests.js @@ -8,6 +8,7 @@ var expectRevert = tokenUtils.expectRevert; var mintUtils = require('./MintControllerUtils.js'); var AccountUtils = require('./../AccountUtils.js'); var Accounts = AccountUtils.Accounts; +var MintControllerState = AccountUtils.MintControllerState; var initializeTokenWithProxyAndMintController = mintUtils.initializeTokenWithProxyAndMintController; var checkMintControllerState = mintUtils.checkMintControllerState; @@ -15,20 +16,17 @@ async function run_tests(newToken, accounts) { beforeEach('Make fresh token contract', async function () { rawToken = await newToken(); - var tokenConfig = await initializeTokenWithProxyAndMintController(rawToken); + tokenConfig = await initializeTokenWithProxyAndMintController(rawToken); token = tokenConfig.token; mintController = tokenConfig.mintController; + customState = tokenConfig.customState.clone(); }); it('should mint through mint controller', async function () { var amount = 5000; await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); await mintController.configureMinter(amount, {from: Accounts.controller1Account}); - customState = { - 'minterManager': token.address, - 'controllers': {'controller1Account': Accounts.minterAccount } - } - await checkMintControllerState([mintController], [customState]); + customState.controllers['controller1Account'] = Accounts.minterAccount; await token.mint(Accounts.arbitraryAccount, amount, {from: Accounts.minterAccount}); customVars = [ @@ -37,15 +35,11 @@ async function run_tests(newToken, accounts) { { 'variable': 'balances.arbitraryAccount', 'expectedValue': new BigNumber(amount) }, { 'variable': 'totalSupply', 'expectedValue': new BigNumber(amount)} ]; - await checkVariables([token], [customVars]); + await checkVariables([token, mintController], [customVars, customState]); }); it('initial state', async function () { - customState = { - 'minterManager': token.address, - }; - - await checkMintControllerState([mintController], [customState]); + await checkVariables([mintController], [customState]); }); it('only owner configures controller', async function () { @@ -55,17 +49,11 @@ async function run_tests(newToken, accounts) { it('remove controller', async function () { var amount = 5000; await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - customState = { - 'minterManager': token.address, - 'controllers': {'controller1Account': Accounts.minterAccount } - } - await checkMintControllerState([mintController], [customState]); + customState.controllers['controller1Account'] = Accounts.minterAccount; + await checkVariables([mintController], [customState]); await mintController.removeController(Accounts.controller1Account, {from: Accounts.mintOwnerAccount}); - customState = { - 'minterManager': token.address - }; - await checkMintControllerState([mintController], [customState]); + await checkVariables([mintController], [tokenConfig.customState.clone()]); }); it('only owner can remove controller', async function () { @@ -74,6 +62,8 @@ async function run_tests(newToken, accounts) { it('sets token', async function () { await mintController.setMinterManager(mintController.address, {from: Accounts.mintOwnerAccount}); + customState.minterManager = mintController.address; + checkVariables([mintController], [customState]); }); it('only owner sets token', async function () { @@ -85,25 +75,20 @@ async function run_tests(newToken, accounts) { var amount = 500; await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); await mintController.configureMinter(amount, {from: Accounts.controller1Account}); - customState = { - 'minterManager': token.address, - 'controllers': {'controller1Account': Accounts.minterAccount } - } - await checkMintControllerState([mintController], [customState]); + customState.controllers['controller1Account'] = Accounts.minterAccount; customVars = [ { 'variable': 'masterMinter', 'expectedValue': mintController.address }, { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount) }, ]; - await checkVariables([token], [customVars]); + await checkVariables([token, mintController], [customVars, customState]); // remove minter await mintController.removeMinter({from: Accounts.controller1Account}); - await checkMintControllerState([mintController], [customState]); customVars = [ { 'variable': 'masterMinter', 'expectedValue': mintController.address }, ]; - await checkVariables([token], [customVars]); + await checkVariables([token, mintController], [customVars, customState]); }); it('only controller removes a minter', async function () { @@ -119,27 +104,22 @@ async function run_tests(newToken, accounts) { var amount = 500; await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); await mintController.configureMinter(amount, {from: Accounts.controller1Account}); - customState = { - 'minterManager': token.address, - 'controllers': {'controller1Account': Accounts.minterAccount } - } - await checkMintControllerState([mintController], [customState]); + customState.controllers['controller1Account'] = Accounts.minterAccount; customVars = [ { 'variable': 'masterMinter', 'expectedValue': mintController.address }, { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount) }, ]; - await checkVariables([token], [customVars]); + await checkVariables([token, mintController], [customVars, customState]); // increment minter allowance await mintController.incrementMinterAllowance(amount, {from: Accounts.controller1Account}); - await checkMintControllerState([mintController], [customState]); customVars = [ { 'variable': 'masterMinter', 'expectedValue': mintController.address }, { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount*2) }, ]; - await checkVariables([token], [customVars]); + await checkVariables([token, mintController], [customVars, customState]); }); it('only controller increments allowance', async function () { @@ -150,15 +130,11 @@ async function run_tests(newToken, accounts) { // configure controller but not minter var amount = 500; await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - customState = { - 'minterManager': token.address, - 'controllers': {'controller1Account': Accounts.minterAccount } - } - await checkMintControllerState([mintController], [customState]); + customState.controllers['controller1Account']= Accounts.minterAccount; customVars = [ { 'variable': 'masterMinter', 'expectedValue': mintController.address }, ]; - await checkVariables([token], [customVars]); + await checkVariables([token, mintController], [customVars, customState]); // increment minter allowance await expectRevert(mintController.incrementMinterAllowance(amount, {from: Accounts.controller1Account})); diff --git a/test/minting/MintControllerUtils.js b/test/minting/MintControllerUtils.js index 46188b4ef..228b10f24 100644 --- a/test/minting/MintControllerUtils.js +++ b/test/minting/MintControllerUtils.js @@ -13,30 +13,21 @@ var getAccountState = AccountUtils.getAccountState; var ControllerUtils = require('./ControllerTestUtils'); var checkControllerState = ControllerUtils.checkControllerState; - -// Deploys a FiatTokenV1 with a MintController contract as the masterMinter. -// Uses the same workflow we would do in production - first deploy FiatToken then set the masterMinter. -async function initializeTokenWithProxyAndMintController(rawToken) { - var tokenConfig = await initializeTokenWithProxy(rawToken); - var mintController = await MintController.new(tokenConfig.token.address, {from:Accounts.mintOwnerAccount}); - await tokenConfig.token.updateMasterMinter(mintController.address, {from:Accounts.tokenOwnerAccount}); - var tokenConfigWithMinter = { - proxy: tokenConfig.proxy, - token: tokenConfig.token, - mintController: mintController - }; - return tokenConfigWithMinter; +function MintControllerState(owner, controllers, minterManager) { + this.owner = owner; + this.controllers = controllers; + this.minterManager = minterManager; + this.checkState = async function(mintController) {await checkMintControllerState(mintController, this)}; + this.clone = function(){return new MintControllerState(this.owner, AccountUtils.cloneState(this.controllers), this.minterManager)}; } // Default state of MintController when it is deployed -var mintControllerEmptyState = { - 'minterManager' : bigZero, -}; +var mintControllerEmptyState = new MintControllerState(null, {}, bigZero); // Checks the state of the mintController contract -async function checkMintControllerState(mintControllers, customVars) { - await checkControllerState(mintControllers, customVars, true); - await checkState(mintControllers, customVars, mintControllerEmptyState, getActualMintControllerState, Accounts, true); +async function checkMintControllerState(mintController, customState) { + await checkControllerState(mintController, customState); + await checkState(mintController, customState, mintControllerEmptyState, getActualMintControllerState, Accounts, true); } @@ -48,7 +39,23 @@ async function getActualMintControllerState(mintController, accounts) { }; } +// Deploys a FiatTokenV1 with a MintController contract as the masterMinter. +// Uses the same workflow we would do in production - first deploy FiatToken then set the masterMinter. +async function initializeTokenWithProxyAndMintController(rawToken) { + var tokenConfig = await initializeTokenWithProxy(rawToken); + var mintController = await MintController.new(tokenConfig.token.address, {from:Accounts.mintOwnerAccount}); + await tokenConfig.token.updateMasterMinter(mintController.address, {from:Accounts.tokenOwnerAccount}); + var tokenConfigWithMinter = { + proxy: tokenConfig.proxy, + token: tokenConfig.token, + mintController: mintController, + customState: new MintControllerState(null, {}, tokenConfig.token.address) + }; + return tokenConfigWithMinter; +} + module.exports = { initializeTokenWithProxyAndMintController: initializeTokenWithProxyAndMintController, - checkMintControllerState: checkMintControllerState + checkMintControllerState: checkMintControllerState, + MintControllerState: MintControllerState } \ No newline at end of file From 0eb61a62b770d5ed15e69e7994ff5acc6acfb003 Mon Sep 17 00:00:00 2001 From: mirathewhite Date: Thu, 20 Sep 2018 16:13:49 -0400 Subject: [PATCH 13/74] replaced literal objects with actual objects --- test/minting/ControllerTestUtils.js | 2 ++ test/minting/MintControllerUtils.js | 5 ++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/test/minting/ControllerTestUtils.js b/test/minting/ControllerTestUtils.js index 236dcefc9..c1d745a17 100644 --- a/test/minting/ControllerTestUtils.js +++ b/test/minting/ControllerTestUtils.js @@ -18,6 +18,8 @@ function ControllerState(owner, controllers) { this.owner = owner; this.controllers = controllers; this.checkState = checkControllerState; + this.checkState = async function(controllerContract) {await checkControllerState(controllerContract, this)}; + this.clone = function(){return new ControllerState(this.owner, AccountUtils.cloneState(this.controllers))}; } // Default state of Controller when it is deployed diff --git a/test/minting/MintControllerUtils.js b/test/minting/MintControllerUtils.js index 228b10f24..d7f34aa68 100644 --- a/test/minting/MintControllerUtils.js +++ b/test/minting/MintControllerUtils.js @@ -34,9 +34,8 @@ async function checkMintControllerState(mintController, customState) { // Gets the actual state of the mintController contract. // Evaluates all mappings on the provided accounts. async function getActualMintControllerState(mintController, accounts) { - return { - 'minterManager': await mintController.minterManager.call() - }; + var minterManager = await mintController.minterManager.call(); + return new MintControllerState(null, {}, minterManager); } // Deploys a FiatTokenV1 with a MintController contract as the masterMinter. From fd3ded71196919205d34f624043b36fdd6b796d2 Mon Sep 17 00:00:00 2001 From: mirathewhite Date: Wed, 26 Sep 2018 12:26:46 -0400 Subject: [PATCH 14/74] Using library funciton clone(), removing logObject, and creating checkMINTp0 function for unit tests --- package.json | 3 +- test/AccountUtils.js | 50 +------ test/TokenTestUtils.js | 48 ++++--- test/minting/ControllerTestUtils.js | 4 +- test/minting/MintControllerTests.js | 65 +++++----- test/minting/MintControllerUtils.js | 4 +- yarn.lock | 195 +++++++++++++++++++++------- 7 files changed, 222 insertions(+), 147 deletions(-) diff --git a/package.json b/package.json index 2c77626fe..77a2abc70 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "dependencies": { "assert-diff": "^1.2.6", "bignumber.js": "6.0.0", + "clone": "2.1.2", "ethereum-input-data-decoder": "0.0.12", "ethereumjs-abi": "^0.6.5", "ethereumjs-tx": "1.3.1", @@ -33,7 +34,7 @@ "ganache-cli": "6.1.0", "lodash": "^4.17.10", "mkdirp": "^0.5.1", - "npm": "^6.2.0", + "npm": "^6.4.1", "openzeppelin-solidity": "1.11.0", "path": "^0.12.7", "q": "^1.5.1", diff --git a/test/AccountUtils.js b/test/AccountUtils.js index f7a8bf950..2be04f3c2 100644 --- a/test/AccountUtils.js +++ b/test/AccountUtils.js @@ -3,6 +3,7 @@ var debugLogging = false; var assertDiff = require('assert-diff'); assertDiff.options.strict = true; +var clone = require('clone'); // named list of all accounts var Accounts = { @@ -54,26 +55,10 @@ function setAccountDefault(accounts, defaultValue) { return result; } -// Clones a state object -function cloneState(state) { - // for each item in customVars, set the item in expectedState - var clone = {}; - for (var attr in state) { - var attrValue = state[attr]; - if(typeof(attrValue) != 'object') { - clone[attr] = state[attr]; - } else { - clone[attr] = cloneState(attrValue); - } - } - return clone; -} - // return an expectedState that combines customState with the emptyState -// todo: after merge, integrate this with TokenTestUtils.js function buildExpectedPartialState(emptyState, customState, ignoreExtraCustomVars) { // for each item in customVars, set the item in expectedState - var expectedState = cloneState(emptyState); + var expectedState = clone(emptyState); for( var variableName in customState) { // do I ignore extra values @@ -102,7 +87,6 @@ function buildExpectedPartialState(emptyState, customState, ignoreExtraCustomVar // getActualState: async function(token, accounts) => state // accounts: list of accounts on which to evaluate mappings // ignoreExtraCustomVars: ignore _customVars names that are not in the emptyState -// todo: after merge, integrate this with TokenTestUtils.js async function checkState(_tokens, _customVars, emptyState, getActualState, accounts, ignoreExtraCustomVars) { // Iterate over array of tokens. var numTokens = _tokens.length; @@ -141,41 +125,11 @@ function isLiteral(object) { return true; } -// Turns a simple literal object into a printable string -function logObject(object) { - internal_logObject(object, 0); -} - -function internal_logObject(object, stackHeight){ - if(stackHeight > 2) return; - - for (var property in object) { - var value = object[property]; - if(typeof(value) == 'function') { - console.log("function " + property + "\n"); - } else if(Array.isArray(value)) { - console.log("array " + property); - logObject(value); - } else if(typeof(value) == 'object') { - if(value == null) console.log("object: " + null); - else if(value._isBigNumber) console.log("BigNum: " + value ); - else { - console.log("object " + property + ':\n'); - logObject(value); - } - } else { - console.log("value " + property + ': ' + value+';\n '); - } - } -} - module.exports = { Accounts: Accounts, AccountPrivateKeys: AccountPrivateKeys, setAccountDefault: setAccountDefault, - cloneState: cloneState, buildExpectedPartialState: buildExpectedPartialState, checkState: checkState, - logObject: logObject, getAccountState: getAccountState, } \ No newline at end of file diff --git a/test/TokenTestUtils.js b/test/TokenTestUtils.js index cf9c632c5..f9cd4fb67 100644 --- a/test/TokenTestUtils.js +++ b/test/TokenTestUtils.js @@ -316,30 +316,41 @@ async function checkVariables(_tokens, _customVars) { var token = _tokens[n]; var customVars = _customVars[n]; - if(! Array.isArray(customVars)) { - await customVars.checkState(token); - } else { - let expectedState = buildExpectedState(token, customVars); - if (debugLogging) { - console.log(util.inspect(expectedState, { showHidden: false, depth: null })) - } + let expectedState = buildExpectedState(token, customVars); + if (debugLogging) { + console.log(util.inspect(expectedState, { showHidden: false, depth: null })) + } - let actualState = await getActualState(token); - assertDiff.deepEqual(actualState, expectedState, "difference between expected and actual state"); + let actualState = await getActualState(token); + assertDiff.deepEqual(actualState, expectedState, "difference between expected and actual state"); - // Check that sum of individual balances equals totalSupply - var accounts = [Accounts.arbitraryAccount, Accounts.masterMinterAccount, Accounts.minterAccount, Accounts.pauserAccount, Accounts.blacklisterAccount, Accounts.tokenOwnerAccount, Accounts.upgraderAccount]; - var balanceSum = bigZero; - var x; - for (x = 0; x < accounts.length; x++) { - balanceSum = balanceSum.plus(new BigNumber(await token.balanceOf(accounts[x]))); - } - var totalSupply = new BigNumber(await token.totalSupply()) - assert(balanceSum.isEqualTo(totalSupply)); + // Check that sum of individual balances equals totalSupply + var accounts = [Accounts.arbitraryAccount, Accounts.masterMinterAccount, Accounts.minterAccount, Accounts.pauserAccount, Accounts.blacklisterAccount, Accounts.tokenOwnerAccount, Accounts.upgraderAccount]; + var balanceSum = bigZero; + var x; + for (x = 0; x < accounts.length; x++) { + balanceSum = balanceSum.plus(new BigNumber(await token.balanceOf(accounts[x]))); } + var totalSupply = new BigNumber(await token.totalSupply()) + assert(balanceSum.isEqualTo(totalSupply)); } } +// All MINT p0 tests will call this function. +// _contracts is an array of exactly two values: a FiatTokenV1 and a MintController +// _customVars is an array of exactly two values: the expected state of the FiatTokenV1 +// and the expected state of the MintController +async function checkMINTp0(_contracts, _customVars) { + assert.equal(_contracts.length, 2); + assert.equal(_customVars.length, 2); + + // the first is a FiatTokenV1 + await checkVariables([_contracts[0]], [_customVars[0]]); + + // the second is a MintController + await _customVars[1].checkState(_contracts[1]); +} + // build up actualState object to compare to expectedState object async function getActualState(token) { return Q.all([ @@ -930,6 +941,7 @@ module.exports = { checkAdminChangedEvent: checkAdminChangedEvent, buildExpectedState, checkVariables: checkVariables, + checkMINTp0: checkMINTp0, setMinter: setMinter, mint: mint, burn: burn, diff --git a/test/minting/ControllerTestUtils.js b/test/minting/ControllerTestUtils.js index c1d745a17..b06f7fcf8 100644 --- a/test/minting/ControllerTestUtils.js +++ b/test/minting/ControllerTestUtils.js @@ -1,5 +1,6 @@ var BigNumber = require('bignumber.js'); var Q = require('q'); +var clone = require('clone'); // set to true to enable verbose logging in the tests var debugLogging = false; @@ -19,7 +20,8 @@ function ControllerState(owner, controllers) { this.controllers = controllers; this.checkState = checkControllerState; this.checkState = async function(controllerContract) {await checkControllerState(controllerContract, this)}; - this.clone = function(){return new ControllerState(this.owner, AccountUtils.cloneState(this.controllers))}; +// this.clone = function(){return clone(this);}; + //this.clone = function(){return new ControllerState(this.owner, clone(this.controllers))}; } // Default state of Controller when it is deployed diff --git a/test/minting/MintControllerTests.js b/test/minting/MintControllerTests.js index ab34d6299..d7b278c4e 100644 --- a/test/minting/MintControllerTests.js +++ b/test/minting/MintControllerTests.js @@ -2,8 +2,11 @@ var MintController = artifacts.require('minting/MintController'); var BigNumber = require('bignumber.js'); var tokenUtils = require('./../TokenTestUtils'); -var checkVariables = tokenUtils.checkVariables; +var checkMINTp0 = tokenUtils.checkMINTp0; var expectRevert = tokenUtils.expectRevert; +var bigZero = tokenUtils.bigZero; + +var clone = require('clone'); var mintUtils = require('./MintControllerUtils.js'); var AccountUtils = require('./../AccountUtils.js'); @@ -19,27 +22,27 @@ async function run_tests(newToken, accounts) { tokenConfig = await initializeTokenWithProxyAndMintController(rawToken); token = tokenConfig.token; mintController = tokenConfig.mintController; - customState = tokenConfig.customState.clone(); + expectedMintControllerState = clone(tokenConfig.customState); + expectedTokenState = [{ 'variable': 'masterMinter', 'expectedValue': mintController.address }]; }); it('should mint through mint controller', async function () { var amount = 5000; await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); await mintController.configureMinter(amount, {from: Accounts.controller1Account}); - customState.controllers['controller1Account'] = Accounts.minterAccount; + expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; await token.mint(Accounts.arbitraryAccount, amount, {from: Accounts.minterAccount}); - customVars = [ - { 'variable': 'masterMinter', 'expectedValue': mintController.address }, + expectedTokenState.push( { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'balances.arbitraryAccount', 'expectedValue': new BigNumber(amount) }, { 'variable': 'totalSupply', 'expectedValue': new BigNumber(amount)} - ]; - await checkVariables([token, mintController], [customVars, customState]); + ); + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); }); it('initial state', async function () { - await checkVariables([mintController], [customState]); + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); }); it('only owner configures controller', async function () { @@ -49,11 +52,12 @@ async function run_tests(newToken, accounts) { it('remove controller', async function () { var amount = 5000; await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - customState.controllers['controller1Account'] = Accounts.minterAccount; - await checkVariables([mintController], [customState]); + expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); await mintController.removeController(Accounts.controller1Account, {from: Accounts.mintOwnerAccount}); - await checkVariables([mintController], [tokenConfig.customState.clone()]); + expectedMintControllerState.controllers['controller1Account'] = bigZero; + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); }); it('only owner can remove controller', async function () { @@ -62,8 +66,8 @@ async function run_tests(newToken, accounts) { it('sets token', async function () { await mintController.setMinterManager(mintController.address, {from: Accounts.mintOwnerAccount}); - customState.minterManager = mintController.address; - checkVariables([mintController], [customState]); + expectedMintControllerState.minterManager = mintController.address; + checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); }); it('only owner sets token', async function () { @@ -75,20 +79,19 @@ async function run_tests(newToken, accounts) { var amount = 500; await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); await mintController.configureMinter(amount, {from: Accounts.controller1Account}); - customState.controllers['controller1Account'] = Accounts.minterAccount; - customVars = [ - { 'variable': 'masterMinter', 'expectedValue': mintController.address }, + expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; + expectedTokenState.push( { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount) }, - ]; - await checkVariables([token, mintController], [customVars, customState]); + ); + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); // remove minter await mintController.removeMinter({from: Accounts.controller1Account}); - customVars = [ + expectedTokenState = [ { 'variable': 'masterMinter', 'expectedValue': mintController.address }, ]; - await checkVariables([token, mintController], [customVars, customState]); + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); }); it('only controller removes a minter', async function () { @@ -104,22 +107,21 @@ async function run_tests(newToken, accounts) { var amount = 500; await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); await mintController.configureMinter(amount, {from: Accounts.controller1Account}); - customState.controllers['controller1Account'] = Accounts.minterAccount; - customVars = [ - { 'variable': 'masterMinter', 'expectedValue': mintController.address }, + expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; + expectedTokenState.push( { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount) }, - ]; - await checkVariables([token, mintController], [customVars, customState]); + ); + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); // increment minter allowance await mintController.incrementMinterAllowance(amount, {from: Accounts.controller1Account}); - customVars = [ + expectedTokenState = [ { 'variable': 'masterMinter', 'expectedValue': mintController.address }, { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount*2) }, ]; - await checkVariables([token, mintController], [customVars, customState]); + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); }); it('only controller increments allowance', async function () { @@ -130,17 +132,12 @@ async function run_tests(newToken, accounts) { // configure controller but not minter var amount = 500; await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - customState.controllers['controller1Account']= Accounts.minterAccount; - customVars = [ - { 'variable': 'masterMinter', 'expectedValue': mintController.address }, - ]; - await checkVariables([token, mintController], [customVars, customState]); + expectedMintControllerState.controllers['controller1Account']= Accounts.minterAccount; + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); // increment minter allowance await expectRevert(mintController.incrementMinterAllowance(amount, {from: Accounts.controller1Account})); }); - - } var testWrapper = require('./../TestWrapper'); diff --git a/test/minting/MintControllerUtils.js b/test/minting/MintControllerUtils.js index d7f34aa68..eca81121e 100644 --- a/test/minting/MintControllerUtils.js +++ b/test/minting/MintControllerUtils.js @@ -1,5 +1,6 @@ var BigNumber = require('bignumber.js'); var bigZero = new BigNumber(0); +var clone = require('clone'); var tokenUtils = require('./../TokenTestUtils'); var initializeTokenWithProxy = tokenUtils.initializeTokenWithProxy; @@ -18,7 +19,8 @@ function MintControllerState(owner, controllers, minterManager) { this.controllers = controllers; this.minterManager = minterManager; this.checkState = async function(mintController) {await checkMintControllerState(mintController, this)}; - this.clone = function(){return new MintControllerState(this.owner, AccountUtils.cloneState(this.controllers), this.minterManager)}; +// this.clone = function(){return clone(this);}; +// this.clone = function(){return new MintControllerState(this.owner, clone(this.controllers), this.minterManager)}; } // Default state of MintController when it is deployed diff --git a/yarn.lock b/yarn.lock index 8614b4960..b10c67eb3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -23,9 +23,9 @@ version "0.7.0" resolved "https://registry.yarnpkg.com/@sindresorhus/is/-/is-0.7.0.tgz#9a06f4f137ee84d7df0460c1fdb1135ffa6c50fd" -JSONStream@^1.3.3: - version "1.3.3" - resolved "https://registry.yarnpkg.com/JSONStream/-/JSONStream-1.3.3.tgz#27b4b8fbbfeab4e71bcf551e7f27be8d952239bf" +JSONStream@^1.3.4: + version "1.3.4" + resolved "https://registry.yarnpkg.com/JSONStream/-/JSONStream-1.3.4.tgz#615bb2adb0cd34c8f4c447b5f6512fa1d8f16a2e" dependencies: jsonparse "^1.2.0" through ">=2.2.7 <3" @@ -1329,6 +1329,25 @@ cacache@^11.0.1, cacache@^11.0.2: unique-filename "^1.1.0" y18n "^4.0.0" +cacache@^11.2.0: + version "11.2.0" + resolved "https://registry.yarnpkg.com/cacache/-/cacache-11.2.0.tgz#617bdc0b02844af56310e411c0878941d5739965" + dependencies: + bluebird "^3.5.1" + chownr "^1.0.1" + figgy-pudding "^3.1.0" + glob "^7.1.2" + graceful-fs "^4.1.11" + lru-cache "^4.1.3" + mississippi "^3.0.0" + mkdirp "^0.5.1" + move-concurrently "^1.0.1" + promise-inflight "^1.0.1" + rimraf "^2.6.2" + ssri "^6.0.0" + unique-filename "^1.1.0" + y18n "^4.0.0" + cache-base@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/cache-base/-/cache-base-1.0.1.tgz#0a7f46416831c8b662ee36fe4e7c59d76f666ab2" @@ -1482,6 +1501,10 @@ ci-info@^1.0.0: version "1.1.3" resolved "https://registry.yarnpkg.com/ci-info/-/ci-info-1.1.3.tgz#710193264bb05c77b8c90d02f5aaf22216a667b2" +ci-info@^1.4.0: + version "1.6.0" + resolved "https://registry.yarnpkg.com/ci-info/-/ci-info-1.6.0.tgz#2ca20dbb9ceb32d4524a683303313f0304b1e497" + cidr-regex@^2.0.8: version "2.0.9" resolved "https://registry.yarnpkg.com/cidr-regex/-/cidr-regex-2.0.9.tgz#9c17bb2b18e15af07f7d0c3b994b961d687ed1c9" @@ -1605,14 +1628,14 @@ clone-stats@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/clone-stats/-/clone-stats-1.0.0.tgz#b3782dff8bb5474e18b9b6bf0fdfe782f8777680" +clone@2.1.2, clone@^2.0.0: + version "2.1.2" + resolved "https://registry.yarnpkg.com/clone/-/clone-2.1.2.tgz#1b7f4b9f591f1e8f83670401600345a02887435f" + clone@^1.0.0, clone@^1.0.2: version "1.0.4" resolved "https://registry.yarnpkg.com/clone/-/clone-1.0.4.tgz#da309cc263df15994c688ca902179ca3c7cd7c7e" -clone@^2.0.0: - version "2.1.2" - resolved "https://registry.yarnpkg.com/clone/-/clone-2.1.2.tgz#1b7f4b9f591f1e8f83670401600345a02887435f" - clone@^2.1.1: version "2.1.1" resolved "https://registry.yarnpkg.com/clone/-/clone-2.1.1.tgz#d217d1e961118e3ac9a4b8bba3285553bf647cdb" @@ -1912,7 +1935,7 @@ debug@3.1.0, debug@^3.1.0, debug@~3.1.0: dependencies: ms "2.0.0" -debuglog@^1.0.1: +debuglog@*, debuglog@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/debuglog/-/debuglog-1.0.1.tgz#aa24ffb9ac3df9a2351837cfb2d279360cd78492" @@ -2779,6 +2802,10 @@ figgy-pudding@^3.0.0, figgy-pudding@^3.1.0, figgy-pudding@^3.2.0: version "3.2.0" resolved "https://registry.yarnpkg.com/figgy-pudding/-/figgy-pudding-3.2.0.tgz#464626b73d7b0fc045a99753d191b0785957ff73" +figgy-pudding@^3.4.1: + version "3.5.1" + resolved "https://registry.yarnpkg.com/figgy-pudding/-/figgy-pudding-3.5.1.tgz#862470112901c727a0e495a80744bd5baa1d6790" + figures@^1.7.0: version "1.7.0" resolved "https://registry.yarnpkg.com/figures/-/figures-1.7.0.tgz#cbe1e3affcf1cd44b80cadfed28dc793a9701d2e" @@ -3489,7 +3516,7 @@ homedir-polyfill@^1.0.1: dependencies: parse-passwd "^1.0.0" -hosted-git-info@^2.1.4, hosted-git-info@^2.6.0: +hosted-git-info@^2.1.4, hosted-git-info@^2.6.0, hosted-git-info@^2.7.1: version "2.7.1" resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.7.1.tgz#97f236977bd6e125408930ff6de3eec6281ec047" @@ -3559,7 +3586,7 @@ iferr@^0.1.5: version "0.1.5" resolved "https://registry.yarnpkg.com/iferr/-/iferr-0.1.5.tgz#c60eed69e6d8fdb6b3104a1fcbca1c192dc5b501" -iferr@^1.0.0: +iferr@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/iferr/-/iferr-1.0.2.tgz#e9fde49a9da06dc4a4194c6c9ed6d08305037a6d" @@ -3592,7 +3619,7 @@ import-local@^1.0.0: pkg-dir "^2.0.0" resolve-cwd "^2.0.0" -imurmurhash@^0.1.4: +imurmurhash@*, imurmurhash@^0.1.4: version "0.1.4" resolved "https://registry.yarnpkg.com/imurmurhash/-/imurmurhash-0.1.4.tgz#9218b9b2b928a238b13dc4fb6b6d576f231453ea" @@ -4327,9 +4354,9 @@ levn@~0.3.0: prelude-ls "~1.1.2" type-check "~0.3.2" -libcipm@^2.0.0: - version "2.0.1" - resolved "https://registry.yarnpkg.com/libcipm/-/libcipm-2.0.1.tgz#2f4ebf8562e0fc6e46f415373674e4cf3ac4b9ba" +libcipm@^2.0.2: + version "2.0.2" + resolved "https://registry.yarnpkg.com/libcipm/-/libcipm-2.0.2.tgz#4f38c2b37acf2ec156936cef1cbf74636568fc7b" dependencies: bin-links "^1.1.2" bluebird "^3.5.1" @@ -4483,6 +4510,10 @@ lockfile@^1.0.4: dependencies: signal-exit "^3.0.2" +lodash._baseindexof@*: + version "3.1.0" + resolved "https://registry.yarnpkg.com/lodash._baseindexof/-/lodash._baseindexof-3.1.0.tgz#fe52b53a1c6761e42618d654e4a25789ed61822c" + lodash._baseuniq@~4.6.0: version "4.6.0" resolved "https://registry.yarnpkg.com/lodash._baseuniq/-/lodash._baseuniq-4.6.0.tgz#0ebb44e456814af7905c6212fa2c9b2d51b841e8" @@ -4490,10 +4521,28 @@ lodash._baseuniq@~4.6.0: lodash._createset "~4.0.0" lodash._root "~3.0.0" +lodash._bindcallback@*: + version "3.0.1" + resolved "https://registry.yarnpkg.com/lodash._bindcallback/-/lodash._bindcallback-3.0.1.tgz#e531c27644cf8b57a99e17ed95b35c748789392e" + +lodash._cacheindexof@*: + version "3.0.2" + resolved "https://registry.yarnpkg.com/lodash._cacheindexof/-/lodash._cacheindexof-3.0.2.tgz#3dc69ac82498d2ee5e3ce56091bafd2adc7bde92" + +lodash._createcache@*: + version "3.1.2" + resolved "https://registry.yarnpkg.com/lodash._createcache/-/lodash._createcache-3.1.2.tgz#56d6a064017625e79ebca6b8018e17440bdcf093" + dependencies: + lodash._getnative "^3.0.0" + lodash._createset@~4.0.0: version "4.0.3" resolved "https://registry.yarnpkg.com/lodash._createset/-/lodash._createset-4.0.3.tgz#0f4659fbb09d75194fa9e2b88a6644d363c9fe26" +lodash._getnative@*, lodash._getnative@^3.0.0: + version "3.9.1" + resolved "https://registry.yarnpkg.com/lodash._getnative/-/lodash._getnative-3.9.1.tgz#570bc7dede46d61cdcde687d65d3eecbaa3aaff5" + lodash._root@~3.0.0: version "3.0.1" resolved "https://registry.yarnpkg.com/lodash._root/-/lodash._root-3.0.1.tgz#fba1c4524c19ee9a5f8136b4609f017cf4ded692" @@ -4514,6 +4563,10 @@ lodash.isstring@^4.0.1: version "4.0.1" resolved "https://registry.yarnpkg.com/lodash.isstring/-/lodash.isstring-4.0.1.tgz#d527dfb5456eca7cc9bb95d5daeaf88ba54a5451" +lodash.restparam@*: + version "3.6.1" + resolved "https://registry.yarnpkg.com/lodash.restparam/-/lodash.restparam-3.6.1.tgz#936a4e309ef330a7645ed4145986c85ae5b20805" + lodash.union@~4.6.0: version "4.6.0" resolved "https://registry.yarnpkg.com/lodash.union/-/lodash.union-4.6.0.tgz#48bb5088409f16f1821666641c44dd1aaae3cd88" @@ -5002,7 +5055,7 @@ node-forge@^0.7.4: version "0.7.5" resolved "https://registry.yarnpkg.com/node-forge/-/node-forge-0.7.5.tgz#6c152c345ce11c52f465c2abd957e8639cd674df" -node-gyp@^3.6.2, node-gyp@^3.7.0: +node-gyp@^3.6.2: version "3.7.0" resolved "https://registry.yarnpkg.com/node-gyp/-/node-gyp-3.7.0.tgz#789478e8f6c45e277aa014f3e28f958f286f9203" dependencies: @@ -5019,6 +5072,23 @@ node-gyp@^3.6.2, node-gyp@^3.7.0: tar "^2.0.0" which "1" +node-gyp@^3.8.0: + version "3.8.0" + resolved "https://registry.yarnpkg.com/node-gyp/-/node-gyp-3.8.0.tgz#540304261c330e80d0d5edce253a68cb3964218c" + dependencies: + fstream "^1.0.0" + glob "^7.0.3" + graceful-fs "^4.1.2" + mkdirp "^0.5.0" + nopt "2 || 3" + npmlog "0 || 1 || 2 || 3 || 4" + osenv "0" + request "^2.87.0" + rimraf "2" + semver "~5.3.0" + tar "^2.0.0" + which "1" + node-pre-gyp@^0.10.0: version "0.10.3" resolved "https://registry.yarnpkg.com/node-pre-gyp/-/node-pre-gyp-0.10.3.tgz#3070040716afdc778747b61b6887bf78880b80fc" @@ -5111,6 +5181,19 @@ npm-lifecycle@^2.0.3: umask "^1.1.0" which "^1.3.0" +npm-lifecycle@^2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/npm-lifecycle/-/npm-lifecycle-2.1.0.tgz#1eda2eedb82db929e3a0c50341ab0aad140ed569" + dependencies: + byline "^5.0.0" + graceful-fs "^4.1.11" + node-gyp "^3.8.0" + resolve-from "^4.0.0" + slide "^1.1.6" + uid-number "0.0.6" + umask "^1.1.0" + which "^1.3.1" + npm-logical-tree@^1.2.1: version "1.2.1" resolved "https://registry.yarnpkg.com/npm-logical-tree/-/npm-logical-tree-1.2.1.tgz#44610141ca24664cad35d1e607176193fd8f5b88" @@ -5124,7 +5207,7 @@ npm-logical-tree@^1.2.1: semver "^5.5.0" validate-npm-package-name "^3.0.0" -npm-packlist@^1.1.10, npm-packlist@^1.1.6, npm-packlist@~1.1.10: +npm-packlist@^1.1.10, npm-packlist@^1.1.11, npm-packlist@^1.1.6: version "1.1.11" resolved "https://registry.yarnpkg.com/npm-packlist/-/npm-packlist-1.1.11.tgz#84e8c683cbe7867d34b1d357d893ce29e28a02de" dependencies: @@ -5145,7 +5228,7 @@ npm-profile@^3.0.2: aproba "^1.1.2 || 2" make-fetch-happen "^2.5.0 || 3 || 4" -npm-registry-client@^8.5.1: +npm-registry-client@^8.6.0: version "8.6.0" resolved "https://registry.yarnpkg.com/npm-registry-client/-/npm-registry-client-8.6.0.tgz#7f1529f91450732e89f8518e0f21459deea3e4c4" dependencies: @@ -5194,11 +5277,11 @@ npm-user-validate@~1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/npm-user-validate/-/npm-user-validate-1.0.0.tgz#8ceca0f5cea04d4e93519ef72d0557a75122e951" -npm@^6.2.0: - version "6.2.0" - resolved "https://registry.yarnpkg.com/npm/-/npm-6.2.0.tgz#2cee4b52825a91f531cd324a3b0f6e105be40c16" +npm@^6.4.1: + version "6.4.1" + resolved "https://registry.yarnpkg.com/npm/-/npm-6.4.1.tgz#4f39f9337b557a28faed4a771d5c8802d6b4288b" dependencies: - JSONStream "^1.3.3" + JSONStream "^1.3.4" abbrev "~1.1.1" ansicolors "~0.3.2" ansistyles "~0.1.3" @@ -5207,9 +5290,10 @@ npm@^6.2.0: bin-links "^1.1.2" bluebird "~3.5.1" byte-size "^4.0.3" - cacache "^11.0.2" + cacache "^11.2.0" call-limit "~1.1.0" chownr "~1.0.1" + ci-info "^1.4.0" cli-columns "^3.1.2" cli-table3 "^0.5.0" cmd-shim "~2.0.2" @@ -5219,7 +5303,7 @@ npm@^6.2.0: detect-newline "^2.1.0" dezalgo "~1.0.3" editor "~1.0.0" - figgy-pudding "^3.1.0" + figgy-pudding "^3.4.1" find-npm-prefix "^1.0.2" fs-vacuum "~1.2.10" fs-write-stream-atomic "~1.0.10" @@ -5227,8 +5311,8 @@ npm@^6.2.0: glob "~7.1.2" graceful-fs "~4.1.11" has-unicode "~2.0.1" - hosted-git-info "^2.6.0" - iferr "^1.0.0" + hosted-git-info "^2.7.1" + iferr "^1.0.2" inflight "~1.0.6" inherits "~2.0.3" ini "^1.3.5" @@ -5236,7 +5320,7 @@ npm@^6.2.0: is-cidr "^2.0.6" json-parse-better-errors "^1.0.2" lazy-property "~1.0.0" - libcipm "^2.0.0" + libcipm "^2.0.2" libnpmhook "^4.0.1" libnpx "^10.2.0" lock-verify "^2.0.2" @@ -5251,23 +5335,23 @@ npm@^6.2.0: mississippi "^3.0.0" mkdirp "~0.5.1" move-concurrently "^1.0.1" - node-gyp "^3.7.0" + node-gyp "^3.8.0" nopt "~4.0.1" normalize-package-data "~2.4.0" npm-audit-report "^1.3.1" npm-cache-filename "~1.0.2" npm-install-checks "~3.0.0" - npm-lifecycle "^2.0.3" + npm-lifecycle "^2.1.0" npm-package-arg "^6.1.0" - npm-packlist "~1.1.10" + npm-packlist "^1.1.11" npm-pick-manifest "^2.1.0" npm-profile "^3.0.2" - npm-registry-client "^8.5.1" + npm-registry-client "^8.6.0" npm-registry-fetch "^1.1.0" npm-user-validate "~1.0.0" npmlog "~4.1.2" once "~1.4.0" - opener "~1.4.3" + opener "^1.5.0" osenv "^0.1.5" pacote "^8.1.6" path-is-inside "~1.0.2" @@ -5281,7 +5365,7 @@ npm@^6.2.0: read-package-json "^2.0.13" read-package-tree "^5.2.1" readable-stream "^2.3.6" - request "^2.81.0" + request "^2.88.0" retry "^0.12.0" rimraf "~2.6.2" safe-buffer "^5.1.2" @@ -5291,7 +5375,8 @@ npm@^6.2.0: sorted-object "~2.0.1" sorted-union-stream "~2.1.3" ssri "^6.0.0" - tar "^4.4.4" + stringify-package "^1.0.0" + tar "^4.4.6" text-table "~0.2.0" tiny-relative-date "^1.3.0" uid-number "0.0.6" @@ -5300,11 +5385,10 @@ npm@^6.2.0: unpipe "~1.0.0" update-notifier "^2.5.0" uuid "^3.3.2" - validate-npm-package-license "^3.0.3" + validate-npm-package-license "^3.0.4" validate-npm-package-name "~3.0.0" which "^1.3.1" worker-farm "^1.6.0" - wrappy "~1.0.2" write-file-atomic "^2.3.0" "npmlog@0 || 1 || 2 || 3 || 4", "npmlog@2 || ^3.1.0 || ^4.0.0", npmlog@^4.0.2, npmlog@~4.1.2: @@ -5408,9 +5492,9 @@ onetime@^2.0.0: dependencies: mimic-fn "^1.0.0" -opener@~1.4.3: - version "1.4.3" - resolved "https://registry.yarnpkg.com/opener/-/opener-1.4.3.tgz#5c6da2c5d7e5831e8ffa3964950f8d6674ac90b8" +opener@^1.5.0: + version "1.5.1" + resolved "https://registry.yarnpkg.com/opener/-/opener-1.5.1.tgz#6d2f0e77f1a0af0032aca716c2c1fbb8e7e8abed" openurl@1.1.1: version "1.1.1" @@ -6065,7 +6149,7 @@ readable-stream@~1.0.15: isarray "0.0.1" string_decoder "~0.10.x" -readdir-scoped-modules@^1.0.0: +readdir-scoped-modules@*, readdir-scoped-modules@^1.0.0: version "1.0.2" resolved "https://registry.yarnpkg.com/readdir-scoped-modules/-/readdir-scoped-modules-1.0.2.tgz#9fafa37d286be5d92cbaebdee030dc9b5f406747" dependencies: @@ -6233,7 +6317,7 @@ req-from@^1.0.1: tunnel-agent "^0.6.0" uuid "^3.0.0" -request@^2.67.0: +request@^2.67.0, request@^2.87.0, request@^2.88.0: version "2.88.0" resolved "https://registry.yarnpkg.com/request/-/request-2.88.0.tgz#9c2fca4f7d35b592efe57c7f0a55e81052124fef" dependencies: @@ -6258,7 +6342,7 @@ request@^2.67.0: tunnel-agent "^0.6.0" uuid "^3.3.2" -request@^2.74.0, request@^2.81.0: +request@^2.74.0: version "2.87.0" resolved "https://registry.yarnpkg.com/request/-/request-2.87.0.tgz#32f00235cd08d482b4d0d68db93a829c0ed5756e" dependencies: @@ -7066,6 +7150,10 @@ string_decoder@~1.1.1: dependencies: safe-buffer "~5.1.0" +stringify-package@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/stringify-package/-/stringify-package-1.0.0.tgz#e02828089333d7d45cd8c287c30aa9a13375081b" + stringstream@~0.0.4: version "0.0.6" resolved "https://registry.yarnpkg.com/stringstream/-/stringstream-0.0.6.tgz#7880225b0d4ad10e30927d167a1d6f2fd3b33a72" @@ -7177,7 +7265,7 @@ tar@^2.0.0: fstream "^1.0.2" inherits "2" -tar@^4, tar@^4.4.3, tar@^4.4.4: +tar@^4, tar@^4.4.3: version "4.4.4" resolved "https://registry.yarnpkg.com/tar/-/tar-4.4.4.tgz#ec8409fae9f665a4355cc3b4087d0820232bb8cd" dependencies: @@ -7189,6 +7277,18 @@ tar@^4, tar@^4.4.3, tar@^4.4.4: safe-buffer "^5.1.2" yallist "^3.0.2" +tar@^4.4.6: + version "4.4.6" + resolved "https://registry.yarnpkg.com/tar/-/tar-4.4.6.tgz#63110f09c00b4e60ac8bcfe1bf3c8660235fbc9b" + dependencies: + chownr "^1.0.1" + fs-minipass "^1.2.5" + minipass "^2.3.3" + minizlib "^1.1.0" + mkdirp "^0.5.0" + safe-buffer "^5.1.2" + yallist "^3.0.2" + temp@^0.8.1: version "0.8.3" resolved "https://registry.yarnpkg.com/temp/-/temp-0.8.3.tgz#e0c6bc4d26b903124410e4fed81103014dfc1f59" @@ -7532,13 +7632,20 @@ v8-compile-cache@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/v8-compile-cache/-/v8-compile-cache-2.0.0.tgz#526492e35fc616864284700b7043e01baee09f0a" -validate-npm-package-license@^3.0.1, validate-npm-package-license@^3.0.3: +validate-npm-package-license@^3.0.1: version "3.0.3" resolved "https://registry.yarnpkg.com/validate-npm-package-license/-/validate-npm-package-license-3.0.3.tgz#81643bcbef1bdfecd4623793dc4648948ba98338" dependencies: spdx-correct "^3.0.0" spdx-expression-parse "^3.0.0" +validate-npm-package-license@^3.0.4: + version "3.0.4" + resolved "https://registry.yarnpkg.com/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz#fc91f6b9c7ba15c857f4cb2c5defeec39d4f410a" + dependencies: + spdx-correct "^3.0.0" + spdx-expression-parse "^3.0.0" + validate-npm-package-name@^3.0.0, validate-npm-package-name@~3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/validate-npm-package-name/-/validate-npm-package-name-3.0.0.tgz#5fa912d81eb7d0c74afc140de7317f0ca7df437e" @@ -7759,7 +7866,7 @@ wrap-ansi@^2.0.0: string-width "^1.0.1" strip-ansi "^3.0.1" -wrappy@1, wrappy@~1.0.2: +wrappy@1: version "1.0.2" resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f" From 7059470c37e3ddc75961535f9028a02dc980a45a Mon Sep 17 00:00:00 2001 From: mirathewhite Date: Fri, 28 Sep 2018 11:31:27 -0400 Subject: [PATCH 15/74] [CENT-331]: Unify checkVariables and checkState (#221) * add ControllerState object to ControllerTestUtils.js * checkVariables takes as input either FiatTokenV1 or MintController * replaced literal objects with actual objects * Using library funciton clone(), removing logObject, and creating checkMINTp0 function for unit tests * removed unused clone code * Updated yarn.lock and package.json to use yarn 1.10.1 --- package.json | 4 +- test/AccountUtils.js | 35 +----- test/TokenTestUtils.js | 19 +++- test/minting/ControllerTestUtils.js | 27 +++-- test/minting/MintControllerTests.js | 93 ++++++---------- test/minting/MintControllerUtils.js | 52 +++++---- yarn.lock | 167 +++++++++++++++++++++------- 7 files changed, 227 insertions(+), 170 deletions(-) diff --git a/package.json b/package.json index 2c77626fe..6a4648069 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "dependencies": { "assert-diff": "^1.2.6", "bignumber.js": "6.0.0", + "clone": "2.1.2", "ethereum-input-data-decoder": "0.0.12", "ethereumjs-abi": "^0.6.5", "ethereumjs-tx": "1.3.1", @@ -33,11 +34,12 @@ "ganache-cli": "6.1.0", "lodash": "^4.17.10", "mkdirp": "^0.5.1", - "npm": "^6.2.0", + "npm": "^6.4.1", "openzeppelin-solidity": "1.11.0", "path": "^0.12.7", "q": "^1.5.1", "truffle-hdwallet-provider": "^0.0.6", + "yarn": "^1.10.1", "zos-lib": "1.3.0" }, "devDependencies": { diff --git a/test/AccountUtils.js b/test/AccountUtils.js index 1660839e3..2be04f3c2 100644 --- a/test/AccountUtils.js +++ b/test/AccountUtils.js @@ -3,6 +3,7 @@ var debugLogging = false; var assertDiff = require('assert-diff'); assertDiff.options.strict = true; +var clone = require('clone'); // named list of all accounts var Accounts = { @@ -54,26 +55,10 @@ function setAccountDefault(accounts, defaultValue) { return result; } -// Clones a state object -function cloneState(state) { - // for each item in customVars, set the item in expectedState - var clone = {}; - for (var attr in state) { - var attrValue = state[attr]; - if(isLiteral(attrValue)) { - clone[attr] = state[attr]; - } else { - clone[attr] = cloneState(attrValue); - } - } - return clone; -} - // return an expectedState that combines customState with the emptyState -// todo: after merge, integrate this with TokenTestUtils.js function buildExpectedPartialState(emptyState, customState, ignoreExtraCustomVars) { // for each item in customVars, set the item in expectedState - var expectedState = cloneState(emptyState); + var expectedState = clone(emptyState); for( var variableName in customState) { // do I ignore extra values @@ -102,7 +87,6 @@ function buildExpectedPartialState(emptyState, customState, ignoreExtraCustomVar // getActualState: async function(token, accounts) => state // accounts: list of accounts on which to evaluate mappings // ignoreExtraCustomVars: ignore _customVars names that are not in the emptyState -// todo: after merge, integrate this with TokenTestUtils.js async function checkState(_tokens, _customVars, emptyState, getActualState, accounts, ignoreExtraCustomVars) { // Iterate over array of tokens. var numTokens = _tokens.length; @@ -141,26 +125,11 @@ function isLiteral(object) { return true; } -// Turns a simple literal object into a printable string -function logObject(object) { - var output = ''; - for (var property in object) { - if(isLiteral(object[property])) { - output += property + ':\n' + logObject(object[property]); - } else { - output += property + ': ' + object[property]+';\n '; - } - } - return output; -} - module.exports = { Accounts: Accounts, AccountPrivateKeys: AccountPrivateKeys, setAccountDefault: setAccountDefault, - cloneState: cloneState, buildExpectedPartialState: buildExpectedPartialState, checkState: checkState, - logObject: logObject, getAccountState: getAccountState, } \ No newline at end of file diff --git a/test/TokenTestUtils.js b/test/TokenTestUtils.js index 28a3ece28..f9cd4fb67 100644 --- a/test/TokenTestUtils.js +++ b/test/TokenTestUtils.js @@ -315,9 +315,10 @@ async function checkVariables(_tokens, _customVars) { for (n = 0; n < numTokens; n++) { var token = _tokens[n]; var customVars = _customVars[n]; + let expectedState = buildExpectedState(token, customVars); if (debugLogging) { - console.log(util.inspect(expectedState, { showHidden: false, depth: null })) + console.log(util.inspect(expectedState, { showHidden: false, depth: null })) } let actualState = await getActualState(token); @@ -335,6 +336,21 @@ async function checkVariables(_tokens, _customVars) { } } +// All MINT p0 tests will call this function. +// _contracts is an array of exactly two values: a FiatTokenV1 and a MintController +// _customVars is an array of exactly two values: the expected state of the FiatTokenV1 +// and the expected state of the MintController +async function checkMINTp0(_contracts, _customVars) { + assert.equal(_contracts.length, 2); + assert.equal(_customVars.length, 2); + + // the first is a FiatTokenV1 + await checkVariables([_contracts[0]], [_customVars[0]]); + + // the second is a MintController + await _customVars[1].checkState(_contracts[1]); +} + // build up actualState object to compare to expectedState object async function getActualState(token) { return Q.all([ @@ -925,6 +941,7 @@ module.exports = { checkAdminChangedEvent: checkAdminChangedEvent, buildExpectedState, checkVariables: checkVariables, + checkMINTp0: checkMINTp0, setMinter: setMinter, mint: mint, burn: burn, diff --git a/test/minting/ControllerTestUtils.js b/test/minting/ControllerTestUtils.js index d11520538..a94c31262 100644 --- a/test/minting/ControllerTestUtils.js +++ b/test/minting/ControllerTestUtils.js @@ -14,15 +14,22 @@ var setAccountDefault = AccountUtils.setAccountDefault; var checkState = AccountUtils.checkState; var getAccountState = AccountUtils.getAccountState; +function ControllerState(owner, controllers) { + this.owner = owner; + this.controllers = controllers; + this.checkState = checkControllerState; + this.checkState = async function(controllerContract) {await checkControllerState(controllerContract, this)}; +} + // Default state of Controller when it is deployed -var controllerEmptyState = { - 'owner': Accounts.mintOwnerAccount, - 'controllers': setAccountDefault(Accounts, "0x0000000000000000000000000000000000000000") -}; +var controllerEmptyState = new ControllerState( + Accounts.mintOwnerAccount, + setAccountDefault(Accounts, "0x0000000000000000000000000000000000000000") +); // Checks the state of an array of controller contracts -async function checkControllerState(controllers, customVars, ignoreExtraStateVariables) { - await checkState(controllers, customVars, controllerEmptyState, getActualControllerState, Accounts, ignoreExtraStateVariables); +async function checkControllerState(controller, customState) { + await checkState(controller, customState, controllerEmptyState, getActualControllerState, Accounts, true); } // Gets the actual state of the controller contract. @@ -40,12 +47,8 @@ async function getActualControllerState(controllerContract, accounts) { owner, controllerState, ) { - var actualState = { - 'owner': owner, - 'controllers': controllerState, - }; - return actualState; - }) + return new ControllerState(owner, controllerState); + }); } module.exports = { diff --git a/test/minting/MintControllerTests.js b/test/minting/MintControllerTests.js index fb03fad80..d7b278c4e 100644 --- a/test/minting/MintControllerTests.js +++ b/test/minting/MintControllerTests.js @@ -2,12 +2,16 @@ var MintController = artifacts.require('minting/MintController'); var BigNumber = require('bignumber.js'); var tokenUtils = require('./../TokenTestUtils'); -var checkVariables = tokenUtils.checkVariables; +var checkMINTp0 = tokenUtils.checkMINTp0; var expectRevert = tokenUtils.expectRevert; +var bigZero = tokenUtils.bigZero; + +var clone = require('clone'); var mintUtils = require('./MintControllerUtils.js'); var AccountUtils = require('./../AccountUtils.js'); var Accounts = AccountUtils.Accounts; +var MintControllerState = AccountUtils.MintControllerState; var initializeTokenWithProxyAndMintController = mintUtils.initializeTokenWithProxyAndMintController; var checkMintControllerState = mintUtils.checkMintControllerState; @@ -15,37 +19,30 @@ async function run_tests(newToken, accounts) { beforeEach('Make fresh token contract', async function () { rawToken = await newToken(); - var tokenConfig = await initializeTokenWithProxyAndMintController(rawToken); + tokenConfig = await initializeTokenWithProxyAndMintController(rawToken); token = tokenConfig.token; mintController = tokenConfig.mintController; + expectedMintControllerState = clone(tokenConfig.customState); + expectedTokenState = [{ 'variable': 'masterMinter', 'expectedValue': mintController.address }]; }); it('should mint through mint controller', async function () { var amount = 5000; await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); await mintController.configureMinter(amount, {from: Accounts.controller1Account}); - customState = { - 'minterManager': token.address, - 'controllers': {'controller1Account': Accounts.minterAccount } - } - await checkMintControllerState([mintController], [customState]); + expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; await token.mint(Accounts.arbitraryAccount, amount, {from: Accounts.minterAccount}); - customVars = [ - { 'variable': 'masterMinter', 'expectedValue': mintController.address }, + expectedTokenState.push( { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'balances.arbitraryAccount', 'expectedValue': new BigNumber(amount) }, { 'variable': 'totalSupply', 'expectedValue': new BigNumber(amount)} - ]; - await checkVariables([token], [customVars]); + ); + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); }); it('initial state', async function () { - customState = { - 'minterManager': token.address, - }; - - await checkMintControllerState([mintController], [customState]); + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); }); it('only owner configures controller', async function () { @@ -55,17 +52,12 @@ async function run_tests(newToken, accounts) { it('remove controller', async function () { var amount = 5000; await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - customState = { - 'minterManager': token.address, - 'controllers': {'controller1Account': Accounts.minterAccount } - } - await checkMintControllerState([mintController], [customState]); + expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); await mintController.removeController(Accounts.controller1Account, {from: Accounts.mintOwnerAccount}); - customState = { - 'minterManager': token.address - }; - await checkMintControllerState([mintController], [customState]); + expectedMintControllerState.controllers['controller1Account'] = bigZero; + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); }); it('only owner can remove controller', async function () { @@ -74,6 +66,8 @@ async function run_tests(newToken, accounts) { it('sets token', async function () { await mintController.setMinterManager(mintController.address, {from: Accounts.mintOwnerAccount}); + expectedMintControllerState.minterManager = mintController.address; + checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); }); it('only owner sets token', async function () { @@ -85,25 +79,19 @@ async function run_tests(newToken, accounts) { var amount = 500; await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); await mintController.configureMinter(amount, {from: Accounts.controller1Account}); - customState = { - 'minterManager': token.address, - 'controllers': {'controller1Account': Accounts.minterAccount } - } - await checkMintControllerState([mintController], [customState]); - customVars = [ - { 'variable': 'masterMinter', 'expectedValue': mintController.address }, + expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; + expectedTokenState.push( { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount) }, - ]; - await checkVariables([token], [customVars]); + ); + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); // remove minter await mintController.removeMinter({from: Accounts.controller1Account}); - await checkMintControllerState([mintController], [customState]); - customVars = [ + expectedTokenState = [ { 'variable': 'masterMinter', 'expectedValue': mintController.address }, ]; - await checkVariables([token], [customVars]); + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); }); it('only controller removes a minter', async function () { @@ -119,27 +107,21 @@ async function run_tests(newToken, accounts) { var amount = 500; await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); await mintController.configureMinter(amount, {from: Accounts.controller1Account}); - customState = { - 'minterManager': token.address, - 'controllers': {'controller1Account': Accounts.minterAccount } - } - await checkMintControllerState([mintController], [customState]); - customVars = [ - { 'variable': 'masterMinter', 'expectedValue': mintController.address }, + expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; + expectedTokenState.push( { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount) }, - ]; - await checkVariables([token], [customVars]); + ); + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); // increment minter allowance await mintController.incrementMinterAllowance(amount, {from: Accounts.controller1Account}); - await checkMintControllerState([mintController], [customState]); - customVars = [ + expectedTokenState = [ { 'variable': 'masterMinter', 'expectedValue': mintController.address }, { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount*2) }, ]; - await checkVariables([token], [customVars]); + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); }); it('only controller increments allowance', async function () { @@ -150,21 +132,12 @@ async function run_tests(newToken, accounts) { // configure controller but not minter var amount = 500; await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - customState = { - 'minterManager': token.address, - 'controllers': {'controller1Account': Accounts.minterAccount } - } - await checkMintControllerState([mintController], [customState]); - customVars = [ - { 'variable': 'masterMinter', 'expectedValue': mintController.address }, - ]; - await checkVariables([token], [customVars]); + expectedMintControllerState.controllers['controller1Account']= Accounts.minterAccount; + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); // increment minter allowance await expectRevert(mintController.incrementMinterAllowance(amount, {from: Accounts.controller1Account})); }); - - } var testWrapper = require('./../TestWrapper'); diff --git a/test/minting/MintControllerUtils.js b/test/minting/MintControllerUtils.js index 46188b4ef..eca81121e 100644 --- a/test/minting/MintControllerUtils.js +++ b/test/minting/MintControllerUtils.js @@ -1,5 +1,6 @@ var BigNumber = require('bignumber.js'); var bigZero = new BigNumber(0); +var clone = require('clone'); var tokenUtils = require('./../TokenTestUtils'); var initializeTokenWithProxy = tokenUtils.initializeTokenWithProxy; @@ -13,42 +14,49 @@ var getAccountState = AccountUtils.getAccountState; var ControllerUtils = require('./ControllerTestUtils'); var checkControllerState = ControllerUtils.checkControllerState; - -// Deploys a FiatTokenV1 with a MintController contract as the masterMinter. -// Uses the same workflow we would do in production - first deploy FiatToken then set the masterMinter. -async function initializeTokenWithProxyAndMintController(rawToken) { - var tokenConfig = await initializeTokenWithProxy(rawToken); - var mintController = await MintController.new(tokenConfig.token.address, {from:Accounts.mintOwnerAccount}); - await tokenConfig.token.updateMasterMinter(mintController.address, {from:Accounts.tokenOwnerAccount}); - var tokenConfigWithMinter = { - proxy: tokenConfig.proxy, - token: tokenConfig.token, - mintController: mintController - }; - return tokenConfigWithMinter; +function MintControllerState(owner, controllers, minterManager) { + this.owner = owner; + this.controllers = controllers; + this.minterManager = minterManager; + this.checkState = async function(mintController) {await checkMintControllerState(mintController, this)}; +// this.clone = function(){return clone(this);}; +// this.clone = function(){return new MintControllerState(this.owner, clone(this.controllers), this.minterManager)}; } // Default state of MintController when it is deployed -var mintControllerEmptyState = { - 'minterManager' : bigZero, -}; +var mintControllerEmptyState = new MintControllerState(null, {}, bigZero); // Checks the state of the mintController contract -async function checkMintControllerState(mintControllers, customVars) { - await checkControllerState(mintControllers, customVars, true); - await checkState(mintControllers, customVars, mintControllerEmptyState, getActualMintControllerState, Accounts, true); +async function checkMintControllerState(mintController, customState) { + await checkControllerState(mintController, customState); + await checkState(mintController, customState, mintControllerEmptyState, getActualMintControllerState, Accounts, true); } // Gets the actual state of the mintController contract. // Evaluates all mappings on the provided accounts. async function getActualMintControllerState(mintController, accounts) { - return { - 'minterManager': await mintController.minterManager.call() + var minterManager = await mintController.minterManager.call(); + return new MintControllerState(null, {}, minterManager); +} + +// Deploys a FiatTokenV1 with a MintController contract as the masterMinter. +// Uses the same workflow we would do in production - first deploy FiatToken then set the masterMinter. +async function initializeTokenWithProxyAndMintController(rawToken) { + var tokenConfig = await initializeTokenWithProxy(rawToken); + var mintController = await MintController.new(tokenConfig.token.address, {from:Accounts.mintOwnerAccount}); + await tokenConfig.token.updateMasterMinter(mintController.address, {from:Accounts.tokenOwnerAccount}); + var tokenConfigWithMinter = { + proxy: tokenConfig.proxy, + token: tokenConfig.token, + mintController: mintController, + customState: new MintControllerState(null, {}, tokenConfig.token.address) }; + return tokenConfigWithMinter; } module.exports = { initializeTokenWithProxyAndMintController: initializeTokenWithProxyAndMintController, - checkMintControllerState: checkMintControllerState + checkMintControllerState: checkMintControllerState, + MintControllerState: MintControllerState } \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 8614b4960..07910ca5a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -23,9 +23,9 @@ version "0.7.0" resolved "https://registry.yarnpkg.com/@sindresorhus/is/-/is-0.7.0.tgz#9a06f4f137ee84d7df0460c1fdb1135ffa6c50fd" -JSONStream@^1.3.3: - version "1.3.3" - resolved "https://registry.yarnpkg.com/JSONStream/-/JSONStream-1.3.3.tgz#27b4b8fbbfeab4e71bcf551e7f27be8d952239bf" +JSONStream@^1.3.4: + version "1.3.4" + resolved "https://registry.yarnpkg.com/JSONStream/-/JSONStream-1.3.4.tgz#615bb2adb0cd34c8f4c447b5f6512fa1d8f16a2e" dependencies: jsonparse "^1.2.0" through ">=2.2.7 <3" @@ -1329,6 +1329,25 @@ cacache@^11.0.1, cacache@^11.0.2: unique-filename "^1.1.0" y18n "^4.0.0" +cacache@^11.2.0: + version "11.2.0" + resolved "https://registry.yarnpkg.com/cacache/-/cacache-11.2.0.tgz#617bdc0b02844af56310e411c0878941d5739965" + dependencies: + bluebird "^3.5.1" + chownr "^1.0.1" + figgy-pudding "^3.1.0" + glob "^7.1.2" + graceful-fs "^4.1.11" + lru-cache "^4.1.3" + mississippi "^3.0.0" + mkdirp "^0.5.1" + move-concurrently "^1.0.1" + promise-inflight "^1.0.1" + rimraf "^2.6.2" + ssri "^6.0.0" + unique-filename "^1.1.0" + y18n "^4.0.0" + cache-base@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/cache-base/-/cache-base-1.0.1.tgz#0a7f46416831c8b662ee36fe4e7c59d76f666ab2" @@ -1482,6 +1501,10 @@ ci-info@^1.0.0: version "1.1.3" resolved "https://registry.yarnpkg.com/ci-info/-/ci-info-1.1.3.tgz#710193264bb05c77b8c90d02f5aaf22216a667b2" +ci-info@^1.4.0: + version "1.6.0" + resolved "https://registry.yarnpkg.com/ci-info/-/ci-info-1.6.0.tgz#2ca20dbb9ceb32d4524a683303313f0304b1e497" + cidr-regex@^2.0.8: version "2.0.9" resolved "https://registry.yarnpkg.com/cidr-regex/-/cidr-regex-2.0.9.tgz#9c17bb2b18e15af07f7d0c3b994b961d687ed1c9" @@ -1605,14 +1628,14 @@ clone-stats@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/clone-stats/-/clone-stats-1.0.0.tgz#b3782dff8bb5474e18b9b6bf0fdfe782f8777680" +clone@2.1.2, clone@^2.0.0: + version "2.1.2" + resolved "https://registry.yarnpkg.com/clone/-/clone-2.1.2.tgz#1b7f4b9f591f1e8f83670401600345a02887435f" + clone@^1.0.0, clone@^1.0.2: version "1.0.4" resolved "https://registry.yarnpkg.com/clone/-/clone-1.0.4.tgz#da309cc263df15994c688ca902179ca3c7cd7c7e" -clone@^2.0.0: - version "2.1.2" - resolved "https://registry.yarnpkg.com/clone/-/clone-2.1.2.tgz#1b7f4b9f591f1e8f83670401600345a02887435f" - clone@^2.1.1: version "2.1.1" resolved "https://registry.yarnpkg.com/clone/-/clone-2.1.1.tgz#d217d1e961118e3ac9a4b8bba3285553bf647cdb" @@ -2779,6 +2802,10 @@ figgy-pudding@^3.0.0, figgy-pudding@^3.1.0, figgy-pudding@^3.2.0: version "3.2.0" resolved "https://registry.yarnpkg.com/figgy-pudding/-/figgy-pudding-3.2.0.tgz#464626b73d7b0fc045a99753d191b0785957ff73" +figgy-pudding@^3.4.1: + version "3.5.1" + resolved "https://registry.yarnpkg.com/figgy-pudding/-/figgy-pudding-3.5.1.tgz#862470112901c727a0e495a80744bd5baa1d6790" + figures@^1.7.0: version "1.7.0" resolved "https://registry.yarnpkg.com/figures/-/figures-1.7.0.tgz#cbe1e3affcf1cd44b80cadfed28dc793a9701d2e" @@ -3489,7 +3516,7 @@ homedir-polyfill@^1.0.1: dependencies: parse-passwd "^1.0.0" -hosted-git-info@^2.1.4, hosted-git-info@^2.6.0: +hosted-git-info@^2.1.4, hosted-git-info@^2.6.0, hosted-git-info@^2.7.1: version "2.7.1" resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.7.1.tgz#97f236977bd6e125408930ff6de3eec6281ec047" @@ -3559,7 +3586,7 @@ iferr@^0.1.5: version "0.1.5" resolved "https://registry.yarnpkg.com/iferr/-/iferr-0.1.5.tgz#c60eed69e6d8fdb6b3104a1fcbca1c192dc5b501" -iferr@^1.0.0: +iferr@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/iferr/-/iferr-1.0.2.tgz#e9fde49a9da06dc4a4194c6c9ed6d08305037a6d" @@ -4327,9 +4354,9 @@ levn@~0.3.0: prelude-ls "~1.1.2" type-check "~0.3.2" -libcipm@^2.0.0: - version "2.0.1" - resolved "https://registry.yarnpkg.com/libcipm/-/libcipm-2.0.1.tgz#2f4ebf8562e0fc6e46f415373674e4cf3ac4b9ba" +libcipm@^2.0.2: + version "2.0.2" + resolved "https://registry.yarnpkg.com/libcipm/-/libcipm-2.0.2.tgz#4f38c2b37acf2ec156936cef1cbf74636568fc7b" dependencies: bin-links "^1.1.2" bluebird "^3.5.1" @@ -5002,7 +5029,7 @@ node-forge@^0.7.4: version "0.7.5" resolved "https://registry.yarnpkg.com/node-forge/-/node-forge-0.7.5.tgz#6c152c345ce11c52f465c2abd957e8639cd674df" -node-gyp@^3.6.2, node-gyp@^3.7.0: +node-gyp@^3.6.2: version "3.7.0" resolved "https://registry.yarnpkg.com/node-gyp/-/node-gyp-3.7.0.tgz#789478e8f6c45e277aa014f3e28f958f286f9203" dependencies: @@ -5019,6 +5046,23 @@ node-gyp@^3.6.2, node-gyp@^3.7.0: tar "^2.0.0" which "1" +node-gyp@^3.8.0: + version "3.8.0" + resolved "https://registry.yarnpkg.com/node-gyp/-/node-gyp-3.8.0.tgz#540304261c330e80d0d5edce253a68cb3964218c" + dependencies: + fstream "^1.0.0" + glob "^7.0.3" + graceful-fs "^4.1.2" + mkdirp "^0.5.0" + nopt "2 || 3" + npmlog "0 || 1 || 2 || 3 || 4" + osenv "0" + request "^2.87.0" + rimraf "2" + semver "~5.3.0" + tar "^2.0.0" + which "1" + node-pre-gyp@^0.10.0: version "0.10.3" resolved "https://registry.yarnpkg.com/node-pre-gyp/-/node-pre-gyp-0.10.3.tgz#3070040716afdc778747b61b6887bf78880b80fc" @@ -5111,6 +5155,19 @@ npm-lifecycle@^2.0.3: umask "^1.1.0" which "^1.3.0" +npm-lifecycle@^2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/npm-lifecycle/-/npm-lifecycle-2.1.0.tgz#1eda2eedb82db929e3a0c50341ab0aad140ed569" + dependencies: + byline "^5.0.0" + graceful-fs "^4.1.11" + node-gyp "^3.8.0" + resolve-from "^4.0.0" + slide "^1.1.6" + uid-number "0.0.6" + umask "^1.1.0" + which "^1.3.1" + npm-logical-tree@^1.2.1: version "1.2.1" resolved "https://registry.yarnpkg.com/npm-logical-tree/-/npm-logical-tree-1.2.1.tgz#44610141ca24664cad35d1e607176193fd8f5b88" @@ -5124,7 +5181,7 @@ npm-logical-tree@^1.2.1: semver "^5.5.0" validate-npm-package-name "^3.0.0" -npm-packlist@^1.1.10, npm-packlist@^1.1.6, npm-packlist@~1.1.10: +npm-packlist@^1.1.10, npm-packlist@^1.1.11, npm-packlist@^1.1.6: version "1.1.11" resolved "https://registry.yarnpkg.com/npm-packlist/-/npm-packlist-1.1.11.tgz#84e8c683cbe7867d34b1d357d893ce29e28a02de" dependencies: @@ -5145,7 +5202,7 @@ npm-profile@^3.0.2: aproba "^1.1.2 || 2" make-fetch-happen "^2.5.0 || 3 || 4" -npm-registry-client@^8.5.1: +npm-registry-client@^8.6.0: version "8.6.0" resolved "https://registry.yarnpkg.com/npm-registry-client/-/npm-registry-client-8.6.0.tgz#7f1529f91450732e89f8518e0f21459deea3e4c4" dependencies: @@ -5194,11 +5251,11 @@ npm-user-validate@~1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/npm-user-validate/-/npm-user-validate-1.0.0.tgz#8ceca0f5cea04d4e93519ef72d0557a75122e951" -npm@^6.2.0: - version "6.2.0" - resolved "https://registry.yarnpkg.com/npm/-/npm-6.2.0.tgz#2cee4b52825a91f531cd324a3b0f6e105be40c16" +npm@^6.4.1: + version "6.4.1" + resolved "https://registry.yarnpkg.com/npm/-/npm-6.4.1.tgz#4f39f9337b557a28faed4a771d5c8802d6b4288b" dependencies: - JSONStream "^1.3.3" + JSONStream "^1.3.4" abbrev "~1.1.1" ansicolors "~0.3.2" ansistyles "~0.1.3" @@ -5207,9 +5264,10 @@ npm@^6.2.0: bin-links "^1.1.2" bluebird "~3.5.1" byte-size "^4.0.3" - cacache "^11.0.2" + cacache "^11.2.0" call-limit "~1.1.0" chownr "~1.0.1" + ci-info "^1.4.0" cli-columns "^3.1.2" cli-table3 "^0.5.0" cmd-shim "~2.0.2" @@ -5219,7 +5277,7 @@ npm@^6.2.0: detect-newline "^2.1.0" dezalgo "~1.0.3" editor "~1.0.0" - figgy-pudding "^3.1.0" + figgy-pudding "^3.4.1" find-npm-prefix "^1.0.2" fs-vacuum "~1.2.10" fs-write-stream-atomic "~1.0.10" @@ -5227,8 +5285,8 @@ npm@^6.2.0: glob "~7.1.2" graceful-fs "~4.1.11" has-unicode "~2.0.1" - hosted-git-info "^2.6.0" - iferr "^1.0.0" + hosted-git-info "^2.7.1" + iferr "^1.0.2" inflight "~1.0.6" inherits "~2.0.3" ini "^1.3.5" @@ -5236,7 +5294,7 @@ npm@^6.2.0: is-cidr "^2.0.6" json-parse-better-errors "^1.0.2" lazy-property "~1.0.0" - libcipm "^2.0.0" + libcipm "^2.0.2" libnpmhook "^4.0.1" libnpx "^10.2.0" lock-verify "^2.0.2" @@ -5251,23 +5309,23 @@ npm@^6.2.0: mississippi "^3.0.0" mkdirp "~0.5.1" move-concurrently "^1.0.1" - node-gyp "^3.7.0" + node-gyp "^3.8.0" nopt "~4.0.1" normalize-package-data "~2.4.0" npm-audit-report "^1.3.1" npm-cache-filename "~1.0.2" npm-install-checks "~3.0.0" - npm-lifecycle "^2.0.3" + npm-lifecycle "^2.1.0" npm-package-arg "^6.1.0" - npm-packlist "~1.1.10" + npm-packlist "^1.1.11" npm-pick-manifest "^2.1.0" npm-profile "^3.0.2" - npm-registry-client "^8.5.1" + npm-registry-client "^8.6.0" npm-registry-fetch "^1.1.0" npm-user-validate "~1.0.0" npmlog "~4.1.2" once "~1.4.0" - opener "~1.4.3" + opener "^1.5.0" osenv "^0.1.5" pacote "^8.1.6" path-is-inside "~1.0.2" @@ -5281,7 +5339,7 @@ npm@^6.2.0: read-package-json "^2.0.13" read-package-tree "^5.2.1" readable-stream "^2.3.6" - request "^2.81.0" + request "^2.88.0" retry "^0.12.0" rimraf "~2.6.2" safe-buffer "^5.1.2" @@ -5291,7 +5349,8 @@ npm@^6.2.0: sorted-object "~2.0.1" sorted-union-stream "~2.1.3" ssri "^6.0.0" - tar "^4.4.4" + stringify-package "^1.0.0" + tar "^4.4.6" text-table "~0.2.0" tiny-relative-date "^1.3.0" uid-number "0.0.6" @@ -5300,11 +5359,10 @@ npm@^6.2.0: unpipe "~1.0.0" update-notifier "^2.5.0" uuid "^3.3.2" - validate-npm-package-license "^3.0.3" + validate-npm-package-license "^3.0.4" validate-npm-package-name "~3.0.0" which "^1.3.1" worker-farm "^1.6.0" - wrappy "~1.0.2" write-file-atomic "^2.3.0" "npmlog@0 || 1 || 2 || 3 || 4", "npmlog@2 || ^3.1.0 || ^4.0.0", npmlog@^4.0.2, npmlog@~4.1.2: @@ -5408,9 +5466,9 @@ onetime@^2.0.0: dependencies: mimic-fn "^1.0.0" -opener@~1.4.3: - version "1.4.3" - resolved "https://registry.yarnpkg.com/opener/-/opener-1.4.3.tgz#5c6da2c5d7e5831e8ffa3964950f8d6674ac90b8" +opener@^1.5.0: + version "1.5.1" + resolved "https://registry.yarnpkg.com/opener/-/opener-1.5.1.tgz#6d2f0e77f1a0af0032aca716c2c1fbb8e7e8abed" openurl@1.1.1: version "1.1.1" @@ -6233,7 +6291,7 @@ req-from@^1.0.1: tunnel-agent "^0.6.0" uuid "^3.0.0" -request@^2.67.0: +request@^2.67.0, request@^2.87.0, request@^2.88.0: version "2.88.0" resolved "https://registry.yarnpkg.com/request/-/request-2.88.0.tgz#9c2fca4f7d35b592efe57c7f0a55e81052124fef" dependencies: @@ -6258,7 +6316,7 @@ request@^2.67.0: tunnel-agent "^0.6.0" uuid "^3.3.2" -request@^2.74.0, request@^2.81.0: +request@^2.74.0: version "2.87.0" resolved "https://registry.yarnpkg.com/request/-/request-2.87.0.tgz#32f00235cd08d482b4d0d68db93a829c0ed5756e" dependencies: @@ -7066,6 +7124,10 @@ string_decoder@~1.1.1: dependencies: safe-buffer "~5.1.0" +stringify-package@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/stringify-package/-/stringify-package-1.0.0.tgz#e02828089333d7d45cd8c287c30aa9a13375081b" + stringstream@~0.0.4: version "0.0.6" resolved "https://registry.yarnpkg.com/stringstream/-/stringstream-0.0.6.tgz#7880225b0d4ad10e30927d167a1d6f2fd3b33a72" @@ -7177,7 +7239,7 @@ tar@^2.0.0: fstream "^1.0.2" inherits "2" -tar@^4, tar@^4.4.3, tar@^4.4.4: +tar@^4, tar@^4.4.3: version "4.4.4" resolved "https://registry.yarnpkg.com/tar/-/tar-4.4.4.tgz#ec8409fae9f665a4355cc3b4087d0820232bb8cd" dependencies: @@ -7189,6 +7251,18 @@ tar@^4, tar@^4.4.3, tar@^4.4.4: safe-buffer "^5.1.2" yallist "^3.0.2" +tar@^4.4.6: + version "4.4.6" + resolved "https://registry.yarnpkg.com/tar/-/tar-4.4.6.tgz#63110f09c00b4e60ac8bcfe1bf3c8660235fbc9b" + dependencies: + chownr "^1.0.1" + fs-minipass "^1.2.5" + minipass "^2.3.3" + minizlib "^1.1.0" + mkdirp "^0.5.0" + safe-buffer "^5.1.2" + yallist "^3.0.2" + temp@^0.8.1: version "0.8.3" resolved "https://registry.yarnpkg.com/temp/-/temp-0.8.3.tgz#e0c6bc4d26b903124410e4fed81103014dfc1f59" @@ -7532,13 +7606,20 @@ v8-compile-cache@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/v8-compile-cache/-/v8-compile-cache-2.0.0.tgz#526492e35fc616864284700b7043e01baee09f0a" -validate-npm-package-license@^3.0.1, validate-npm-package-license@^3.0.3: +validate-npm-package-license@^3.0.1: version "3.0.3" resolved "https://registry.yarnpkg.com/validate-npm-package-license/-/validate-npm-package-license-3.0.3.tgz#81643bcbef1bdfecd4623793dc4648948ba98338" dependencies: spdx-correct "^3.0.0" spdx-expression-parse "^3.0.0" +validate-npm-package-license@^3.0.4: + version "3.0.4" + resolved "https://registry.yarnpkg.com/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz#fc91f6b9c7ba15c857f4cb2c5defeec39d4f410a" + dependencies: + spdx-correct "^3.0.0" + spdx-expression-parse "^3.0.0" + validate-npm-package-name@^3.0.0, validate-npm-package-name@~3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/validate-npm-package-name/-/validate-npm-package-name-3.0.0.tgz#5fa912d81eb7d0c74afc140de7317f0ca7df437e" @@ -7759,7 +7840,7 @@ wrap-ansi@^2.0.0: string-width "^1.0.1" strip-ansi "^3.0.1" -wrappy@1, wrappy@~1.0.2: +wrappy@1: version "1.0.2" resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f" @@ -7951,6 +8032,10 @@ yargs@~3.10.0: decamelize "^1.0.0" window-size "0.1.0" +yarn@^1.10.1: + version "1.10.1" + resolved "https://registry.yarnpkg.com/yarn/-/yarn-1.10.1.tgz#b792ba28f050ae94cd7e719dbca80639d70da76f" + yeast@0.1.2: version "0.1.2" resolved "https://registry.yarnpkg.com/yeast/-/yeast-0.1.2.tgz#008e06d8094320c372dbc2f8ed76a0ca6c8ac419" From 59ec401e96a9b747b3c0b37cdf7fd3e2ae3fa190 Mon Sep 17 00:00:00 2001 From: mirathewhite Date: Fri, 28 Sep 2018 16:30:33 -0400 Subject: [PATCH 16/74] Adding spreadsheets --- ...ContractStateChanges - ABIHackingTests.csv | 18 ++++++ .../ContractStateChanges - EventTests.csv | 18 ++++++ ...ctStateChanges - ExtendedPositiveTests.csv | 37 +++++++++++++ .../ContractStateChanges - MiscTests.csv | 34 ++++++++++++ .../ContractStateChanges - NegativeTests.csv | 49 +++++++++++++++++ .../ContractStateChanges - PositiveTests.csv | 29 ++++++++++ ...tractStateChanges - ProxyNegativeTests.csv | 11 ++++ ...tractStateChanges - ProxyPositiveTests.csv | 15 +++++ ...actStateChanges - UnitTestCompleteness.csv | 36 ++++++++++++ .../MINTp0UnitTests - ABITests.csv | 3 + .../MINTp0UnitTests - ArgumentTests.csv | 20 +++++++ .../MINTp0UnitTests - BasicTests.csv | 55 +++++++++++++++++++ .../MINTp0UnitTests - EndToEndTests.csv | 20 +++++++ .../MINTp0UnitTests - EventTests.csv | 8 +++ 14 files changed, 353 insertions(+) create mode 100644 verification/Spreadsheets/ContractStateChanges - ABIHackingTests.csv create mode 100644 verification/Spreadsheets/ContractStateChanges - EventTests.csv create mode 100644 verification/Spreadsheets/ContractStateChanges - ExtendedPositiveTests.csv create mode 100644 verification/Spreadsheets/ContractStateChanges - MiscTests.csv create mode 100644 verification/Spreadsheets/ContractStateChanges - NegativeTests.csv create mode 100644 verification/Spreadsheets/ContractStateChanges - PositiveTests.csv create mode 100644 verification/Spreadsheets/ContractStateChanges - ProxyNegativeTests.csv create mode 100644 verification/Spreadsheets/ContractStateChanges - ProxyPositiveTests.csv create mode 100644 verification/Spreadsheets/ContractStateChanges - UnitTestCompleteness.csv create mode 100644 verification/Spreadsheets/MINTp0UnitTests - ABITests.csv create mode 100644 verification/Spreadsheets/MINTp0UnitTests - ArgumentTests.csv create mode 100644 verification/Spreadsheets/MINTp0UnitTests - BasicTests.csv create mode 100644 verification/Spreadsheets/MINTp0UnitTests - EndToEndTests.csv create mode 100644 verification/Spreadsheets/MINTp0UnitTests - EventTests.csv diff --git a/verification/Spreadsheets/ContractStateChanges - ABIHackingTests.csv b/verification/Spreadsheets/ContractStateChanges - ABIHackingTests.csv new file mode 100644 index 000000000..01b4a2bac --- /dev/null +++ b/verification/Spreadsheets/ContractStateChanges - ABIHackingTests.csv @@ -0,0 +1,18 @@ +File,Function,Code,Test +Proxy.sol,_delegate,abi056,abi056 Proxy _delegate is internal +Proxy.sol,_fallback,abi058,abi058 Proxy _fallback is internal +AdminUpgradeabilityProxy.sol,_setAdmin,abi053,abi053 AdminUpgradeabillityProxy _setAdmin is internal +UpgradeabilityProxy.sol,_setImplementation,abi050,abi050 Upgradeability implementation is internal +UpgradeabilityProxy.sol,_upgradeTo,abi028,abi028 UpgradeabilityProxy._upgradeTo is internal +AdminUpgradeabilityProxy.sol,_willFallback,abi057,abi057 Proxy _willFallback is internal +Proxy.sol,_willFallback,abi057,abi057 Proxy _willFallback is internal +AdminUpgradeabilityProxy.sol,AdminUpgradeabilityProxy,abi051,abi051 AdminUpgradeabillityProxy constructor is not a function +Blacklistable.sol,Blacklistable,abi040,abi040 Blacklistable constructor is not a function +FiatTokenV1.sol,FiatToken,abi041,abi041 FiatToken constructor is not a function +Ownable.sol,Ownable,abi042,abi042 Ownable constructor is not a function +Pausable.sol,Pausable,abi005,abi005 Pausable constructor is not a function +FiatTokenV1.sol,pause,abi004,abi004 FiatToken pause() is public +FiatTokenProxy.sol,Proxy,abi043,abi043 FiatTokenProxy constructor is not a function +Proxy.sol,Proxy,abi055,abi055 Proxy constructor is not a function +Ownable.sol,setOwner,abi025,abi025 setOwner is internal +UpgradeabilityProxy.sol,UpgradeabilityProxy,abi027,abi027 UpgradeabilityProxy constructor \ No newline at end of file diff --git a/verification/Spreadsheets/ContractStateChanges - EventTests.csv b/verification/Spreadsheets/ContractStateChanges - EventTests.csv new file mode 100644 index 000000000..484979fb4 --- /dev/null +++ b/verification/Spreadsheets/ContractStateChanges - EventTests.csv @@ -0,0 +1,18 @@ +Event(s),File,Function,Code,Test +MinterConfigured,FiatTokenV1,configureMinter,et000,et000 should check MinterConfigured event +"Mint, Transfer",FiatTokenV1,mint,et001,et001 should check Mint/Transfer events +"Burn, Transfer",FiatTokenV1,burn,et002 ,et002 should check Burn/Transfer events +MinterRemoved,FiatTokenV1,removeMinter,et003,et003 should check MinterRemoved event +MasterMinterChanged,FiatTokenV1,updateMasterMinter,et004,et004 should check MasterMinterChanged event +Blacklisted,Blacklistable,blacklist,et005,et005 should check Blacklisted event +UnBlacklisted,Blacklistable,unBlacklist,et006,et006 should check UnBlacklisted event +BlacklisterChanged,Blacklistable,updateBlacklister,et007,et007 should check BlacklisterChanged event +Upgraded,_upgradeTo,UpgradeabilityProxy,et008,et008 should check Upgraded event +AdminChanged,changeAdmin,AdminUpgradeabilityProxy,et009,et009 should check AdminChanged event +OwnershipTransferred,Ownable,transferOwnership,et010,et010 should check OwnershipTransferred event +Approval,FiatTokenV1,approve,et011,et011 should check Approval event +Pause,Pausable,pause,et012,et012 should check Pause event +Unpause,Pausable,unpause,et013,et013 should check Unpause event +PauserChanged,Pausable,updatePauser,et014,et014 should check PauserChanged event +Transfer,FiatTokenV1,transfer,et015,et015 should check Transfer event +Transfer,FiatTokenV1,transferFrom,et016,et016 should check Transfer event in transferFrom \ No newline at end of file diff --git a/verification/Spreadsheets/ContractStateChanges - ExtendedPositiveTests.csv b/verification/Spreadsheets/ContractStateChanges - ExtendedPositiveTests.csv new file mode 100644 index 000000000..15d17ee83 --- /dev/null +++ b/verification/Spreadsheets/ContractStateChanges - ExtendedPositiveTests.csv @@ -0,0 +1,37 @@ +variable type,visibility,variable name,Modification Function,Arguments,Result,Special Condition,Code,Test +mapping(address => bool),internal,blacklisted,blacklist,_account,blacklisted[_account] = true,blacklisted[_account] == true,ept024,ept024 should blacklist a blacklisted address +address,ifAdmin,implementation(),upgradeTo,newImplementation,"sstore(slot, newImplementation)",blacklisted[newImplementation] == true,ept023,ept023 should upgrade to blacklisted address +address,public,blacklister,updateBlacklister,_newBlacklister,blacklister = _newBlacklister,blacklisted[_newBlacklister] == true,ept027,ept027 should updateBlacklister to blacklisted address +address,public,masterMinter,updateMasterMinter,_newMasterMinter,masterMinter = _newMasterMinter,blacklisted[_newMasterMinter ] == true,ept026,ept026 should updateMasterMinter to blacklisted address +mapping(address => uint256),internal,minterAllowed,removeMinter,minter,minterAllowed[minter] = 0,blacklisted[masterMinter ] == true,ept033,ept033 should removeMinter when masterMinter is blacklisted +mapping(address => bool),internal,minters,removeMinter,minter,minters[minter] = false,blacklisted[masterMinter ] == true,ept033,ept033 should removeMinter when masterMinter is blacklisted +address,private,_owner,transferOwnership,newOwner,_owner = newOwner,blacklisted[newOwner] == true,ept029,ept029 should transferOwnership to blacklisted address +address,public,pauser,updatePauser,_newPauser,pauser = _newPauser,blacklisted[_newPauser] == true,ept028,ept028 should updatePauser to blacklisted address +mapping(address => uint256),internal,minterAllowed,configureMinter,"minter, minterAllowedAmount",minterAllowed[minter] = minterAllowedAmount,blacklisted[masterMinter] == true,ept030,ept030 should configureMinter when masterMinter is blacklisted +mapping(address => bool),internal,minters,configureMinter,"minter, minterAllowedAmount",minters[minter] = true ,blacklisted[masterMinter] == true,ept030,ept030 should configureMinter when masterMinter is blacklisted +mapping(address => uint256),internal,minterAllowed,configureMinter,"minter, minterAllowedAmount",minterAllowed[minter] = minterAllowedAmount,blacklisted[minter] == true,ept032,ept032 should configureMinter when minter is blacklisted +mapping(address => bool),internal,minters,configureMinter,"minter, minterAllowedAmount",minters[minter] = true ,blacklisted[minter] == true,ept032,ept032 should configureMinter when minter is blacklisted +mapping(address => uint256),internal,minterAllowed,removeMinter,minter,minterAllowed[minter] = 0,blacklisted[minter] == true,ept034,ept034 should removeMinter when minter is blacklisted +mapping(address => bool),internal,minters,removeMinter,minter,minters[minter] = false,blacklisted[minter] == true,ept034,ept034 should removeMinter when minter is blacklisted +address,ifAdmin,admin(),changeAdmin,newAdmin,"sstore(slot, newAdmin)",blacklisted[msg.sender] == true,ept013,ept013 should changeAdmin when msg.sender blacklisted +address,public,masterMinter,updateMasterMinter,_newMasterMinter,masterMinter = _newMasterMinter,blacklisted[msg.sender] == true,ept014,ept014 should updateMasterMinter when msg.sender blacklisted +address,public,blacklister,updateBlacklister,_newBlacklister,blacklister = _newBlacklister,blacklisted[msg.sender] == true,ept015,ept015 should updateBlacklister when msg.sender blacklisted +address,public,pauser,updatePauser,_newPauser,pauser = _newPauser,blacklisted[msg.sender] == true,ept016,ept016 should updatePauser when msg.sender blacklisted +address,private,_owner,transferOwnership,newOwner,_owner = newOwner,blacklisted[msg.sender] == true,ept017,ept017 should transferOwnership when msg.sender blacklisted +bool,public,paused,pause,NA,paused = true,blacklisted[msg.sender] == true,ept018,ept018 should pause when msg.sender blacklisted +bool,public,paused,unpause,NA,paused = false ,blacklisted[msg.sender] == true,ept019,ept019 should unpause when msg.sender blacklisted +mapping(address => bool),internal,blacklisted,blacklist,_account,blacklisted[_account] = true,blacklisted[msg.sender] == true,ept020,ept020 should blacklist when msg.sender blacklisted +mapping(address => bool),internal,blacklisted,unBlacklist,_account,blacklisted[_account] = false,blacklisted[msg.sender] == true,ept021,ept021 should unBlacklist when msg.sender blacklisted +address,ifAdmin,implementation(),upgradeTo,newImplementation,"sstore(slot, newImplementation)",blacklisted[msg.sender] == true,ept022,ept022 should upgrade when msg.sender blacklisted +address,ifAdmin,admin(),changeAdmin,newAdmin,"sstore(slot, newAdmin)",blacklisted[newAdmin] == true,ept025,ept025 should changeAdmin to blacklisted address +address,ifAdmin,admin(),changeAdmin,newAdmin,"sstore(slot, newAdmin)",paused == true,ept001,ept001 should changeAdmin while paused +address,public,masterMinter,updateMasterMinter,_newMasterMinter,masterMinter = _newMasterMinter,paused == true,ept002,ept002 should updateMasterMinter while paused +address,public,blacklister,updateBlacklister,_newBlacklister,blacklister = _newBlacklister,paused == true,ept003,ept003 should updateBlacklister while paused +address,public,pauser,updatePauser,_newPauser,pauser = _newPauser,paused == true,ept004,ept004 should updatePauser while paused +address,private,_owner,transferOwnership,newOwner,_owner = newOwner,paused == true,ept005,ept005 should transferOwnership while paused +mapping(address => uint256),internal,minterAllowed,removeMinter,minter,minterAllowed[minter] = 0,paused == true,ept006,ept006 should removeMinter while paused +mapping(address => bool),internal,minters,removeMinter,minter,minters[minter] = false,paused == true,ept006,ept006 should removeMinter while paused +address,ifAdmin,implementation(),upgradeTo,newImplementation,"sstore(slot, newImplementation)",paused == true,ept008,ept008 should upgrade while paused +mapping(address => bool),internal,blacklisted,unBlacklist,_account,blacklisted[_account]= false,paused == true,ept035,ept035 should unBlacklist while contract is paused +mapping(address => bool),internal,blacklisted,blacklist,_account,blacklisted[_account]= true,paused == true,ept036,ept036 should blacklist while contract is paused +bool,public,paused,pause,NA,paused = true ,paused == true,ept037,ept037 should pause while contract is paused \ No newline at end of file diff --git a/verification/Spreadsheets/ContractStateChanges - MiscTests.csv b/verification/Spreadsheets/ContractStateChanges - MiscTests.csv new file mode 100644 index 000000000..da25efe45 --- /dev/null +++ b/verification/Spreadsheets/ContractStateChanges - MiscTests.csv @@ -0,0 +1,34 @@ +Code,Test,Test Type +ms001,ms001 no payable function,No Payable Function +ms002,ms002 should transfer to self has correct final balance,Same Address +ms003,ms003 should transferFrom to self from approved account and have correct final balance,Same Address +ms004,ms004 should transferFrom to self from approved self and have correct final balance,Same Address +ms005,ms005 should mint to self with correct final balance,Same Address +ms006,ms006 should approve correct allowance for self,Same Address +ms007,ms007 should configureMinter for masterMinter,Same Address +ms009,ms009 should configure two minters,Multiple Minters +ms010,ms010 should configure two minters and each mint distinct amounts,Multiple Minters +ms011,"ms011 should configure two minters, each minting distinct amounts and then remove one minter",Multiple Minters +ms012,ms012 should configure two minters and adjust both allowances,Multiple Minters +ms013,"ms013 should configure two minters, one with zero allowance fails to mint",Multiple Minters +ms014,ms014 should configure two minters and fail to mint when paused,Multiple Minters +ms015,"ms015 should configure two minters, blacklist one and ensure it cannot mint, then unblacklist and ensure it can mint",Multiple Minters +ms016,"ms016 should configure two minters, each mints to themselves and then burns certain amount",Multiple Minters +ms018,ms018 should approve 0 token allowance with unchanged state,0 Input +ms019,ms019 should transferFrom 0 tokens with unchanged state ,0 Input +ms020,ms020 should transfer 0 tokens with unchanged state,0 Input +ms036,ms036 should get allowance for same address,Same Address +ms039 ,ms039 should return true on mint,Return Value +ms040 ,ms040 should return true on approve,Return Value +ms041 ,ms041 should return true on transferFrom,Return Value +ms042 ,ms042 should return true on transfer,Return Value +ms043 ,ms043 should return true on configureMinter,Return Value +ms044 ,ms044 should return true on removeMinter,Return Value +ms045,"ms045 initialized should be in slot 8, byte 21",Slot Storage +ms046,ms046 initialized should be 0 before initialization,Slot Storage +ms047 -p,ms047 configureMinter works on amount=2^256-1,2^256-1 Input +ms048 -p,ms048 mint works on amount=2^256-1,2^256-1 Input +ms049 -p,ms049 burn on works on amount=2^256-1,2^256-1 Input +ms050 -p,ms050 approve works on amount=2^256-1,2^256-1 Input +ms051 -p,ms051 transfer works on amount=2^256-1,2^256-1 Input +ms052 -p,ms052 transferFrom works on amount=2^256-1,2^256-1 Input \ No newline at end of file diff --git a/verification/Spreadsheets/ContractStateChanges - NegativeTests.csv b/verification/Spreadsheets/ContractStateChanges - NegativeTests.csv new file mode 100644 index 000000000..7c968283e --- /dev/null +++ b/verification/Spreadsheets/ContractStateChanges - NegativeTests.csv @@ -0,0 +1,49 @@ +Function,Restriction,Code,Test +approve,blacklisted[msg.sender] == false,nt009,nt009 should fail to approve when msg.sender is blacklisted +approve,blacklisted[_spender] == false,nt008,nt008 should fail to approve when spender is blacklisted +approve,paused == false,nt010,nt010 should fail to approve when contract is paused +blacklist,msg.sender == blacklister,nt042,nt042 should fail to blacklist when sender is not blacklister +burn,_amount > 0,nt056,nt056 should fail to burn when amount = 0 +burn,_amount >= 0,nt032,nt032 should fail to burn when amount is -1 +burn,balances[msg.sender] >= _amount,nt031,nt031 should fail to burn when balance is less than amount +burn,blacklisted[msg.sender] ==false,nt033,nt033 should fail to burn when sender is blacklisted +burn,minters[msg.sender] == true,nt035,nt035 should fail to burn when sender is not minter +burn,minters[msg.sender] == true,nt036,nt036 should fail to burn after removeMinter +burn,paused == false,nt034,nt034 should fail to burn when paused +configureMinter,msg.sender == masterMinter,nt026,nt026 should fail to configureMinter when sender is not masterMinter +configureMinter,paused == false,nt028,nt028 should fail to configureMinter when paused +initialize,_blacklister != address(0),nt062,nt062 initialize should fail when _blacklister is 0x0 +initialize,_masterMinter != address(0),nt060,nt060 initialize should fail when _masterMinter is 0x0 +initialize,_owner != address(0),nt063,nt063 initialize should fail when _owner is 0x0 +initialize,_pauser != address(0),nt061,nt061 initialize should fail when _pauser is 0x0 +mint,_amount > 0,nt055,nt055 should fail to mint when amount = 0 +mint,blacklisted[msg.sender] == false,nt003,nt003 should fail to mint when msg.sender is blacklisted +mint,blacklisted[_to] == false,nt004,nt004 should fail to mint when recipient is blacklisted +mint,minterAllowed[msg.sender] >= amount,nt005,nt005 should fail to mint when allowance of minter is less than amount +mint,minters[msg.sender] == true,nt002,nt002 should fail to mint when msg.sender is not a minter +mint,paused == false,nt001,nt001 should fail to mint when paused +mint,_to != address(0),nt006,nt006 should fail to mint to 0x0 address +pause,msg.sender == pauser,nt040,nt040 should fail to pause when sender is not pauser +removeMinter,msg.sender == masterMinter,nt029,nt029 should fail to removeMinter when sender is not masterMinter +transfer,_value <= balances[msg.sender],nt021,nt021 should fail to transfer an amount greater than balance +transfer,_to != address(0),nt020,nt020 should fail to transfer to 0x0 address +transfer,blacklisted[msg.sender] == false,nt023,nt023 should fail to transfer when sender is blacklisted +transfer,blacklisted[_to] == false,nt022,nt022 should fail to transfer to blacklisted recipient +transfer,paused == false,nt024,nt024 should fail to transfer when paused +transferFrom,_value <= balances[_from],nt013,nt013 should fail to transferFrom an amount greater than balance +transferFrom,_to != address(0),nt012,nt012 should fail to transferFrom to 0x0 address +transferFrom,_value <= allowed[_from][msg.sender],nt017,nt017 should fail to transferFrom an amount greater than allowed for msg.sender +transferFrom,blacklisted[_from] == false,nt016,nt016 should fail to transferFrom when from is blacklisted +transferFrom,blacklisted[msg.sender] == false,nt015,nt015 should fail to transferFrom from blacklisted msg.sender +transferFrom,blacklisted[_to] == false,nt014,nt014 should fail to transferFrom to blacklisted recipient +transferFrom,paused == false,nt018,nt018 should fail to transferFrom when paused +transferOwnership,newOwner != address(0),nt064,nt064 transferOwnership should fail on 0x0 +transferOwnership,msg.sender == _owner,nt054,nt054 should fail to transferOwnership when sender is not owner +unBlacklist,msg.sender == blacklister,nt043,nt043 should fail to unblacklist when sender is not blacklister +unpause,msg.sender == pauser,nt041,nt041 should fail to unpause when sender is not pauser +updateBlacklister,_newBlacklister != address(0),nt059,nt059 updateBlacklister should fail on 0x0 +updateBlacklister,msg.sender == _owner,nt048,nt048 should fail to updateBlacklister when sender is not owner +updateMasterMinter,_newMasterMinter != address(0),nt057,nt057 updateMasterMinter should fail on 0x0 +updateMasterMinter,msg.sender == _owner,nt049,nt049 should fail to updateMasterMinter when sender is not owner +updatePauser,_newPauser != address(0),nt058,nt058 updatePauser should fail on 0x0 +updatePauser,msg.sender == _owner,nt050,nt050 should fail to updatePauser when sender is not owner \ No newline at end of file diff --git a/verification/Spreadsheets/ContractStateChanges - PositiveTests.csv b/verification/Spreadsheets/ContractStateChanges - PositiveTests.csv new file mode 100644 index 000000000..26198138e --- /dev/null +++ b/verification/Spreadsheets/ContractStateChanges - PositiveTests.csv @@ -0,0 +1,29 @@ +type,visibility,variable name,Modification Function,Arguments,Result,Code,Test +mapping(address => mapping(address => uint256)),internal,allowed,approve,"_spender = spender, _value = value",allowed[msg.sender][spender] = value,pt020,pt020 should approve a spend and set allowed amount +mapping(address => mapping(address => uint256)),internal,allowed,transferFrom,"_from = from, _to = to, _value = value",allowed[from][spender] -= value,pt007,"pt007 should transferFrom, reducing sender balance by amount and increasing recipient balance by amount" +mapping(address => uint256),internal,balances,burn,_amount = amount,balances[msg.sender] -= amount,pt017,pt017 should burn amount of tokens and reduce balance and total supply by amount +mapping(address => uint256),internal,balances,mint," _to = to, _amount = amount",balances[to] += amount,pt012,"pt012 should mint the amount, increasing balance of recipient by amount, increasing total supply by amount, and decreasing minterAllowed by amount" +mapping(address => uint256),internal,balances,transfer,"_to = to, _value = value","balances[msg.sender] -= amount, balances[to] += amount",pt008,"pt008 should transfer, reducing sender balance by amount and increasing recipient balance by amount" +mapping(address => uint256),internal,balances,transferFrom,"_from = from, _to = to, _value = value","balances[from] -= amount, balances[to] += amount ",pt007,"pt007 should transferFrom, reducing sender balance by amount and increasing recipient balance by amount" +mapping(address => bool),internal,blacklisted,blacklist,_account = account,blacklisted[account] = true,pt019,pt019 should blacklist and set blacklisted to true +mapping(address => bool),internal,blacklisted,unBlacklist,_account = account,blacklisted[account] = false,pt018,"pt018 should blacklist and set blacklisted to true, then unblacklist and set blacklisted to false" +address,public,blacklister,initialize,_blacklister = blacklister,assign,pt000,pt000 should check that default variable values are correct +address,public,blacklister,updateBlacklister,_newBlacklister = newBlacklister,blacklister = _newBlacklister,pt005,pt005 should updateBlacklister +string,public,currency,initialize,_currency = currency,assign,pt000,pt000 should check that default variable values are correct +uint8,public,decimals,initialize,_decimals = decimals,assign,pt000 ,pt000 should check that default variable values are correct +address,public,masterMinter,initialize,_masterMinter = masterMinter,assign,pt000,pt000 should check that default variable values are correct +address,public,masterMinter,updateMasterMinter,_newMasterMinter,masterMinter = _newMasterMinter ,pt004,pt004 should updateMasterMinter +mapping(address => uint256),internal,minterAllowed,configureMinter,"_minter = minter, _minterAllowedAmount = minterAllowedAmount",minterAllowed[minter] = minterAllowedAmount,pt015,"pt015 should configureMinter, setting the minter to true and mintingAllowance to amount" +mapping(address => uint256),internal,minterAllowed,mint,"_to = to, _amount = amount",minterAllowed[msg.sender] -= amount,pt012,"pt012 should mint the amount, increasing balance of recipient by amount, increasing total supply by amount, and decreasing minterAllowed by amount" +mapping(address => uint256),internal,minterAllowed,removeMinter,_minter = minter,minterAllowed[minter] = 0,pt010,"pt010 should removeMinter, setting the minter to false and minterAllowed to 0" +mapping(address => bool),internal,minters,configureMinter,"_minter = minter, _minterAllowedAmount = minterAllowedAmount",minters[minter] = true,pt015,"pt015 should configureMinter, setting the minter to true and mintingAllowance to amount" +mapping(address => bool),internal,minters,removeMinter,_minter = minter,minters[minter] = false,pt010,"pt010 should removeMinter, setting the minter to false and minterAllowed to 0" +string,public,name,initialize,_name = name,assign,pt000,pt000 should check that default variable values are correct +address,private,owner,transferOwnership ,_newOwner = newOwner,_owner = newOwner,pt009,pt009 should set owner to _newOwner +bool,public,paused = false,pause,NA,paused = true,pt011,pt011 should pause and set paused to true +bool,public,paused = false,unpause,NA,paused = false,pt006,pt006 should unpause and set paused to false +address,public,pauser,initialize,_pauser = pauser,assign,pt000,pt000 should check that default variable values are correct +address,public,pauser,updatePauser,_newPauser = newPauser,pauser = _newPauser,pt003,pt003 should updatePauser +string,public,symbol,initialize,symbol = _symbol,assign,pt000,pt000 should check that default variable values are correct +uint256,internal,totalSupply_,burn,_amount = amount,totalSupply_ -= _amount,pt017,pt017 should burn amount of tokens and reduce balance and total supply by amount +uint256,internal,totalSupply_,mint," _to = to, _amount = amount",totalSupply_ += _amount,pt012,"pt012 should mint the amount, increasing balance of recipient by amount, increasing total supply by amount, and decreasing minterAllowed by amount" \ No newline at end of file diff --git a/verification/Spreadsheets/ContractStateChanges - ProxyNegativeTests.csv b/verification/Spreadsheets/ContractStateChanges - ProxyNegativeTests.csv new file mode 100644 index 000000000..2d44c582f --- /dev/null +++ b/verification/Spreadsheets/ContractStateChanges - ProxyNegativeTests.csv @@ -0,0 +1,11 @@ +Function,Restriction,Code,Test +changeAdmin,msg.sender == admin,nut002,nut002 should fail to switch adminAccount with non-adminAccount as caller +upgradeTo,newImplementation is realContract,nut003,nut003 should fail to upgradeTo to null contract address +upgradeToAndCall,newImplementation is realContract,nut004,nut004 should fail to upgradeToAndCall to null contract address +initialize,initialized == false,nut005,nut005 should fail to initialize contract twice +allowance,msg.sender != admin,nut006,nut006 should fail to call contract function with adminAccount +admin,msg.sender == admin,nut007,nut007 should fail to call proxy function with non-adminAccount +transfer,N/A,nut008,nut008 shoud fail to update proxy storage if state-changing function called directly in FiatToken +upgradeTo,msg.sender == admin,nut009,nut009 should fail to call upgradeTo with non-adminAccount +upgradeToAndCall,msg.sender == admin,nut010,nut010 should fail to call updateToAndCall with non-adminAccount +upgradeToAndCall,initialized == false,nut011,nut011 should fail to upgradeToAndCall with initialize (already set variables) \ No newline at end of file diff --git a/verification/Spreadsheets/ContractStateChanges - ProxyPositiveTests.csv b/verification/Spreadsheets/ContractStateChanges - ProxyPositiveTests.csv new file mode 100644 index 000000000..be31bfbfc --- /dev/null +++ b/verification/Spreadsheets/ContractStateChanges - ProxyPositiveTests.csv @@ -0,0 +1,15 @@ +Variable Name,Code,Test +_implementation,upt001,upt001 should upgradeTo new contract and preserve data field values +"_implementation, [new fields]",upt002,upt002 should upgradeToandCall to contract with new data fields set on initVX and ensure new fields are correct and old data is preserved +"_implementation, [new fields]",upt003,"upt003 should upgradeToAndCall to contract with new data fields set on initVX and new logic and ensure old data preserved,new logic works, and new fields correct" +_admin,upt004,upt004 should update proxy adminAccount with previous adminAccount +"_implementation, balances",upt005,upt005 should receive Transfer event on transfer when proxied after upgrade +pause,upt006,upt006 should upgrade while paused and upgraded contract should be paused as a result; then unpause should unpause contract +should not change state,upt007,upt007 should upgrade contract to original address +"initialization fields, _implementation",upt008,upt008 should deploy upgraded version of contract with new data fields and without previous deployment and ensure new fields correct +_admin,upt009,upt009 should check that admin is set correctly by proxy constructor +"initialization fields, _implementation",upt010,"upt010 should deploy upgraded version of contract with new data fields and logic without previous deployment and ensure new logic works, and new fields correct" +"_implementation, [new fields]",upt011,upt011 should upgradeToAndCall while paused and upgraded contract should be paused as a result +"_implementation, [new fields]",upt012,upt012 should upgradeToAndCall while upgrader is blacklisted +"_implementation, [new fields]",upt013,upt013 should upgradeToAndCall while new logic is blacklisted +_implementation,upt014,upt014 should upgradeTo while new logic is blacklisted \ No newline at end of file diff --git a/verification/Spreadsheets/ContractStateChanges - UnitTestCompleteness.csv b/verification/Spreadsheets/ContractStateChanges - UnitTestCompleteness.csv new file mode 100644 index 000000000..0e1a79236 --- /dev/null +++ b/verification/Spreadsheets/ContractStateChanges - UnitTestCompleteness.csv @@ -0,0 +1,36 @@ +File,Function,Modifier,Simple Test,ABI Test,Pausable,Code: paused=true,Blacklistable,blacklisted[msg.sender]=true,blacklisted[address]=true,Only 1 User,Wrong msg.sender +AdminUpgradeabilityProxy.sol,_setAdmin,internal,,abi053,,,,,,, +AdminUpgradeabilityProxy.sol,_willFallback,internal,,abi057,,,,,,, +Blacklistable.sol,blacklist,public,pt019,,no,ept036,no,ept020,ept024,blacklister,nt042 +Blacklistable.sol,unBlacklist,public,pt018,,no,ept035,no,ept021,,blacklister,nt043 +Blacklistable.sol,updateBlacklister,public,pt005,,no,ept003,no,ept015,ept027,owner,nt048 +Blacklistable.sol,isBlacklisted,view,,,,,,,,, +FiatTokenProxy.sol,changeAdmin,public,upt004,,no,ept001,no,ept013,ept025,upgrader,nut002 +FiatTokenProxy.sol,upgradeTo,public,upt001,,no,ept008,no,ept022,upt013,upgrader,nut009 +FiatTokenProxy.sol,upgradeToAndCall,public ,upt002,,no,upt010,no,upt011,upt012,upgrader,nut010 +FiatTokenV1.sol,initialize,public,upt002,,no,,no,,,, +FiatTokenV1.sol,removeMinter,public,pt010,,no,ept006,no,ept033,ept034,masterMinter,nt029 +FiatTokenV1.sol,updateMasterMinter,public,pt004,,no,ept002,no,ept014,ept026,masterMinter,nt049 +FiatTokenV1.sol,approve,public,pt020,,yes,nt010,yes,nt009,nt008,user, +FiatTokenV1.sol,burn,public,pt017,,yes,nt034,yes,nt033,,minter,"nt035, nt031" +FiatTokenV1.sol,configureMinter,public,pt015,,yes,nt028,no,ept030,ept032,masterMinter,nt026 +FiatTokenV1.sol,mint,public,pt012,,yes,nt001,yes,nt003,nt004,minter,"nt002, nt005" +FiatTokenV1.sol,transfer,public,pt008,,yes,nt024,yes,nt023,nt022,user,nt021 +FiatTokenV1.sol,transferFrom,public,pt007,,yes,nt018,yes,nt015,"nt014, nt016",user,nt017 +FiatTokenV1.sol,allowance,view,,,,,,,,, +FiatTokenV1.sol,blanceOf,view,,,,,,,,, +FiatTokenV1.sol,isMinter,view,,,,,,,,, +FiatTokenV1.sol,minterAllowance,view,,,,,,,,, +FiatTokenV1.sol,totalSupply,view,,,,,,,,, +Ownable.sol,transferOwnership,public,pt009,,no,ept005,no,ept017,ept029,owner,nt054 +Ownable.sol,owner,view,,,,,,,,, +Ownable.sol,setOwner,internal,,abi025,,,,,,, +Pausable.sol,pause,public,pt011,,no,ept037,no,ept018,,pauser,nt040 +Pausable.sol,unpause,public,pt006,,no,pt006,no,ept019,,pauser,nt041 +Pausable.sol,updatePauser,public,pt003,,no,ept004,no,ept016,ept028,owner,nt050 +Proxy.sol,_delegate,internal,,abi056,,,,,,, +Proxy.sol,_fallback,internal,,abi058,,,,,,, +Proxy.sol,_willFallback,internal,,abi057,,,,,,, +Proxy.sol,implementation,view,,,,,,,,, +UpgradeabilityProxy.sol,_setImplementation,internal,,abi050,,,,,,, +UpgradeabilityProxy.sol,_upgradeTo,internal,,abi028,,,,,,, \ No newline at end of file diff --git a/verification/Spreadsheets/MINTp0UnitTests - ABITests.csv b/verification/Spreadsheets/MINTp0UnitTests - ABITests.csv new file mode 100644 index 000000000..b0d83e76d --- /dev/null +++ b/verification/Spreadsheets/MINTp0UnitTests - ABITests.csv @@ -0,0 +1,3 @@ +File,Function,Code,Description +MintController.sol,internal_setMinterAllowance,abi100,abi100 internal_setMinterAllowance is internal +Ownable.sol,setOwner,abi101,abi101 setOwner is internal \ No newline at end of file diff --git a/verification/Spreadsheets/MINTp0UnitTests - ArgumentTests.csv b/verification/Spreadsheets/MINTp0UnitTests - ArgumentTests.csv new file mode 100644 index 000000000..94454ee90 --- /dev/null +++ b/verification/Spreadsheets/MINTp0UnitTests - ArgumentTests.csv @@ -0,0 +1,20 @@ +File,Function,Arguments,Code,Description +Ownable.sol,transferOwnership,newOwner == msg.sender,arg000,arg000 transferOwnership(msg.sender) works +Ownable.sol,transferOwnership,newOwner == 0,arg001,arg001 transferOwnership(0) works +Ownable.sol,transferOwnership,newOwner == owner,arg002,arg002 transferOwnership(owner) works +Controller.sol,configureController,newController == 0,arg003,"arg003 configureController(0, M) works" +Controller.sol,configureController,newController == msg.sender,arg004,"arg004 configureController(msg.sender, M) works" +Controller.sol,configureController,newController == newMinter,arg005,"arg005 configureController(M, M) works" +Controller.sol,configureController,newMinter == 0,arg006,"arg006 configureController(C, 0) works" +Controller.sol,removeController,newController == 0,arg007,arg007 removeController(0) works +MintController.sol,setMinterManager,newMinterManager = 0,arg008,arg008 setMinterManager(0) works +MintController.sol,setMinterManager,newMinterManager == minterManager,arg009,arg009 setMinterManager(oldMinterManager) works +MintController.sol,setMinterManager,newMinterManager == user,arg010,arg010 setMinterManager(user_account) works +MintController.sol,setMinterManager,newMinterManager == newToken,arg011,arg011 setMinterManager(newToken) works +MintController.sol,configureMinter,newAllowance == 0,arg012,arg012 configureMinter(0) sets allowance to 0 +MintController.sol,configureMinter,newAllowance == oldAllowance,arg013,arg013 configureMinter(oldAllowance) makes no changes +MintController.sol,configureMinter,newAllowance == 2^256-1,arg014,arg014 configureMinter(MAX) works +MintController.sol,incrementMinterAllowance,increment ==0,arg015,arg015 incrementMinterAllowance(0) makes no changes to allowance +MintController.sol,incrementMinterAllowance,increment == oldAllowance,arg016,arg016 incrementMinterAllowance(oldAllowance) doubles the allowance +MintController.sol,incrementMinterAllowance,increment == 2^256-1,arg017,arg017 incrementMinterAllowance(MAX) throws +MintController.sol,incrementMinterAllowance,increment + oldAllowance == 2^256 -1,arg018,arg018 incrementMinterAlllowance(BIG) throws \ No newline at end of file diff --git a/verification/Spreadsheets/MINTp0UnitTests - BasicTests.csv b/verification/Spreadsheets/MINTp0UnitTests - BasicTests.csv new file mode 100644 index 000000000..4a27a8473 --- /dev/null +++ b/verification/Spreadsheets/MINTp0UnitTests - BasicTests.csv @@ -0,0 +1,55 @@ +File,Function,Special Condition,Code,Description +Controller.sol,configureController,msg.sender == owner,bt004,bt004 configureController works when owner is msg.sender +Controller.sol,configureController,msg.sender != owner,bt005,bt005 configureController reverts when owner is not msg.sender +Controller.sol,configureController,controllers[C]=0,bt019,bt019 configureController works when controller[C]=0 +Controller.sol,configureController,controllers[C] != 0,bt020,bt020 configureController works when controller[C] != 0 +Controller.sol,configureController,controllers[C]=C,bt021,"bt021 configureController(C,C) works" +Controller.sol,configureController,controllers[C] == msg.sender,bt022,bt022 configureController works when setting controller[C]=msg.sender +Controller.sol,configureController,controllers[C] == newM,bt023,"bt023 configureController(C, newM) works when controller[C]=newM" +Controller.sol,constructor,controllers[ALL] = 0,bt016,bt016 Constructor sets all controllers to 0 +Controller.sol,removeController,msg.sender == owner,bt008,bt008 removeController works when owner is msg.sender +Controller.sol,removeController,msg.sender != owner,bt009,bt009 removeController reverts when owner is not msg.sender +Controller.sol,removeController,controllers[C]=0,bt017,bt017 removeController does not revert when controllers[C] is 0 +Controller.sol,removeController,controllers[C]=M,bt018,bt018 removeController removes an arbitrary controller +FiatTokenV1.sol,constructor,minterManager.isMinter[ALL] == false,bt045,bt045 constructor - minterManager.isMinter[ALL] is false +FiatTokenV1.sol,constructor,minterManager.minterAllowance[ALL] == 0,bt046,bt046 constructor - minterManager.minterAllowance[ALL] = 0 +MintController.sol,configureMinter,controllers[msg.sender]==0,bt012,bt012 configureMinter reverts when msg.sender is not a controller +MintController.sol,configureMinter,controllers[msg.sender]==M,bt013,bt013 configureMinter sents controllers[msg.sender] to M +MintController.sol,configureMinter,minterManager = 0,bt033,bt033 configureMinter reverts when minterManager is 0 +MintController.sol,configureMinter,minterManager != MinterManagerInterface,bt034,bt034 configureMinter reverts when minterManager is a user account +MintController.sol,configureMinter,minterManager == OK,bt035,bt035 configureMinter works when minterManager is ok +MintController.sol,configureMinter,minterManager.isMinter == false,bt039,"bt039 configureMinter(M, amt) works when minterManager.isMinter(M)=false" +MintController.sol,configureMinter,minterManager.isMinter == true,bt040,"bt040 configureMinter(M, amt) works when minterManager.isMinter(M)=true" +MintController.sol,configureMinter,minterManager.minterAllowance[M] == 0,bt050,"bt050 configureMinter(M,amt) works when minterAllowance=0" +MintController.sol,configureMinter,minterManager.minterAllowance[M] == X,bt051,"bt051 configureMinter(M,amt) works when minterAllowance>0" +MintController.sol,configureMinter,minterManager.minterAllowance[M] == BIG,bt052,"bt052 configureMinter(M,amt) works when amt+minterAllowance > 2^256" +MintController.sol,constructor,minterManager == init,bt024,bt024 Constructor sets minterManager +MintController.sol,incrementMinterAllowance,controllers[msg.sender]==0,bt014,bt014 incrementMinterAllowance reverts if msg.sender is not a controller +MintController.sol,incrementMinterAllowance,controllers[msg.sender]==M,bt015,bt015 incrementMinterAllowance sets controllers[msg.sender] to M +MintController.sol,incrementMinterAllowance,minterManager = 0,bt036,bt036 incrementMinterAllowance reverts when minterManager is 0 +MintController.sol,incrementMinterAllowance,minterManager != MinterManagerInterface,bt037,bt037 incrementMinterAllowance reverts when minterManager is a user account +MintController.sol,incrementMinterAllowance,minterManager == OK,bt038,bt038 incrementMinterAllowance works when minterManager is ok +MintController.sol,incrementMinterAllowance,minterManager.isMinter == false,bt043,"bt043 incrementMinterAllowance(M, amt) works when minterManager.isMinter(M)=false" +MintController.sol,incrementMinterAllowance,minterManager.isMinter == true,bt044,"bt044 incrementMinterAllowance(M, amt) works when minterManager.isMinter(M)=true" +MintController.sol,incrementMinterAllowance,minterManager.minterAllowance[M] == 0,bt047,"bt047 incrementMinterAllowance(M,amt) works when minterAllowance is 0" +MintController.sol,incrementMinterAllowance,minterManager.minterAllowance[M] == X,bt048,"bt048 incrementMinterAllowance(M, amt) works when minterAllowance > 0" +MintController.sol,incrementMinterAllowance,minterManager.minterAllowance[M] == BIG,bt049,"bt049 incrementMinterAllowance(M,amt) reverts when minterAllowance[M] + amt > 2^256" +MintController.sol,removeMinter,controllers[msg.sender]==0,bt010,bt010 removeMinter reverts when msg.sender is not a controller +MintController.sol,removeMinter,controllers[msg.sender]==M,bt011,bt011 removeMinter sets controllers[msg.sender] to 0 +MintController.sol,removeMinter,minterManager = 0,bt030,bt030 removeMinter reverts when minterManager is 0 +MintController.sol,removeMinter,minterManager != MinterManagerInterface,bt031,bt031 removeMinter reverts when minterManager is a user account +MintController.sol,removeMinter,minterManager == OK,bt032,bt032 removeMinter works when minterManager is ok +MintController.sol,removeMinter,minterManager.isMinter == false,bt041,bt041 removeMinter(M) works when minterManager.isMinter(M)=false +MintController.sol,removeMinter,minterManager.isMinter == true,bt042,bt042 removeMinter(M) works when minterManager.isMinter(M)=true +MintController.sol,removeMinter,minterManager.minterAllowance[M] == 0,bt053,bt053 removeMinter works when the minterAllowance is 0 +MintController.sol,removeMinter,minterManager.minterAllowance[M] == X,bt054,bt054 removeMinter works when the minterAllowance is not zero +MintController.sol,removeMinter,minterManager.minterAllowance[M] == BIG,bt055,bt055 removeMinter works when the minterAllowance is big +MintController.sol,setMinterManager,msg.sender == owner,bt006,bt006 setMinterManager works when owner is msg.sender +MintController.sol,setMinterManager,msg.sender != owner,bt007,bt007 setMinterManager reverts when owner is not msg.sender +MintController.sol,setMinterManager,minterManager == 0,bt025,bt025 setMinterManager(x) works when existing minterManager = 0 +MintController.sol,setMinterManager,minterManager != 0,bt026,bt026 setMinterManager(x) works when existing minterManager != 0 +MintController.sol,setMinterManager,minterManager == msg.sender,bt027,bt027 setMinterManager(x) works when x = msg.sender +MintController.sol,setMinterManager,minterManager == newMinterManager,bt028,bt028 setMinterManager(x) works when x = minterManager +Ownable.sol,constructor,msg.sender == owner,bt001,bt001 Constructor - owner is msg.sender +Ownable.sol,transferOwnership,msg.sender == owner,bt002,bt002 transferOwnership works when owner is msg.sender +Ownable.sol,transferOwnership,msg.sender != owner,bt003,bt003 transferOwnership reverts when owner is not msg.sender \ No newline at end of file diff --git a/verification/Spreadsheets/MINTp0UnitTests - EndToEndTests.csv b/verification/Spreadsheets/MINTp0UnitTests - EndToEndTests.csv new file mode 100644 index 000000000..e5211baa1 --- /dev/null +++ b/verification/Spreadsheets/MINTp0UnitTests - EndToEndTests.csv @@ -0,0 +1,20 @@ +File,Function 1,Function 2,Function 3,Code,Description +Ownable.sol,transferOwnership,configureController,,ete000,ete000 New owner can configure controllers +Ownable.sol,transferOwnership,removeController,,ete001,ete001 New owner can remove controllers +Controller.sol,configureController,configureMinter,,ete002,ete002 New controller can configure minter +Controller.sol,configureController,incrementMinterAllowance,,ete011,ete011 New controller can increment minter allowance +Controller.sol,configureController,removeMinter,,ete012,ete012 New controller can remove minter +Controller.sol,configureController,configureController,configureMinter,ete003,ete003 Configure two controllers for the same minter and make sure they can both configureMinter +Controller.sol,configureController,configureMinter,removeMinter,ete004,"ete004 Configure two controllers for the same minter, one adds a minter and the other removes it" +Controller.sol,configureController,configureMinter,removeMinter,ete005,ete005 Configure two controllers for different minters and make sure 2nd cant remove +Controller.sol,configureController,configureMinter,configureMinter,ete006,ete006 Configure two controllers for different minters and make sure 2nd cant configure +Controller.sol,removeController,configureMinter,,ete007,ete007 Remove a controller and make sure it can't modify minter +MintController.sol,setMinterManager,configureMinter,,ete008,ete008 Change minter manager and make sure existing controllers still can configure their minters +MintController.sol,setMinterManager,removeMinter,,ete009,ete009 Change minter manager and make sure existing controllers still can remove their minters +MintController.sol,setMinterManager,incrementMinterAllowance,,ete010,ete010 Change minter manager and make sure existing controllers can increment allowances +MintController.sol,setMinterManager,configureMinter,setMinterManager,ete013,"ete013 Change minter manager, configure a minter, then change back and make sure changes DID NOT propogate" +MintController.sol,removeMinter,incrementMinterAllowance,,ete014,ete014 Remove a minter and then try to increment its allowance reverts +MintController.sol,configureMinter,mint,,ete015,ete015 Configure a minter and make sure it can mint +MintController.sol,configureMinter,burn,,ete017,ete017 Configure a minter and make sure it can burn +MintController.sol,removeMinter,mint,,ete016,ete016 Remove a minter and make sure it cannot mint +MintController.sol,removeMinter,burn,,ete018,ete018 Remove a minter and make sure it cannot burn \ No newline at end of file diff --git a/verification/Spreadsheets/MINTp0UnitTests - EventTests.csv b/verification/Spreadsheets/MINTp0UnitTests - EventTests.csv new file mode 100644 index 000000000..da5473939 --- /dev/null +++ b/verification/Spreadsheets/MINTp0UnitTests - EventTests.csv @@ -0,0 +1,8 @@ +File,Function,Event,Code,Description +Ownable.sol,transferOwnership,OwnershipTransferred,et100,et100 transferOwnership emits OwnershipTransferred event +Controller.sol,configureController,ControllerConfigured,et101,et101 configureController emits ControllerConfigured event +Controller.sol,removeController,ControllerRemoved,et102,et102 removeController emits ControllerRemoved event +MintController,setMinterManager,MinterManagerSet,et103,et103 setMinterManager emits MinterManagerSet event +MintController,removeMinter,MinterRemoved,et104,et104 removeMinter emits MinterRemoved event +MintController,configureMinter,MinterConfigured,et105,et105 configureMinter emits MinterConfigured event +MintController,incrementMinterAllowance,MinterAllowanceIncremented,et106,et106 incrementMinterAllowance emits MinterAllowanceConfigured event \ No newline at end of file From 620df426efe2b4baec2990ce570e5b1fdcbb1cd5 Mon Sep 17 00:00:00 2001 From: mirathewhite Date: Fri, 28 Sep 2018 16:44:43 -0400 Subject: [PATCH 17/74] Adding parse-csv package --- package.json | 4 +++- yarn.lock | 36 +++++++----------------------------- 2 files changed, 10 insertions(+), 30 deletions(-) diff --git a/package.json b/package.json index 6a4648069..f68c93e66 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "assert-diff": "^1.2.6", "bignumber.js": "6.0.0", "clone": "2.1.2", + "csv-parse": "^3.0.0", "ethereum-input-data-decoder": "0.0.12", "ethereumjs-abi": "^0.6.5", "ethereumjs-tx": "1.3.1", @@ -40,7 +41,8 @@ "q": "^1.5.1", "truffle-hdwallet-provider": "^0.0.6", "yarn": "^1.10.1", - "zos-lib": "1.3.0" + "zos-lib": "1.3.0", + "csv-parse": "3.0.0" }, "devDependencies": { "chai": "^4.1.2", diff --git a/yarn.lock b/yarn.lock index a32bbd82b..4d9c8440b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1891,6 +1891,10 @@ crypto-random-string@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/crypto-random-string/-/crypto-random-string-1.0.0.tgz#a230f64f568310e1498009940790ec99545bca7e" +csv-parse@3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/csv-parse/-/csv-parse-3.0.0.tgz#2d592cf4bf7f3b1606900812df298a5bcc9f66e5" + cyclist@~0.2.2: version "0.2.2" resolved "https://registry.yarnpkg.com/cyclist/-/cyclist-0.2.2.tgz#1b33792e11e914a2fd6d6ed6447464444e5fa640" @@ -1935,7 +1939,7 @@ debug@3.1.0, debug@^3.1.0, debug@~3.1.0: dependencies: ms "2.0.0" -debuglog@*, debuglog@^1.0.1: +debuglog@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/debuglog/-/debuglog-1.0.1.tgz#aa24ffb9ac3df9a2351837cfb2d279360cd78492" @@ -3619,7 +3623,7 @@ import-local@^1.0.0: pkg-dir "^2.0.0" resolve-cwd "^2.0.0" -imurmurhash@*, imurmurhash@^0.1.4: +imurmurhash@^0.1.4: version "0.1.4" resolved "https://registry.yarnpkg.com/imurmurhash/-/imurmurhash-0.1.4.tgz#9218b9b2b928a238b13dc4fb6b6d576f231453ea" @@ -4510,10 +4514,6 @@ lockfile@^1.0.4: dependencies: signal-exit "^3.0.2" -lodash._baseindexof@*: - version "3.1.0" - resolved "https://registry.yarnpkg.com/lodash._baseindexof/-/lodash._baseindexof-3.1.0.tgz#fe52b53a1c6761e42618d654e4a25789ed61822c" - lodash._baseuniq@~4.6.0: version "4.6.0" resolved "https://registry.yarnpkg.com/lodash._baseuniq/-/lodash._baseuniq-4.6.0.tgz#0ebb44e456814af7905c6212fa2c9b2d51b841e8" @@ -4521,28 +4521,10 @@ lodash._baseuniq@~4.6.0: lodash._createset "~4.0.0" lodash._root "~3.0.0" -lodash._bindcallback@*: - version "3.0.1" - resolved "https://registry.yarnpkg.com/lodash._bindcallback/-/lodash._bindcallback-3.0.1.tgz#e531c27644cf8b57a99e17ed95b35c748789392e" - -lodash._cacheindexof@*: - version "3.0.2" - resolved "https://registry.yarnpkg.com/lodash._cacheindexof/-/lodash._cacheindexof-3.0.2.tgz#3dc69ac82498d2ee5e3ce56091bafd2adc7bde92" - -lodash._createcache@*: - version "3.1.2" - resolved "https://registry.yarnpkg.com/lodash._createcache/-/lodash._createcache-3.1.2.tgz#56d6a064017625e79ebca6b8018e17440bdcf093" - dependencies: - lodash._getnative "^3.0.0" - lodash._createset@~4.0.0: version "4.0.3" resolved "https://registry.yarnpkg.com/lodash._createset/-/lodash._createset-4.0.3.tgz#0f4659fbb09d75194fa9e2b88a6644d363c9fe26" -lodash._getnative@*, lodash._getnative@^3.0.0: - version "3.9.1" - resolved "https://registry.yarnpkg.com/lodash._getnative/-/lodash._getnative-3.9.1.tgz#570bc7dede46d61cdcde687d65d3eecbaa3aaff5" - lodash._root@~3.0.0: version "3.0.1" resolved "https://registry.yarnpkg.com/lodash._root/-/lodash._root-3.0.1.tgz#fba1c4524c19ee9a5f8136b4609f017cf4ded692" @@ -4563,10 +4545,6 @@ lodash.isstring@^4.0.1: version "4.0.1" resolved "https://registry.yarnpkg.com/lodash.isstring/-/lodash.isstring-4.0.1.tgz#d527dfb5456eca7cc9bb95d5daeaf88ba54a5451" -lodash.restparam@*: - version "3.6.1" - resolved "https://registry.yarnpkg.com/lodash.restparam/-/lodash.restparam-3.6.1.tgz#936a4e309ef330a7645ed4145986c85ae5b20805" - lodash.union@~4.6.0: version "4.6.0" resolved "https://registry.yarnpkg.com/lodash.union/-/lodash.union-4.6.0.tgz#48bb5088409f16f1821666641c44dd1aaae3cd88" @@ -6149,7 +6127,7 @@ readable-stream@~1.0.15: isarray "0.0.1" string_decoder "~0.10.x" -readdir-scoped-modules@*, readdir-scoped-modules@^1.0.0: +readdir-scoped-modules@^1.0.0: version "1.0.2" resolved "https://registry.yarnpkg.com/readdir-scoped-modules/-/readdir-scoped-modules-1.0.2.tgz#9fafa37d286be5d92cbaebdee030dc9b5f406747" dependencies: From 60101f305498037652e88cee830f5f9b746d9445 Mon Sep 17 00:00:00 2001 From: mirathewhite Date: Wed, 3 Oct 2018 21:04:35 -0400 Subject: [PATCH 18/74] basic functionality working with *csv spreadsheets --- package.json | 5 +- truffle.js | 4 +- ...actStateChanges - UnitTestCompleteness.csv | 0 verification/GoogleSheets/index.js | 255 ------------------ verification/spreadsheet_parser.js | 126 +++++++++ verification/verification_reporter.js | 66 ++--- 6 files changed, 165 insertions(+), 291 deletions(-) rename verification/{Spreadsheets => }/ContractStateChanges - UnitTestCompleteness.csv (100%) delete mode 100644 verification/GoogleSheets/index.js create mode 100644 verification/spreadsheet_parser.js diff --git a/package.json b/package.json index f68c93e66..33ac07789 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "assert-diff": "^1.2.6", "bignumber.js": "6.0.0", "clone": "2.1.2", - "csv-parse": "^3.0.0", + "csv-parse": "3.0.0", "ethereum-input-data-decoder": "0.0.12", "ethereumjs-abi": "^0.6.5", "ethereumjs-tx": "1.3.1", @@ -41,8 +41,7 @@ "q": "^1.5.1", "truffle-hdwallet-provider": "^0.0.6", "yarn": "^1.10.1", - "zos-lib": "1.3.0", - "csv-parse": "3.0.0" + "zos-lib": "1.3.0" }, "devDependencies": { "chai": "^4.1.2", diff --git a/truffle.js b/truffle.js index 061c042d8..6191b721b 100644 --- a/truffle.js +++ b/truffle.js @@ -46,7 +46,7 @@ module.exports = { * To disable the spreadsheet verification tool ensure that * the reporter is set to 'Spec' by commenting/uncommenting the lines below. */ - reporter: 'Spec', - //reporter: './verification/verification_reporter.js', + // reporter: 'Spec', + reporter: "/Users/mirabelenkiy/Documents/Dev/centre-tokens/verification/verification_reporter.js", }, }; diff --git a/verification/Spreadsheets/ContractStateChanges - UnitTestCompleteness.csv b/verification/ContractStateChanges - UnitTestCompleteness.csv similarity index 100% rename from verification/Spreadsheets/ContractStateChanges - UnitTestCompleteness.csv rename to verification/ContractStateChanges - UnitTestCompleteness.csv diff --git a/verification/GoogleSheets/index.js b/verification/GoogleSheets/index.js deleted file mode 100644 index c6c8ad3dd..000000000 --- a/verification/GoogleSheets/index.js +++ /dev/null @@ -1,255 +0,0 @@ -const fs = require('fs'); -const readline = require('readline'); -const {google} = require('googleapis'); - -const SCOPES = ['https://www.googleapis.com/auth/spreadsheets.readonly']; -const CREDENTIALS_PATH = __dirname + '/credentials.json'; -const TOKEN_PATH = __dirname + '/token.json'; - -var indent = ' '; - - -/** -* Authorize access to GoogleSheets API and load spreadsheet data. -*/ -function load() { - return new Promise((resolve, reject) => { - // Load client secrets from a local file. - fs.readFile(CREDENTIALS_PATH, async (err, content) => { - if (err) { - reject('Error loading credentials file:' + err); - } - // If no error loading client secrets, authorize and run getTests(). - var res = await authorize(JSON.parse(content), getTests).catch((err) => { - reject(err); - }); - resolve(res); - }); - }); -} - - -/** - * Create an OAuth2 client with the given credentials, and then execute the - * given callback function. - * @param {Object} credentials The authorization client credentials. - * @param {function} callback The callback to call with the authorized client. - */ -function authorize(credentials, callback) { - const {client_secret, client_id, redirect_uris} = credentials.installed; - const oAuth2Client = new google.auth.OAuth2( - client_id, client_secret, redirect_uris[0]); - - return new Promise((resolve, reject) => { - // Check if we have previously stored an OAuth token. - fs.readFile(TOKEN_PATH, async (err, token) => { - // If we have not previously stored an OAuth token, get a new one and - // call getTests(). - if (err) { - var res = await getNewToken(oAuth2Client, callback).catch((err) => { - reject(err); - }); - } else { - // If we have previously stored an OAuth token, call getTests(). - oAuth2Client.setCredentials(JSON.parse(token)); - var res = await callback(oAuth2Client).catch((err) => { - reject(err); - }); - } - resolve(res); - }); - }); -} - - -/** - * Get and store new token after prompting for user authorization, and then - * execute the given callback with the authorized OAuth2 client. - * @param {google.auth.OAuth2} oAuth2Client The OAuth2 client to get token for. - * @param {getEventsCallback} callback The callback for the authorized client. - */ -function getNewToken(oAuth2Client, callback) { - const authUrl = oAuth2Client.generateAuthUrl({ - access_type: 'offline', - scope: SCOPES, - }); - console.log('Authorize this app by visiting this url:', authUrl); - const rl = readline.createInterface({ - input: process.stdin, - output: process.stdout, - }); - - return new Promise((resolve, reject) => { - rl.question('Enter the code from that page here: ', (code) => { - rl.close(); - oAuth2Client.getToken(code, async (err, token) => { - if (err) { - reject(await callback(err)); - } - oAuth2Client.setCredentials(token); - // Store the token to disk for later program executions - fs.writeFile(TOKEN_PATH, JSON.stringify(token), (err) => { - if (err) { - console.error(err); - } - console.log('Token stored to', TOKEN_PATH); - }); - var res = await callback(oAuth2Client).catch((err) => { - reject(err); - }); - resolve(res); - }); - }); - }); -} - - -/** -* Gets the tests to verify from the GoogleSheets spreadsheet. -* @see https://docs.google.com/spreadsheets/d/1zP1_q8XbLH8YrWMJ0Od80PKleklUnvBAX96wypJaVTU/edit?usp=sharing -* @param {google.auth.OAuth2} auth The authenticated Google OAuth client. -*/ -function getTests(auth) { - const sheets = google.sheets({version: 'v4', auth}); - - return new Promise((resolve, reject) => { - sheets.spreadsheets.get({ - spreadsheetId: '1zP1_q8XbLH8YrWMJ0Od80PKleklUnvBAX96wypJaVTU', - includeGridData: true, - }, (err, res) => { - if (err) { - reject('The GoogleSheets API returned an error: ' + err); - } - var tests = {}; - let tabs = res.data.sheets; - if (tabs.length) { - tabs.map((tab) => { - let tab_name = tab.properties.title; - if (tab_name == 'UnitTestCompleteness') { - load_UnitTestCompleteness(tests, tab); - return; - } - let rows = tab.data[0].rowData; - let top_row = rows.shift().values; - let col = getCol(top_row); - if (typeof col == 'undefined') { - console.log('\nNo code column found in tab "' - + tab_name + '". Skipping.\n'); - return; - } - rows.map((rowData) => { - let row = rowData.values; - if (row) { - processRow(row, tab_name, tests, col); - } - }); - }); - } else { - reject('No GoogleSheets data found.'); - } - resolve(tests); - }); - }); -} - - -/** -* Helper function that gets the test code and test description from a row in a -* given speadsheet tab and adds them to the tests object returned by getTests(). -* @param {Array} row The row of the spreadsheet to processs. -* @param {String} tab_name The name of the spreadsheet tab currently loading. -* @param {Object} tests Contains all the spreadsheet test data to verify. -* @param {Int} col The index of the test code column of the spreadsheet tab. -*/ -function processRow(row, tab_name, tests, col) { - let code_cell = row[col]; - let desc_cell = row[col+1]; - if (code_cell && desc_cell) { - let test_code = code_cell.formattedValue; - let test_desc = desc_cell.formattedValue; - if (test_code && test_desc) { - let pending = test_code.match(/ -p/); - if (pending) { - test_code = test_code.replace(pending[0], ''); - } - categorize_test( - tests, - test_code.trim(), - test_desc.trim(), - tab_name.trim(), - pending - ); - } - } -} - - -/** -* Helper function that gets all test codes included in tab UnitTestCompleteness. -* @param {Object} tab The UnitTestCompleteness tab object. -* @param {Object} tests Contains all the spreadsheet test data to verify. -*/ -function load_UnitTestCompleteness(tests, tab) { - tests.completeness = {}; - let rows = tab.data[0].rowData; - rows.map((row) => { - row = row.values; - row.map((cell) => { - cell = cell.formattedValue; - if (cell) { - let codes = cell.match(/([a-z]{2,})([0-9]+)/g); - if (codes != null) { - codes.map((code) => { - if (!tests.completeness[code]) { - tests.completeness[code] = true; - } - }); - } - } - }); - }); -} - - -/** -* Helper function that adds a test code and description to the tests object -* returned by getTests(). -* @param {Object} tests Contains all the spreadsheet test data to verify. -* @param {String} code The test code to add to tests. -* @param {String} desc The test description to add to tests. -* @param {String} tab The name of the spreadsheet tab currently loading. -* @param {Array?} pending [' -p'] if test is pending, 'undefined' otherwise. -*/ -function categorize_test(tests, code, desc, tab, pending) { - if (pending) { - tab = 'pending'; - } - if (!tests[tab]) { - tests[tab] = {}; - } - let tab_tests = tests[tab]; - tab_tests[code] = desc.replace(code, ''); - tests[tab] = tab_tests; -} - - -/** -* Helper function that finds the 'Code' or 'code' column in a spreadsheet tab. -* @param {Array} top_row An array containing all the cells along the top row of -* the spreadsheet tab. Should contain column headers. -*/ -function getCol(top_row) { - var col; - for (let i = 0; i < top_row.length; i++) { - let cell = top_row[i]; - let label = cell.formattedValue; - if(label == 'code' || label == 'Code') { - col = i; - } - } - return col; -} - -module.exports = { - load: load, -} diff --git a/verification/spreadsheet_parser.js b/verification/spreadsheet_parser.js new file mode 100644 index 000000000..084354cf6 --- /dev/null +++ b/verification/spreadsheet_parser.js @@ -0,0 +1,126 @@ +var fs = require('fs'); +var parse = require('csv-parse/lib/sync'); +var SPREADSHEETS_DIR = '/Users/mirabelenkiy/Documents/Dev/centre-tokens/verification/Spreadsheets' + +function UnitTest(code, description, pending){ + this.code = code; + this.description = description; + this.pending = pending; +} + +/* + UnitTestDirectory is a literal object. + Keys - names of unit test files + Values - a UnitTestSet + + UnitTestSet is a literal object + Keys - codes associated with unit tests + Values - an instance of a UnitTest object +* + + +/** +* Reads all files in Spreadsheets directory and returns an oject with their contents +* Returns a UnitTestDirectory object +* TODO: handle errors, null objects, UnitTestCompleteness +*/ +function load() { + var unitTestDirectory = {}; + + // get names of all files in SPREADSHEETS_DIR + var files = fs.readdirSync(SPREADSHEETS_DIR, (err, data) => { + if(err){ + console.log("error reading " + SPREADSHEETS_DIR + " " + err); + return null; + } + return data; + }); + // process each file into a unitTestSet, then add the + // unitTestSet to unitTestDirectory + files.forEach(file => { + console.log('reading ' + file); + var csvFileContents = fs.readFileSync(SPREADSHEETS_DIR + "/" + file, "utf8"); + if(csvFileContents != null) { + var unitTestSet = {}; + var spreadsheet = parse(csvFileContents, {columns: true}); + spreadsheet.forEach(row => { + var unitTest = parseRow(row); + unitTestSet[unitTest.code] = unitTest; + }); + var unittestfilename = getUnitTestFileName(file); + unitTestDirectory[unittestfilename] = unitTestSet; + } + }); + + // return array of unitTestDirectory objects + return unitTestDirectory; +} + +// +// spreadsheet: UnitTestDirectory +function isPending(spreadsheet, filename, code) { + if((filename in spreadsheet ) && (code in spreadsheet[filename])) + { + return spreadsheet[filename][code].pending; + } + return false; +} + +// Transforms a row in spreadsheet into a UnitTest object +// row: a literal object. One of the keys must be 'code/Code' and another 'description/Description' +// Returns a UnitTest object or null if cannot find appropriate keys. +function parseRow(row) { + var test_code = ""; + var testCodeKey = ""; + var pending = false; + var description = ""; + for(var columnName in row) { + if(columnName == 'code' || columnName == 'Code') { + test_code = row[columnName]; + testCodeKey = columnName; + pending = test_code.match(/ -p/); + if (pending) { + test_code = test_code.replace(pending[0], ''); + pending = true; + } else { + pending = false; + } + } + } + var descriptionKey = getDescriptionKey(row, testCodeKey); + description = row[descriptionKey]; + if(test_code == '' || description == '') return null; + return new UnitTest(test_code, description, pending); +} + +function getDescriptionKey(row, testCodeKey) { + // get the index of the testCodeKey + var testCodeKeyIndex = 0; + for(var i=0; i { - console.log(err); - }); - spreadsheet_clone = JSON.parse(JSON.stringify(spreadsheet)); + spreadsheet = sheets.load(); }); // Runs at the beginning of each contract block execution. @@ -59,6 +55,7 @@ function verification_reporter (runner) { }); // Runs at the end of every test. + // TODO: upgraded tests "missing" because deleted from spreadsheet after first run runner.on('test end', function (test) { // If contract block title is marked 'Legacy', // we skip verification. (See README.verification) @@ -95,40 +92,46 @@ function verification_reporter (runner) { + indent + '(See README.verification)')); return; } - var test_ran = test.title.replace(id, ''); + var test_ran = test.title; +// var test_ran = test.title.replace(id, ''); // Check if test is in UnitTestCompleteness tab and "cross-off" if it is. + /* TODO: implement UnitTestCompleteness spreadsheet processing if (!_.isEmpty(spreadsheet.completeness)) { if (spreadsheet.completeness[id]) { delete spreadsheet.completeness[id]; } } - - // If test is marked pending in spreadsheet, record for later output. - if (spreadsheet.pending && (spreadsheet.pending[id] == test_ran)) { - console.log(indent + green_x + color('bright pass', ' pending')); - pending[id] = test_ran; - } else { +*/ // Verify test is in spreadsheet. if (spreadsheet[file]) { - let spreadsheet_test = spreadsheet[file][id] || spreadsheet_clone[file][id]; + let spreadsheet_test = spreadsheet[file][id]; if (spreadsheet_test) { - // Verify test descriptions match. - if (spreadsheet_test == test_ran) { + + // If test is marked pending in spreadsheet, record for later output. + if(spreadsheet_test.pending) { + console.log(indent + green_x + color('bright pass', ' pending')); + pending[id] = test_ran; + + // If test descriptions match, mark green. + } else if (spreadsheet_test.description == test_ran) { console.log(indent + green_x); + + // If test is in spreadsheet, but descriptions don't match. } else { - // If test is in spreadsheet, but descriptions don't match. console.log(indent + red_x + color('fail', ' test description inconsistent with spreadsheet for ' + id + ', ' + file)); + console.log("s: " + spreadsheet_test.description); + console.log("t: " + test_ran); // Print test description string diff. - let diff = getStringDiff(test_ran, spreadsheet_test); + let diff = getStringDiff(test_ran, spreadsheet_test.description); console.log(indent + diff); errs.push(red_x + color('fail', ' Test descriptions do not match for ' + id + ', ' + file) - + '\n' + indent + 'In spreadsheet: ' + spreadsheet_test + + '\n' + indent + 'In spreadsheet: ' + spreadsheet_test.description + '\n' + indent + 'In test file: ' + test_ran + '\n' + indent + 'Diff: ' + diff); } @@ -140,24 +143,23 @@ function verification_reporter (runner) { // If test is not in spreadsheet. console.log(indent + red_x + color('fail', ' ' - + id + ' missing from spreadsheet tab ' + file)); + + id + ' missing from spreadsheet file ' + file)); errs.push(red_x + color('fail', ' Test ' + id + ' missing from ' - + file + ' spreadsheet tab.')); + + file + ' spreadsheet file.')); } } else { - // If test file not found in spreadsheet tabs. + // If test file not found in directory. console.log(indent + red_x + color('fail', ' test file ' + file - + ' does not match a spreadsheet tab')); + + ' does not match a spreadsheet in the Spreadsheets directory')); errs.push(red_x + color('fail', ' Test file ' + file - + ' missing from spreadsheet. Possible solutions:\n' - + '1. Ensure test is listed in correct spreadsheet tab.\n' - + '2. Ensure the tab name is included in the contract block title.\n' + + ' missing from Spreadsheets directory. Possible solutions:\n' + + '1. Ensure test is listed in correct *.csv file.\n' + + '2. Ensure the *.csv file name is included in the contract block title.\n' + '(See README.verification)')); } - } }); // Runs at the end of test suite execution. Prints verification summary. @@ -170,11 +172,13 @@ function verification_reporter (runner) { + 'marked pending in the spreadsheet (delete -p flag once merged): '); console.log(pending); } + // TODO: fix pending // Do not report tests that are missing from test suite but marked pending. - delete spreadsheet.pending; + // delete spreadsheet.pending; // Print out any tests that are included in UnitTestCompleteness tab but // missing from the test suite. - if (!_.isEmpty(spreadsheet.completeness)) { + // TODO: fix completeness spreadshet + /* if (!_.isEmpty(spreadsheet.completeness)) { console.log('\n' + red_x + color('bright fail', ' UnitTestCompleteness tab includes tests that are not present in test suite:') + '\n' + Object.keys(spreadsheet.completeness).toString()); @@ -182,7 +186,7 @@ function verification_reporter (runner) { console.log(green_ok + color('bright pass', ' Test suite suite contains all tests in UnitTestCompleteness tab.')); } - delete spreadsheet.completeness; + delete spreadsheet.completeness;*/ // If all the tests in a tab are present, 'cross-off' tab by deleting. for(var file in spreadsheet) { if (_.isEmpty(spreadsheet[file])) { @@ -197,7 +201,7 @@ function verification_reporter (runner) { // If not all tests are 'crossed-off', print the tests remaining. console.log(color('bright fail', '\nTests missing from test suite (but included in spreadsheet):\n')); - console.log(spreadsheet); + console.log(spreadsheet); // TODO: test this line works } // Print all errors where executed tests did not match spreadsheet. if (errs.length) { From 43aaaf027e317ef0216e9953c65ab4bd78c78acb Mon Sep 17 00:00:00 2001 From: mirathewhite Date: Thu, 4 Oct 2018 11:48:25 -0400 Subject: [PATCH 19/74] Added pending support, relative paths --- truffle.js | 2 +- ...ests.csv => FiatToken_ABIHackingTests.csv} | 0 ...ventTests.csv => FiatToken_EventTests.csv} | 0 ...sv => FiatToken_ExtendedPositiveTests.csv} | 0 ... MiscTests.csv => FiatToken_MiscTests.csv} | 0 ...eTests.csv => FiatToken_NegativeTests.csv} | 0 ...eTests.csv => FiatToken_PositiveTests.csv} | 0 ...s.csv => FiatToken_ProxyNegativeTests.csv} | 0 ...s.csv => FiatToken_ProxyPositiveTests.csv} | 0 ...s - ABITests.csv => MINTp0 - ABITests.csv} | 0 ...ntTests.csv => MINTp0 - ArgumentTests.csv} | 0 ...BasicTests.csv => MINTp0 - BasicTests.csv} | 0 ...ndTests.csv => MINTp0 - EndToEndTests.csv} | 0 ...EventTests.csv => MINTp0 - EventTests.csv} | 0 verification/spreadsheet_parser.js | 30 +++--- verification/verification_reporter.js | 93 ++++++++++--------- 16 files changed, 61 insertions(+), 64 deletions(-) rename verification/Spreadsheets/{ContractStateChanges - ABIHackingTests.csv => FiatToken_ABIHackingTests.csv} (100%) rename verification/Spreadsheets/{ContractStateChanges - EventTests.csv => FiatToken_EventTests.csv} (100%) rename verification/Spreadsheets/{ContractStateChanges - ExtendedPositiveTests.csv => FiatToken_ExtendedPositiveTests.csv} (100%) rename verification/Spreadsheets/{ContractStateChanges - MiscTests.csv => FiatToken_MiscTests.csv} (100%) rename verification/Spreadsheets/{ContractStateChanges - NegativeTests.csv => FiatToken_NegativeTests.csv} (100%) rename verification/Spreadsheets/{ContractStateChanges - PositiveTests.csv => FiatToken_PositiveTests.csv} (100%) rename verification/Spreadsheets/{ContractStateChanges - ProxyNegativeTests.csv => FiatToken_ProxyNegativeTests.csv} (100%) rename verification/Spreadsheets/{ContractStateChanges - ProxyPositiveTests.csv => FiatToken_ProxyPositiveTests.csv} (100%) rename verification/Spreadsheets/{MINTp0UnitTests - ABITests.csv => MINTp0 - ABITests.csv} (100%) rename verification/Spreadsheets/{MINTp0UnitTests - ArgumentTests.csv => MINTp0 - ArgumentTests.csv} (100%) rename verification/Spreadsheets/{MINTp0UnitTests - BasicTests.csv => MINTp0 - BasicTests.csv} (100%) rename verification/Spreadsheets/{MINTp0UnitTests - EndToEndTests.csv => MINTp0 - EndToEndTests.csv} (100%) rename verification/Spreadsheets/{MINTp0UnitTests - EventTests.csv => MINTp0 - EventTests.csv} (100%) diff --git a/truffle.js b/truffle.js index 6191b721b..f0aa71a44 100644 --- a/truffle.js +++ b/truffle.js @@ -47,6 +47,6 @@ module.exports = { * the reporter is set to 'Spec' by commenting/uncommenting the lines below. */ // reporter: 'Spec', - reporter: "/Users/mirabelenkiy/Documents/Dev/centre-tokens/verification/verification_reporter.js", + reporter: "verification/verification_reporter.js", }, }; diff --git a/verification/Spreadsheets/ContractStateChanges - ABIHackingTests.csv b/verification/Spreadsheets/FiatToken_ABIHackingTests.csv similarity index 100% rename from verification/Spreadsheets/ContractStateChanges - ABIHackingTests.csv rename to verification/Spreadsheets/FiatToken_ABIHackingTests.csv diff --git a/verification/Spreadsheets/ContractStateChanges - EventTests.csv b/verification/Spreadsheets/FiatToken_EventTests.csv similarity index 100% rename from verification/Spreadsheets/ContractStateChanges - EventTests.csv rename to verification/Spreadsheets/FiatToken_EventTests.csv diff --git a/verification/Spreadsheets/ContractStateChanges - ExtendedPositiveTests.csv b/verification/Spreadsheets/FiatToken_ExtendedPositiveTests.csv similarity index 100% rename from verification/Spreadsheets/ContractStateChanges - ExtendedPositiveTests.csv rename to verification/Spreadsheets/FiatToken_ExtendedPositiveTests.csv diff --git a/verification/Spreadsheets/ContractStateChanges - MiscTests.csv b/verification/Spreadsheets/FiatToken_MiscTests.csv similarity index 100% rename from verification/Spreadsheets/ContractStateChanges - MiscTests.csv rename to verification/Spreadsheets/FiatToken_MiscTests.csv diff --git a/verification/Spreadsheets/ContractStateChanges - NegativeTests.csv b/verification/Spreadsheets/FiatToken_NegativeTests.csv similarity index 100% rename from verification/Spreadsheets/ContractStateChanges - NegativeTests.csv rename to verification/Spreadsheets/FiatToken_NegativeTests.csv diff --git a/verification/Spreadsheets/ContractStateChanges - PositiveTests.csv b/verification/Spreadsheets/FiatToken_PositiveTests.csv similarity index 100% rename from verification/Spreadsheets/ContractStateChanges - PositiveTests.csv rename to verification/Spreadsheets/FiatToken_PositiveTests.csv diff --git a/verification/Spreadsheets/ContractStateChanges - ProxyNegativeTests.csv b/verification/Spreadsheets/FiatToken_ProxyNegativeTests.csv similarity index 100% rename from verification/Spreadsheets/ContractStateChanges - ProxyNegativeTests.csv rename to verification/Spreadsheets/FiatToken_ProxyNegativeTests.csv diff --git a/verification/Spreadsheets/ContractStateChanges - ProxyPositiveTests.csv b/verification/Spreadsheets/FiatToken_ProxyPositiveTests.csv similarity index 100% rename from verification/Spreadsheets/ContractStateChanges - ProxyPositiveTests.csv rename to verification/Spreadsheets/FiatToken_ProxyPositiveTests.csv diff --git a/verification/Spreadsheets/MINTp0UnitTests - ABITests.csv b/verification/Spreadsheets/MINTp0 - ABITests.csv similarity index 100% rename from verification/Spreadsheets/MINTp0UnitTests - ABITests.csv rename to verification/Spreadsheets/MINTp0 - ABITests.csv diff --git a/verification/Spreadsheets/MINTp0UnitTests - ArgumentTests.csv b/verification/Spreadsheets/MINTp0 - ArgumentTests.csv similarity index 100% rename from verification/Spreadsheets/MINTp0UnitTests - ArgumentTests.csv rename to verification/Spreadsheets/MINTp0 - ArgumentTests.csv diff --git a/verification/Spreadsheets/MINTp0UnitTests - BasicTests.csv b/verification/Spreadsheets/MINTp0 - BasicTests.csv similarity index 100% rename from verification/Spreadsheets/MINTp0UnitTests - BasicTests.csv rename to verification/Spreadsheets/MINTp0 - BasicTests.csv diff --git a/verification/Spreadsheets/MINTp0UnitTests - EndToEndTests.csv b/verification/Spreadsheets/MINTp0 - EndToEndTests.csv similarity index 100% rename from verification/Spreadsheets/MINTp0UnitTests - EndToEndTests.csv rename to verification/Spreadsheets/MINTp0 - EndToEndTests.csv diff --git a/verification/Spreadsheets/MINTp0UnitTests - EventTests.csv b/verification/Spreadsheets/MINTp0 - EventTests.csv similarity index 100% rename from verification/Spreadsheets/MINTp0UnitTests - EventTests.csv rename to verification/Spreadsheets/MINTp0 - EventTests.csv diff --git a/verification/spreadsheet_parser.js b/verification/spreadsheet_parser.js index 084354cf6..9996510d6 100644 --- a/verification/spreadsheet_parser.js +++ b/verification/spreadsheet_parser.js @@ -1,6 +1,7 @@ var fs = require('fs'); var parse = require('csv-parse/lib/sync'); -var SPREADSHEETS_DIR = '/Users/mirabelenkiy/Documents/Dev/centre-tokens/verification/Spreadsheets' +// NOTE: SPREADSHEETS_DIR must be relative to truffle.js +var SPREADSHEETS_DIR = './verification/Spreadsheets' function UnitTest(code, description, pending){ this.code = code; @@ -10,7 +11,7 @@ function UnitTest(code, description, pending){ /* UnitTestDirectory is a literal object. - Keys - names of unit test files + Keys - names of unit test suites Values - a UnitTestSet UnitTestSet is a literal object @@ -38,7 +39,6 @@ function load() { // process each file into a unitTestSet, then add the // unitTestSet to unitTestDirectory files.forEach(file => { - console.log('reading ' + file); var csvFileContents = fs.readFileSync(SPREADSHEETS_DIR + "/" + file, "utf8"); if(csvFileContents != null) { var unitTestSet = {}; @@ -47,7 +47,7 @@ function load() { var unitTest = parseRow(row); unitTestSet[unitTest.code] = unitTest; }); - var unittestfilename = getUnitTestFileName(file); + var unittestfilename = getTestSuiteTitle(file); unitTestDirectory[unittestfilename] = unitTestSet; } }); @@ -75,9 +75,9 @@ function parseRow(row) { var pending = false; var description = ""; for(var columnName in row) { - if(columnName == 'code' || columnName == 'Code') { - test_code = row[columnName]; - testCodeKey = columnName; + if(columnName.trim() == 'code' || columnName.trim() == 'Code') { + test_code = row[columnName].trim(); + testCodeKey = columnName.trim(); pending = test_code.match(/ -p/); if (pending) { test_code = test_code.replace(pending[0], ''); @@ -88,7 +88,7 @@ function parseRow(row) { } } var descriptionKey = getDescriptionKey(row, testCodeKey); - description = row[descriptionKey]; + description = row[descriptionKey].trim(); if(test_code == '' || description == '') return null; return new UnitTest(test_code, description, pending); } @@ -105,17 +105,11 @@ function getDescriptionKey(row, testCodeKey) { return Object.keys(row)[i];; } -// Returns the raw name of the unit test file associated with this csv file +// Returns the raw name of the unit test suite associated with this csv file // csvFileName: filename in the format `/path/to/file/spreadsheetname - unittestfilename.csv` -// returns unittestfilename -function getUnitTestFileName(csvFileName) { - var filenames = csvFileName.split(/ - /); - if(filenames.length != 2) { - console.log("failed to split " + csvFileName) - return ''; - } - var unitTestFileName = filenames[filenames.length - 1].replace(/\.csv/, "" ); - return unitTestFileName; +// returns 'spreadsheetname - unittestfilename' +function getTestSuiteTitle(csvFileName) { + return csvFileName.replace(/\.csv/, "" ); } diff --git a/verification/verification_reporter.js b/verification/verification_reporter.js index 7e3c3e2ec..4b9e5de13 100644 --- a/verification/verification_reporter.js +++ b/verification/verification_reporter.js @@ -1,3 +1,4 @@ +const util = require('util'); const mocha = require('mocha'); const spec_reporter = mocha.reporters.Spec; const base_reporter = mocha.reporters.Base; @@ -24,14 +25,18 @@ function verification_reporter (runner) { spec_reporter.call(this, runner); var spreadsheet; + var missingUnitTests; var errs = []; var pending = {}; + var executedTestSuites = {}; // Runs before tests are executed. Loads tests from spreadsheet. before('load_spreadsheet_tests', async function() { this.timeout(200000); console.log('Loading spreadsheet...\n'); - spreadsheet = sheets.load(); + // need two copies of spreadsheet because some unit tests run multiple times + spreadsheet = sheets.load(); // check if unit test is in spreadsheet at all + missingUnitTests = sheets.load(); // reporter will remove codes once they're found }); // Runs at the beginning of each contract block execution. @@ -55,7 +60,6 @@ function verification_reporter (runner) { }); // Runs at the end of every test. - // TODO: upgraded tests "missing" because deleted from spreadsheet after first run runner.on('test end', function (test) { // If contract block title is marked 'Legacy', // we skip verification. (See README.verification) @@ -72,16 +76,10 @@ function verification_reporter (runner) { } // Parse test title. - var file = test.parent.title.match(/[a-z]+Tests/gi); - if (file) { - file = file[0]; - } else { - console.log(indent + color('pass', - 'Error parsing test title.\n' - + indent + 'Confirm file name is formatted correctly and included in contract \n' - + indent + 'block title. (See README.verification)')); - return; - } + var fullSuiteName = test.parent.title.replace('Contract:','').trim(); + var suite = fullSuiteName.split(" ", 1)[0].trim(); + executedTestSuites[suite]=true; + var id = test.title.match(/([a-z]{2,})([0-9]+)/g); if (id) { id = id[0]; @@ -92,8 +90,7 @@ function verification_reporter (runner) { + indent + '(See README.verification)')); return; } - var test_ran = test.title; -// var test_ran = test.title.replace(id, ''); + var test_ran = test.title.trim(); // Check if test is in UnitTestCompleteness tab and "cross-off" if it is. /* TODO: implement UnitTestCompleteness spreadsheet processing @@ -104,14 +101,17 @@ function verification_reporter (runner) { } */ // Verify test is in spreadsheet. - if (spreadsheet[file]) { - let spreadsheet_test = spreadsheet[file][id]; + if (spreadsheet[suite]) { + let spreadsheet_test = spreadsheet[suite][id]; if (spreadsheet_test) { // If test is marked pending in spreadsheet, record for later output. if(spreadsheet_test.pending) { console.log(indent + green_x + color('bright pass', ' pending')); - pending[id] = test_ran; + if(! pending[suite]) { + pending[suite] = {}; + } + pending[suite][id] = test_ran; // If test descriptions match, mark green. } else if (spreadsheet_test.description == test_ran) { @@ -122,7 +122,7 @@ function verification_reporter (runner) { console.log(indent + red_x + color('fail', ' test description inconsistent with spreadsheet for ' - + id + ', ' + file)); + + id + ', ' + suite)); console.log("s: " + spreadsheet_test.description); console.log("t: " + test_ran); // Print test description string diff. @@ -130,31 +130,32 @@ function verification_reporter (runner) { console.log(indent + diff); errs.push(red_x + color('fail', ' Test descriptions do not match for ' - + id + ', ' + file) + + id + ', ' + suite) + '\n' + indent + 'In spreadsheet: ' + spreadsheet_test.description - + '\n' + indent + 'In test file: ' + test_ran + + '\n' + indent + 'In test suite: ' + test_ran + '\n' + indent + 'Diff: ' + diff); } // If test is included in spreadsheet, 'cross-off' by deleting. - if (spreadsheet[file][id]) { - delete spreadsheet[file][id]; + if (missingUnitTests[suite][id]) { + delete missingUnitTests[suite][id]; } } else { // If test is not in spreadsheet. console.log(indent + red_x + color('fail', ' ' - + id + ' missing from spreadsheet file ' + file)); + + id + ' missing from spreadsheet suite ' + suite)); errs.push(red_x + color('fail', ' Test ' + id + ' missing from ' - + file + ' spreadsheet file.')); + + suite + ' spreadsheet suite.')); + assert.equal(true, false); } } else { // If test file not found in directory. console.log(indent + red_x - + color('fail', ' test file ' + file + + color('fail', ' test suite ' + suite + ' does not match a spreadsheet in the Spreadsheets directory')); errs.push(red_x - + color('fail', ' Test file ' + file + + color('fail', ' Test suite ' + suite + ' missing from Spreadsheets directory. Possible solutions:\n' + '1. Ensure test is listed in correct *.csv file.\n' + '2. Ensure the *.csv file name is included in the contract block title.\n' @@ -170,11 +171,15 @@ function verification_reporter (runner) { console.log(color('bright pass', 'Pending Tests:')); console.log('The following tests are included in the test suite, but\n' + 'marked pending in the spreadsheet (delete -p flag once merged): '); - console.log(pending); + console.log(util.inspect(pending, { showHidden: false, depth: null })); } - // TODO: fix pending // Do not report tests that are missing from test suite but marked pending. - // delete spreadsheet.pending; + for(var pendingsuite in pending) { + for(var pendingID in pending[pendingsuite]) { + delete missingUnitTests[pendingsuite][pendingID]; + } + } + // Print out any tests that are included in UnitTestCompleteness tab but // missing from the test suite. // TODO: fix completeness spreadshet @@ -188,31 +193,29 @@ function verification_reporter (runner) { } delete spreadsheet.completeness;*/ // If all the tests in a tab are present, 'cross-off' tab by deleting. - for(var file in spreadsheet) { - if (_.isEmpty(spreadsheet[file])) { - delete spreadsheet[file]; + for(var testSuite in missingUnitTests) { + if (_.isEmpty(missingUnitTests[testSuite])) { + delete missingUnitTests[testSuite]; } } + + // Do not report missing unit tests for files that did not run + for(var testSuite in missingUnitTests){ + if(! _.has(executedTestSuites, testSuite)) { + console.log(color('fail', 'Did not run: ' + testSuite)); + delete missingUnitTests[testSuite]; + } + } + // If all tests are 'crossed-off', print success. - if (_.isEmpty(spreadsheet)) { + if (_.isEmpty(missingUnitTests)) { console.log('\n' + green_ok + color('bright pass', ' Test suite contains all tests in spreadsheet.')); } else { // If not all tests are 'crossed-off', print the tests remaining. console.log(color('bright fail', '\nTests missing from test suite (but included in spreadsheet):\n')); - console.log(spreadsheet); // TODO: test this line works - } - // Print all errors where executed tests did not match spreadsheet. - if (errs.length) { - console.log(color('bright fail', - '\nTests missing from spreadsheet (but included in test suite): ')); - errs.map((err) => { - console.log('\n' + err); - }); - } else { - console.log('\n' + green_ok + color('bright pass', - ' Spreadsheet contains all tests in test suite.')); + console.log(util.inspect(missingUnitTests, { showHidden: false, depth: null })); } }); } From 3895e5777daa8cb9e3d40bf5dcbb5a12939bfa48 Mon Sep 17 00:00:00 2001 From: mirathewhite Date: Thu, 4 Oct 2018 11:56:56 -0400 Subject: [PATCH 20/74] updated README --- verification/README.verification.txt | 51 ++++++---------------------- 1 file changed, 11 insertions(+), 40 deletions(-) diff --git a/verification/README.verification.txt b/verification/README.verification.txt index 5a075ff42..fe4dd63e6 100644 --- a/verification/README.verification.txt +++ b/verification/README.verification.txt @@ -1,7 +1,7 @@ The spreadsheet verification tool requires certain naming and usage conventions to function correctly. -Test Codes: +Unit test codes: - Should follow the format of lowercase letters followed by a number with no spaces. (ex. pt001, ept016, misc0000, legacy2, fiat19) @@ -11,17 +11,15 @@ Test Codes: - Should be listed under the 'Code' column of each spreadsheet tab. -Test Titles: -- Should exactly match the test description assigned to the test in the - spreadsheet. +CSV files: +- All CSV files must be in the `verification/Spreadsheets` directory. -Spreadsheet Tabs: - -- Should have the same name as the test file they represent. - This name should be formatted BlankTests where Blank consists of uppercase - and/or lowercase letters and is followed without a space by the word 'Tests'. - (ex. PositiveTests, tokenTests, ABITests) +- Each unit test contract block is associated with a single *.csv file. + If the contract block title is 'FiatToken_EventTests' then it will be tested + against FiatToken_EventTests.csv. The verification tool will ignore all + text in the contract block title after a space. 'FiatToken_EventTests Upgraded' + will also be verified against FiatToken_EventTests.csv - Should include a column 'code' or 'Code' listing all unique test codes that correspond to tests expected in the test file. @@ -33,7 +31,7 @@ Spreadsheet Tabs: - Should keep the column headers in the top row. -UnitTestCompleteness tab: +UnitTestCompleteness CSV (unsupported): - The verification tool will print out any test codes that are featured in the UnitTestCompleteness tab but missing from the test suite. @@ -44,11 +42,7 @@ UnitTestCompleteness tab: Contract Block Titles: -- Should include the name of the test file they run, and this name should not - be immediately preceded by letters. - (ex. If the contract block runs the PositiveTests file, it should be named - 'FiatToken_PositiveTests', 'PositiveTestsupgraded', 'PositiveTests' etc., - but not 'upgradedPositiveTests'.) +- Must match the CSV file name that it is tested against (see CSV files above). - Should include the word 'Legacy' if they run tests that do not need to be recorded in the spreadsheet and can be ignored by the verification tool. @@ -74,29 +68,6 @@ Pending Tests: - To DISABLE the spreadsheet verification tool, go to the file truffle.js and comment out the following line: - reporter: './verification/verification_reporter.js', + reporter: 'verification/verification_reporter.js', Then, uncomment the line above it. //reporter: 'Spec', - -- To ENABLE the spreadsheet verification tool FOR THE FIRST TIME. - - 1) Ensure your browser is signed in to your Circle Google account and visit - https://developers.google.com/sheets/api/quickstart/nodejs . - - 2) Press the blue 'ENABLE THE GOOGLE SHEETS API' button. - - 3) Enter a project name (i.e. 'spreadsheet-verification') and product name - (i.e 'centre-tokens') and download the credentials.json file. - - 4) Move your credentials.json file into the verification/GoogleSheets folder. - - 5) Run 'npm run truffle-test'. You should be prompted to visit a URL and enter a code - that you find there into your terminal. This will create a token.json file - inside the GoogleSheets folder. Note, if a token.json file already exists in - this folder, you will encounter an error. - - From there, you should be good to go. This process only needs to be completed - the first time you use the tool. - - Note: Ensure that credentials.json and token.json are included in .gitignore - before committing. From 9f524bfa76a2a524a49a0e5dc2ec231372f1e1d8 Mon Sep 17 00:00:00 2001 From: mirathewhite Date: Thu, 4 Oct 2018 13:44:57 -0400 Subject: [PATCH 21/74] Added unit test completeness testing --- .../FiatToken - UnitTestCompleteness.csv} | 0 verification/spreadsheet_parser.js | 29 +++++++++++++++++-- verification/verification_reporter.js | 24 ++++++++------- 3 files changed, 40 insertions(+), 13 deletions(-) rename verification/{ContractStateChanges - UnitTestCompleteness.csv => Spreadsheets/FiatToken - UnitTestCompleteness.csv} (100%) diff --git a/verification/ContractStateChanges - UnitTestCompleteness.csv b/verification/Spreadsheets/FiatToken - UnitTestCompleteness.csv similarity index 100% rename from verification/ContractStateChanges - UnitTestCompleteness.csv rename to verification/Spreadsheets/FiatToken - UnitTestCompleteness.csv diff --git a/verification/spreadsheet_parser.js b/verification/spreadsheet_parser.js index 9996510d6..be5df1f4e 100644 --- a/verification/spreadsheet_parser.js +++ b/verification/spreadsheet_parser.js @@ -23,7 +23,7 @@ function UnitTest(code, description, pending){ /** * Reads all files in Spreadsheets directory and returns an oject with their contents * Returns a UnitTestDirectory object -* TODO: handle errors, null objects, UnitTestCompleteness +* TODO: handle errors, null objects */ function load() { var unitTestDirectory = {}; @@ -44,8 +44,13 @@ function load() { var unitTestSet = {}; var spreadsheet = parse(csvFileContents, {columns: true}); spreadsheet.forEach(row => { - var unitTest = parseRow(row); - unitTestSet[unitTest.code] = unitTest; + if(file.match("Completeness")){ + var unitTestArray = parseCompletenessRow(row); + unitTestArray.forEach(unitTest => {unitTestSet[unitTest.code] = unitTest}); + } else { + var unitTest = parseRow(row); + unitTestSet[unitTest.code] = unitTest; + } }); var unittestfilename = getTestSuiteTitle(file); unitTestDirectory[unittestfilename] = unitTestSet; @@ -66,6 +71,24 @@ function isPending(spreadsheet, filename, code) { return false; } +// Reads a row and tries to find one or more test codes inside the row +// Returns an array of UnitTest objects +function parseCompletenessRow(row){ + var unitTests = []; + var index =0; + for(var columnName in row) { + var rowValues = row[columnName].split(","); + for(var potentialCodeIndex in rowValues) { + var codes = rowValues[potentialCodeIndex].match(/([a-z]{2,4})([0-9]+)/g); + for(var codeIndex in codes) { + unitTests[index] = new UnitTest(codes[codeIndex], "", false); + ++index; + } + } + } + return unitTests; +} + // Transforms a row in spreadsheet into a UnitTest object // row: a literal object. One of the keys must be 'code/Code' and another 'description/Description' // Returns a UnitTest object or null if cannot find appropriate keys. diff --git a/verification/verification_reporter.js b/verification/verification_reporter.js index 4b9e5de13..b38cbe4cb 100644 --- a/verification/verification_reporter.js +++ b/verification/verification_reporter.js @@ -92,14 +92,18 @@ function verification_reporter (runner) { } var test_ran = test.title.trim(); - // Check if test is in UnitTestCompleteness tab and "cross-off" if it is. - /* TODO: implement UnitTestCompleteness spreadsheet processing - if (!_.isEmpty(spreadsheet.completeness)) { - if (spreadsheet.completeness[id]) { - delete spreadsheet.completeness[id]; - } + // check if test is in a "completeness" unit test sheet + // if it is, cross it off as found by deleting it + for(var completeness_suite in missingUnitTests) { + if(completeness_suite.match(/Completeness/)){ + if(missingUnitTests[completeness_suite][id]) { + console.log("complete: " + id); + delete missingUnitTests[completeness_suite][id]; + } + } } -*/ + + // Verify test is in spreadsheet. if (spreadsheet[suite]) { let spreadsheet_test = spreadsheet[suite][id]; @@ -201,7 +205,7 @@ function verification_reporter (runner) { // Do not report missing unit tests for files that did not run for(var testSuite in missingUnitTests){ - if(! _.has(executedTestSuites, testSuite)) { + if(! _.has(executedTestSuites, testSuite) && ! testSuite.match(/Completeness/)) { console.log(color('fail', 'Did not run: ' + testSuite)); delete missingUnitTests[testSuite]; } @@ -210,11 +214,11 @@ function verification_reporter (runner) { // If all tests are 'crossed-off', print success. if (_.isEmpty(missingUnitTests)) { console.log('\n' + green_ok + color('bright pass', - ' Test suite contains all tests in spreadsheet.')); + ' Test run contains all tests in spreadsheet.')); } else { // If not all tests are 'crossed-off', print the tests remaining. console.log(color('bright fail', - '\nTests missing from test suite (but included in spreadsheet):\n')); + '\nThe following tests were not executed (but are included in a spreadsheet):\n')); console.log(util.inspect(missingUnitTests, { showHidden: false, depth: null })); } }); From 836cf2ba160e363543f6bf2f8bc38741c3b2f0b9 Mon Sep 17 00:00:00 2001 From: mirathewhite Date: Tue, 9 Oct 2018 17:11:14 -0400 Subject: [PATCH 22/74] Basic tests (#224) * Wrote 15 BasicTests * Finish writing BasicTests, added ABITests * Removed unused variables, fixed comments, and deleted quotation marks from csv file * returning quatation marks --- test/TokenTestUtils.js | 2 + test/minting/MintP0BasicTests.js | 633 ++++++++++++++++++ test/minting/MintP0_ABITests.js | 70 ++ ...Tp0 - ABITests.csv => MINTp0_ABITests.csv} | 0 ...- BasicTests.csv => MINTp0_BasicTests.csv} | 110 +-- verification/verification_reporter.js | 14 +- 6 files changed, 761 insertions(+), 68 deletions(-) create mode 100644 test/minting/MintP0BasicTests.js create mode 100644 test/minting/MintP0_ABITests.js rename verification/Spreadsheets/{MINTp0 - ABITests.csv => MINTp0_ABITests.csv} (100%) rename verification/Spreadsheets/{MINTp0 - BasicTests.csv => MINTp0_BasicTests.csv} (94%) diff --git a/test/TokenTestUtils.js b/test/TokenTestUtils.js index f9cd4fb67..2f452a917 100644 --- a/test/TokenTestUtils.js +++ b/test/TokenTestUtils.js @@ -9,6 +9,7 @@ var BigNumber = require('bignumber.js'); var trueInStorageFormat = "0x01"; var bigZero = new BigNumber(0); var bigHundred = new BigNumber(100); +var maxAmount = "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"; var assertDiff = require('assert-diff'); assertDiff.options.strict = true; var Q = require('q'); @@ -963,4 +964,5 @@ module.exports = { encodeCall: encodeCall, getInitializedV1: getInitializedV1, getAdmin: getAdmin, + maxAmount: maxAmount, }; diff --git a/test/minting/MintP0BasicTests.js b/test/minting/MintP0BasicTests.js new file mode 100644 index 000000000..9c761b7eb --- /dev/null +++ b/test/minting/MintP0BasicTests.js @@ -0,0 +1,633 @@ +var MintController = artifacts.require('minting/MintController'); +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"; + +async function run_tests(newToken, accounts) { + + beforeEach('Make fresh token contract', async function () { + rawToken = await newToken(); + tokenConfig = await initializeTokenWithProxyAndMintController(rawToken); + token = tokenConfig.token; + mintController = tokenConfig.mintController; + expectedMintControllerState = clone(tokenConfig.customState); + expectedTokenState = [{ 'variable': 'masterMinter', 'expectedValue': mintController.address }]; + }); + + it('bt001 Constructor - owner is msg.sender', async function () { + var newMintController = await MintController.new(token.address, {from: Accounts.arbitraryAccount}); + var owner = await newMintController.owner(); + assert.equal(owner, Accounts.arbitraryAccount); + }); + + it('bt002 transferOwnership works when owner is msg.sender', async function () { + await mintController.transferOwnership(Accounts.arbitraryAccount, {from: Accounts.mintOwnerAccount}); + expectedMintControllerState.owner = Accounts.arbitraryAccount; + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + }); + + it('bt003 transferOwnership reverts when owner is not msg.sender', async function () { + await expectRevert(mintController.transferOwnership(Accounts.arbitraryAccount, {from: Accounts.arbitraryAccount})); + }); + + it('bt004 configureController works when owner is msg.sender', async function () { + await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + }); + + it('bt005 configureController reverts when owner is not msg.sender', async function () { + await expectRevert(mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.arbitraryAccount})); + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + }); + + it('bt006 setMinterManager works when owner is msg.sender', async function () { + await mintController.setMinterManager(Accounts.arbitraryAccount, {from: Accounts.mintOwnerAccount}); + expectedMintControllerState.minterManager = Accounts.arbitraryAccount; + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + }); + + it('bt007 setMinterManager reverts when owner is not msg.sender', async function () { + await expectRevert(mintController.setMinterManager(Accounts.arbitraryAccount, {from: Accounts.arbitraryAccount})); + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + }); + + it('bt008 removeController works when owner is msg.sender', async function () { + // add a controller + await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + + // now remove it + await mintController.removeController(Accounts.controller1Account, {from: Accounts.mintOwnerAccount}); + expectedMintControllerState.controllers['controller1Account'] = zeroAddress; + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + }); + + it('bt009 removeController reverts when owner is not msg.sender', async function () { + // add a controller + await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + + // fail to remove it + await expectRevert(mintController.removeController(Accounts.controller1Account, {from: Accounts.arbitraryAccount})); + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + }); + + it('bt010 removeMinter reverts when msg.sender is not a controller', async function () { + await expectRevert(mintController.removeMinter({from: Accounts.controller1Account})); + }); + + it('bt011 removeMinter sets minters[M] to 0', async function () { + // add a minter + var amount = 789; + await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + await mintController.configureMinter(amount, {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]); + + // remove minter + await mintController.removeMinter({from: Accounts.controller1Account}); + expectedTokenState.pop(); + expectedTokenState.pop(); + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + }); + + it('bt012 configureMinter reverts when msg.sender is not a controller', async function () { + await expectRevert(mintController.configureMinter(50, {from: Accounts.controller1Account})); + }); + + it('bt013 configureMinter works when controllers[msg.sender]=M', async function () { + // add a controller + await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + + // now configure minter + var amount = 6789; + await mintController.configureMinter(amount, {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('bt014 incrementMinterAllowance reverts if msg.sender is not a controller', async function () { + await expectRevert(mintController.incrementMinterAllowance(50, {from: Accounts.controller1Account})); + }); + + it('bt015 incrementMinterAllowance works when controllers[msg.sender]=M', async function () { + await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + await mintController.configureMinter(0, {from: Accounts.controller1Account}); + + // now configure minter + var amount = 6789; + 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(amount) } + ); + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + }); + + + it('bt016 Constructor sets all controllers to 0', async function () { + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + }); + + it('bt017 removeController does not revert when controllers[C] is 0', async function () { + // "remove" a controller that does not exist + await mintController.removeController(Accounts.controller1Account, {from: Accounts.mintOwnerAccount}); + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + }); + + it('bt018 removeController removes an arbitrary controller', async function () { + // add a controller + await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + + // now remove it + await mintController.removeController(Accounts.controller1Account, {from: Accounts.mintOwnerAccount}); + expectedMintControllerState.controllers['controller1Account'] = zeroAddress; + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + }); + + it('bt019 configureController works when controller[C]=0', async function () { + // note: this is a duplicate of bt004 + await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + }); + + it('bt020 configureController works when controller[C] != 0', async function () { + // set controllers[controller1Account]=minterAccount + await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + + // now set controllers[controller1Account]=arbitraryAccount + await mintController.configureController(Accounts.controller1Account, Accounts.arbitraryAccount, {from: Accounts.mintOwnerAccount}); + expectedMintControllerState.controllers['controller1Account'] = Accounts.arbitraryAccount; + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + }); + + it('bt021 configureController(C,C) works', async function () { + await mintController.configureController(Accounts.controller1Account, Accounts.controller1Account, {from: Accounts.mintOwnerAccount}); + expectedMintControllerState.controllers['controller1Account'] = Accounts.controller1Account; + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + }); + + it('bt022 configureController works when setting controller[C]=msg.sender', async function () { + await mintController.configureController(Accounts.mintOwnerAccount, Accounts.controller1Account, {from: Accounts.mintOwnerAccount}); + expectedMintControllerState.controllers['controller1Account'] = Accounts.mintOwnerAccount; + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + }); + + it('bt023 configureController(C, newM) works when controller[C]=newM', async function () { + // set controllers[controller1Account]=minterAccount + await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + + // now set controllers[controller1Account]=minterAccount + await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + }); + + it('bt024 Constructor sets minterManager', async function () { + var minterManagerAddress = await mintController.minterManager(); + assert.equal(token.address, minterManagerAddress); + }); + + it('bt025 setMinterManager(x) works when existing minterManager = 0', async function () { + await mintController.setMinterManager(zeroAddress, {from: Accounts.mintOwnerAccount}); + expectedMintControllerState.minterManager = zeroAddress; + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + + await mintController.setMinterManager(Accounts.arbitraryAccount, {from: Accounts.mintOwnerAccount}); + expectedMintControllerState.minterManager = Accounts.arbitraryAccount; + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + }); + + it('bt026 setMinterManager(x) works when existing minterManager != 0', async function () { + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + + await mintController.setMinterManager(Accounts.arbitraryAccount, {from: Accounts.mintOwnerAccount}); + expectedMintControllerState.minterManager = Accounts.arbitraryAccount; + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + }); + + it('bt027 setMinterManager(x) works when x = msg.sender', async function () { + await mintController.setMinterManager(Accounts.mintOwnerAccount, {from: Accounts.mintOwnerAccount}); + expectedMintControllerState.minterManager = Accounts.mintOwnerAccount; + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + }); + + it('bt028 setMinterManager(x) works when x = minterManager', async function () { + var minterManagerAddress = await mintController.minterManager(); + await mintController.setMinterManager(minterManagerAddress, {from: Accounts.mintOwnerAccount}); + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + }); + + it('bt030 removeMinter reverts when minterManager is 0', async function () { + // set minterManager to 0 + await mintController.setMinterManager(zeroAddress, {from:Accounts.mintOwnerAccount}); + expectedMintControllerState.minterManager = zeroAddress; + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + + // configure minter will fail with any args + await(expectRevert(mintController.removeMinter({from: Accounts.controller1Account}))); + }); + + it('bt031 removeMinter reverts when minterManager is a user account', async function () { + // set minterManager to user account + await mintController.setMinterManager(Accounts.arbitraryAccount, {from:Accounts.mintOwnerAccount}); + expectedMintControllerState.minterManager = Accounts.arbitraryAccount; + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + + // configure minter will fail with any args + await(expectRevert(mintController.removeMinter({from: Accounts.controller1Account}))); + }); + + it('bt032 removeMinter works when minterManager is ok', async function () { + // add a minter + var amount = 3; + await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + await mintController.configureMinter(amount, {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]); + + // remove minter + await mintController.removeMinter({from: Accounts.controller1Account}); + expectedTokenState.pop(); + expectedTokenState.pop(); + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + }); + + it('bt033 configureMinter reverts when minterManager is 0', async function () { + // set minterManager to 0 + await mintController.setMinterManager(zeroAddress, {from:Accounts.mintOwnerAccount}); + expectedMintControllerState.minterManager = zeroAddress; + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + + // configure minter will fail with any args + await(expectRevert(mintController.configureMinter(50, {from: Accounts.controller1Account}))); + }); + + it('bt034 configureMinter reverts when minterManager is a user account', async function () { + // set minterManager to user account + await mintController.setMinterManager(Accounts.arbitraryAccount, {from:Accounts.mintOwnerAccount}); + expectedMintControllerState.minterManager = Accounts.arbitraryAccount; + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + + // configure minter will fail with any args + await(expectRevert(mintController.configureMinter(50, {from: Accounts.controller1Account}))); + }); + + it('bt035 configureMinter works when minterManager is ok', async function () { + var amount = 456; + await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + await mintController.configureMinter(amount, {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('bt036 incrementMinterAllowance reverts when minterManager is 0', async function () { + // set minterManager to zero + await mintController.setMinterManager(zeroAddress, {from:Accounts.mintOwnerAccount}); + expectedMintControllerState.minterManager = zeroAddress; + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + + // incrementMinterAllowance will fail with any args + await(expectRevert(mintController.incrementMinterAllowance(50, {from: Accounts.controller1Account}))); + }); + + it('bt037 incrementMinterAllowance reverts when minterManager is a user account', async function () { + // set minterManager to user account + await mintController.setMinterManager(Accounts.arbitraryAccount, {from:Accounts.mintOwnerAccount}); + expectedMintControllerState.minterManager = Accounts.arbitraryAccount; + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + + // incrementMinterAllowance will fail with any args + await(expectRevert(mintController.incrementMinterAllowance(50, {from: Accounts.controller1Account}))); + }); + + it('bt038 incrementMinterAllowance works when minterManager is ok', async function () { + await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + await mintController.configureMinter(0, {from: Accounts.controller1Account}); + + // now incrementMinterAllowance + var amount = 45; + 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(amount) } + ); + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + }); + + it('bt039 configureMinter(M, amt) works when minterManager.isMinter(M)=false', async function () { + var amount = 64; + await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + + var minterManager = FiatToken.at(await mintController.minterManager()); + var isMinter = await minterManager.isMinter(Accounts.minterAccount); + assert.isFalse(isMinter); + + await mintController.configureMinter(amount, {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('bt040 configureMinter(M, amt) works when minterManager.isMinter(M)=true', async function () { + var amount = 64; + await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + await mintController.configureMinter(0, {from: Accounts.controller1Account}); + + var minterManager = FiatToken.at(await mintController.minterManager()); + var isMinter = await minterManager.isMinter(Accounts.minterAccount); + assert.isTrue(isMinter); + + await mintController.configureMinter(amount, {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('bt041 removeMinter(M) works when minterManager.isMinter(M)=false', async function () { + var amount = 64; + await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + + var minterManager = FiatToken.at(await mintController.minterManager()); + var isMinter = await minterManager.isMinter(Accounts.minterAccount); + assert.isFalse(isMinter); + + await mintController.removeMinter({from: Accounts.controller1Account}); + expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + }); + + it('bt042 removeMinter(M) works when minterManager.isMinter(M)=true', async function () { + var amount = 64; + await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + await mintController.configureMinter(0, {from: Accounts.controller1Account}); + + var minterManager = FiatToken.at(await mintController.minterManager()); + var isMinter = await minterManager.isMinter(Accounts.minterAccount); + assert.isTrue(isMinter); + + await mintController.removeMinter({from: Accounts.controller1Account}); + expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + }); + + it('bt043 incrementMinterAllowance(M, amt) reverts when minterManager.isMinter(M)=false', async function () { + var amount = 64; + await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + + var minterManager = FiatToken.at(await mintController.minterManager()); + var isMinter = await minterManager.isMinter(Accounts.minterAccount); + assert.isFalse(isMinter); + + await expectRevert(mintController.incrementMinterAllowance(amount, {from: Accounts.controller1Account})); + expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + }); + + it('bt044 incrementMinterAllowance(M, amt) works when minterManager.isMinter(M)=true', async function () { + var amount = 65424; + await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + await mintController.configureMinter(0, {from: Accounts.controller1Account}); + + var minterManager = FiatToken.at(await mintController.minterManager()); + var isMinter = await minterManager.isMinter(Accounts.minterAccount); + assert.isTrue(isMinter); + + 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(amount) } + ); + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + }); + + it('bt045 constructor - minterManager.isMinter[ALL] is false', async function () { + var minterManager = FiatToken.at(await mintController.minterManager()); + + var isMinterMappingEval = async function(accountAddress) { + return await minterManager.isMinter(accountAddress); + }; + + var isMinterResults = await getAccountState(isMinterMappingEval, Accounts); + for(var account in Accounts) { + assert.isFalse(isMinterResults[account]); + } + }); + + it('bt046 constructor - minterManager.minterAllowance[ALL] = 0', async function () { + var minterManager = FiatToken.at(await mintController.minterManager()); + + var minterAllowanceMapping = async function(accountAddress) { + return await minterManager.minterAllowance(accountAddress); + }; + + var minterAllowanceResults = await getAccountState(minterAllowanceMapping, Accounts); + for(var account in Accounts) { + assert(new BigNumber(minterAllowanceResults[account]).isEqualTo(new BigNumber(0))); + } + }); + + it('bt047 incrementMinterAllowance(M,amt) works when minterAllowance is 0', async function () { + var amount = 64; + await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + await mintController.configureMinter(0, {from: Accounts.controller1Account}); + + var minterManager = FiatToken.at(await mintController.minterManager()); + var minterAllowance = await minterManager.minterAllowance(Accounts.minterAccount); + assert((new BigNumber(minterAllowance)).isEqualTo(new BigNumber(0))); + + 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(amount) } + ); + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + }); + + it('bt048 incrementMinterAllowance(M, amt) works when minterAllowance > 0', async function () { + var initialAmount = 987341; + var incrementAmount = 64; + await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + await mintController.configureMinter(initialAmount, {from: Accounts.controller1Account}); + + var minterManager = FiatToken.at(await mintController.minterManager()); + var minterAllowance = await minterManager.minterAllowance(Accounts.minterAccount); + assert((new BigNumber(minterAllowance)).isEqualTo(new BigNumber(initialAmount))); + + await mintController.incrementMinterAllowance(incrementAmount, {from: Accounts.controller1Account}); + expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; + expectedTokenState.push( + { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(initialAmount + incrementAmount) } + ); + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + }); + + it('bt049 incrementMinterAllowance(M,amt) reverts when minterAllowance[M] + amt > 2^256', async function () { + var initialAmount = "0x" + ((new BigNumber(maxAmount)).minus(new BigNumber(45))).toString(16); + var incrementAmount = 64; + await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + await mintController.configureMinter(initialAmount, {from: Accounts.controller1Account}); + + expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; + expectedTokenState.push( + { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(initialAmount) } + ); + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + + await expectJump(mintController.incrementMinterAllowance(incrementAmount, {from: Accounts.controller1Account})); + + }); + + it('bt050 configureMinter(M,amt) works when minterAllowance=0', async function () { + var amount = 64; + await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + await mintController.configureMinter(0, {from: Accounts.controller1Account}); + + var minterManager = FiatToken.at(await mintController.minterManager()); + var minterAllowance = await minterManager.minterAllowance(Accounts.minterAccount); + assert((new BigNumber(minterAllowance)).isEqualTo(new BigNumber(0))); + + await mintController.configureMinter(amount, {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('bt051 configureMinter(M,amt) works when minterAllowance>0', async function () { + var amount = 64; + await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + await mintController.configureMinter(amount, {from: Accounts.controller1Account}); + + var minterManager = FiatToken.at(await mintController.minterManager()); + var minterAllowance = await minterManager.minterAllowance(Accounts.minterAccount); + assert((new BigNumber(minterAllowance)).isEqualTo(new BigNumber(amount))); + + await mintController.configureMinter(2* 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('bt052 configureMinter(M,amt) works when amt+minterAllowance > 2^256', async function () { + var amount = 64; + var minterAllowance = maxAmount; + await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + await mintController.configureMinter(maxAmount, {from: Accounts.controller1Account}); + + await mintController.configureMinter(amount, {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('bt053 removeMinter works when the minterAllowance is 0', async function () { + var amount = 64; + await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + await mintController.configureMinter(0, {from: Accounts.controller1Account}); + + var minterManager = FiatToken.at(await mintController.minterManager()); + var minterAllowance = await minterManager.minterAllowance(Accounts.minterAccount); + assert((new BigNumber(minterAllowance)).isEqualTo(new BigNumber(0))); + + await mintController.removeMinter({from: Accounts.controller1Account}); + expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + }); + + it('bt054 removeMinter works when the minterAllowance is not zero', async function () { + var amount = 64; + await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + await mintController.configureMinter(amount, {from: Accounts.controller1Account}); + + var minterManager = FiatToken.at(await mintController.minterManager()); + var minterAllowance = await minterManager.minterAllowance(Accounts.minterAccount); + assert((new BigNumber(minterAllowance)).isEqualTo(new BigNumber(amount))); + + await mintController.removeMinter({from: Accounts.controller1Account}); + expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + }); + + it('bt055 removeMinter works when the minterAllowance is big', async function () { + var amount = maxAmount; + await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + await mintController.configureMinter(maxAmount, {from: Accounts.controller1Account}); + + await mintController.removeMinter({from: Accounts.controller1Account}); + expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + }); +} + +var testWrapper = require('./../TestWrapper'); +testWrapper.execute('MINTp0_BasicTests', run_tests); + +module.exports = { + run_tests: run_tests, +} diff --git a/test/minting/MintP0_ABITests.js b/test/minting/MintP0_ABITests.js new file mode 100644 index 000000000..d8344eb39 --- /dev/null +++ b/test/minting/MintP0_ABITests.js @@ -0,0 +1,70 @@ +var MintController = artifacts.require('minting/MintController'); +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 AccountPrivateKeys = AccountUtils.AccountPrivateKeys; +var getAccountState = AccountUtils.getAccountState; +var MintControllerState = AccountUtils.MintControllerState; +var initializeTokenWithProxyAndMintController = mintUtils.initializeTokenWithProxyAndMintController; +var checkMintControllerState = mintUtils.checkMintControllerState; + +var zeroAddress = "0x0000000000000000000000000000000000000000"; + +var abiUtils = require('./../ABIUtils'); +var makeRawTransaction = abiUtils.makeRawTransaction; +var sendRawTransaction = abiUtils.sendRawTransaction; +var msgData = abiUtils.msgData; +var msgData1 = abiUtils.msgData1; + +async function run_tests(newToken, accounts) { + + beforeEach('Make fresh token contract', async function () { + rawToken = await newToken(); + tokenConfig = await initializeTokenWithProxyAndMintController(rawToken); + token = tokenConfig.token; + mintController = tokenConfig.mintController; + expectedMintControllerState = clone(tokenConfig.customState); + expectedTokenState = [{ 'variable': 'masterMinter', 'expectedValue': mintController.address }]; + }); + + it('abi100 internal_setMinterAllowance is internal', async function () { + await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + let badData = msgData1('internal_setMinterAllowance(address,uint256)', Accounts.controller1Account, 569); + let raw = makeRawTransaction( + badData, + Accounts.mintOwnerAccount, + AccountPrivateKeys.mintOwnerPrivateKey, + mintController.address); + await expectRevert(sendRawTransaction(raw)); + }); + + it('abi101 setOwner is internal', async function () { + let badData = msgData('setOwner(address)', Accounts.arbitraryAccount); + let raw = makeRawTransaction( + badData, + Accounts.mintOwnerAccount, + AccountPrivateKeys.mintOwnerPrivateKey, + mintController.address); + await expectRevert(sendRawTransaction(raw)); + }); + +} + +var testWrapper = require('./../TestWrapper'); +testWrapper.execute('MINTp0_ABITests', run_tests); + +module.exports = { + run_tests: run_tests, +} diff --git a/verification/Spreadsheets/MINTp0 - ABITests.csv b/verification/Spreadsheets/MINTp0_ABITests.csv similarity index 100% rename from verification/Spreadsheets/MINTp0 - ABITests.csv rename to verification/Spreadsheets/MINTp0_ABITests.csv diff --git a/verification/Spreadsheets/MINTp0 - BasicTests.csv b/verification/Spreadsheets/MINTp0_BasicTests.csv similarity index 94% rename from verification/Spreadsheets/MINTp0 - BasicTests.csv rename to verification/Spreadsheets/MINTp0_BasicTests.csv index 4a27a8473..b994bc2fd 100644 --- a/verification/Spreadsheets/MINTp0 - BasicTests.csv +++ b/verification/Spreadsheets/MINTp0_BasicTests.csv @@ -1,55 +1,55 @@ -File,Function,Special Condition,Code,Description -Controller.sol,configureController,msg.sender == owner,bt004,bt004 configureController works when owner is msg.sender -Controller.sol,configureController,msg.sender != owner,bt005,bt005 configureController reverts when owner is not msg.sender -Controller.sol,configureController,controllers[C]=0,bt019,bt019 configureController works when controller[C]=0 -Controller.sol,configureController,controllers[C] != 0,bt020,bt020 configureController works when controller[C] != 0 -Controller.sol,configureController,controllers[C]=C,bt021,"bt021 configureController(C,C) works" -Controller.sol,configureController,controllers[C] == msg.sender,bt022,bt022 configureController works when setting controller[C]=msg.sender -Controller.sol,configureController,controllers[C] == newM,bt023,"bt023 configureController(C, newM) works when controller[C]=newM" -Controller.sol,constructor,controllers[ALL] = 0,bt016,bt016 Constructor sets all controllers to 0 -Controller.sol,removeController,msg.sender == owner,bt008,bt008 removeController works when owner is msg.sender -Controller.sol,removeController,msg.sender != owner,bt009,bt009 removeController reverts when owner is not msg.sender -Controller.sol,removeController,controllers[C]=0,bt017,bt017 removeController does not revert when controllers[C] is 0 -Controller.sol,removeController,controllers[C]=M,bt018,bt018 removeController removes an arbitrary controller -FiatTokenV1.sol,constructor,minterManager.isMinter[ALL] == false,bt045,bt045 constructor - minterManager.isMinter[ALL] is false -FiatTokenV1.sol,constructor,minterManager.minterAllowance[ALL] == 0,bt046,bt046 constructor - minterManager.minterAllowance[ALL] = 0 -MintController.sol,configureMinter,controllers[msg.sender]==0,bt012,bt012 configureMinter reverts when msg.sender is not a controller -MintController.sol,configureMinter,controllers[msg.sender]==M,bt013,bt013 configureMinter sents controllers[msg.sender] to M -MintController.sol,configureMinter,minterManager = 0,bt033,bt033 configureMinter reverts when minterManager is 0 -MintController.sol,configureMinter,minterManager != MinterManagerInterface,bt034,bt034 configureMinter reverts when minterManager is a user account -MintController.sol,configureMinter,minterManager == OK,bt035,bt035 configureMinter works when minterManager is ok -MintController.sol,configureMinter,minterManager.isMinter == false,bt039,"bt039 configureMinter(M, amt) works when minterManager.isMinter(M)=false" -MintController.sol,configureMinter,minterManager.isMinter == true,bt040,"bt040 configureMinter(M, amt) works when minterManager.isMinter(M)=true" -MintController.sol,configureMinter,minterManager.minterAllowance[M] == 0,bt050,"bt050 configureMinter(M,amt) works when minterAllowance=0" -MintController.sol,configureMinter,minterManager.minterAllowance[M] == X,bt051,"bt051 configureMinter(M,amt) works when minterAllowance>0" -MintController.sol,configureMinter,minterManager.minterAllowance[M] == BIG,bt052,"bt052 configureMinter(M,amt) works when amt+minterAllowance > 2^256" -MintController.sol,constructor,minterManager == init,bt024,bt024 Constructor sets minterManager -MintController.sol,incrementMinterAllowance,controllers[msg.sender]==0,bt014,bt014 incrementMinterAllowance reverts if msg.sender is not a controller -MintController.sol,incrementMinterAllowance,controllers[msg.sender]==M,bt015,bt015 incrementMinterAllowance sets controllers[msg.sender] to M -MintController.sol,incrementMinterAllowance,minterManager = 0,bt036,bt036 incrementMinterAllowance reverts when minterManager is 0 -MintController.sol,incrementMinterAllowance,minterManager != MinterManagerInterface,bt037,bt037 incrementMinterAllowance reverts when minterManager is a user account -MintController.sol,incrementMinterAllowance,minterManager == OK,bt038,bt038 incrementMinterAllowance works when minterManager is ok -MintController.sol,incrementMinterAllowance,minterManager.isMinter == false,bt043,"bt043 incrementMinterAllowance(M, amt) works when minterManager.isMinter(M)=false" -MintController.sol,incrementMinterAllowance,minterManager.isMinter == true,bt044,"bt044 incrementMinterAllowance(M, amt) works when minterManager.isMinter(M)=true" -MintController.sol,incrementMinterAllowance,minterManager.minterAllowance[M] == 0,bt047,"bt047 incrementMinterAllowance(M,amt) works when minterAllowance is 0" -MintController.sol,incrementMinterAllowance,minterManager.minterAllowance[M] == X,bt048,"bt048 incrementMinterAllowance(M, amt) works when minterAllowance > 0" -MintController.sol,incrementMinterAllowance,minterManager.minterAllowance[M] == BIG,bt049,"bt049 incrementMinterAllowance(M,amt) reverts when minterAllowance[M] + amt > 2^256" -MintController.sol,removeMinter,controllers[msg.sender]==0,bt010,bt010 removeMinter reverts when msg.sender is not a controller -MintController.sol,removeMinter,controllers[msg.sender]==M,bt011,bt011 removeMinter sets controllers[msg.sender] to 0 -MintController.sol,removeMinter,minterManager = 0,bt030,bt030 removeMinter reverts when minterManager is 0 -MintController.sol,removeMinter,minterManager != MinterManagerInterface,bt031,bt031 removeMinter reverts when minterManager is a user account -MintController.sol,removeMinter,minterManager == OK,bt032,bt032 removeMinter works when minterManager is ok -MintController.sol,removeMinter,minterManager.isMinter == false,bt041,bt041 removeMinter(M) works when minterManager.isMinter(M)=false -MintController.sol,removeMinter,minterManager.isMinter == true,bt042,bt042 removeMinter(M) works when minterManager.isMinter(M)=true -MintController.sol,removeMinter,minterManager.minterAllowance[M] == 0,bt053,bt053 removeMinter works when the minterAllowance is 0 -MintController.sol,removeMinter,minterManager.minterAllowance[M] == X,bt054,bt054 removeMinter works when the minterAllowance is not zero -MintController.sol,removeMinter,minterManager.minterAllowance[M] == BIG,bt055,bt055 removeMinter works when the minterAllowance is big -MintController.sol,setMinterManager,msg.sender == owner,bt006,bt006 setMinterManager works when owner is msg.sender -MintController.sol,setMinterManager,msg.sender != owner,bt007,bt007 setMinterManager reverts when owner is not msg.sender -MintController.sol,setMinterManager,minterManager == 0,bt025,bt025 setMinterManager(x) works when existing minterManager = 0 -MintController.sol,setMinterManager,minterManager != 0,bt026,bt026 setMinterManager(x) works when existing minterManager != 0 -MintController.sol,setMinterManager,minterManager == msg.sender,bt027,bt027 setMinterManager(x) works when x = msg.sender -MintController.sol,setMinterManager,minterManager == newMinterManager,bt028,bt028 setMinterManager(x) works when x = minterManager -Ownable.sol,constructor,msg.sender == owner,bt001,bt001 Constructor - owner is msg.sender -Ownable.sol,transferOwnership,msg.sender == owner,bt002,bt002 transferOwnership works when owner is msg.sender -Ownable.sol,transferOwnership,msg.sender != owner,bt003,bt003 transferOwnership reverts when owner is not msg.sender \ No newline at end of file +File,Function,Special Condition,Code,Description +Controller.sol,configureController,msg.sender == owner,bt004,bt004 configureController works when owner is msg.sender +Controller.sol,configureController,msg.sender != owner,bt005,bt005 configureController reverts when owner is not msg.sender +Controller.sol,configureController,controllers[C]=0,bt019,bt019 configureController works when controller[C]=0 +Controller.sol,configureController,controllers[C] != 0,bt020,bt020 configureController works when controller[C] != 0 +Controller.sol,configureController,controllers[C]=C,bt021,"bt021 configureController(C,C) works" +Controller.sol,configureController,controllers[C] == msg.sender,bt022,bt022 configureController works when setting controller[C]=msg.sender +Controller.sol,configureController,controllers[C] == newM,bt023,"bt023 configureController(C, newM) works when controller[C]=newM" +Controller.sol,constructor,controllers[ALL] = 0,bt016,bt016 Constructor sets all controllers to 0 +Controller.sol,removeController,msg.sender == owner,bt008,bt008 removeController works when owner is msg.sender +Controller.sol,removeController,msg.sender != owner,bt009,bt009 removeController reverts when owner is not msg.sender +Controller.sol,removeController,controllers[C]=0,bt017,bt017 removeController does not revert when controllers[C] is 0 +Controller.sol,removeController,controllers[C]=M,bt018,bt018 removeController removes an arbitrary controller +FiatTokenV1.sol,constructor,minterManager.isMinter[ALL] == false,bt045,bt045 constructor - minterManager.isMinter[ALL] is false +FiatTokenV1.sol,constructor,minterManager.minterAllowance[ALL] == 0,bt046,bt046 constructor - minterManager.minterAllowance[ALL] = 0 +MintController.sol,configureMinter,controllers[msg.sender]==0,bt012,bt012 configureMinter reverts when msg.sender is not a controller +MintController.sol,configureMinter,controllers[msg.sender]==M,bt013,bt013 configureMinter works when controllers[msg.sender]=M +MintController.sol,configureMinter,minterManager = 0,bt033,bt033 configureMinter reverts when minterManager is 0 +MintController.sol,configureMinter,minterManager != MinterManagerInterface,bt034,bt034 configureMinter reverts when minterManager is a user account +MintController.sol,configureMinter,minterManager == OK,bt035,bt035 configureMinter works when minterManager is ok +MintController.sol,configureMinter,minterManager.isMinter == false,bt039,"bt039 configureMinter(M, amt) works when minterManager.isMinter(M)=false" +MintController.sol,configureMinter,minterManager.isMinter == true,bt040,"bt040 configureMinter(M, amt) works when minterManager.isMinter(M)=true" +MintController.sol,configureMinter,minterManager.minterAllowance[M] == 0,bt050,"bt050 configureMinter(M,amt) works when minterAllowance=0" +MintController.sol,configureMinter,minterManager.minterAllowance[M] == X,bt051,"bt051 configureMinter(M,amt) works when minterAllowance>0" +MintController.sol,configureMinter,minterManager.minterAllowance[M] == BIG,bt052,"bt052 configureMinter(M,amt) works when amt+minterAllowance > 2^256" +MintController.sol,constructor,minterManager == init,bt024,bt024 Constructor sets minterManager +MintController.sol,incrementMinterAllowance,controllers[msg.sender]==0,bt014,bt014 incrementMinterAllowance reverts if msg.sender is not a controller +MintController.sol,incrementMinterAllowance,controllers[msg.sender]==M,bt015,bt015 incrementMinterAllowance works when controllers[msg.sender]=M +MintController.sol,incrementMinterAllowance,minterManager = 0,bt036,bt036 incrementMinterAllowance reverts when minterManager is 0 +MintController.sol,incrementMinterAllowance,minterManager != MinterManagerInterface,bt037,bt037 incrementMinterAllowance reverts when minterManager is a user account +MintController.sol,incrementMinterAllowance,minterManager == OK,bt038,bt038 incrementMinterAllowance works when minterManager is ok +MintController.sol,incrementMinterAllowance,minterManager.isMinter == false,bt043,"bt043 incrementMinterAllowance(M, amt) reverts when minterManager.isMinter(M)=false" +MintController.sol,incrementMinterAllowance,minterManager.isMinter == true,bt044,"bt044 incrementMinterAllowance(M, amt) works when minterManager.isMinter(M)=true" +MintController.sol,incrementMinterAllowance,minterManager.minterAllowance[M] == 0,bt047,"bt047 incrementMinterAllowance(M,amt) works when minterAllowance is 0" +MintController.sol,incrementMinterAllowance,minterManager.minterAllowance[M] == X,bt048,"bt048 incrementMinterAllowance(M, amt) works when minterAllowance > 0" +MintController.sol,incrementMinterAllowance,minterManager.minterAllowance[M] == BIG,bt049,"bt049 incrementMinterAllowance(M,amt) reverts when minterAllowance[M] + amt > 2^256" +MintController.sol,removeMinter,controllers[msg.sender]==0,bt010,bt010 removeMinter reverts when msg.sender is not a controller +MintController.sol,removeMinter,controllers[msg.sender]==M,bt011,bt011 removeMinter sets minters[M] to 0 +MintController.sol,removeMinter,minterManager = 0,bt030,bt030 removeMinter reverts when minterManager is 0 +MintController.sol,removeMinter,minterManager != MinterManagerInterface,bt031,bt031 removeMinter reverts when minterManager is a user account +MintController.sol,removeMinter,minterManager == OK,bt032,bt032 removeMinter works when minterManager is ok +MintController.sol,removeMinter,minterManager.isMinter == false,bt041,bt041 removeMinter(M) works when minterManager.isMinter(M)=false +MintController.sol,removeMinter,minterManager.isMinter == true,bt042,bt042 removeMinter(M) works when minterManager.isMinter(M)=true +MintController.sol,removeMinter,minterManager.minterAllowance[M] == 0,bt053,bt053 removeMinter works when the minterAllowance is 0 +MintController.sol,removeMinter,minterManager.minterAllowance[M] == X,bt054,bt054 removeMinter works when the minterAllowance is not zero +MintController.sol,removeMinter,minterManager.minterAllowance[M] == BIG,bt055,bt055 removeMinter works when the minterAllowance is big +MintController.sol,setMinterManager,msg.sender == owner,bt006,bt006 setMinterManager works when owner is msg.sender +MintController.sol,setMinterManager,msg.sender != owner,bt007,bt007 setMinterManager reverts when owner is not msg.sender +MintController.sol,setMinterManager,minterManager == 0,bt025,bt025 setMinterManager(x) works when existing minterManager = 0 +MintController.sol,setMinterManager,minterManager != 0,bt026,bt026 setMinterManager(x) works when existing minterManager != 0 +MintController.sol,setMinterManager,minterManager == msg.sender,bt027,bt027 setMinterManager(x) works when x = msg.sender +MintController.sol,setMinterManager,minterManager == newMinterManager,bt028,bt028 setMinterManager(x) works when x = minterManager +Ownable.sol,constructor,msg.sender == owner,bt001,bt001 Constructor - owner is msg.sender +Ownable.sol,transferOwnership,msg.sender == owner,bt002,bt002 transferOwnership works when owner is msg.sender +Ownable.sol,transferOwnership,msg.sender != owner,bt003,bt003 transferOwnership reverts when owner is not msg.sender diff --git a/verification/verification_reporter.js b/verification/verification_reporter.js index b38cbe4cb..047f550f8 100644 --- a/verification/verification_reporter.js +++ b/verification/verification_reporter.js @@ -184,18 +184,6 @@ function verification_reporter (runner) { } } - // Print out any tests that are included in UnitTestCompleteness tab but - // missing from the test suite. - // TODO: fix completeness spreadshet - /* if (!_.isEmpty(spreadsheet.completeness)) { - console.log('\n' + red_x + color('bright fail', - ' UnitTestCompleteness tab includes tests that are not present in test suite:') - + '\n' + Object.keys(spreadsheet.completeness).toString()); - } else { - console.log(green_ok + color('bright pass', - ' Test suite suite contains all tests in UnitTestCompleteness tab.')); - } - delete spreadsheet.completeness;*/ // If all the tests in a tab are present, 'cross-off' tab by deleting. for(var testSuite in missingUnitTests) { if (_.isEmpty(missingUnitTests[testSuite])) { @@ -205,7 +193,7 @@ function verification_reporter (runner) { // Do not report missing unit tests for files that did not run for(var testSuite in missingUnitTests){ - if(! _.has(executedTestSuites, testSuite) && ! testSuite.match(/Completeness/)) { + if(! _.has(executedTestSuites, testSuite) /* && ! testSuite.match(/Completeness/)*/) { console.log(color('fail', 'Did not run: ' + testSuite)); delete missingUnitTests[testSuite]; } From fd438956dbc5cebe1329b3dab149cd563711fa93 Mon Sep 17 00:00:00 2001 From: mirathewhite Date: Wed, 10 Oct 2018 12:07:19 -0400 Subject: [PATCH 23/74] add requirement to configureController(c,m) that m is not 0 (#225) --- contracts/minting/Controller.sol | 5 +-- .../Spreadsheets/MINTp0 - ArgumentTests.csv | 40 +++++++++---------- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/contracts/minting/Controller.sol b/contracts/minting/Controller.sol index fec46a8f8..029ec98fd 100644 --- a/contracts/minting/Controller.sol +++ b/contracts/minting/Controller.sol @@ -51,11 +51,10 @@ contract Controller is Ownable { /** * @dev set the controller of a particular _worker - * To disable the controller, call configureController(_controller, address(0)) - * Since a controller manages a single worker, assigning it address(0) is equivalent to - * removing _controller from the list of active controllers. + * Argument _worker must not be 0x00, call removeController(_controller) instead. */ function configureController(address _controller, address _worker) onlyOwner public returns (bool) { + require(_worker != address(0)); controllers[_controller] = _worker; emit ControllerConfigured(_controller, _worker); return true; diff --git a/verification/Spreadsheets/MINTp0 - ArgumentTests.csv b/verification/Spreadsheets/MINTp0 - ArgumentTests.csv index 94454ee90..1b9e0ab28 100644 --- a/verification/Spreadsheets/MINTp0 - ArgumentTests.csv +++ b/verification/Spreadsheets/MINTp0 - ArgumentTests.csv @@ -1,20 +1,20 @@ -File,Function,Arguments,Code,Description -Ownable.sol,transferOwnership,newOwner == msg.sender,arg000,arg000 transferOwnership(msg.sender) works -Ownable.sol,transferOwnership,newOwner == 0,arg001,arg001 transferOwnership(0) works -Ownable.sol,transferOwnership,newOwner == owner,arg002,arg002 transferOwnership(owner) works -Controller.sol,configureController,newController == 0,arg003,"arg003 configureController(0, M) works" -Controller.sol,configureController,newController == msg.sender,arg004,"arg004 configureController(msg.sender, M) works" -Controller.sol,configureController,newController == newMinter,arg005,"arg005 configureController(M, M) works" -Controller.sol,configureController,newMinter == 0,arg006,"arg006 configureController(C, 0) works" -Controller.sol,removeController,newController == 0,arg007,arg007 removeController(0) works -MintController.sol,setMinterManager,newMinterManager = 0,arg008,arg008 setMinterManager(0) works -MintController.sol,setMinterManager,newMinterManager == minterManager,arg009,arg009 setMinterManager(oldMinterManager) works -MintController.sol,setMinterManager,newMinterManager == user,arg010,arg010 setMinterManager(user_account) works -MintController.sol,setMinterManager,newMinterManager == newToken,arg011,arg011 setMinterManager(newToken) works -MintController.sol,configureMinter,newAllowance == 0,arg012,arg012 configureMinter(0) sets allowance to 0 -MintController.sol,configureMinter,newAllowance == oldAllowance,arg013,arg013 configureMinter(oldAllowance) makes no changes -MintController.sol,configureMinter,newAllowance == 2^256-1,arg014,arg014 configureMinter(MAX) works -MintController.sol,incrementMinterAllowance,increment ==0,arg015,arg015 incrementMinterAllowance(0) makes no changes to allowance -MintController.sol,incrementMinterAllowance,increment == oldAllowance,arg016,arg016 incrementMinterAllowance(oldAllowance) doubles the allowance -MintController.sol,incrementMinterAllowance,increment == 2^256-1,arg017,arg017 incrementMinterAllowance(MAX) throws -MintController.sol,incrementMinterAllowance,increment + oldAllowance == 2^256 -1,arg018,arg018 incrementMinterAlllowance(BIG) throws \ No newline at end of file +File,Function,Arguments,Code,Description +Ownable.sol,transferOwnership,newOwner == msg.sender,arg000,arg000 transferOwnership(msg.sender) works +Ownable.sol,transferOwnership,newOwner == 0,arg001,arg001 transferOwnership(0) works +Ownable.sol,transferOwnership,newOwner == owner,arg002,arg002 transferOwnership(owner) works +Controller.sol,configureController,newController == 0,arg003,"arg003 configureController(0, M) works" +Controller.sol,configureController,newController == msg.sender,arg004,"arg004 configureController(msg.sender, M) works" +Controller.sol,configureController,newController == newMinter,arg005,"arg005 configureController(M, M) works" +Controller.sol,configureController,newMinter == 0,arg006,"arg006 configureController(C, 0) throws" +Controller.sol,removeController,newController == 0,arg007,arg007 removeController(0) works +MintController.sol,setMinterManager,newMinterManager = 0,arg008,arg008 setMinterManager(0) works +MintController.sol,setMinterManager,newMinterManager == minterManager,arg009,arg009 setMinterManager(oldMinterManager) works +MintController.sol,setMinterManager,newMinterManager == user,arg010,arg010 setMinterManager(user_account) works +MintController.sol,setMinterManager,newMinterManager == newToken,arg011,arg011 setMinterManager(newToken) works +MintController.sol,configureMinter,newAllowance == 0,arg012,arg012 configureMinter(0) sets allowance to 0 +MintController.sol,configureMinter,newAllowance == oldAllowance,arg013,arg013 configureMinter(oldAllowance) makes no changes +MintController.sol,configureMinter,newAllowance == 2^256-1,arg014,arg014 configureMinter(MAX) works +MintController.sol,incrementMinterAllowance,increment ==0,arg015,arg015 incrementMinterAllowance(0) makes no changes to allowance +MintController.sol,incrementMinterAllowance,increment == oldAllowance,arg016,arg016 incrementMinterAllowance(oldAllowance) doubles the allowance +MintController.sol,incrementMinterAllowance,increment == 2^256-1,arg017,arg017 incrementMinterAllowance(MAX) throws +MintController.sol,incrementMinterAllowance,increment + oldAllowance == 2^256 -1,arg018,arg018 incrementMinterAlllowance(BIG) throws From 4b9ebf3941a48e41e7363fee729035610a71ca66 Mon Sep 17 00:00:00 2001 From: mirathewhite Date: Thu, 11 Oct 2018 09:47:09 -0400 Subject: [PATCH 24/74] Fixed bug in MasterMinter.sol constructor and added MasterMinter unit tests --- contracts/minting/MasterMinter.sol | 3 +++ test/minting/MintControllerUtils.js | 6 ++---- test/minting/MintP0BasicTests.js | 20 +++++++++++++------- test/minting/MintP0_ABITests.js | 19 +++++++++++++------ 4 files changed, 31 insertions(+), 17 deletions(-) diff --git a/contracts/minting/MasterMinter.sol b/contracts/minting/MasterMinter.sol index 20809b6b9..56c009f0d 100644 --- a/contracts/minting/MasterMinter.sol +++ b/contracts/minting/MasterMinter.sol @@ -25,4 +25,7 @@ import './MintController.sol'; contract MasterMinter is MintController { + constructor(address _minterManager) MintController(_minterManager) public { + + } } \ No newline at end of file diff --git a/test/minting/MintControllerUtils.js b/test/minting/MintControllerUtils.js index eca81121e..d67e0e847 100644 --- a/test/minting/MintControllerUtils.js +++ b/test/minting/MintControllerUtils.js @@ -19,8 +19,6 @@ function MintControllerState(owner, controllers, minterManager) { this.controllers = controllers; this.minterManager = minterManager; this.checkState = async function(mintController) {await checkMintControllerState(mintController, this)}; -// this.clone = function(){return clone(this);}; -// this.clone = function(){return new MintControllerState(this.owner, clone(this.controllers), this.minterManager)}; } // Default state of MintController when it is deployed @@ -42,9 +40,9 @@ async function getActualMintControllerState(mintController, accounts) { // Deploys a FiatTokenV1 with a MintController contract as the masterMinter. // Uses the same workflow we would do in production - first deploy FiatToken then set the masterMinter. -async function initializeTokenWithProxyAndMintController(rawToken) { +async function initializeTokenWithProxyAndMintController(rawToken, MintControllerArtifact) { var tokenConfig = await initializeTokenWithProxy(rawToken); - var mintController = await MintController.new(tokenConfig.token.address, {from:Accounts.mintOwnerAccount}); + var mintController = await MintControllerArtifact.new(tokenConfig.token.address, {from:Accounts.mintOwnerAccount}); await tokenConfig.token.updateMasterMinter(mintController.address, {from:Accounts.tokenOwnerAccount}); var tokenConfigWithMinter = { proxy: tokenConfig.proxy, diff --git a/test/minting/MintP0BasicTests.js b/test/minting/MintP0BasicTests.js index 9c761b7eb..09f2456cb 100644 --- a/test/minting/MintP0BasicTests.js +++ b/test/minting/MintP0BasicTests.js @@ -1,4 +1,5 @@ var MintController = artifacts.require('minting/MintController'); +var MasterMinter = artifacts.require('minting/MasterMinter'); var FiatToken = artifacts.require('FiatTokenV1'); var BigNumber = require('bignumber.js'); @@ -21,11 +22,19 @@ var checkMintControllerState = mintUtils.checkMintControllerState; var zeroAddress = "0x0000000000000000000000000000000000000000"; -async function run_tests(newToken, accounts) { +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); + tokenConfig = await initializeTokenWithProxyAndMintController(rawToken, MintControllerArtifact); token = tokenConfig.token; mintController = tokenConfig.mintController; expectedMintControllerState = clone(tokenConfig.customState); @@ -626,8 +635,5 @@ async function run_tests(newToken, accounts) { } var testWrapper = require('./../TestWrapper'); -testWrapper.execute('MINTp0_BasicTests', run_tests); - -module.exports = { - run_tests: run_tests, -} +testWrapper.execute('MINTp0_BasicTests MintController', run_tests_MintController); +testWrapper.execute('MINTp0_BasicTests MasterMinter', run_tests_MasterMinter); \ No newline at end of file diff --git a/test/minting/MintP0_ABITests.js b/test/minting/MintP0_ABITests.js index d8344eb39..adb627460 100644 --- a/test/minting/MintP0_ABITests.js +++ b/test/minting/MintP0_ABITests.js @@ -1,4 +1,5 @@ var MintController = artifacts.require('minting/MintController'); +var MasterMinter = artifacts.require('minting/MasterMinter'); var FiatToken = artifacts.require('FiatTokenV1'); var BigNumber = require('bignumber.js'); @@ -28,11 +29,19 @@ var sendRawTransaction = abiUtils.sendRawTransaction; var msgData = abiUtils.msgData; var msgData1 = abiUtils.msgData1; -async function run_tests(newToken, accounts) { +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); + tokenConfig = await initializeTokenWithProxyAndMintController(rawToken, MintControllerArtifact); token = tokenConfig.token; mintController = tokenConfig.mintController; expectedMintControllerState = clone(tokenConfig.customState); @@ -63,8 +72,6 @@ async function run_tests(newToken, accounts) { } var testWrapper = require('./../TestWrapper'); -testWrapper.execute('MINTp0_ABITests', run_tests); +testWrapper.execute('MINTp0_ABITests MintController', run_tests_MintController); +testWrapper.execute('MINTp0_ABITests MasterMinter', run_tests_MasterMinter); -module.exports = { - run_tests: run_tests, -} From 40fdc07001d99558e37ad354100710b1eb000f34 Mon Sep 17 00:00:00 2001 From: mirathewhite Date: Thu, 11 Oct 2018 11:45:31 -0400 Subject: [PATCH 25/74] beforeEach sends MintController as argument to initialization function --- test/minting/MintControllerTests.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/minting/MintControllerTests.js b/test/minting/MintControllerTests.js index d7b278c4e..d1adc8946 100644 --- a/test/minting/MintControllerTests.js +++ b/test/minting/MintControllerTests.js @@ -19,7 +19,7 @@ async function run_tests(newToken, accounts) { beforeEach('Make fresh token contract', async function () { rawToken = await newToken(); - tokenConfig = await initializeTokenWithProxyAndMintController(rawToken); + tokenConfig = await initializeTokenWithProxyAndMintController(rawToken, MintController); token = tokenConfig.token; mintController = tokenConfig.mintController; expectedMintControllerState = clone(tokenConfig.customState); From 0f4aa09ef2427ea69be76e1c635ea9374a432732 Mon Sep 17 00:00:00 2001 From: mirathewhite Date: Wed, 17 Oct 2018 12:51:28 -0400 Subject: [PATCH 26/74] README file for MasterMinter --- doc/masterminter.md | 101 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 doc/masterminter.md diff --git a/doc/masterminter.md b/doc/masterminter.md new file mode 100644 index 000000000..6bc41561b --- /dev/null +++ b/doc/masterminter.md @@ -0,0 +1,101 @@ +# MasterMinter contract +The MasterMinter is a governance contract. It delegates the functionality +of the `masterMinter` role in the Centre USDC contract to multiple addresses. +(The `masterMinter` role can add and remove minters from a FiatToken and set their +allowances.) The MasterMinter contract delegates the minter management capability to +`controllers`. Each `controller` manages exactly one `minter`, and a single `minter` +may be managed by multiple `controllers`. This allows separation of duties +(off-line key management) and simplifies nonce management for warm transactions. + +Minters and FiatToken holders are not affected by replacing a `masterMinter` user address with +a `MasterMinter` contract. + +# Roles +The `MasterMinter` contract has the following roles: + +- `owner` - adds and removes controllers, sets the address of the `minterManager`, + and sets the owner. +- `minterManager` - address of a contract (e.g. USDC) with a `MinterManagementInterface`. + The `minterManager` contract stores information about minter allowances and which + minters are enabled/disabled. +- `controller` - each controller manages exactly one minter. A controller + can enable/disable its minter, and modify the minting allowance by calling functions on + the `MasterMinter` contract, and `MasterMinter` will call the appropriate functions on + the `minterManager`. +- `minter` - each `minter` is managed by one or more `controller`. The `minter` cannot + perform any actions on the MasterMinter contract. It interacts only with + the FiatToken contract. + +# Interaction with FiatToken contract +The `owner` of the FiatToken contract can set the `masterMinter` role to point +to the address of the `MasterMinter` contract. This enables the `MasterMinter` +contract to call minter management functions on the FiatToken contract: + +- `configureMinter(minter, allowance)` - Enables the `minter` and sets its minting allowance. +- `removeMinter(minter)` - Disables the `minter` and sets its mintingallowance to 0. +- `isMinter(minter)` - Returns `true` if the `minter` is enabled, and `false` otherwise. +- `minterAllowance(minter)` - Returns the minting allowance of the `minter`. + +Together, these four functions are defined as the `MinterManagementInterface`. The +`MasterMinter` contains the address of a `minterManager` that implements the `MinterManagementInterface`. +The `MasterMinter` interacts with the USDC token via the `minterManager`. + +When a `controller` calls a function on `MasterMinter`, the `MasterMinter` will call +the appropriate function on the `FiatToken` contract on its behalf. Both the `MasterMinter` +and the `FiatToken` do their own access control. + +# Function Summary + +- `configureController(controller, minter)` - The owner assigns the controller to manage the minter. This allows + the `controller` to call `configureMinter`, `incrementMinterAllowance` and `removeMinter`. Note: + `configureController(controller, 0x00)` is forbidden because it has the effect of removing the controller. +- `removeController(controller)` - The owner disables the controller by setting its `minter` to `0x00`. +- `setMinterManager(minterManager)` - The owner sets a new contract to the `minterManager` address. This has + no effect on the old `minterManager` contract. If the new `minterManager` does not implement the + `MinterManagementInterface` or does not give this instance of the `MasterMinter` contract permission to + call minter management functions then the `controller` calls to `configureMinter`, + `incrementMinterAllowance`, and `removeMinter` will throw. +- `configureMinter(allowance)` - A controller enables its minter and sets its allowance. The `MasterMinter` + contract will call the `minterManager` contract on the `controller`'s behalf. +- `incrementMinterAllowance` - A controller increments the allowance of an enabled minter + (`incrementMinterAllowance` will throw if the `minter` is disabled). The `MasterMinter` + contract will call the `minterManager` contract on the `controller`'s behalf. +- `removeMinter` - A controller disables a `minter`. The `MasterMinter` + contract will call the `minterManager` contract on the `controller`'s behalf. + +# Deployment +The `MasterMinter` may be deployed independently of the `FiatToken` contract (e.g. USDC). + +- FiatToken then MasterMinter. Deploy `MasterMinter` and set the `minterManager` + to point to the `FiatToken` in the constructor. Then use the `MasterMinter` `owner` role to + configure at least one `controller` for each existing `minter` in the `FiatToken`. Once the + `MasterMinter` is fully configured, use the `FiatToken` `owner` role to broadcast + an `updateMasterMinter` transaction setting `masterMinter` role to the `MasterMinter` contract + address. +- MasterMinter then FiatToken. Deploy `MasterMinter` and set the `minterManager` + to point to address `0x00` in the constructor. Then deploy the `FiatToken` and set + the `masterMinter` to be the address of the `MasterMinter` contract in the constructor. + Next, use the `MasterMinter` `owner` to set the `minterManager` and configure `controllers`. + + +# Configuring the MasterMinter +We recommend assigning at least two `controllers` to each `minter`. + +- AllowanceController. Use this `controller` to enable the `minter` with a single + `configureMinter` transaction, and then use it exclusively to sign `incrementMinterAllowance` transactions. + There may be multiple `AllowanceControllers` that sign different size allowance increment transactions. +- SecurityController. Use this `controller` to sign a single `removeMinter` transaction and store + it for emergencies. + +The private keys to the `AllowanceController` and `SecurityController` should stay in cold storage. +This configuration lets the Controller keep multiple warm `incrementMinterAllowance` transactions on hand, +as well as the `removeMinter` transaction in case of a problem. Broadcasting the `removeMinter` transaction +will cause all future `incrementMinterAllowance` transactions to `throw`. Since there two types +of transactions are managed by different addresses, there is no need to worry about nonce management. + + +# MasterMinter vs. MintController +Creating a `MasterMinter` contract that *inherits* from a `MintController` contract with no +changes may seem like a curious design choice. This leaves open the possibility of creating other +contracts that inherit from `MintController` without creating naming confusion due to their different +functionality. \ No newline at end of file From 922b8debdee7a67324a09f2c77f0f1367f956410 Mon Sep 17 00:00:00 2001 From: Erik Tierney Date: Thu, 18 Oct 2018 13:24:15 -0400 Subject: [PATCH 27/74] Merge master into multi-issuer to pick up CI changes. (#231) * Fix typo in readme * remove encoder and decoder tools * Update readme add link to centre.io * housekeeping * cleanup * readme cleanup remove out of date comments about openzeppelin - now installed via yarn * add cloudformation template for codebuild project (#222) * add cloudformation template for codebuild project * fix linter warnings * adjust policy name, linter fix * Initial .travis.yml file --- .travis.yml | 16 ++++ README.md | 14 +--- ci/{codebuild.yml => codebuild.yaml} | 11 +-- package.json | 3 +- scripts/decodeTxData.js | 113 --------------------------- scripts/encodeTxData.js | 50 ------------ scripts/tests/dataEncodingTests.js | 84 -------------------- yarn.lock | 87 +-------------------- 8 files changed, 25 insertions(+), 353 deletions(-) create mode 100644 .travis.yml rename ci/{codebuild.yml => codebuild.yaml} (89%) delete mode 100644 scripts/decodeTxData.js delete mode 100644 scripts/encodeTxData.js delete mode 100644 scripts/tests/dataEncodingTests.js diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 000000000..85696c4fa --- /dev/null +++ b/.travis.yml @@ -0,0 +1,16 @@ +language: node_js +node_js: + - 8 + +before_install: + - curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version 1.9.2 + - export PATH="$HOME/.yarn/bin:$PATH" + + +install: + - npm install -g truffle@4.1.13 + - yarn install --frozen-lockfile + +script: + - yarn check --integrity && truffle compile && npm test + diff --git a/README.md b/README.md index d8bcf0db1..cf1fdf91e 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # centre-tokens -Fiat tokens on the CENTRE network. +Fiat tokens on the [CENTRE](https://centre.io) network. # Setup Tests need node v8.0.0 or higher, as they depend on async/await functionality. Interacting with eth is very async-y so await makes it much easier to write tests. @@ -27,7 +27,7 @@ to generate test coverage on all tests run: # Contracts The implementation uses 2 separate contracts - a proxy contract (`FiatTokenProxy.sol`)and an implementation contract(`FiatToken.sol`). -This allows upgrading the contract, as a new implentation contact can be deployed and the Proxy updated to point to it. +This allows upgrading the contract, as a new implementation contact can be deployed and the Proxy updated to point to it. ## FiatToken The FiatToken offers a number of capabilities, which briefly are described below. There are more [detailed design docs](./doc/tokendesign.md) in the `doc` folder. @@ -57,13 +57,3 @@ need the allowance increased again by the `masterMinter`. The contract has an Owner, who can change the `owner`, `pauser`, `blacklister`, or `masterMinter` addresses. The `owner` can not change the `proxyOwner` address. -# OpenZeppelin -Contracts from OpenZeppelin version 1.10 are used where possible, with some modifications. These contracts are located -in `contracts/thirdparty/openzepplin`. `Ownable` and `Pausable` have been modified. The other contacts are unmodified. - -## `Ownable` has been modified to: -1. Remove the renounceOwnership function and OwnershipdRenounced event. -## `Pausable` has been modified to: -1. Add the pauser role, which controlls `pause`/`unpause` -2. Remove `whenPaused`/`whenNotPaused` modifiers on `unpause`/`pause` methods -3. Remove `whenPaused` as is is no longer used diff --git a/ci/codebuild.yml b/ci/codebuild.yaml similarity index 89% rename from ci/codebuild.yml rename to ci/codebuild.yaml index e4b175990..43a75d77d 100644 --- a/ci/codebuild.yml +++ b/ci/codebuild.yaml @@ -40,7 +40,7 @@ Resources: Location: !Ref CodeBuildBucket Name: artifacts NamespaceType: BUILD_ID - BadgeEnabled: True + BadgeEnabled: true Environment: Type: LINUX_CONTAINER ComputeType: BUILD_GENERAL1_SMALL @@ -79,7 +79,7 @@ Resources: Action: "sts:AssumeRole" Path: "/" Policies: - - PolicyName: !Ref AWS::StackName + - PolicyName: "CodeBuildAccess" PolicyDocument: Version: "2012-10-17" Statement: @@ -98,12 +98,9 @@ Resources: Resource: !Sub "arn:aws:s3:::${AWS::StackName}-${AWS::AccountId}-${AWS::Region}*" - Sid: "AllowPublishToSNS" Effect: "Allow" - Action: "SNS:Publish" + Action: + - "SNS:Publish" Resource: !Ref FailedBuildTopic FailedBuildTopic: Type: AWS::SNS::Topic - Properties: - Subscription: - - { "Endpoint": "o6j1v0d5h5d8h5h7@circlefin.slack.com", "Protocol": "email" } # Slack notification - - { "Endpoint": "ohudson@circle.com", "Protocol": "email" } # Oliver's email \ No newline at end of file diff --git a/package.json b/package.json index 33ac07789..c4674aa05 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "scripts": { "dev": "lite-server", "truffle-test": "scripts/start-ganache.sh && truffle test", - "test": "scripts/start-ganache.sh && truffle test scripts/tests/dataEncodingTests.js && ./node_modules/.bin/solidity-coverage" + "test": "scripts/start-ganache.sh && ./node_modules/.bin/solidity-coverage" }, "repository": { "type": "git", @@ -28,7 +28,6 @@ "bignumber.js": "6.0.0", "clone": "2.1.2", "csv-parse": "3.0.0", - "ethereum-input-data-decoder": "0.0.12", "ethereumjs-abi": "^0.6.5", "ethereumjs-tx": "1.3.1", "g": "^2.0.1", diff --git a/scripts/decodeTxData.js b/scripts/decodeTxData.js deleted file mode 100644 index a827fa2c8..000000000 --- a/scripts/decodeTxData.js +++ /dev/null @@ -1,113 +0,0 @@ -const InputDataDecoder = require('ethereum-input-data-decoder') -var fs = require('fs') -var mkdirp = require('mkdirp') -var args = process.argv; - -var helpText = `Decodes "data" field of ethereum transactions -args: -"--truffle-artifact" or "--abi-path": - "--truffle-artifact": name of truffle-artifact (contract name) - "--abi-path": /path/to/abi.json (contents of file should be one abi array) -"--data": hex used as input data to ethereum transaction. Encodes function name, parameter types, and parameter values -"--filename": (optional) file name used for decoded output. File is saved to ./decoded_data/.json. If no filename is provided, output is logged to stdout. - -example using truffle with --truffle-artifact: -- in process 1, run ganache: $ ganache-cli -- in process 2, compile contracts to /build/contracts/ folder: $ truffle compile -- in process 2, run decoder: $ truffle exec decodeTxData.js --truffle-artifact FiatTokenV1 --data 0x4e44d9560000000000000000000000009c08210cc65b5c9f1961cdbd9ea9bf017522464d000000000000000000000000000000000000000000000000000000003b9aca00$ --filename configureMinter -Output: new file is created at decoded_data/configureMinter.json: -{ - "name":"configureMinter", - "types":[ - "address", - "uint256" - ], - "inputs":[ - "9c08210cc65b5c9f1961cdbd9ea9bf017522464d", - "1000000000" - ] -} - -example using just node with --abi-path: -- (ensure that correct abi is located at --abi-path) -- run decoder: $ node decodeTxData.js --abi-path ./tests/FiatTokenProxy_abi.json --data 4f1ef286000000000000000000000000023fe1585d8361f0584aaa78c152f94cdcff7b3000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000064d76c43c60000000000000000000000000000000000000000000000000000000000000001000000000000000000000000aca94ef8bd5ffee41947b4585a84bda5a3d3da6e000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000 --filename upgradeToAndCall -Output: new file is created at decoded_data/upgradeToAndCall.json: -{ - "name":"upgradeToAndCall", - "types":[ - "address", - "bytes" - ], - "inputs":[ - "023fe1585d8361f0584aaa78c152f94cdcff7b30", - "d76c43c60000000000000000000000000000000000000000000000000000000000000001000000000000000000000000aca94ef8bd5ffee41947b4585a84bda5a3d3da6e000000000000000000000000000000000000000000000000000000000000000c" - ] -} -` - -function toHexString(byteArray) { - return Array.from(byteArray, function(byte) { - return ('0' + (byte & 0xFF).toString(16)).slice(-2); - }).join('') -} - -function decode() { - var helpFlagIndex = args.indexOf("--help"); - if (helpFlagIndex != -1) { - console.log(helpText) - return - } - - var dataFlagIndex = args.indexOf("--data"); - var data = args[dataFlagIndex + 1] - var truffleArtifactFlagIndex = args.indexOf("--truffle-artifact") - var abiPathFlagIndex = args.indexOf("--abi-path") - var outputFileNameFlagIndex = args.indexOf("--filename") - - var abi; - - if (abiPathFlagIndex != -1) { - var abiPathIndex = args[abiPathFlagIndex + 1] - var abiStr = fs.readFileSync(abiPathIndex, "utf8") - abi = JSON.parse(abiStr) - } else { - if (truffleArtifactFlagIndex != -1) { - var truffleArtifactName = args[truffleArtifactFlagIndex + 1] - var truffleArtifact = artifacts.require(truffleArtifactName) - abi = truffleArtifact.abi - } else { - throw new Error(`ABI is missing. Pass in the ABI with one of the following flags: - --abi-path /path/to/abi.json - --truffle-artifact nameOfContract - print full instructions with: --help - `) - } - } - - var decoder = new InputDataDecoder(abi) - result = decoder.decodeData(data) - for (i = 0; i < result.inputs.length; i++) { - // if the the type is object and corresponding type in type array is uint, try to parse it - if ((typeof result.inputs[i] == "object") && result.types[i].includes("uint")) { - result.inputs[i] = result.inputs[i].toString() - } - if (result.types[i] == "bytes") { - result.inputs[i] = toHexString(result.inputs[i]) - } - } - var decodedDataJson = JSON.stringify(result) - - if (outputFileNameFlagIndex != -1) { - outputFileName = args[outputFileNameFlagIndex + 1] - mkdirp.sync('decoded_data') - fs.writeFileSync('decoded_data/' + outputFileName + '.json', decodedDataJson, 'utf8'); - } else { - console.log(decodedDataJson) - } -} - -decode() - -module.exports = async function(callback) { - callback() -} \ No newline at end of file diff --git a/scripts/encodeTxData.js b/scripts/encodeTxData.js deleted file mode 100644 index 7cfd9ac99..000000000 --- a/scripts/encodeTxData.js +++ /dev/null @@ -1,50 +0,0 @@ -// Description: -// Returns "data" parameter for Ethereum transaction of an upgraded token -// Note: Addresses must start with 0x - -// Args: -// arg0: truffle -// arg1: exec -// arg2: --compile -// arg3: encodeTxData.js -// arg4: name of contract (e.g. FiatTokenV2NewFieldsTest). Do not pass the source file name. -// arg5: function name (e.g. initV2) -// arg6+: solidity argument values - -// Example usage: -// make sure Ganache is running (`ganache-cli --defaultBalanceEther 1000000 --deterministic --a 15`) -// run `truffle compile` to generate build artifacts, or pass `-c` or `--compile` after exec, as in the following example: -// `truffle exec --compile encodeTxData.js FiatTokenV2NewFieldsTest initV2 true 0xaca94ef8bd5ffee41947b4585a84bda5a3d3da6e 12` -// returns -// 0xd76c43c60000000000000000000000000000000000000000000000000000000000000001000000000000000000000000aca94ef8bd5ffee41947b4585a84bda5a3d3da6e000000000000000000000000000000000000000000000000000000000000000c - -var args = process.argv; -// slice off the paths to node and truffle executables, which are included automatically -args = args.slice(2) -// slice off everything from truffle through name of this file -if (args[1] == "--compile" || args[1] == "-c") { - args = args.slice(3) -} else { - args = args.slice(2) -} - -var contractName = args[0] -// slice off name of contract -args = args.slice(1); - -var ContractArtifact = artifacts.require(contractName) - -async function run() { - // TODO support contracts with more than zero constructor parameters - var contract = await ContractArtifact.new(); - var func = args[0] - // slice off name of function, leaving only solidity parameter values - args = args.slice(1) - var data = contract[func].request.apply(null, args)["params"][0]["data"] - console.log(data) -} - -module.exports = async function(callback) { - await run(); - callback(); -} \ No newline at end of file diff --git a/scripts/tests/dataEncodingTests.js b/scripts/tests/dataEncodingTests.js deleted file mode 100644 index 9ab767928..000000000 --- a/scripts/tests/dataEncodingTests.js +++ /dev/null @@ -1,84 +0,0 @@ -const assert = require('assert'); -const util = require('util'); -const exec = util.promisify(require('child_process').exec); -var fs = require('fs') - -describe('transaction data encoding and decoding tests', function() { - // disable timeouts - this.timeout(0); - - var initV2Data = "d76c43c60000000000000000000000000000000000000000000000000000000000000001000000000000000000000000aca94ef8bd5ffee41947b4585a84bda5a3d3da6e000000000000000000000000000000000000000000000000000000000000000c"; - var upgradeToAndCallData = "4f1ef286000000000000000000000000023fe1585d8361f0584aaa78c152f94cdcff7b3000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000064d76c43c60000000000000000000000000000000000000000000000000000000000000001000000000000000000000000aca94ef8bd5ffee41947b4585a84bda5a3d3da6e000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000" - var configureMinterData = "4e44d9560000000000000000000000009c08210cc65b5c9f1961cdbd9ea9bf017522464d000000000000000000000000000000000000000000000000000000003b9aca00" - - it('td001 should return correct data using encodeTxData with --compile flag', async function () { - const { stdout, stderr } = await exec('truffle exec --compile ./scripts/encodeTxData.js FiatTokenV2NewFieldsTest initV2 true 0xaca94ef8bd5ffee41947b4585a84bda5a3d3da6e 12'); - assert(stdout.includes(initV2Data)) - }) - - it('td002 should return correct data using encodeTxData with -c flag', async function () { - const { stdout, stderr } = await exec('truffle exec -c ./scripts/encodeTxData.js FiatTokenV2NewFieldsTest initV2 true 0xaca94ef8bd5ffee41947b4585a84bda5a3d3da6e 12'); - assert(stdout.includes(initV2Data)) - }) - - it('td003 should return correct data using encodeTxData without using compile flag', async function () { - const { stdout, stderr } = await exec('truffle exec ./scripts/encodeTxData.js FiatTokenV2NewFieldsTest initV2 true 0xaca94ef8bd5ffee41947b4585a84bda5a3d3da6e 12'); - assert(stdout.includes(initV2Data)) - }) - - it('td004 should return correct data for FiatTokenV1 method configureMinter', async function () { - const { stdout, stderr } = await exec('truffle exec ./scripts/encodeTxData.js FiatTokenV1 configureMinter 0x9c08210cc65b5c9f1961cdbd9ea9bf017522464d 1000000000'); - assert(stdout.includes(configureMinterData)) - }) - - it("td005 should decode a data string and output decoded result to stdout stream", async function () { - const { stdout, stderr } = await exec("truffle exec ./scripts/decodeTxData.js --truffle-artifact FiatTokenV1 --data " + configureMinterData); - - // trim extra output from truffle - var bracketIndex = stdout.indexOf("{") - var stdoutJson = stdout.substring(bracketIndex) - var decodedData = JSON.parse(stdoutJson); - assert.equal(decodedData.name, "configureMinter") - assert.equal(decodedData.types[0], "address") - assert.equal(decodedData.types[1], "uint256") - assert.equal(decodedData.inputs[0], "9c08210cc65b5c9f1961cdbd9ea9bf017522464d") - assert.equal(decodedData.inputs[1], "1000000000") - }) - - it('td006 should decode a data string and output decoded result to a file', async function () { - await exec("truffle exec ./scripts/decodeTxData.js --truffle-artifact FiatTokenV1 --data " + configureMinterData + " --filename configureMinterTest"); - var decodedDataJson = fs.readFileSync('./scripts/decoded_data/configureMinterTest.json'); - var decodedData = JSON.parse(decodedDataJson); - assert.equal(decodedData.name, "configureMinter") - assert.equal(decodedData.types[0], "address") - assert.equal(decodedData.types[1], "uint256") - assert.equal(decodedData.inputs[0], "9c08210cc65b5c9f1961cdbd9ea9bf017522464d") - assert.equal(decodedData.inputs[1], "1000000000") - }) - - it('td007 should decode a data string for FiatTokenProxy and its byte array input to a hex string', async function () { - await exec ("truffle exec scripts/decodeTxData.js --truffle-artifact FiatTokenProxy --data " + upgradeToAndCallData + " --filename upgradeToAndCallTruffleTest") - var decodedDataJson = fs.readFileSync('./scripts/decoded_data/upgradeToAndCallTruffleTest.json'); - var decodedData = JSON.parse(decodedDataJson); - assert.equal(decodedData.name, "upgradeToAndCall") - assert.equal(decodedData.types[0], "address") - assert.equal(decodedData.types[1], "bytes") - assert.equal(decodedData.inputs[0], "023fe1585d8361f0584aaa78c152f94cdcff7b30") - assert.equal(decodedData.inputs[1], initV2Data) - }) - - it('td008 should decode a data string using --abi-path', async function () { - fiatTokenProxyCompiled = fs.readFileSync("./build/contracts/FiatTokenProxy.json", "utf8"); - fiatTokenProxyJson = JSON.parse(fiatTokenProxyCompiled) - fs.writeFileSync("./scripts/tests/FiatTokenProxy_abi.json", JSON.stringify(fiatTokenProxyJson.abi), 'utf8') - - await exec ("cd scripts && node ./decodeTxData.js --abi-path ./tests/FiatTokenProxy_abi.json --data " + upgradeToAndCallData + " --filename upgradeToAndCallNodeTest") - var decodedDataJson = fs.readFileSync('./scripts/decoded_data/upgradeToAndCallNodeTest.json'); - var decodedData = JSON.parse(decodedDataJson); - assert.equal(decodedData.name, "upgradeToAndCall") - assert.equal(decodedData.types[0], "address") - assert.equal(decodedData.types[1], "bytes") - assert.equal(decodedData.inputs[0], "023fe1585d8361f0584aaa78c152f94cdcff7b30") - assert.equal(decodedData.inputs[1], initV2Data) - }) -}) \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 4d9c8440b..e8835105d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -57,10 +57,6 @@ accepts@~1.3.4: mime-types "~2.1.18" negotiator "0.6.1" -aes-js@3.0.0: - version "3.0.0" - resolved "https://registry.yarnpkg.com/aes-js/-/aes-js-3.0.0.tgz#e21df10ad6c2053295bcbb8dab40b09dbea87e4d" - aes-js@^0.2.3: version "0.2.4" resolved "https://registry.yarnpkg.com/aes-js/-/aes-js-0.2.4.tgz#94b881ab717286d015fa219e08fb66709dda5a3d" @@ -2177,15 +2173,6 @@ elegant-spinner@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/elegant-spinner/-/elegant-spinner-1.0.1.tgz#db043521c95d7e303fd8f345bedc3349cfb0729e" -elliptic@6.3.3: - version "6.3.3" - resolved "https://registry.yarnpkg.com/elliptic/-/elliptic-6.3.3.tgz#5482d9646d54bcb89fd7d994fc9e2e9568876e3f" - dependencies: - bn.js "^4.4.0" - brorand "^1.0.1" - hash.js "^1.0.0" - inherits "^2.0.1" - elliptic@^6.2.3: version "6.4.0" resolved "https://registry.yarnpkg.com/elliptic/-/elliptic-6.4.0.tgz#cac9af8762c85836187003c8dfe193e5e2eae5df" @@ -2470,14 +2457,7 @@ ethereum-common@^0.0.18: version "0.0.18" resolved "https://registry.yarnpkg.com/ethereum-common/-/ethereum-common-0.0.18.tgz#2fdc3576f232903358976eb39da783213ff9523f" -ethereum-input-data-decoder@0.0.12: - version "0.0.12" - resolved "https://registry.yarnpkg.com/ethereum-input-data-decoder/-/ethereum-input-data-decoder-0.0.12.tgz#e7abd764e76ba6942028051717759234cf64ba6d" - dependencies: - ethereumjs-abi "^0.6.4" - ethers "^2.1.3" - -ethereumjs-abi@^0.6.4, ethereumjs-abi@^0.6.5: +ethereumjs-abi@^0.6.5: version "0.6.5" resolved "https://registry.yarnpkg.com/ethereumjs-abi/-/ethereumjs-abi-0.6.5.tgz#5a637ef16ab43473fa72a29ad90871405b3f5241" dependencies: @@ -2600,49 +2580,6 @@ ethereumjs-wallet@0.6.0: utf8 "^2.1.1" uuid "^2.0.1" -ethers-contracts@2.2.1: - version "2.2.1" - resolved "https://registry.yarnpkg.com/ethers-contracts/-/ethers-contracts-2.2.1.tgz#e2bf5dd5e157313ba454b50c646c8472fcd0a8b3" - dependencies: - ethers-utils "^2.1.0" - -ethers-providers@2.1.19: - version "2.1.19" - resolved "https://registry.yarnpkg.com/ethers-providers/-/ethers-providers-2.1.19.tgz#d597e298f70cfbf8da207c303af0a5cbed5b4cd2" - dependencies: - ethers-utils "^2.1.0" - inherits "2.0.1" - xmlhttprequest "1.8.0" - -ethers-utils@2.1.11, ethers-utils@^2.1.0: - version "2.1.11" - resolved "https://registry.yarnpkg.com/ethers-utils/-/ethers-utils-2.1.11.tgz#b27535ca3226118be300211c39c896b1e5e21641" - dependencies: - bn.js "^4.4.0" - hash.js "^1.0.0" - js-sha3 "0.5.7" - xmlhttprequest "1.8.0" - -ethers-wallet@2.1.8: - version "2.1.8" - resolved "https://registry.yarnpkg.com/ethers-wallet/-/ethers-wallet-2.1.8.tgz#2819a51d439525ddedeec84992b0b83f59da3cef" - dependencies: - aes-js "3.0.0" - elliptic "6.3.3" - ethers-utils "^2.1.0" - scrypt-js "2.0.3" - setimmediate "1.0.4" - uuid "2.0.1" - -ethers@^2.1.3: - version "2.2.6" - resolved "https://registry.yarnpkg.com/ethers/-/ethers-2.2.6.tgz#d1081c3e132930686fa7a3b508ae4d0ef8bd986a" - dependencies: - ethers-contracts "2.2.1" - ethers-providers "2.1.19" - ethers-utils "2.1.11" - ethers-wallet "2.1.8" - ethjs-abi@0.1.8: version "0.1.8" resolved "https://registry.yarnpkg.com/ethjs-abi/-/ethjs-abi-0.1.8.tgz#cd288583ed628cdfadaf8adefa3ba1dbcbca6c18" @@ -3652,10 +3589,6 @@ inherits@2, inherits@2.0.3, inherits@^2.0.1, inherits@^2.0.3, inherits@~2.0.0, i version "2.0.3" resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de" -inherits@2.0.1: - version "2.0.1" - resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.1.tgz#b17d08d326b4423e568eff719f91b0b1cbdf69f1" - ini@^1.3.4, ini@^1.3.5, ini@~1.3.0: version "1.3.5" resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.5.tgz#eee25f56db1c9ec6085e0c22778083f596abf927" @@ -4061,10 +3994,6 @@ js-sha3@0.5.5: version "0.5.5" resolved "https://registry.yarnpkg.com/js-sha3/-/js-sha3-0.5.5.tgz#baf0c0e8c54ad5903447df96ade7a4a1bca79a4a" -js-sha3@0.5.7: - version "0.5.7" - resolved "https://registry.yarnpkg.com/js-sha3/-/js-sha3-0.5.7.tgz#0d4ffd8002d5333aabaf4a23eed2f6374c9f28e7" - js-sha3@^0.3.1: version "0.3.1" resolved "https://registry.yarnpkg.com/js-sha3/-/js-sha3-0.3.1.tgz#86122802142f0828502a0d1dee1d95e253bb0243" @@ -6542,10 +6471,6 @@ scoped-regex@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/scoped-regex/-/scoped-regex-1.0.0.tgz#a346bb1acd4207ae70bd7c0c7ca9e566b6baddb8" -scrypt-js@2.0.3: - version "2.0.3" - resolved "https://registry.yarnpkg.com/scrypt-js/-/scrypt-js-2.0.3.tgz#bb0040be03043da9a012a2cea9fc9f852cfc87d4" - scrypt.js@^0.2.0: version "0.2.0" resolved "https://registry.yarnpkg.com/scrypt.js/-/scrypt.js-0.2.0.tgz#af8d1465b71e9990110bedfc593b9479e03a8ada" @@ -6669,10 +6594,6 @@ set-value@^2.0.0: is-plain-object "^2.0.3" split-string "^3.0.1" -setimmediate@1.0.4: - version "1.0.4" - resolved "https://registry.yarnpkg.com/setimmediate/-/setimmediate-1.0.4.tgz#20e81de622d4a02588ce0c8da8973cbcf1d3138f" - setprototypeof@1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/setprototypeof/-/setprototypeof-1.1.0.tgz#d0bd85536887b6fe7c0d818cb962d9d91c54e656" @@ -7594,10 +7515,6 @@ utils-merge@1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/utils-merge/-/utils-merge-1.0.1.tgz#9f95710f50a267947b2ccc124741c1028427e713" -uuid@2.0.1: - version "2.0.1" - resolved "https://registry.yarnpkg.com/uuid/-/uuid-2.0.1.tgz#c2a30dedb3e535d72ccf82e343941a50ba8533ac" - uuid@^2.0.1: version "2.0.3" resolved "https://registry.yarnpkg.com/uuid/-/uuid-2.0.3.tgz#67e2e863797215530dff318e5bf9dcebfd47b21a" @@ -7899,7 +7816,7 @@ xmlhttprequest-ssl@~1.5.4: version "1.5.5" resolved "https://registry.yarnpkg.com/xmlhttprequest-ssl/-/xmlhttprequest-ssl-1.5.5.tgz#c2876b06168aadc40e57d97e81191ac8f4398b3e" -xmlhttprequest@*, xmlhttprequest@1.8.0: +xmlhttprequest@*: version "1.8.0" resolved "https://registry.yarnpkg.com/xmlhttprequest/-/xmlhttprequest-1.8.0.tgz#67fe075c5c24fef39f9d65f5f7b7fe75171968fc" From e9b6a081b3b4e4ba6b37715144e62c8e5b841441 Mon Sep 17 00:00:00 2001 From: mirathewhite Date: Mon, 22 Oct 2018 09:45:34 -0400 Subject: [PATCH 28/74] cleaned up Completeness output and colors/checkmarks (#232) --- verification/verification_reporter.js | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/verification/verification_reporter.js b/verification/verification_reporter.js index 047f550f8..99584c2c6 100644 --- a/verification/verification_reporter.js +++ b/verification/verification_reporter.js @@ -10,9 +10,8 @@ const jsdiff = require('diff'); const colors = require('colors'); // Global variables for text output. -const green_x = color('bright pass', base_reporter.symbols.err); const red_x = color('bright fail', base_reporter.symbols.err); -const green_ok = color('bright pass', base_reporter.symbols.ok); +const green_ok = color('green', base_reporter.symbols.ok); const red_ok = color('bright fail', base_reporter.symbols.ok); const indent = ' '; @@ -111,7 +110,7 @@ function verification_reporter (runner) { // If test is marked pending in spreadsheet, record for later output. if(spreadsheet_test.pending) { - console.log(indent + green_x + color('bright pass', ' pending')); + console.log(indent + green_ok + color('green', ' pending')); if(! pending[suite]) { pending[suite] = {}; } @@ -119,7 +118,7 @@ function verification_reporter (runner) { // If test descriptions match, mark green. } else if (spreadsheet_test.description == test_ran) { - console.log(indent + green_x); + console.log(indent + green_ok); // If test is in spreadsheet, but descriptions don't match. } else { @@ -172,7 +171,7 @@ function verification_reporter (runner) { console.log('\n\nSpreadsheet Verification Summary:\n'); // If there are pending tests included in the test suite... if (!_.isEmpty(pending)) { - console.log(color('bright pass', 'Pending Tests:')); + console.log(color('green', 'Pending Tests:')); console.log('The following tests are included in the test suite, but\n' + 'marked pending in the spreadsheet (delete -p flag once merged): '); console.log(util.inspect(pending, { showHidden: false, depth: null })); @@ -191,17 +190,29 @@ function verification_reporter (runner) { } } - // Do not report missing unit tests for files that did not run + // Report missing unit tests for files that were executed for(var testSuite in missingUnitTests){ - if(! _.has(executedTestSuites, testSuite) /* && ! testSuite.match(/Completeness/)*/) { + if(! _.has(executedTestSuites, testSuite)) { console.log(color('fail', 'Did not run: ' + testSuite)); delete missingUnitTests[testSuite]; } } + // report missing Completeness unit tests ONLY if every test file ran + var onlyCompletenessTestsAreMissing = true; + for(var testSuite in missingUnitTests){ + if(! testSuite.match(/Completeness/)) + onlyCompletenessTestsAreMissing = false; + } + if(onlyCompletenessTestsAreMissing){ + for(var testSuite in missingUnitTests){ + console.log(color('fail', 'Did not run: ' + testSuite)); + } + } + // If all tests are 'crossed-off', print success. if (_.isEmpty(missingUnitTests)) { - console.log('\n' + green_ok + color('bright pass', + console.log('\n' + green_ok + color('green', ' Test run contains all tests in spreadsheet.')); } else { // If not all tests are 'crossed-off', print the tests remaining. From dab79893ac6a95490b39a53cbc969b9c92ec15dc Mon Sep 17 00:00:00 2001 From: mirathewhite Date: Mon, 22 Oct 2018 10:01:37 -0400 Subject: [PATCH 29/74] fixed typos --- doc/masterminter.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/masterminter.md b/doc/masterminter.md index 6bc41561b..ed0ece93b 100644 --- a/doc/masterminter.md +++ b/doc/masterminter.md @@ -1,6 +1,6 @@ # MasterMinter contract The MasterMinter is a governance contract. It delegates the functionality -of the `masterMinter` role in the Centre USDC contract to multiple addresses. +of the `masterMinter` role in the CENTRE USDC contract to multiple addresses. (The `masterMinter` role can add and remove minters from a FiatToken and set their allowances.) The MasterMinter contract delegates the minter management capability to `controllers`. Each `controller` manages exactly one `minter`, and a single `minter` @@ -32,7 +32,7 @@ to the address of the `MasterMinter` contract. This enables the `MasterMinter` contract to call minter management functions on the FiatToken contract: - `configureMinter(minter, allowance)` - Enables the `minter` and sets its minting allowance. -- `removeMinter(minter)` - Disables the `minter` and sets its mintingallowance to 0. +- `removeMinter(minter)` - Disables the `minter` and sets its minting allowance to 0. - `isMinter(minter)` - Returns `true` if the `minter` is enabled, and `false` otherwise. - `minterAllowance(minter)` - Returns the minting allowance of the `minter`. @@ -90,7 +90,7 @@ We recommend assigning at least two `controllers` to each `minter`. The private keys to the `AllowanceController` and `SecurityController` should stay in cold storage. This configuration lets the Controller keep multiple warm `incrementMinterAllowance` transactions on hand, as well as the `removeMinter` transaction in case of a problem. Broadcasting the `removeMinter` transaction -will cause all future `incrementMinterAllowance` transactions to `throw`. Since there two types +will cause all future `incrementMinterAllowance` transactions to `throw`. Since the two types of transactions are managed by different addresses, there is no need to worry about nonce management. From 0ca51ea4d38b124168b94861bd242045522b3541 Mon Sep 17 00:00:00 2001 From: mirathewhite Date: Mon, 22 Oct 2018 10:03:30 -0400 Subject: [PATCH 30/74] Added ArgumentTests (#230) --- test/minting/MintP0_ArgumentTests.js | 0 test/minting/{MintP0BasicTests.js => MintP0_BasicTests.js} | 0 .../{MINTp0 - ArgumentTests.csv => MINTp0_ArgumentTests.csv} | 0 3 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 test/minting/MintP0_ArgumentTests.js rename test/minting/{MintP0BasicTests.js => MintP0_BasicTests.js} (100%) rename verification/Spreadsheets/{MINTp0 - ArgumentTests.csv => MINTp0_ArgumentTests.csv} (100%) diff --git a/test/minting/MintP0_ArgumentTests.js b/test/minting/MintP0_ArgumentTests.js new file mode 100644 index 000000000..e69de29bb diff --git a/test/minting/MintP0BasicTests.js b/test/minting/MintP0_BasicTests.js similarity index 100% rename from test/minting/MintP0BasicTests.js rename to test/minting/MintP0_BasicTests.js diff --git a/verification/Spreadsheets/MINTp0 - ArgumentTests.csv b/verification/Spreadsheets/MINTp0_ArgumentTests.csv similarity index 100% rename from verification/Spreadsheets/MINTp0 - ArgumentTests.csv rename to verification/Spreadsheets/MINTp0_ArgumentTests.csv From dc693a09b60c096523d55bec104e54c25880c384 Mon Sep 17 00:00:00 2001 From: mirathewhite Date: Wed, 24 Oct 2018 09:22:54 -0400 Subject: [PATCH 31/74] [CENT-361] Modify TokenTestUtils function buildExpectedState/getActualState (#228) * use compact state representation and getters for FiatToken * export fiatTokenEmptyState * Fixed bug: removed Accounts.upgraderAccount since it was causing duplication errors * Speeded up unit tests by removing some Accounts * fixed balance check bug in unit tests by changing pauserAccount to arbitraryAccount2 * Use all accounts and explicit token empty state * typos and minor fixes * removed bad file --- test/AccountUtils.js | 46 +- test/ExtendedPositiveTests.js | 20 +- test/MiscTests.js | 49 +- test/NegativeTests.js | 46 +- test/PositiveTests.js | 8 +- test/ProxyNegativeTests.js | 6 +- test/ProxyPositiveTests.js | 32 +- test/TokenTestUtils.js | 461 +++--------------- test/minting/ControllerTestUtils.js | 11 +- test/minting/MintControllerUtils.js | 1 - test/minting/MintP0_ArgumentTests.js | 0 .../Spreadsheets/FiatToken_MiscTests.csv | 12 +- .../FiatToken_ProxyPositiveTests.csv | 30 +- verification/verification_reporter.js | 5 +- 14 files changed, 210 insertions(+), 517 deletions(-) delete mode 100644 test/minting/MintP0_ArgumentTests.js diff --git a/test/AccountUtils.js b/test/AccountUtils.js index 2be04f3c2..98a09d202 100644 --- a/test/AccountUtils.js +++ b/test/AccountUtils.js @@ -3,26 +3,26 @@ 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 @@ -30,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] @@ -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 @@ -55,6 +54,17 @@ function setAccountDefault(accounts, defaultValue) { return result; } +// Returns an object with all named account values set to +// an object containing all named account values set to default +// e.g. sets {owner: setAccountDefault(accounts, 0), minter: setAccountDefault(accounts, 0),...} +function recursiveSetAccountDefault(accounts, value) { + var result = {}; + for(var account in accounts) { + result[account] = setAccountDefault(accounts, value); + } + return result; +} + // return an expectedState that combines customState with the emptyState function buildExpectedPartialState(emptyState, customState, ignoreExtraCustomVars) { // for each item in customVars, set the item in expectedState @@ -109,14 +119,23 @@ async function checkState(_tokens, _customVars, emptyState, getActualState, acco // accountQuery: an async function that takes as input an address and // queries the blockchain for a result // accounts: an object containing account addresses. Eg: {owner: 0xffad9033, minter: 0x45289432} -// returns an object containing the results of calling mappingQuery on each account +// returns an object containing the results of calling accountQuery 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) { @@ -129,6 +148,7 @@ module.exports = { Accounts: Accounts, AccountPrivateKeys: AccountPrivateKeys, setAccountDefault: setAccountDefault, + recursiveSetAccountDefault: recursiveSetAccountDefault, buildExpectedPartialState: buildExpectedPartialState, checkState: checkState, getAccountState: getAccountState, diff --git a/test/ExtendedPositiveTests.js b/test/ExtendedPositiveTests.js index 7734c3fd3..742bff571 100644 --- a/test/ExtendedPositiveTests.js +++ b/test/ExtendedPositiveTests.js @@ -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]); }); @@ -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]); }); @@ -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]); }); @@ -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]); }); diff --git a/test/MiscTests.js b/test/MiscTests.js index bfeb0a9d0..f70306558 100644 --- a/test/MiscTests.js +++ b/test/MiscTests.js @@ -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) }, @@ -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]); @@ -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]); @@ -230,16 +230,15 @@ 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 checkVariables([token], [customVars]); }); @@ -267,7 +266,7 @@ 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 }, @@ -275,20 +274,20 @@ async function run_tests(newToken, accounts) { { '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]); }); @@ -502,12 +501,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]); }); @@ -522,10 +521,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]); @@ -534,19 +533,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]); diff --git a/test/NegativeTests.js b/test/NegativeTests.js index 5712d23bf..8ff4d6911 100644 --- a/test/NegativeTests.js +++ b/test/NegativeTests.js @@ -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]); }); @@ -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]); }); @@ -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]); }); @@ -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]); }); @@ -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]); }); @@ -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]); }); @@ -337,16 +337,16 @@ async function run_tests(newToken, accounts) { ] await checkVariables([token], [customVars]); - await token.mint(Accounts.tokenOwnerAccount, 50, {from: Accounts.minterAccount}); + await token.mint(Accounts.arbitraryAccount2, 50, {from: Accounts.minterAccount}); 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': 'isAccountBlacklisted.arbitraryAccount', 'expectedValue': true} ] - await expectRevert(token.transfer(Accounts.arbitraryAccount, 50, {from: Accounts.tokenOwnerAccount})); + await expectRevert(token.transfer(Accounts.arbitraryAccount, 50, {from: Accounts.arbitraryAccount2})); await checkVariables([token], [customVars]); }); diff --git a/test/PositiveTests.js b/test/PositiveTests.js index b0b26790c..995459132 100644 --- a/test/PositiveTests.js +++ b/test/PositiveTests.js @@ -182,12 +182,12 @@ async function run_tests(newToken, accounts) { ]; await checkVariables([token], [customVars]); - await token.transfer(Accounts.pauserAccount, mintAmount, { from: Accounts.arbitraryAccount }); + await token.transfer(Accounts.arbitraryAccount2, mintAmount, { from: Accounts.arbitraryAccount }); customVars = [ { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - mintAmount) }, { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'balances.arbitraryAccount', 'expectedValue': bigZero }, - { 'variable': 'balances.pauserAccount', 'expectedValue': new BigNumber(mintAmount) }, + { 'variable': 'balances.arbitraryAccount2', 'expectedValue': new BigNumber(mintAmount) }, { 'variable': 'totalSupply', 'expectedValue': new BigNumber(mintAmount) } ]; await checkVariables([token], [customVars]); @@ -213,12 +213,12 @@ async function run_tests(newToken, accounts) { await checkVariables([token], [customVars]); await token.approve(Accounts.masterMinterAccount, mintAmount, { from: Accounts.arbitraryAccount }); - await token.transferFrom(Accounts.arbitraryAccount, Accounts.pauserAccount, mintAmount, { from: Accounts.masterMinterAccount }); + await token.transferFrom(Accounts.arbitraryAccount, Accounts.arbitraryAccount2, mintAmount, { from: Accounts.masterMinterAccount }); customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - mintAmount) }, { 'variable': 'balances.arbitraryAccount', 'expectedValue': bigZero }, - { 'variable': 'balances.pauserAccount', 'expectedValue': new BigNumber(mintAmount) }, + { 'variable': 'balances.arbitraryAccount2', 'expectedValue': new BigNumber(mintAmount) }, { 'variable': 'totalSupply', 'expectedValue': new BigNumber(mintAmount) } ]; await checkVariables([token], [customVars]); diff --git a/test/ProxyNegativeTests.js b/test/ProxyNegativeTests.js index 509293c3a..f3c0eac81 100644 --- a/test/ProxyNegativeTests.js +++ b/test/ProxyNegativeTests.js @@ -117,17 +117,17 @@ 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.transfer(Accounts.pauserAccount, mintAmount, { from: Accounts.arbitraryAccount }); + await token.transfer(Accounts.arbitraryAccount2, mintAmount, { from: Accounts.arbitraryAccount }); var upgradedToken = await UpgradedFiatTokenNewFields.new(); - var data = encodeCall('initialize', ['string','string','string','uint8','address','address','address','address','bool','address','uint256'], [name, symbol, currency, decimals, Accounts.masterMinterAccount, Accounts.pauserAccount, Accounts.blacklisterAccount, Accounts.tokenOwnerAccount, true, Accounts.pauserAccount, 12]); + var data = encodeCall('initialize', ['string','string','string','uint8','address','address','address','address','bool','address','uint256'], [name, symbol, currency, decimals, Accounts.masterMinterAccount, Accounts.arbitraryAccount2, Accounts.blacklisterAccount, Accounts.tokenOwnerAccount, true, Accounts.arbitraryAccount2, 12]); await expectRevert(proxy.upgradeToAndCall(upgradedToken.address, data, { from: Accounts.proxyOwnerAccount })); customVars = [ { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - mintAmount) }, { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'balances.arbitraryAccount', 'expectedValue': bigZero }, - { 'variable': 'balances.pauserAccount', 'expectedValue': new BigNumber(mintAmount) }, + { 'variable': 'balances.arbitraryAccount2', 'expectedValue': new BigNumber(mintAmount) }, { 'variable': 'totalSupply', 'expectedValue': new BigNumber(mintAmount) }, ]; await checkVariables([token], [customVars]); diff --git a/test/ProxyPositiveTests.js b/test/ProxyPositiveTests.js index e03fea7eb..b1b4e6210 100644 --- a/test/ProxyPositiveTests.js +++ b/test/ProxyPositiveTests.js @@ -48,7 +48,7 @@ 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.transfer(Accounts.pauserAccount, mintAmount, { from: Accounts.arbitraryAccount }); + await token.transfer(Accounts.arbitraryAccount2, mintAmount, { from: Accounts.arbitraryAccount }); var upgradedToken = await UpgradedFiatToken.new(); var tokenConfig = await upgradeTo(proxy, upgradedToken, Accounts.proxyOwnerAccount); @@ -58,7 +58,7 @@ async function run_tests(newToken, accounts) { { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - mintAmount) }, { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'balances.arbitraryAccount', 'expectedValue': bigZero }, - { 'variable': 'balances.pauserAccount', 'expectedValue': new BigNumber(mintAmount) }, + { 'variable': 'balances.arbitraryAccount2', 'expectedValue': new BigNumber(mintAmount) }, { 'variable': 'totalSupply', 'expectedValue': new BigNumber(mintAmount) }, { 'variable': 'proxiedTokenAddress', 'expectedValue': upgradedToken.address } ]; @@ -70,7 +70,7 @@ 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.transfer(Accounts.pauserAccount, mintAmount, { from: Accounts.arbitraryAccount }); + await token.transfer(Accounts.arbitraryAccount2, mintAmount, { from: Accounts.arbitraryAccount }); var upgradedToken = await UpgradedFiatTokenNewFields.new(); const initializeData = encodeCall('initV2', ['bool', 'address', 'uint256'], [true, Accounts.pauserAccount, 12]); @@ -87,7 +87,7 @@ async function run_tests(newToken, accounts) { { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - mintAmount) }, { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'balances.arbitraryAccount', 'expectedValue': bigZero }, - { 'variable': 'balances.pauserAccount', 'expectedValue': new BigNumber(mintAmount) }, + { 'variable': 'balances.arbitraryAccount2', 'expectedValue': new BigNumber(mintAmount) }, { 'variable': 'totalSupply', 'expectedValue': new BigNumber(mintAmount) }, { 'variable': 'proxiedTokenAddress', 'expectedValue': upgradedToken.address } ]; @@ -99,7 +99,7 @@ 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.transfer(Accounts.pauserAccount, mintAmount, { from: Accounts.arbitraryAccount }); + await token.transfer(Accounts.arbitraryAccount2, mintAmount, { from: Accounts.arbitraryAccount }); var upgradedToken = await UpgradedFiatTokenNewFieldsNewLogic.new(); const initializeData = encodeCall('initV2', ['bool', 'address', 'uint256'], [true, Accounts.pauserAccount, 12]); @@ -119,7 +119,7 @@ async function run_tests(newToken, accounts) { { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - mintAmount) }, { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'balances.arbitraryAccount', 'expectedValue': bigZero }, - { 'variable': 'balances.pauserAccount', 'expectedValue': new BigNumber(mintAmount) }, + { 'variable': 'balances.arbitraryAccount2', 'expectedValue': new BigNumber(mintAmount) }, { 'variable': 'totalSupply', 'expectedValue': new BigNumber(mintAmount) }, { 'variable': 'proxiedTokenAddress', 'expectedValue': upgradedToken.address } ]; @@ -170,7 +170,7 @@ async function run_tests(newToken, accounts) { it('upt004 should update proxy adminAccount with previous adminAccount', async function () { await proxy.changeAdmin(Accounts.masterMinterAccount, {from: Accounts.proxyOwnerAccount}); customVars = [ - { 'variable': 'upgrader', 'expectedValue': Accounts.masterMinterAccount}, + { 'variable': 'proxyOwner', 'expectedValue': Accounts.masterMinterAccount}, ] await checkVariables([token], [customVars]); }); @@ -180,20 +180,20 @@ async function run_tests(newToken, accounts) { await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); await token.mint(Accounts.arbitraryAccount, mintAmount + 1, { from: Accounts.minterAccount }); - await token.transfer(Accounts.pauserAccount, mintAmount, { from: Accounts.arbitraryAccount }); + await token.transfer(Accounts.arbitraryAccount2, mintAmount, { from: Accounts.arbitraryAccount }); var upgradedToken = await UpgradedFiatToken.new(); var tokenConfig = await upgradeTo(proxy, upgradedToken, Accounts.proxyOwnerAccount); var newToken = tokenConfig.token; - transfer = await newToken.transfer(Accounts.pauserAccount, 1, { from: Accounts.arbitraryAccount}); - validateTransferEvent(transfer, Accounts.arbitraryAccount, Accounts.pauserAccount, 1); + transfer = await newToken.transfer(Accounts.arbitraryAccount2, 1, { from: Accounts.arbitraryAccount}); + validateTransferEvent(transfer, Accounts.arbitraryAccount, Accounts.arbitraryAccount2, 1); customVars = [ { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - mintAmount - 1) }, { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'balances.arbitraryAccount', 'expectedValue': bigZero }, - { 'variable': 'balances.pauserAccount', 'expectedValue': new BigNumber(mintAmount + 1) }, + { 'variable': 'balances.arbitraryAccount2', 'expectedValue': new BigNumber(mintAmount + 1) }, { 'variable': 'totalSupply', 'expectedValue': new BigNumber(mintAmount + 1) }, { 'variable': 'proxiedTokenAddress', 'expectedValue': upgradedToken.address } ]; @@ -225,7 +225,7 @@ 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.transfer(Accounts.pauserAccount, mintAmount, { from: Accounts.arbitraryAccount }); + await token.transfer(Accounts.arbitraryAccount2, mintAmount, { from: Accounts.arbitraryAccount }); var tokenConfig = await upgradeTo(proxy, rawToken, Accounts.proxyOwnerAccount); var sameToken = tokenConfig.token; @@ -235,14 +235,14 @@ async function run_tests(newToken, accounts) { { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - mintAmount) }, { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'balances.arbitraryAccount', 'expectedValue': bigZero }, - { 'variable': 'balances.pauserAccount', 'expectedValue': new BigNumber(mintAmount) }, + { 'variable': 'balances.arbitraryAccount2', 'expectedValue': new BigNumber(mintAmount) }, { 'variable': 'totalSupply', 'expectedValue': new BigNumber(mintAmount) }, ]; await checkVariables([sameToken], [customVars]); }); it('upt009 should check that admin is set correctly by proxy constructor', async function() { - assert.equal(await getAdmin(token), Accounts.upgraderAccount); + assert.equal(await getAdmin(token), Accounts.proxyOwnerAccount); }); it('upt011 should upgradeToAndCall while paused and upgraded contract should be paused as a result', async function () { @@ -262,7 +262,7 @@ async function run_tests(newToken, accounts) { await checkVariables([newProxiedToken], [customVars]); }); - it('upt012 should upgradeToAndCall while upgrader is blacklisted', async function () { + it('upt012 should upgradeToAndCall while proxyOwner is blacklisted', async function () { await token.blacklist(Accounts.proxyOwnerAccount, {from: Accounts.blacklisterAccount}); var upgradedToken = await UpgradedFiatTokenNewFields.new(); @@ -271,7 +271,7 @@ async function run_tests(newToken, accounts) { newProxiedToken = await UpgradedFiatTokenNewFields.at(proxy.address); customVars = [ - { 'variable': 'isAccountBlacklisted.upgraderAccount', 'expectedValue': true, }, + { 'variable': 'isAccountBlacklisted.proxyOwnerAccount', 'expectedValue': true, }, { 'variable': 'proxiedTokenAddress', 'expectedValue': upgradedToken.address } ]; await checkVariables([newProxiedToken], [customVars]); diff --git a/test/TokenTestUtils.js b/test/TokenTestUtils.js index 2f452a917..ccfe78e36 100644 --- a/test/TokenTestUtils.js +++ b/test/TokenTestUtils.js @@ -1,6 +1,7 @@ const util = require('util'); const abi = require('ethereumjs-abi') var _ = require('lodash'); +var clone = require('clone'); var name = 'Sample Fiat Token'; var symbol = 'C-USD'; var currency = 'USD'; @@ -21,6 +22,11 @@ var FiatTokenProxy = artifacts.require('FiatTokenProxy'); var AccountUtils = require('./AccountUtils'); var Accounts = AccountUtils.Accounts; +var setAccountDefault = AccountUtils.setAccountDefault; +var recursiveSetAccountDefault = AccountUtils.recursiveSetAccountDefault; +var checkState = AccountUtils.checkState; +var getAccountState = AccountUtils.getAccountState; + // TODO: test really big numbers Does this still have to be done?? var adminSlot = "0x10d6a54a4754c8869d6886b5f5d7fbfa5b4522237ea5c60d11bc4e7a1ff9390b"; @@ -166,128 +172,34 @@ function checkBurnEvents(burning, amount, burner) { } +var fiatTokenEmptyState = { + "name": name, + "symbol": symbol, + "currency": currency, + "decimals": new BigNumber(decimals), + "masterMinter": Accounts.masterMinterAccount, + "pauser": Accounts.pauserAccount, + "blacklister" : Accounts.blacklisterAccount, + "tokenOwner": Accounts.tokenOwnerAccount, + "proxiedTokenAddress": bigZero, + "initializedV1": trueInStorageFormat, + "proxyOwner": Accounts.proxyOwnerAccount, + "balances": setAccountDefault(Accounts, bigZero), + "allowance": recursiveSetAccountDefault(Accounts, bigZero), + "totalSupply": bigZero, + "isAccountBlacklisted": setAccountDefault(Accounts, false), + "isAccountMinter": setAccountDefault(Accounts, false), + "minterAllowance": setAccountDefault(Accounts, bigZero), + "paused": false, +}; + // Creates a state object, with default values replaced by // customVars where appropriate. function buildExpectedState(token, customVars) { - // set each variable's default value - var expectedState = { - 'name': name, - 'symbol': symbol, - 'currency': currency, - 'decimals': new BigNumber(decimals), - 'masterMinter': Accounts.masterMinterAccount, - 'pauser': Accounts.pauserAccount, - 'blacklister': Accounts.blacklisterAccount, - 'tokenOwner': Accounts.tokenOwnerAccount, - 'proxiedTokenAddress': token.proxiedTokenAddress, - 'initializedV1': trueInStorageFormat, - 'upgrader': Accounts.proxyOwnerAccount, - 'balances': { - 'arbitraryAccount': bigZero, - 'masterMinterAccount': bigZero, - 'minterAccount': bigZero, - 'pauserAccount': bigZero, - 'blacklisterAccount': bigZero, - 'tokenOwnerAccount': bigZero, - 'upgraderAccount': bigZero, - }, - 'allowance': { - 'arbitraryAccount': { - 'masterMinterAccount': bigZero, - 'minterAccount': bigZero, - 'pauserAccount': bigZero, - 'blacklisterAccount': bigZero, - 'tokenOwnerAccount': bigZero, - 'arbitraryAccount': bigZero, - 'upgraderAccount': bigZero, - }, - 'masterMinterAccount': { - 'arbitraryAccount': bigZero, - 'minterAccount': bigZero, - 'pauserAccount': bigZero, - 'blacklisterAccount': bigZero, - 'tokenOwnerAccount': bigZero, - 'masterMinterAccount': bigZero, - 'upgraderAccount': bigZero, - }, - 'minterAccount': { - 'arbitraryAccount': bigZero, - 'masterMinterAccount': bigZero, - 'pauserAccount': bigZero, - 'blacklisterAccount': bigZero, - 'tokenOwnerAccount': bigZero, - 'minterAccount': bigZero, - 'upgraderAccount': bigZero, - }, - 'pauserAccount': { - 'arbitraryAccount': bigZero, - 'masterMinterAccount': bigZero, - 'minterAccount': bigZero, - 'blacklisterAccount': bigZero, - 'tokenOwnerAccount': bigZero, - 'pauserAccount': bigZero, - 'upgraderAccount': bigZero, - }, - 'blacklisterAccount': { - 'arbitraryAccount': bigZero, - 'masterMinterAccount': bigZero, - 'minterAccount': bigZero, - 'pauserAccount': bigZero, - 'tokenOwnerAccount': bigZero, - 'blacklisterAccount': bigZero, - 'upgraderAccount': bigZero, - }, - 'tokenOwnerAccount': { - 'arbitraryAccount': bigZero, - 'masterMinterAccount': bigZero, - 'minterAccount': bigZero, - 'pauserAccount': bigZero, - 'blacklisterAccount': bigZero, - 'tokenOwnerAccount': bigZero, - 'upgraderAccount': bigZero, - }, - 'upgraderAccount': { - 'arbitraryAccount': bigZero, - 'masterMinterAccount': bigZero, - 'minterAccount': bigZero, - 'pauserAccount': bigZero, - 'blacklisterAccount': bigZero, - 'tokenOwnerAccount': bigZero, - 'upgraderAccount': bigZero, - } - }, - 'totalSupply': bigZero, - 'isAccountBlacklisted': { - 'arbitraryAccount': false, - 'masterMinterAccount': false, - 'minterAccount': false, - 'pauserAccount': false, - 'blacklisterAccount': false, - 'tokenOwnerAccount': false, - 'upgraderAccount': false, - }, - 'isAccountMinter': { - 'arbitraryAccount': false, - 'masterMinterAccount': false, - 'minterAccount': false, - 'pauserAccount': false, - 'blacklisterAccount': false, - 'tokenOwnerAccount': false, - 'upgraderAccount': false, - }, - 'minterAllowance': { - 'arbitraryAccount': bigZero, - 'masterMinterAccount': bigZero, - 'minterAccount': bigZero, - 'pauserAccount': bigZero, - 'blacklisterAccount': bigZero, - 'tokenOwnerAccount': bigZero, - 'upgraderAccount': bigZero, - }, - 'paused': false - }; - // for each item in customVars, set the item in expectedState + var expectedState = clone(fiatTokenEmptyState); + expectedState.proxiedTokenAddress = token.proxiedTokenAddress; + var i; for (i = 0; i < customVars.length; ++i) { if (_.has(expectedState, customVars[i].variable)) { @@ -326,14 +238,14 @@ async function checkVariables(_tokens, _customVars) { assertDiff.deepEqual(actualState, expectedState, "difference between expected and actual state"); // Check that sum of individual balances equals totalSupply - var accounts = [Accounts.arbitraryAccount, Accounts.masterMinterAccount, Accounts.minterAccount, Accounts.pauserAccount, Accounts.blacklisterAccount, Accounts.tokenOwnerAccount, Accounts.upgraderAccount]; + var accounts = Object.keys(Accounts).map(accountName => Accounts[accountName]); var balanceSum = bigZero; var x; for (x = 0; x < accounts.length; x++) { balanceSum = balanceSum.plus(new BigNumber(await token.balanceOf(accounts[x]))); } var totalSupply = new BigNumber(await token.totalSupply()) - assert(balanceSum.isEqualTo(totalSupply)); + assert(balanceSum.isEqualTo(totalSupply), "sum of balances is not equal to totalSupply"); } } @@ -354,97 +266,33 @@ async function checkMINTp0(_contracts, _customVars) { // build up actualState object to compare to expectedState object async function getActualState(token) { + // lambda expressions to get allowance mappings in token contract + var allowanceMappingEval = async function(account1) { + var myAllowances = async function(account2) { + return token.allowance(account1, account2); + } + return getAccountState(myAllowances, Accounts); + }; + return Q.all([ - await token.name.call(), - await token.symbol.call(), - await token.currency.call(), - await token.decimals.call(), - await token.masterMinter.call(), - await token.pauser.call(), - await token.blacklister.call(), - await token.owner.call(), - await getImplementation(token), - await getAdmin(token), - await getInitializedV1(token), - await token.balanceOf(Accounts.arbitraryAccount), - await token.balanceOf(Accounts.masterMinterAccount), - await token.balanceOf(Accounts.minterAccount), - await token.balanceOf(Accounts.pauserAccount), - await token.balanceOf(Accounts.blacklisterAccount), - await token.balanceOf(Accounts.tokenOwnerAccount), - await token.balanceOf(Accounts.upgraderAccount), - await token.allowance(Accounts.arbitraryAccount, Accounts.masterMinterAccount), - await token.allowance(Accounts.arbitraryAccount, Accounts.minterAccount), - await token.allowance(Accounts.arbitraryAccount, Accounts.pauserAccount), - await token.allowance(Accounts.arbitraryAccount, Accounts.blacklisterAccount), - await token.allowance(Accounts.arbitraryAccount, Accounts.tokenOwnerAccount), - await token.allowance(Accounts.arbitraryAccount, Accounts.arbitraryAccount), - await token.allowance(Accounts.arbitraryAccount, Accounts.upgraderAccount), - await token.allowance(Accounts.masterMinterAccount, Accounts.arbitraryAccount), - await token.allowance(Accounts.masterMinterAccount, Accounts.minterAccount), - await token.allowance(Accounts.masterMinterAccount, Accounts.pauserAccount), - await token.allowance(Accounts.masterMinterAccount, Accounts.blacklisterAccount), - await token.allowance(Accounts.masterMinterAccount, Accounts.tokenOwnerAccount), - await token.allowance(Accounts.masterMinterAccount, Accounts.masterMinterAccount), - await token.allowance(Accounts.masterMinterAccount, Accounts.upgraderAccount), - await token.allowance(Accounts.minterAccount, Accounts.arbitraryAccount), - await token.allowance(Accounts.minterAccount, Accounts.masterMinterAccount), - await token.allowance(Accounts.minterAccount, Accounts.pauserAccount), - await token.allowance(Accounts.minterAccount, Accounts.blacklisterAccount), - await token.allowance(Accounts.minterAccount, Accounts.tokenOwnerAccount), - await token.allowance(Accounts.minterAccount, Accounts.minterAccount), - await token.allowance(Accounts.minterAccount, Accounts.upgraderAccount), - await token.allowance(Accounts.pauserAccount, Accounts.arbitraryAccount), - await token.allowance(Accounts.pauserAccount, Accounts.masterMinterAccount), - await token.allowance(Accounts.pauserAccount, Accounts.minterAccount), - await token.allowance(Accounts.pauserAccount, Accounts.blacklisterAccount), - await token.allowance(Accounts.pauserAccount, Accounts.tokenOwnerAccount), - await token.allowance(Accounts.pauserAccount, Accounts.pauserAccount), - await token.allowance(Accounts.pauserAccount, Accounts.upgraderAccount), - await token.allowance(Accounts.blacklisterAccount, Accounts.arbitraryAccount), - await token.allowance(Accounts.blacklisterAccount, Accounts.masterMinterAccount), - await token.allowance(Accounts.blacklisterAccount, Accounts.minterAccount), - await token.allowance(Accounts.blacklisterAccount, Accounts.pauserAccount), - await token.allowance(Accounts.blacklisterAccount, Accounts.tokenOwnerAccount), - await token.allowance(Accounts.blacklisterAccount, Accounts.blacklisterAccount), - await token.allowance(Accounts.blacklisterAccount, Accounts.upgraderAccount), - await token.allowance(Accounts.tokenOwnerAccount, Accounts.arbitraryAccount), - await token.allowance(Accounts.tokenOwnerAccount, Accounts.masterMinterAccount), - await token.allowance(Accounts.tokenOwnerAccount, Accounts.minterAccount), - await token.allowance(Accounts.tokenOwnerAccount, Accounts.pauserAccount), - await token.allowance(Accounts.tokenOwnerAccount, Accounts.blacklisterAccount), - await token.allowance(Accounts.tokenOwnerAccount, Accounts.tokenOwnerAccount), - await token.allowance(Accounts.tokenOwnerAccount, Accounts.upgraderAccount), - await token.allowance(Accounts.upgraderAccount, Accounts.arbitraryAccount), - await token.allowance(Accounts.upgraderAccount, Accounts.masterMinterAccount), - await token.allowance(Accounts.upgraderAccount, Accounts.minterAccount), - await token.allowance(Accounts.upgraderAccount, Accounts.pauserAccount), - await token.allowance(Accounts.upgraderAccount, Accounts.blacklisterAccount), - await token.allowance(Accounts.upgraderAccount, Accounts.tokenOwnerAccount), - await token.allowance(Accounts.upgraderAccount, Accounts.upgraderAccount), - await token.totalSupply(), - await token.isBlacklisted(Accounts.arbitraryAccount), - await token.isBlacklisted(Accounts.masterMinterAccount), - await token.isBlacklisted(Accounts.minterAccount), - await token.isBlacklisted(Accounts.pauserAccount), - await token.isBlacklisted(Accounts.blacklisterAccount), - await token.isBlacklisted(Accounts.tokenOwnerAccount), - await token.isBlacklisted(Accounts.upgraderAccount), - await token.isMinter(Accounts.arbitraryAccount), - await token.isMinter(Accounts.masterMinterAccount), - await token.isMinter(Accounts.minterAccount), - await token.isMinter(Accounts.pauserAccount), - await token.isMinter(Accounts.blacklisterAccount), - await token.isMinter(Accounts.tokenOwnerAccount), - await token.isMinter(Accounts.upgraderAccount), - await token.minterAllowance(Accounts.arbitraryAccount), - await token.minterAllowance(Accounts.masterMinterAccount), - await token.minterAllowance(Accounts.minterAccount), - await token.minterAllowance(Accounts.pauserAccount), - await token.minterAllowance(Accounts.blacklisterAccount), - await token.minterAllowance(Accounts.tokenOwnerAccount), - await token.minterAllowance(Accounts.upgraderAccount), - await token.paused() + token.name.call(), + token.symbol.call(), + token.currency.call(), + token.decimals.call(), + token.masterMinter.call(), + token.pauser.call(), + token.blacklister.call(), + token.owner.call(), + getImplementation(token), + getAdmin(token), + getInitializedV1(token), + getAccountState(token.balanceOf, Accounts), + getAccountState(allowanceMappingEval, Accounts), + token.totalSupply(), + getAccountState(token.isBlacklisted, Accounts), + getAccountState(token.isMinter, Accounts), + getAccountState(token.minterAllowance, Accounts), + token.paused() ]).spread(function ( name, symbol, @@ -455,86 +303,14 @@ async function getActualState(token) { blacklister, tokenOwner, proxiedTokenAddress, - upgrader, + proxyOwner, initializedV1, - balancesA, - balancesMM, - balancesM, - balancesP, - balancesB, - balancesRAC, - balancesU, - allowanceAtoMM, - allowanceAtoM, - allowanceAtoP, - allowanceAtoB, - allowanceAtoRAC, - allowanceAtoA, - allowanceAtoU, - allowanceMMtoA, - allowanceMMtoM, - allowanceMMtoP, - allowanceMMtoB, - allowanceMMtoRAC, - allowanceMMtoMM, - allowanceMMtoU, - allowanceMtoA, - allowanceMtoMM, - allowanceMtoP, - allowanceMtoB, - allowanceMtoRAC, - allowanceMtoM, - allowanceMtoU, - allowancePtoA, - allowancePtoMM, - allowancePtoM, - allowancePtoB, - allowancePtoRAC, - allowancePtoP, - allowancePtoU, - allowanceBtoA, - allowanceBtoMM, - allowanceBtoM, - allowanceBtoP, - allowanceBtoRAC, - allowanceBtoB, - allowanceBtoU, - allowanceRACtoA, - allowanceRACtoMM, - allowanceRACtoM, - allowanceRACtoP, - allowanceRACtoB, - allowanceRACtoRAC, - allowanceRACtoU, - allowanceUtoA, - allowanceUtoMM, - allowanceUtoM, - allowanceUtoP, - allowanceUtoB, - allowanceUtoRAC, - allowanceUtoU, + balances, + allowances, totalSupply, - isAccountBlacklistedA, - isAccountBlacklistedMM, - isAccountBlacklistedM, - isAccountBlacklistedP, - isAccountBlacklistedB, - isAccountBlacklistedRAC, - isAccountBlacklistedU, - isAccountMinterA, - isAccountMinterMM, - isAccountMinterM, - isAccountMinterP, - isAccountMinterB, - isAccountMinterRAC, - isAccountMinterU, - minterAllowanceA, - minterAllowanceMM, - minterAllowanceM, - minterAllowanceP, - minterAllowanceB, - minterAllowanceRAC, - minterAllowanceU, + isAccountBlacklisted, + isAccountMinter, + minterAllowance, paused ) { var actualState = { @@ -547,110 +323,14 @@ async function getActualState(token) { 'blacklister': blacklister, 'tokenOwner': tokenOwner, 'proxiedTokenAddress': proxiedTokenAddress, - 'upgrader': upgrader, + 'proxyOwner': proxyOwner, 'initializedV1': initializedV1, - 'balances': { - 'arbitraryAccount': balancesA, - 'masterMinterAccount': balancesMM, - 'minterAccount': balancesM, - 'pauserAccount': balancesP, - 'blacklisterAccount': balancesB, - 'tokenOwnerAccount': balancesRAC, - 'upgraderAccount': balancesU, - }, - 'allowance': { - 'arbitraryAccount': { - 'masterMinterAccount': allowanceAtoMM, - 'minterAccount': allowanceAtoM, - 'pauserAccount': allowanceAtoP, - 'blacklisterAccount': allowanceAtoB, - 'tokenOwnerAccount': allowanceAtoRAC, - 'arbitraryAccount': allowanceAtoA, - 'upgraderAccount': allowanceAtoU, - }, - 'masterMinterAccount': { - 'arbitraryAccount': allowanceMMtoA, - 'minterAccount': allowanceMMtoM, - 'pauserAccount': allowanceMMtoP, - 'blacklisterAccount': allowanceMMtoB, - 'tokenOwnerAccount': allowanceMMtoRAC, - 'masterMinterAccount': allowanceMMtoMM, - 'upgraderAccount': allowanceMMtoU, - }, - 'minterAccount': { - 'arbitraryAccount': allowanceMtoA, - 'masterMinterAccount': allowanceMtoMM, - 'pauserAccount': allowanceMtoP, - 'blacklisterAccount': allowanceMtoB, - 'tokenOwnerAccount': allowanceMtoRAC, - 'minterAccount': allowanceMtoM, - 'upgraderAccount': allowanceMtoU, - }, - 'pauserAccount': { - 'arbitraryAccount': allowancePtoA, - 'masterMinterAccount': allowancePtoMM, - 'minterAccount': allowancePtoM, - 'blacklisterAccount': allowancePtoB, - 'tokenOwnerAccount': allowancePtoRAC, - 'pauserAccount': allowancePtoP, - 'upgraderAccount': allowancePtoU, - }, - 'blacklisterAccount': { - 'arbitraryAccount': allowanceBtoA, - 'masterMinterAccount': allowanceBtoMM, - 'minterAccount': allowanceBtoM, - 'pauserAccount': allowanceBtoP, - 'tokenOwnerAccount': allowanceBtoRAC, - 'blacklisterAccount': allowanceBtoB, - 'upgraderAccount': allowanceBtoU, - }, - 'tokenOwnerAccount': { - 'arbitraryAccount': allowanceRACtoA, - 'masterMinterAccount': allowanceRACtoMM, - 'minterAccount': allowanceRACtoM, - 'pauserAccount': allowanceRACtoP, - 'blacklisterAccount': allowanceRACtoB, - 'tokenOwnerAccount': allowanceRACtoRAC, - 'upgraderAccount': allowanceRACtoU, - }, - 'upgraderAccount': { - 'arbitraryAccount': allowanceUtoA, - 'masterMinterAccount': allowanceUtoMM, - 'minterAccount': allowanceUtoM, - 'pauserAccount': allowanceUtoP, - 'blacklisterAccount': allowanceUtoB, - 'tokenOwnerAccount': allowanceUtoRAC, - 'upgraderAccount': allowanceUtoU, - } - }, + 'balances': balances, + 'allowance': allowances, 'totalSupply': totalSupply, - 'isAccountBlacklisted': { - 'arbitraryAccount': isAccountBlacklistedA, - 'masterMinterAccount': isAccountBlacklistedMM, - 'minterAccount': isAccountBlacklistedM, - 'pauserAccount': isAccountBlacklistedP, - 'blacklisterAccount': isAccountBlacklistedB, - 'tokenOwnerAccount': isAccountBlacklistedRAC, - 'upgraderAccount': isAccountBlacklistedU, - }, - 'isAccountMinter': { - 'arbitraryAccount': isAccountMinterA, - 'masterMinterAccount': isAccountMinterMM, - 'minterAccount': isAccountMinterM, - 'pauserAccount': isAccountMinterP, - 'blacklisterAccount': isAccountMinterB, - 'tokenOwnerAccount': isAccountMinterRAC, - 'upgraderAccount': isAccountMinterU, - }, - 'minterAllowance': { - 'arbitraryAccount': minterAllowanceA, - 'masterMinterAccount': minterAllowanceMM, - 'minterAccount': minterAllowanceM, - 'pauserAccount': minterAllowanceP, - 'blacklisterAccount': minterAllowanceB, - 'tokenOwnerAccount': minterAllowanceRAC, - 'upgraderAccount': minterAllowanceU, - }, + 'isAccountBlacklisted': isAccountBlacklisted, + 'isAccountMinter': isAccountMinter, + 'minterAllowance': minterAllowance, 'paused': paused }; return actualState; @@ -965,4 +645,5 @@ module.exports = { getInitializedV1: getInitializedV1, getAdmin: getAdmin, maxAmount: maxAmount, + fiatTokenEmptyState, }; diff --git a/test/minting/ControllerTestUtils.js b/test/minting/ControllerTestUtils.js index 8a73089f8..8fe59693e 100644 --- a/test/minting/ControllerTestUtils.js +++ b/test/minting/ControllerTestUtils.js @@ -1,6 +1,5 @@ var BigNumber = require('bignumber.js'); var Q = require('q'); -var clone = require('clone'); // set to true to enable verbose logging in the tests var debugLogging = false; @@ -18,7 +17,6 @@ var getAccountState = AccountUtils.getAccountState; function ControllerState(owner, controllers) { this.owner = owner; this.controllers = controllers; - this.checkState = checkControllerState; this.checkState = async function(controllerContract) {await checkControllerState(controllerContract, this)}; } @@ -36,14 +34,9 @@ async function checkControllerState(controller, customState) { // Gets the actual state of the controller contract. // Evaluates all mappings on the provided accounts. async function getActualControllerState(controllerContract, accounts) { - // Lambda expressions for retrieving values from mappings - var controllerMappingEval = async function(accountAddress) { - return await controllerContract.controllers(accountAddress); - }; - return Q.all([ - await controllerContract.owner.call(), - await getAccountState(controllerMappingEval, accounts), + controllerContract.owner.call(), + getAccountState(controllerContract.controllers, accounts), ]).spread(function ( owner, controllerState, diff --git a/test/minting/MintControllerUtils.js b/test/minting/MintControllerUtils.js index d67e0e847..64eb8d139 100644 --- a/test/minting/MintControllerUtils.js +++ b/test/minting/MintControllerUtils.js @@ -1,6 +1,5 @@ var BigNumber = require('bignumber.js'); var bigZero = new BigNumber(0); -var clone = require('clone'); var tokenUtils = require('./../TokenTestUtils'); var initializeTokenWithProxy = tokenUtils.initializeTokenWithProxy; diff --git a/test/minting/MintP0_ArgumentTests.js b/test/minting/MintP0_ArgumentTests.js deleted file mode 100644 index e69de29bb..000000000 diff --git a/verification/Spreadsheets/FiatToken_MiscTests.csv b/verification/Spreadsheets/FiatToken_MiscTests.csv index da25efe45..d65929415 100644 --- a/verification/Spreadsheets/FiatToken_MiscTests.csv +++ b/verification/Spreadsheets/FiatToken_MiscTests.csv @@ -26,9 +26,9 @@ ms043 ,ms043 should return true on configureMinter,Return Value ms044 ,ms044 should return true on removeMinter,Return Value ms045,"ms045 initialized should be in slot 8, byte 21",Slot Storage ms046,ms046 initialized should be 0 before initialization,Slot Storage -ms047 -p,ms047 configureMinter works on amount=2^256-1,2^256-1 Input -ms048 -p,ms048 mint works on amount=2^256-1,2^256-1 Input -ms049 -p,ms049 burn on works on amount=2^256-1,2^256-1 Input -ms050 -p,ms050 approve works on amount=2^256-1,2^256-1 Input -ms051 -p,ms051 transfer works on amount=2^256-1,2^256-1 Input -ms052 -p,ms052 transferFrom works on amount=2^256-1,2^256-1 Input \ No newline at end of file +ms047,ms047 configureMinter works on amount=2^256-1,2^256-1 Input +ms048,ms048 mint works on amount=2^256-1,2^256-1 Input +ms049,ms049 burn on works on amount=2^256-1,2^256-1 Input +ms050,ms050 approve works on amount=2^256-1,2^256-1 Input +ms051,ms051 transfer works on amount=2^256-1,2^256-1 Input +ms052,ms052 transferFrom works on amount=2^256-1,2^256-1 Input \ No newline at end of file diff --git a/verification/Spreadsheets/FiatToken_ProxyPositiveTests.csv b/verification/Spreadsheets/FiatToken_ProxyPositiveTests.csv index be31bfbfc..247a93ad9 100644 --- a/verification/Spreadsheets/FiatToken_ProxyPositiveTests.csv +++ b/verification/Spreadsheets/FiatToken_ProxyPositiveTests.csv @@ -1,15 +1,15 @@ -Variable Name,Code,Test -_implementation,upt001,upt001 should upgradeTo new contract and preserve data field values -"_implementation, [new fields]",upt002,upt002 should upgradeToandCall to contract with new data fields set on initVX and ensure new fields are correct and old data is preserved -"_implementation, [new fields]",upt003,"upt003 should upgradeToAndCall to contract with new data fields set on initVX and new logic and ensure old data preserved,new logic works, and new fields correct" -_admin,upt004,upt004 should update proxy adminAccount with previous adminAccount -"_implementation, balances",upt005,upt005 should receive Transfer event on transfer when proxied after upgrade -pause,upt006,upt006 should upgrade while paused and upgraded contract should be paused as a result; then unpause should unpause contract -should not change state,upt007,upt007 should upgrade contract to original address -"initialization fields, _implementation",upt008,upt008 should deploy upgraded version of contract with new data fields and without previous deployment and ensure new fields correct -_admin,upt009,upt009 should check that admin is set correctly by proxy constructor -"initialization fields, _implementation",upt010,"upt010 should deploy upgraded version of contract with new data fields and logic without previous deployment and ensure new logic works, and new fields correct" -"_implementation, [new fields]",upt011,upt011 should upgradeToAndCall while paused and upgraded contract should be paused as a result -"_implementation, [new fields]",upt012,upt012 should upgradeToAndCall while upgrader is blacklisted -"_implementation, [new fields]",upt013,upt013 should upgradeToAndCall while new logic is blacklisted -_implementation,upt014,upt014 should upgradeTo while new logic is blacklisted \ No newline at end of file +Variable Name,Code,Test +_implementation,upt001,upt001 should upgradeTo new contract and preserve data field values +"_implementation, [new fields]",upt002,upt002 should upgradeToandCall to contract with new data fields set on initVX and ensure new fields are correct and old data is preserved +"_implementation, [new fields]",upt003,"upt003 should upgradeToAndCall to contract with new data fields set on initVX and new logic and ensure old data preserved,new logic works, and new fields correct" +_admin,upt004,upt004 should update proxy adminAccount with previous adminAccount +"_implementation, balances",upt005,upt005 should receive Transfer event on transfer when proxied after upgrade +pause,upt006,upt006 should upgrade while paused and upgraded contract should be paused as a result; then unpause should unpause contract +should not change state,upt007,upt007 should upgrade contract to original address +"initialization fields, _implementation",upt008,upt008 should deploy upgraded version of contract with new data fields and without previous deployment and ensure new fields correct +_admin,upt009,upt009 should check that admin is set correctly by proxy constructor +"initialization fields, _implementation",upt010,"upt010 should deploy upgraded version of contract with new data fields and logic without previous deployment and ensure new logic works, and new fields correct" +"_implementation, [new fields]",upt011,upt011 should upgradeToAndCall while paused and upgraded contract should be paused as a result +"_implementation, [new fields]",upt012,upt012 should upgradeToAndCall while proxyOwner is blacklisted +"_implementation, [new fields]",upt013,upt013 should upgradeToAndCall while new logic is blacklisted +_implementation,upt014,upt014 should upgradeTo while new logic is blacklisted diff --git a/verification/verification_reporter.js b/verification/verification_reporter.js index 99584c2c6..3320ea9cc 100644 --- a/verification/verification_reporter.js +++ b/verification/verification_reporter.js @@ -82,7 +82,9 @@ function verification_reporter (runner) { var id = test.title.match(/([a-z]{2,})([0-9]+)/g); if (id) { id = id[0]; - } else { + } else if(spreadsheet[suite]) { + // only print if the testsuite is in a spreadsheet + // otherwise, will print a different error later console.log(indent + color('pass', 'Error parsing test title.\n' + indent + 'Confirm id is formatted correctly and included in test title.\n' @@ -96,7 +98,6 @@ function verification_reporter (runner) { for(var completeness_suite in missingUnitTests) { if(completeness_suite.match(/Completeness/)){ if(missingUnitTests[completeness_suite][id]) { - console.log("complete: " + id); delete missingUnitTests[completeness_suite][id]; } } From 7b2c573197420a9b621f1dd7b657ba134551cab0 Mon Sep 17 00:00:00 2001 From: mirathewhite Date: Wed, 24 Oct 2018 14:06:17 -0400 Subject: [PATCH 32/74] [CENT-355] Write ArgumentTests (#234) * use compact state representation and getters for FiatToken * export fiatTokenEmptyState * Fixed bug: removed Accounts.upgraderAccount since it was causing duplication errors * fixed test 006 --- test/minting/MintP0_ArgumentTests.js | 212 ++++++++++++++++++ .../Spreadsheets/MINTp0_ArgumentTests.csv | 2 +- 2 files changed, 213 insertions(+), 1 deletion(-) create mode 100644 test/minting/MintP0_ArgumentTests.js diff --git a/test/minting/MintP0_ArgumentTests.js b/test/minting/MintP0_ArgumentTests.js new file mode 100644 index 000000000..e8690edd7 --- /dev/null +++ b/test/minting/MintP0_ArgumentTests.js @@ -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); + diff --git a/verification/Spreadsheets/MINTp0_ArgumentTests.csv b/verification/Spreadsheets/MINTp0_ArgumentTests.csv index 1b9e0ab28..48b05337a 100644 --- a/verification/Spreadsheets/MINTp0_ArgumentTests.csv +++ b/verification/Spreadsheets/MINTp0_ArgumentTests.csv @@ -1,6 +1,6 @@ File,Function,Arguments,Code,Description Ownable.sol,transferOwnership,newOwner == msg.sender,arg000,arg000 transferOwnership(msg.sender) works -Ownable.sol,transferOwnership,newOwner == 0,arg001,arg001 transferOwnership(0) works +Ownable.sol,transferOwnership,newOwner == 0,arg001,arg001 transferOwnership(0) reverts Ownable.sol,transferOwnership,newOwner == owner,arg002,arg002 transferOwnership(owner) works Controller.sol,configureController,newController == 0,arg003,"arg003 configureController(0, M) works" Controller.sol,configureController,newController == msg.sender,arg004,"arg004 configureController(msg.sender, M) works" From 8acd8e3c1e4cd4005d7225f55eb321ea4f2ae31c Mon Sep 17 00:00:00 2001 From: mirathewhite Date: Thu, 25 Oct 2018 11:44:00 -0400 Subject: [PATCH 33/74] create parallel travis test environments (#235) * create parallel travis test environments * fixed typo * fixed filepaths * fixed more paths * split up long running tests suites * added .js extension to all require statements * fixed require references --- .travis.yml | 13 ++++++++++++- test/{minting => }/ControllerTestUtils.js | 4 ++-- test/{minting => }/MintControllerUtils.js | 8 ++++---- test/{ => assert}/ABITests.test.js | 8 ++++---- test/{ => assert}/EventsTests.js | 6 +++--- test/{ => assert}/FiatTokenLegacy.test.js | 6 +++--- test/{ => assert}/Pausable.test.js | 4 ++-- test/{ => basic}/NegativeTests.js | 6 +++--- test/{ => basic}/PositiveTests.js | 6 +++--- test/{ => extended}/ExtendedPositiveTests.js | 6 +++--- test/minting/MintP0_ArgumentTests.js | 6 +++--- test/{minting => minting2}/MintControllerTests.js | 4 ++-- test/{minting => minting2}/MintP0_ABITests.js | 6 +++--- test/{minting => minting3}/MintP0_BasicTests.js | 4 ++-- test/{ => misc}/MiscTests.js | 6 +++--- test/{ => proxy}/ProxyNegativeTests.js | 6 +++--- test/{ => proxy}/ProxyPositiveTests.js | 8 ++++---- 17 files changed, 59 insertions(+), 48 deletions(-) rename test/{minting => }/ControllerTestUtils.js (94%) rename test/{minting => }/MintControllerUtils.js (91%) rename test/{ => assert}/ABITests.test.js (98%) rename test/{ => assert}/EventsTests.js (97%) rename test/{ => assert}/FiatTokenLegacy.test.js (99%) rename test/{ => assert}/Pausable.test.js (96%) rename test/{ => basic}/NegativeTests.js (99%) rename test/{ => basic}/PositiveTests.js (98%) rename test/{ => extended}/ExtendedPositiveTests.js (99%) rename test/{minting => minting2}/MintControllerTests.js (98%) rename test/{minting => minting2}/MintP0_ABITests.js (95%) rename test/{minting => minting3}/MintP0_BasicTests.js (99%) rename test/{ => misc}/MiscTests.js (99%) rename test/{ => proxy}/ProxyNegativeTests.js (97%) rename test/{ => proxy}/ProxyPositiveTests.js (98%) diff --git a/.travis.yml b/.travis.yml index 85696c4fa..588a8364c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,6 +11,17 @@ install: - npm install -g truffle@4.1.13 - yarn install --frozen-lockfile +env: + - TEST_SUITE=test/assert/* + - TEST_SUITE=test/basic/* + - TEST_SUITE=test/extended/* + - TEST_SUITE=test/minting/* + - TEST_SUITE=test/minting2/* + - TEST_SUITE=test/minting3/* + - TEST_SUITE=test/misc/* + - TEST_SUITE=test/proxy/* + script: - - yarn check --integrity && truffle compile && npm test + - "yarn check --integrity && truffle compile && npm run truffle-test $TEST_SUITE" + diff --git a/test/minting/ControllerTestUtils.js b/test/ControllerTestUtils.js similarity index 94% rename from test/minting/ControllerTestUtils.js rename to test/ControllerTestUtils.js index 8fe59693e..ba821cabd 100644 --- a/test/minting/ControllerTestUtils.js +++ b/test/ControllerTestUtils.js @@ -5,10 +5,10 @@ var Q = require('q'); var debugLogging = false; -var tokenUtils = require('./../TokenTestUtils'); +var tokenUtils = require('./TokenTestUtils.js'); var Controller = artifacts.require('./../minting/Controller'); -var AccountUtils = require('./../AccountUtils'); +var AccountUtils = require('./AccountUtils.js'); var Accounts = AccountUtils.Accounts; var setAccountDefault = AccountUtils.setAccountDefault; var checkState = AccountUtils.checkState; diff --git a/test/minting/MintControllerUtils.js b/test/MintControllerUtils.js similarity index 91% rename from test/minting/MintControllerUtils.js rename to test/MintControllerUtils.js index 64eb8d139..05999fa90 100644 --- a/test/minting/MintControllerUtils.js +++ b/test/MintControllerUtils.js @@ -1,16 +1,16 @@ var BigNumber = require('bignumber.js'); var bigZero = new BigNumber(0); -var tokenUtils = require('./../TokenTestUtils'); +var tokenUtils = require('./TokenTestUtils.js'); var initializeTokenWithProxy = tokenUtils.initializeTokenWithProxy; -var MintController = artifacts.require('./../minting/MintController'); -var AccountUtils = require('./../AccountUtils'); +var MintController = artifacts.require('./minting/MintController'); +var AccountUtils = require('./AccountUtils.js'); var Accounts = AccountUtils.Accounts; var checkState = AccountUtils.checkState; var getAccountState = AccountUtils.getAccountState; -var ControllerUtils = require('./ControllerTestUtils'); +var ControllerUtils = require('./ControllerTestUtils.js'); var checkControllerState = ControllerUtils.checkControllerState; function MintControllerState(owner, controllers, minterManager) { diff --git a/test/ABITests.test.js b/test/assert/ABITests.test.js similarity index 98% rename from test/ABITests.test.js rename to test/assert/ABITests.test.js index 21c2cde41..28693527d 100644 --- a/test/ABITests.test.js +++ b/test/assert/ABITests.test.js @@ -1,5 +1,5 @@ var Tx = require('ethereumjs-tx'); -var tokenUtils = require('./TokenTestUtils'); +var tokenUtils = require('./../TokenTestUtils.js'); var FiatToken = tokenUtils.FiatToken; var name = tokenUtils.name; var symbol = tokenUtils.symbol; @@ -17,11 +17,11 @@ var checkVariables = tokenUtils.checkVariables; var checkFailureIsExpected = tokenUtils.checkFailureIsExpected; var initializeTokenWithProxy = tokenUtils.initializeTokenWithProxy; -var AccountUtils = require('./AccountUtils'); +var AccountUtils = require('./../AccountUtils.js'); var Accounts = AccountUtils.Accounts; var AccountPrivateKeys = AccountUtils.AccountPrivateKeys; -var abiUtils = require('./ABIUtils'); +var abiUtils = require('./../ABIUtils.js'); var makeRawTransaction = abiUtils.makeRawTransaction; var sendRawTransaction = abiUtils.sendRawTransaction; var functionSignature = abiUtils.functionSignature; @@ -264,7 +264,7 @@ async function run_tests(newToken, accounts) { }); } -var testWrapper = require('./TestWrapper'); +var testWrapper = require('./../TestWrapper'); testWrapper.execute('FiatToken_ABIHackingTests', run_tests); module.exports = { diff --git a/test/EventsTests.js b/test/assert/EventsTests.js similarity index 97% rename from test/EventsTests.js rename to test/assert/EventsTests.js index 0d3c68c11..6549d0b93 100644 --- a/test/EventsTests.js +++ b/test/assert/EventsTests.js @@ -1,4 +1,4 @@ -var tokenUtils = require('./TokenTestUtils'); +var tokenUtils = require('./../TokenTestUtils.js'); var FiatToken = tokenUtils.FiatToken; var FiatTokenProxy = tokenUtils.FiatTokenProxy; @@ -28,7 +28,7 @@ var UpgradedFiatTokenNewFields = tokenUtils.UpgradedFiatTokenNewFields; var checkPauseEvent = tokenUtils.checkPauseEvent; var checkTransferEvents = tokenUtils.checkTransferEvents; -var AccountUtils = require('./AccountUtils'); +var AccountUtils = require('./../AccountUtils.js'); var Accounts = AccountUtils.Accounts; var amount = 100; @@ -140,7 +140,7 @@ async function run_tests(newToken, accounts) { }); } -var testWrapper = require('./TestWrapper'); +var testWrapper = require('./../TestWrapper'); testWrapper.execute('FiatToken_EventTests', run_tests); module.exports = { diff --git a/test/FiatTokenLegacy.test.js b/test/assert/FiatTokenLegacy.test.js similarity index 99% rename from test/FiatTokenLegacy.test.js rename to test/assert/FiatTokenLegacy.test.js index 01a039367..343efa67a 100644 --- a/test/FiatTokenLegacy.test.js +++ b/test/assert/FiatTokenLegacy.test.js @@ -1,4 +1,4 @@ -var tokenUtils = require('./TokenTestUtils'); +var tokenUtils = require('./../TokenTestUtils.js'); var name = tokenUtils.name; var symbol = tokenUtils.symbol; var currency = tokenUtils.currency; @@ -22,7 +22,7 @@ var UpgradedFiatToken = tokenUtils.UpgradedFiatToken; var FiatToken = tokenUtils.FiatToken; var getAdmin = tokenUtils.getAdmin; -var AccountUtils = require('./AccountUtils'); +var AccountUtils = require('./../AccountUtils.js'); var Accounts = AccountUtils.Accounts; // these tests are for reference and do not track side effects on all variables @@ -670,7 +670,7 @@ async function run_tests(newToken, accounts) { }); } -var testWrapper = require('./TestWrapper'); +var testWrapper = require('./../TestWrapper'); testWrapper.execute('FiatToken_LegacyTests', run_tests); module.exports = { diff --git a/test/Pausable.test.js b/test/assert/Pausable.test.js similarity index 96% rename from test/Pausable.test.js rename to test/assert/Pausable.test.js index adb7797e8..31f9da115 100644 --- a/test/Pausable.test.js +++ b/test/assert/Pausable.test.js @@ -1,11 +1,11 @@ var Tx = require('ethereumjs-tx'); var Pausable = artifacts.require('Pausable'); -var tokenUtils = require('./TokenTestUtils'); +var tokenUtils = require('./../TokenTestUtils.js'); var BigNumber = require('bignumber.js'); var expectRevert = tokenUtils.expectRevert; -var AccountUtils = require('./AccountUtils'); +var AccountUtils = require('./../AccountUtils.js'); var Accounts = AccountUtils.Accounts; const should = require('chai') diff --git a/test/NegativeTests.js b/test/basic/NegativeTests.js similarity index 99% rename from test/NegativeTests.js rename to test/basic/NegativeTests.js index 8ff4d6911..062e63d8d 100644 --- a/test/NegativeTests.js +++ b/test/basic/NegativeTests.js @@ -1,4 +1,4 @@ -var tokenUtils = require('./TokenTestUtils'); +var tokenUtils = require('./../TokenTestUtils.js'); var BigNumber = require('bignumber.js'); var assertDiff = require('assert-diff'); assertDiff.options.strict = true; @@ -19,7 +19,7 @@ var upgradeTo = tokenUtils.upgradeTo; var UpgradedFiatToken = tokenUtils.UpgradedFiatToken; var FiatToken = tokenUtils.FiatToken; -var AccountUtils = require('./AccountUtils'); +var AccountUtils = require('./../AccountUtils.js'); var Accounts = AccountUtils.Accounts; var amount = 100; @@ -671,7 +671,7 @@ async function run_tests(newToken, accounts) { }); } -var testWrapper = require('./TestWrapper'); +var testWrapper = require('./../TestWrapper'); testWrapper.execute('FiatToken_NegativeTests', run_tests); module.exports = { diff --git a/test/PositiveTests.js b/test/basic/PositiveTests.js similarity index 98% rename from test/PositiveTests.js rename to test/basic/PositiveTests.js index 995459132..045b18f49 100644 --- a/test/PositiveTests.js +++ b/test/basic/PositiveTests.js @@ -1,4 +1,4 @@ -var tokenUtils = require('./TokenTestUtils');; +var tokenUtils = require('./../TokenTestUtils.js');; var BigNumber = require('bignumber.js'); var assertDiff = require('assert-diff'); assertDiff.options.strict = true; @@ -15,7 +15,7 @@ var decimals = tokenUtils.decimals; var initializeTokenWithProxy = tokenUtils.initializeTokenWithProxy; var FiatToken = tokenUtils.FiatToken; -var AccountUtils = require('./AccountUtils'); +var AccountUtils = require('./../AccountUtils.js'); var Accounts = AccountUtils.Accounts; var amount = 100; @@ -262,7 +262,7 @@ async function run_tests(newToken, accounts) { } -var testWrapper = require('./TestWrapper'); +var testWrapper = require('./../TestWrapper'); testWrapper.execute('FiatToken_PositiveTests', run_tests); module.exports = { diff --git a/test/ExtendedPositiveTests.js b/test/extended/ExtendedPositiveTests.js similarity index 99% rename from test/ExtendedPositiveTests.js rename to test/extended/ExtendedPositiveTests.js index 742bff571..0eba21532 100644 --- a/test/ExtendedPositiveTests.js +++ b/test/extended/ExtendedPositiveTests.js @@ -1,4 +1,4 @@ -var tokenUtils = require('./TokenTestUtils'); +var tokenUtils = require('./../TokenTestUtils.js'); var BigNumber = require('bignumber.js'); var assertDiff = require('assert-diff'); assertDiff.options.strict = true; @@ -17,7 +17,7 @@ var UpgradedFiatToken = tokenUtils.UpgradedFiatToken; var FiatToken = tokenUtils.FiatToken; var upgradeTo = tokenUtils.upgradeTo; -var AccountUtils = require('./AccountUtils'); +var AccountUtils = require('./../AccountUtils.js'); var Accounts = AccountUtils.Accounts; var amount = 100; @@ -411,7 +411,7 @@ async function run_tests(newToken, accounts) { } -var testWrapper = require('./TestWrapper'); +var testWrapper = require('./../TestWrapper'); testWrapper.execute('FiatToken_ExtendedPositiveTests', run_tests); module.exports = { diff --git a/test/minting/MintP0_ArgumentTests.js b/test/minting/MintP0_ArgumentTests.js index e8690edd7..cac6a38a0 100644 --- a/test/minting/MintP0_ArgumentTests.js +++ b/test/minting/MintP0_ArgumentTests.js @@ -5,7 +5,7 @@ var MasterMinter = artifacts.require('minting/MasterMinter'); var FiatToken = artifacts.require('FiatTokenV1'); var BigNumber = require('bignumber.js'); -var tokenUtils = require('./../TokenTestUtils'); +var tokenUtils = require('./../TokenTestUtils.js'); var checkMINTp0 = tokenUtils.checkMINTp0; var expectRevert = tokenUtils.expectRevert; var expectJump = tokenUtils.expectJump; @@ -14,7 +14,7 @@ var maxAmount = tokenUtils.maxAmount; var clone = require('clone'); -var mintUtils = require('./MintControllerUtils.js'); +var mintUtils = require('./../MintControllerUtils.js'); var AccountUtils = require('./../AccountUtils.js'); var Accounts = AccountUtils.Accounts; var getAccountState = AccountUtils.getAccountState; @@ -97,7 +97,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { await mintController.removeController(zeroAddress, {from: Accounts.mintOwnerAccount}); await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); actualMinter = await mintController.controllers(zeroAddress); - assert.equal(zeroAddress, zeroAddress); + assert.equal(actualMinter, zeroAddress); }); it('arg008 setMinterManager(0) works', async function () { diff --git a/test/minting/MintControllerTests.js b/test/minting2/MintControllerTests.js similarity index 98% rename from test/minting/MintControllerTests.js rename to test/minting2/MintControllerTests.js index d1adc8946..4a27c6bec 100644 --- a/test/minting/MintControllerTests.js +++ b/test/minting2/MintControllerTests.js @@ -1,14 +1,14 @@ var MintController = artifacts.require('minting/MintController'); var BigNumber = require('bignumber.js'); -var tokenUtils = require('./../TokenTestUtils'); +var tokenUtils = require('./../TokenTestUtils.js'); var checkMINTp0 = tokenUtils.checkMINTp0; var expectRevert = tokenUtils.expectRevert; var bigZero = tokenUtils.bigZero; var clone = require('clone'); -var mintUtils = require('./MintControllerUtils.js'); +var mintUtils = require('./../MintControllerUtils.js'); var AccountUtils = require('./../AccountUtils.js'); var Accounts = AccountUtils.Accounts; var MintControllerState = AccountUtils.MintControllerState; diff --git a/test/minting/MintP0_ABITests.js b/test/minting2/MintP0_ABITests.js similarity index 95% rename from test/minting/MintP0_ABITests.js rename to test/minting2/MintP0_ABITests.js index adb627460..d51edcf33 100644 --- a/test/minting/MintP0_ABITests.js +++ b/test/minting2/MintP0_ABITests.js @@ -3,7 +3,7 @@ var MasterMinter = artifacts.require('minting/MasterMinter'); var FiatToken = artifacts.require('FiatTokenV1'); var BigNumber = require('bignumber.js'); -var tokenUtils = require('./../TokenTestUtils'); +var tokenUtils = require('./../TokenTestUtils.js'); var checkMINTp0 = tokenUtils.checkMINTp0; var expectRevert = tokenUtils.expectRevert; var expectJump = tokenUtils.expectJump; @@ -12,7 +12,7 @@ var maxAmount = tokenUtils.maxAmount; var clone = require('clone'); -var mintUtils = require('./MintControllerUtils.js'); +var mintUtils = require('./../MintControllerUtils.js'); var AccountUtils = require('./../AccountUtils.js'); var Accounts = AccountUtils.Accounts; var AccountPrivateKeys = AccountUtils.AccountPrivateKeys; @@ -23,7 +23,7 @@ var checkMintControllerState = mintUtils.checkMintControllerState; var zeroAddress = "0x0000000000000000000000000000000000000000"; -var abiUtils = require('./../ABIUtils'); +var abiUtils = require('./../ABIUtils.js'); var makeRawTransaction = abiUtils.makeRawTransaction; var sendRawTransaction = abiUtils.sendRawTransaction; var msgData = abiUtils.msgData; diff --git a/test/minting/MintP0_BasicTests.js b/test/minting3/MintP0_BasicTests.js similarity index 99% rename from test/minting/MintP0_BasicTests.js rename to test/minting3/MintP0_BasicTests.js index 09f2456cb..57a1de5c7 100644 --- a/test/minting/MintP0_BasicTests.js +++ b/test/minting3/MintP0_BasicTests.js @@ -3,7 +3,7 @@ var MasterMinter = artifacts.require('minting/MasterMinter'); var FiatToken = artifacts.require('FiatTokenV1'); var BigNumber = require('bignumber.js'); -var tokenUtils = require('./../TokenTestUtils'); +var tokenUtils = require('./../TokenTestUtils.js'); var checkMINTp0 = tokenUtils.checkMINTp0; var expectRevert = tokenUtils.expectRevert; var expectJump = tokenUtils.expectJump; @@ -12,7 +12,7 @@ var maxAmount = tokenUtils.maxAmount; var clone = require('clone'); -var mintUtils = require('./MintControllerUtils.js'); +var mintUtils = require('./../MintControllerUtils.js'); var AccountUtils = require('./../AccountUtils.js'); var Accounts = AccountUtils.Accounts; var getAccountState = AccountUtils.getAccountState; diff --git a/test/MiscTests.js b/test/misc/MiscTests.js similarity index 99% rename from test/MiscTests.js rename to test/misc/MiscTests.js index f70306558..ef4060db5 100644 --- a/test/MiscTests.js +++ b/test/misc/MiscTests.js @@ -1,6 +1,6 @@ var FiatTokenProxy = artifacts.require('FiatTokenProxy'); -var tokenUtils = require('./TokenTestUtils');; +var tokenUtils = require('./../TokenTestUtils.js');; var BigNumber = require('bignumber.js'); var assertDiff = require('assert-diff'); assertDiff.options.strict = true; @@ -19,7 +19,7 @@ var initializeTokenWithProxy = tokenUtils.initializeTokenWithProxy; var getInitializedV1 = tokenUtils.getInitializedV1; var FiatToken = tokenUtils.FiatToken; -var AccountUtils = require('./AccountUtils'); +var AccountUtils = require('./../AccountUtils.js'); var Accounts = AccountUtils.Accounts; var maxAmount = "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"; @@ -552,7 +552,7 @@ async function run_tests(newToken, accounts) { }); } -var testWrapper = require('./TestWrapper'); +var testWrapper = require('./../TestWrapper'); testWrapper.execute('FiatToken_MiscTests', run_tests); module.exports = { diff --git a/test/ProxyNegativeTests.js b/test/proxy/ProxyNegativeTests.js similarity index 97% rename from test/ProxyNegativeTests.js rename to test/proxy/ProxyNegativeTests.js index f3c0eac81..9f6150e57 100644 --- a/test/ProxyNegativeTests.js +++ b/test/proxy/ProxyNegativeTests.js @@ -1,4 +1,4 @@ -var tokenUtils = require('./TokenTestUtils');; +var tokenUtils = require('./../TokenTestUtils');; var BigNumber = require('bignumber.js'); var assertDiff = require('assert-diff'); assertDiff.options.strict = true; @@ -20,7 +20,7 @@ var FiatToken = tokenUtils.FiatToken; var UpgradedFiatToken = tokenUtils.UpgradedFiatToken; var UpgradedFiatTokenNewFields = tokenUtils.UpgradedFiatTokenNewFields; -var AccountUtils = require('./AccountUtils'); +var AccountUtils = require('./../AccountUtils'); var Accounts = AccountUtils.Accounts; var amount = 100; @@ -135,7 +135,7 @@ async function run_tests(newToken, accounts) { } -var testWrapper = require('./TestWrapper'); +var testWrapper = require('./../TestWrapper'); testWrapper.execute('FiatToken_ProxyNegativeTests', run_tests); module.exports = { diff --git a/test/ProxyPositiveTests.js b/test/proxy/ProxyPositiveTests.js similarity index 98% rename from test/ProxyPositiveTests.js rename to test/proxy/ProxyPositiveTests.js index b1b4e6210..c90a8195f 100644 --- a/test/ProxyPositiveTests.js +++ b/test/proxy/ProxyPositiveTests.js @@ -1,4 +1,4 @@ -var tokenUtils = require('./TokenTestUtils');; +var tokenUtils = require('./../TokenTestUtils');; var BigNumber = require('bignumber.js'); var assertDiff = require('assert-diff'); assertDiff.options.strict = true; @@ -23,11 +23,11 @@ var UpgradedFiatTokenNewFields = tokenUtils.UpgradedFiatTokenNewFields; var UpgradedFiatTokenNewFieldsNewLogic = tokenUtils.UpgradedFiatTokenNewFieldsNewLogic; var getAdmin = tokenUtils.getAdmin; -var abiUtils = require('./ABIUtils'); +var abiUtils = require('./../ABIUtils'); var makeRawTransaction = abiUtils.makeRawTransaction; var sendRawTransaction = abiUtils.sendRawTransaction; -var AccountUtils = require('./AccountUtils'); +var AccountUtils = require('./../AccountUtils'); var Accounts = AccountUtils.Accounts; var AccountPrivateKeys = AccountUtils.AccountPrivateKeys; @@ -306,7 +306,7 @@ async function run_tests(newToken, accounts) { } -var testWrapper = require('./TestWrapper'); +var testWrapper = require('./../TestWrapper'); testWrapper.execute('FiatToken_ProxyPositiveTests', run_tests); module.exports = { From f7f81245706ad2e94727ac0b858a144fd4fb5cbe Mon Sep 17 00:00:00 2001 From: mirathewhite Date: Thu, 10 Jan 2019 17:12:24 -0500 Subject: [PATCH 34/74] Added error msgs to require statements in minting/* contracts (#242) * Added error msgs to require statements in minting/* contracts * migrating to truffle 5, MINT unit tests use expectError whenever possible * removing comments * updating yarn.lock with truffle 5 dependency * migrated test/assert/* to truffle 5, checkvariables uses hex representation of BN for comparison, convert all addresses to uppercase prior to comparison, change some function calls to comply with web3js 1.0.0 api. * migrated remaining unit tests to truffle 5 * updated yarn.lock * fixed package name from BN.js to bn.js * updating to truffle 5.0.0 in .travis.yml * updating yarn.lock * changed contract error messages and address comparison in tests * fixed compile errors * replaced assert.true with assert.isTrue * turned addressEquals into an assert and added error message * removed assert.true and added addressNotEquals * fixed missing import of addressEquals and bad zeroAddress * fixed bug in expectError * fixed bug in expectRevert * removed error message test because results inconsistent --- .travis.yml | 2 +- contracts/minting/Controller.sol | 4 +- contracts/minting/MintController.sol | 2 +- migrations/2_deploy_usdc.js | 6 +- package.json | 2 + test/ABIUtils.js | 11 +- test/AccountUtils.js | 44 ++++-- test/ControllerTestUtils.js | 4 - test/MintControllerUtils.js | 4 +- test/TokenTestUtils.js | 185 ++++++++++++++----------- test/assert/ABITests.test.js | 145 +++++++------------ test/assert/FiatTokenLegacy.test.js | 111 +++++++-------- test/assert/Pausable.test.js | 7 +- test/basic/NegativeTests.js | 176 +++++++++++------------ test/basic/PositiveTests.js | 64 ++++----- test/extended/ExtendedPositiveTests.js | 19 ++- test/minting/MintP0_ArgumentTests.js | 21 +-- test/minting2/MintControllerTests.js | 21 +-- test/minting2/MintP0_ABITests.js | 1 - test/minting3/MintP0_BasicTests.js | 90 ++++++------ test/misc/MiscTests.js | 183 ++++++++++++------------ test/proxy/ProxyNegativeTests.js | 22 +-- test/proxy/ProxyPositiveTests.js | 66 ++++----- truffle.js | 5 + yarn.lock | 4 + 25 files changed, 602 insertions(+), 597 deletions(-) diff --git a/.travis.yml b/.travis.yml index 588a8364c..7880617ad 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ before_install: install: - - npm install -g truffle@4.1.13 + - npm install -g truffle@5.0.0 - yarn install --frozen-lockfile env: diff --git a/contracts/minting/Controller.sol b/contracts/minting/Controller.sol index 029ec98fd..9a7b36f47 100644 --- a/contracts/minting/Controller.sol +++ b/contracts/minting/Controller.sol @@ -40,7 +40,7 @@ contract Controller is Ownable { * @dev ensure that the caller is the controller of a non-zero worker address */ modifier onlyController() { - require(controllers[msg.sender] != address(0)); + require(controllers[msg.sender] != address(0), "The value of controller[msg.sender] must be non-zero."); _; } @@ -54,7 +54,7 @@ contract Controller is Ownable { * Argument _worker must not be 0x00, call removeController(_controller) instead. */ function configureController(address _controller, address _worker) onlyOwner public returns (bool) { - require(_worker != address(0)); + require(_worker != address(0), "Worker must be a non-zero address."); controllers[_controller] = _worker; emit ControllerConfigured(_controller, _worker); return true; diff --git a/contracts/minting/MintController.sol b/contracts/minting/MintController.sol index ad49f4587..6113a1e88 100644 --- a/contracts/minting/MintController.sol +++ b/contracts/minting/MintController.sol @@ -91,7 +91,7 @@ contract MintController is Controller { */ function incrementMinterAllowance(uint256 allowanceIncrement) onlyController public returns (bool) { address minter = controllers[msg.sender]; - require(minterManager.isMinter(minter)); + require(minterManager.isMinter(minter), "Can only increment allowance for minters in minterManager."); uint256 currentAllowance = minterManager.minterAllowance(minter); uint256 newAllowance = currentAllowance.add(allowanceIncrement); diff --git a/migrations/2_deploy_usdc.js b/migrations/2_deploy_usdc.js index f02618921..60394b371 100644 --- a/migrations/2_deploy_usdc.js +++ b/migrations/2_deploy_usdc.js @@ -52,8 +52,10 @@ module.exports = function(deployer, network, accounts) { console.log("initializing proxy"); // Pretend that the proxy address is a FiatTokenV1 // this is fine because the proxy will forward all the calls to the FiatTokenV1 impl - tokenProxy = FiatTokenV1.at(tokenProxy.address); - return tokenProxy.initialize( + return FiatTokenV1.at(tokenProxy.address); + }) + .then(function(tokenProxyAsFiatTokenV1){ + return tokenProxyAsFiatTokenV1.initialize( "USD//C", "USDC", "USD", diff --git a/package.json b/package.json index c4674aa05..15c587518 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "dependencies": { "assert-diff": "^1.2.6", "bignumber.js": "6.0.0", + "bn.js": "^4.11.8", "clone": "2.1.2", "csv-parse": "3.0.0", "ethereumjs-abi": "^0.6.5", @@ -43,6 +44,7 @@ "zos-lib": "1.3.0" }, "devDependencies": { + "bn-chai": "^1.0.1", "chai": "^4.1.2", "chai-as-promised": "^7.1.1", "chai-bignumber": "^2.0.2", diff --git a/test/ABIUtils.js b/test/ABIUtils.js index 5b91ad859..8ea39ba7e 100644 --- a/test/ABIUtils.js +++ b/test/ABIUtils.js @@ -1,10 +1,11 @@ var Tx = require('ethereumjs-tx'); -function makeRawTransaction(msgData, msgSender, hexPrivateKey, contractAddress) { +async function makeRawTransaction(msgData, msgSender, hexPrivateKey, contractAddress) { + var nonce = web3.utils.toHex(await web3.eth.getTransactionCount(msgSender)); var tx = new Tx({ - nonce: web3.toHex(web3.eth.getTransactionCount(msgSender)), - gasPrice: web3.toHex(web3.toWei('20', 'gwei')), + nonce: nonce, + gasPrice: web3.utils.toHex(web3.utils.toWei('20', 'gwei')), gasLimit: 1000000, to: contractAddress, value: 0, @@ -18,7 +19,7 @@ function makeRawTransaction(msgData, msgSender, hexPrivateKey, contractAddress) function sendRawTransaction(raw) { return new Promise(function (resolve, reject) { - web3.eth.sendRawTransaction(raw, function (err, transactionHash) { + web3.eth.sendSignedTransaction(raw, function (err, transactionHash) { if (err !== null) return reject(err); resolve(transactionHash); }); @@ -26,7 +27,7 @@ function sendRawTransaction(raw) { } function functionSignature(methodName) { - return web3.sha3(methodName).substr(0, 2 + 8); + return web3.utils.sha3(methodName).substr(0, 2 + 8); } function encodeAddress(address) { diff --git a/test/AccountUtils.js b/test/AccountUtils.js index 98a09d202..1fd8c1d8b 100644 --- a/test/AccountUtils.js +++ b/test/AccountUtils.js @@ -8,21 +8,17 @@ 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.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] - controller1Account: "0x855fa758c77d68a04990e992aa4dcdef899f654a", // accounts[11] -// controller2Account: "0xfa2435eacf10ca62ae6787ba2fb044f8733ee843", // accounts[12] -// issuerOwnerAccount: "0x64e078a8aa15a41b85890265648e965de686bae6", // accounts[13] - proxyOwnerAccount: "0x2f560290fef1b3ada194b6aa9c40aa71f8e95598", // accounts[14] + deployerAccount: "0x90F8BF6A479F320EAD074411A4B0E7944EA8C9C1", // accounts[0] + arbitraryAccount: "0xFFCF8FDEE72AC11B5C542428B35EEF5769C409F0", // accounts[1] + 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] + controller1Account: "0x855FA758C77D68A04990E992AA4DCDEF899F654A", // accounts[11] + proxyOwnerAccount: "0x2F560290FEF1B3ADA194B6AA9C40AA71F8E95598", // accounts[14] }; // named list of known private keys @@ -44,6 +40,22 @@ var AccountPrivateKeys = { proxyOwnerAccount: "21d7212f3b4e5332fd465877b64926e3532653e2798a11255a46f533852dfe46", // accounts[14] }; +function addressEquals(address1, address2) { + if (address1.toUpperCase() == address2.toUpperCase()) { + return true; + } else { + assert.isFalse("expect " + address1 + " to equal " + address2); + } +} + +function addressNotEquals(address1, address2) { + if (address1.toUpperCase() != address2.toUpperCase()) { + return true; + } else { + assert.isFalse("expect " + address1 + " to not equal " + address2); + } +} + // Returns an object with all named account values set to the default value // e.g sets {owner: 0, minter: 0,...} function setAccountDefault(accounts, defaultValue) { @@ -152,4 +164,6 @@ module.exports = { buildExpectedPartialState: buildExpectedPartialState, checkState: checkState, getAccountState: getAccountState, + addressEquals: addressEquals, + addressNotEquals: addressNotEquals, } \ No newline at end of file diff --git a/test/ControllerTestUtils.js b/test/ControllerTestUtils.js index ba821cabd..4102536bc 100644 --- a/test/ControllerTestUtils.js +++ b/test/ControllerTestUtils.js @@ -1,12 +1,8 @@ -var BigNumber = require('bignumber.js'); var Q = require('q'); // set to true to enable verbose logging in the tests var debugLogging = false; - -var tokenUtils = require('./TokenTestUtils.js'); - var Controller = artifacts.require('./../minting/Controller'); var AccountUtils = require('./AccountUtils.js'); var Accounts = AccountUtils.Accounts; diff --git a/test/MintControllerUtils.js b/test/MintControllerUtils.js index 05999fa90..8fc2e4b0a 100644 --- a/test/MintControllerUtils.js +++ b/test/MintControllerUtils.js @@ -1,7 +1,5 @@ -var BigNumber = require('bignumber.js'); -var bigZero = new BigNumber(0); - var tokenUtils = require('./TokenTestUtils.js'); +var bigZero = tokenUtils.bigZero; var initializeTokenWithProxy = tokenUtils.initializeTokenWithProxy; var MintController = artifacts.require('./minting/MintController'); diff --git a/test/TokenTestUtils.js b/test/TokenTestUtils.js index ccfe78e36..750e6032b 100644 --- a/test/TokenTestUtils.js +++ b/test/TokenTestUtils.js @@ -5,11 +5,13 @@ var clone = require('clone'); var name = 'Sample Fiat Token'; var symbol = 'C-USD'; var currency = 'USD'; -var decimals = 2; +var BN = require('bn.js'); var BigNumber = require('bignumber.js'); var trueInStorageFormat = "0x01"; -var bigZero = new BigNumber(0); -var bigHundred = new BigNumber(100); +var decimals = newBigNumber(10); +var bigZero = newBigNumber(0); +var zeroAddress = '0x' + bigZero.toString(16, 40); +var bigHundred = newBigNumber(100); var maxAmount = "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"; var assertDiff = require('assert-diff'); assertDiff.options.strict = true; @@ -26,34 +28,36 @@ var setAccountDefault = AccountUtils.setAccountDefault; var recursiveSetAccountDefault = AccountUtils.recursiveSetAccountDefault; var checkState = AccountUtils.checkState; var getAccountState = AccountUtils.getAccountState; +var addressEquals = AccountUtils.addressEquals; // TODO: test really big numbers Does this still have to be done?? var adminSlot = "0x10d6a54a4754c8869d6886b5f5d7fbfa5b4522237ea5c60d11bc4e7a1ff9390b"; var implSlot = "0x7050c9e0f4ca769c69bd3a8ef740bc37934f8e2c036e5a723fd8ee048ed3f8c3"; -const should = require('chai') - .use(require('chai-as-promised')) - .use(require('chai-bignumber')(BigNumber)) - .should(); - -var BigNumber = require('bignumber.js'); // set to true to enable verbose logging in the tests var debugLogging = false; +// Returns a new BN object +function newBigNumber(value) { + var hex = new BigNumber(value).toString(16); + return new BN(hex, 16); +} + + function calculateFeeAmount(amount) { return Math.floor((fee / feeBase) * amount); } function checkMinterConfiguredEvent(configureMinterEvent, minter, minterAllowedAmount) { assert.equal(configureMinterEvent.logs[0].event, 'MinterConfigured') - assert.equal(configureMinterEvent.logs[0].args.minter, minter) + assert.isTrue(addressEquals(configureMinterEvent.logs[0].args.minter, minter)); assert.equal(configureMinterEvent.logs[0].args.minterAllowedAmount, minterAllowedAmount) } function checkMinterRemovedEvent(minterRemovedEvent, minter) { assert.equal(minterRemovedEvent.logs[0].event, 'MinterRemoved') - assert.equal(minterRemovedEvent.logs[0].args.oldMinter, minter); + assert.isTrue(addressEquals(minterRemovedEvent.logs[0].args.oldMinter, minter)); } function checkTransferEventsWithFee(transferEvent, from, to, value, feeAmount) { @@ -62,77 +66,77 @@ function checkTransferEventsWithFee(transferEvent, from, to, value, feeAmount) { assert.equal(transferEvent.logs[0].args.feeAccount, feeAccount); assert.equal(transferEvent.logs[0].args.feeAmount, feeAmount); assert.equal(transferEvent.logs[1].event, 'Transfer'); - assert.equal(transferEvent.logs[1].args.from, from); - assert.equal(transferEvent.logs[1].args.to, to); + assert.isTrue(addressEquals(transferEvent.logs[1].args.from, from)); + assert.isTrue(addressEquals(transferEvent.logs[1].args.to, to)); assert.equal(transferEvent.logs[1].args.value, value); } function checkTransferEvents(transferEvent, from, to, value) { assert.equal(transferEvent.logs[0].event, 'Transfer'); - assert.equal(transferEvent.logs[0].args.from, from); - assert.equal(transferEvent.logs[0].args.to, to); + assert.isTrue(addressEquals(transferEvent.logs[0].args.from, from)); + assert.isTrue(addressEquals(transferEvent.logs[0].args.to, to)); assert.equal(transferEvent.logs[0].args.value, value); } function checkApprovalEvent(approvalEvent, approver, spender, value) { assert.equal(approvalEvent.logs[0].event, 'Approval'); - assert.equal(approvalEvent.logs[0].args.owner, approver); - assert.equal(approvalEvent.logs[0].args.spender, spender); + assert.isTrue(addressEquals(approvalEvent.logs[0].args.owner, approver)); + assert.isTrue(addressEquals(approvalEvent.logs[0].args.spender, spender)); assert.equal(approvalEvent.logs[0].args.value, value); } function checkBurnEvent(burnEvent, burner, amount) { assert.equal(burnEvent.logs[0].event, 'Burn'); - assert.equal(burnEvent.logs[0].args.burner, burner); - assert.equal(burnEvent.logs[0].args.amount, amount); + assert.isTrue(addressEquals(burnEvent.logs[0].args.burner, burner)); + assert.isTrue(addressEquals(burnEvent.logs[0].args.amount, amount)); } function checkBlacklistEvent(blacklistEvent, account) { assert.equal(blacklistEvent.logs[0].event, 'Blacklisted'); - assert.equal(blacklistEvent.logs[0].args._account, account); + assert.isTrue(addressEquals(blacklistEvent.logs[0].args._account, account)); } function checkUnblacklistEvent(unblacklistEvent, account) { assert.equal(unblacklistEvent.logs[0].event, 'UnBlacklisted'); - assert.equal(unblacklistEvent.logs[0].args._account, account); + assert.isTrue(addressEquals(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); + assert.isTrue(addressEquals(blacklisterChangedEvent.logs[0].args.newBlacklister, blacklister)); } function checkPauserChangedEvent(pauserChangedEvent, pauser) { assert.equal(pauserChangedEvent.logs[0].event, 'PauserChanged'); - assert.equal(pauserChangedEvent.logs[0].args.newAddress, pauser); + assert.isTrue(addressEquals(pauserChangedEvent.logs[0].args.newAddress, pauser)); } function checkTransferOwnershipEvent(transferOwnershipEvent, previousOwner, newOwner) { assert.equal(transferOwnershipEvent.logs[0].event, 'OwnershipTransferred'); - assert.equal(transferOwnershipEvent.logs[0].args.previousOwner, previousOwner) - assert.equal(transferOwnershipEvent.logs[0].args.newOwner, newOwner); + assert.isTrue(addressEquals(transferOwnershipEvent.logs[0].args.previousOwner, previousOwner)) + assert.isTrue(addressEquals(transferOwnershipEvent.logs[0].args.newOwner, newOwner)); } function checkUpdateMasterMinterEvent(checkUpdateMasterMinterEvent, newMasterMinter) { assert.equal(checkUpdateMasterMinterEvent.logs[0].event, 'MasterMinterChanged'); - assert.equal(checkUpdateMasterMinterEvent.logs[0].args.newMasterMinter, newMasterMinter); + assert.isTrue(addressEquals(checkUpdateMasterMinterEvent.logs[0].args.newMasterMinter, newMasterMinter)); } function checkAdminChangedEvent(adminChangedEvent, previousAdmin, newAdmin) { assert.equal(adminChangedEvent.logs[0].event, 'AdminChanged') - assert.equal(adminChangedEvent.logs[0].args.previousAdmin, previousAdmin); - assert.equal(adminChangedEvent.logs[0].args.newAdmin, newAdmin); + assert.isTrue(addressEquals(adminChangedEvent.logs[0].args.previousAdmin, previousAdmin)); + assert.isTrue(addressEquals(adminChangedEvent.logs[0].args.newAdmin, newAdmin)); } function checkUpgradeEvent(upgradeEvent, implementation) { assert.equal(upgradeEvent.logs[0].event, 'Upgraded'); - assert.equal(upgradeEvent.logs[0].args.implementation, implementation); + assert.isTrue(addressEquals(upgradeEvent.logs[0].args.implementation, implementation)); } function checkTransferProxyOwnershipEvent(transferProxyOwnershipEvent, previousOwner, newOwner) { assert.equal(transferProxyOwnershipEvent.logs[0].event, 'ProxyOwnershipTransferred'); - assert.equal(transferProxyOwnershipEvent.logs[0].args.previousOwner, previousOwner); - assert.equal(transferProxyOwnershipEvent.logs[0].args.newOwner, newOwner); + assert.isTrue(addressEquals(transferProxyOwnershipEvent.logs[0].args.previousOwner, previousOwner)); + assert.isTrue(addressEquals(transferProxyOwnershipEvent.logs[0].args.newOwner, newOwner)); } function checkPauseEvent(pause) { @@ -146,14 +150,14 @@ function checkUnpauseEvent(unpause) { function checkMintEvent(minting, to, amount, minter) { // Mint Event assert.equal(minting.logs[0].event, 'Mint'); - assert.equal(minting.logs[0].args.minter, minter); - assert.equal(minting.logs[0].args.to, to); + assert.isTrue(addressEquals(minting.logs[0].args.minter, minter)); + assert.isTrue(addressEquals(minting.logs[0].args.to, to)); assert.equal(minting.logs[0].args.amount, amount); // Transfer from 0 Event assert.equal(minting.logs[1].event, 'Transfer'); - assert.equal(minting.logs[1].args.from, 0); - assert.equal(minting.logs[1].args.to, to); + assert.isTrue(addressEquals(minting.logs[1].args.from, zeroAddress)); + assert.isTrue(addressEquals(minting.logs[1].args.to, to)); assert.equal(minting.logs[1].args.value, amount); } @@ -161,13 +165,13 @@ function checkMintEvent(minting, to, amount, minter) { function checkBurnEvents(burning, amount, burner) { // Burn Event assert.equal(burning.logs[0].event, 'Burn'); - assert.equal(burning.logs[0].args.burner, burner); + assert.isTrue(addressEquals(burning.logs[0].args.burner, burner)); assert.equal(burning.logs[0].args.amount, amount); // Transfer to 0 Event assert.equal(burning.logs[1].event, 'Transfer'); - assert.equal(burning.logs[1].args.from, burner); - assert.equal(burning.logs[1].args.to, 0); + assert.isTrue(addressEquals(burning.logs[1].args.from, burner)); + assert.isTrue(addressEquals(burning.logs[1].args.to, zeroAddress)); assert.equal(burning.logs[1].args.value, amount); } @@ -176,7 +180,7 @@ var fiatTokenEmptyState = { "name": name, "symbol": symbol, "currency": currency, - "decimals": new BigNumber(decimals), + "decimals": decimals, "masterMinter": Accounts.masterMinterAccount, "pauser": Accounts.pauserAccount, "blacklister" : Accounts.blacklisterAccount, @@ -216,6 +220,23 @@ function buildExpectedState(token, customVars) { return expectedState; } +// Replaces all BN objects with 32 character hex strings +function mapBNToHex(state) { + var result = {}; + for (var name in state) { + if(BN.isBN(state[name])) { + result[name] = web3.utils.toHex(state[name]); + } else if(typeof state[name] == 'object') { + result[name] = mapBNToHex(state[name]); + } else if(typeof state[name] == 'string' && state[name].substring(0,2)=='0x') { + result[name] = state[name].toUpperCase(); + } else { + result[name] = state[name]; + } + } + return result; +} + // For testing variance of specific variables from their default values. // customVars is an array of objects of the form, // {'variable': , 'expectedValue': } @@ -229,12 +250,13 @@ async function checkVariables(_tokens, _customVars) { var token = _tokens[n]; var customVars = _customVars[n]; - let expectedState = buildExpectedState(token, customVars); + let expectedState = mapBNToHex(buildExpectedState(token, customVars)); + let actualState = mapBNToHex(await getActualState(token)); if (debugLogging) { console.log(util.inspect(expectedState, { showHidden: false, depth: null })) + console.log(util.inspect(actualState, { showHidden: false, depth: null })) } - let actualState = await getActualState(token); assertDiff.deepEqual(actualState, expectedState, "difference between expected and actual state"); // Check that sum of individual balances equals totalSupply @@ -242,10 +264,10 @@ async function checkVariables(_tokens, _customVars) { var balanceSum = bigZero; var x; for (x = 0; x < accounts.length; x++) { - balanceSum = balanceSum.plus(new BigNumber(await token.balanceOf(accounts[x]))); + balanceSum = balanceSum.add(await token.balanceOf(accounts[x])); } - var totalSupply = new BigNumber(await token.totalSupply()) - assert(balanceSum.isEqualTo(totalSupply), "sum of balances is not equal to totalSupply"); + var totalSupply = newBigNumber(await token.totalSupply()) + assert(balanceSum.cmp(totalSupply)==0, "sum of balances is not equal to totalSupply"); } } @@ -340,7 +362,7 @@ async function getActualState(token) { async function setMinter(token, minter, amount) { let update = await token.configureMinter(minter, amount, { from: Accounts.masterMinterAccount }); assert.equal(update.logs[0].event, 'MinterConfigured'); - assert.equal(update.logs[0].args.minter, minter); + assert.isTrue(addressEquals(update.logs[0].args.minter, minter)); assert.equal(update.logs[0].args.minterAllowedAmount, amount); let minterAllowance = await token.minterAllowance(minter); @@ -367,7 +389,8 @@ async function mintRaw(token, to, amount, minter) { /* let totalSupply = await token.totalSupply(); totalSupply.should.be.bignumber.equal(initialTotalSupply); let minterAllowance = await token.minterAllowance(minter); - assert.isTrue(new BigNumber(initialMinterAllowance).minus(new BigNumber(amount)).isEqualTo(new BigNumber(minterAllowance)));*/ + assert.isTrue(newBigNumber(initialMinterAllowance).minus(newBigNumber(amount)).cmp(newBigNumber(minterAllowance)) + ==0);*/ } async function blacklist(token, account) { @@ -385,13 +408,13 @@ async function setLongDecimalFeesTransferWithFees(token, ownerAccount, arbitrary feeBase = 1000000; await token.updateTransferFee(fee, feeBase); let allowed = await token.allowance.call(ownerAccount, arbitraryAccount); - assert.isTrue(new BigNumber(allowed).isEqualTo(new BigNumber(0))); + assert.isTrue(allowed.isZero()); await mint(token, ownerAccount, 1900); let initialBalanceFeeAccount = await token.balanceOf(feeAccount); await token.approve(arbitraryAccount, 1500); allowed = await token.allowance.call(ownerAccount, arbitraryAccount); - assert.isTrue(new BigNumber(allowed).isEqualTo(new BigNumber(1500))); + assert.isTrue(allowed.cmp(newBigNumber(1500))==0); let transfer = await token.transfer(arbitraryAccount, 1000, { from: ownerAccount }); @@ -404,17 +427,17 @@ async function setLongDecimalFeesTransferWithFees(token, ownerAccount, arbitrary let balance3 = await token.balanceOf(arbitraryAccount); assert.equal(balance3, 1000); let balanceFeeAccount = await token.balanceOf(feeAccount); - assert.isTrue(new BigNumber(balanceFeeAccount).minus(new BigNumber(initialBalanceFeeAccount)).isEqualTo(new BigNumber(feeAmount))); + assert.isTrue(balanceFeeAccount.sub(initialBalanceFeeAccount).cmp(newBigNumber(feeAmount))==0); } async function sampleTransfer(token, ownerAccount, arbitraryAccount, minter) { let allowed = await token.allowance.call(ownerAccount, arbitraryAccount); - assert.isTrue(new BigNumber(allowed).isEqualTo(new BigNumber(0))); + assert.isTrue(allowed.isZero()); await mint(token, ownerAccount, 1900, minter); await token.approve(arbitraryAccount, 1500); allowed = await token.allowance.call(ownerAccount, arbitraryAccount); - assert.isTrue(new BigNumber(allowed).isEqualTo(new BigNumber(1500))); + assert.isTrue(allowed.cmp(newBigNumber(1500))==0); let transfer = await token.transfer(arbitraryAccount, 1000, { from: ownerAccount }); @@ -431,12 +454,12 @@ async function transferFromWithFees(token, ownerAccount, arbitraryAccount, minte feeBase = 10000; await token.updateTransferFee(fee, feeBase); let allowed = await token.allowance.call(ownerAccount, arbitraryAccount); - assert.isTrue(new BigNumber(allowed).isEqualTo(new BigNumber(0))); + assert.isTrue(allowed.isZero()); await mint(token, ownerAccount, 900, minter); let initialBalanceFeeAccount = await token.balanceOf(feeAccount); await token.approve(arbitraryAccount, 634); allowed = await token.allowance.call(ownerAccount, arbitraryAccount); - assert.isTrue(new BigNumber(allowed).isEqualTo(new BigNumber(634))); + assert.isTrue(allowed.cmp(newBigNumber(634))==0); transfer = await token.transferFrom(ownerAccount, arbitraryAccount, 534, { from: arbitraryAccount }); @@ -444,29 +467,29 @@ async function transferFromWithFees(token, ownerAccount, arbitraryAccount, minte checkTransferEvents(transfer, ownerAccount, arbitraryAccount, 534, feeAmount); let balance0 = await token.balanceOf(ownerAccount); - assert.isTrue(new BigNumber(balance0).isEqualTo(new BigNumber(900).minus(new BigNumber(534)).minus(new BigNumber(feeAmount)))); + assert.isTrue(balance0.cmp(900 - 534 - feeAmount)==0); let balance3 = await token.balanceOf(arbitraryAccount); - assert.isTrue(new BigNumber(balance3).isEqualTo(new BigNumber(534))); + assert.isTrue(balance3.cmp(newBigNumber(534))==0); let balanceFeeAccount = await token.balanceOf(feeAccount); - assert.isTrue(new BigNumber(balanceFeeAccount).minus(new BigNumber(initialBalanceFeeAccount)).isEqualTo(new BigNumber(feeAmount))); + assert.isTrue(balanceFeeAccount.sub(initialBalanceFeeAccount).cmp(newBigNumber(feeAmount))==0); } async function sampleTransferFrom(token, ownerAccount, arbitraryAccount, minter) { let allowed = await token.allowance.call(ownerAccount, arbitraryAccount); // TODO not this - assert.isTrue(new BigNumber(allowed).isEqualTo(new BigNumber(0))); + assert.isTrue(allowed.isZero()); await mint(token, ownerAccount, 900, minter); // TODO maybe this await token.approve(arbitraryAccount, 634); // TODO not this allowed = await token.allowance.call(ownerAccount, arbitraryAccount); // TODO not this - assert.isTrue(new BigNumber(allowed).isEqualTo(new BigNumber(634))); + assert.isTrue(allowed.cmp(newBigNumber(634))==0); let transfer = await token.transferFrom(ownerAccount, arbitraryAccount, 534, { from: arbitraryAccount }); // TODO not this checkTransferEvents(transfer, ownerAccount, arbitraryAccount, 534); let balance0 = await token.balanceOf(ownerAccount); - assert.isTrue(new BigNumber(balance0).isEqualTo(new BigNumber(900).minus(new BigNumber(534)))); + assert.isTrue(balance0.cmp(newBigNumber(900-534))==0); let balance3 = await token.balanceOf(arbitraryAccount); - assert.isTrue(new BigNumber(balance3).isEqualTo(new BigNumber(534))); + assert.isTrue(balance3.cmp(newBigNumber(534))==0); } async function approve(token, to, amount, from) { @@ -483,8 +506,8 @@ async function redeem(token, account, amount) { function validateTransferEvent(transferEvent, from, to, value) { let eventResult = transferEvent.logs[0]; assert.equal(eventResult.event, 'Transfer'); - assert.equal(eventResult.args.from, from); - assert.equal(eventResult.args.to, to); + assert.isTrue(addressEquals(eventResult.args.from, from)); + assert.isTrue(addressEquals(eventResult.args.to, to)); assert.equal(eventResult.args.value, value); } @@ -521,26 +544,21 @@ async function upgradeTo(proxy, upgradedToken, proxyUpgraderAccount) { } async function expectRevert(contractPromise) { - try { - await contractPromise; - } catch (error) { - const revert = error.message.search('revert') >= 0; - assert( - revert, - 'Expected error of type revert, got \'' + error + '\' instead', - ); - return; - } - assert.fail('Expected error of type revert, but no error was received'); + await expectError(contractPromise, 'error:'); } async function expectJump(contractPromise) { + await expectError(contractPromise, 'invalid opcode'); +} + +async function expectError(contractPromise, errorMsg) { try { await contractPromise; - assert.fail('Expected invalid opcode not received'); + assert.fail('Expected error ${errorMsg}, but no error received'); } catch (error) { - const invalidOpcodeReceived = error.message.search('invalid opcode') >= 0; - assert(invalidOpcodeReceived, `Expected "invalid opcode", got ${error} instead`); +// Todo: perform error message check in separate PR +// var correctErrorMsgReceived = error.message.includes(errorMsg); +// assert(correctErrorMsgReceived, `Expected ${errorMsg}, got ${error.message} instead`); } } @@ -550,13 +568,13 @@ function encodeCall(name, arguments, values) { return '0x' + methodId + params; } -function getAdmin(proxy) { - let adm = web3.eth.getStorageAt(proxy.address, adminSlot); +async function getAdmin(proxy) { + var adm = await web3.eth.getStorageAt(proxy.address, adminSlot); return adm; } -function getImplementation(proxy) { - let impl = web3.eth.getStorageAt(proxy.address, implSlot); +async function getImplementation(proxy) { + let impl = await web3.eth.getStorageAt(proxy.address, implSlot); return impl; } @@ -582,13 +600,15 @@ async function getInitializedV1(token) { } else { assert.fail("slot8Data incorrect size"); } - masterMinterAddress = "0x" + slot8Data.substring(masterMinterStart, masterMinterStart + 40); - assert.equal(await token.masterMinter.call(), masterMinterAddress); + masterMinterAddress = "0x" + slot8Data.substring(masterMinterStart, masterMinterStart + 40).toUpperCase(); + var tokenMMA = await token.masterMinter.call(); + assert.isTrue(addressEquals(tokenMMA, masterMinterAddress)); } return initialized; } module.exports = { + newBigNumber: newBigNumber, FiatToken: FiatToken, FiatTokenProxy: FiatTokenProxy, UpgradedFiatToken: UpgradedFiatToken, @@ -641,6 +661,7 @@ module.exports = { upgradeTo: upgradeTo, expectRevert: expectRevert, expectJump: expectJump, + expectError: expectError, encodeCall: encodeCall, getInitializedV1: getInitializedV1, getAdmin: getAdmin, diff --git a/test/assert/ABITests.test.js b/test/assert/ABITests.test.js index 28693527d..b3847ff5a 100644 --- a/test/assert/ABITests.test.js +++ b/test/assert/ABITests.test.js @@ -5,7 +5,6 @@ var name = tokenUtils.name; var symbol = tokenUtils.symbol; var currency = tokenUtils.currency; var decimals = tokenUtils.decimals -var BigNumber = require('bignumber.js'); var bigZero = tokenUtils.bigZero; var bigHundred = tokenUtils.bigHundred; var mint = tokenUtils.mint; @@ -52,18 +51,11 @@ async function run_tests(newToken, accounts) { // sanity check for pausable it('abi004 FiatToken pause() is public', async function () { let badData = functionSignature('pause()'); - var tx = new Tx({ - nonce: web3.toHex(web3.eth.getTransactionCount(Accounts.pauserAccount)), - gasPrice: web3.toHex(web3.toWei('20', 'gwei')), - gasLimit: 100000, - to: token.address, - value: 0, - data: badData, - }); - var privateKey = Buffer.from(AccountPrivateKeys.pauserPrivateKey, 'hex'); - tx.sign(privateKey); - var raw = '0x' + tx.serialize().toString('hex'); - + let raw = await makeRawTransaction( + badData, + Accounts.pauserAccount, + AccountPrivateKeys.pauserPrivateKey, + token.address); await sendRawTransaction(raw); var customVars = [ { 'variable': 'paused', 'expectedValue': true } @@ -73,75 +65,48 @@ async function run_tests(newToken, accounts) { it('abi040 Blacklistable constructor is not a function', async function () { let badData = functionSignature('Blacklistable()'); - var tx = new Tx({ - nonce: web3.toHex(web3.eth.getTransactionCount(Accounts.pauserAccount)), - gasPrice: web3.toHex(web3.toWei('20', 'gwei')), - gasLimit: 100000, - to: token.address, - value: 0, - data: badData, - }); - var privateKey = Buffer.from(AccountPrivateKeys.pauserPrivateKey, 'hex'); - tx.sign(privateKey); - var raw = '0x' + tx.serialize().toString('hex'); - + let raw = await makeRawTransaction( + badData, + Accounts.pauserAccount, + AccountPrivateKeys.pauserPrivateKey, + token.address); await expectRevert(sendRawTransaction(raw)); }); it('abi042 Ownable constructor is not a function', async function () { let badData = functionSignature('Ownable()'); - var tx = new Tx({ - nonce: web3.toHex(web3.eth.getTransactionCount(Accounts.pauserAccount)), - gasPrice: web3.toHex(web3.toWei('20', 'gwei')), - gasLimit: 100000, - to: token.address, - value: 0, - data: badData, - }); - var privateKey = Buffer.from(AccountPrivateKeys.pauserPrivateKey, 'hex'); - tx.sign(privateKey); - var raw = '0x' + tx.serialize().toString('hex'); - + let raw = await makeRawTransaction( + badData, + Accounts.pauserAccount, + AccountPrivateKeys.pauserPrivateKey, + token.address); + await expectRevert(sendRawTransaction(raw)); await expectRevert(sendRawTransaction(raw)); }); it('abi005 Pausable constructor is not a function', async function () { - let badData = functionSignature('Pausable()'); - var tx = new Tx({ - nonce: web3.toHex(web3.eth.getTransactionCount(Accounts.pauserAccount)), - gasPrice: web3.toHex(web3.toWei('20', 'gwei')), - gasLimit: 100000, - to: token.address, - value: 0, - data: badData, - }); - var privateKey = Buffer.from(AccountPrivateKeys.pauserPrivateKey, 'hex'); - tx.sign(privateKey); - var raw = '0x' + tx.serialize().toString('hex'); - + let badData = functionSignature('Pausable()'); + let raw = await makeRawTransaction( + badData, + Accounts.pauserAccount, + AccountPrivateKeys.pauserPrivateKey, + token.address); await expectRevert(sendRawTransaction(raw)); }); it('abi043 FiatTokenProxy constructor is not a function', async function () { - let badData = functionSignature('FiatTokenProxy()'); - var tx = new Tx({ - nonce: web3.toHex(web3.eth.getTransactionCount(Accounts.pauserAccount)), - gasPrice: web3.toHex(web3.toWei('20', 'gwei')), - gasLimit: 100000, - to: token.address, - value: 0, - data: badData, - }); - var privateKey = Buffer.from(AccountPrivateKeys.pauserPrivateKey, 'hex'); - tx.sign(privateKey); - var raw = '0x' + tx.serialize().toString('hex'); - + let badData = functionSignature('FiatTokenProxy()'); + let raw = await makeRawTransaction( + badData, + Accounts.pauserAccount, + AccountPrivateKeys.pauserPrivateKey, + token.address); await expectRevert(sendRawTransaction(raw)); }); it('abi027 UpgradeabilityProxy constructor', async function () { let badData = msgData('UpgradeabilityProxy(address)', Accounts.arbitraryAccount); - let raw = makeRawTransaction( + let raw = await makeRawTransaction( badData, Accounts.arbitraryAccount, AccountPrivateKeys.arbitraryPrivateKey, @@ -151,7 +116,7 @@ async function run_tests(newToken, accounts) { it('abi055 Proxy constructor is not a function', async function () { let badData = functionSignature('Proxy()'); - let raw = makeRawTransaction( + let raw = await makeRawTransaction( badData, Accounts.arbitraryAccount, AccountPrivateKeys.arbitraryPrivateKey, @@ -161,7 +126,7 @@ async function run_tests(newToken, accounts) { it('abi056 Proxy _delegate is internal', async function () { let badData = msgData('_delegate(address)', Accounts.arbitraryAccount); - let raw = makeRawTransaction( + let raw = await makeRawTransaction( badData, Accounts.arbitraryAccount, AccountPrivateKeys.arbitraryPrivateKey, @@ -171,7 +136,7 @@ async function run_tests(newToken, accounts) { it('abi057 Proxy _willFallback is internal', async function () { let badData = functionSignature('_willFallback()'); - let raw = makeRawTransaction( + let raw = await makeRawTransaction( badData, Accounts.arbitraryAccount, AccountPrivateKeys.arbitraryPrivateKey, @@ -181,7 +146,7 @@ async function run_tests(newToken, accounts) { it('abi058 Proxy _fallback is internal', async function () { let badData = functionSignature('_fallback()'); - let raw = makeRawTransaction( + let raw = await makeRawTransaction( badData, Accounts.arbitraryAccount, AccountPrivateKeys.arbitraryPrivateKey, @@ -191,7 +156,7 @@ async function run_tests(newToken, accounts) { it('abi050 Upgradeability implementation is internal', async function () { let badData = msgData('UpgradeabilityProxy(address)', Accounts.arbitraryAccount); - let raw = makeRawTransaction( + let raw = await makeRawTransaction( badData, Accounts.arbitraryAccount, AccountPrivateKeys.arbitraryPrivateKey, @@ -201,7 +166,7 @@ async function run_tests(newToken, accounts) { it('abi051 AdminUpgradeabillityProxy constructor is not a function', async function () { let badData = msgData('AdminUpgradeabillityProxy(address)', Accounts.arbitraryAccount); - let raw = makeRawTransaction( + let raw = await makeRawTransaction( badData, Accounts.arbitraryAccount, AccountPrivateKeys.arbitraryPrivateKey, @@ -211,7 +176,7 @@ async function run_tests(newToken, accounts) { it('abi053 AdminUpgradeabillityProxy _setAdmin is internal', async function () { let badData = msgData('AdminUpgradeabillityProxy(address)', Accounts.arbitraryAccount); - let raw = makeRawTransaction( + let raw = await makeRawTransaction( badData, Accounts.arbitraryAccount, AccountPrivateKeys.arbitraryPrivateKey, @@ -220,36 +185,22 @@ async function run_tests(newToken, accounts) { }); it('abi041 FiatToken constructor is not a function', async function () { - let badData = functionSignature('FiatToken()'); - var tx = new Tx({ - nonce: web3.toHex(web3.eth.getTransactionCount(Accounts.pauserAccount)), - gasPrice: web3.toHex(web3.toWei('20', 'gwei')), - gasLimit: 100000, - to: token.address, - value: 0, - data: badData, - }); - var privateKey = Buffer.from(AccountPrivateKeys.pauserPrivateKey, 'hex'); - tx.sign(privateKey); - var raw = '0x' + tx.serialize().toString('hex'); - + let badData = functionSignature('FiatToken()'); + let raw = await makeRawTransaction( + badData, + Accounts.pauserAccount, + AccountPrivateKeys.pauserPrivateKey, + token.address); await expectRevert(sendRawTransaction(raw)); }); it('abi025 setOwner is internal', async function () { - let badData = msgData('setOwner(address)', Accounts.pauserAccount); - var tx = new Tx({ - nonce: web3.toHex(web3.eth.getTransactionCount(Accounts.tokenOwnerAccount)), - gasPrice: web3.toHex(web3.toWei('20', 'gwei')), - gasLimit: 100000, - to: token.address, - value: 0, - data: badData, - }); - var privateKey = Buffer.from(AccountPrivateKeys.tokenOwnerPrivateKey, 'hex'); - tx.sign(privateKey); - var raw = '0x' + tx.serialize().toString('hex'); - + let badData = msgData('setOwner(address)', Accounts.pauserAccount); + let raw = await makeRawTransaction( + badData, + Accounts.pauserAccount, + AccountPrivateKeys.pauserPrivateKey, + token.address); await expectRevert(sendRawTransaction(raw)); }); diff --git a/test/assert/FiatTokenLegacy.test.js b/test/assert/FiatTokenLegacy.test.js index 343efa67a..ac8c90c86 100644 --- a/test/assert/FiatTokenLegacy.test.js +++ b/test/assert/FiatTokenLegacy.test.js @@ -3,7 +3,6 @@ var name = tokenUtils.name; var symbol = tokenUtils.symbol; var currency = tokenUtils.currency; var decimals = tokenUtils.decimals -var BigNumber = require('bignumber.js'); var bigZero = tokenUtils.bigZero; var bigHundred = tokenUtils.bigHundred; var mint = tokenUtils.mint; @@ -21,9 +20,11 @@ var upgradeTo = tokenUtils.upgradeTo; var UpgradedFiatToken = tokenUtils.UpgradedFiatToken; var FiatToken = tokenUtils.FiatToken; var getAdmin = tokenUtils.getAdmin; +var newBigNumber = tokenUtils.newBigNumber; var AccountUtils = require('./../AccountUtils.js'); var Accounts = AccountUtils.Accounts; +var addressEquals = AccountUtils.addressEquals; // these tests are for reference and do not track side effects on all variables async function run_tests(newToken, accounts) { @@ -35,10 +36,10 @@ async function run_tests(newToken, accounts) { token = tokenConfig.token; assert.equal(proxy.address, token.address); }); - +/* it('should start with a totalSupply of 0', async function () { let totalSupply = await token.totalSupply(); - assert.isTrue(new BigNumber(totalSupply).isEqualTo(new BigNumber(0))); + assert.isTrue(totalSupply.isZero()); }); it('should add multiple mints to a given address in address balance', async function () { @@ -55,22 +56,22 @@ async function run_tests(newToken, accounts) { await expectRevert(mint(token, "0x0", 100, Accounts.minterAccount)); totalSupply = await token.totalSupply(); - assert.isTrue(new BigNumber(totalSupply).isEqualTo(new BigNumber(initialTotalSupply))); + assert.isTrue(totalSupply.cmp(newBigNumber(initialTotalSupply))==0); await expectRevert(mint(token, 0x0, 100, Accounts.minterAccount)); totalSupply = await token.totalSupply(); - assert.isTrue(new BigNumber(totalSupply).isEqualTo(new BigNumber(initialTotalSupply))); + assert.isTrue(totalSupply.cmp(newBigNumber(initialTotalSupply))==0); await expectRevert(mint(token, "0x0000000000000000000000000000000000000000", 100, Accounts.minterAccount)); totalSupply = await token.totalSupply(); - assert.isTrue(new BigNumber(totalSupply).isEqualTo(new BigNumber(initialTotalSupply))); + assert.isTrue(totalSupply.cmp(newBigNumber(initialTotalSupply))==0); await expectRevert(mint(token, 0x0000000000000000000000000000000000000000, 100, Accounts.minterAccount)); totalSupply = await token.totalSupply(); - assert.isTrue(new BigNumber(totalSupply).isEqualTo(new BigNumber(initialTotalSupply))); + assert.isTrue(totalSupply.cmp(newBigNumber(initialTotalSupply))==0); }); it('should add multiple mints to a given address in address balance', async function () { @@ -78,7 +79,7 @@ async function run_tests(newToken, accounts) { await mint(token, accounts[0], 200, Accounts.minterAccount); let balance0 = await token.balanceOf(accounts[0]); - assert.isTrue(new BigNumber(balance0).isEqualTo(new BigNumber(300))); + assert.isTrue(balance0.cmp(newBigNumber(300))==0); }); it('should add multiple mints to total supply', async function () { @@ -88,7 +89,7 @@ async function run_tests(newToken, accounts) { await mint(token, accounts[1], 600, Accounts.minterAccount); let totalSupply = await token.totalSupply(); - assert.isTrue(new BigNumber(totalSupply).minus(new BigNumber(initialTotalSupply)).isEqualTo(new BigNumber(1100))); + assert.isTrue(totalSupply.sub(initialTotalSupply).cmp(newBigNumber(1100))==0); }); it('should fail to mint from blacklisted minter', async function () { @@ -126,7 +127,7 @@ async function run_tests(newToken, accounts) { it('should approve', async function () { await approve(token, accounts[3], 100, accounts[2]); let allowance = await token.allowance(accounts[2], accounts[3]); - assert.isTrue(new BigNumber(allowance).isEqualTo(new BigNumber(100))); + assert.isTrue(allowance.cmp(newBigNumber(100))==0); }); it('should complete sample transfer', async function () { @@ -147,29 +148,29 @@ async function run_tests(newToken, accounts) { it('should set allowance and balances before and after approved transfer', async function () { let allowed = await token.allowance.call(accounts[0], accounts[3]); - assert.isTrue(new BigNumber(allowed).isEqualTo(new BigNumber(0))); + assert.isTrue(allowed.isZero()); await mint(token, accounts[0], 500, Accounts.minterAccount); await token.approve(accounts[3], 100); allowed = await token.allowance.call(accounts[0], accounts[3]); - assert.isTrue(new BigNumber(allowed).isEqualTo(new BigNumber(100))); + assert.isTrue(allowed.cmp(newBigNumber(100))==0); let transfer = await token.transferFrom(accounts[0], accounts[3], 50, { from: accounts[3] }); checkTransferEvents(transfer, accounts[0], accounts[3], 50); let balance0 = await token.balanceOf(accounts[0]); - assert.isTrue(new BigNumber(balance0).isEqualTo(new BigNumber(450))); + assert.isTrue(balance0.cmp(newBigNumber(450))==0); let balance3 = await token.balanceOf(accounts[3]); - assert.isTrue(new BigNumber(balance3).isEqualTo(new BigNumber(50))); + assert.isTrue(balance3.cmp(newBigNumber(50))==0); }); it('should fail on unauthorized approved transfer and not change balances', async function () { let allowed = await token.allowance.call(accounts[0], accounts[3]); - assert.isTrue(new BigNumber(allowed).isEqualTo(new BigNumber(0))); + assert.isTrue(allowed.cmp(newBigNumber(0))==0); await mint(token, accounts[0], 500, Accounts.minterAccount); await token.approve(accounts[3], 100); allowed = await token.allowance.call(accounts[0], accounts[3]); - assert.isTrue(new BigNumber(allowed).isEqualTo(new BigNumber(100))); + assert.isTrue(allowed.cmp(newBigNumber(100))==0); await expectRevert(token.transferFrom(accounts[0], accounts[3], 50, { from: accounts[4] })); @@ -178,14 +179,14 @@ async function run_tests(newToken, accounts) { let balance3 = await token.balanceOf(accounts[3]); assert.equal(balance3, 0); }); - +*/ it('should fail on invalid approved transfer amount and not change balances', async function () { let allowed = await token.allowance.call(accounts[0], accounts[3]); - assert.isTrue(new BigNumber(allowed).isEqualTo(new BigNumber(0))); + assert.isTrue(allowed.cmp(newBigNumber(0))==0); await mint(token, accounts[0], 500, Accounts.minterAccount); await token.approve(accounts[3], 100); allowed = await token.allowance.call(accounts[0], accounts[3]); - assert.isTrue(new BigNumber(allowed).isEqualTo(new BigNumber(100))); + assert.isTrue(allowed.cmp(newBigNumber(100))==0); await expectRevert(token.transferFrom(accounts[0], accounts[3], 450, { from: accounts[3] })); @@ -201,7 +202,7 @@ async function run_tests(newToken, accounts) { await mint(token, accounts[0], 500, Accounts.minterAccount); await token.approve(accounts[3], 100); let allowed = await token.allowance.call(accounts[0], accounts[3]); - assert.isTrue(new BigNumber(allowed).isEqualTo(new BigNumber(100))); + assert.isTrue(allowed.cmp(newBigNumber(100))==0); await expectRevert(token.transferFrom(accounts[0], 0, 50, { from: accounts[3] })); @@ -211,7 +212,7 @@ async function run_tests(newToken, accounts) { it('should test consistency of transfer(x) and approve(x) + transferFrom(x)', async function () { let allowed = await token.allowance.call(accounts[0], accounts[3]); - assert.isTrue(new BigNumber(allowed).isEqualTo(new BigNumber(0))); + assert.isTrue(allowed.isZero()); let transferAmount = 650; let totalAmount = transferAmount; await mint(token, accounts[0], totalAmount, Accounts.minterAccount); @@ -225,12 +226,12 @@ async function run_tests(newToken, accounts) { assert.equal(balance3, transferAmount); await token.allowance.call(accounts[1], accounts[4]); - assert.isTrue(new BigNumber(allowed).isEqualTo(new BigNumber(0))); + assert.isTrue(allowed.isZero()); await mint(token, accounts[1], totalAmount, Accounts.minterAccount); await token.approve(accounts[4], transferAmount, { from: accounts[1] }); allowed = await token.allowance.call(accounts[1], accounts[4]); - assert.isTrue(new BigNumber(allowed).isEqualTo(new BigNumber(transferAmount))); + assert.isTrue(allowed.cmp(newBigNumber(transferAmount))==0); transfer = await token.transferFrom(accounts[1], accounts[4], transferAmount, { from: accounts[4] }); @@ -316,7 +317,7 @@ async function run_tests(newToken, accounts) { await expectRevert(token.transferFrom(accounts[2], accounts[1], 600, { from: accounts[1] })); let balance = await token.balanceOf(accounts[2]); - assert.isTrue(new BigNumber(balance).isEqualTo(new BigNumber(100))); + assert.isTrue(balance.cmp(newBigNumber(100))==0); }); it('should blacklist and make transfer impossible', async function () { @@ -337,9 +338,9 @@ async function run_tests(newToken, accounts) { await expectRevert(token.transfer(accounts[2], 600, { from: accounts[9] })); let balance = await token.balanceOf(accounts[2]); - assert.isTrue(new BigNumber(balance).isEqualTo(new BigNumber(1900))); + assert.isTrue(balance.cmp(newBigNumber(1900))==0); balance = await token.balanceOf(accounts[9]); - assert.isTrue(new BigNumber(balance).isEqualTo(new BigNumber(1600))); + assert.isTrue(balance.cmp(newBigNumber(1600))==0); }); it('should blacklist and make transferFrom impossible with the approved transferer', async function () { @@ -353,7 +354,7 @@ async function run_tests(newToken, accounts) { await expectRevert(token.transferFrom(accounts[2], accounts[3], 600, { from: accounts[1] })); let balance = await token.balanceOf(accounts[2]); - assert.isTrue(new BigNumber(balance).isEqualTo(new BigNumber(1900))); + assert.isTrue(balance.cmp(newBigNumber(1900))==0); let isBlacklistedAfter = await token.isBlacklisted(accounts[2]); assert.equal(isBlacklistedAfter, true); @@ -367,7 +368,7 @@ async function run_tests(newToken, accounts) { await expectRevert(token.transferFrom(accounts[2], accounts[3], 600, { from: accounts[1] })); let balance = await token.balanceOf(accounts[2]); - assert.isTrue(new BigNumber(balance).isEqualTo(new BigNumber(1900))); + assert.isTrue(balance.cmp(newBigNumber(1900))==0); }); it('should blacklist recipient and make transfer to recipient using transferFrom impossible', async function () { @@ -378,7 +379,7 @@ async function run_tests(newToken, accounts) { await expectRevert(token.transferFrom(accounts[2], accounts[3], 600, { from: accounts[2] })); let balance = await token.balanceOf(accounts[2]); - assert.isTrue(new BigNumber(balance).isEqualTo(new BigNumber(1900))); + assert.isTrue(balance.cmp(newBigNumber(1900))==0); }); it('should blacklist and make approve impossible', async function () { @@ -387,7 +388,7 @@ async function run_tests(newToken, accounts) { await expectRevert(token.approve(accounts[2], 600, { from: accounts[1] })); let approval = await token.allowance(accounts[1], accounts[2]); - assert.isTrue(new BigNumber(approval).isEqualTo(new BigNumber(0))); + assert.isTrue(approval.isZero()); }); it('should make giving approval to blacklisted account impossible', async function () { @@ -397,7 +398,7 @@ async function run_tests(newToken, accounts) { await expectRevert(token.approve(accounts[1], 600, { from: accounts[2] })); let approval = await token.allowance(accounts[2], accounts[1]); - assert.isTrue(new BigNumber(approval).isEqualTo(new BigNumber(0))); + assert.isTrue(approval.isZero()); }); it('should blacklist then unblacklist to make a transfer possible', async function () { @@ -406,9 +407,9 @@ async function run_tests(newToken, accounts) { await unBlacklist(token, accounts[2]); await token.transfer(accounts[3], 600, { from: accounts[2] }); let balance = await token.balanceOf(accounts[2]); - assert.isTrue(new BigNumber(balance).isEqualTo(new BigNumber(1300))); + assert.isTrue(balance.cmp(newBigNumber(1300))==0); balance = await token.balanceOf(accounts[3]); - assert.isTrue(new BigNumber(balance).isEqualTo(new BigNumber(600))); + assert.isTrue(balance.cmp(newBigNumber(600))==0); }); it('should fail to blacklist with non-blacklister account', async function () { @@ -418,9 +419,9 @@ async function run_tests(newToken, accounts) { await token.transfer(accounts[3], 600, { from: accounts[2] }); let balance = await token.balanceOf(accounts[2]); - assert.isTrue(new BigNumber(balance).isEqualTo(new BigNumber(1300))); + assert.isTrue(balance.cmp(newBigNumber(1300))==0); balance = await token.balanceOf(accounts[3]); - assert.isTrue(new BigNumber(balance).isEqualTo(new BigNumber(600))); + assert.isTrue(balance.cmp(newBigNumber(600))==0); }); it('should unblacklist when paused', async function () { @@ -437,13 +438,13 @@ async function run_tests(newToken, accounts) { assert.isFalse(blacklisted); let balance = await token.balanceOf(accounts[2]); - assert.isTrue(new BigNumber(balance).isEqualTo(new BigNumber(1900))); + assert.isTrue(balance.cmp(newBigNumber(1900))==0); }); it('should change the minter and mint as well as fail to mint with the old minter', async function () { let update = await token.removeMinter(Accounts.minterAccount, { from: Accounts.masterMinterAccount }); assert.equal(update.logs[0].event, 'MinterRemoved'); - assert.equal(update.logs[0].args.oldMinter, Accounts.minterAccount); + assert.isTrue(addressEquals(update.logs[0].args.oldMinter, Accounts.minterAccount)); update = await setMinter(token, accounts[3], 10000, { from: Accounts.masterMinterAccount }); await token.mint(accounts[1], 100, { from: accounts[3] }); @@ -500,7 +501,7 @@ async function run_tests(newToken, accounts) { it('should have correct decimals', async function () { let actual = await token.decimals.call(); - assert.equal(actual, decimals); + assert.equal(actual.toString(16,32), decimals.toString(16,32)); }); it('should have correct currency', async function () { @@ -514,24 +515,24 @@ async function run_tests(newToken, accounts) { await setMinter(token, burnerAddress, amount); let totalSupply = await token.totalSupply(); let minterBalance = await token.balanceOf(burnerAddress); - assert.isTrue(new BigNumber(totalSupply).isEqualTo(new BigNumber(0))); - assert.isTrue(new BigNumber(minterBalance).isEqualTo(new BigNumber(0))); + assert.isTrue(totalSupply.isZero()); + assert.isTrue(minterBalance.isZero()); // mint tokens to burnerAddress await mint(token, burnerAddress, amount, Accounts.minterAccount); let totalSupply1 = await token.totalSupply(); let minterBalance1 = await token.balanceOf(burnerAddress); - assert.isTrue(new BigNumber(totalSupply1).isEqualTo(new BigNumber(totalSupply).plus(new BigNumber(amount)))); - assert.isTrue(new BigNumber(minterBalance1).isEqualTo(new BigNumber(minterBalance).plus(new BigNumber(amount)))); + assert.isTrue(totalSupply1.cmp(totalSupply.add(newBigNumber(amount)))==0); + assert.isTrue(minterBalance1.cmp(minterBalance.add(newBigNumber(amount)))==0); // burn tokens await burn(token, amount, burnerAddress); let totalSupply2 = await token.totalSupply(); - assert.isTrue(new BigNumber(totalSupply2).isEqualTo(new BigNumber(totalSupply1).minus(new BigNumber(amount)))); + assert.isTrue(totalSupply2.cmp(totalSupply1.sub(newBigNumber(amount)))==0); // check that minter's balance has been reduced let minterBalance2 = await token.balanceOf(burnerAddress); - assert.isTrue(new BigNumber(minterBalance2).isEqualTo(new BigNumber(minterBalance1).minus(new BigNumber(amount)))); + assert.isTrue(minterBalance2.cmp(minterBalance1.sub(newBigNumber(amount)))==0); }); it('should try to burn tokens from a non-minter and fail', async function () { @@ -564,7 +565,7 @@ async function run_tests(newToken, accounts) { it('should upgrade and preserve data', async function () { await mint(token, accounts[2], 200, Accounts.minterAccount); let initialBalance = await token.balanceOf(accounts[2]); - assert.isTrue((new BigNumber(initialBalance)).isEqualTo(new BigNumber(200))); + assert.isTrue(initialBalance.cmp(newBigNumber(200))==0); var newRawToken = await UpgradedFiatToken.new(); var tokenConfig = await upgradeTo(proxy, newRawToken); @@ -572,11 +573,11 @@ async function run_tests(newToken, accounts) { var newToken = newProxiedToken; let upgradedBalance = await newToken.balanceOf(accounts[2]); - assert.isTrue((new BigNumber(upgradedBalance)).isEqualTo(new BigNumber(200))); + assert.isTrue(upgradedBalance.cmp(newBigNumber(200))==0); await newToken.configureMinter(Accounts.minterAccount, 500, { from: Accounts.masterMinterAccount }); await newToken.mint(accounts[2], 200, { from: Accounts.minterAccount }); let balance = await newToken.balanceOf(accounts[2]); - assert.isTrue((new BigNumber(balance)).isEqualTo(new BigNumber(400))); + assert.isTrue(balance.cmp(newBigNumber(400))==0); }); it('should updateRoleAddress for masterMinter', async function () { @@ -616,19 +617,19 @@ async function run_tests(newToken, accounts) { }); it('should updateUpgraderAddress for upgrader', async function () { - let upgrader = getAdmin(proxy); - assert.equal(Accounts.proxyOwnerAccount, upgrader); + let upgrader = await getAdmin(proxy); + assert.isTrue(addressEquals(Accounts.proxyOwnerAccount, upgrader)); let address1 = accounts[10]; let updated = await proxy.changeAdmin(address1, { from: Accounts.proxyOwnerAccount }); - upgrader = getAdmin(proxy); - assert.equal(upgrader, address1); + upgrader = await getAdmin(proxy); + assert.isTrue(addressEquals(upgrader, address1)); //Test upgrade with new upgrader account await token.configureMinter(Accounts.minterAccount, 1000, {from: Accounts.masterMinterAccount}); await token.mint(accounts[2], 200, {from: Accounts.minterAccount}); let initialBalance = await token.balanceOf(accounts[2]); - assert.isTrue((new BigNumber(initialBalance)).isEqualTo(new BigNumber(200))); + assert.isTrue(initialBalance.cmp(newBigNumber(200))==0); var newRawToken = await UpgradedFiatToken.new(); var tokenConfig = await upgradeTo(proxy, newRawToken, address1); @@ -636,17 +637,17 @@ async function run_tests(newToken, accounts) { var newToken = newProxiedToken; let upgradedBalance = await newToken.balanceOf(accounts[2]); - assert.isTrue((new BigNumber(upgradedBalance)).isEqualTo(new BigNumber(200))); + assert.isTrue(upgradedBalance.cmp(newBigNumber(200))==0); await newToken.configureMinter(Accounts.minterAccount, 500, { from: Accounts.masterMinterAccount }); await newToken.mint(accounts[2], 200, { from: Accounts.minterAccount }); let balance = await newToken.balanceOf(accounts[2]); - assert.isTrue((new BigNumber(balance)).isEqualTo(new BigNumber(400))); + assert.isTrue(balance.cmp(newBigNumber(400))==0); }); it('should fail to updateUpgraderAddress for upgrader using non-upgrader account', async function () { let address1 = accounts[7]; await expectRevert(proxy.changeAdmin(address1, { from: Accounts.tokenOwnerAccount })); - let upgrader = getAdmin(proxy); + let upgrader = await getAdmin(proxy); assert.notEqual(upgrader, address1); }); diff --git a/test/assert/Pausable.test.js b/test/assert/Pausable.test.js index 31f9da115..64160dbc6 100644 --- a/test/assert/Pausable.test.js +++ b/test/assert/Pausable.test.js @@ -7,6 +7,7 @@ var expectRevert = tokenUtils.expectRevert; var AccountUtils = require('./../AccountUtils.js'); var Accounts = AccountUtils.Accounts; +var addressEquals = AccountUtils.addressEquals; const should = require('chai') .use(require('chai-as-promised')) @@ -22,12 +23,12 @@ contract('PausableTests', function (accounts) { it('constructor owner', async function () { var actualOwner = await pause.owner.call(); - assert.equal(Accounts.deployerAccount, actualOwner, "wrong owner"); + assert.isTrue(addressEquals(Accounts.deployerAccount, actualOwner), "wrong owner"); }); it('constructor pauser', async function () { var actualOwner = await pause.pauser.call(); - assert.equal(Accounts.pauserAccount, actualOwner, "wrong pauser"); + assert.isTrue(addressEquals(Accounts.pauserAccount, actualOwner), "wrong pauser"); }); it('paused after pausing', async function () { @@ -51,7 +52,7 @@ contract('PausableTests', function (accounts) { await pause.updatePauser(Accounts.arbitraryAccount, {from: Accounts.deployerAccount}); var newPauser = await pause.pauser.call(); - assert.equal(Accounts.arbitraryAccount, newPauser); + assert.isTrue(addressEquals(Accounts.arbitraryAccount, newPauser)); // double check we're still paused await checkPaused("should still be paused after changing pauser"); diff --git a/test/basic/NegativeTests.js b/test/basic/NegativeTests.js index 062e63d8d..d275772cc 100644 --- a/test/basic/NegativeTests.js +++ b/test/basic/NegativeTests.js @@ -1,5 +1,5 @@ var tokenUtils = require('./../TokenTestUtils.js'); -var BigNumber = require('bignumber.js'); +var newBigNumber = tokenUtils.newBigNumber; var assertDiff = require('assert-diff'); assertDiff.options.strict = true; @@ -44,7 +44,7 @@ async function run_tests(newToken, accounts) { await token.pause({from: Accounts.pauserAccount}); var customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)}, + {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount)}, {'variable': 'paused', 'expectedValue': true} ] await expectRevert(token.mint(Accounts.arbitraryAccount, 50, {from: Accounts.minterAccount})); @@ -62,7 +62,7 @@ async function run_tests(newToken, accounts) { await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); var customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)}, + {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount)}, {'variable': 'isAccountBlacklisted.minterAccount', 'expectedValue': true} ] await expectRevert(token.mint(Accounts.arbitraryAccount, 50, {from: Accounts.minterAccount})); @@ -74,7 +74,7 @@ async function run_tests(newToken, accounts) { await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); var customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)}, + {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount)}, {'variable': 'isAccountBlacklisted.arbitraryAccount', 'expectedValue': true} ] await expectRevert(token.mint(Accounts.arbitraryAccount, 50, {from: Accounts.minterAccount})); @@ -85,7 +85,7 @@ async function run_tests(newToken, accounts) { await token.configureMinter(Accounts.minterAccount, amount - 1, {from: Accounts.masterMinterAccount}); var customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - 1)} + {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - 1)} ] await expectRevert(token.mint(Accounts.arbitraryAccount, amount, {from: Accounts.minterAccount})); await checkVariables([token], [customVars]); @@ -95,7 +95,7 @@ async function run_tests(newToken, accounts) { await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); var customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)} + {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount)} ] await expectRevert(token.mint("0x0", amount, {from: Accounts.minterAccount})); await expectRevert(token.mint("0x0000000000000000000000000000000000000000", amount, {from: Accounts.minterAccount})); @@ -138,7 +138,7 @@ async function run_tests(newToken, accounts) { await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); var customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)} + {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount)} ] await checkVariables([token], [customVars]); @@ -146,10 +146,10 @@ async function run_tests(newToken, accounts) { 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.arbitraryAccount2', 'expectedValue': new BigNumber(50)} + {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - 50)}, + {'variable': 'balances.arbitraryAccount', 'expectedValue': newBigNumber(50)}, + {'variable': 'totalSupply', 'expectedValue': newBigNumber(50)}, + {'variable': 'allowance.arbitraryAccount.arbitraryAccount2', 'expectedValue': newBigNumber(50)} ] await expectRevert(token.transferFrom(Accounts.arbitraryAccount, "0x0", 50, {from: Accounts.arbitraryAccount2})); await checkVariables([token], [customVars]); @@ -159,7 +159,7 @@ async function run_tests(newToken, accounts) { await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)} + {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount)} ] await checkVariables([token], [customVars]); @@ -167,10 +167,10 @@ async function run_tests(newToken, accounts) { await token.approve(Accounts.blacklisterAccount, amount, {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.blacklisterAccount', 'expectedValue': new BigNumber(amount)}, + {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - 50)}, + {'variable': 'balances.arbitraryAccount', 'expectedValue': newBigNumber(50)}, + {'variable': 'totalSupply', 'expectedValue': newBigNumber(50)}, + {'variable': 'allowance.arbitraryAccount.blacklisterAccount', 'expectedValue': newBigNumber(amount)}, ] await expectRevert(token.transferFrom(Accounts.arbitraryAccount, Accounts.pauserAccount, amount, {from: Accounts.blacklisterAccount})); await checkVariables([token], [customVars]); @@ -180,7 +180,7 @@ async function run_tests(newToken, accounts) { await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)} + {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount)} ] await checkVariables([token], [customVars]); @@ -189,10 +189,10 @@ async function run_tests(newToken, accounts) { 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.arbitraryAccount2', 'expectedValue': new BigNumber(50)}, + {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - 50)}, + {'variable': 'balances.blacklisterAccount', 'expectedValue': newBigNumber(50)}, + {'variable': 'totalSupply', 'expectedValue': newBigNumber(50)}, + {'variable': 'allowance.blacklisterAccount.arbitraryAccount2', 'expectedValue': newBigNumber(50)}, {'variable': 'isAccountBlacklisted.arbitraryAccount', 'expectedValue': true} ] await expectRevert(token.transferFrom(Accounts.blacklisterAccount, Accounts.arbitraryAccount, 50, {from: Accounts.arbitraryAccount2})); @@ -203,7 +203,7 @@ async function run_tests(newToken, accounts) { await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)} + {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount)} ] await checkVariables([token], [customVars]); @@ -212,10 +212,10 @@ async function run_tests(newToken, accounts) { await token.blacklist(Accounts.arbitraryAccount, {from: Accounts.blacklisterAccount}); customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - 50)}, - {'variable': 'balances.arbitraryAccount2', 'expectedValue': new BigNumber(50)}, - {'variable': 'totalSupply', 'expectedValue': new BigNumber(50)}, - {'variable': 'allowance.arbitraryAccount2.arbitraryAccount', 'expectedValue': new BigNumber(50)}, + {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - 50)}, + {'variable': 'balances.arbitraryAccount2', 'expectedValue': newBigNumber(50)}, + {'variable': 'totalSupply', 'expectedValue': newBigNumber(50)}, + {'variable': 'allowance.arbitraryAccount2.arbitraryAccount', 'expectedValue': newBigNumber(50)}, {'variable': 'isAccountBlacklisted.arbitraryAccount', 'expectedValue': true} ] await expectRevert(token.transferFrom(Accounts.arbitraryAccount2, Accounts.pauserAccount, 50, {from: Accounts.arbitraryAccount})); @@ -226,7 +226,7 @@ async function run_tests(newToken, accounts) { await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)} + {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount)} ] await checkVariables([token], [customVars]); @@ -235,10 +235,10 @@ async function run_tests(newToken, accounts) { 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.arbitraryAccount2', 'expectedValue': new BigNumber(50)}, + {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - 50)}, + {'variable': 'balances.arbitraryAccount', 'expectedValue': newBigNumber(50)}, + {'variable': 'totalSupply', 'expectedValue': newBigNumber(50)}, + {'variable': 'allowance.arbitraryAccount.arbitraryAccount2', 'expectedValue': newBigNumber(50)}, {'variable': 'isAccountBlacklisted.arbitraryAccount', 'expectedValue': true} ] await expectRevert(token.transferFrom(Accounts.arbitraryAccount, Accounts.pauserAccount, 50, {from: Accounts.arbitraryAccount2})); @@ -249,7 +249,7 @@ async function run_tests(newToken, accounts) { await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)} + {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount)} ] await checkVariables([token], [customVars]); @@ -257,10 +257,10 @@ async function run_tests(newToken, accounts) { 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.arbitraryAccount2', 'expectedValue': new BigNumber(50)}, + {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - 50)}, + {'variable': 'balances.arbitraryAccount', 'expectedValue': newBigNumber(50)}, + {'variable': 'totalSupply', 'expectedValue': newBigNumber(50)}, + {'variable': 'allowance.arbitraryAccount.arbitraryAccount2', 'expectedValue': newBigNumber(50)}, ] await expectRevert(token.transferFrom(Accounts.arbitraryAccount, Accounts.pauserAccount, 60, {from: Accounts.arbitraryAccount2})); await checkVariables([token], [customVars]); @@ -270,7 +270,7 @@ async function run_tests(newToken, accounts) { await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); var customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)} + {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount)} ] await checkVariables([token], [customVars]); @@ -279,10 +279,10 @@ async function run_tests(newToken, accounts) { 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.arbitraryAccount2', 'expectedValue': new BigNumber(50)}, + {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - 50)}, + {'variable': 'balances.arbitraryAccount', 'expectedValue': newBigNumber(50)}, + {'variable': 'totalSupply', 'expectedValue': newBigNumber(50)}, + {'variable': 'allowance.arbitraryAccount.arbitraryAccount2', 'expectedValue': newBigNumber(50)}, {'variable': 'paused', 'expectedValue': true} ] await expectRevert(token.transferFrom(Accounts.arbitraryAccount, Accounts.pauserAccount, 50, {from: Accounts.arbitraryAccount2})); @@ -295,16 +295,16 @@ async function run_tests(newToken, accounts) { await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); var customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)} + {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount)} ] await checkVariables([token], [customVars]); await token.mint(Accounts.arbitraryAccount, 50, {from: Accounts.minterAccount}); 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': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - 50)}, + {'variable': 'balances.arbitraryAccount', 'expectedValue': newBigNumber(50)}, + {'variable': 'totalSupply', 'expectedValue': newBigNumber(50)} ] await expectRevert(token.transfer("0x0", 50, {from: Accounts.arbitraryAccount})); await checkVariables([token], [customVars]); @@ -314,16 +314,16 @@ async function run_tests(newToken, accounts) { await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)} + {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount)} ] await checkVariables([token], [customVars]); await token.mint(Accounts.arbitraryAccount, 50, {from: Accounts.minterAccount}); var 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': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - 50)}, + {'variable': 'balances.arbitraryAccount', 'expectedValue': newBigNumber(50)}, + {'variable': 'totalSupply', 'expectedValue': newBigNumber(50)} ] await expectRevert(token.transfer(Accounts.pauserAccount, amount, {from: Accounts.arbitraryAccount})); await checkVariables([token], [customVars]); @@ -333,7 +333,7 @@ async function run_tests(newToken, accounts) { await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)} + {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount)} ] await checkVariables([token], [customVars]); @@ -341,9 +341,9 @@ async function run_tests(newToken, accounts) { await token.blacklist(Accounts.arbitraryAccount, {from: Accounts.blacklisterAccount}); customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - 50)}, - {'variable': 'balances.arbitraryAccount2', 'expectedValue': new BigNumber(50)}, - {'variable': 'totalSupply', 'expectedValue': new BigNumber(50)}, + {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - 50)}, + {'variable': 'balances.arbitraryAccount2', 'expectedValue': newBigNumber(50)}, + {'variable': 'totalSupply', 'expectedValue': newBigNumber(50)}, {'variable': 'isAccountBlacklisted.arbitraryAccount', 'expectedValue': true} ] await expectRevert(token.transfer(Accounts.arbitraryAccount, 50, {from: Accounts.arbitraryAccount2})); @@ -354,7 +354,7 @@ async function run_tests(newToken, accounts) { await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)} + {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount)} ] await checkVariables([token], [customVars]); @@ -362,9 +362,9 @@ async function run_tests(newToken, accounts) { 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': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - 50)}, + {'variable': 'balances.arbitraryAccount', 'expectedValue': newBigNumber(50)}, + {'variable': 'totalSupply', 'expectedValue': newBigNumber(50)}, {'variable': 'isAccountBlacklisted.arbitraryAccount', 'expectedValue': true} ] await expectRevert(token.transfer(Accounts.tokenOwnerAccount, 50, {from: Accounts.arbitraryAccount})); @@ -375,7 +375,7 @@ async function run_tests(newToken, accounts) { await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); var customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)} + {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount)} ] await checkVariables([token], [customVars]); @@ -383,9 +383,9 @@ async function run_tests(newToken, accounts) { 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': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - 50)}, + {'variable': 'balances.arbitraryAccount', 'expectedValue': newBigNumber(50)}, + {'variable': 'totalSupply', 'expectedValue': newBigNumber(50)}, {'variable': 'paused', 'expectedValue': true} ] await expectRevert(token.transfer(Accounts.tokenOwnerAccount, 50, {from: Accounts.arbitraryAccount})); @@ -416,7 +416,7 @@ async function run_tests(newToken, accounts) { await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); var customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)} + {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount)} ] await expectRevert(token.removeMinter(Accounts.minterAccount, {from: Accounts.arbitraryAccount})); await checkVariables([token], [customVars]); @@ -428,7 +428,7 @@ async function run_tests(newToken, accounts) { await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); var customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)} + {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount)} ] await expectRevert(token.burn(amount, {from: Accounts.minterAccount})); await checkVariables([token], [customVars]); @@ -439,9 +439,9 @@ async function run_tests(newToken, accounts) { await token.mint(Accounts.minterAccount, amount, {from: Accounts.minterAccount}); var customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(0)}, - {'variable': 'balances.minterAccount', 'expectedValue': new BigNumber(amount)}, - {'variable': 'totalSupply', 'expectedValue': new BigNumber(amount)} + {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(0)}, + {'variable': 'balances.minterAccount', 'expectedValue': newBigNumber(amount)}, + {'variable': 'totalSupply', 'expectedValue': newBigNumber(amount)} ] await expectRevert(token.burn(-1, {from: Accounts.minterAccount})); await checkVariables([token], [customVars]); @@ -451,7 +451,7 @@ async function run_tests(newToken, accounts) { await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); var customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)} + {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount)} ] await checkVariables([token], [customVars]); @@ -459,9 +459,9 @@ async function run_tests(newToken, accounts) { await token.blacklist(Accounts.minterAccount, {from: Accounts.blacklisterAccount}); customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - 50)}, - {'variable': 'balances.minterAccount', 'expectedValue': new BigNumber(50)}, - {'variable': 'totalSupply', 'expectedValue': new BigNumber(50)}, + {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - 50)}, + {'variable': 'balances.minterAccount', 'expectedValue': newBigNumber(50)}, + {'variable': 'totalSupply', 'expectedValue': newBigNumber(50)}, {'variable': 'isAccountBlacklisted.minterAccount', 'expectedValue': true} ] await expectRevert(token.burn(50, {from: Accounts.minterAccount})); @@ -472,7 +472,7 @@ async function run_tests(newToken, accounts) { await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); var customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)} + {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount)} ] await checkVariables([token], [customVars]); @@ -480,9 +480,9 @@ async function run_tests(newToken, accounts) { await token.pause({from: Accounts.pauserAccount}); customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - 50)}, - {'variable': 'balances.minterAccount', 'expectedValue': new BigNumber(50)}, - {'variable': 'totalSupply', 'expectedValue': new BigNumber(50)}, + {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - 50)}, + {'variable': 'balances.minterAccount', 'expectedValue': newBigNumber(50)}, + {'variable': 'totalSupply', 'expectedValue': newBigNumber(50)}, {'variable': 'paused', 'expectedValue': true} ] await expectRevert(token.burn(50, {from: Accounts.minterAccount})); @@ -493,16 +493,16 @@ async function run_tests(newToken, accounts) { await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); var customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)} + {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount)} ] await checkVariables([token], [customVars]); await token.mint(Accounts.minterAccount, 50, {from: Accounts.minterAccount}); customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - 50)}, - {'variable': 'balances.minterAccount', 'expectedValue': new BigNumber(50)}, - {'variable': 'totalSupply', 'expectedValue': new BigNumber(50)} + {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - 50)}, + {'variable': 'balances.minterAccount', 'expectedValue': newBigNumber(50)}, + {'variable': 'totalSupply', 'expectedValue': newBigNumber(50)} ] await expectRevert(token.burn(50, {from: Accounts.arbitraryAccount})); await checkVariables([token], [customVars]); @@ -512,25 +512,25 @@ async function run_tests(newToken, accounts) { await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); var customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)} + {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount)} ] await checkVariables([token], [customVars]); await token.mint(Accounts.minterAccount, 50, {from: Accounts.minterAccount}); customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - 50)}, - {'variable': 'balances.minterAccount', 'expectedValue': new BigNumber(50)}, - {'variable': 'totalSupply', 'expectedValue': new BigNumber(50)} + {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - 50)}, + {'variable': 'balances.minterAccount', 'expectedValue': newBigNumber(50)}, + {'variable': 'totalSupply', 'expectedValue': newBigNumber(50)} ] await checkVariables([token], [customVars]); await token.removeMinter(Accounts.minterAccount, {from: Accounts.masterMinterAccount}); customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': false}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(0)}, - {'variable': 'balances.minterAccount', 'expectedValue': new BigNumber(50)}, - {'variable': 'totalSupply', 'expectedValue': new BigNumber(50)} + {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(0)}, + {'variable': 'balances.minterAccount', 'expectedValue': newBigNumber(50)}, + {'variable': 'totalSupply', 'expectedValue': newBigNumber(50)} ] await expectRevert(token.burn(50, {from: Accounts.minterAccount})); await checkVariables([token], [customVars]); @@ -609,7 +609,7 @@ async function run_tests(newToken, accounts) { var customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)} + {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount)} ] await checkVariables([token], [customVars]); }); @@ -620,8 +620,8 @@ async function run_tests(newToken, accounts) { await expectRevert(token.burn(0, {from: Accounts.minterAccount})); var customVars = [ {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'balances.minterAccount', 'expectedValue': new BigNumber(amount)}, - {'variable': 'totalSupply', 'expectedValue': new BigNumber(amount)} + {'variable': 'balances.minterAccount', 'expectedValue': newBigNumber(amount)}, + {'variable': 'totalSupply', 'expectedValue': newBigNumber(amount)} ] await checkVariables([token], [customVars]); }); diff --git a/test/basic/PositiveTests.js b/test/basic/PositiveTests.js index 045b18f49..07b1a329c 100644 --- a/test/basic/PositiveTests.js +++ b/test/basic/PositiveTests.js @@ -1,5 +1,5 @@ var tokenUtils = require('./../TokenTestUtils.js');; -var BigNumber = require('bignumber.js'); +var newBigNumber = tokenUtils.newBigNumber; var assertDiff = require('assert-diff'); assertDiff.options.strict = true; @@ -55,7 +55,7 @@ async function run_tests(newToken, accounts) { it('pt020 should approve a spend and set allowed amount', async function () { await token.approve(Accounts.minterAccount, amount, { from: Accounts.arbitraryAccount }); var customVars = [ - { 'variable': 'allowance.arbitraryAccount.minterAccount', 'expectedValue': new BigNumber(amount) } + { 'variable': 'allowance.arbitraryAccount.minterAccount', 'expectedValue': newBigNumber(amount) } ]; await checkVariables([token], [customVars]); }); @@ -87,7 +87,7 @@ async function run_tests(newToken, accounts) { await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); var customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount) } + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) } ]; await checkVariables([token], [customVars]); }); @@ -100,16 +100,16 @@ async function run_tests(newToken, accounts) { await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); var customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount) } + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) } ]; await checkVariables([token], [customVars]); await token.mint(Accounts.arbitraryAccount, mintAmount, { from: Accounts.minterAccount }); customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - mintAmount) }, - { 'variable': 'balances.arbitraryAccount', 'expectedValue': new BigNumber(mintAmount) }, - { 'variable': 'totalSupply', 'expectedValue': new BigNumber(mintAmount) } + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - mintAmount) }, + { 'variable': 'balances.arbitraryAccount', 'expectedValue': newBigNumber(mintAmount) }, + { 'variable': 'totalSupply', 'expectedValue': newBigNumber(mintAmount) } ]; await checkVariables([token], [customVars]); }); @@ -122,18 +122,18 @@ async function run_tests(newToken, accounts) { await token.mint(Accounts.minterAccount, mintAmount, { from: Accounts.minterAccount }); var setup = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(0) }, - { 'variable': 'balances.minterAccount', 'expectedValue': new BigNumber(mintAmount) }, - { 'variable': 'totalSupply', 'expectedValue': new BigNumber(mintAmount) }, + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(0) }, + { 'variable': 'balances.minterAccount', 'expectedValue': newBigNumber(mintAmount) }, + { 'variable': 'totalSupply', 'expectedValue': newBigNumber(mintAmount) }, ]; await checkVariables([token], [setup]); await token.burn(burnAmount, { from: Accounts.minterAccount }); var afterBurn = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(0) }, - { 'variable': 'balances.minterAccount', 'expectedValue': new BigNumber(mintAmount - burnAmount) }, - { 'variable': 'totalSupply', 'expectedValue': new BigNumber(mintAmount - burnAmount) }, + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(0) }, + { 'variable': 'balances.minterAccount', 'expectedValue': newBigNumber(mintAmount - burnAmount) }, + { 'variable': 'totalSupply', 'expectedValue': newBigNumber(mintAmount - burnAmount) }, ]; await checkVariables([token], [afterBurn]); }); @@ -147,16 +147,16 @@ async function run_tests(newToken, accounts) { await token.mint(Accounts.arbitraryAccount, mintAmount, { from: Accounts.minterAccount }) var customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - mintAmount) }, - { 'variable': 'balances.arbitraryAccount', 'expectedValue': new BigNumber(mintAmount) }, - { 'variable': 'totalSupply', 'expectedValue': new BigNumber(mintAmount) } + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - mintAmount) }, + { 'variable': 'balances.arbitraryAccount', 'expectedValue': newBigNumber(mintAmount) }, + { 'variable': 'totalSupply', 'expectedValue': newBigNumber(mintAmount) } ]; await checkVariables([token], [customVars]); await token.removeMinter(Accounts.minterAccount, { from: Accounts.masterMinterAccount }); customVars = [ - { 'variable': 'balances.arbitraryAccount', 'expectedValue': new BigNumber(mintAmount) }, - { 'variable': 'totalSupply', 'expectedValue': new BigNumber(mintAmount) } + { 'variable': 'balances.arbitraryAccount', 'expectedValue': newBigNumber(mintAmount) }, + { 'variable': 'totalSupply', 'expectedValue': newBigNumber(mintAmount) } ]; await checkVariables([token], [customVars]); }); @@ -169,26 +169,26 @@ async function run_tests(newToken, accounts) { await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); var customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount) } + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) } ]; await checkVariables([token], [customVars]); await token.mint(Accounts.arbitraryAccount, mintAmount, { from: Accounts.minterAccount }); customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - mintAmount) }, - { 'variable': 'balances.arbitraryAccount', 'expectedValue': new BigNumber(mintAmount) }, - { 'variable': 'totalSupply', 'expectedValue': new BigNumber(mintAmount) } + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - mintAmount) }, + { 'variable': 'balances.arbitraryAccount', 'expectedValue': newBigNumber(mintAmount) }, + { 'variable': 'totalSupply', 'expectedValue': newBigNumber(mintAmount) } ]; await checkVariables([token], [customVars]); await token.transfer(Accounts.arbitraryAccount2, mintAmount, { from: Accounts.arbitraryAccount }); customVars = [ - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - mintAmount) }, + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - mintAmount) }, { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'balances.arbitraryAccount', 'expectedValue': bigZero }, - { 'variable': 'balances.arbitraryAccount2', 'expectedValue': new BigNumber(mintAmount) }, - { 'variable': 'totalSupply', 'expectedValue': new BigNumber(mintAmount) } + { 'variable': 'balances.arbitraryAccount2', 'expectedValue': newBigNumber(mintAmount) }, + { 'variable': 'totalSupply', 'expectedValue': newBigNumber(mintAmount) } ]; await checkVariables([token], [customVars]); }); @@ -199,16 +199,16 @@ async function run_tests(newToken, accounts) { await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); var customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount) } + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) } ]; await checkVariables([token], [customVars]); await token.mint(Accounts.arbitraryAccount, mintAmount, { from: Accounts.minterAccount }); customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - mintAmount) }, - { 'variable': 'balances.arbitraryAccount', 'expectedValue': new BigNumber(mintAmount) }, - { 'variable': 'totalSupply', 'expectedValue': new BigNumber(mintAmount) } + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - mintAmount) }, + { 'variable': 'balances.arbitraryAccount', 'expectedValue': newBigNumber(mintAmount) }, + { 'variable': 'totalSupply', 'expectedValue': newBigNumber(mintAmount) } ]; await checkVariables([token], [customVars]); @@ -216,10 +216,10 @@ async function run_tests(newToken, accounts) { await token.transferFrom(Accounts.arbitraryAccount, Accounts.arbitraryAccount2, mintAmount, { from: Accounts.masterMinterAccount }); customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - mintAmount) }, + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - mintAmount) }, { 'variable': 'balances.arbitraryAccount', 'expectedValue': bigZero }, - { 'variable': 'balances.arbitraryAccount2', 'expectedValue': new BigNumber(mintAmount) }, - { 'variable': 'totalSupply', 'expectedValue': new BigNumber(mintAmount) } + { 'variable': 'balances.arbitraryAccount2', 'expectedValue': newBigNumber(mintAmount) }, + { 'variable': 'totalSupply', 'expectedValue': newBigNumber(mintAmount) } ]; await checkVariables([token], [customVars]); }); diff --git a/test/extended/ExtendedPositiveTests.js b/test/extended/ExtendedPositiveTests.js index 0eba21532..28cc2f35b 100644 --- a/test/extended/ExtendedPositiveTests.js +++ b/test/extended/ExtendedPositiveTests.js @@ -1,5 +1,5 @@ var tokenUtils = require('./../TokenTestUtils.js'); -var BigNumber = require('bignumber.js'); +var newBigNumber = tokenUtils.newBigNumber; var assertDiff = require('assert-diff'); assertDiff.options.strict = true; @@ -32,7 +32,6 @@ async function run_tests(newToken, accounts) { assert.equal(proxy.address, token.address); }); - // Paused it('ept001 should changeAdmin while paused', async function () { @@ -90,7 +89,7 @@ async function run_tests(newToken, accounts) { await token.pause({ from: Accounts.pauserAccount }); var isAMinter = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount) }, + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) }, { 'variable': 'paused', 'expectedValue': true } ]; await checkVariables([token], [isAMinter]); @@ -98,7 +97,7 @@ async function run_tests(newToken, accounts) { await token.removeMinter(Accounts.minterAccount, { from: Accounts.masterMinterAccount }); var notAMinter = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': false }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(0) }, + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(0) }, { 'variable': 'paused', 'expectedValue': true } ]; await checkVariables([token], [notAMinter]); @@ -309,7 +308,7 @@ async function run_tests(newToken, accounts) { await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); var result = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount) }, + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) }, { 'variable': 'isAccountBlacklisted.masterMinterAccount', 'expectedValue': true } ]; await checkVariables([token], [result]); @@ -320,7 +319,7 @@ async function run_tests(newToken, accounts) { await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); var result = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount) }, + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) }, { 'variable': 'isAccountBlacklisted.minterAccount', 'expectedValue': true }, ]; await checkVariables([token], [result]); @@ -331,7 +330,7 @@ async function run_tests(newToken, accounts) { await token.blacklist(Accounts.masterMinterAccount, { from: Accounts.blacklisterAccount }); var customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount) }, + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) }, { 'variable': 'isAccountBlacklisted.masterMinterAccount', 'expectedValue': true }, ]; await checkVariables([token], [customVars]); @@ -339,7 +338,7 @@ async function run_tests(newToken, accounts) { await token.removeMinter(Accounts.minterAccount, { from: Accounts.masterMinterAccount }); customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': false }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(0) }, + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(0) }, { 'variable': 'isAccountBlacklisted.masterMinterAccount', 'expectedValue': true }, ]; await checkVariables([token], [customVars]); @@ -350,7 +349,7 @@ async function run_tests(newToken, accounts) { await token.blacklist(Accounts.minterAccount, { from: Accounts.blacklisterAccount }); var customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount) }, + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) }, { 'variable': 'isAccountBlacklisted.minterAccount', 'expectedValue': true }, ]; await checkVariables([token], [customVars]); @@ -358,7 +357,7 @@ async function run_tests(newToken, accounts) { await token.removeMinter(Accounts.minterAccount, { from: Accounts.masterMinterAccount }); customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': false }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(0) }, + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(0) }, { 'variable': 'isAccountBlacklisted.minterAccount', 'expectedValue': true }, ]; await checkVariables([token], [customVars]); diff --git a/test/minting/MintP0_ArgumentTests.js b/test/minting/MintP0_ArgumentTests.js index cac6a38a0..99a5e4bfa 100644 --- a/test/minting/MintP0_ArgumentTests.js +++ b/test/minting/MintP0_ArgumentTests.js @@ -4,11 +4,12 @@ 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.js'); +var newBigNumber = tokenUtils.newBigNumber; var checkMINTp0 = tokenUtils.checkMINTp0; var expectRevert = tokenUtils.expectRevert; var expectJump = tokenUtils.expectJump; +var expectError = tokenUtils.expectError; var bigZero = tokenUtils.bigZero; var maxAmount = tokenUtils.maxAmount; @@ -19,6 +20,7 @@ var AccountUtils = require('./../AccountUtils.js'); var Accounts = AccountUtils.Accounts; var getAccountState = AccountUtils.getAccountState; var MintControllerState = AccountUtils.MintControllerState; +var addressEquals = AccountUtils.addressEquals; var initializeTokenWithProxyAndMintController = mintUtils.initializeTokenWithProxyAndMintController; var checkMintControllerState = mintUtils.checkMintControllerState; @@ -64,7 +66,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { // 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); + assert.isTrue(addressEquals(Accounts.minterAccount, actualMinter)); }); it('arg004 configureController(msg.sender, M) works', async function () { @@ -80,7 +82,8 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { }); it('arg006 configureController(C, 0) throws', async function () { - await expectRevert(mintController.configureController(Accounts.controller1Account, zeroAddress, {from: Accounts.mintOwnerAccount})); + await expectError(mintController.configureController(Accounts.controller1Account, zeroAddress, {from: Accounts + .mintOwnerAccount}), "Worker must be a non-zero address"); }); it('arg007 removeController(0) works', async function () { @@ -91,7 +94,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { // 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); + assert.isTrue(addressEquals(Accounts.minterAccount, actualMinter)); // remove 0 await mintController.removeController(zeroAddress, {from: Accounts.mintOwnerAccount}); @@ -132,7 +135,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; expectedTokenState.push( { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(0) } + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(0) } ); await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); }); @@ -146,7 +149,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; expectedTokenState.push( { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(oldAllowance) } + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(oldAllowance) } ); await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); }); @@ -158,7 +161,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; expectedTokenState.push( { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(maxAmount) } + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(maxAmount) } ); await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); }); @@ -172,7 +175,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; expectedTokenState.push( { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount) } + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) } ); await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); }); @@ -186,7 +189,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; expectedTokenState.push( { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(2*amount) } + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(2*amount) } ); await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); }); diff --git a/test/minting2/MintControllerTests.js b/test/minting2/MintControllerTests.js index 4a27c6bec..b285ac94c 100644 --- a/test/minting2/MintControllerTests.js +++ b/test/minting2/MintControllerTests.js @@ -1,9 +1,10 @@ var MintController = artifacts.require('minting/MintController'); -var BigNumber = require('bignumber.js'); var tokenUtils = require('./../TokenTestUtils.js'); +var newBigNumber = tokenUtils.newBigNumber; var checkMINTp0 = tokenUtils.checkMINTp0; var expectRevert = tokenUtils.expectRevert; +var expectError = tokenUtils.expectError; var bigZero = tokenUtils.bigZero; var clone = require('clone'); @@ -35,8 +36,8 @@ async function run_tests(newToken, accounts) { await token.mint(Accounts.arbitraryAccount, amount, {from: Accounts.minterAccount}); expectedTokenState.push( { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'balances.arbitraryAccount', 'expectedValue': new BigNumber(amount) }, - { 'variable': 'totalSupply', 'expectedValue': new BigNumber(amount)} + { 'variable': 'balances.arbitraryAccount', 'expectedValue': newBigNumber(amount) }, + { 'variable': 'totalSupply', 'expectedValue': newBigNumber(amount)} ); await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); }); @@ -82,7 +83,7 @@ async function run_tests(newToken, accounts) { expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; expectedTokenState.push( { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount) }, + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) }, ); await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); @@ -95,11 +96,11 @@ async function run_tests(newToken, accounts) { }); it('only controller removes a minter', async function () { - await expectRevert(mintController.removeMinter({from: Accounts.controller1Account})); + await expectError(mintController.removeMinter({from: Accounts.controller1Account}), "Sender must be a controller"); }); it('only controller configures a minter', async function () { - await expectRevert(mintController.configureMinter(0, {from: Accounts.controller1Account})); + await expectError(mintController.configureMinter(0, {from: Accounts.controller1Account}), "Sender must be a controller"); }); it('increment minter allowance', async function () { @@ -110,7 +111,7 @@ async function run_tests(newToken, accounts) { expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; expectedTokenState.push( { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount) }, + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) }, ); await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); @@ -119,13 +120,13 @@ async function run_tests(newToken, accounts) { expectedTokenState = [ { 'variable': 'masterMinter', 'expectedValue': mintController.address }, { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount*2) }, + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount*2) }, ]; await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); }); it('only controller increments allowance', async function () { - await expectRevert(mintController.incrementMinterAllowance(0, {from: Accounts.controller1Account})); + await expectError(mintController.incrementMinterAllowance(0, {from: Accounts.controller1Account}), "Sender must be a controller"); }); it('only active minters can have allowance incremented', async function () { @@ -136,7 +137,7 @@ async function run_tests(newToken, accounts) { await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); // increment minter allowance - await expectRevert(mintController.incrementMinterAllowance(amount, {from: Accounts.controller1Account})); + await expectError(mintController.incrementMinterAllowance(amount, {from: Accounts.controller1Account}), "Can only increment allowance for enabled minter"); }); } diff --git a/test/minting2/MintP0_ABITests.js b/test/minting2/MintP0_ABITests.js index d51edcf33..6e161d805 100644 --- a/test/minting2/MintP0_ABITests.js +++ b/test/minting2/MintP0_ABITests.js @@ -2,7 +2,6 @@ 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.js'); var checkMINTp0 = tokenUtils.checkMINTp0; var expectRevert = tokenUtils.expectRevert; diff --git a/test/minting3/MintP0_BasicTests.js b/test/minting3/MintP0_BasicTests.js index 57a1de5c7..388120c80 100644 --- a/test/minting3/MintP0_BasicTests.js +++ b/test/minting3/MintP0_BasicTests.js @@ -2,11 +2,12 @@ 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.js'); +var newBigNumber = tokenUtils.newBigNumber; var checkMINTp0 = tokenUtils.checkMINTp0; var expectRevert = tokenUtils.expectRevert; var expectJump = tokenUtils.expectJump; +var expectError = tokenUtils.expectError; var bigZero = tokenUtils.bigZero; var maxAmount = tokenUtils.maxAmount; @@ -17,6 +18,7 @@ var AccountUtils = require('./../AccountUtils.js'); var Accounts = AccountUtils.Accounts; var getAccountState = AccountUtils.getAccountState; var MintControllerState = AccountUtils.MintControllerState; +var addressEquals = AccountUtils.addressEquals; var initializeTokenWithProxyAndMintController = mintUtils.initializeTokenWithProxyAndMintController; var checkMintControllerState = mintUtils.checkMintControllerState; @@ -44,7 +46,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { it('bt001 Constructor - owner is msg.sender', async function () { var newMintController = await MintController.new(token.address, {from: Accounts.arbitraryAccount}); var owner = await newMintController.owner(); - assert.equal(owner, Accounts.arbitraryAccount); + assert.isTrue(addressEquals(owner, Accounts.arbitraryAccount)); }); it('bt002 transferOwnership works when owner is msg.sender', async function () { @@ -103,7 +105,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { }); it('bt010 removeMinter reverts when msg.sender is not a controller', async function () { - await expectRevert(mintController.removeMinter({from: Accounts.controller1Account})); + await expectError(mintController.removeMinter({from: Accounts.controller1Account}), "Sender must be a controller"); }); it('bt011 removeMinter sets minters[M] to 0', async function () { @@ -115,7 +117,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; expectedTokenState.push( { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount) } + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) } ); await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); @@ -127,7 +129,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { }); it('bt012 configureMinter reverts when msg.sender is not a controller', async function () { - await expectRevert(mintController.configureMinter(50, {from: Accounts.controller1Account})); + await expectError(mintController.configureMinter(50, {from: Accounts.controller1Account}), "Sender must be a controller"); }); it('bt013 configureMinter works when controllers[msg.sender]=M', async function () { @@ -140,13 +142,13 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; expectedTokenState.push( { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount) } + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) } ); await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); }); it('bt014 incrementMinterAllowance reverts if msg.sender is not a controller', async function () { - await expectRevert(mintController.incrementMinterAllowance(50, {from: Accounts.controller1Account})); + await expectError(mintController.incrementMinterAllowance(50, {from: Accounts.controller1Account}), "Sender must be a controller"); }); it('bt015 incrementMinterAllowance works when controllers[msg.sender]=M', async function () { @@ -159,7 +161,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; expectedTokenState.push( { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount) } + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) } ); await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); }); @@ -231,7 +233,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { it('bt024 Constructor sets minterManager', async function () { var minterManagerAddress = await mintController.minterManager(); - assert.equal(token.address, minterManagerAddress); + assert.isTrue(addressEquals(token.address, minterManagerAddress)); }); it('bt025 setMinterManager(x) works when existing minterManager = 0', async function () { @@ -293,7 +295,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; expectedTokenState.push( { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount) } + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) } ); await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); @@ -331,7 +333,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; expectedTokenState.push( { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount) } + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) } ); await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); }); @@ -366,7 +368,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; expectedTokenState.push( { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount) } + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) } ); await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); }); @@ -375,7 +377,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { var amount = 64; await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - var minterManager = FiatToken.at(await mintController.minterManager()); + var minterManager = await FiatToken.at(await mintController.minterManager()); var isMinter = await minterManager.isMinter(Accounts.minterAccount); assert.isFalse(isMinter); @@ -383,7 +385,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; expectedTokenState.push( { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount) } + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) } ); await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); }); @@ -393,7 +395,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); await mintController.configureMinter(0, {from: Accounts.controller1Account}); - var minterManager = FiatToken.at(await mintController.minterManager()); + var minterManager = await FiatToken.at(await mintController.minterManager()); var isMinter = await minterManager.isMinter(Accounts.minterAccount); assert.isTrue(isMinter); @@ -401,7 +403,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; expectedTokenState.push( { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount) } + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) } ); await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); }); @@ -410,7 +412,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { var amount = 64; await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - var minterManager = FiatToken.at(await mintController.minterManager()); + var minterManager = await FiatToken.at(await mintController.minterManager()); var isMinter = await minterManager.isMinter(Accounts.minterAccount); assert.isFalse(isMinter); @@ -424,7 +426,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); await mintController.configureMinter(0, {from: Accounts.controller1Account}); - var minterManager = FiatToken.at(await mintController.minterManager()); + var minterManager = await FiatToken.at(await mintController.minterManager()); var isMinter = await minterManager.isMinter(Accounts.minterAccount); assert.isTrue(isMinter); @@ -437,11 +439,11 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { var amount = 64; await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - var minterManager = FiatToken.at(await mintController.minterManager()); + var minterManager = await FiatToken.at(await mintController.minterManager()); var isMinter = await minterManager.isMinter(Accounts.minterAccount); assert.isFalse(isMinter); - await expectRevert(mintController.incrementMinterAllowance(amount, {from: Accounts.controller1Account})); + await expectError(mintController.incrementMinterAllowance(amount, {from: Accounts.controller1Account}), "Can only increment allowance for enabled minter"); expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); }); @@ -451,7 +453,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); await mintController.configureMinter(0, {from: Accounts.controller1Account}); - var minterManager = FiatToken.at(await mintController.minterManager()); + var minterManager = await FiatToken.at(await mintController.minterManager()); var isMinter = await minterManager.isMinter(Accounts.minterAccount); assert.isTrue(isMinter); @@ -459,13 +461,13 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; expectedTokenState.push( { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount) } + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) } ); await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); }); it('bt045 constructor - minterManager.isMinter[ALL] is false', async function () { - var minterManager = FiatToken.at(await mintController.minterManager()); + var minterManager = await FiatToken.at(await mintController.minterManager()); var isMinterMappingEval = async function(accountAddress) { return await minterManager.isMinter(accountAddress); @@ -478,7 +480,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { }); it('bt046 constructor - minterManager.minterAllowance[ALL] = 0', async function () { - var minterManager = FiatToken.at(await mintController.minterManager()); + var minterManager = await FiatToken.at(await mintController.minterManager()); var minterAllowanceMapping = async function(accountAddress) { return await minterManager.minterAllowance(accountAddress); @@ -486,7 +488,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { var minterAllowanceResults = await getAccountState(minterAllowanceMapping, Accounts); for(var account in Accounts) { - assert(new BigNumber(minterAllowanceResults[account]).isEqualTo(new BigNumber(0))); + assert(minterAllowanceResults[account].isZero()); } }); @@ -495,15 +497,15 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); await mintController.configureMinter(0, {from: Accounts.controller1Account}); - var minterManager = FiatToken.at(await mintController.minterManager()); + var minterManager = await FiatToken.at(await mintController.minterManager()); var minterAllowance = await minterManager.minterAllowance(Accounts.minterAccount); - assert((new BigNumber(minterAllowance)).isEqualTo(new BigNumber(0))); + assert(minterAllowance.isZero()); 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(amount) } + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) } ); await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); }); @@ -514,21 +516,21 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); await mintController.configureMinter(initialAmount, {from: Accounts.controller1Account}); - var minterManager = FiatToken.at(await mintController.minterManager()); + var minterManager = await FiatToken.at(await mintController.minterManager()); var minterAllowance = await minterManager.minterAllowance(Accounts.minterAccount); - assert((new BigNumber(minterAllowance)).isEqualTo(new BigNumber(initialAmount))); + assert(minterAllowance.cmp(newBigNumber(initialAmount))==0); await mintController.incrementMinterAllowance(incrementAmount, {from: Accounts.controller1Account}); expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; expectedTokenState.push( { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(initialAmount + incrementAmount) } + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(initialAmount + incrementAmount) } ); await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); }); it('bt049 incrementMinterAllowance(M,amt) reverts when minterAllowance[M] + amt > 2^256', async function () { - var initialAmount = "0x" + ((new BigNumber(maxAmount)).minus(new BigNumber(45))).toString(16); + var initialAmount = "0x" + newBigNumber(maxAmount).sub(newBigNumber(45)).toString(16,64); var incrementAmount = 64; await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); await mintController.configureMinter(initialAmount, {from: Accounts.controller1Account}); @@ -536,7 +538,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; expectedTokenState.push( { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(initialAmount) } + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(initialAmount) } ); await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); @@ -549,15 +551,15 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); await mintController.configureMinter(0, {from: Accounts.controller1Account}); - var minterManager = FiatToken.at(await mintController.minterManager()); + var minterManager = await FiatToken.at(await mintController.minterManager()); var minterAllowance = await minterManager.minterAllowance(Accounts.minterAccount); - assert((new BigNumber(minterAllowance)).isEqualTo(new BigNumber(0))); + assert(minterAllowance.cmp(newBigNumber(0))==0); await mintController.configureMinter(amount, {from: Accounts.controller1Account}); expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; expectedTokenState.push( { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount) } + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) } ); await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); }); @@ -567,15 +569,15 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); await mintController.configureMinter(amount, {from: Accounts.controller1Account}); - var minterManager = FiatToken.at(await mintController.minterManager()); + var minterManager = await FiatToken.at(await mintController.minterManager()); var minterAllowance = await minterManager.minterAllowance(Accounts.minterAccount); - assert((new BigNumber(minterAllowance)).isEqualTo(new BigNumber(amount))); + assert(minterAllowance.cmp(newBigNumber(amount))==0); await mintController.configureMinter(2* amount, {from: Accounts.controller1Account}); expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; expectedTokenState.push( { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(2*amount) } + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(2*amount) } ); await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); }); @@ -590,7 +592,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; expectedTokenState.push( { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount) } + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) } ); await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); }); @@ -600,9 +602,9 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); await mintController.configureMinter(0, {from: Accounts.controller1Account}); - var minterManager = FiatToken.at(await mintController.minterManager()); + var minterManager = await FiatToken.at(await mintController.minterManager()); var minterAllowance = await minterManager.minterAllowance(Accounts.minterAccount); - assert((new BigNumber(minterAllowance)).isEqualTo(new BigNumber(0))); + assert(minterAllowance.isZero()); await mintController.removeMinter({from: Accounts.controller1Account}); expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; @@ -614,9 +616,9 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); await mintController.configureMinter(amount, {from: Accounts.controller1Account}); - var minterManager = FiatToken.at(await mintController.minterManager()); + var minterManager = await FiatToken.at(await mintController.minterManager()); var minterAllowance = await minterManager.minterAllowance(Accounts.minterAccount); - assert((new BigNumber(minterAllowance)).isEqualTo(new BigNumber(amount))); + assert(minterAllowance.cmp(newBigNumber(amount))==0); await mintController.removeMinter({from: Accounts.controller1Account}); expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; diff --git a/test/misc/MiscTests.js b/test/misc/MiscTests.js index ef4060db5..13eea02d5 100644 --- a/test/misc/MiscTests.js +++ b/test/misc/MiscTests.js @@ -1,7 +1,7 @@ var FiatTokenProxy = artifacts.require('FiatTokenProxy'); var tokenUtils = require('./../TokenTestUtils.js');; -var BigNumber = require('bignumber.js'); +var newBigNumber = tokenUtils.newBigNumber; var assertDiff = require('assert-diff'); assertDiff.options.strict = true; @@ -21,6 +21,7 @@ var FiatToken = tokenUtils.FiatToken; var AccountUtils = require('./../AccountUtils.js'); var Accounts = AccountUtils.Accounts; +var addressEquals = AccountUtils.addressEquals; var maxAmount = "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"; var amount = 100; @@ -32,7 +33,7 @@ async function run_tests(newToken, accounts) { var tokenConfig = await initializeTokenWithProxy(rawToken); proxy = tokenConfig.proxy; token = tokenConfig.token; - assert.equal(proxy.address, token.address); + assert.isTrue(addressEquals(proxy.address, token.address)); }); @@ -57,10 +58,10 @@ async function run_tests(newToken, accounts) { await token.transfer(Accounts.arbitraryAccount, mintAmount, { from: Accounts.arbitraryAccount }); var customVars = [ - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - mintAmount) }, + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - mintAmount) }, { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'balances.arbitraryAccount', 'expectedValue': new BigNumber(mintAmount) }, - { 'variable': 'totalSupply', 'expectedValue': new BigNumber(mintAmount) } + { 'variable': 'balances.arbitraryAccount', 'expectedValue': newBigNumber(mintAmount) }, + { 'variable': 'totalSupply', 'expectedValue': newBigNumber(mintAmount) } ]; await checkVariables([token], [customVars]); }); @@ -75,9 +76,9 @@ async function run_tests(newToken, accounts) { 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) }, - { 'variable': 'balances.arbitraryAccount', 'expectedValue': new BigNumber(mintAmount) }, - { 'variable': 'totalSupply', 'expectedValue': new BigNumber(mintAmount) } + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - mintAmount) }, + { 'variable': 'balances.arbitraryAccount', 'expectedValue': newBigNumber(mintAmount) }, + { 'variable': 'totalSupply', 'expectedValue': newBigNumber(mintAmount) } ]; await checkVariables([token], [customVars]); }); @@ -92,9 +93,9 @@ async function run_tests(newToken, accounts) { await token.transferFrom(Accounts.arbitraryAccount, Accounts.arbitraryAccount, mintAmount, { from: Accounts.arbitraryAccount }); customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - mintAmount) }, - { 'variable': 'balances.arbitraryAccount', 'expectedValue': new BigNumber(mintAmount) }, - { 'variable': 'totalSupply', 'expectedValue': new BigNumber(mintAmount) } + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - mintAmount) }, + { 'variable': 'balances.arbitraryAccount', 'expectedValue': newBigNumber(mintAmount) }, + { 'variable': 'totalSupply', 'expectedValue': newBigNumber(mintAmount) } ]; await checkVariables([token], [customVars]); }); @@ -105,16 +106,16 @@ async function run_tests(newToken, accounts) { await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); var customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount) } + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) } ]; await checkVariables([token], [customVars]); await token.mint(Accounts.minterAccount, mintAmount, { from: Accounts.minterAccount }); customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - mintAmount) }, - { 'variable': 'balances.minterAccount', 'expectedValue': new BigNumber(mintAmount) }, - { 'variable': 'totalSupply', 'expectedValue': new BigNumber(mintAmount) } + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - mintAmount) }, + { 'variable': 'balances.minterAccount', 'expectedValue': newBigNumber(mintAmount) }, + { 'variable': 'totalSupply', 'expectedValue': newBigNumber(mintAmount) } ]; await checkVariables([token], [customVars]); }); @@ -125,7 +126,7 @@ async function run_tests(newToken, accounts) { await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); var customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount) } + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) } ]; await checkVariables([token], [customVars]); @@ -133,10 +134,10 @@ async function run_tests(newToken, accounts) { await token.approve(Accounts.arbitraryAccount, amount, { from: Accounts.arbitraryAccount }); customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - mintAmount) }, - { 'variable': 'balances.arbitraryAccount', 'expectedValue': new BigNumber(mintAmount) }, - { 'variable': 'totalSupply', 'expectedValue': new BigNumber(mintAmount) }, - { 'variable': 'allowance.arbitraryAccount.arbitraryAccount', 'expectedValue': new BigNumber(amount) } + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - mintAmount) }, + { 'variable': 'balances.arbitraryAccount', 'expectedValue': newBigNumber(mintAmount) }, + { 'variable': 'totalSupply', 'expectedValue': newBigNumber(mintAmount) }, + { 'variable': 'allowance.arbitraryAccount.arbitraryAccount', 'expectedValue': newBigNumber(amount) } ]; await checkVariables([token], [customVars]); }); @@ -145,7 +146,7 @@ async function run_tests(newToken, accounts) { await token.configureMinter(Accounts.masterMinterAccount, amount, { from: Accounts.masterMinterAccount }); var customVars = [ { 'variable': 'isAccountMinter.masterMinterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.masterMinterAccount', 'expectedValue': new BigNumber(amount) } + { 'variable': 'minterAllowance.masterMinterAccount', 'expectedValue': newBigNumber(amount) } ]; await checkVariables([token], [customVars]); }); @@ -158,8 +159,8 @@ async function run_tests(newToken, accounts) { 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) }, + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) }, + { 'variable': 'minterAllowance.arbitraryAccount', 'expectedValue': newBigNumber(amount) }, ]; await checkVariables([token], [customVars]); }); @@ -175,10 +176,10 @@ async function run_tests(newToken, accounts) { 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.arbitraryAccount2', 'expectedValue': new BigNumber(mintAmount1 + mintAmount2) }, - { 'variable': 'totalSupply', 'expectedValue': new BigNumber(mintAmount1 + mintAmount2) }, + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - mintAmount1) }, + { 'variable': 'minterAllowance.arbitraryAccount', 'expectedValue': newBigNumber(amount - mintAmount2) }, + { 'variable': 'balances.arbitraryAccount2', 'expectedValue': newBigNumber(mintAmount1 + mintAmount2) }, + { 'variable': 'totalSupply', 'expectedValue': newBigNumber(mintAmount1 + mintAmount2) }, ]; await checkVariables([token], [customVars]); }); @@ -194,9 +195,9 @@ async function run_tests(newToken, accounts) { 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.arbitraryAccount2', 'expectedValue': new BigNumber(mintAmount1 + mintAmount2) }, - { 'variable': 'totalSupply', 'expectedValue': new BigNumber(mintAmount1 + mintAmount2) }, + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - mintAmount1) }, + { 'variable': 'balances.arbitraryAccount2', 'expectedValue': newBigNumber(mintAmount1 + mintAmount2) }, + { 'variable': 'totalSupply', 'expectedValue': newBigNumber(mintAmount1 + mintAmount2) }, ]; await checkVariables([token], [customVars]); }); @@ -209,8 +210,8 @@ async function run_tests(newToken, accounts) { 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) }, + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) }, + { 'variable': 'minterAllowance.arbitraryAccount', 'expectedValue': newBigNumber(amount) }, ]; await checkVariables([token], [customVars]); @@ -219,8 +220,8 @@ async function run_tests(newToken, accounts) { var customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'isAccountMinter.arbitraryAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - adjustment) }, - { 'variable': 'minterAllowance.arbitraryAccount', 'expectedValue': new BigNumber(amount + adjustment) }, + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - adjustment) }, + { 'variable': 'minterAllowance.arbitraryAccount', 'expectedValue': newBigNumber(amount + adjustment) }, ]; await checkVariables([token], [customVars]); }); @@ -234,9 +235,9 @@ async function run_tests(newToken, accounts) { var customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'isAccountMinter.arbitraryAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - mintAmount) }, - { 'variable': 'balances.arbitraryAccount2', 'expectedValue': new BigNumber(mintAmount) }, - { 'variable': 'totalSupply', 'expectedValue': new BigNumber(mintAmount) }, + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - mintAmount) }, + { 'variable': 'balances.arbitraryAccount2', 'expectedValue': newBigNumber(mintAmount) }, + { 'variable': 'totalSupply', 'expectedValue': newBigNumber(mintAmount) }, ]; await expectRevert(token.mint(Accounts.arbitraryAccount2, mintAmount, { from: Accounts.arbitraryAccount })); await checkVariables([token], [customVars]); @@ -252,8 +253,8 @@ async function run_tests(newToken, accounts) { { 'variable': 'paused', 'expectedValue': true }, { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'isAccountMinter.arbitraryAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount) }, - { 'variable': 'minterAllowance.arbitraryAccount', 'expectedValue': new BigNumber(amount) } + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) }, + { 'variable': 'minterAllowance.arbitraryAccount', 'expectedValue': newBigNumber(amount) } ]; await expectRevert(token.mint(Accounts.pauserAccount, mintAmount, { from: Accounts.minterAccount })); await expectRevert(token.mint(Accounts.pauserAccount, mintAmount, { from: Accounts.arbitraryAccount })); @@ -270,11 +271,11 @@ async function run_tests(newToken, accounts) { 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': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) }, + { 'variable': 'minterAllowance.arbitraryAccount', 'expectedValue': newBigNumber(amount - mintAmount) }, { 'variable': 'isAccountBlacklisted.minterAccount', 'expectedValue': true }, - { 'variable': 'totalSupply', 'expectedValue': new BigNumber(mintAmount) }, - { 'variable': 'balances.arbitraryAccount2', 'expectedValue': new BigNumber(mintAmount) }, + { 'variable': 'totalSupply', 'expectedValue': newBigNumber(mintAmount) }, + { 'variable': 'balances.arbitraryAccount2', 'expectedValue': newBigNumber(mintAmount) }, ]; await expectRevert(token.mint(Accounts.arbitraryAccount2, mintAmount, { from: Accounts.minterAccount })); await checkVariables([token], [customVars]); @@ -284,10 +285,10 @@ async function run_tests(newToken, accounts) { 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.arbitraryAccount2', 'expectedValue': new BigNumber(mintAmount + mintAmount) }, + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - mintAmount) }, + { 'variable': 'minterAllowance.arbitraryAccount', 'expectedValue': newBigNumber(amount - mintAmount) }, + { 'variable': 'totalSupply', 'expectedValue': newBigNumber(mintAmount + mintAmount) }, + { 'variable': 'balances.arbitraryAccount2', 'expectedValue': newBigNumber(mintAmount + mintAmount) }, ]; await checkVariables([token], [customVars]); }); @@ -304,11 +305,11 @@ async function run_tests(newToken, accounts) { 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.minterAccount', 'expectedValue': new BigNumber(mintAmount1) }, - { 'variable': 'balances.arbitraryAccount', 'expectedValue': new BigNumber(mintAmount2) }, - { 'variable': 'totalSupply', 'expectedValue': new BigNumber(mintAmount1 + mintAmount2) }, + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - mintAmount1) }, + { 'variable': 'minterAllowance.arbitraryAccount', 'expectedValue': newBigNumber(amount - mintAmount2) }, + { 'variable': 'balances.minterAccount', 'expectedValue': newBigNumber(mintAmount1) }, + { 'variable': 'balances.arbitraryAccount', 'expectedValue': newBigNumber(mintAmount2) }, + { 'variable': 'totalSupply', 'expectedValue': newBigNumber(mintAmount1 + mintAmount2) }, ]; await checkVariables([token], [customVars]); @@ -317,11 +318,11 @@ async function run_tests(newToken, accounts) { 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.minterAccount', 'expectedValue': new BigNumber(mintAmount1 - burnAmount) }, - { 'variable': 'balances.arbitraryAccount', 'expectedValue': new BigNumber(mintAmount2 - burnAmount) }, - { 'variable': 'totalSupply', 'expectedValue': new BigNumber(mintAmount1 + mintAmount2 - burnAmount - burnAmount) }, + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - mintAmount1) }, + { 'variable': 'minterAllowance.arbitraryAccount', 'expectedValue': newBigNumber(amount - mintAmount2) }, + { 'variable': 'balances.minterAccount', 'expectedValue': newBigNumber(mintAmount1 - burnAmount) }, + { 'variable': 'balances.arbitraryAccount', 'expectedValue': newBigNumber(mintAmount2 - burnAmount) }, + { 'variable': 'totalSupply', 'expectedValue': newBigNumber(mintAmount1 + mintAmount2 - burnAmount - burnAmount) }, ]; await checkVariables([token], [customVars]); }); @@ -345,8 +346,8 @@ async function run_tests(newToken, accounts) { it('ms036 should get allowance for same address', async function() { await token.approve(Accounts.arbitraryAccount, amount, {from: Accounts.arbitraryAccount}); - var allowance = new BigNumber(await token.allowance(Accounts.arbitraryAccount, Accounts.arbitraryAccount)); - assert(allowance.isEqualTo(new BigNumber(amount))); + var allowance = newBigNumber(await token.allowance(Accounts.arbitraryAccount, Accounts.arbitraryAccount)); + assert(allowance.cmp(newBigNumber(amount))==0); }); // Return value @@ -372,7 +373,7 @@ async function run_tests(newToken, accounts) { await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); var customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount) } + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) } ]; assert(await token.mint.call(Accounts.arbitraryAccount, mintAmount, { from: Accounts.minterAccount })); await checkVariables([token], [customVars]); @@ -388,7 +389,7 @@ async function run_tests(newToken, accounts) { await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); var customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount) } + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) } ]; await checkVariables([token], [customVars]); @@ -396,10 +397,10 @@ async function run_tests(newToken, accounts) { await token.approve(Accounts.masterMinterAccount, mintAmount, { from: Accounts.arbitraryAccount }); customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - mintAmount) }, - { 'variable': 'balances.arbitraryAccount', 'expectedValue': new BigNumber(mintAmount) }, - { 'variable': 'totalSupply', 'expectedValue': new BigNumber(mintAmount) }, - { 'variable': 'allowance.arbitraryAccount.masterMinterAccount', 'expectedValue': new BigNumber(mintAmount)}, + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - mintAmount) }, + { 'variable': 'balances.arbitraryAccount', 'expectedValue': newBigNumber(mintAmount) }, + { 'variable': 'totalSupply', 'expectedValue': newBigNumber(mintAmount) }, + { 'variable': 'allowance.arbitraryAccount.masterMinterAccount', 'expectedValue': newBigNumber(mintAmount)}, ]; assert(await token.transferFrom.call(Accounts.arbitraryAccount, Accounts.pauserAccount, mintAmount, { from: Accounts.masterMinterAccount })); await checkVariables([token], [customVars]); @@ -411,16 +412,16 @@ async function run_tests(newToken, accounts) { await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); var customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount) } + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) } ]; await checkVariables([token], [customVars]); await token.mint(Accounts.arbitraryAccount, mintAmount, { from: Accounts.minterAccount }); customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - mintAmount) }, - { 'variable': 'balances.arbitraryAccount', 'expectedValue': new BigNumber(mintAmount) }, - { 'variable': 'totalSupply', 'expectedValue': new BigNumber(mintAmount) } + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - mintAmount) }, + { 'variable': 'balances.arbitraryAccount', 'expectedValue': newBigNumber(mintAmount) }, + { 'variable': 'totalSupply', 'expectedValue': newBigNumber(mintAmount) } ]; assert(await token.transfer.call(Accounts.pauserAccount, mintAmount, { from: Accounts.arbitraryAccount })); await checkVariables([token], [customVars]); @@ -442,7 +443,7 @@ async function run_tests(newToken, accounts) { it('ms046 initialized should be 0 before initialization', async function() { var rawToken = await newToken(); var newProxy = await FiatTokenProxy.new(rawToken.address, { from: Accounts.arbitraryAccount }); - var token = FiatToken.at(newProxy.address); + var token = await FiatToken.at(newProxy.address); var initialized = await getInitializedV1(token); assert.equal("0x00", initialized); }); @@ -451,7 +452,7 @@ async function run_tests(newToken, accounts) { await token.configureMinter(Accounts.minterAccount, maxAmount, { from: Accounts.masterMinterAccount }); var customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(maxAmount) } + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(maxAmount) } ]; await checkVariables([token], [customVars]); }); @@ -460,16 +461,16 @@ async function run_tests(newToken, accounts) { await token.configureMinter(Accounts.minterAccount, maxAmount, { from: Accounts.masterMinterAccount }); var customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(maxAmount) } + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(maxAmount) } ]; await checkVariables([token], [customVars]); await token.mint(Accounts.arbitraryAccount, maxAmount, { from: Accounts.minterAccount }); customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(0) }, - { 'variable': 'balances.arbitraryAccount', 'expectedValue': new BigNumber(maxAmount) }, - { 'variable': 'totalSupply', 'expectedValue': new BigNumber(maxAmount) } + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(0) }, + { 'variable': 'balances.arbitraryAccount', 'expectedValue': newBigNumber(maxAmount) }, + { 'variable': 'totalSupply', 'expectedValue': newBigNumber(maxAmount) } ]; await checkVariables([token], [customVars]); }); @@ -479,8 +480,8 @@ async function run_tests(newToken, accounts) { await token.mint(Accounts.minterAccount, maxAmount, { from: Accounts.minterAccount }); customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'balances.minterAccount', 'expectedValue': new BigNumber(maxAmount) }, - { 'variable': 'totalSupply', 'expectedValue': new BigNumber(maxAmount) } + { 'variable': 'balances.minterAccount', 'expectedValue': newBigNumber(maxAmount) }, + { 'variable': 'totalSupply', 'expectedValue': newBigNumber(maxAmount) } ]; await checkVariables([token], [customVars]); @@ -496,17 +497,17 @@ async function run_tests(newToken, accounts) { await token.mint(Accounts.arbitraryAccount, maxAmount, { from: Accounts.minterAccount }); customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'balances.arbitraryAccount', 'expectedValue': new BigNumber(maxAmount) }, - { 'variable': 'totalSupply', 'expectedValue': new BigNumber(maxAmount) } + { 'variable': 'balances.arbitraryAccount', 'expectedValue': newBigNumber(maxAmount) }, + { 'variable': 'totalSupply', 'expectedValue': newBigNumber(maxAmount) } ]; await checkVariables([token], [customVars]); 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.arbitraryAccount2', 'expectedValue': new BigNumber(maxAmount) } + { 'variable': 'balances.arbitraryAccount', 'expectedValue': newBigNumber(maxAmount) }, + { 'variable': 'totalSupply', 'expectedValue': newBigNumber(maxAmount) }, + { 'variable': 'allowance.arbitraryAccount.arbitraryAccount2', 'expectedValue': newBigNumber(maxAmount) } ]; await checkVariables([token], [customVars]); }); @@ -516,16 +517,16 @@ async function run_tests(newToken, accounts) { await token.mint(Accounts.arbitraryAccount, maxAmount, { from: Accounts.minterAccount }); customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'balances.arbitraryAccount', 'expectedValue': new BigNumber(maxAmount) }, - { 'variable': 'totalSupply', 'expectedValue': new BigNumber(maxAmount) } + { 'variable': 'balances.arbitraryAccount', 'expectedValue': newBigNumber(maxAmount) }, + { 'variable': 'totalSupply', 'expectedValue': newBigNumber(maxAmount) } ]; await checkVariables([token], [customVars]); await token.transfer(Accounts.arbitraryAccount2, maxAmount, {from: Accounts.arbitraryAccount}); customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'balances.arbitraryAccount2', 'expectedValue': new BigNumber(maxAmount) }, - { 'variable': 'totalSupply', 'expectedValue': new BigNumber(maxAmount) }, + { 'variable': 'balances.arbitraryAccount2', 'expectedValue': newBigNumber(maxAmount) }, + { 'variable': 'totalSupply', 'expectedValue': newBigNumber(maxAmount) }, ]; await checkVariables([token], [customVars]); }); @@ -536,17 +537,17 @@ async function run_tests(newToken, accounts) { 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.arbitraryAccount2', 'expectedValue': new BigNumber(maxAmount) } + { 'variable': 'balances.arbitraryAccount', 'expectedValue': newBigNumber(maxAmount) }, + { 'variable': 'totalSupply', 'expectedValue': newBigNumber(maxAmount) }, + { 'variable': 'allowance.arbitraryAccount.arbitraryAccount2', 'expectedValue': newBigNumber(maxAmount) } ]; await checkVariables([token], [customVars]); await token.transferFrom(Accounts.arbitraryAccount, Accounts.arbitraryAccount2, maxAmount, {from: Accounts.arbitraryAccount2}); customVars = [ { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'balances.arbitraryAccount2', 'expectedValue': new BigNumber(maxAmount) }, - { 'variable': 'totalSupply', 'expectedValue': new BigNumber(maxAmount) }, + { 'variable': 'balances.arbitraryAccount2', 'expectedValue': newBigNumber(maxAmount) }, + { 'variable': 'totalSupply', 'expectedValue': newBigNumber(maxAmount) }, ]; await checkVariables([token], [customVars]); }); diff --git a/test/proxy/ProxyNegativeTests.js b/test/proxy/ProxyNegativeTests.js index 9f6150e57..2b3823dad 100644 --- a/test/proxy/ProxyNegativeTests.js +++ b/test/proxy/ProxyNegativeTests.js @@ -1,5 +1,5 @@ var tokenUtils = require('./../TokenTestUtils');; -var BigNumber = require('bignumber.js'); +var newBigNumber = tokenUtils.newBigNumber; var assertDiff = require('assert-diff'); assertDiff.options.strict = true; @@ -22,6 +22,7 @@ var UpgradedFiatTokenNewFields = tokenUtils.UpgradedFiatTokenNewFields; var AccountUtils = require('./../AccountUtils'); var Accounts = AccountUtils.Accounts; +var addressEquals = AccountUtils.addressEquals; var amount = 100; @@ -32,12 +33,13 @@ async function run_tests(newToken, accounts) { var tokenConfig = await initializeTokenWithProxy(rawToken); proxy = tokenConfig.proxy; token = tokenConfig.token; - assert.equal(proxy.address, token.address); + assert.isTrue(addressEquals(proxy.address ,token.address)); }); it('nut002 should fail to switch adminAccount with non-adminAccount as caller', async function () { await expectRevert(proxy.changeAdmin(Accounts.masterMinterAccount, {from: Accounts.masterMinterAccount})); - assert.equal(await proxy.admin({from: Accounts.proxyOwnerAccount}), Accounts.proxyOwnerAccount); + assert.isTrue(addressEquals(await proxy.admin({from: Accounts.proxyOwnerAccount}), Accounts + .proxyOwnerAccount)); customVars = []; await checkVariables([token], [customVars]); }); @@ -81,9 +83,9 @@ async function run_tests(newToken, accounts) { it('nut008 shoud fail to update proxy storage if state-changing function called directly in FiatToken', async function () { await rawToken.initialize(name, symbol, currency, decimals, Accounts.masterMinterAccount, Accounts.pauserAccount, Accounts.blacklisterAccount, Accounts.tokenOwnerAccount); - assert.equal(await rawToken.pauser(), Accounts.pauserAccount); + assert.isTrue(addressEquals(await rawToken.pauser(), Accounts.pauserAccount)); await rawToken.updatePauser(Accounts.masterMinterAccount, {from: Accounts.tokenOwnerAccount}); - assert.equal(await rawToken.pauser(), Accounts.masterMinterAccount); + assert.isTrue(addressEquals(await rawToken.pauser(), Accounts.masterMinterAccount)); customVars = []; await checkVariables([token], [customVars]); @@ -92,7 +94,7 @@ async function run_tests(newToken, accounts) { it('nut009 should fail to call upgradeTo with non-adminAccount', async function () { var upgradedToken = await UpgradedFiatToken.new(); await expectRevert(proxy.upgradeTo(upgradedToken.address, {from:Accounts.masterMinterAccount})); - var finalToken = FiatToken.at(proxy.address); + var finalToken = await FiatToken.at(proxy.address); var implementation = await proxy.implementation({from: Accounts.proxyOwnerAccount}); finalToken.proxiedTokenAddress = implementation; @@ -104,7 +106,7 @@ async function run_tests(newToken, accounts) { var upgradedToken = await UpgradedFiatTokenNewFields.new(); const initializeData = encodeCall('initialize', ['bool', 'address', 'uint256'], [true, Accounts.pauserAccount, 12]); await expectRevert(proxy.upgradeToAndCall(upgradedToken.address, initializeData, { from: Accounts.masterMinterAccount })); - var finalToken = FiatToken.at(proxy.address); + var finalToken = await FiatToken.at(proxy.address); var implementation = await proxy.implementation({from: Accounts.proxyOwnerAccount}); finalToken.proxiedTokenAddress = implementation; @@ -124,11 +126,11 @@ async function run_tests(newToken, accounts) { await expectRevert(proxy.upgradeToAndCall(upgradedToken.address, data, { from: Accounts.proxyOwnerAccount })); customVars = [ - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - mintAmount) }, + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - mintAmount) }, { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'balances.arbitraryAccount', 'expectedValue': bigZero }, - { 'variable': 'balances.arbitraryAccount2', 'expectedValue': new BigNumber(mintAmount) }, - { 'variable': 'totalSupply', 'expectedValue': new BigNumber(mintAmount) }, + { 'variable': 'balances.arbitraryAccount2', 'expectedValue': newBigNumber(mintAmount) }, + { 'variable': 'totalSupply', 'expectedValue': newBigNumber(mintAmount) }, ]; await checkVariables([token], [customVars]); }); diff --git a/test/proxy/ProxyPositiveTests.js b/test/proxy/ProxyPositiveTests.js index c90a8195f..69adf3296 100644 --- a/test/proxy/ProxyPositiveTests.js +++ b/test/proxy/ProxyPositiveTests.js @@ -1,5 +1,5 @@ var tokenUtils = require('./../TokenTestUtils');; -var BigNumber = require('bignumber.js'); +var newBigNumber = tokenUtils.newBigNumber; var assertDiff = require('assert-diff'); assertDiff.options.strict = true; @@ -30,6 +30,8 @@ var sendRawTransaction = abiUtils.sendRawTransaction; var AccountUtils = require('./../AccountUtils'); var Accounts = AccountUtils.Accounts; var AccountPrivateKeys = AccountUtils.AccountPrivateKeys; +var addressEquals = AccountUtils.addressEquals; +var addressNotEquals = AccountUtils.addressNotEquals; var amount = 100; @@ -40,7 +42,7 @@ async function run_tests(newToken, accounts) { var tokenConfig = await initializeTokenWithProxy(rawToken); proxy = tokenConfig.proxy; token = tokenConfig.token; - assert.equal(proxy.address, token.address); + assert.isTrue(addressEquals(proxy.address, token.address)); }); it('upt001 should upgradeTo new contract and preserve data field values', async function () { @@ -55,11 +57,11 @@ async function run_tests(newToken, accounts) { var newToken = tokenConfig.token; customVars = [ - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - mintAmount) }, + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - mintAmount) }, { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'balances.arbitraryAccount', 'expectedValue': bigZero }, - { 'variable': 'balances.arbitraryAccount2', 'expectedValue': new BigNumber(mintAmount) }, - { 'variable': 'totalSupply', 'expectedValue': new BigNumber(mintAmount) }, + { 'variable': 'balances.arbitraryAccount2', 'expectedValue': newBigNumber(mintAmount) }, + { 'variable': 'totalSupply', 'expectedValue': newBigNumber(mintAmount) }, { 'variable': 'proxiedTokenAddress', 'expectedValue': upgradedToken.address } ]; await checkVariables([newToken], [customVars]); @@ -76,19 +78,19 @@ async function run_tests(newToken, accounts) { const initializeData = encodeCall('initV2', ['bool', 'address', 'uint256'], [true, Accounts.pauserAccount, 12]); await proxy.upgradeToAndCall(upgradedToken.address, initializeData, { from: Accounts.proxyOwnerAccount }) newProxiedToken = await UpgradedFiatTokenNewFields.at(proxy.address); - assert.equal(newProxiedToken.address, proxy.address); - assert.notEqual(newProxiedToken.address, upgradedToken.address); + assert.isTrue(addressEquals(newProxiedToken.address, proxy.address)); + addressNotEquals(newProxiedToken.address, upgradedToken.address); assert.equal(await newProxiedToken.newBool(), true); - assert.equal(await newProxiedToken.newAddress(), Accounts.pauserAccount); - assert.equal((new BigNumber(12)).isEqualTo(await newProxiedToken.newUint()), true); + assert.isTrue(addressEquals(await newProxiedToken.newAddress(), Accounts.pauserAccount)); + assert.equal(newBigNumber(12).cmp(await newProxiedToken.newUint()), 0); customVars = [ - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - mintAmount) }, + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - mintAmount) }, { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'balances.arbitraryAccount', 'expectedValue': bigZero }, - { 'variable': 'balances.arbitraryAccount2', 'expectedValue': new BigNumber(mintAmount) }, - { 'variable': 'totalSupply', 'expectedValue': new BigNumber(mintAmount) }, + { 'variable': 'balances.arbitraryAccount2', 'expectedValue': newBigNumber(mintAmount) }, + { 'variable': 'totalSupply', 'expectedValue': newBigNumber(mintAmount) }, { 'variable': 'proxiedTokenAddress', 'expectedValue': upgradedToken.address } ]; await checkVariables([newProxiedToken], [customVars]); @@ -105,22 +107,22 @@ async function run_tests(newToken, accounts) { const initializeData = encodeCall('initV2', ['bool', 'address', 'uint256'], [true, Accounts.pauserAccount, 12]); await proxy.upgradeToAndCall(upgradedToken.address, initializeData, { from: Accounts.proxyOwnerAccount }) newProxiedToken = await UpgradedFiatTokenNewFieldsNewLogic.at(proxy.address); - assert.equal(newProxiedToken.address, proxy.address); - assert.notEqual(newProxiedToken.address, upgradedToken.address); + assert.isTrue(addressEquals(newProxiedToken.address, proxy.address)); + addressNotEquals(newProxiedToken.address, upgradedToken.address); assert.equal(await newProxiedToken.newBool(), true); - assert.equal(await newProxiedToken.newAddress(), Accounts.pauserAccount); - assert.equal((new BigNumber(12)).isEqualTo(await newProxiedToken.newUint()), true); + assert.isTrue(addressEquals(await newProxiedToken.newAddress(), Accounts.pauserAccount)); + assert.equal(newBigNumber(12).cmp(await newProxiedToken.newUint()), 0); await newProxiedToken.setNewAddress(Accounts.masterMinterAccount); - assert.equal(await newProxiedToken.newAddress(), Accounts.masterMinterAccount); + assert.isTrue(addressEquals(await newProxiedToken.newAddress(), Accounts.masterMinterAccount)); customVars = [ - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - mintAmount) }, + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - mintAmount) }, { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'balances.arbitraryAccount', 'expectedValue': bigZero }, - { 'variable': 'balances.arbitraryAccount2', 'expectedValue': new BigNumber(mintAmount) }, - { 'variable': 'totalSupply', 'expectedValue': new BigNumber(mintAmount) }, + { 'variable': 'balances.arbitraryAccount2', 'expectedValue': newBigNumber(mintAmount) }, + { 'variable': 'totalSupply', 'expectedValue': newBigNumber(mintAmount) }, { 'variable': 'proxiedTokenAddress', 'expectedValue': upgradedToken.address } ]; await checkVariables([newProxiedToken], [customVars]); @@ -137,7 +139,7 @@ async function run_tests(newToken, accounts) { assert.equal(await proxiedToken.newUint(), 12); assert.equal(await proxiedToken.newBool(), true); - assert.equal(await proxiedToken.newAddress(), Accounts.pauserAccount); + assert.isTrue(addressEquals(await proxiedToken.newAddress(), Accounts.pauserAccount)); customVars = [ { 'variable': 'proxiedTokenAddress', 'expectedValue': upgradedToken.address } @@ -156,10 +158,10 @@ async function run_tests(newToken, accounts) { assert.equal(await proxiedToken.newUint(), 12); assert.equal(await proxiedToken.newBool(), true); - assert.equal(await proxiedToken.newAddress(), Accounts.pauserAccount); + assert.isTrue(addressEquals(await proxiedToken.newAddress(), Accounts.pauserAccount)); await newProxiedToken.setNewAddress(Accounts.masterMinterAccount); - assert.equal(await newProxiedToken.newAddress(), Accounts.masterMinterAccount); + assert.isTrue(addressEquals(await newProxiedToken.newAddress(), Accounts.masterMinterAccount)); customVars = [ { 'variable': 'proxiedTokenAddress', 'expectedValue': upgradedToken.address } @@ -190,11 +192,11 @@ async function run_tests(newToken, accounts) { validateTransferEvent(transfer, Accounts.arbitraryAccount, Accounts.arbitraryAccount2, 1); customVars = [ - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - mintAmount - 1) }, + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - mintAmount - 1) }, { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'balances.arbitraryAccount', 'expectedValue': bigZero }, - { 'variable': 'balances.arbitraryAccount2', 'expectedValue': new BigNumber(mintAmount + 1) }, - { 'variable': 'totalSupply', 'expectedValue': new BigNumber(mintAmount + 1) }, + { 'variable': 'balances.arbitraryAccount2', 'expectedValue': newBigNumber(mintAmount + 1) }, + { 'variable': 'totalSupply', 'expectedValue': newBigNumber(mintAmount + 1) }, { 'variable': 'proxiedTokenAddress', 'expectedValue': upgradedToken.address } ]; await checkVariables([newToken], [customVars]); @@ -232,17 +234,17 @@ async function run_tests(newToken, accounts) { sameToken.proxiedTokenAddress = rawToken.address; customVars = [ - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - mintAmount) }, + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - mintAmount) }, { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, { 'variable': 'balances.arbitraryAccount', 'expectedValue': bigZero }, - { 'variable': 'balances.arbitraryAccount2', 'expectedValue': new BigNumber(mintAmount) }, - { 'variable': 'totalSupply', 'expectedValue': new BigNumber(mintAmount) }, + { 'variable': 'balances.arbitraryAccount2', 'expectedValue': newBigNumber(mintAmount) }, + { 'variable': 'totalSupply', 'expectedValue': newBigNumber(mintAmount) }, ]; await checkVariables([sameToken], [customVars]); }); it('upt009 should check that admin is set correctly by proxy constructor', async function() { - assert.equal(await getAdmin(token), Accounts.proxyOwnerAccount); + assert.isTrue(addressEquals(await getAdmin(token), Accounts.proxyOwnerAccount)); }); it('upt011 should upgradeToAndCall while paused and upgraded contract should be paused as a result', async function () { @@ -252,8 +254,8 @@ async function run_tests(newToken, accounts) { const initializeData = encodeCall('initV2', ['bool', 'address', 'uint256'], [true, Accounts.pauserAccount, 12]); await proxy.upgradeToAndCall(upgradedToken.address, initializeData, { from: Accounts.proxyOwnerAccount }) newProxiedToken = await UpgradedFiatTokenNewFields.at(proxy.address); - assert.equal(newProxiedToken.address, proxy.address); - assert.notEqual(newProxiedToken.address, upgradedToken.address); + assert.isTrue(addressEquals(newProxiedToken.address, proxy.address)); + addressNotEquals(newProxiedToken.address, upgradedToken.address); customVars = [ { 'variable': 'paused', 'expectedValue': true, }, diff --git a/truffle.js b/truffle.js index f0aa71a44..738457419 100644 --- a/truffle.js +++ b/truffle.js @@ -10,6 +10,11 @@ try { } module.exports = { + compilers: { + solc: { + version: "0.4.24" + } + }, networks: { development: { host: "localhost", diff --git a/yarn.lock b/yarn.lock index e8835105d..28b8336e7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1100,6 +1100,10 @@ bluebird@^3.5.0, bluebird@^3.5.1, bluebird@~3.5.1: version "3.5.1" resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.5.1.tgz#d9551f9de98f1fcda1e683d17ee91a0602ee2eb9" +bn-chai@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/bn-chai/-/bn-chai-1.0.1.tgz#5d6e9654162602a527b08a1546e60cfb44213725" + bn.js@4.11.6: version "4.11.6" resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.11.6.tgz#53344adb14617a13f6e8dd2ce28905d1c0ba3215" From d888649fafd62778ec7356b14d0a024798510a77 Mon Sep 17 00:00:00 2001 From: Walker Date: Wed, 9 Jan 2019 00:27:01 -0500 Subject: [PATCH 35/74] line spacing according to Solidity style guide --- contracts/minting/Controller.sol | 37 ++++++++---- contracts/minting/MasterMinter.sol | 13 +++-- contracts/minting/MintController.sol | 85 +++++++++++++++++++++------- 3 files changed, 97 insertions(+), 38 deletions(-) diff --git a/contracts/minting/Controller.sol b/contracts/minting/Controller.sol index 9a7b36f47..c5f3b4557 100644 --- a/contracts/minting/Controller.sol +++ b/contracts/minting/Controller.sol @@ -5,8 +5,8 @@ * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is furnished to -* do so, subject to the following conditions: +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. @@ -14,9 +14,10 @@ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. */ pragma solidity ^0.4.24; @@ -33,11 +34,14 @@ contract Controller is Ownable { // The controller manages a single worker address. mapping(address => address) public controllers; - event ControllerConfigured(address indexed _controller, address indexed _worker); + event ControllerConfigured( + address indexed _controller, + address indexed _worker + ); event ControllerRemoved(address indexed _controller); /** - * @dev ensure that the caller is the controller of a non-zero worker address + * @dev ensure that caller is the controller of a non-zero worker address */ modifier onlyController() { require(controllers[msg.sender] != address(0), "The value of controller[msg.sender] must be non-zero."); @@ -51,9 +55,16 @@ contract Controller is Ownable { /** * @dev set the controller of a particular _worker - * Argument _worker must not be 0x00, call removeController(_controller) instead. + * + * Argument _worker must not be 0x00. Call removeController(_controller) + * instead to disable the controller. */ - function configureController(address _controller, address _worker) onlyOwner public returns (bool) { + function configureController( + address _controller, + address _worker + ) + onlyOwner public returns (bool) + { require(_worker != address(0), "Worker must be a non-zero address."); controllers[_controller] = _worker; emit ControllerConfigured(_controller, _worker); @@ -63,9 +74,13 @@ contract Controller is Ownable { /** * @dev disables a controller by setting its worker to address(0); */ - function removeController(address _controller) onlyOwner public returns (bool) { + function removeController( + address _controller + ) + onlyOwner public returns (bool) + { controllers[_controller] = address(0); emit ControllerRemoved(_controller); return true; } -} \ No newline at end of file +} diff --git a/contracts/minting/MasterMinter.sol b/contracts/minting/MasterMinter.sol index 56c009f0d..f2ba86558 100644 --- a/contracts/minting/MasterMinter.sol +++ b/contracts/minting/MasterMinter.sol @@ -5,8 +5,8 @@ * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is furnished to -* do so, subject to the following conditions: +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. @@ -14,9 +14,10 @@ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. */ pragma solidity ^0.4.24; @@ -28,4 +29,4 @@ contract MasterMinter is MintController { constructor(address _minterManager) MintController(_minterManager) public { } -} \ No newline at end of file +} diff --git a/contracts/minting/MintController.sol b/contracts/minting/MintController.sol index 6113a1e88..748c9ae7c 100644 --- a/contracts/minting/MintController.sol +++ b/contracts/minting/MintController.sol @@ -5,8 +5,8 @@ * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is furnished to -* do so, subject to the following conditions: +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. @@ -14,9 +14,10 @@ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. */ pragma solidity ^0.4.24; @@ -29,7 +30,11 @@ import 'openzeppelin-solidity/contracts/math/SafeMath.sol'; interface MinterManagementInterface { function isMinter(address account) external view returns (bool); function minterAllowance(address minter) external view returns (uint256); - function configureMinter(address minter, uint256 minterAllowedAmount) external returns (bool); + function configureMinter( + address minter, + uint256 minterAllowedAmount + ) + external returns (bool); function removeMinter(address minter) external returns (bool); } @@ -43,10 +48,25 @@ contract MintController is Controller { MinterManagementInterface public minterManager; - event MinterManagerSet(address indexed oldMinterManager, address indexed newMinterManager); - event MinterConfigured(address indexed msgSender, address indexed minter, uint256 allowance); - event MinterRemoved(address indexed msgSender, address indexed minter); - event MinterAllowanceIncrement(address indexed msgSender, address indexed minter, uint256 increment, uint256 newAllowance); + event MinterManagerSet( + address indexed oldMinterManager, + address indexed newMinterManager + ); + event MinterConfigured( + address indexed msgSender, + address indexed minter, + uint256 allowance + ); + event MinterRemoved( + address indexed msgSender, + address indexed minter + ); + event MinterAllowanceIncrement( + address indexed msgSender, + address indexed minter, + uint256 increment, + uint256 newAllowance + ); constructor(address _minterManager) public { minterManager = MinterManagementInterface(_minterManager); @@ -57,7 +77,11 @@ contract MintController is Controller { /** * @dev sets the minterManager */ - function setMinterManager(address _newMinterManager) onlyOwner public returns (bool) { + function setMinterManager( + address _newMinterManager + ) + onlyOwner public returns (bool) + { emit MinterManagerSet(minterManager, _newMinterManager); minterManager = MinterManagementInterface(_newMinterManager); return true; @@ -77,35 +101,54 @@ contract MintController is Controller { /** * @dev Enables the minter and sets its allowance */ - function configureMinter(uint256 newAllowance) onlyController public returns (bool) { + function configureMinter( + uint256 newAllowance + ) + onlyController public returns (bool) + { address minter = controllers[msg.sender]; emit MinterConfigured(msg.sender, minter, newAllowance); return internal_setMinterAllowance(minter, newAllowance); } - /** + /** * @dev Increases the minter allowance if and only if the minter is - * currently active. The controller can safely send a signed incrementMinterAllowance() - * transaction to a minter and not worry about it being used to undo a removeMinter() - * transaction. + * currently active. The controller can safely send a signed + * incrementMinterAllowance() transaction to a minter and not worry + * about it being used to undo a removeMinter() transaction. */ - function incrementMinterAllowance(uint256 allowanceIncrement) onlyController public returns (bool) { + function incrementMinterAllowance( + uint256 allowanceIncrement + ) + onlyController public returns (bool) + { address minter = controllers[msg.sender]; require(minterManager.isMinter(minter), "Can only increment allowance for minters in minterManager."); uint256 currentAllowance = minterManager.minterAllowance(minter); uint256 newAllowance = currentAllowance.add(allowanceIncrement); - emit MinterAllowanceIncrement(msg.sender, minter, allowanceIncrement, newAllowance); + emit MinterAllowanceIncrement( + msg.sender, + minter, + allowanceIncrement, + newAllowance + ); return internal_setMinterAllowance(minter, newAllowance); } // Internal functions /** - * @dev Uses the MinterManagementInterface to enable the minter and set its allowance. + * @dev Uses the MinterManagementInterface to enable the minter and + * set its allowance. */ - function internal_setMinterAllowance(address minter, uint256 newAllowance) internal returns (bool) { + function internal_setMinterAllowance( + address minter, + uint256 newAllowance + ) + internal returns (bool) + { return minterManager.configureMinter(minter, newAllowance); } -} \ No newline at end of file +} From 272d0d28d935544e38e23f4423ce66966a61515b Mon Sep 17 00:00:00 2001 From: Walker Date: Wed, 9 Jan 2019 00:43:09 -0500 Subject: [PATCH 36/74] use double quotes in import statements per style guide --- contracts/minting/Controller.sol | 2 +- contracts/minting/MasterMinter.sol | 3 +-- contracts/minting/MintController.sol | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/contracts/minting/Controller.sol b/contracts/minting/Controller.sol index c5f3b4557..4ba06dbc9 100644 --- a/contracts/minting/Controller.sol +++ b/contracts/minting/Controller.sol @@ -22,7 +22,7 @@ pragma solidity ^0.4.24; -import './../Ownable.sol'; +import "./../Ownable.sol"; /** * @title Controller diff --git a/contracts/minting/MasterMinter.sol b/contracts/minting/MasterMinter.sol index f2ba86558..37b04b2e3 100644 --- a/contracts/minting/MasterMinter.sol +++ b/contracts/minting/MasterMinter.sol @@ -22,11 +22,10 @@ pragma solidity ^0.4.24; -import './MintController.sol'; +import "./MintController.sol"; contract MasterMinter is MintController { constructor(address _minterManager) MintController(_minterManager) public { - } } diff --git a/contracts/minting/MintController.sol b/contracts/minting/MintController.sol index 748c9ae7c..675e7879b 100644 --- a/contracts/minting/MintController.sol +++ b/contracts/minting/MintController.sol @@ -22,8 +22,8 @@ pragma solidity ^0.4.24; -import './Controller.sol'; -import 'openzeppelin-solidity/contracts/math/SafeMath.sol'; +import "./Controller.sol"; +import "openzeppelin-solidity/contracts/math/SafeMath.sol"; // Using an interface for managing minters so that MintController // can be used for managing minters with different contracts. From b0471f22286611f7d842c680bddec0c964500aa5 Mon Sep 17 00:00:00 2001 From: Walker Date: Wed, 9 Jan 2019 00:55:28 -0500 Subject: [PATCH 37/74] remove double space in MintController constructor --- contracts/minting/MintController.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/minting/MintController.sol b/contracts/minting/MintController.sol index 675e7879b..74108d7d7 100644 --- a/contracts/minting/MintController.sol +++ b/contracts/minting/MintController.sol @@ -69,7 +69,7 @@ contract MintController is Controller { ); constructor(address _minterManager) public { - minterManager = MinterManagementInterface(_minterManager); + minterManager = MinterManagementInterface(_minterManager); } // onlyOwner functions From 8b731f8449a93d0ba7fd4d844c932d1191b6b645 Mon Sep 17 00:00:00 2001 From: Walker Date: Wed, 9 Jan 2019 01:00:48 -0500 Subject: [PATCH 38/74] remove extra line in comment of configureController --- contracts/minting/Controller.sol | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/contracts/minting/Controller.sol b/contracts/minting/Controller.sol index 4ba06dbc9..7d3c5d170 100644 --- a/contracts/minting/Controller.sol +++ b/contracts/minting/Controller.sol @@ -54,8 +54,7 @@ contract Controller is Ownable { // onlyOwner functions /** - * @dev set the controller of a particular _worker - * + * @dev set the controller of a particular _worker. * Argument _worker must not be 0x00. Call removeController(_controller) * instead to disable the controller. */ From 15227091b797c37d87dfd566dbada830c964a0e9 Mon Sep 17 00:00:00 2001 From: Walker Date: Fri, 11 Jan 2019 13:01:08 -0500 Subject: [PATCH 39/74] delete unnecessary leading ./ in import Ownable --- contracts/minting/Controller.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/minting/Controller.sol b/contracts/minting/Controller.sol index 7d3c5d170..8a280821f 100644 --- a/contracts/minting/Controller.sol +++ b/contracts/minting/Controller.sol @@ -22,7 +22,7 @@ pragma solidity ^0.4.24; -import "./../Ownable.sol"; +import "../Ownable.sol"; /** * @title Controller From cd0ad7a17e129a94e83a1460b965a49a399132fa Mon Sep 17 00:00:00 2001 From: Walker Date: Fri, 11 Jan 2019 13:12:10 -0500 Subject: [PATCH 40/74] modifiers moved to their own line per style guide --- contracts/minting/Controller.sol | 8 ++++++-- contracts/minting/MintController.sol | 15 +++++++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/contracts/minting/Controller.sol b/contracts/minting/Controller.sol index 8a280821f..692c85e78 100644 --- a/contracts/minting/Controller.sol +++ b/contracts/minting/Controller.sol @@ -62,7 +62,9 @@ contract Controller is Ownable { address _controller, address _worker ) - onlyOwner public returns (bool) + onlyOwner + public + returns (bool) { require(_worker != address(0), "Worker must be a non-zero address."); controllers[_controller] = _worker; @@ -76,7 +78,9 @@ contract Controller is Ownable { function removeController( address _controller ) - onlyOwner public returns (bool) + onlyOwner + public + returns (bool) { controllers[_controller] = address(0); emit ControllerRemoved(_controller); diff --git a/contracts/minting/MintController.sol b/contracts/minting/MintController.sol index 74108d7d7..166cf43f2 100644 --- a/contracts/minting/MintController.sol +++ b/contracts/minting/MintController.sol @@ -80,7 +80,9 @@ contract MintController is Controller { function setMinterManager( address _newMinterManager ) - onlyOwner public returns (bool) + onlyOwner + public + returns (bool) { emit MinterManagerSet(minterManager, _newMinterManager); minterManager = MinterManagementInterface(_newMinterManager); @@ -104,7 +106,9 @@ contract MintController is Controller { function configureMinter( uint256 newAllowance ) - onlyController public returns (bool) + onlyController + public + returns (bool) { address minter = controllers[msg.sender]; emit MinterConfigured(msg.sender, minter, newAllowance); @@ -120,7 +124,9 @@ contract MintController is Controller { function incrementMinterAllowance( uint256 allowanceIncrement ) - onlyController public returns (bool) + onlyController + public + returns (bool) { address minter = controllers[msg.sender]; require(minterManager.isMinter(minter), "Can only increment allowance for minters in minterManager."); @@ -147,7 +153,8 @@ contract MintController is Controller { address minter, uint256 newAllowance ) - internal returns (bool) + internal + returns (bool) { return minterManager.configureMinter(minter, newAllowance); } From 04278df55cf7a6029f43493b63a841d159410c84 Mon Sep 17 00:00:00 2001 From: Walker Date: Fri, 11 Jan 2019 13:13:52 -0500 Subject: [PATCH 41/74] visibility modifiers come first per style guide --- contracts/minting/Controller.sol | 4 ++-- contracts/minting/MintController.sol | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/contracts/minting/Controller.sol b/contracts/minting/Controller.sol index 692c85e78..b5d675308 100644 --- a/contracts/minting/Controller.sol +++ b/contracts/minting/Controller.sol @@ -62,8 +62,8 @@ contract Controller is Ownable { address _controller, address _worker ) - onlyOwner public + onlyOwner returns (bool) { require(_worker != address(0), "Worker must be a non-zero address."); @@ -78,8 +78,8 @@ contract Controller is Ownable { function removeController( address _controller ) - onlyOwner public + onlyOwner returns (bool) { controllers[_controller] = address(0); diff --git a/contracts/minting/MintController.sol b/contracts/minting/MintController.sol index 166cf43f2..af8555ae0 100644 --- a/contracts/minting/MintController.sol +++ b/contracts/minting/MintController.sol @@ -80,8 +80,8 @@ contract MintController is Controller { function setMinterManager( address _newMinterManager ) - onlyOwner public + onlyOwner returns (bool) { emit MinterManagerSet(minterManager, _newMinterManager); @@ -106,8 +106,8 @@ contract MintController is Controller { function configureMinter( uint256 newAllowance ) - onlyController public + onlyController returns (bool) { address minter = controllers[msg.sender]; @@ -124,8 +124,8 @@ contract MintController is Controller { function incrementMinterAllowance( uint256 allowanceIncrement ) - onlyController public + onlyController returns (bool) { address minter = controllers[msg.sender]; From 1503358c29490677fcf0be9429e1bb245c47be98 Mon Sep 17 00:00:00 2001 From: Oliver Hudson <32966763+o-a-hudson@users.noreply.github.com> Date: Fri, 11 Jan 2019 14:22:34 -0500 Subject: [PATCH 42/74] Fixes expectRevert not checking revert string (#250) * Fixes expectRevert not checking revert string * Fixes 0x0 address throwing errors (replaces will full null address) due to web3 upgrade * Updates ganache to version that supports revert strings * Updates lockfile * Fixes incorrect asserts on wrong number of arguments; Fixes 0x0 vs 0x00 in new truffle null address --- contracts/minting/Controller.sol | 2 +- package.json | 2 +- scripts/start-ganache.sh | 2 +- test/TokenTestUtils.js | 22 +++++++---- test/assert/ABITests.test.js | 3 +- test/assert/FiatTokenLegacy.test.js | 3 +- test/basic/NegativeTests.js | 35 ++++++----------- test/minting2/MintControllerTests.js | 8 ++-- test/minting2/MintP0_ABITests.js | 10 ++--- test/minting3/MintP0_BasicTests.js | 8 ++-- test/misc/MiscTests.js | 2 +- test/proxy/ProxyNegativeTests.js | 5 ++- yarn.lock | 57 +++++++++++++++++----------- 13 files changed, 82 insertions(+), 77 deletions(-) diff --git a/contracts/minting/Controller.sol b/contracts/minting/Controller.sol index 9a7b36f47..b6857487d 100644 --- a/contracts/minting/Controller.sol +++ b/contracts/minting/Controller.sol @@ -40,7 +40,7 @@ contract Controller is Ownable { * @dev ensure that the caller is the controller of a non-zero worker address */ modifier onlyController() { - require(controllers[msg.sender] != address(0), "The value of controller[msg.sender] must be non-zero."); + require(controllers[msg.sender] != address(0), "The value of controllers[msg.sender] must be non-zero."); _; } diff --git a/package.json b/package.json index 15c587518..9107d628d 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "ethereumjs-abi": "^0.6.5", "ethereumjs-tx": "1.3.1", "g": "^2.0.1", - "ganache-cli": "6.1.0", + "ganache-cli": "6.2.5", "lodash": "^4.17.10", "mkdirp": "^0.5.1", "npm": "^6.4.1", diff --git a/scripts/start-ganache.sh b/scripts/start-ganache.sh index b01d31ccb..738a0fdde 100755 --- a/scripts/start-ganache.sh +++ b/scripts/start-ganache.sh @@ -1 +1 @@ -./node_modules/ganache-cli/build/cli.node.js --defaultBalanceEther 1000000 --deterministic --a 15 > ganache-blockchain-log.txt & \ No newline at end of file +./node_modules/ganache-cli/cli.js --defaultBalanceEther 1000000 --deterministic --a 15 > ganache-blockchain-log.txt & \ No newline at end of file diff --git a/test/TokenTestUtils.js b/test/TokenTestUtils.js index 750e6032b..1fd22be98 100644 --- a/test/TokenTestUtils.js +++ b/test/TokenTestUtils.js @@ -10,7 +10,7 @@ var BigNumber = require('bignumber.js'); var trueInStorageFormat = "0x01"; var decimals = newBigNumber(10); var bigZero = newBigNumber(0); -var zeroAddress = '0x' + bigZero.toString(16, 40); +var zeroAddress = '0x0000000000000000000000000000000000000000'; var bigHundred = newBigNumber(100); var maxAmount = "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"; var assertDiff = require('assert-diff'); @@ -38,6 +38,11 @@ var implSlot = "0x7050c9e0f4ca769c69bd3a8ef740bc37934f8e2c036e5a723fd8ee048ed3f8 // set to true to enable verbose logging in the tests var debugLogging = false; +// Common solidity error messages +var solidityErrors = { + "argumentType": "argument must be a string, Buffer, ArrayBuffer, Array, or array-like object." +} + // Returns a new BN object function newBigNumber(value) { var hex = new BigNumber(value).toString(16); @@ -544,11 +549,11 @@ async function upgradeTo(proxy, upgradedToken, proxyUpgraderAccount) { } async function expectRevert(contractPromise) { - await expectError(contractPromise, 'error:'); + await expectError(contractPromise, "revert"); } async function expectJump(contractPromise) { - await expectError(contractPromise, 'invalid opcode'); + await expectError(contractPromise, "invalid opcode"); } async function expectError(contractPromise, errorMsg) { @@ -556,9 +561,8 @@ async function expectError(contractPromise, errorMsg) { await contractPromise; assert.fail('Expected error ${errorMsg}, but no error received'); } catch (error) { -// Todo: perform error message check in separate PR -// var correctErrorMsgReceived = error.message.includes(errorMsg); -// assert(correctErrorMsgReceived, `Expected ${errorMsg}, got ${error.message} instead`); + var correctErrorMsgReceived = error.message.includes(errorMsg); + assert(correctErrorMsgReceived, `Expected ${errorMsg}, got ${error.message} instead`); } } @@ -584,10 +588,10 @@ async function getInitializedV1(token) { var initialized; var masterMinterStart; var masterMinterAddress; - if (slot8DataLength == 4) { + if (slot8DataLength == 3) { //Validate proxy not yet initialized for (var i = 0; i <= 20; i++) { - assert.equal("0x00", await web3.eth.getStorageAt(token.address, i)); + assert.equal("0x0", await web3.eth.getStorageAt(token.address, i)); } initialized = slot8Data; } else { @@ -619,8 +623,10 @@ module.exports = { currency: currency, decimals: decimals, bigZero: bigZero, + zeroAddress: zeroAddress, bigHundred: bigHundred, debugLogging: debugLogging, + solidityErrors: solidityErrors, calculateFeeAmount: calculateFeeAmount, checkTransferEventsWithFee: checkTransferEventsWithFee, checkTransferEvents: checkTransferEvents, diff --git a/test/assert/ABITests.test.js b/test/assert/ABITests.test.js index b3847ff5a..f6eedda3e 100644 --- a/test/assert/ABITests.test.js +++ b/test/assert/ABITests.test.js @@ -81,7 +81,6 @@ async function run_tests(newToken, accounts) { AccountPrivateKeys.pauserPrivateKey, token.address); await expectRevert(sendRawTransaction(raw)); - await expectRevert(sendRawTransaction(raw)); }); it('abi005 Pausable constructor is not a function', async function () { @@ -206,7 +205,7 @@ async function run_tests(newToken, accounts) { it('abi028 UpgradeabilityProxy._upgradeTo is internal', async function () { let badData = mockStringAddressEncode('_upgradeTo(string,address)', Accounts.pauserAccount); - let raw = makeRawTransaction( + let raw = await makeRawTransaction( badData, Accounts.tokenOwnerAccount, AccountPrivateKeys.tokenOwnerPrivateKey, diff --git a/test/assert/FiatTokenLegacy.test.js b/test/assert/FiatTokenLegacy.test.js index ac8c90c86..1309ae88f 100644 --- a/test/assert/FiatTokenLegacy.test.js +++ b/test/assert/FiatTokenLegacy.test.js @@ -5,6 +5,7 @@ var currency = tokenUtils.currency; var decimals = tokenUtils.decimals var bigZero = tokenUtils.bigZero; var bigHundred = tokenUtils.bigHundred; +var zeroAddress = tokenUtils.zeroAddress; var mint = tokenUtils.mint; var burn = tokenUtils.burn; var setMinter = tokenUtils.setMinter; @@ -204,7 +205,7 @@ async function run_tests(newToken, accounts) { let allowed = await token.allowance.call(accounts[0], accounts[3]); assert.isTrue(allowed.cmp(newBigNumber(100))==0); - await expectRevert(token.transferFrom(accounts[0], 0, 50, { from: accounts[3] })); + await expectRevert(token.transferFrom(accounts[0], zeroAddress, 50, { from: accounts[3] })); let balance0 = await token.balanceOf(accounts[0]); assert.equal(balance0, 500); diff --git a/test/basic/NegativeTests.js b/test/basic/NegativeTests.js index d275772cc..194bc99fb 100644 --- a/test/basic/NegativeTests.js +++ b/test/basic/NegativeTests.js @@ -23,8 +23,7 @@ var AccountUtils = require('./../AccountUtils.js'); var Accounts = AccountUtils.Accounts; var amount = 100; -let longZero = 0x0000000000000000000000000000000000000000; -let shortZero = 0x00; +var zeroAddress = tokenUtils.zeroAddress; async function run_tests(newToken, accounts) { @@ -97,9 +96,7 @@ async function run_tests(newToken, accounts) { {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount)} ] - await expectRevert(token.mint("0x0", amount, {from: Accounts.minterAccount})); - await expectRevert(token.mint("0x0000000000000000000000000000000000000000", amount, {from: Accounts.minterAccount})); - await expectRevert(token.mint(0x0000000000000000000000000000000000000000, amount, {from: Accounts.minterAccount})); + await expectRevert(token.mint(zeroAddress, amount, {from: Accounts.minterAccount})); await checkVariables([token], [customVars]); }); @@ -151,7 +148,7 @@ async function run_tests(newToken, accounts) { {'variable': 'totalSupply', 'expectedValue': newBigNumber(50)}, {'variable': 'allowance.arbitraryAccount.arbitraryAccount2', 'expectedValue': newBigNumber(50)} ] - await expectRevert(token.transferFrom(Accounts.arbitraryAccount, "0x0", 50, {from: Accounts.arbitraryAccount2})); + await expectRevert(token.transferFrom(Accounts.arbitraryAccount, zeroAddress, 50, {from: Accounts.arbitraryAccount2})); await checkVariables([token], [customVars]); }); @@ -306,7 +303,7 @@ async function run_tests(newToken, accounts) { {'variable': 'balances.arbitraryAccount', 'expectedValue': newBigNumber(50)}, {'variable': 'totalSupply', 'expectedValue': newBigNumber(50)} ] - await expectRevert(token.transfer("0x0", 50, {from: Accounts.arbitraryAccount})); + await expectRevert(token.transfer(zeroAddress, 50, {from: Accounts.arbitraryAccount})); await checkVariables([token], [customVars]); }); @@ -627,47 +624,39 @@ async function run_tests(newToken, accounts) { }); it('nt064 transferOwnership should fail on 0x0', async function () { - await expectRevert(token.transferOwnership(longZero, { from: Accounts.tokenOwnerAccount })); - await expectRevert(token.transferOwnership(shortZero, { from: Accounts.tokenOwnerAccount })); + await expectRevert(token.transferOwnership(zeroAddress, { from: Accounts.tokenOwnerAccount })); }); it('nt057 updateMasterMinter should fail on 0x0', async function () { - await expectRevert(token.updateMasterMinter(longZero, { from: Accounts.tokenOwnerAccount })); - await expectRevert(token.updateMasterMinter(shortZero, { from: Accounts.tokenOwnerAccount })); + await expectRevert(token.updateMasterMinter(zeroAddress, { from: Accounts.tokenOwnerAccount })); }); it('nt058 updatePauser should fail on 0x0', async function () { - await expectRevert(token.updatePauser(longZero, { from: Accounts.tokenOwnerAccount })); - await expectRevert(token.updatePauser(shortZero, { from: Accounts.tokenOwnerAccount })); + await expectRevert(token.updatePauser(zeroAddress, { from: Accounts.tokenOwnerAccount })); }); it('nt059 updateBlacklister should fail on 0x0', async function () { - await expectRevert(token.updateBlacklister(longZero, { from: Accounts.tokenOwnerAccount })); - await expectRevert(token.updateBlacklister(shortZero, { from: Accounts.tokenOwnerAccount })); + await expectRevert(token.updateBlacklister(zeroAddress, { from: Accounts.tokenOwnerAccount })); }); it('nt060 initialize should fail when _masterMinter is 0x0', async function () { rawToken = await newToken(); - await expectRevert(customInitializeTokenWithProxy(rawToken, longZero, Accounts.pauserAccount, Accounts.blacklisterAccount, Accounts.tokenOwnerAccount)); - await expectRevert(customInitializeTokenWithProxy(rawToken, shortZero, Accounts.pauserAccount, Accounts.blacklisterAccount, Accounts.tokenOwnerAccount)); + await expectRevert(customInitializeTokenWithProxy(rawToken, zeroAddress, Accounts.pauserAccount, Accounts.blacklisterAccount, Accounts.tokenOwnerAccount)); }); it('nt061 initialize should fail when _pauser is 0x0', async function () { rawToken = await newToken(); - await expectRevert(customInitializeTokenWithProxy(rawToken, Accounts.masterMinterAccount, longZero, Accounts.blacklisterAccount, Accounts.tokenOwnerAccount)); - await expectRevert(customInitializeTokenWithProxy(rawToken, Accounts.masterMinterAccount, shortZero, Accounts.blacklisterAccount, Accounts.tokenOwnerAccount)); + await expectRevert(customInitializeTokenWithProxy(rawToken, Accounts.masterMinterAccount, zeroAddress, Accounts.blacklisterAccount, Accounts.tokenOwnerAccount)); }); it('nt062 initialize should fail when _blacklister is 0x0', async function () { rawToken = await newToken(); - await expectRevert(customInitializeTokenWithProxy(rawToken, Accounts.masterMinterAccount, Accounts.pauserAccount, longZero, Accounts.tokenOwnerAccount)); - await expectRevert(customInitializeTokenWithProxy(rawToken, Accounts.masterMinterAccount, Accounts.pauserAccount, shortZero, Accounts.tokenOwnerAccount)); + await expectRevert(customInitializeTokenWithProxy(rawToken, Accounts.masterMinterAccount, Accounts.pauserAccount, zeroAddress, Accounts.tokenOwnerAccount)); }); it('nt063 initialize should fail when _owner is 0x0', async function () { rawToken = await newToken(); - await expectRevert(customInitializeTokenWithProxy(rawToken, Accounts.masterMinterAccount, Accounts.pauserAccount, Accounts.blacklisterAccount, longZero)); - await expectRevert(customInitializeTokenWithProxy(rawToken, Accounts.masterMinterAccount, Accounts.pauserAccount, Accounts.blacklisterAccount, shortZero)); + await expectRevert(customInitializeTokenWithProxy(rawToken, Accounts.masterMinterAccount, Accounts.pauserAccount, Accounts.blacklisterAccount, zeroAddress)); }); } diff --git a/test/minting2/MintControllerTests.js b/test/minting2/MintControllerTests.js index b285ac94c..5778e9c88 100644 --- a/test/minting2/MintControllerTests.js +++ b/test/minting2/MintControllerTests.js @@ -96,11 +96,11 @@ async function run_tests(newToken, accounts) { }); it('only controller removes a minter', async function () { - await expectError(mintController.removeMinter({from: Accounts.controller1Account}), "Sender must be a controller"); + await expectError(mintController.removeMinter({from: Accounts.controller1Account}), "The value of controllers[msg.sender] must be non-zero."); }); it('only controller configures a minter', async function () { - await expectError(mintController.configureMinter(0, {from: Accounts.controller1Account}), "Sender must be a controller"); + await expectError(mintController.configureMinter(0, {from: Accounts.controller1Account}), "The value of controllers[msg.sender] must be non-zero."); }); it('increment minter allowance', async function () { @@ -126,7 +126,7 @@ async function run_tests(newToken, accounts) { }); it('only controller increments allowance', async function () { - await expectError(mintController.incrementMinterAllowance(0, {from: Accounts.controller1Account}), "Sender must be a controller"); + await expectError(mintController.incrementMinterAllowance(0, {from: Accounts.controller1Account}), "The value of controllers[msg.sender] must be non-zero."); }); it('only active minters can have allowance incremented', async function () { @@ -137,7 +137,7 @@ async function run_tests(newToken, accounts) { await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); // increment minter allowance - await expectError(mintController.incrementMinterAllowance(amount, {from: Accounts.controller1Account}), "Can only increment allowance for enabled minter"); + await expectError(mintController.incrementMinterAllowance(amount, {from: Accounts.controller1Account}), "Can only increment allowance for minters in minterManager."); }); } diff --git a/test/minting2/MintP0_ABITests.js b/test/minting2/MintP0_ABITests.js index 6e161d805..90d8116ae 100644 --- a/test/minting2/MintP0_ABITests.js +++ b/test/minting2/MintP0_ABITests.js @@ -4,10 +4,10 @@ var FiatToken = artifacts.require('FiatTokenV1'); var tokenUtils = require('./../TokenTestUtils.js'); var checkMINTp0 = tokenUtils.checkMINTp0; -var expectRevert = tokenUtils.expectRevert; -var expectJump = tokenUtils.expectJump; +var expectError = tokenUtils.expectError; var bigZero = tokenUtils.bigZero; var maxAmount = tokenUtils.maxAmount; +var solidityErrors = tokenUtils.solidityErrors; var clone = require('clone'); @@ -20,8 +20,6 @@ var MintControllerState = AccountUtils.MintControllerState; var initializeTokenWithProxyAndMintController = mintUtils.initializeTokenWithProxyAndMintController; var checkMintControllerState = mintUtils.checkMintControllerState; -var zeroAddress = "0x0000000000000000000000000000000000000000"; - var abiUtils = require('./../ABIUtils.js'); var makeRawTransaction = abiUtils.makeRawTransaction; var sendRawTransaction = abiUtils.sendRawTransaction; @@ -55,7 +53,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { Accounts.mintOwnerAccount, AccountPrivateKeys.mintOwnerPrivateKey, mintController.address); - await expectRevert(sendRawTransaction(raw)); + await expectError(sendRawTransaction(raw), solidityErrors.argumentType); }); it('abi101 setOwner is internal', async function () { @@ -65,7 +63,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { Accounts.mintOwnerAccount, AccountPrivateKeys.mintOwnerPrivateKey, mintController.address); - await expectRevert(sendRawTransaction(raw)); + await expectError(sendRawTransaction(raw), solidityErrors.argumentType); }); } diff --git a/test/minting3/MintP0_BasicTests.js b/test/minting3/MintP0_BasicTests.js index 388120c80..2f07e1e45 100644 --- a/test/minting3/MintP0_BasicTests.js +++ b/test/minting3/MintP0_BasicTests.js @@ -105,7 +105,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { }); it('bt010 removeMinter reverts when msg.sender is not a controller', async function () { - await expectError(mintController.removeMinter({from: Accounts.controller1Account}), "Sender must be a controller"); + await expectError(mintController.removeMinter({from: Accounts.controller1Account}), "The value of controllers[msg.sender] must be non-zero."); }); it('bt011 removeMinter sets minters[M] to 0', async function () { @@ -129,7 +129,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { }); it('bt012 configureMinter reverts when msg.sender is not a controller', async function () { - await expectError(mintController.configureMinter(50, {from: Accounts.controller1Account}), "Sender must be a controller"); + await expectError(mintController.configureMinter(50, {from: Accounts.controller1Account}), "The value of controllers[msg.sender] must be non-zero."); }); it('bt013 configureMinter works when controllers[msg.sender]=M', async function () { @@ -148,7 +148,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { }); it('bt014 incrementMinterAllowance reverts if msg.sender is not a controller', async function () { - await expectError(mintController.incrementMinterAllowance(50, {from: Accounts.controller1Account}), "Sender must be a controller"); + await expectError(mintController.incrementMinterAllowance(50, {from: Accounts.controller1Account}), "The value of controllers[msg.sender] must be non-zero."); }); it('bt015 incrementMinterAllowance works when controllers[msg.sender]=M', async function () { @@ -443,7 +443,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { var isMinter = await minterManager.isMinter(Accounts.minterAccount); assert.isFalse(isMinter); - await expectError(mintController.incrementMinterAllowance(amount, {from: Accounts.controller1Account}), "Can only increment allowance for enabled minter"); + await expectError(mintController.incrementMinterAllowance(amount, {from: Accounts.controller1Account}), "Can only increment allowance for minters in minterManager."); expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); }); diff --git a/test/misc/MiscTests.js b/test/misc/MiscTests.js index 13eea02d5..af75b5fa3 100644 --- a/test/misc/MiscTests.js +++ b/test/misc/MiscTests.js @@ -445,7 +445,7 @@ async function run_tests(newToken, accounts) { var newProxy = await FiatTokenProxy.new(rawToken.address, { from: Accounts.arbitraryAccount }); var token = await FiatToken.at(newProxy.address); var initialized = await getInitializedV1(token); - assert.equal("0x00", initialized); + assert.equal("0x0", initialized); }); it('ms047 configureMinter works on amount=2^256-1', async function() { diff --git a/test/proxy/ProxyNegativeTests.js b/test/proxy/ProxyNegativeTests.js index 2b3823dad..eb2b1bdde 100644 --- a/test/proxy/ProxyNegativeTests.js +++ b/test/proxy/ProxyNegativeTests.js @@ -5,6 +5,7 @@ assertDiff.options.strict = true; var bigZero = tokenUtils.bigZero; var bigHundred = tokenUtils.bigHundred; +var zeroAddress = tokenUtils.zeroAddress; var mint = tokenUtils.mint; var expectRevert = tokenUtils.expectRevert; var checkVariables = tokenUtils.checkVariables; @@ -46,7 +47,7 @@ async function run_tests(newToken, accounts) { it('nut003 should fail to upgradeTo to null contract address', async function () { var upgradedToken = await UpgradedFiatToken.new(); - await expectRevert(proxy.upgradeTo("0x0", token, {from: Accounts.proxyOwnerAccount})); + await expectRevert(proxy.upgradeTo(zeroAddress, {from: Accounts.proxyOwnerAccount})); customVars = []; await checkVariables([token], [customVars]); @@ -55,7 +56,7 @@ async function run_tests(newToken, accounts) { it('nut004 should fail to upgradeToAndCall to null contract address', async function () { var upgradedToken = await UpgradedFiatToken.new(); const initializeData = encodeCall('pauser', [], []); - await expectRevert(proxy.upgradeToAndCall("0x0", initializeData, { from: Accounts.proxyOwnerAccount })); + await expectRevert(proxy.upgradeToAndCall(zeroAddress, initializeData, { from: Accounts.proxyOwnerAccount })); customVars = []; await checkVariables([token], [customVars]); diff --git a/yarn.lock b/yarn.lock index 28b8336e7..f36512d7c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1108,7 +1108,7 @@ bn.js@4.11.6: version "4.11.6" resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.11.6.tgz#53344adb14617a13f6e8dd2ce28905d1c0ba3215" -bn.js@^4.10.0, bn.js@^4.11.0, bn.js@^4.11.3, bn.js@^4.11.8, bn.js@^4.4.0, bn.js@^4.8.0: +bn.js@4.11.8, bn.js@^4.10.0, bn.js@^4.11.0, bn.js@^4.11.3, bn.js@^4.11.8, bn.js@^4.4.0, bn.js@^4.8.0: version "4.11.8" resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.11.8.tgz#2cde09eb5ee341f484746bb0309b3253b1b1442f" @@ -2976,12 +2976,14 @@ g@^2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/g/-/g-2.0.1.tgz#0b5963ebd0ca70e3bc8c6766934a021821c8b857" -ganache-cli@6.1.0: - version "6.1.0" - resolved "https://registry.yarnpkg.com/ganache-cli/-/ganache-cli-6.1.0.tgz#486c846497204b644166b5f0f74c9b41d02bdc25" +ganache-cli@6.2.5: + version "6.2.5" + resolved "https://registry.yarnpkg.com/ganache-cli/-/ganache-cli-6.2.5.tgz#efda5115fa3a0c62d7f5729fdd78da70ca55b1ad" + integrity sha512-E4SP8QNeuc2N/ojFoCK+08OYHX8yrtGeFtipZmJPPTQ6U8Hmq3JcbXZDxQfChPQUY5mtbRSwptJa4EtiQyJjAQ== dependencies: - source-map-support "^0.5.3" - webpack-cli "^2.0.9" + bn.js "4.11.8" + source-map-support "0.5.9" + yargs "11.1.0" gauge@~2.7.3: version "2.7.4" @@ -6866,6 +6868,14 @@ source-map-resolve@^0.5.0: source-map-url "^0.4.0" urix "^0.1.0" +source-map-support@0.5.9: + version "0.5.9" + resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.9.tgz#41bc953b2534267ea2d605bccfa7bfa3111ced5f" + integrity sha512-gR6Rw4MvUlYy83vP0vxoVNzM6t8MUXqNuRsuBmBHQDu1Fh6X015FrLdgoDKcNdkwGubozq0P4N0Q37UyFVr1EA== + dependencies: + buffer-from "^1.0.0" + source-map "^0.6.0" + source-map-support@^0.4.15: version "0.4.18" resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.4.18.tgz#0286a6de8be42641338594e97ccea75f0a2c585f" @@ -7869,6 +7879,24 @@ yargs-parser@^9.0.2: dependencies: camelcase "^4.1.0" +yargs@11.1.0, yargs@^11.0.0, yargs@^11.1.0: + version "11.1.0" + resolved "https://registry.yarnpkg.com/yargs/-/yargs-11.1.0.tgz#90b869934ed6e871115ea2ff58b03f4724ed2d77" + integrity sha512-NwW69J42EsCSanF8kyn5upxvjp5ds+t3+udGBeTbFnERA+lF541DDpMawzo4z6W/QrzNM18D+BPMiOBibnFV5A== + dependencies: + cliui "^4.0.0" + decamelize "^1.1.1" + find-up "^2.1.0" + get-caller-file "^1.0.1" + os-locale "^2.0.0" + require-directory "^2.1.1" + require-main-filename "^1.0.1" + set-blocking "^2.0.0" + string-width "^2.0.0" + which-module "^2.0.0" + y18n "^3.2.1" + yargs-parser "^9.0.2" + yargs@6.4.0: version "6.4.0" resolved "https://registry.yarnpkg.com/yargs/-/yargs-6.4.0.tgz#816e1a866d5598ccf34e5596ddce22d92da490d4" @@ -7906,23 +7934,6 @@ yargs@6.6.0: y18n "^3.2.1" yargs-parser "^4.2.0" -yargs@^11.0.0, yargs@^11.1.0: - version "11.1.0" - resolved "https://registry.yarnpkg.com/yargs/-/yargs-11.1.0.tgz#90b869934ed6e871115ea2ff58b03f4724ed2d77" - dependencies: - cliui "^4.0.0" - decamelize "^1.1.1" - find-up "^2.1.0" - get-caller-file "^1.0.1" - os-locale "^2.0.0" - require-directory "^2.1.1" - require-main-filename "^1.0.1" - set-blocking "^2.0.0" - string-width "^2.0.0" - which-module "^2.0.0" - y18n "^3.2.1" - yargs-parser "^9.0.2" - yargs@^4.6.0, yargs@^4.7.1: version "4.8.1" resolved "https://registry.yarnpkg.com/yargs/-/yargs-4.8.1.tgz#c0c42924ca4aaa6b0e6da1739dfb216439f9ddc0" From 0c405cd180183ec23123d5fce83b565082b1e1c0 Mon Sep 17 00:00:00 2001 From: Walker Date: Mon, 14 Jan 2019 11:05:27 -0500 Subject: [PATCH 43/74] explicit conversion of minterManager to address type --- contracts/minting/MintController.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/minting/MintController.sol b/contracts/minting/MintController.sol index af8555ae0..dde0672fe 100644 --- a/contracts/minting/MintController.sol +++ b/contracts/minting/MintController.sol @@ -84,7 +84,7 @@ contract MintController is Controller { onlyOwner returns (bool) { - emit MinterManagerSet(minterManager, _newMinterManager); + emit MinterManagerSet(address(minterManager), _newMinterManager); minterManager = MinterManagementInterface(_newMinterManager); return true; } From a9cf321387f8bb16e3effc4dcdc164a970cb0fde Mon Sep 17 00:00:00 2001 From: Johnny Liang Date: Mon, 14 Jan 2019 11:12:12 -0500 Subject: [PATCH 44/74] Move MinterManagementInterface to its own file (#251) * move MinterManagementInterface to its own file --- contracts/minting/MintController.sol | 14 +-------- .../minting/MinterManagementInterface.sol | 31 +++++++++++++++++++ test/minting/MintP0_ArgumentTests.js | 1 - 3 files changed, 32 insertions(+), 14 deletions(-) create mode 100644 contracts/minting/MinterManagementInterface.sol diff --git a/contracts/minting/MintController.sol b/contracts/minting/MintController.sol index af8555ae0..68ce03071 100644 --- a/contracts/minting/MintController.sol +++ b/contracts/minting/MintController.sol @@ -23,21 +23,9 @@ pragma solidity ^0.4.24; import "./Controller.sol"; +import "./MinterManagementInterface.sol"; import "openzeppelin-solidity/contracts/math/SafeMath.sol"; -// Using an interface for managing minters so that MintController -// can be used for managing minters with different contracts. -interface MinterManagementInterface { - function isMinter(address account) external view returns (bool); - function minterAllowance(address minter) external view returns (uint256); - function configureMinter( - address minter, - uint256 minterAllowedAmount - ) - external returns (bool); - function removeMinter(address minter) external returns (bool); -} - /** * @title MintController * @dev allows control of configure/remove minter by different addresses diff --git a/contracts/minting/MinterManagementInterface.sol b/contracts/minting/MinterManagementInterface.sol new file mode 100644 index 000000000..9f3971e6b --- /dev/null +++ b/contracts/minting/MinterManagementInterface.sol @@ -0,0 +1,31 @@ +/** +* Copyright CENTRE SECZ 2019 +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is furnished to +* do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in all +* copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +pragma solidity ^0.4.24; + +// Using an interface for managing minters so that MintController +// can be used for managing minters with different contracts. +interface MinterManagementInterface { + function isMinter(address account) external view returns (bool); + function minterAllowance(address minter) external view returns (uint256); + function configureMinter(address minter, uint256 minterAllowedAmount) external returns (bool); + function removeMinter(address minter) external returns (bool); +} diff --git a/test/minting/MintP0_ArgumentTests.js b/test/minting/MintP0_ArgumentTests.js index 99a5e4bfa..038928b1a 100644 --- a/test/minting/MintP0_ArgumentTests.js +++ b/test/minting/MintP0_ArgumentTests.js @@ -212,4 +212,3 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { var testWrapper = require('./../TestWrapper'); testWrapper.execute('MINTp0_ArgumentTests MintController', run_tests_MintController); testWrapper.execute('MINTp0_ArgumentTests MasterMinter', run_tests_MasterMinter); - From aa862cd614b0488ca108e59913155b3ee05482e8 Mon Sep 17 00:00:00 2001 From: Johnny Liang Date: Mon, 14 Jan 2019 14:07:31 -0500 Subject: [PATCH 45/74] Lack of check might lead to gas burn (#248) * added check for allowanceIncrement to avoid gas burn --- contracts/minting/MintController.sol | 23 +++++++++++-------- test/minting/MintP0_ArgumentTests.js | 13 ++--------- .../Spreadsheets/MINTp0_ArgumentTests.csv | 2 +- 3 files changed, 16 insertions(+), 22 deletions(-) diff --git a/contracts/minting/MintController.sol b/contracts/minting/MintController.sol index 68ce03071..5e3e16136 100644 --- a/contracts/minting/MintController.sol +++ b/contracts/minting/MintController.sol @@ -68,8 +68,8 @@ contract MintController is Controller { function setMinterManager( address _newMinterManager ) - public - onlyOwner + public + onlyOwner returns (bool) { emit MinterManagerSet(minterManager, _newMinterManager); @@ -94,8 +94,8 @@ contract MintController is Controller { function configureMinter( uint256 newAllowance ) - public - onlyController + public + onlyController returns (bool) { address minter = controllers[msg.sender]; @@ -109,25 +109,28 @@ contract MintController is Controller { * incrementMinterAllowance() transaction to a minter and not worry * about it being used to undo a removeMinter() transaction. */ + function incrementMinterAllowance( - uint256 allowanceIncrement + uint256 _allowanceIncrement ) - public - onlyController + public + onlyController returns (bool) { + require(_allowanceIncrement > 0, "Allowance increment must be greater than 0."); address minter = controllers[msg.sender]; require(minterManager.isMinter(minter), "Can only increment allowance for minters in minterManager."); uint256 currentAllowance = minterManager.minterAllowance(minter); - uint256 newAllowance = currentAllowance.add(allowanceIncrement); + uint256 newAllowance = currentAllowance.add(_allowanceIncrement); emit MinterAllowanceIncrement( msg.sender, minter, - allowanceIncrement, + _allowanceIncrement, newAllowance ); + return internal_setMinterAllowance(minter, newAllowance); } @@ -141,7 +144,7 @@ contract MintController is Controller { address minter, uint256 newAllowance ) - internal + internal returns (bool) { return minterManager.configureMinter(minter, newAllowance); diff --git a/test/minting/MintP0_ArgumentTests.js b/test/minting/MintP0_ArgumentTests.js index 038928b1a..b69fe6c95 100644 --- a/test/minting/MintP0_ArgumentTests.js +++ b/test/minting/MintP0_ArgumentTests.js @@ -166,18 +166,9 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); }); - it('arg015 incrementMinterAllowance(0) makes no changes to allowance', async function () { - var amount = 897; + it('arg015 incrementMinterAllowance(0) throws', async function () { 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': newBigNumber(amount) } - ); - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + await expectError(mintController.incrementMinterAllowance(0, {from: Accounts.controller1Account}), "Allowance increment must be greater than 0."); }); it('arg016 incrementMinterAllowance(oldAllowance) doubles the allowance', async function () { diff --git a/verification/Spreadsheets/MINTp0_ArgumentTests.csv b/verification/Spreadsheets/MINTp0_ArgumentTests.csv index 48b05337a..bad319d21 100644 --- a/verification/Spreadsheets/MINTp0_ArgumentTests.csv +++ b/verification/Spreadsheets/MINTp0_ArgumentTests.csv @@ -14,7 +14,7 @@ MintController.sol,setMinterManager,newMinterManager == newToken,arg011,arg011 s MintController.sol,configureMinter,newAllowance == 0,arg012,arg012 configureMinter(0) sets allowance to 0 MintController.sol,configureMinter,newAllowance == oldAllowance,arg013,arg013 configureMinter(oldAllowance) makes no changes MintController.sol,configureMinter,newAllowance == 2^256-1,arg014,arg014 configureMinter(MAX) works -MintController.sol,incrementMinterAllowance,increment ==0,arg015,arg015 incrementMinterAllowance(0) makes no changes to allowance +MintController.sol,incrementMinterAllowance,increment ==0,arg015,arg015 incrementMinterAllowance(0) throws MintController.sol,incrementMinterAllowance,increment == oldAllowance,arg016,arg016 incrementMinterAllowance(oldAllowance) doubles the allowance MintController.sol,incrementMinterAllowance,increment == 2^256-1,arg017,arg017 incrementMinterAllowance(MAX) throws MintController.sol,incrementMinterAllowance,increment + oldAllowance == 2^256 -1,arg018,arg018 incrementMinterAlllowance(BIG) throws From 71e07c6afed377674a0ebcb16a56d9219efc5242 Mon Sep 17 00:00:00 2001 From: Oliver Hudson <32966763+o-a-hudson@users.noreply.github.com> Date: Mon, 14 Jan 2019 14:28:22 -0500 Subject: [PATCH 46/74] Adds integrity check on development environment dependencies (#261) Adds integrity, tree check on dependencies before testing --- .travis.yml | 2 +- package.json | 4 ++-- scripts/verify-environment.sh | 7 +++++++ 3 files changed, 10 insertions(+), 3 deletions(-) create mode 100755 scripts/verify-environment.sh diff --git a/.travis.yml b/.travis.yml index 7880617ad..b8540c151 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,6 +22,6 @@ env: - TEST_SUITE=test/proxy/* script: - - "yarn check --integrity && truffle compile && npm run truffle-test $TEST_SUITE" + - "truffle compile && npm run truffle-test $TEST_SUITE" diff --git a/package.json b/package.json index 9107d628d..83bcbbd7c 100644 --- a/package.json +++ b/package.json @@ -9,8 +9,8 @@ }, "scripts": { "dev": "lite-server", - "truffle-test": "scripts/start-ganache.sh && truffle test", - "test": "scripts/start-ganache.sh && ./node_modules/.bin/solidity-coverage" + "truffle-test": "scripts/verify-environment.sh && scripts/start-ganache.sh && truffle test", + "test": "scripts/verify-environment.sh && scripts/start-ganache.sh && ./node_modules/.bin/solidity-coverage" }, "repository": { "type": "git", diff --git a/scripts/verify-environment.sh b/scripts/verify-environment.sh new file mode 100755 index 000000000..d6abea139 --- /dev/null +++ b/scripts/verify-environment.sh @@ -0,0 +1,7 @@ +#!/bin/bash +set -e + +echo "Verifying integrity" +yarn check --integrity +echo "Verifying tree" +yarn check --verify-tree From a2b26cdd4ae004bc9d89fb649f61e4796f221244 Mon Sep 17 00:00:00 2001 From: Johnny Liang Date: Wed, 16 Jan 2019 10:06:33 -0500 Subject: [PATCH 47/74] #252: add null address check (#247) * add null address check to removeController and configureController * update unit tests --- contracts/minting/Controller.sol | 2 + test/minting/MintP0_ArgumentTests.js | 49 ++++++++++--------- test/minting3/MintP0_BasicTests.js | 39 ++------------- .../Spreadsheets/MINTp0_ArgumentTests.csv | 6 ++- .../Spreadsheets/MINTp0_BasicTests.csv | 3 -- 5 files changed, 38 insertions(+), 61 deletions(-) diff --git a/contracts/minting/Controller.sol b/contracts/minting/Controller.sol index 91dc9557d..d87ae3af5 100644 --- a/contracts/minting/Controller.sol +++ b/contracts/minting/Controller.sol @@ -66,6 +66,7 @@ contract Controller is Ownable { onlyOwner returns (bool) { + require(_controller != address(0), "Controller must be a non-zero address"); require(_worker != address(0), "Worker must be a non-zero address."); controllers[_controller] = _worker; emit ControllerConfigured(_controller, _worker); @@ -82,6 +83,7 @@ contract Controller is Ownable { onlyOwner returns (bool) { + require(_controller != address(0), "Controller must be a non-zero address"); controllers[_controller] = address(0); emit ControllerRemoved(_controller); return true; diff --git a/test/minting/MintP0_ArgumentTests.js b/test/minting/MintP0_ArgumentTests.js index b69fe6c95..c588d365f 100644 --- a/test/minting/MintP0_ArgumentTests.js +++ b/test/minting/MintP0_ArgumentTests.js @@ -60,13 +60,9 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { 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.isTrue(addressEquals(Accounts.minterAccount, actualMinter)); + it('arg003 configureController(0, M) throws', async function () { + await expectError(mintController.configureController(zeroAddress, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}), + "Controller must be a non-zero address"); }); it('arg004 configureController(msg.sender, M) works', async function () { @@ -86,21 +82,9 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { .mintOwnerAccount}), "Worker must be a non-zero address"); }); - 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.isTrue(addressEquals(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(actualMinter, zeroAddress); + it('arg007 removeController(0) throws', async function () { + await expectError(mintController.removeController(zeroAddress, {from: Accounts.mintOwnerAccount}), + "Controller must be a non-zero address"); }); it('arg008 setMinterManager(0) works', async function () { @@ -198,6 +182,27 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { await expectJump(mintController.incrementMinterAllowance(1, {from: Accounts.controller1Account})); }); + it('arg019 configureController(0, 0) throws', async function () { + await expectError(mintController.configureController(zeroAddress, zeroAddress, {from: Accounts.mintOwnerAccount}), + "Controller must be a non-zero address"); + }); + + it('arg020 removeController(C) works', async function() { + // expect no changes + await mintController.removeController(Accounts.controller1Account, {from: Accounts.mintOwnerAccount}); + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + + // now make controller1Account a controller + await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + var actualMinter = await mintController.controllers(Accounts.controller1Account); + addressEquals(Accounts.minterAccount, actualMinter); + + // remove controller1Account + await mintController.removeController(Accounts.controller1Account, {from : Accounts.mintOwnerAccount}); + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + actualMinter = await mintController.controllers(Accounts.controller1Account); + addressEquals(actualMinter, zeroAddress); + }); } var testWrapper = require('./../TestWrapper'); diff --git a/test/minting3/MintP0_BasicTests.js b/test/minting3/MintP0_BasicTests.js index 2f07e1e45..21722cc1e 100644 --- a/test/minting3/MintP0_BasicTests.js +++ b/test/minting3/MintP0_BasicTests.js @@ -236,16 +236,6 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { assert.isTrue(addressEquals(token.address, minterManagerAddress)); }); - it('bt025 setMinterManager(x) works when existing minterManager = 0', async function () { - await mintController.setMinterManager(zeroAddress, {from: Accounts.mintOwnerAccount}); - expectedMintControllerState.minterManager = zeroAddress; - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); - - await mintController.setMinterManager(Accounts.arbitraryAccount, {from: Accounts.mintOwnerAccount}); - expectedMintControllerState.minterManager = Accounts.arbitraryAccount; - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); - }); - it('bt026 setMinterManager(x) works when existing minterManager != 0', async function () { await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); @@ -267,9 +257,10 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { }); it('bt030 removeMinter reverts when minterManager is 0', async function () { - // set minterManager to 0 - await mintController.setMinterManager(zeroAddress, {from:Accounts.mintOwnerAccount}); - expectedMintControllerState.minterManager = zeroAddress; + // set minterManager + var minterManagerAddress = await mintController.minterManager(); + await mintController.setMinterManager(minterManagerAddress, {from:Accounts.mintOwnerAccount}); + expectedMintControllerState.minterManager = minterManagerAddress; await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); // configure minter will fail with any args @@ -306,16 +297,6 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); }); - it('bt033 configureMinter reverts when minterManager is 0', async function () { - // set minterManager to 0 - await mintController.setMinterManager(zeroAddress, {from:Accounts.mintOwnerAccount}); - expectedMintControllerState.minterManager = zeroAddress; - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); - - // configure minter will fail with any args - await(expectRevert(mintController.configureMinter(50, {from: Accounts.controller1Account}))); - }); - it('bt034 configureMinter reverts when minterManager is a user account', async function () { // set minterManager to user account await mintController.setMinterManager(Accounts.arbitraryAccount, {from:Accounts.mintOwnerAccount}); @@ -338,16 +319,6 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); }); - it('bt036 incrementMinterAllowance reverts when minterManager is 0', async function () { - // set minterManager to zero - await mintController.setMinterManager(zeroAddress, {from:Accounts.mintOwnerAccount}); - expectedMintControllerState.minterManager = zeroAddress; - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); - - // incrementMinterAllowance will fail with any args - await(expectRevert(mintController.incrementMinterAllowance(50, {from: Accounts.controller1Account}))); - }); - it('bt037 incrementMinterAllowance reverts when minterManager is a user account', async function () { // set minterManager to user account await mintController.setMinterManager(Accounts.arbitraryAccount, {from:Accounts.mintOwnerAccount}); @@ -638,4 +609,4 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { var testWrapper = require('./../TestWrapper'); testWrapper.execute('MINTp0_BasicTests MintController', run_tests_MintController); -testWrapper.execute('MINTp0_BasicTests MasterMinter', run_tests_MasterMinter); \ No newline at end of file +testWrapper.execute('MINTp0_BasicTests MasterMinter', run_tests_MasterMinter); diff --git a/verification/Spreadsheets/MINTp0_ArgumentTests.csv b/verification/Spreadsheets/MINTp0_ArgumentTests.csv index bad319d21..0912288d0 100644 --- a/verification/Spreadsheets/MINTp0_ArgumentTests.csv +++ b/verification/Spreadsheets/MINTp0_ArgumentTests.csv @@ -2,11 +2,11 @@ File,Function,Arguments,Code,Description Ownable.sol,transferOwnership,newOwner == msg.sender,arg000,arg000 transferOwnership(msg.sender) works Ownable.sol,transferOwnership,newOwner == 0,arg001,arg001 transferOwnership(0) reverts Ownable.sol,transferOwnership,newOwner == owner,arg002,arg002 transferOwnership(owner) works -Controller.sol,configureController,newController == 0,arg003,"arg003 configureController(0, M) works" +Controller.sol,configureController,newController == 0,arg003,"arg003 configureController(0, M) throws" Controller.sol,configureController,newController == msg.sender,arg004,"arg004 configureController(msg.sender, M) works" Controller.sol,configureController,newController == newMinter,arg005,"arg005 configureController(M, M) works" Controller.sol,configureController,newMinter == 0,arg006,"arg006 configureController(C, 0) throws" -Controller.sol,removeController,newController == 0,arg007,arg007 removeController(0) works +Controller.sol,removeController,newController == 0,arg007,arg007 removeController(0) throws MintController.sol,setMinterManager,newMinterManager = 0,arg008,arg008 setMinterManager(0) works MintController.sol,setMinterManager,newMinterManager == minterManager,arg009,arg009 setMinterManager(oldMinterManager) works MintController.sol,setMinterManager,newMinterManager == user,arg010,arg010 setMinterManager(user_account) works @@ -18,3 +18,5 @@ MintController.sol,incrementMinterAllowance,increment ==0,arg015,arg015 incremen MintController.sol,incrementMinterAllowance,increment == oldAllowance,arg016,arg016 incrementMinterAllowance(oldAllowance) doubles the allowance MintController.sol,incrementMinterAllowance,increment == 2^256-1,arg017,arg017 incrementMinterAllowance(MAX) throws MintController.sol,incrementMinterAllowance,increment + oldAllowance == 2^256 -1,arg018,arg018 incrementMinterAlllowance(BIG) throws +Controller.sol,configureController,newController == 0,arg019,"arg019 configureController(0, 0) throws" +Controller.sol,removeController,newController == msg.sender,arg020,arg020 removeController(C) works diff --git a/verification/Spreadsheets/MINTp0_BasicTests.csv b/verification/Spreadsheets/MINTp0_BasicTests.csv index b994bc2fd..11f0e73dc 100644 --- a/verification/Spreadsheets/MINTp0_BasicTests.csv +++ b/verification/Spreadsheets/MINTp0_BasicTests.csv @@ -15,7 +15,6 @@ FiatTokenV1.sol,constructor,minterManager.isMinter[ALL] == false,bt045,bt045 con FiatTokenV1.sol,constructor,minterManager.minterAllowance[ALL] == 0,bt046,bt046 constructor - minterManager.minterAllowance[ALL] = 0 MintController.sol,configureMinter,controllers[msg.sender]==0,bt012,bt012 configureMinter reverts when msg.sender is not a controller MintController.sol,configureMinter,controllers[msg.sender]==M,bt013,bt013 configureMinter works when controllers[msg.sender]=M -MintController.sol,configureMinter,minterManager = 0,bt033,bt033 configureMinter reverts when minterManager is 0 MintController.sol,configureMinter,minterManager != MinterManagerInterface,bt034,bt034 configureMinter reverts when minterManager is a user account MintController.sol,configureMinter,minterManager == OK,bt035,bt035 configureMinter works when minterManager is ok MintController.sol,configureMinter,minterManager.isMinter == false,bt039,"bt039 configureMinter(M, amt) works when minterManager.isMinter(M)=false" @@ -26,7 +25,6 @@ MintController.sol,configureMinter,minterManager.minterAllowance[M] == BIG,bt052 MintController.sol,constructor,minterManager == init,bt024,bt024 Constructor sets minterManager MintController.sol,incrementMinterAllowance,controllers[msg.sender]==0,bt014,bt014 incrementMinterAllowance reverts if msg.sender is not a controller MintController.sol,incrementMinterAllowance,controllers[msg.sender]==M,bt015,bt015 incrementMinterAllowance works when controllers[msg.sender]=M -MintController.sol,incrementMinterAllowance,minterManager = 0,bt036,bt036 incrementMinterAllowance reverts when minterManager is 0 MintController.sol,incrementMinterAllowance,minterManager != MinterManagerInterface,bt037,bt037 incrementMinterAllowance reverts when minterManager is a user account MintController.sol,incrementMinterAllowance,minterManager == OK,bt038,bt038 incrementMinterAllowance works when minterManager is ok MintController.sol,incrementMinterAllowance,minterManager.isMinter == false,bt043,"bt043 incrementMinterAllowance(M, amt) reverts when minterManager.isMinter(M)=false" @@ -46,7 +44,6 @@ MintController.sol,removeMinter,minterManager.minterAllowance[M] == X,bt054,bt05 MintController.sol,removeMinter,minterManager.minterAllowance[M] == BIG,bt055,bt055 removeMinter works when the minterAllowance is big MintController.sol,setMinterManager,msg.sender == owner,bt006,bt006 setMinterManager works when owner is msg.sender MintController.sol,setMinterManager,msg.sender != owner,bt007,bt007 setMinterManager reverts when owner is not msg.sender -MintController.sol,setMinterManager,minterManager == 0,bt025,bt025 setMinterManager(x) works when existing minterManager = 0 MintController.sol,setMinterManager,minterManager != 0,bt026,bt026 setMinterManager(x) works when existing minterManager != 0 MintController.sol,setMinterManager,minterManager == msg.sender,bt027,bt027 setMinterManager(x) works when x = msg.sender MintController.sol,setMinterManager,minterManager == newMinterManager,bt028,bt028 setMinterManager(x) works when x = minterManager From b2dc2107319c28dde6501769de239a990a7cc35d Mon Sep 17 00:00:00 2001 From: walkerq Date: Wed, 16 Jan 2019 10:11:07 -0500 Subject: [PATCH 48/74] (style) add newline to configureMinter, reorder visibility modifier in removeMinter (#269) --- contracts/minting/MintController.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/minting/MintController.sol b/contracts/minting/MintController.sol index a35a3405f..d012e7ef9 100644 --- a/contracts/minting/MintController.sol +++ b/contracts/minting/MintController.sol @@ -82,7 +82,7 @@ contract MintController is Controller { /** * @dev remove the controller's minter. */ - function removeMinter() onlyController public returns (bool) { + function removeMinter() public onlyController returns (bool) { address minter = controllers[msg.sender]; emit MinterRemoved(msg.sender, minter); return minterManager.removeMinter(minter); From 43b5f74f27e78806c1e506793ffb7251af55e6e8 Mon Sep 17 00:00:00 2001 From: walkerq Date: Wed, 16 Jan 2019 10:13:18 -0500 Subject: [PATCH 49/74] prefix parameters in MintController with underscores for consistency (#270) --- contracts/minting/Controller.sol | 3 +- contracts/minting/MintController.sol | 37 ++++++++++--------- .../minting/MinterManagementInterface.sol | 26 ++++++++----- 3 files changed, 38 insertions(+), 28 deletions(-) diff --git a/contracts/minting/Controller.sol b/contracts/minting/Controller.sol index d87ae3af5..0e4e3791d 100644 --- a/contracts/minting/Controller.sol +++ b/contracts/minting/Controller.sol @@ -44,7 +44,8 @@ contract Controller is Ownable { * @dev ensure that caller is the controller of a non-zero worker address */ modifier onlyController() { - require(controllers[msg.sender] != address(0), "The value of controllers[msg.sender] must be non-zero."); + require(controllers[msg.sender] != address(0), + "The value of controllers[msg.sender] must be non-zero."); _; } diff --git a/contracts/minting/MintController.sol b/contracts/minting/MintController.sol index d012e7ef9..36a03d0d9 100644 --- a/contracts/minting/MintController.sol +++ b/contracts/minting/MintController.sol @@ -37,23 +37,23 @@ contract MintController is Controller { MinterManagementInterface public minterManager; event MinterManagerSet( - address indexed oldMinterManager, - address indexed newMinterManager + address indexed _oldMinterManager, + address indexed _newMinterManager ); event MinterConfigured( - address indexed msgSender, - address indexed minter, - uint256 allowance + address indexed _msgSender, + address indexed _minter, + uint256 _allowance ); event MinterRemoved( - address indexed msgSender, - address indexed minter + address indexed _msgSender, + address indexed _minter ); event MinterAllowanceIncrement( - address indexed msgSender, - address indexed minter, - uint256 increment, - uint256 newAllowance + address indexed _msgSender, + address indexed _minter, + uint256 _increment, + uint256 _newAllowance ); constructor(address _minterManager) public { @@ -92,15 +92,15 @@ contract MintController is Controller { * @dev Enables the minter and sets its allowance */ function configureMinter( - uint256 newAllowance + uint256 _newAllowance ) public onlyController returns (bool) { address minter = controllers[msg.sender]; - emit MinterConfigured(msg.sender, minter, newAllowance); - return internal_setMinterAllowance(minter, newAllowance); + emit MinterConfigured(msg.sender, minter, _newAllowance); + return internal_setMinterAllowance(minter, _newAllowance); } /** @@ -119,7 +119,8 @@ contract MintController is Controller { { require(_allowanceIncrement > 0, "Allowance increment must be greater than 0."); address minter = controllers[msg.sender]; - require(minterManager.isMinter(minter), "Can only increment allowance for minters in minterManager."); + require(minterManager.isMinter(minter), + "Can only increment allowance for minters in minterManager."); uint256 currentAllowance = minterManager.minterAllowance(minter); uint256 newAllowance = currentAllowance.add(_allowanceIncrement); @@ -141,12 +142,12 @@ contract MintController is Controller { * set its allowance. */ function internal_setMinterAllowance( - address minter, - uint256 newAllowance + address _minter, + uint256 _newAllowance ) internal returns (bool) { - return minterManager.configureMinter(minter, newAllowance); + return minterManager.configureMinter(_minter, _newAllowance); } } diff --git a/contracts/minting/MinterManagementInterface.sol b/contracts/minting/MinterManagementInterface.sol index 9f3971e6b..faf82b3cb 100644 --- a/contracts/minting/MinterManagementInterface.sol +++ b/contracts/minting/MinterManagementInterface.sol @@ -5,8 +5,8 @@ * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is furnished to -* do so, subject to the following conditions: +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. @@ -14,9 +14,10 @@ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. */ pragma solidity ^0.4.24; @@ -24,8 +25,15 @@ pragma solidity ^0.4.24; // Using an interface for managing minters so that MintController // can be used for managing minters with different contracts. interface MinterManagementInterface { - function isMinter(address account) external view returns (bool); - function minterAllowance(address minter) external view returns (uint256); - function configureMinter(address minter, uint256 minterAllowedAmount) external returns (bool); - function removeMinter(address minter) external returns (bool); + function isMinter(address _account) external view returns (bool); + function minterAllowance(address _minter) external view returns (uint256); + + function configureMinter( + address _minter, + uint256 _minterAllowedAmount + ) + external + returns (bool); + + function removeMinter(address _minter) external returns (bool); } From 7ad74d7114d378fc817f9c2889469eb4860a3544 Mon Sep 17 00:00:00 2001 From: walkerq Date: Wed, 16 Jan 2019 14:47:56 -0500 Subject: [PATCH 50/74] removeController reverts if controllers[C] is 0 (#273) * removeController throws if worker is already zero-address * remove a bunch of unnecessary periods for consistency, fix broken tests --- .gitignore | 1 + contracts/minting/Controller.sol | 5 +-- contracts/minting/MintController.sol | 4 +-- test/minting/MintP0_ArgumentTests.js | 32 +++++++++++++------ test/minting2/MintControllerTests.js | 10 +++--- test/minting2/MintP0_ABITests.js | 8 ++--- test/minting3/MintP0_BasicTests.js | 20 ++++++------ .../Spreadsheets/MINTp0_ArgumentTests.csv | 5 +-- .../Spreadsheets/MINTp0_BasicTests.csv | 2 +- 9 files changed, 52 insertions(+), 35 deletions(-) diff --git a/.gitignore b/.gitignore index 828920310..d95c54b2b 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ token.json credentials.json echidna/ validate/apikey.infura +ganache-blockchain-log.txt diff --git a/contracts/minting/Controller.sol b/contracts/minting/Controller.sol index 0e4e3791d..ad1099172 100644 --- a/contracts/minting/Controller.sol +++ b/contracts/minting/Controller.sol @@ -45,7 +45,7 @@ contract Controller is Ownable { */ modifier onlyController() { require(controllers[msg.sender] != address(0), - "The value of controllers[msg.sender] must be non-zero."); + "The value of controllers[msg.sender] must be non-zero"); _; } @@ -68,7 +68,7 @@ contract Controller is Ownable { returns (bool) { require(_controller != address(0), "Controller must be a non-zero address"); - require(_worker != address(0), "Worker must be a non-zero address."); + require(_worker != address(0), "Worker must be a non-zero address"); controllers[_controller] = _worker; emit ControllerConfigured(_controller, _worker); return true; @@ -85,6 +85,7 @@ contract Controller is Ownable { returns (bool) { require(_controller != address(0), "Controller must be a non-zero address"); + require(controllers[_controller] != address(0), "Worker must be a non-zero address"); controllers[_controller] = address(0); emit ControllerRemoved(_controller); return true; diff --git a/contracts/minting/MintController.sol b/contracts/minting/MintController.sol index 36a03d0d9..a7d16ed65 100644 --- a/contracts/minting/MintController.sol +++ b/contracts/minting/MintController.sol @@ -117,10 +117,10 @@ contract MintController is Controller { onlyController returns (bool) { - require(_allowanceIncrement > 0, "Allowance increment must be greater than 0."); + require(_allowanceIncrement > 0, "Allowance increment must be greater than 0"); address minter = controllers[msg.sender]; require(minterManager.isMinter(minter), - "Can only increment allowance for minters in minterManager."); + "Can only increment allowance for minters in minterManager"); uint256 currentAllowance = minterManager.minterAllowance(minter); uint256 newAllowance = currentAllowance.add(_allowanceIncrement); diff --git a/test/minting/MintP0_ArgumentTests.js b/test/minting/MintP0_ArgumentTests.js index c588d365f..9d08cef06 100644 --- a/test/minting/MintP0_ArgumentTests.js +++ b/test/minting/MintP0_ArgumentTests.js @@ -4,7 +4,7 @@ var MintController = artifacts.require('minting/MintController'); var MasterMinter = artifacts.require('minting/MasterMinter'); var FiatToken = artifacts.require('FiatTokenV1'); -var tokenUtils = require('./../TokenTestUtils.js'); +var tokenUtils = require('../TokenTestUtils.js'); var newBigNumber = tokenUtils.newBigNumber; var checkMINTp0 = tokenUtils.checkMINTp0; var expectRevert = tokenUtils.expectRevert; @@ -15,8 +15,8 @@ var maxAmount = tokenUtils.maxAmount; var clone = require('clone'); -var mintUtils = require('./../MintControllerUtils.js'); -var AccountUtils = require('./../AccountUtils.js'); +var mintUtils = require('../MintControllerUtils.js'); +var AccountUtils = require('../AccountUtils.js'); var Accounts = AccountUtils.Accounts; var getAccountState = AccountUtils.getAccountState; var MintControllerState = AccountUtils.MintControllerState; @@ -83,8 +83,9 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { }); it('arg007 removeController(0) throws', async function () { - await expectError(mintController.removeController(zeroAddress, {from: Accounts.mintOwnerAccount}), - "Controller must be a non-zero address"); + // expect no changes + await expectError(mintController.removeController(zeroAddress, {from: Accounts.mintOwnerAccount}), "Controller must be a non-zero address"); + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); }); it('arg008 setMinterManager(0) works', async function () { @@ -188,11 +189,20 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { }); it('arg020 removeController(C) works', async function() { - // expect no changes - await mintController.removeController(Accounts.controller1Account, {from: Accounts.mintOwnerAccount}); + // make controller1Account a controller + await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + var actualMinter = await mintController.controllers(Accounts.controller1Account); + addressEquals(Accounts.minterAccount, actualMinter); + + // remove controller1Account + await mintController.removeController(Accounts.controller1Account, {from : Accounts.mintOwnerAccount}); await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + actualMinter = await mintController.controllers(Accounts.controller1Account); + addressEquals(actualMinter, zeroAddress); + }); - // now make controller1Account a controller + it('arg021 removeController throws if worker is already address(0)', async function () { + // make controller1Account a controller await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); var actualMinter = await mintController.controllers(Accounts.controller1Account); addressEquals(Accounts.minterAccount, actualMinter); @@ -202,7 +212,11 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); actualMinter = await mintController.controllers(Accounts.controller1Account); addressEquals(actualMinter, zeroAddress); - }); + + // attempting to remove the controller1Account again should throw because the worker is already set to address(0). + await expectError(mintController.removeController(Accounts.controller1Account, {from: Accounts.mintOwnerAccount}), + "Worker must be a non-zero address"); + }) } var testWrapper = require('./../TestWrapper'); diff --git a/test/minting2/MintControllerTests.js b/test/minting2/MintControllerTests.js index 5778e9c88..544f5a457 100644 --- a/test/minting2/MintControllerTests.js +++ b/test/minting2/MintControllerTests.js @@ -96,11 +96,11 @@ async function run_tests(newToken, accounts) { }); it('only controller removes a minter', async function () { - await expectError(mintController.removeMinter({from: Accounts.controller1Account}), "The value of controllers[msg.sender] must be non-zero."); + await expectError(mintController.removeMinter({from: Accounts.controller1Account}), "The value of controllers[msg.sender] must be non-zero"); }); it('only controller configures a minter', async function () { - await expectError(mintController.configureMinter(0, {from: Accounts.controller1Account}), "The value of controllers[msg.sender] must be non-zero."); + await expectError(mintController.configureMinter(0, {from: Accounts.controller1Account}), "The value of controllers[msg.sender] must be non-zero"); }); it('increment minter allowance', async function () { @@ -126,7 +126,7 @@ async function run_tests(newToken, accounts) { }); it('only controller increments allowance', async function () { - await expectError(mintController.incrementMinterAllowance(0, {from: Accounts.controller1Account}), "The value of controllers[msg.sender] must be non-zero."); + await expectError(mintController.incrementMinterAllowance(0, {from: Accounts.controller1Account}), "The value of controllers[msg.sender] must be non-zero"); }); it('only active minters can have allowance incremented', async function () { @@ -137,11 +137,11 @@ async function run_tests(newToken, accounts) { await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); // increment minter allowance - await expectError(mintController.incrementMinterAllowance(amount, {from: Accounts.controller1Account}), "Can only increment allowance for minters in minterManager."); + await expectError(mintController.incrementMinterAllowance(amount, {from: Accounts.controller1Account}), "Can only increment allowance for minters in minterManager"); }); } -var testWrapper = require('./../TestWrapper'); +var testWrapper = require('../TestWrapper'); testWrapper.execute('MintController_Tests', run_tests); module.exports = { diff --git a/test/minting2/MintP0_ABITests.js b/test/minting2/MintP0_ABITests.js index 90d8116ae..9cb9bfe18 100644 --- a/test/minting2/MintP0_ABITests.js +++ b/test/minting2/MintP0_ABITests.js @@ -2,7 +2,7 @@ var MintController = artifacts.require('minting/MintController'); var MasterMinter = artifacts.require('minting/MasterMinter'); var FiatToken = artifacts.require('FiatTokenV1'); -var tokenUtils = require('./../TokenTestUtils.js'); +var tokenUtils = require('../TokenTestUtils.js'); var checkMINTp0 = tokenUtils.checkMINTp0; var expectError = tokenUtils.expectError; var bigZero = tokenUtils.bigZero; @@ -11,8 +11,8 @@ var solidityErrors = tokenUtils.solidityErrors; var clone = require('clone'); -var mintUtils = require('./../MintControllerUtils.js'); -var AccountUtils = require('./../AccountUtils.js'); +var mintUtils = require('../MintControllerUtils.js'); +var AccountUtils = require('../AccountUtils.js'); var Accounts = AccountUtils.Accounts; var AccountPrivateKeys = AccountUtils.AccountPrivateKeys; var getAccountState = AccountUtils.getAccountState; @@ -20,7 +20,7 @@ var MintControllerState = AccountUtils.MintControllerState; var initializeTokenWithProxyAndMintController = mintUtils.initializeTokenWithProxyAndMintController; var checkMintControllerState = mintUtils.checkMintControllerState; -var abiUtils = require('./../ABIUtils.js'); +var abiUtils = require('../ABIUtils.js'); var makeRawTransaction = abiUtils.makeRawTransaction; var sendRawTransaction = abiUtils.sendRawTransaction; var msgData = abiUtils.msgData; diff --git a/test/minting3/MintP0_BasicTests.js b/test/minting3/MintP0_BasicTests.js index 21722cc1e..9f2d9a302 100644 --- a/test/minting3/MintP0_BasicTests.js +++ b/test/minting3/MintP0_BasicTests.js @@ -2,7 +2,7 @@ var MintController = artifacts.require('minting/MintController'); var MasterMinter = artifacts.require('minting/MasterMinter'); var FiatToken = artifacts.require('FiatTokenV1'); -var tokenUtils = require('./../TokenTestUtils.js'); +var tokenUtils = require('../TokenTestUtils.js'); var newBigNumber = tokenUtils.newBigNumber; var checkMINTp0 = tokenUtils.checkMINTp0; var expectRevert = tokenUtils.expectRevert; @@ -13,8 +13,8 @@ var maxAmount = tokenUtils.maxAmount; var clone = require('clone'); -var mintUtils = require('./../MintControllerUtils.js'); -var AccountUtils = require('./../AccountUtils.js'); +var mintUtils = require('../MintControllerUtils.js'); +var AccountUtils = require('../AccountUtils.js'); var Accounts = AccountUtils.Accounts; var getAccountState = AccountUtils.getAccountState; var MintControllerState = AccountUtils.MintControllerState; @@ -105,7 +105,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { }); it('bt010 removeMinter reverts when msg.sender is not a controller', async function () { - await expectError(mintController.removeMinter({from: Accounts.controller1Account}), "The value of controllers[msg.sender] must be non-zero."); + await expectError(mintController.removeMinter({from: Accounts.controller1Account}), "The value of controllers[msg.sender] must be non-zero"); }); it('bt011 removeMinter sets minters[M] to 0', async function () { @@ -129,7 +129,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { }); it('bt012 configureMinter reverts when msg.sender is not a controller', async function () { - await expectError(mintController.configureMinter(50, {from: Accounts.controller1Account}), "The value of controllers[msg.sender] must be non-zero."); + await expectError(mintController.configureMinter(50, {from: Accounts.controller1Account}), "The value of controllers[msg.sender] must be non-zero"); }); it('bt013 configureMinter works when controllers[msg.sender]=M', async function () { @@ -148,7 +148,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { }); it('bt014 incrementMinterAllowance reverts if msg.sender is not a controller', async function () { - await expectError(mintController.incrementMinterAllowance(50, {from: Accounts.controller1Account}), "The value of controllers[msg.sender] must be non-zero."); + await expectError(mintController.incrementMinterAllowance(50, {from: Accounts.controller1Account}), "The value of controllers[msg.sender] must be non-zero"); }); it('bt015 incrementMinterAllowance works when controllers[msg.sender]=M', async function () { @@ -171,9 +171,9 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); }); - it('bt017 removeController does not revert when controllers[C] is 0', async function () { + it('bt017 removeController reverts when controllers[C] is 0', async function () { // "remove" a controller that does not exist - await mintController.removeController(Accounts.controller1Account, {from: Accounts.mintOwnerAccount}); + await expectError(mintController.removeController(Accounts.controller1Account, {from: Accounts.mintOwnerAccount}), "Worker must be a non-zero address"); await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); }); @@ -414,7 +414,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { var isMinter = await minterManager.isMinter(Accounts.minterAccount); assert.isFalse(isMinter); - await expectError(mintController.incrementMinterAllowance(amount, {from: Accounts.controller1Account}), "Can only increment allowance for minters in minterManager."); + await expectError(mintController.incrementMinterAllowance(amount, {from: Accounts.controller1Account}), "Can only increment allowance for minters in minterManager"); expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); }); @@ -607,6 +607,6 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { }); } -var testWrapper = require('./../TestWrapper'); +var testWrapper = require('../TestWrapper'); testWrapper.execute('MINTp0_BasicTests MintController', run_tests_MintController); testWrapper.execute('MINTp0_BasicTests MasterMinter', run_tests_MasterMinter); diff --git a/verification/Spreadsheets/MINTp0_ArgumentTests.csv b/verification/Spreadsheets/MINTp0_ArgumentTests.csv index 0912288d0..6bb969e48 100644 --- a/verification/Spreadsheets/MINTp0_ArgumentTests.csv +++ b/verification/Spreadsheets/MINTp0_ArgumentTests.csv @@ -6,7 +6,7 @@ Controller.sol,configureController,newController == 0,arg003,"arg003 configureCo Controller.sol,configureController,newController == msg.sender,arg004,"arg004 configureController(msg.sender, M) works" Controller.sol,configureController,newController == newMinter,arg005,"arg005 configureController(M, M) works" Controller.sol,configureController,newMinter == 0,arg006,"arg006 configureController(C, 0) throws" -Controller.sol,removeController,newController == 0,arg007,arg007 removeController(0) throws +Controller.sol,removeController,controller == 0,arg007,arg007 removeController(0) throws MintController.sol,setMinterManager,newMinterManager = 0,arg008,arg008 setMinterManager(0) works MintController.sol,setMinterManager,newMinterManager == minterManager,arg009,arg009 setMinterManager(oldMinterManager) works MintController.sol,setMinterManager,newMinterManager == user,arg010,arg010 setMinterManager(user_account) works @@ -19,4 +19,5 @@ MintController.sol,incrementMinterAllowance,increment == oldAllowance,arg016,arg MintController.sol,incrementMinterAllowance,increment == 2^256-1,arg017,arg017 incrementMinterAllowance(MAX) throws MintController.sol,incrementMinterAllowance,increment + oldAllowance == 2^256 -1,arg018,arg018 incrementMinterAlllowance(BIG) throws Controller.sol,configureController,newController == 0,arg019,"arg019 configureController(0, 0) throws" -Controller.sol,removeController,newController == msg.sender,arg020,arg020 removeController(C) works +Controller.sol,removeController,controller == msg.sender,arg020,arg020 removeController(C) works +Controller.sol,removeController,controller where controllers[controller] == 0,arg021,arg021 removeController throws if worker is already address(0) \ No newline at end of file diff --git a/verification/Spreadsheets/MINTp0_BasicTests.csv b/verification/Spreadsheets/MINTp0_BasicTests.csv index 11f0e73dc..4bdfedca4 100644 --- a/verification/Spreadsheets/MINTp0_BasicTests.csv +++ b/verification/Spreadsheets/MINTp0_BasicTests.csv @@ -9,7 +9,7 @@ Controller.sol,configureController,controllers[C] == newM,bt023,"bt023 configure Controller.sol,constructor,controllers[ALL] = 0,bt016,bt016 Constructor sets all controllers to 0 Controller.sol,removeController,msg.sender == owner,bt008,bt008 removeController works when owner is msg.sender Controller.sol,removeController,msg.sender != owner,bt009,bt009 removeController reverts when owner is not msg.sender -Controller.sol,removeController,controllers[C]=0,bt017,bt017 removeController does not revert when controllers[C] is 0 +Controller.sol,removeController,controllers[C]=0,bt017,bt017 removeController reverts when controllers[C] is 0 Controller.sol,removeController,controllers[C]=M,bt018,bt018 removeController removes an arbitrary controller FiatTokenV1.sol,constructor,minterManager.isMinter[ALL] == false,bt045,bt045 constructor - minterManager.isMinter[ALL] is false FiatTokenV1.sol,constructor,minterManager.minterAllowance[ALL] == 0,bt046,bt046 constructor - minterManager.minterAllowance[ALL] = 0 From 1a627134493ba58ec78c2a4e4ed0777f220b38f2 Mon Sep 17 00:00:00 2001 From: mgrissa <44446208+mgrissa@users.noreply.github.com> Date: Thu, 17 Jan 2019 09:15:00 -0500 Subject: [PATCH 51/74] CENT-631 - No way to decrement an allowance without reconfiguring minter (#249) * Adding decrementMinterAllowance * adding test for decrementMinterAllowance * adding tests for decrementMinterAllowance in the spreadsheets * improve testing for specific solidity errors in TokenTestUtils --- contracts/minting/MintController.sol | 42 +++++- test/TokenTestUtils.js | 3 +- test/minting/MintP0_ArgumentTests.js | 36 ++++- test/minting2/MintControllerTests.js | 37 +++++ test/minting3/MintP0_BasicTests.js | 141 ++++++++++++++++++ .../Spreadsheets/MINTp0_ArgumentTests.csv | 7 +- .../Spreadsheets/MINTp0_BasicTests.csv | 10 ++ 7 files changed, 270 insertions(+), 6 deletions(-) diff --git a/contracts/minting/MintController.sol b/contracts/minting/MintController.sol index a7d16ed65..4c1d98f72 100644 --- a/contracts/minting/MintController.sol +++ b/contracts/minting/MintController.sol @@ -49,13 +49,20 @@ contract MintController is Controller { address indexed _msgSender, address indexed _minter ); - event MinterAllowanceIncrement( + event MinterAllowanceIncremented( address indexed _msgSender, address indexed _minter, uint256 _increment, uint256 _newAllowance ); + event MinterAllowanceDecremented( + address indexed msgSender, + address indexed minter, + uint256 decrement, + uint256 newAllowance + ); + constructor(address _minterManager) public { minterManager = MinterManagementInterface(_minterManager); } @@ -125,7 +132,7 @@ contract MintController is Controller { uint256 currentAllowance = minterManager.minterAllowance(minter); uint256 newAllowance = currentAllowance.add(_allowanceIncrement); - emit MinterAllowanceIncrement( + emit MinterAllowanceIncremented( msg.sender, minter, _allowanceIncrement, @@ -135,6 +142,37 @@ contract MintController is Controller { return internal_setMinterAllowance(minter, newAllowance); } + /** + * @dev decreases the minter allowance if and only if the minter is + * currently active. The controller can safely send a signed decrementMinterAllowance() + * transaction to a minter and not worry about it being used to undo a removeMinter() + * transaction. + */ + function decrementMinterAllowance( + uint256 _allowanceDecrement + ) + public + onlyController + returns (bool) + { + require(_allowanceDecrement > 0, "Allowance decrement must be greater than 0."); + address minter = controllers[msg.sender]; + require(minterManager.isMinter(minter), "Can only decrement allowance for minters in minterManager."); + + uint256 currentAllowance = minterManager.minterAllowance(minter); + uint256 actualAllowanceDecrement = (currentAllowance > _allowanceDecrement ? _allowanceDecrement : currentAllowance); + uint256 newAllowance = currentAllowance.sub(actualAllowanceDecrement); + + emit MinterAllowanceDecremented( + msg.sender, + minter, + actualAllowanceDecrement, + newAllowance + ); + + return internal_setMinterAllowance(minter, newAllowance); + } + // Internal functions /** diff --git a/test/TokenTestUtils.js b/test/TokenTestUtils.js index 1fd22be98..249baadcc 100644 --- a/test/TokenTestUtils.js +++ b/test/TokenTestUtils.js @@ -40,7 +40,8 @@ var debugLogging = false; // Common solidity error messages var solidityErrors = { - "argumentType": "argument must be a string, Buffer, ArrayBuffer, Array, or array-like object." + "argumentType": "argument must be", + } // Returns a new BN object diff --git a/test/minting/MintP0_ArgumentTests.js b/test/minting/MintP0_ArgumentTests.js index 9d08cef06..303797fb6 100644 --- a/test/minting/MintP0_ArgumentTests.js +++ b/test/minting/MintP0_ArgumentTests.js @@ -177,12 +177,13 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { await expectJump(mintController.incrementMinterAllowance(maxAmount, {from: Accounts.controller1Account})); }); - it('arg018 incrementMinterAlllowance(BIG) throws', async function () { + it('arg018 incrementMinterAllowance(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})); }); + it('arg019 configureController(0, 0) throws', async function () { await expectError(mintController.configureController(zeroAddress, zeroAddress, {from: Accounts.mintOwnerAccount}), "Controller must be a non-zero address"); @@ -217,6 +218,39 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { await expectError(mintController.removeController(Accounts.controller1Account, {from: Accounts.mintOwnerAccount}), "Worker must be a non-zero address"); }) + + it('arg022 decrementMinterAllowance(oldAllowance) sets the allowance to 0', async function () { + var amount = 897; + await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + await mintController.configureMinter(amount, {from: Accounts.controller1Account}); + await mintController.decrementMinterAllowance(amount, {from: Accounts.controller1Account}); + + expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; + expectedTokenState.push( + { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': bigZero } + ); + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + }); + + it('arg023 decrementMinterAllowance(MIN) sets the allowance to 0', async function () { + var amount = 0; + await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + await mintController.configureMinter(amount, {from: Accounts.controller1Account}); + await mintController.decrementMinterAllowance(1, {from: Accounts.controller1Account}); + expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; + expectedTokenState.push( + { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': bigZero } + ); + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + }); + + it('arg024 decrementMinterAllowance(0) throws', async function () { + await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + await expectError(mintController.decrementMinterAllowance(0, {from: Accounts.controller1Account}), "Allowance decrement must be greater than 0."); + }); + } var testWrapper = require('./../TestWrapper'); diff --git a/test/minting2/MintControllerTests.js b/test/minting2/MintControllerTests.js index 544f5a457..c36365367 100644 --- a/test/minting2/MintControllerTests.js +++ b/test/minting2/MintControllerTests.js @@ -139,6 +139,43 @@ async function run_tests(newToken, accounts) { // increment minter allowance await expectError(mintController.incrementMinterAllowance(amount, {from: Accounts.controller1Account}), "Can only increment allowance for minters in minterManager"); }); + + it('decrement minter allowance', async function () { + // configure controller & minter + var amount = 500; + await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + await mintController.configureMinter(amount, {from: Accounts.controller1Account}); + expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; + expectedTokenState.push( + { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) }, + ); + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + + // decrement minter allowance + await mintController.decrementMinterAllowance(amount, {from: Accounts.controller1Account}); + expectedTokenState = [ + { 'variable': 'masterMinter', 'expectedValue': mintController.address }, + { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': bigZero }, + ]; + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + }); + + it('only controller decrements allowance', async function () { + await expectError(mintController.decrementMinterAllowance(0, {from: Accounts.controller1Account}), "The value of controllers[msg.sender] must be non-zero."); + }); + + it('only active minters can have allowance decremented', async function () { + // configure controller but not minter + var amount = 500; + await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + expectedMintControllerState.controllers['controller1Account']= Accounts.minterAccount; + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + + // decrement minter allowance + await expectError(mintController.decrementMinterAllowance(amount, {from: Accounts.controller1Account}), "Can only decrement allowance for minters in minterManager."); + }); } var testWrapper = require('../TestWrapper'); diff --git a/test/minting3/MintP0_BasicTests.js b/test/minting3/MintP0_BasicTests.js index 9f2d9a302..b8f81917f 100644 --- a/test/minting3/MintP0_BasicTests.js +++ b/test/minting3/MintP0_BasicTests.js @@ -605,6 +605,147 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); }); + + it('bt056 decrementMinterAllowance reverts if msg.sender is not a controller', async function () { + await expectError(mintController.decrementMinterAllowance(0, {from: Accounts.controller1Account}), "The value of controllers[msg.sender] must be non-zero."); + }); + + it('bt057 decrementMinterAllowance works when controllers[msg.sender]=M', async function () { + await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + await mintController.configureMinter(6789, {from: Accounts.controller1Account}); + + // now configure minter + var amount = 1; + await mintController.decrementMinterAllowance(amount, {from: Accounts.controller1Account}); + expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; + expectedTokenState.push( + { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(6788) } + ); + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + }); + + it('bt058 decrementMinterAllowance reverts when minterManager is 0', async function () { + // set minterManager to zero + await mintController.setMinterManager(zeroAddress, {from:Accounts.mintOwnerAccount}); + expectedMintControllerState.minterManager = zeroAddress; + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + + // decrementMinterAllowance will fail with any args + await(expectRevert(mintController.decrementMinterAllowance(1, {from: Accounts.controller1Account}))); + }); + + it('bt059 decrementMinterAllowance reverts when minterManager is a user account', async function () { + // set minterManager to user account + await mintController.setMinterManager(Accounts.arbitraryAccount, {from:Accounts.mintOwnerAccount}); + expectedMintControllerState.minterManager = Accounts.arbitraryAccount; + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + + // decrementMinterAllowance will fail with any args + await(expectRevert(mintController.decrementMinterAllowance(1, {from: Accounts.controller1Account}))); + }); + + it('bt060 decrementMinterAllowance works when minterManager is ok', async function () { + await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + await mintController.configureMinter(45, {from: Accounts.controller1Account}); + + // now decrementMinterAllowance + var amount = 45; + await mintController.decrementMinterAllowance(amount, {from: Accounts.controller1Account}); + expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; + expectedTokenState.push( + { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': bigZero } + ); + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + }); + + it('bt061 decrementMinterAllowance(M, amt) reverts when minterManager.isMinter(M)=false', async function () { + var amount = 1; + await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + + var minterManager = await FiatToken.at(await mintController.minterManager()); + var isMinter = await minterManager.isMinter(Accounts.minterAccount); + + assert.isFalse(isMinter); + + await expectError(mintController.decrementMinterAllowance(amount, {from: Accounts.controller1Account}), "Can only decrement allowance for minters in minterManager."); + expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + }); + + it('bt062 decrementMinterAllowance(M, amt) works when minterManager.isMinter(M)=true', async function () { + var amount = 65424; + await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + await mintController.configureMinter(amount, {from: Accounts.controller1Account}); + + var minterManager = await FiatToken.at(await mintController.minterManager()); + var isMinter = await minterManager.isMinter(Accounts.minterAccount); + assert.isTrue(isMinter); + + await mintController.decrementMinterAllowance(amount, {from: Accounts.controller1Account}); + expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; + expectedTokenState.push( + { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': bigZero} + ); + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + }); + + it('bt063 decrementMinterAllowance(M,amt) works when minterAllowance is MAX', async function () { + var amount = maxAmount; + await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + await mintController.configureMinter(amount, {from: Accounts.controller1Account}); + + var minterManager = await FiatToken.at(await mintController.minterManager()); + var minterAllowance = await minterManager.minterAllowance(Accounts.minterAccount); + assert(minterAllowance.cmp(newBigNumber(maxAmount))==0); + await mintController.decrementMinterAllowance(amount, {from: Accounts.controller1Account}); + expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; + expectedTokenState.push( + { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': bigZero } + ); + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + }); + + it('bt064 decrementMinterAllowance(M, amt) works when minterAllowance > 0', async function () { + var initialAmount = 987341; + var decrementAmount = 64; + await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + await mintController.configureMinter(initialAmount, {from: Accounts.controller1Account}); + + var minterManager = await FiatToken.at(await mintController.minterManager()); + var minterAllowance = await minterManager.minterAllowance(Accounts.minterAccount); + assert(minterAllowance.cmp(newBigNumber(initialAmount))==0); + + await mintController.decrementMinterAllowance(decrementAmount, {from: Accounts.controller1Account}); + expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; + expectedTokenState.push( + { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(initialAmount - decrementAmount) } + ); + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + }); + + it('bt065 decrementMinterAllowance(M,amt) sets allowance to 0 when minterAllowance[M] - amt < 0', async function () { + var initialAmount = 45; + var decrementAmount = 64; + await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + await mintController.configureMinter(initialAmount, {from: Accounts.controller1Account}); + + var minterManager = await FiatToken.at(await mintController.minterManager()); + var minterAllowance = await minterManager.minterAllowance(Accounts.minterAccount); + assert(minterAllowance.cmp(newBigNumber(initialAmount))==0); + await mintController.decrementMinterAllowance(decrementAmount, {from: Accounts.controller1Account}); + expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; + expectedTokenState.push( + { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': bigZero } + ); + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + + }); } var testWrapper = require('../TestWrapper'); diff --git a/verification/Spreadsheets/MINTp0_ArgumentTests.csv b/verification/Spreadsheets/MINTp0_ArgumentTests.csv index 6bb969e48..ba3545b83 100644 --- a/verification/Spreadsheets/MINTp0_ArgumentTests.csv +++ b/verification/Spreadsheets/MINTp0_ArgumentTests.csv @@ -17,7 +17,10 @@ MintController.sol,configureMinter,newAllowance == 2^256-1,arg014,arg014 configu MintController.sol,incrementMinterAllowance,increment ==0,arg015,arg015 incrementMinterAllowance(0) throws MintController.sol,incrementMinterAllowance,increment == oldAllowance,arg016,arg016 incrementMinterAllowance(oldAllowance) doubles the allowance MintController.sol,incrementMinterAllowance,increment == 2^256-1,arg017,arg017 incrementMinterAllowance(MAX) throws -MintController.sol,incrementMinterAllowance,increment + oldAllowance == 2^256 -1,arg018,arg018 incrementMinterAlllowance(BIG) throws +MintController.sol,incrementMinterAllowance,increment + oldAllowance == 2^256 -1,arg018,arg018 incrementMinterAllowance(BIG) throws Controller.sol,configureController,newController == 0,arg019,"arg019 configureController(0, 0) throws" Controller.sol,removeController,controller == msg.sender,arg020,arg020 removeController(C) works -Controller.sol,removeController,controller where controllers[controller] == 0,arg021,arg021 removeController throws if worker is already address(0) \ No newline at end of file +Controller.sol,removeController,controller where controllers[controller] == 0,arg021,arg021 removeController throws if worker is already address(0) +MintController.sol,decrementMinterAllowance,decrement == oldAllowance,arg022,arg022 decrementMinterAllowance(oldAllowance) sets the allowance to 0 +MintController.sol,decrementMinterAllowance,oldAllowance - decrement == 0 - 1,arg023,arg023 decrementMinterAllowance(MIN) sets the allowance to 0 +MintController.sol,decrementMinterAllowance,decrement ==0,arg024,arg024 decrementMinterAllowance(0) throws diff --git a/verification/Spreadsheets/MINTp0_BasicTests.csv b/verification/Spreadsheets/MINTp0_BasicTests.csv index 4bdfedca4..fed6ed274 100644 --- a/verification/Spreadsheets/MINTp0_BasicTests.csv +++ b/verification/Spreadsheets/MINTp0_BasicTests.csv @@ -50,3 +50,13 @@ MintController.sol,setMinterManager,minterManager == newMinterManager,bt028,bt02 Ownable.sol,constructor,msg.sender == owner,bt001,bt001 Constructor - owner is msg.sender Ownable.sol,transferOwnership,msg.sender == owner,bt002,bt002 transferOwnership works when owner is msg.sender Ownable.sol,transferOwnership,msg.sender != owner,bt003,bt003 transferOwnership reverts when owner is not msg.sender +MintController.sol,decrementMinterAllowance,controllers[msg.sender]==0,bt056,bt056 decrementMinterAllowance reverts if msg.sender is not a controller +MintController.sol,decrementMinterAllowance,controllers[msg.sender]==M,bt057,bt057 decrementMinterAllowance works when controllers[msg.sender]=M +MintController.sol,decrementMinterAllowance,minterManager = 0,bt058,bt058 decrementMinterAllowance reverts when minterManager is 0 +MintController.sol,decrementMinterAllowance,minterManager != MinterManagerInterface,bt059,bt059 decrementMinterAllowance reverts when minterManager is a user account +MintController.sol,decrementMinterAllowance,minterManager == OK,bt060,bt060 decrementMinterAllowance works when minterManager is ok +MintController.sol,decrementMinterAllowance,minterManager.isMinter == false,bt061,"bt061 decrementMinterAllowance(M, amt) reverts when minterManager.isMinter(M)=false" +MintController.sol,decrementMinterAllowance,minterManager.isMinter == true,bt062,"bt062 decrementMinterAllowance(M, amt) works when minterManager.isMinter(M)=true" +MintController.sol,decrementMinterAllowance,minterManager.minterAllowance[M] == 0,bt063,"bt063 decrementMinterAllowance(M,amt) works when minterAllowance is MAX" +MintController.sol,decrementMinterAllowance,minterManager.minterAllowance[M] == X,bt064,"bt064 decrementMinterAllowance(M, amt) works when minterAllowance > 0" +MintController.sol,decrementMinterAllowance,minterManager.minterAllowance[M] == BIG,bt065,"bt065 decrementMinterAllowance(M,amt) sets allowance to 0 when minterAllowance[M] - amt < 0" \ No newline at end of file From acdf6b54182d4992481d3d39123f7408d3c23011 Mon Sep 17 00:00:00 2001 From: walkerq Date: Thu, 17 Jan 2019 09:18:34 -0500 Subject: [PATCH 52/74] remove hardcoded boolean values being returned from three functions (#275) --- contracts/minting/Controller.sol | 4 ---- contracts/minting/MintController.sol | 2 -- 2 files changed, 6 deletions(-) diff --git a/contracts/minting/Controller.sol b/contracts/minting/Controller.sol index ad1099172..e87276824 100644 --- a/contracts/minting/Controller.sol +++ b/contracts/minting/Controller.sol @@ -65,13 +65,11 @@ contract Controller is Ownable { ) public onlyOwner - returns (bool) { require(_controller != address(0), "Controller must be a non-zero address"); require(_worker != address(0), "Worker must be a non-zero address"); controllers[_controller] = _worker; emit ControllerConfigured(_controller, _worker); - return true; } /** @@ -82,12 +80,10 @@ contract Controller is Ownable { ) public onlyOwner - returns (bool) { require(_controller != address(0), "Controller must be a non-zero address"); require(controllers[_controller] != address(0), "Worker must be a non-zero address"); controllers[_controller] = address(0); emit ControllerRemoved(_controller); - return true; } } diff --git a/contracts/minting/MintController.sol b/contracts/minting/MintController.sol index 4c1d98f72..e0a3e9ae3 100644 --- a/contracts/minting/MintController.sol +++ b/contracts/minting/MintController.sol @@ -77,11 +77,9 @@ contract MintController is Controller { ) public onlyOwner - returns (bool) { emit MinterManagerSet(address(minterManager), _newMinterManager); minterManager = MinterManagementInterface(_newMinterManager); - return true; } // onlyController functions From b762bd47908b4ae23a59aa5d9a2a37cdb16bd8b2 Mon Sep 17 00:00:00 2001 From: Oliver Hudson <32966763+o-a-hudson@users.noreply.github.com> Date: Thu, 17 Jan 2019 09:20:24 -0500 Subject: [PATCH 53/74] Updates dependency installation instructions (#276) --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index cf1fdf91e..4b7747260 100644 --- a/README.md +++ b/README.md @@ -8,11 +8,11 @@ Depends on truffle and testrpc for testing. install truffle: ```npm install -g truffle``` -install ganache-cli: -```npm install -g ganache-cli``` +install yarn: +```npm install -g yarn``` install project npm dependencies: -```npm install``` +```yarn install``` # Testing All tests are run with: From b3a98530a3d40b3bd14b0bdd14563a2141535d02 Mon Sep 17 00:00:00 2001 From: mgrissa <44446208+mgrissa@users.noreply.github.com> Date: Thu, 17 Jan 2019 13:37:26 -0500 Subject: [PATCH 54/74] CENT-639 & CENT-643 - Remove empty Constructor & Adding getters for controllers and minterManager (#277) * Remove empty constructor * Making controllers and minterManager internal and creating getters for them * replace controllers and minterManager by their respective getters in the tests --- contracts/minting/Controller.sol | 14 +++++++-- contracts/minting/MintController.sol | 14 ++++++++- test/minting/MintP0_ArgumentTests.js | 8 ++--- test/minting3/MintP0_BasicTests.js | 44 ++++++++++++++-------------- 4 files changed, 51 insertions(+), 29 deletions(-) diff --git a/contracts/minting/Controller.sol b/contracts/minting/Controller.sol index e87276824..33063220a 100644 --- a/contracts/minting/Controller.sol +++ b/contracts/minting/Controller.sol @@ -32,7 +32,7 @@ import "../Ownable.sol"; contract Controller is Ownable { // controllers[controller] = worker // The controller manages a single worker address. - mapping(address => address) public controllers; + mapping(address => address) internal controllers; event ControllerConfigured( address indexed _controller, @@ -49,7 +49,17 @@ contract Controller is Ownable { _; } - constructor() public { + /** + * @dev gets the worker at address _controller + */ + function getWorker( + address _controller + ) + external + view + returns (address) + { + return controllers[_controller]; } // onlyOwner functions diff --git a/contracts/minting/MintController.sol b/contracts/minting/MintController.sol index e0a3e9ae3..b8d156706 100644 --- a/contracts/minting/MintController.sol +++ b/contracts/minting/MintController.sol @@ -34,7 +34,7 @@ import "openzeppelin-solidity/contracts/math/SafeMath.sol"; contract MintController is Controller { using SafeMath for uint256; - MinterManagementInterface public minterManager; + MinterManagementInterface internal minterManager; event MinterManagerSet( address indexed _oldMinterManager, @@ -67,6 +67,18 @@ contract MintController is Controller { minterManager = MinterManagementInterface(_minterManager); } + /** + * @dev gets the minterManager + */ + function getMinterManager( + ) + external + view + returns (MinterManagementInterface) + { + return minterManager; + } + // onlyOwner functions /** diff --git a/test/minting/MintP0_ArgumentTests.js b/test/minting/MintP0_ArgumentTests.js index 303797fb6..5f44b822a 100644 --- a/test/minting/MintP0_ArgumentTests.js +++ b/test/minting/MintP0_ArgumentTests.js @@ -192,26 +192,26 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { it('arg020 removeController(C) works', async function() { // make controller1Account a controller await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - var actualMinter = await mintController.controllers(Accounts.controller1Account); + var actualMinter = await mintController.getWorker(Accounts.controller1Account); addressEquals(Accounts.minterAccount, actualMinter); // remove controller1Account await mintController.removeController(Accounts.controller1Account, {from : Accounts.mintOwnerAccount}); await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); - actualMinter = await mintController.controllers(Accounts.controller1Account); + actualMinter = await mintController.getWorker(Accounts.controller1Account); addressEquals(actualMinter, zeroAddress); }); it('arg021 removeController throws if worker is already address(0)', async function () { // make controller1Account a controller await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - var actualMinter = await mintController.controllers(Accounts.controller1Account); + var actualMinter = await mintController.getWorker(Accounts.controller1Account); addressEquals(Accounts.minterAccount, actualMinter); // remove controller1Account await mintController.removeController(Accounts.controller1Account, {from : Accounts.mintOwnerAccount}); await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); - actualMinter = await mintController.controllers(Accounts.controller1Account); + actualMinter = await mintController.getWorker(Accounts.controller1Account); addressEquals(actualMinter, zeroAddress); // attempting to remove the controller1Account again should throw because the worker is already set to address(0). diff --git a/test/minting3/MintP0_BasicTests.js b/test/minting3/MintP0_BasicTests.js index b8f81917f..08f3ba908 100644 --- a/test/minting3/MintP0_BasicTests.js +++ b/test/minting3/MintP0_BasicTests.js @@ -232,7 +232,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { }); it('bt024 Constructor sets minterManager', async function () { - var minterManagerAddress = await mintController.minterManager(); + var minterManagerAddress = await mintController.getMinterManager(); assert.isTrue(addressEquals(token.address, minterManagerAddress)); }); @@ -251,14 +251,14 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { }); it('bt028 setMinterManager(x) works when x = minterManager', async function () { - var minterManagerAddress = await mintController.minterManager(); + var minterManagerAddress = await mintController.getMinterManager(); await mintController.setMinterManager(minterManagerAddress, {from: Accounts.mintOwnerAccount}); await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); }); it('bt030 removeMinter reverts when minterManager is 0', async function () { // set minterManager - var minterManagerAddress = await mintController.minterManager(); + var minterManagerAddress = await mintController.getMinterManager(); await mintController.setMinterManager(minterManagerAddress, {from:Accounts.mintOwnerAccount}); expectedMintControllerState.minterManager = minterManagerAddress; await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); @@ -348,7 +348,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { var amount = 64; await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - var minterManager = await FiatToken.at(await mintController.minterManager()); + var minterManager = await FiatToken.at(await mintController.getMinterManager()); var isMinter = await minterManager.isMinter(Accounts.minterAccount); assert.isFalse(isMinter); @@ -366,7 +366,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); await mintController.configureMinter(0, {from: Accounts.controller1Account}); - var minterManager = await FiatToken.at(await mintController.minterManager()); + var minterManager = await FiatToken.at(await mintController.getMinterManager()); var isMinter = await minterManager.isMinter(Accounts.minterAccount); assert.isTrue(isMinter); @@ -383,7 +383,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { var amount = 64; await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - var minterManager = await FiatToken.at(await mintController.minterManager()); + var minterManager = await FiatToken.at(await mintController.getMinterManager()); var isMinter = await minterManager.isMinter(Accounts.minterAccount); assert.isFalse(isMinter); @@ -397,7 +397,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); await mintController.configureMinter(0, {from: Accounts.controller1Account}); - var minterManager = await FiatToken.at(await mintController.minterManager()); + var minterManager = await FiatToken.at(await mintController.getMinterManager()); var isMinter = await minterManager.isMinter(Accounts.minterAccount); assert.isTrue(isMinter); @@ -410,7 +410,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { var amount = 64; await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - var minterManager = await FiatToken.at(await mintController.minterManager()); + var minterManager = await FiatToken.at(await mintController.getMinterManager()); var isMinter = await minterManager.isMinter(Accounts.minterAccount); assert.isFalse(isMinter); @@ -424,7 +424,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); await mintController.configureMinter(0, {from: Accounts.controller1Account}); - var minterManager = await FiatToken.at(await mintController.minterManager()); + var minterManager = await FiatToken.at(await mintController.getMinterManager()); var isMinter = await minterManager.isMinter(Accounts.minterAccount); assert.isTrue(isMinter); @@ -438,7 +438,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { }); it('bt045 constructor - minterManager.isMinter[ALL] is false', async function () { - var minterManager = await FiatToken.at(await mintController.minterManager()); + var minterManager = await FiatToken.at(await mintController.getMinterManager()); var isMinterMappingEval = async function(accountAddress) { return await minterManager.isMinter(accountAddress); @@ -451,7 +451,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { }); it('bt046 constructor - minterManager.minterAllowance[ALL] = 0', async function () { - var minterManager = await FiatToken.at(await mintController.minterManager()); + var minterManager = await FiatToken.at(await mintController.getMinterManager()); var minterAllowanceMapping = async function(accountAddress) { return await minterManager.minterAllowance(accountAddress); @@ -468,7 +468,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); await mintController.configureMinter(0, {from: Accounts.controller1Account}); - var minterManager = await FiatToken.at(await mintController.minterManager()); + var minterManager = await FiatToken.at(await mintController.getMinterManager()); var minterAllowance = await minterManager.minterAllowance(Accounts.minterAccount); assert(minterAllowance.isZero()); @@ -487,7 +487,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); await mintController.configureMinter(initialAmount, {from: Accounts.controller1Account}); - var minterManager = await FiatToken.at(await mintController.minterManager()); + var minterManager = await FiatToken.at(await mintController.getMinterManager()); var minterAllowance = await minterManager.minterAllowance(Accounts.minterAccount); assert(minterAllowance.cmp(newBigNumber(initialAmount))==0); @@ -522,7 +522,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); await mintController.configureMinter(0, {from: Accounts.controller1Account}); - var minterManager = await FiatToken.at(await mintController.minterManager()); + var minterManager = await FiatToken.at(await mintController.getMinterManager()); var minterAllowance = await minterManager.minterAllowance(Accounts.minterAccount); assert(minterAllowance.cmp(newBigNumber(0))==0); @@ -540,7 +540,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); await mintController.configureMinter(amount, {from: Accounts.controller1Account}); - var minterManager = await FiatToken.at(await mintController.minterManager()); + var minterManager = await FiatToken.at(await mintController.getMinterManager()); var minterAllowance = await minterManager.minterAllowance(Accounts.minterAccount); assert(minterAllowance.cmp(newBigNumber(amount))==0); @@ -573,7 +573,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); await mintController.configureMinter(0, {from: Accounts.controller1Account}); - var minterManager = await FiatToken.at(await mintController.minterManager()); + var minterManager = await FiatToken.at(await mintController.getMinterManager()); var minterAllowance = await minterManager.minterAllowance(Accounts.minterAccount); assert(minterAllowance.isZero()); @@ -587,7 +587,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); await mintController.configureMinter(amount, {from: Accounts.controller1Account}); - var minterManager = await FiatToken.at(await mintController.minterManager()); + var minterManager = await FiatToken.at(await mintController.getMinterManager()); var minterAllowance = await minterManager.minterAllowance(Accounts.minterAccount); assert(minterAllowance.cmp(newBigNumber(amount))==0); @@ -664,7 +664,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { var amount = 1; await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - var minterManager = await FiatToken.at(await mintController.minterManager()); + var minterManager = await FiatToken.at(await mintController.getMinterManager()); var isMinter = await minterManager.isMinter(Accounts.minterAccount); assert.isFalse(isMinter); @@ -679,7 +679,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); await mintController.configureMinter(amount, {from: Accounts.controller1Account}); - var minterManager = await FiatToken.at(await mintController.minterManager()); + var minterManager = await FiatToken.at(await mintController.getMinterManager()); var isMinter = await minterManager.isMinter(Accounts.minterAccount); assert.isTrue(isMinter); @@ -697,7 +697,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); await mintController.configureMinter(amount, {from: Accounts.controller1Account}); - var minterManager = await FiatToken.at(await mintController.minterManager()); + var minterManager = await FiatToken.at(await mintController.getMinterManager()); var minterAllowance = await minterManager.minterAllowance(Accounts.minterAccount); assert(minterAllowance.cmp(newBigNumber(maxAmount))==0); await mintController.decrementMinterAllowance(amount, {from: Accounts.controller1Account}); @@ -715,7 +715,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); await mintController.configureMinter(initialAmount, {from: Accounts.controller1Account}); - var minterManager = await FiatToken.at(await mintController.minterManager()); + var minterManager = await FiatToken.at(await mintController.getMinterManager()); var minterAllowance = await minterManager.minterAllowance(Accounts.minterAccount); assert(minterAllowance.cmp(newBigNumber(initialAmount))==0); @@ -734,7 +734,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); await mintController.configureMinter(initialAmount, {from: Accounts.controller1Account}); - var minterManager = await FiatToken.at(await mintController.minterManager()); + var minterManager = await FiatToken.at(await mintController.getMinterManager()); var minterAllowance = await minterManager.minterAllowance(Accounts.minterAccount); assert(minterAllowance.cmp(newBigNumber(initialAmount))==0); await mintController.decrementMinterAllowance(decrementAmount, {from: Accounts.controller1Account}); From fbb6cfeb503ece6719cd456f82e6ef1602145db3 Mon Sep 17 00:00:00 2001 From: walkerq Date: Fri, 18 Jan 2019 10:44:05 -0500 Subject: [PATCH 55/74] Document multi-issuer contracts according to NatSpec guidelines (#274) * document multi-issuer contracts according to NatSpec * fix line wrapping in contracts * remove periods in require statement error messages. --- contracts/minting/Controller.sol | 38 +++++++---- contracts/minting/MasterMinter.sol | 6 ++ contracts/minting/MintController.sol | 66 +++++++++++++------ .../minting/MinterManagementInterface.sol | 7 +- test/minting/MintP0_ArgumentTests.js | 4 +- test/minting2/MintControllerTests.js | 4 +- test/minting3/MintP0_BasicTests.js | 4 +- 7 files changed, 86 insertions(+), 43 deletions(-) diff --git a/contracts/minting/Controller.sol b/contracts/minting/Controller.sol index 33063220a..91f851ced 100644 --- a/contracts/minting/Controller.sol +++ b/contracts/minting/Controller.sol @@ -26,12 +26,15 @@ import "../Ownable.sol"; /** * @title Controller - * @dev Generic implementation of the owner-controller-worker model. - * + * @notice Generic implementation of the owner-controller-worker model. + * One owner manages many controllers. Each controller manages one worker. + * Workers may be reused across different controllers. */ contract Controller is Ownable { - // controllers[controller] = worker - // The controller manages a single worker address. + /** + * @notice A controller manages a single worker address. + * controllers[controller] = worker + */ mapping(address => address) internal controllers; event ControllerConfigured( @@ -41,7 +44,8 @@ contract Controller is Ownable { event ControllerRemoved(address indexed _controller); /** - * @dev ensure that caller is the controller of a non-zero worker address + * @notice Ensures that caller is the controller of a non-zero worker + * address. */ modifier onlyController() { require(controllers[msg.sender] != address(0), @@ -50,8 +54,8 @@ contract Controller is Ownable { } /** - * @dev gets the worker at address _controller - */ + * @notice Gets the worker at address _controller. + */ function getWorker( address _controller ) @@ -65,9 +69,11 @@ contract Controller is Ownable { // onlyOwner functions /** - * @dev set the controller of a particular _worker. - * Argument _worker must not be 0x00. Call removeController(_controller) - * instead to disable the controller. + * @notice Configure a controller with the given worker. + * @param _controller The controller to be configured with a worker. + * @param _worker The worker to be set for the newly configured controller. + * _worker must not be a non-zero address. To disable a worker, + * use removeController instead. */ function configureController( address _controller, @@ -76,14 +82,16 @@ contract Controller is Ownable { public onlyOwner { - require(_controller != address(0), "Controller must be a non-zero address"); + require(_controller != address(0), + "Controller must be a non-zero address"); require(_worker != address(0), "Worker must be a non-zero address"); controllers[_controller] = _worker; emit ControllerConfigured(_controller, _worker); } /** - * @dev disables a controller by setting its worker to address(0); + * @notice disables a controller by setting its worker to address(0). + * @param _controller The controller to disable. */ function removeController( address _controller @@ -91,8 +99,10 @@ contract Controller is Ownable { public onlyOwner { - require(_controller != address(0), "Controller must be a non-zero address"); - require(controllers[_controller] != address(0), "Worker must be a non-zero address"); + require(_controller != address(0), + "Controller must be a non-zero address"); + require(controllers[_controller] != address(0), + "Worker must be a non-zero address"); controllers[_controller] = address(0); emit ControllerRemoved(_controller); } diff --git a/contracts/minting/MasterMinter.sol b/contracts/minting/MasterMinter.sol index 37b04b2e3..372123bce 100644 --- a/contracts/minting/MasterMinter.sol +++ b/contracts/minting/MasterMinter.sol @@ -24,6 +24,12 @@ pragma solidity ^0.4.24; import "./MintController.sol"; +/** + * @title MasterMinter + * @notice MasterMinter uses multiple controllers to manage minters for a + * contract that implements the MinterManagerInterface. + * @dev MasterMinter inherits all its functionality from MintController. + */ contract MasterMinter is MintController { constructor(address _minterManager) MintController(_minterManager) public { diff --git a/contracts/minting/MintController.sol b/contracts/minting/MintController.sol index b8d156706..9566f35ec 100644 --- a/contracts/minting/MintController.sol +++ b/contracts/minting/MintController.sol @@ -28,12 +28,23 @@ import "openzeppelin-solidity/contracts/math/SafeMath.sol"; /** * @title MintController - * @dev allows control of configure/remove minter by different addresses - * + * @notice The MintController contract manages minters for a contract that + * implements the MinterManagerInterface. It lets the owner designate certain + * addresses as controllers, and these controllers then manage the + * minters by adding and removing minters, as well as modifying their minting + * allowance. A controller may manage exactly one minter, but the same minter + * address may be managed by multiple controllers. + * @dev MintController inherits from the Controller contract. It treats the + * Controller workers as minters. */ contract MintController is Controller { using SafeMath for uint256; + /** + * @title MinterManagementInterface + * @notice MintController calls the minterManager to execute/record minter + * management tasks, as well as to query the status of a minter address. + */ MinterManagementInterface internal minterManager; event MinterManagerSet( @@ -63,12 +74,16 @@ contract MintController is Controller { uint256 newAllowance ); + /** + * @notice Initializes the minterManager. + * @param _minterManager The address of the minterManager contract. + */ constructor(address _minterManager) public { minterManager = MinterManagementInterface(_minterManager); } /** - * @dev gets the minterManager + * @notice gets the minterManager */ function getMinterManager( ) @@ -82,7 +97,8 @@ contract MintController is Controller { // onlyOwner functions /** - * @dev sets the minterManager + * @notice Sets the minterManager. + * @param _newMinterManager The address of the new minterManager contract. */ function setMinterManager( address _newMinterManager @@ -97,7 +113,7 @@ contract MintController is Controller { // onlyController functions /** - * @dev remove the controller's minter. + * @notice Removes the controller's own minter. */ function removeMinter() public onlyController returns (bool) { address minter = controllers[msg.sender]; @@ -106,7 +122,8 @@ contract MintController is Controller { } /** - * @dev Enables the minter and sets its allowance + * @notice Enables the minter and sets its allowance. + * @param _newAllowance New allowance to be set for minter. */ function configureMinter( uint256 _newAllowance @@ -121,12 +138,11 @@ contract MintController is Controller { } /** - * @dev Increases the minter allowance if and only if the minter is - * currently active. The controller can safely send a signed - * incrementMinterAllowance() transaction to a minter and not worry - * about it being used to undo a removeMinter() transaction. + * @notice Increases the minter's allowance if and only if the minter is an + * active minter. + * @dev An minter is considered active if minterManager.isMinter(minter) + * returns true. */ - function incrementMinterAllowance( uint256 _allowanceIncrement ) @@ -134,7 +150,8 @@ contract MintController is Controller { onlyController returns (bool) { - require(_allowanceIncrement > 0, "Allowance increment must be greater than 0"); + require(_allowanceIncrement > 0, + "Allowance increment must be greater than 0"); address minter = controllers[msg.sender]; require(minterManager.isMinter(minter), "Can only increment allowance for minters in minterManager"); @@ -153,10 +170,10 @@ contract MintController is Controller { } /** - * @dev decreases the minter allowance if and only if the minter is - * currently active. The controller can safely send a signed decrementMinterAllowance() - * transaction to a minter and not worry about it being used to undo a removeMinter() - * transaction. + * @notice decreases the minter allowance if and only if the minter is + * currently active. The controller can safely send a signed + * decrementMinterAllowance() transaction to a minter and not worry + * about it being used to undo a removeMinter() transaction. */ function decrementMinterAllowance( uint256 _allowanceDecrement @@ -165,12 +182,17 @@ contract MintController is Controller { onlyController returns (bool) { - require(_allowanceDecrement > 0, "Allowance decrement must be greater than 0."); + require(_allowanceDecrement > 0, + "Allowance decrement must be greater than 0"); address minter = controllers[msg.sender]; - require(minterManager.isMinter(minter), "Can only decrement allowance for minters in minterManager."); + require(minterManager.isMinter(minter), + "Can only decrement allowance for minters in minterManager"); uint256 currentAllowance = minterManager.minterAllowance(minter); - uint256 actualAllowanceDecrement = (currentAllowance > _allowanceDecrement ? _allowanceDecrement : currentAllowance); + uint256 actualAllowanceDecrement = ( + currentAllowance > _allowanceDecrement ? + _allowanceDecrement : currentAllowance + ); uint256 newAllowance = currentAllowance.sub(actualAllowanceDecrement); emit MinterAllowanceDecremented( @@ -183,11 +205,13 @@ contract MintController is Controller { return internal_setMinterAllowance(minter, newAllowance); } - // Internal functions + // Internal functions /** - * @dev Uses the MinterManagementInterface to enable the minter and + * @notice Uses the MinterManagementInterface to enable the minter and * set its allowance. + * @param _minter Minter to set new allowance of. + * @param _newAllowance New allowance to be set for minter. */ function internal_setMinterAllowance( address _minter, diff --git a/contracts/minting/MinterManagementInterface.sol b/contracts/minting/MinterManagementInterface.sol index faf82b3cb..88af54d94 100644 --- a/contracts/minting/MinterManagementInterface.sol +++ b/contracts/minting/MinterManagementInterface.sol @@ -22,8 +22,11 @@ pragma solidity ^0.4.24; -// Using an interface for managing minters so that MintController -// can be used for managing minters with different contracts. +/** + * @notice A contract that implements the MinterManagementInterface has external + * functions for adding and removing minters and modifying their allowances. + * An example is the FiatTokenV1 contract that implements USDC. + */ interface MinterManagementInterface { function isMinter(address _account) external view returns (bool); function minterAllowance(address _minter) external view returns (uint256); diff --git a/test/minting/MintP0_ArgumentTests.js b/test/minting/MintP0_ArgumentTests.js index 5f44b822a..bdfd240a6 100644 --- a/test/minting/MintP0_ArgumentTests.js +++ b/test/minting/MintP0_ArgumentTests.js @@ -153,7 +153,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { it('arg015 incrementMinterAllowance(0) throws', async function () { await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - await expectError(mintController.incrementMinterAllowance(0, {from: Accounts.controller1Account}), "Allowance increment must be greater than 0."); + await expectError(mintController.incrementMinterAllowance(0, {from: Accounts.controller1Account}), "Allowance increment must be greater than 0"); }); it('arg016 incrementMinterAllowance(oldAllowance) doubles the allowance', async function () { @@ -248,7 +248,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { it('arg024 decrementMinterAllowance(0) throws', async function () { await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - await expectError(mintController.decrementMinterAllowance(0, {from: Accounts.controller1Account}), "Allowance decrement must be greater than 0."); + await expectError(mintController.decrementMinterAllowance(0, {from: Accounts.controller1Account}), "Allowance decrement must be greater than 0"); }); } diff --git a/test/minting2/MintControllerTests.js b/test/minting2/MintControllerTests.js index c36365367..8d22c34b9 100644 --- a/test/minting2/MintControllerTests.js +++ b/test/minting2/MintControllerTests.js @@ -163,7 +163,7 @@ async function run_tests(newToken, accounts) { }); it('only controller decrements allowance', async function () { - await expectError(mintController.decrementMinterAllowance(0, {from: Accounts.controller1Account}), "The value of controllers[msg.sender] must be non-zero."); + await expectError(mintController.decrementMinterAllowance(0, {from: Accounts.controller1Account}), "The value of controllers[msg.sender] must be non-zero"); }); it('only active minters can have allowance decremented', async function () { @@ -174,7 +174,7 @@ async function run_tests(newToken, accounts) { await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); // decrement minter allowance - await expectError(mintController.decrementMinterAllowance(amount, {from: Accounts.controller1Account}), "Can only decrement allowance for minters in minterManager."); + await expectError(mintController.decrementMinterAllowance(amount, {from: Accounts.controller1Account}), "Can only decrement allowance for minters in minterManager"); }); } diff --git a/test/minting3/MintP0_BasicTests.js b/test/minting3/MintP0_BasicTests.js index 08f3ba908..c20d0999c 100644 --- a/test/minting3/MintP0_BasicTests.js +++ b/test/minting3/MintP0_BasicTests.js @@ -607,7 +607,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { }); it('bt056 decrementMinterAllowance reverts if msg.sender is not a controller', async function () { - await expectError(mintController.decrementMinterAllowance(0, {from: Accounts.controller1Account}), "The value of controllers[msg.sender] must be non-zero."); + await expectError(mintController.decrementMinterAllowance(0, {from: Accounts.controller1Account}), "The value of controllers[msg.sender] must be non-zero"); }); it('bt057 decrementMinterAllowance works when controllers[msg.sender]=M', async function () { @@ -669,7 +669,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { assert.isFalse(isMinter); - await expectError(mintController.decrementMinterAllowance(amount, {from: Accounts.controller1Account}), "Can only decrement allowance for minters in minterManager."); + await expectError(mintController.decrementMinterAllowance(amount, {from: Accounts.controller1Account}), "Can only decrement allowance for minters in minterManager"); expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); }); From 12e6458ed00f8ff279342e6d5fff90a8a745ef15 Mon Sep 17 00:00:00 2001 From: mirathewhite Date: Tue, 19 Mar 2019 12:00:12 -0400 Subject: [PATCH 56/74] added copy of MasterMiner code from etherscan --- validate/MasterMinter.etherscan | 561 ++++++++++++++++++++++++++++++++ validate/README.contractDiff.md | 6 +- 2 files changed, 564 insertions(+), 3 deletions(-) create mode 100644 validate/MasterMinter.etherscan diff --git a/validate/MasterMinter.etherscan b/validate/MasterMinter.etherscan new file mode 100644 index 000000000..959042d23 --- /dev/null +++ b/validate/MasterMinter.etherscan @@ -0,0 +1,561 @@ +pragma solidity ^0.4.24; + +// File: contracts/Ownable.sol + +/** +* Copyright CENTRE SECZ 2018 +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is furnished to +* do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in all +* copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +pragma solidity ^0.4.24; + +/** + * @title Ownable + * @dev The Ownable contract from https://github.com/zeppelinos/labs/blob/master/upgradeability_ownership/contracts/ownership/Ownable.sol + * branch: master commit: 3887ab77b8adafba4a26ace002f3a684c1a3388b modified to: + * 1) Add emit prefix to OwnershipTransferred event (7/13/18) + * 2) Replace constructor with constructor syntax (7/13/18) + * 3) consolidate OwnableStorage into this contract + */ +contract Ownable { + + // Owner of the contract + address private _owner; + + /** + * @dev Event to show ownership has been transferred + * @param previousOwner representing the address of the previous owner + * @param newOwner representing the address of the new owner + */ + event OwnershipTransferred(address previousOwner, address newOwner); + + /** + * @dev The constructor sets the original owner of the contract to the sender account. + */ + constructor() public { + setOwner(msg.sender); + } + + /** + * @dev Tells the address of the owner + * @return the address of the owner + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Sets a new owner address + */ + function setOwner(address newOwner) internal { + _owner = newOwner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(msg.sender == owner()); + _; + } + + /** + * @dev Allows the current owner to transfer control of the contract to a newOwner. + * @param newOwner The address to transfer ownership to. + */ + function transferOwnership(address newOwner) public onlyOwner { + require(newOwner != address(0)); + emit OwnershipTransferred(owner(), newOwner); + setOwner(newOwner); + } +} + +// File: contracts/minting/Controller.sol + +/** +* Copyright CENTRE SECZ 2018 +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in all +* copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ + +pragma solidity ^0.4.24; + + +/** + * @title Controller + * @notice Generic implementation of the owner-controller-worker model. + * One owner manages many controllers. Each controller manages one worker. + * Workers may be reused across different controllers. + */ +contract Controller is Ownable { + /** + * @notice A controller manages a single worker address. + * controllers[controller] = worker + */ + mapping(address => address) internal controllers; + + event ControllerConfigured( + address indexed _controller, + address indexed _worker + ); + event ControllerRemoved(address indexed _controller); + + /** + * @notice Ensures that caller is the controller of a non-zero worker + * address. + */ + modifier onlyController() { + require(controllers[msg.sender] != address(0), + "The value of controllers[msg.sender] must be non-zero"); + _; + } + + /** + * @notice Gets the worker at address _controller. + */ + function getWorker( + address _controller + ) + external + view + returns (address) + { + return controllers[_controller]; + } + + // onlyOwner functions + + /** + * @notice Configure a controller with the given worker. + * @param _controller The controller to be configured with a worker. + * @param _worker The worker to be set for the newly configured controller. + * _worker must not be a non-zero address. To disable a worker, + * use removeController instead. + */ + function configureController( + address _controller, + address _worker + ) + public + onlyOwner + { + require(_controller != address(0), + "Controller must be a non-zero address"); + require(_worker != address(0), "Worker must be a non-zero address"); + controllers[_controller] = _worker; + emit ControllerConfigured(_controller, _worker); + } + + /** + * @notice disables a controller by setting its worker to address(0). + * @param _controller The controller to disable. + */ + function removeController( + address _controller + ) + public + onlyOwner + { + require(_controller != address(0), + "Controller must be a non-zero address"); + require(controllers[_controller] != address(0), + "Worker must be a non-zero address"); + controllers[_controller] = address(0); + emit ControllerRemoved(_controller); + } +} + +// File: contracts/minting/MinterManagementInterface.sol + +/** +* Copyright CENTRE SECZ 2019 +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in all +* copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ + +pragma solidity ^0.4.24; + +/** + * @notice A contract that implements the MinterManagementInterface has external + * functions for adding and removing minters and modifying their allowances. + * An example is the FiatTokenV1 contract that implements USDC. + */ +interface MinterManagementInterface { + function isMinter(address _account) external view returns (bool); + function minterAllowance(address _minter) external view returns (uint256); + + function configureMinter( + address _minter, + uint256 _minterAllowedAmount + ) + external + returns (bool); + + function removeMinter(address _minter) external returns (bool); +} + +// File: openzeppelin-solidity/contracts/math/SafeMath.sol + +/** + * @title SafeMath + * @dev Math operations with safety checks that throw on error + */ +library SafeMath { + + /** + * @dev Multiplies two numbers, throws on overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256 c) { + // Gas optimization: this is cheaper than asserting 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522 + if (a == 0) { + return 0; + } + + c = a * b; + assert(c / a == b); + return c; + } + + /** + * @dev Integer division of two numbers, truncating the quotient. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + // assert(b > 0); // Solidity automatically throws when dividing by 0 + // uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + return a / b; + } + + /** + * @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend). + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + assert(b <= a); + return a - b; + } + + /** + * @dev Adds two numbers, throws on overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256 c) { + c = a + b; + assert(c >= a); + return c; + } +} + +// File: contracts/minting/MintController.sol + +/** +* Copyright CENTRE SECZ 2018 +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in all +* copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ + +pragma solidity ^0.4.24; + + + + +/** + * @title MintController + * @notice The MintController contract manages minters for a contract that + * implements the MinterManagerInterface. It lets the owner designate certain + * addresses as controllers, and these controllers then manage the + * minters by adding and removing minters, as well as modifying their minting + * allowance. A controller may manage exactly one minter, but the same minter + * address may be managed by multiple controllers. + * @dev MintController inherits from the Controller contract. It treats the + * Controller workers as minters. + */ +contract MintController is Controller { + using SafeMath for uint256; + + /** + * @title MinterManagementInterface + * @notice MintController calls the minterManager to execute/record minter + * management tasks, as well as to query the status of a minter address. + */ + MinterManagementInterface internal minterManager; + + event MinterManagerSet( + address indexed _oldMinterManager, + address indexed _newMinterManager + ); + event MinterConfigured( + address indexed _msgSender, + address indexed _minter, + uint256 _allowance + ); + event MinterRemoved( + address indexed _msgSender, + address indexed _minter + ); + event MinterAllowanceIncremented( + address indexed _msgSender, + address indexed _minter, + uint256 _increment, + uint256 _newAllowance + ); + + event MinterAllowanceDecremented( + address indexed msgSender, + address indexed minter, + uint256 decrement, + uint256 newAllowance + ); + + /** + * @notice Initializes the minterManager. + * @param _minterManager The address of the minterManager contract. + */ + constructor(address _minterManager) public { + minterManager = MinterManagementInterface(_minterManager); + } + + /** + * @notice gets the minterManager + */ + function getMinterManager( + ) + external + view + returns (MinterManagementInterface) + { + return minterManager; + } + + // onlyOwner functions + + /** + * @notice Sets the minterManager. + * @param _newMinterManager The address of the new minterManager contract. + */ + function setMinterManager( + address _newMinterManager + ) + public + onlyOwner + { + emit MinterManagerSet(address(minterManager), _newMinterManager); + minterManager = MinterManagementInterface(_newMinterManager); + } + + // onlyController functions + + /** + * @notice Removes the controller's own minter. + */ + function removeMinter() public onlyController returns (bool) { + address minter = controllers[msg.sender]; + emit MinterRemoved(msg.sender, minter); + return minterManager.removeMinter(minter); + } + + /** + * @notice Enables the minter and sets its allowance. + * @param _newAllowance New allowance to be set for minter. + */ + function configureMinter( + uint256 _newAllowance + ) + public + onlyController + returns (bool) + { + address minter = controllers[msg.sender]; + emit MinterConfigured(msg.sender, minter, _newAllowance); + return internal_setMinterAllowance(minter, _newAllowance); + } + + /** + * @notice Increases the minter's allowance if and only if the minter is an + * active minter. + * @dev An minter is considered active if minterManager.isMinter(minter) + * returns true. + */ + function incrementMinterAllowance( + uint256 _allowanceIncrement + ) + public + onlyController + returns (bool) + { + require(_allowanceIncrement > 0, + "Allowance increment must be greater than 0"); + address minter = controllers[msg.sender]; + require(minterManager.isMinter(minter), + "Can only increment allowance for minters in minterManager"); + + uint256 currentAllowance = minterManager.minterAllowance(minter); + uint256 newAllowance = currentAllowance.add(_allowanceIncrement); + + emit MinterAllowanceIncremented( + msg.sender, + minter, + _allowanceIncrement, + newAllowance + ); + + return internal_setMinterAllowance(minter, newAllowance); + } + + /** + * @notice decreases the minter allowance if and only if the minter is + * currently active. The controller can safely send a signed + * decrementMinterAllowance() transaction to a minter and not worry + * about it being used to undo a removeMinter() transaction. + */ + function decrementMinterAllowance( + uint256 _allowanceDecrement + ) + public + onlyController + returns (bool) + { + require(_allowanceDecrement > 0, + "Allowance decrement must be greater than 0"); + address minter = controllers[msg.sender]; + require(minterManager.isMinter(minter), + "Can only decrement allowance for minters in minterManager"); + + uint256 currentAllowance = minterManager.minterAllowance(minter); + uint256 actualAllowanceDecrement = ( + currentAllowance > _allowanceDecrement ? + _allowanceDecrement : currentAllowance + ); + uint256 newAllowance = currentAllowance.sub(actualAllowanceDecrement); + + emit MinterAllowanceDecremented( + msg.sender, + minter, + actualAllowanceDecrement, + newAllowance + ); + + return internal_setMinterAllowance(minter, newAllowance); + } + + // Internal functions + + /** + * @notice Uses the MinterManagementInterface to enable the minter and + * set its allowance. + * @param _minter Minter to set new allowance of. + * @param _newAllowance New allowance to be set for minter. + */ + function internal_setMinterAllowance( + address _minter, + uint256 _newAllowance + ) + internal + returns (bool) + { + return minterManager.configureMinter(_minter, _newAllowance); + } +} + +// File: contracts/minting/MasterMinter.sol + +/** +* Copyright CENTRE SECZ 2018 +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in all +* copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ + +pragma solidity ^0.4.24; + + +/** + * @title MasterMinter + * @notice MasterMinter uses multiple controllers to manage minters for a + * contract that implements the MinterManagerInterface. + * @dev MasterMinter inherits all its functionality from MintController. + */ +contract MasterMinter is MintController { + + constructor(address _minterManager) MintController(_minterManager) public { + } +} \ No newline at end of file diff --git a/validate/README.contractDiff.md b/validate/README.contractDiff.md index 9655d5938..c3d92673d 100644 --- a/validate/README.contractDiff.md +++ b/validate/README.contractDiff.md @@ -19,16 +19,16 @@ At the end of the run, `checkDiff` will output which files it was able to proces means that the Etherscan file could be read AND all the included files could be read. Validity should be determined by actually looking at the diffs. -# Running checkDiff.js +# Running contractDiff.js To run the script, type `node validate/contractDiff.js ... ` Where the `filename` is the location of source code downloaded from Etherscan. -Copies of `FiatTokenProxy` and `FiatTokenV1` are included for testing purposes. +Copies of `FiatTokenProxy`, `FiatTokenV1`, and `MasterMinter` are included for testing purposes. You can test them: -`node validate/contractDiff.js validate/FiatTokenProxy.etherscan validate/FiatTokenV1.etherscan` +`node validate/contractDiff.js validate/FiatTokenProxy.etherscan validate/FiatTokenV1.etherscan validate/MasterMinter.etherscan` # Finding code on Etherscan 1. Go to [https://etherscan.io](https://etherscan.io) From f7e063f1a1908879f5ab9ddfd5f62e1f997d9f1e Mon Sep 17 00:00:00 2001 From: mirathewhite Date: Tue, 19 Mar 2019 12:27:48 -0400 Subject: [PATCH 57/74] added copy of MasterMiner code from etherscan (#280) --- validate/MasterMinter.etherscan | 561 ++++++++++++++++++++++++++++++++ validate/README.contractDiff.md | 6 +- 2 files changed, 564 insertions(+), 3 deletions(-) create mode 100644 validate/MasterMinter.etherscan diff --git a/validate/MasterMinter.etherscan b/validate/MasterMinter.etherscan new file mode 100644 index 000000000..959042d23 --- /dev/null +++ b/validate/MasterMinter.etherscan @@ -0,0 +1,561 @@ +pragma solidity ^0.4.24; + +// File: contracts/Ownable.sol + +/** +* Copyright CENTRE SECZ 2018 +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is furnished to +* do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in all +* copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +pragma solidity ^0.4.24; + +/** + * @title Ownable + * @dev The Ownable contract from https://github.com/zeppelinos/labs/blob/master/upgradeability_ownership/contracts/ownership/Ownable.sol + * branch: master commit: 3887ab77b8adafba4a26ace002f3a684c1a3388b modified to: + * 1) Add emit prefix to OwnershipTransferred event (7/13/18) + * 2) Replace constructor with constructor syntax (7/13/18) + * 3) consolidate OwnableStorage into this contract + */ +contract Ownable { + + // Owner of the contract + address private _owner; + + /** + * @dev Event to show ownership has been transferred + * @param previousOwner representing the address of the previous owner + * @param newOwner representing the address of the new owner + */ + event OwnershipTransferred(address previousOwner, address newOwner); + + /** + * @dev The constructor sets the original owner of the contract to the sender account. + */ + constructor() public { + setOwner(msg.sender); + } + + /** + * @dev Tells the address of the owner + * @return the address of the owner + */ + function owner() public view returns (address) { + return _owner; + } + + /** + * @dev Sets a new owner address + */ + function setOwner(address newOwner) internal { + _owner = newOwner; + } + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + require(msg.sender == owner()); + _; + } + + /** + * @dev Allows the current owner to transfer control of the contract to a newOwner. + * @param newOwner The address to transfer ownership to. + */ + function transferOwnership(address newOwner) public onlyOwner { + require(newOwner != address(0)); + emit OwnershipTransferred(owner(), newOwner); + setOwner(newOwner); + } +} + +// File: contracts/minting/Controller.sol + +/** +* Copyright CENTRE SECZ 2018 +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in all +* copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ + +pragma solidity ^0.4.24; + + +/** + * @title Controller + * @notice Generic implementation of the owner-controller-worker model. + * One owner manages many controllers. Each controller manages one worker. + * Workers may be reused across different controllers. + */ +contract Controller is Ownable { + /** + * @notice A controller manages a single worker address. + * controllers[controller] = worker + */ + mapping(address => address) internal controllers; + + event ControllerConfigured( + address indexed _controller, + address indexed _worker + ); + event ControllerRemoved(address indexed _controller); + + /** + * @notice Ensures that caller is the controller of a non-zero worker + * address. + */ + modifier onlyController() { + require(controllers[msg.sender] != address(0), + "The value of controllers[msg.sender] must be non-zero"); + _; + } + + /** + * @notice Gets the worker at address _controller. + */ + function getWorker( + address _controller + ) + external + view + returns (address) + { + return controllers[_controller]; + } + + // onlyOwner functions + + /** + * @notice Configure a controller with the given worker. + * @param _controller The controller to be configured with a worker. + * @param _worker The worker to be set for the newly configured controller. + * _worker must not be a non-zero address. To disable a worker, + * use removeController instead. + */ + function configureController( + address _controller, + address _worker + ) + public + onlyOwner + { + require(_controller != address(0), + "Controller must be a non-zero address"); + require(_worker != address(0), "Worker must be a non-zero address"); + controllers[_controller] = _worker; + emit ControllerConfigured(_controller, _worker); + } + + /** + * @notice disables a controller by setting its worker to address(0). + * @param _controller The controller to disable. + */ + function removeController( + address _controller + ) + public + onlyOwner + { + require(_controller != address(0), + "Controller must be a non-zero address"); + require(controllers[_controller] != address(0), + "Worker must be a non-zero address"); + controllers[_controller] = address(0); + emit ControllerRemoved(_controller); + } +} + +// File: contracts/minting/MinterManagementInterface.sol + +/** +* Copyright CENTRE SECZ 2019 +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in all +* copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ + +pragma solidity ^0.4.24; + +/** + * @notice A contract that implements the MinterManagementInterface has external + * functions for adding and removing minters and modifying their allowances. + * An example is the FiatTokenV1 contract that implements USDC. + */ +interface MinterManagementInterface { + function isMinter(address _account) external view returns (bool); + function minterAllowance(address _minter) external view returns (uint256); + + function configureMinter( + address _minter, + uint256 _minterAllowedAmount + ) + external + returns (bool); + + function removeMinter(address _minter) external returns (bool); +} + +// File: openzeppelin-solidity/contracts/math/SafeMath.sol + +/** + * @title SafeMath + * @dev Math operations with safety checks that throw on error + */ +library SafeMath { + + /** + * @dev Multiplies two numbers, throws on overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256 c) { + // Gas optimization: this is cheaper than asserting 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522 + if (a == 0) { + return 0; + } + + c = a * b; + assert(c / a == b); + return c; + } + + /** + * @dev Integer division of two numbers, truncating the quotient. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + // assert(b > 0); // Solidity automatically throws when dividing by 0 + // uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + return a / b; + } + + /** + * @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend). + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + assert(b <= a); + return a - b; + } + + /** + * @dev Adds two numbers, throws on overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256 c) { + c = a + b; + assert(c >= a); + return c; + } +} + +// File: contracts/minting/MintController.sol + +/** +* Copyright CENTRE SECZ 2018 +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in all +* copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ + +pragma solidity ^0.4.24; + + + + +/** + * @title MintController + * @notice The MintController contract manages minters for a contract that + * implements the MinterManagerInterface. It lets the owner designate certain + * addresses as controllers, and these controllers then manage the + * minters by adding and removing minters, as well as modifying their minting + * allowance. A controller may manage exactly one minter, but the same minter + * address may be managed by multiple controllers. + * @dev MintController inherits from the Controller contract. It treats the + * Controller workers as minters. + */ +contract MintController is Controller { + using SafeMath for uint256; + + /** + * @title MinterManagementInterface + * @notice MintController calls the minterManager to execute/record minter + * management tasks, as well as to query the status of a minter address. + */ + MinterManagementInterface internal minterManager; + + event MinterManagerSet( + address indexed _oldMinterManager, + address indexed _newMinterManager + ); + event MinterConfigured( + address indexed _msgSender, + address indexed _minter, + uint256 _allowance + ); + event MinterRemoved( + address indexed _msgSender, + address indexed _minter + ); + event MinterAllowanceIncremented( + address indexed _msgSender, + address indexed _minter, + uint256 _increment, + uint256 _newAllowance + ); + + event MinterAllowanceDecremented( + address indexed msgSender, + address indexed minter, + uint256 decrement, + uint256 newAllowance + ); + + /** + * @notice Initializes the minterManager. + * @param _minterManager The address of the minterManager contract. + */ + constructor(address _minterManager) public { + minterManager = MinterManagementInterface(_minterManager); + } + + /** + * @notice gets the minterManager + */ + function getMinterManager( + ) + external + view + returns (MinterManagementInterface) + { + return minterManager; + } + + // onlyOwner functions + + /** + * @notice Sets the minterManager. + * @param _newMinterManager The address of the new minterManager contract. + */ + function setMinterManager( + address _newMinterManager + ) + public + onlyOwner + { + emit MinterManagerSet(address(minterManager), _newMinterManager); + minterManager = MinterManagementInterface(_newMinterManager); + } + + // onlyController functions + + /** + * @notice Removes the controller's own minter. + */ + function removeMinter() public onlyController returns (bool) { + address minter = controllers[msg.sender]; + emit MinterRemoved(msg.sender, minter); + return minterManager.removeMinter(minter); + } + + /** + * @notice Enables the minter and sets its allowance. + * @param _newAllowance New allowance to be set for minter. + */ + function configureMinter( + uint256 _newAllowance + ) + public + onlyController + returns (bool) + { + address minter = controllers[msg.sender]; + emit MinterConfigured(msg.sender, minter, _newAllowance); + return internal_setMinterAllowance(minter, _newAllowance); + } + + /** + * @notice Increases the minter's allowance if and only if the minter is an + * active minter. + * @dev An minter is considered active if minterManager.isMinter(minter) + * returns true. + */ + function incrementMinterAllowance( + uint256 _allowanceIncrement + ) + public + onlyController + returns (bool) + { + require(_allowanceIncrement > 0, + "Allowance increment must be greater than 0"); + address minter = controllers[msg.sender]; + require(minterManager.isMinter(minter), + "Can only increment allowance for minters in minterManager"); + + uint256 currentAllowance = minterManager.minterAllowance(minter); + uint256 newAllowance = currentAllowance.add(_allowanceIncrement); + + emit MinterAllowanceIncremented( + msg.sender, + minter, + _allowanceIncrement, + newAllowance + ); + + return internal_setMinterAllowance(minter, newAllowance); + } + + /** + * @notice decreases the minter allowance if and only if the minter is + * currently active. The controller can safely send a signed + * decrementMinterAllowance() transaction to a minter and not worry + * about it being used to undo a removeMinter() transaction. + */ + function decrementMinterAllowance( + uint256 _allowanceDecrement + ) + public + onlyController + returns (bool) + { + require(_allowanceDecrement > 0, + "Allowance decrement must be greater than 0"); + address minter = controllers[msg.sender]; + require(minterManager.isMinter(minter), + "Can only decrement allowance for minters in minterManager"); + + uint256 currentAllowance = minterManager.minterAllowance(minter); + uint256 actualAllowanceDecrement = ( + currentAllowance > _allowanceDecrement ? + _allowanceDecrement : currentAllowance + ); + uint256 newAllowance = currentAllowance.sub(actualAllowanceDecrement); + + emit MinterAllowanceDecremented( + msg.sender, + minter, + actualAllowanceDecrement, + newAllowance + ); + + return internal_setMinterAllowance(minter, newAllowance); + } + + // Internal functions + + /** + * @notice Uses the MinterManagementInterface to enable the minter and + * set its allowance. + * @param _minter Minter to set new allowance of. + * @param _newAllowance New allowance to be set for minter. + */ + function internal_setMinterAllowance( + address _minter, + uint256 _newAllowance + ) + internal + returns (bool) + { + return minterManager.configureMinter(_minter, _newAllowance); + } +} + +// File: contracts/minting/MasterMinter.sol + +/** +* Copyright CENTRE SECZ 2018 +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in all +* copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ + +pragma solidity ^0.4.24; + + +/** + * @title MasterMinter + * @notice MasterMinter uses multiple controllers to manage minters for a + * contract that implements the MinterManagerInterface. + * @dev MasterMinter inherits all its functionality from MintController. + */ +contract MasterMinter is MintController { + + constructor(address _minterManager) MintController(_minterManager) public { + } +} \ No newline at end of file diff --git a/validate/README.contractDiff.md b/validate/README.contractDiff.md index 9655d5938..c3d92673d 100644 --- a/validate/README.contractDiff.md +++ b/validate/README.contractDiff.md @@ -19,16 +19,16 @@ At the end of the run, `checkDiff` will output which files it was able to proces means that the Etherscan file could be read AND all the included files could be read. Validity should be determined by actually looking at the diffs. -# Running checkDiff.js +# Running contractDiff.js To run the script, type `node validate/contractDiff.js ... ` Where the `filename` is the location of source code downloaded from Etherscan. -Copies of `FiatTokenProxy` and `FiatTokenV1` are included for testing purposes. +Copies of `FiatTokenProxy`, `FiatTokenV1`, and `MasterMinter` are included for testing purposes. You can test them: -`node validate/contractDiff.js validate/FiatTokenProxy.etherscan validate/FiatTokenV1.etherscan` +`node validate/contractDiff.js validate/FiatTokenProxy.etherscan validate/FiatTokenV1.etherscan validate/MasterMinter.etherscan` # Finding code on Etherscan 1. Go to [https://etherscan.io](https://etherscan.io) From 6b10dd4d74720c0b72d21f897b444d74fa8d9d80 Mon Sep 17 00:00:00 2001 From: mirathewhite Date: Sun, 24 Mar 2019 19:10:08 -0400 Subject: [PATCH 58/74] added event tests --- test/events/MintP0_EventsTests.js | 192 ++++++++++++++++++ ...- EventTests.csv => MINTp0_EventTests.csv} | 3 +- 2 files changed, 194 insertions(+), 1 deletion(-) create mode 100644 test/events/MintP0_EventsTests.js rename verification/Spreadsheets/{MINTp0 - EventTests.csv => MINTp0_EventTests.csv} (76%) diff --git a/test/events/MintP0_EventsTests.js b/test/events/MintP0_EventsTests.js new file mode 100644 index 000000000..1173ee5b7 --- /dev/null +++ b/test/events/MintP0_EventsTests.js @@ -0,0 +1,192 @@ +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 tokenUtils = require('../TokenTestUtils.js'); +var newBigNumber = tokenUtils.newBigNumber; +var checkMINTp0 = tokenUtils.checkMINTp0; +var expectRevert = tokenUtils.expectRevert; +var expectJump = tokenUtils.expectJump; +var expectError = tokenUtils.expectError; +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 addressEquals = AccountUtils.addressEquals; +var initializeTokenWithProxyAndMintController = mintUtils.initializeTokenWithProxyAndMintController; +var checkMintControllerState = mintUtils.checkMintControllerState; + +var zeroAddress = "0x0000000000000000000000000000000000000000"; +var maxAmount = "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"; + +var mintControllerEvents = { + ownershipTransferred: "OwnershipTransferred", + controllerConfigured: "ControllerConfigured", + controllerRemoved: "ControllerRemoved", + minterManagerSet: "MinterManagerSet", + minterCofigured: "MinterConfigured", + minterRemoved: "MinterRemoved", + minterAllowanceIncremented: "MinterAllowanceIncremented", + minterAllowanceDecremented: "MinterAllowanceDecremented" +}; + + + + +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('et100 transferOwnership emits OwnershipTransferred event', async function () { + // get all previous transfer ownership events + var preEvents = await mintController.getPastEvents(mintControllerEvents.ownershipTransferred, + {filter: {previousOwner: Accounts.mintOwnerAccount, newOwner: Accounts.arbitraryAccount}}); + + // now transfer ownership and test again + await mintController.transferOwnership(Accounts.arbitraryAccount, {from: Accounts.mintOwnerAccount}); + var postEvents = await mintController.getPastEvents(mintControllerEvents.ownershipTransferred, + {filter: {previousOwner: Accounts.mintOwnerAccount, newOwner: Accounts.arbitraryAccount}}); + + // one new event must have fired + assert.equal(preEvents.length+1, postEvents.length); + }); + + it('et101 configureController emits ControllerConfigured event', async function () { + // get all previous configure controller events + var preEvents = await mintController.getPastEvents(mintControllerEvents.controllerConfigured, + {filter: {_controller: Accounts.arbitraryAccount, _worker: Accounts.arbitraryAccount2}}); + + // now configure controller and test again + await mintController.configureController(Accounts.arbitraryAccount, Accounts.arbitraryAccount2, {from: Accounts.mintOwnerAccount}); + var postEvents = await mintController.getPastEvents(mintControllerEvents.controllerConfigured, + {filter: {_controller: Accounts.arbitraryAccount, _worker: Accounts.arbitraryAccount2}}); + + // one new event must have fired + assert.equal(preEvents.length+1, postEvents.length); + }); + + it('et102 removeController emits ControllerRemoved event', async function () { + // get all previous removeController events + await mintController.configureController(Accounts.arbitraryAccount, Accounts.arbitraryAccount2, {from: Accounts.mintOwnerAccount}); + var preEvents = await mintController.getPastEvents(mintControllerEvents.controllerRemoved, + {filter: {_controller: Accounts.arbitraryAccount}}); + + // now remove controller and test again + await mintController.removeController(Accounts.arbitraryAccount, {from: Accounts.mintOwnerAccount}); + var postEvents = await mintController.getPastEvents(mintControllerEvents.controllerRemoved, + {filter: {_controller: Accounts.arbitraryAccount}}); + + // one new event must have fired + assert.equal(preEvents.length+1, postEvents.length); + }); + + it('et103 setMinterManager emits MinterManagerSet event', async function () { + // get all previous set minter manager events + var preEvents = await mintController.getPastEvents(mintControllerEvents.minterManagerSet, + {filter: {_oldMinterManager: token.address, _newMinterManager: Accounts.arbitraryAccount}}); + + // now set minter manager and test again + await mintController.setMinterManager(Accounts.arbitraryAccount, {from: Accounts.mintOwnerAccount}); + var postEvents = await mintController.getPastEvents(mintControllerEvents.minterManagerSet, + {filter: {_oldMinterManager: token.address, _newMinterManager: Accounts.arbitraryAccount}}); + + // one new event must have fired + assert.equal(preEvents.length+1, postEvents.length); + }); + + + it('et104 removeMinter emits MinterRemoved event', async function () { + // get all previous remove minter events + var allowance = 10; + await mintController.configureController(Accounts.arbitraryAccount, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + await mintController.configureMinter(allowance, {from: Accounts.arbitraryAccount}); + var preEvents = await mintController.getPastEvents(mintControllerEvents.minterRemoved, + {filter: {_msgSender: Accounts.arbitraryAccount, _minter: Accounts.minterAccount}}); + + // now remove minter and test again + await mintController.removeMinter({from: Accounts.arbitraryAccount}); + var postEvents = await mintController.getPastEvents(mintControllerEvents.minterRemoved, + {filter: {_msgSender: Accounts.arbitraryAccount, _minter: Accounts.minterAccount}}); + + // one new event must have fired + assert.equal(preEvents.length+1, postEvents.length); + }); + + it('et105 configureMinter emits MinterConfigured event', async function () { + // get all previous configureMinter events + var allowance = 10; + await mintController.configureController(Accounts.arbitraryAccount, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + var preEvents = await mintController.getPastEvents(mintControllerEvents.minterCofigured, + {filter: {_msgSender: Accounts.arbitraryAccount, _minter: Accounts.minterAccount, _allowance: allowance}}); + + // now transfer ownership and test again + await mintController.configureMinter(allowance, {from: Accounts.arbitraryAccount}); + var postEvents = await mintController.getPastEvents(mintControllerEvents.minterCofigured, + {filter: {_msgSender: Accounts.arbitraryAccount, _minter: Accounts.minterAccount, _allowance: allowance}}); + + // one new event must have fired + assert.equal(preEvents.length+1, postEvents.length); + }); + + it('et106 incrementMinterAllowance emits MinterAllowanceIncremented event', async function () { + // get all previous increment minter allowance events + var allowance = 10; + await mintController.configureController(Accounts.arbitraryAccount, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + await mintController.configureMinter(allowance, {from: Accounts.arbitraryAccount}); + var preEvents = await mintController.getPastEvents(mintControllerEvents.minterAllowanceIncremented, + {filter: {_msgSender: Accounts.arbitraryAccount, _minter: Accounts.minterAccount, _increment: allowance, _newAllowance: allowance*2}}); + + // now increment minter allowance and test again + await mintController.incrementMinterAllowance(allowance, {from: Accounts.arbitraryAccount}); + var postEvents = await mintController.getPastEvents(mintControllerEvents.minterAllowanceIncremented, + {filter: {_msgSender: Accounts.arbitraryAccount, _minter: Accounts.minterAccount, _increment: allowance, _newAllowance: allowance*2}}); + + // one new event must have fired + assert.equal(preEvents.length+1, postEvents.length); + }); + + it('et107 decrementMinterAllowance emits MinterAllowanceDecremented event', async function () { + // get all previous decrement minter allowance events + var allowance = 10; + await mintController.configureController(Accounts.arbitraryAccount, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + await mintController.configureMinter(allowance, {from: Accounts.arbitraryAccount}); + var preEvents = await mintController.getPastEvents(mintControllerEvents.minterAllowanceDecremented, + {filter: {_msgSender: Accounts.arbitraryAccount, _minter: Accounts.minterAccount, _decrement: allowance, _newAllowance: 0}}); + + // now decrement minter allowance and test again + await mintController.decrementMinterAllowance(allowance, {from: Accounts.arbitraryAccount}); + var postEvents = await mintController.getPastEvents(mintControllerEvents.minterAllowanceDecremented, + {filter: {_msgSender: Accounts.arbitraryAccount, _minter: Accounts.minterAccount, _decrement: allowance, _newAllowance: 0}}); + + // one new event must have fired + assert.equal(preEvents.length+1, postEvents.length); + }); + +} + +var testWrapper = require('./../TestWrapper'); +testWrapper.execute('MINTp0_EventTests MintController', run_tests_MintController); +testWrapper.execute('MINTp0_EventTests MasterMinter', run_tests_MasterMinter); diff --git a/verification/Spreadsheets/MINTp0 - EventTests.csv b/verification/Spreadsheets/MINTp0_EventTests.csv similarity index 76% rename from verification/Spreadsheets/MINTp0 - EventTests.csv rename to verification/Spreadsheets/MINTp0_EventTests.csv index da5473939..d38f78e21 100644 --- a/verification/Spreadsheets/MINTp0 - EventTests.csv +++ b/verification/Spreadsheets/MINTp0_EventTests.csv @@ -5,4 +5,5 @@ Controller.sol,removeController,ControllerRemoved,et102,et102 removeController e MintController,setMinterManager,MinterManagerSet,et103,et103 setMinterManager emits MinterManagerSet event MintController,removeMinter,MinterRemoved,et104,et104 removeMinter emits MinterRemoved event MintController,configureMinter,MinterConfigured,et105,et105 configureMinter emits MinterConfigured event -MintController,incrementMinterAllowance,MinterAllowanceIncremented,et106,et106 incrementMinterAllowance emits MinterAllowanceConfigured event \ No newline at end of file +MintController,incrementMinterAllowance,MinterAllowanceIncremented,et106,et106 incrementMinterAllowance emits MinterAllowanceIncremented event +MintController,decrementMinterAllowance,MinterAllowanceDecremented,et107,et107 decrementMinterAllowance emits MinterAllowanceDecremented event \ No newline at end of file From 45dc385203cb8616005faa9a65db8fec624e11d7 Mon Sep 17 00:00:00 2001 From: mirathewhite Date: Sun, 24 Mar 2019 21:27:13 -0400 Subject: [PATCH 59/74] added e2e tests --- test/e2e/MintP0_EndToEndTests.js | 354 ++++++++++++++++++ ...oEndTests.csv => MINTp0_EndToEndTests.csv} | 0 2 files changed, 354 insertions(+) create mode 100644 test/e2e/MintP0_EndToEndTests.js rename verification/Spreadsheets/{MINTp0 - EndToEndTests.csv => MINTp0_EndToEndTests.csv} (100%) diff --git a/test/e2e/MintP0_EndToEndTests.js b/test/e2e/MintP0_EndToEndTests.js new file mode 100644 index 000000000..fc43feb10 --- /dev/null +++ b/test/e2e/MintP0_EndToEndTests.js @@ -0,0 +1,354 @@ +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 tokenUtils = require('../TokenTestUtils.js'); +var newBigNumber = tokenUtils.newBigNumber; +var checkMINTp0 = tokenUtils.checkMINTp0; +var expectRevert = tokenUtils.expectRevert; +var expectJump = tokenUtils.expectJump; +var expectError = tokenUtils.expectError; +var bigZero = tokenUtils.bigZero; +var maxAmount = tokenUtils.maxAmount; +var initializeTokenWithProxy = tokenUtils.initializeTokenWithProxy; + +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 addressEquals = AccountUtils.addressEquals; +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('ete000 New owner can configure controllers', async function () { + await mintController.transferOwnership(Accounts.arbitraryAccount, {from: Accounts.mintOwnerAccount}); + await mintController.configureController(Accounts.arbitraryAccount2, Accounts.minterAccount, {from: Accounts.arbitraryAccount}); + expectedMintControllerState.controllers['arbitraryAccount2'] = Accounts.minterAccount; + expectedMintControllerState.owner = Accounts.arbitraryAccount; + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + }); + + it('ete001 New owner can remove controllers', async function () { + await mintController.transferOwnership(Accounts.arbitraryAccount, {from: Accounts.mintOwnerAccount}); + await mintController.configureController(Accounts.arbitraryAccount2, Accounts.minterAccount, {from: Accounts.arbitraryAccount}); + await mintController.removeController(Accounts.arbitraryAccount2, {from: Accounts.arbitraryAccount}); + expectedMintControllerState.owner = Accounts.arbitraryAccount; + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + }); + + it('ete002 New controller can configure minter', async function () { + await mintController.configureController(Accounts.arbitraryAccount, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + await mintController.configureMinter(10, {from: Accounts.arbitraryAccount}); + expectedMintControllerState.controllers['arbitraryAccount'] = Accounts.minterAccount; + expectedTokenState.push( + { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(10) } + ); + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + }); + + it('ete003 Configure two controllers for the same minter and make sure they can both configureMinter', async function () { + await mintController.configureController(Accounts.arbitraryAccount, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + await mintController.configureController(Accounts.arbitraryAccount2, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + expectedMintControllerState.controllers['arbitraryAccount'] = Accounts.minterAccount; + expectedMintControllerState.controllers['arbitraryAccount2'] = Accounts.minterAccount; + + // first controller configures minter + await mintController.configureMinter(10, {from: Accounts.arbitraryAccount}); + expectedTokenState.push( + { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(10) } + ); + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + + // second controller configures minter + await mintController.configureMinter(30, {from: Accounts.arbitraryAccount2}); + expectedTokenState.push( + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(30) } + ); + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + }); + + it('ete004 Configure two controllers for the same minter, one adds a minter and the other removes it', async function () { + await mintController.configureController(Accounts.arbitraryAccount, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + await mintController.configureController(Accounts.arbitraryAccount2, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + expectedMintControllerState.controllers['arbitraryAccount'] = Accounts.minterAccount; + expectedMintControllerState.controllers['arbitraryAccount2'] = Accounts.minterAccount; + + // first controller configures minter + await mintController.configureMinter(10, {from: Accounts.arbitraryAccount}); + expectedTokenState.push( + { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(10) } + ); + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + + // second controller remove minter + await mintController.removeMinter({from: Accounts.arbitraryAccount2}); + expectedTokenState.push( + { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': false }, + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(0) } + ); + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + }); + + it('ete005 Configure two controllers for different minters and make sure 2nd cant remove', async function () { + await mintController.configureController(Accounts.arbitraryAccount, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + await mintController.configureController(Accounts.arbitraryAccount2, Accounts.pauserAccount, {from: Accounts.mintOwnerAccount}); + expectedMintControllerState.controllers['arbitraryAccount'] = Accounts.minterAccount; + expectedMintControllerState.controllers['arbitraryAccount2'] = Accounts.minterAccount; + + // first controller configures minter + await mintController.configureMinter(10, {from: Accounts.arbitraryAccount}); + expectedTokenState.push( + { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(10) } + ); + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + + // second controller fails to remove minter (expectedTokenState unchanged) + await mintController.removeMinter({from: Accounts.arbitraryAccount2}); + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + }); + + it('ete006 Configure two controllers for different minters and make sure 2nd cant configure', async function () { + await mintController.configureController(Accounts.arbitraryAccount, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + await mintController.configureController(Accounts.arbitraryAccount2, Accounts.pauserAccount, {from: Accounts.mintOwnerAccount}); + expectedMintControllerState.controllers['arbitraryAccount'] = Accounts.minterAccount; + expectedMintControllerState.controllers['arbitraryAccount2'] = Accounts.minterAccount; + + // second controller fails to configure minter (configures pauser instead) + await mintController.configureMinter(20, {from: Accounts.arbitraryAccount2}); + expectedTokenState.push( + { 'variable': 'isAccountMinter.pauserAccount', 'expectedValue': true }, + { 'variable': 'minterAllowance.pauserAccount', 'expectedValue': newBigNumber(20) } + ); + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + }); + + it('ete007 Remove a controller and make sure it can\'t modify minter', async function () { + await mintController.configureController(Accounts.arbitraryAccount, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + await mintController.removeController(Accounts.arbitraryAccount, {from: Accounts.mintOwnerAccount}); + await expectError(mintController.configureMinter(10, {from: Accounts.arbitraryAccount}), + "The value of controllers[msg.sender] must be non-zero"); + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + }); + + it('ete008 Change minter manager and make sure existing controllers still can configure their minters', async function () { + await mintController.configureController(Accounts.arbitraryAccount, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + expectedMintControllerState.controllers['arbitraryAccount'] = Accounts.minterAccount; + + // change minterManager to a new token + var newTokenConfig = await initializeTokenWithProxy(rawToken); + var newToken = newTokenConfig.token; + await newToken.updateMasterMinter(mintController.address, {from:Accounts.tokenOwnerAccount}); + await mintController.setMinterManager(newToken.address, {from: Accounts.mintOwnerAccount}); + expectedMintControllerState.minterManager = newToken.address; + + // now use controller to configure minter + await mintController.configureMinter(10, {from: Accounts.arbitraryAccount}); + expectedMintControllerState.controllers['arbitraryAccount'] = Accounts.minterAccount; + expectedTokenState.push( + { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(10) } + ); + await checkMINTp0([newToken, mintController], [expectedTokenState, expectedMintControllerState]); + }); + + it('ete009 Change minter manager and make sure existing controllers still can remove their minters', async function () { + await mintController.configureController(Accounts.arbitraryAccount, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + expectedMintControllerState.controllers['arbitraryAccount'] = Accounts.minterAccount; + + // change minterManager to a new token + var newTokenConfig = await initializeTokenWithProxy(rawToken); + var newToken = newTokenConfig.token; + await newToken.updateMasterMinter(mintController.address, {from:Accounts.tokenOwnerAccount}); + await mintController.setMinterManager(newToken.address, {from: Accounts.mintOwnerAccount}); + expectedMintControllerState.minterManager = newToken.address; + + // now use controller to configure and remove minter + await mintController.configureMinter(10, {from: Accounts.arbitraryAccount}); + await mintController.removeMinter({from: Accounts.arbitraryAccount}); + expectedMintControllerState.controllers['arbitraryAccount'] = Accounts.minterAccount; + await checkMINTp0([newToken, mintController], [expectedTokenState, expectedMintControllerState]); + }); + + it('ete010 Change minter manager and make sure existing controllers can increment allowances', async function () { + await mintController.configureController(Accounts.arbitraryAccount, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + expectedMintControllerState.controllers['arbitraryAccount'] = Accounts.minterAccount; + + // change minterManager to a new token + var newTokenConfig = await initializeTokenWithProxy(rawToken); + var newToken = newTokenConfig.token; + await newToken.updateMasterMinter(mintController.address, {from:Accounts.tokenOwnerAccount}); + await mintController.setMinterManager(newToken.address, {from: Accounts.mintOwnerAccount}); + expectedMintControllerState.minterManager = newToken.address; + + // now use controller to configure minter + await mintController.configureMinter(10, {from: Accounts.arbitraryAccount}); + await mintController.incrementMinterAllowance(20, {from: Accounts.arbitraryAccount}); + expectedMintControllerState.controllers['arbitraryAccount'] = Accounts.minterAccount; + expectedTokenState.push( + { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(30) } + ); + await checkMINTp0([newToken, mintController], [expectedTokenState, expectedMintControllerState]); + }); + + it('ete011 New controller can increment minter allowance', async function () { + await mintController.configureController(Accounts.arbitraryAccount, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + await mintController.configureMinter(0, {from: Accounts.arbitraryAccount}); + await mintController.incrementMinterAllowance(10, {from: Accounts.arbitraryAccount}); + expectedMintControllerState.controllers['arbitraryAccount'] = Accounts.minterAccount; + expectedTokenState.push( + { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(10) } + ); + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + }); + + it('ete012 New controller can remove minter', async function () { + await mintController.configureController(Accounts.arbitraryAccount, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + await mintController.configureMinter(10, {from: Accounts.arbitraryAccount}); + await mintController.removeMinter({from: Accounts.arbitraryAccount}); + expectedMintControllerState.controllers['arbitraryAccount'] = Accounts.minterAccount; + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + }); + + it('ete013 Change minter manager, configure a minter, then change back and make sure changes DID NOT propogate', async function () { + await mintController.configureController(Accounts.arbitraryAccount, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + expectedMintControllerState.controllers['arbitraryAccount'] = Accounts.minterAccount; + + // change minterManager to a new token + var newTokenConfig = await initializeTokenWithProxy(rawToken); + var newToken = newTokenConfig.token; + await newToken.updateMasterMinter(mintController.address, {from:Accounts.tokenOwnerAccount}); + await mintController.setMinterManager(newToken.address, {from: Accounts.mintOwnerAccount}); + expectedMintControllerState.minterManager = newToken.address; + + // now use controller to configure minter + await mintController.configureMinter(10, {from: Accounts.arbitraryAccount}); + expectedMintControllerState.controllers['arbitraryAccount'] = Accounts.minterAccount; + expectedTokenState.push( + { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(10) } + ); + await checkMINTp0([newToken, mintController], [expectedTokenState, expectedMintControllerState]); + + // change minterManager to original token and make sure changes did not propagate + await mintController.setMinterManager(token.address, {from: Accounts.mintOwnerAccount}); + expectedMintControllerState.minterManager = token.address; + expectedTokenState.push( + { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': false }, + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(0) } + ); + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + }); + + it('ete014 Remove a minter and then try to increment its allowance reverts', async function () { + // add and remove minter + await mintController.configureController(Accounts.arbitraryAccount, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + await mintController.configureMinter(10, {from: Accounts.arbitraryAccount}); + await mintController.removeMinter({from: Accounts.arbitraryAccount}); + expectedMintControllerState.controllers['arbitraryAccount'] = Accounts.minterAccount; + + // now verify that incrementing its allowance reverts + expectError(mintController.incrementMinterAllowance(20, {from: Accounts.arbitraryAccount}), + "Can only increment allowance for minters in minterManager"); + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + }); + + it('ete015 Configure a minter and make sure it can mint', async function () { + // configure a minter + await mintController.configureController(Accounts.arbitraryAccount, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + await mintController.configureMinter(10, {from: Accounts.arbitraryAccount}); + + // now verify it can mint + await token.mint(Accounts.arbitraryAccount, 5, {from: Accounts.minterAccount}); + expectedMintControllerState.controllers['arbitraryAccount'] = Accounts.minterAccount; + expectedTokenState.push( + { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(5) }, + { 'variable': 'balances.arbitraryAccount', 'expectedValue': newBigNumber(5)}, + { 'variable': 'totalSupply', 'expectedValue': newBigNumber(5)} + ); + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + }); + + it('ete016 Remove a minter and make sure it cannot mint', async function () { + // add and remove minter + await mintController.configureController(Accounts.arbitraryAccount, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + await mintController.configureMinter(10, {from: Accounts.arbitraryAccount}); + await mintController.removeMinter({from: Accounts.arbitraryAccount}); + expectedMintControllerState.controllers['arbitraryAccount'] = Accounts.minterAccount; + + // now verify that minter cannot mint + expectRevert(token.mint(Accounts.arbitraryAccount2, 5, {from: Accounts.minterAccount})); + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + }); + + it('ete017 Configure a minter and make sure it can burn', async function () { + // configure a minter + await mintController.configureController(Accounts.arbitraryAccount, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + await mintController.configureMinter(10, {from: Accounts.arbitraryAccount}); + + // now verify it can burn + await token.mint(Accounts.minterAccount, 5, {from: Accounts.minterAccount}); + await token.burn(5, {from: Accounts.minterAccount}); + expectedMintControllerState.controllers['arbitraryAccount'] = Accounts.minterAccount; + expectedTokenState.push( + { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, + { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(5) } + ); + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + }); + + it('ete018 Remove a minter and make sure it cannot burn', async function () { + // add minter, use it to mint to itself, and remove it again + await mintController.configureController(Accounts.arbitraryAccount, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + await mintController.configureMinter(10, {from: Accounts.arbitraryAccount}); + await token.mint(Accounts.minterAccount, 5, {from: Accounts.minterAccount}); + await mintController.removeMinter({from: Accounts.arbitraryAccount}); + + // now verify that minter cannot burn + expectRevert(token.burn(5, {from: Accounts.minterAccount})); + expectedMintControllerState.controllers['arbitraryAccount'] = Accounts.minterAccount; + expectedTokenState.push( + { 'variable': 'balances.minterAccount', 'expectedValue': newBigNumber(5)}, + { 'variable': 'totalSupply', 'expectedValue': newBigNumber(5)} + ); + await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + }); + +} + +var testWrapper = require('./../TestWrapper'); +testWrapper.execute('MINTp0_EndToEndTests MintController', run_tests_MintController); +testWrapper.execute('MINTp0_EndToEndTests MasterMinter', run_tests_MasterMinter); diff --git a/verification/Spreadsheets/MINTp0 - EndToEndTests.csv b/verification/Spreadsheets/MINTp0_EndToEndTests.csv similarity index 100% rename from verification/Spreadsheets/MINTp0 - EndToEndTests.csv rename to verification/Spreadsheets/MINTp0_EndToEndTests.csv From 405091fe66ab11014f089f5fc313143e67a3fac3 Mon Sep 17 00:00:00 2001 From: Erik Tierney Date: Fri, 5 Apr 2019 10:25:58 -0400 Subject: [PATCH 60/74] Add migration to deploy master minter --- migrations/3_deploy_master_minter.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 migrations/3_deploy_master_minter.js diff --git a/migrations/3_deploy_master_minter.js b/migrations/3_deploy_master_minter.js new file mode 100644 index 000000000..99d0bc2f4 --- /dev/null +++ b/migrations/3_deploy_master_minter.js @@ -0,0 +1,18 @@ +var MasterMinter = artifacts.require('./MasterMinter.sol'); + +module.exports = function(deployer, network, accounts) { + + var minterOwner = '0x496aacE5EEF1f4f505B67Af45de6Ba992785c124'; + var fiatToken = '0x07865c6e87b9f70255377e024ace6630c1eaa37f'; + + console.log("deploying MasterMinter for fiat token at " + fiatToken); + deployer.deploy(MasterMinter, fiatToken) + .then( function(mm) { + console.log("master minter deployed at " + mm.address) + console.log("reassigning owner to " + minterOwner); + return mm.transferOwnership(minterOwner); + }) + .then(function(ownerTransferred) { + console.log("All done.") + }); +} \ No newline at end of file From d7ad665e679c2e9d4faf5319d7582a7ec24c246c Mon Sep 17 00:00:00 2001 From: Erik Tierney Date: Fri, 5 Apr 2019 13:12:37 -0400 Subject: [PATCH 61/74] Fix addresses --- migrations/3_deploy_master_minter.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/migrations/3_deploy_master_minter.js b/migrations/3_deploy_master_minter.js index 99d0bc2f4..b2a912fde 100644 --- a/migrations/3_deploy_master_minter.js +++ b/migrations/3_deploy_master_minter.js @@ -1,10 +1,14 @@ var MasterMinter = artifacts.require('./MasterMinter.sol'); +var FiatToken = artifacts.require('./FiatTokenProxy.sol') module.exports = function(deployer, network, accounts) { - var minterOwner = '0x496aacE5EEF1f4f505B67Af45de6Ba992785c124'; - var fiatToken = '0x07865c6e87b9f70255377e024ace6630c1eaa37f'; - + if( network == "development" || network == "coverage") { + // Change these if deploying for real, these are deterministic + // address from ganache + var minterOwner = "0x3e5e9111ae8eb78fe1cc3bb8915d5d461f3ef9a9"; + var fiatToken = FiatToken.address; + } console.log("deploying MasterMinter for fiat token at " + fiatToken); deployer.deploy(MasterMinter, fiatToken) .then( function(mm) { From c6bc95daba61aad36038ef1996463f0502dcf090 Mon Sep 17 00:00:00 2001 From: Daniel Que Date: Mon, 15 Apr 2019 13:23:25 -0700 Subject: [PATCH 62/74] Enable syntax highlighting --- .gitattributes | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..52031de51 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +*.sol linguist-language=Solidity From 9f492f1b30c23b5976e3be6d507da2c484b06a35 Mon Sep 17 00:00:00 2001 From: Walker Mayerchak Date: Thu, 27 May 2021 19:16:03 -0400 Subject: [PATCH 63/74] resolve conflicts --- README.md | 49 +- contracts/minting/Controller.sol | 94 +- contracts/minting/MasterMinter.sol | 48 +- contracts/minting/MintController.sol | 135 +- .../minting/MinterManagementInterface.sol | 54 +- doc/masterminter.md | 177 +- migrations/2_deploy_usdc.js | 128 +- migrations/3_deploy_master_minter.js | 42 +- package.json | 2 +- test/ABIUtils.js | 103 +- test/AccountUtils.js | 257 ++- test/ControllerTestUtils.js | 50 +- test/MintControllerUtils.js | 72 +- test/TokenTestUtils.js | 1155 +++++----- test/assert/ABITests.test.js | 396 ++-- test/assert/EventsTests.js | 237 +- test/assert/FiatTokenLegacy.test.js | 324 ++- test/assert/Pausable.test.js | 176 +- test/basic/NegativeTests.js | 1262 +++++++---- test/basic/PositiveTests.js | 324 ++- test/e2e/MintP0_EndToEndTests.js | 963 +++++--- test/events/MintP0_EventsTests.js | 464 ++-- test/extended/ExtendedPositiveTests.js | 536 +++-- test/minting/MintP0_ArgumentTests.js | 638 ++++-- test/minting2/MintControllerTests.js | 462 ++-- test/minting2/MintP0_ABITests.js | 101 +- test/minting3/MintP0_BasicTests.js | 1951 +++++++++++------ test/misc/MiscTests.js | 1016 ++++++--- test/proxy/ProxyNegativeTests.js | 198 +- test/proxy/ProxyPositiveTests.js | 473 ++-- truffle.js | 35 +- validate/README.contractDiff.md | 4 +- verification/spreadsheet_parser.js | 175 +- verification/verification_reporter.js | 46 +- 34 files changed, 7847 insertions(+), 4300 deletions(-) diff --git a/README.md b/README.md index 8295ef438..bd093a357 100644 --- a/README.md +++ b/README.md @@ -1,25 +1,20 @@ # centre-tokens -<<<<<<< HEAD -Fiat tokens on the [CENTRE](https://centre.io) network. -======= ->>>>>>> b5aba6ce7b5a867fda355a54a8449818b313bf1a + +<<<<<<< HEAD Fiat tokens on the [CENTRE](https://centre.io) network. ======= + +> > > > > > > b5aba6ce7b5a867fda355a54a8449818b313bf1a Fiat tokens on the [CENTRE](https://centre.io) network. ## Setup -<<<<<<< HEAD -install yarn: -```npm install -g yarn``` +<<<<<<< HEAD install yarn: `npm install -g yarn` -install project npm dependencies: -```yarn install``` -======= -Requirements: +install project npm dependencies: `yarn install` ======= Requirements: - Node >= v12 - Yarn ->>>>>>> b5aba6ce7b5a867fda355a54a8449818b313bf1a + > > > > > > > b5aba6ce7b5a867fda355a54a8449818b313bf1a ``` $ git clone git@github.com:centrehq/centre-tokens.git @@ -38,13 +33,20 @@ $ yarn compile && yarn typechain ``` <<<<<<< HEAD + # Contracts -The implementation uses 2 separate contracts - a proxy contract (`FiatTokenProxy.sol`)and an implementation contract(`FiatToken.sol`). -This allows upgrading the contract, as a new implementation contact can be deployed and the Proxy updated to point to it. + +The implementation uses 2 separate contracts - a proxy contract +(`FiatTokenProxy.sol`)and an implementation contract(`FiatToken.sol`). This +allows upgrading the contract, as a new implementation contact can be deployed +and the Proxy updated to point to it. + ## FiatToken -The FiatToken offers a number of capabilities, which briefly are described below. There are more -[detailed design docs](./doc/tokendesign.md) in the `doc` folder. -======= + +The FiatToken offers a number of capabilities, which briefly are described +below. There are more [detailed design docs](./doc/tokendesign.md) in the `doc` +folder. ======= + ## Linting and Formatting To check code for problems: @@ -112,7 +114,8 @@ and the Proxy updated to point to it. The FiatToken offers a number of capabilities, which briefly are described below. There are more [detailed design docs](./doc/tokendesign.md) in the `doc` folder. ->>>>>>> b5aba6ce7b5a867fda355a54a8449818b313bf1a + +> > > > > > > b5aba6ce7b5a867fda355a54a8449818b313bf1a ### ERC20 compatible @@ -147,13 +150,15 @@ decreases. When it gets too low they will need the allowance increased again by the `masterMinter`. ### Ownable -<<<<<<< HEAD -The contract has an Owner, who can change the `owner`, `pauser`, `blacklister`, or `masterMinter` addresses. The `owner` can not change -the `proxyOwner` address. + +<<<<<<< HEAD The contract has an Owner, who can change the `owner`, `pauser`, +`blacklister`, or `masterMinter` addresses. The `owner` can not change the +`proxyOwner` address. ======= The contract has an Owner, who can change the `owner`, `pauser`, `blacklister`, or `masterMinter` addresses. The `owner` can not change the `proxyOwner` address. ->>>>>>> b5aba6ce7b5a867fda355a54a8449818b313bf1a + +> > > > > > > b5aba6ce7b5a867fda355a54a8449818b313bf1a diff --git a/contracts/minting/Controller.sol b/contracts/minting/Controller.sol index 91f851ced..8e25ad9c2 100644 --- a/contracts/minting/Controller.sol +++ b/contracts/minting/Controller.sol @@ -1,28 +1,28 @@ /** -* Copyright CENTRE SECZ 2018 -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all -* copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -* THE SOFTWARE. -*/ + * Copyright CENTRE SECZ 2021 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ -pragma solidity ^0.4.24; +pragma solidity 0.6.12; -import "../Ownable.sol"; +import { Ownable } from "../v1/Ownable.sol"; /** * @title Controller @@ -44,25 +44,21 @@ contract Controller is Ownable { event ControllerRemoved(address indexed _controller); /** - * @notice Ensures that caller is the controller of a non-zero worker + * @notice Ensures that caller is the controller of a non-zero worker * address. */ modifier onlyController() { - require(controllers[msg.sender] != address(0), - "The value of controllers[msg.sender] must be non-zero"); + require( + controllers[msg.sender] != address(0), + "The value of controllers[msg.sender] must be non-zero" + ); _; } /** * @notice Gets the worker at address _controller. */ - function getWorker( - address _controller - ) - external - view - returns (address) - { + function getWorker(address _controller) external view returns (address) { return controllers[_controller]; } @@ -75,15 +71,14 @@ contract Controller is Ownable { * _worker must not be a non-zero address. To disable a worker, * use removeController instead. */ - function configureController( - address _controller, - address _worker - ) - public - onlyOwner + function configureController(address _controller, address _worker) + public + onlyOwner { - require(_controller != address(0), - "Controller must be a non-zero address"); + require( + _controller != address(0), + "Controller must be a non-zero address" + ); require(_worker != address(0), "Worker must be a non-zero address"); controllers[_controller] = _worker; emit ControllerConfigured(_controller, _worker); @@ -93,16 +88,15 @@ contract Controller is Ownable { * @notice disables a controller by setting its worker to address(0). * @param _controller The controller to disable. */ - function removeController( - address _controller - ) - public - onlyOwner - { - require(_controller != address(0), - "Controller must be a non-zero address"); - require(controllers[_controller] != address(0), - "Worker must be a non-zero address"); + function removeController(address _controller) public onlyOwner { + require( + _controller != address(0), + "Controller must be a non-zero address" + ); + require( + controllers[_controller] != address(0), + "Worker must be a non-zero address" + ); controllers[_controller] = address(0); emit ControllerRemoved(_controller); } diff --git a/contracts/minting/MasterMinter.sol b/contracts/minting/MasterMinter.sol index 372123bce..481e5ed28 100644 --- a/contracts/minting/MasterMinter.sol +++ b/contracts/minting/MasterMinter.sol @@ -1,37 +1,35 @@ /** -* Copyright CENTRE SECZ 2018 -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all -* copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -* THE SOFTWARE. -*/ + * Copyright CENTRE SECZ 2021 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ -pragma solidity ^0.4.24; +pragma solidity 0.6.12; import "./MintController.sol"; /** * @title MasterMinter - * @notice MasterMinter uses multiple controllers to manage minters for a + * @notice MasterMinter uses multiple controllers to manage minters for a * contract that implements the MinterManagerInterface. * @dev MasterMinter inherits all its functionality from MintController. */ contract MasterMinter is MintController { - - constructor(address _minterManager) MintController(_minterManager) public { - } + constructor(address _minterManager) public MintController(_minterManager) {} } diff --git a/contracts/minting/MintController.sol b/contracts/minting/MintController.sol index 9566f35ec..894c8bb1a 100644 --- a/contracts/minting/MintController.sol +++ b/contracts/minting/MintController.sol @@ -1,50 +1,50 @@ /** -* Copyright CENTRE SECZ 2018 -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all -* copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -* THE SOFTWARE. -*/ - -pragma solidity ^0.4.24; + * Copyright CENTRE SECZ 2021 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +pragma solidity 0.6.12; import "./Controller.sol"; import "./MinterManagementInterface.sol"; -import "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import { SafeMath } from "@openzeppelin/contracts/math/SafeMath.sol"; /** * @title MintController - * @notice The MintController contract manages minters for a contract that - * implements the MinterManagerInterface. It lets the owner designate certain - * addresses as controllers, and these controllers then manage the - * minters by adding and removing minters, as well as modifying their minting - * allowance. A controller may manage exactly one minter, but the same minter + * @notice The MintController contract manages minters for a contract that + * implements the MinterManagerInterface. It lets the owner designate certain + * addresses as controllers, and these controllers then manage the + * minters by adding and removing minters, as well as modifying their minting + * allowance. A controller may manage exactly one minter, but the same minter * address may be managed by multiple controllers. - * @dev MintController inherits from the Controller contract. It treats the + * @dev MintController inherits from the Controller contract. It treats the * Controller workers as minters. */ contract MintController is Controller { using SafeMath for uint256; /** - * @title MinterManagementInterface - * @notice MintController calls the minterManager to execute/record minter - * management tasks, as well as to query the status of a minter address. - */ + * @title MinterManagementInterface + * @notice MintController calls the minterManager to execute/record minter + * management tasks, as well as to query the status of a minter address. + */ MinterManagementInterface internal minterManager; event MinterManagerSet( @@ -56,10 +56,7 @@ contract MintController is Controller { address indexed _minter, uint256 _allowance ); - event MinterRemoved( - address indexed _msgSender, - address indexed _minter - ); + event MinterRemoved(address indexed _msgSender, address indexed _minter); event MinterAllowanceIncremented( address indexed _msgSender, address indexed _minter, @@ -85,8 +82,7 @@ contract MintController is Controller { /** * @notice gets the minterManager */ - function getMinterManager( - ) + function getMinterManager() external view returns (MinterManagementInterface) @@ -100,12 +96,7 @@ contract MintController is Controller { * @notice Sets the minterManager. * @param _newMinterManager The address of the new minterManager contract. */ - function setMinterManager( - address _newMinterManager - ) - public - onlyOwner - { + function setMinterManager(address _newMinterManager) public onlyOwner { emit MinterManagerSet(address(minterManager), _newMinterManager); minterManager = MinterManagementInterface(_newMinterManager); } @@ -125,9 +116,7 @@ contract MintController is Controller { * @notice Enables the minter and sets its allowance. * @param _newAllowance New allowance to be set for minter. */ - function configureMinter( - uint256 _newAllowance - ) + function configureMinter(uint256 _newAllowance) public onlyController returns (bool) @@ -138,23 +127,25 @@ contract MintController is Controller { } /** - * @notice Increases the minter's allowance if and only if the minter is an + * @notice Increases the minter's allowance if and only if the minter is an * active minter. - * @dev An minter is considered active if minterManager.isMinter(minter) + * @dev An minter is considered active if minterManager.isMinter(minter) * returns true. */ - function incrementMinterAllowance( - uint256 _allowanceIncrement - ) + function incrementMinterAllowance(uint256 _allowanceIncrement) public onlyController returns (bool) { - require(_allowanceIncrement > 0, - "Allowance increment must be greater than 0"); + require( + _allowanceIncrement > 0, + "Allowance increment must be greater than 0" + ); address minter = controllers[msg.sender]; - require(minterManager.isMinter(minter), - "Can only increment allowance for minters in minterManager"); + require( + minterManager.isMinter(minter), + "Can only increment allowance for minters in minterManager" + ); uint256 currentAllowance = minterManager.minterAllowance(minter); uint256 newAllowance = currentAllowance.add(_allowanceIncrement); @@ -171,27 +162,30 @@ contract MintController is Controller { /** * @notice decreases the minter allowance if and only if the minter is - * currently active. The controller can safely send a signed - * decrementMinterAllowance() transaction to a minter and not worry + * currently active. The controller can safely send a signed + * decrementMinterAllowance() transaction to a minter and not worry * about it being used to undo a removeMinter() transaction. */ - function decrementMinterAllowance( - uint256 _allowanceDecrement - ) + function decrementMinterAllowance(uint256 _allowanceDecrement) public onlyController returns (bool) { - require(_allowanceDecrement > 0, - "Allowance decrement must be greater than 0"); + require( + _allowanceDecrement > 0, + "Allowance decrement must be greater than 0" + ); address minter = controllers[msg.sender]; - require(minterManager.isMinter(minter), - "Can only decrement allowance for minters in minterManager"); + require( + minterManager.isMinter(minter), + "Can only decrement allowance for minters in minterManager" + ); uint256 currentAllowance = minterManager.minterAllowance(minter); uint256 actualAllowanceDecrement = ( - currentAllowance > _allowanceDecrement ? - _allowanceDecrement : currentAllowance + currentAllowance > _allowanceDecrement + ? _allowanceDecrement + : currentAllowance ); uint256 newAllowance = currentAllowance.sub(actualAllowanceDecrement); @@ -213,10 +207,7 @@ contract MintController is Controller { * @param _minter Minter to set new allowance of. * @param _newAllowance New allowance to be set for minter. */ - function internal_setMinterAllowance( - address _minter, - uint256 _newAllowance - ) + function internal_setMinterAllowance(address _minter, uint256 _newAllowance) internal returns (bool) { diff --git a/contracts/minting/MinterManagementInterface.sol b/contracts/minting/MinterManagementInterface.sol index 88af54d94..7a75b1a20 100644 --- a/contracts/minting/MinterManagementInterface.sol +++ b/contracts/minting/MinterManagementInterface.sol @@ -1,40 +1,38 @@ /** -* Copyright CENTRE SECZ 2019 -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all -* copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -* THE SOFTWARE. -*/ + * Copyright CENTRE SECZ 2021 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ -pragma solidity ^0.4.24; +pragma solidity 0.6.12; -/** - * @notice A contract that implements the MinterManagementInterface has external - * functions for adding and removing minters and modifying their allowances. +/** + * @notice A contract that implements the MinterManagementInterface has external + * functions for adding and removing minters and modifying their allowances. * An example is the FiatTokenV1 contract that implements USDC. */ interface MinterManagementInterface { function isMinter(address _account) external view returns (bool); + function minterAllowance(address _minter) external view returns (uint256); - function configureMinter( - address _minter, - uint256 _minterAllowedAmount - ) + function configureMinter(address _minter, uint256 _minterAllowedAmount) external returns (bool); diff --git a/doc/masterminter.md b/doc/masterminter.md index ed0ece93b..54b168f74 100644 --- a/doc/masterminter.md +++ b/doc/masterminter.md @@ -1,101 +1,124 @@ # MasterMinter contract -The MasterMinter is a governance contract. It delegates the functionality -of the `masterMinter` role in the CENTRE USDC contract to multiple addresses. -(The `masterMinter` role can add and remove minters from a FiatToken and set their -allowances.) The MasterMinter contract delegates the minter management capability to -`controllers`. Each `controller` manages exactly one `minter`, and a single `minter` -may be managed by multiple `controllers`. This allows separation of duties -(off-line key management) and simplifies nonce management for warm transactions. -Minters and FiatToken holders are not affected by replacing a `masterMinter` user address with -a `MasterMinter` contract. +The MasterMinter is a governance contract. It delegates the functionality of the +`masterMinter` role in the CENTRE USDC contract to multiple addresses. (The +`masterMinter` role can add and remove minters from a FiatToken and set their +allowances.) The MasterMinter contract delegates the minter management +capability to `controllers`. Each `controller` manages exactly one `minter`, and +a single `minter` may be managed by multiple `controllers`. This allows +separation of duties (off-line key management) and simplifies nonce management +for warm transactions. + +Minters and FiatToken holders are not affected by replacing a `masterMinter` +user address with a `MasterMinter` contract. # Roles + The `MasterMinter` contract has the following roles: -- `owner` - adds and removes controllers, sets the address of the `minterManager`, - and sets the owner. -- `minterManager` - address of a contract (e.g. USDC) with a `MinterManagementInterface`. - The `minterManager` contract stores information about minter allowances and which - minters are enabled/disabled. -- `controller` - each controller manages exactly one minter. A controller - can enable/disable its minter, and modify the minting allowance by calling functions on - the `MasterMinter` contract, and `MasterMinter` will call the appropriate functions on - the `minterManager`. -- `minter` - each `minter` is managed by one or more `controller`. The `minter` cannot - perform any actions on the MasterMinter contract. It interacts only with - the FiatToken contract. +- `owner` - adds and removes controllers, sets the address of the + `minterManager`, and sets the owner. +- `minterManager` - address of a contract (e.g. USDC) with a + `MinterManagementInterface`. The `minterManager` contract stores information + about minter allowances and which minters are enabled/disabled. +- `controller` - each controller manages exactly one minter. A controller can + enable/disable its minter, and modify the minting allowance by calling + functions on the `MasterMinter` contract, and `MasterMinter` will call the + appropriate functions on the `minterManager`. +- `minter` - each `minter` is managed by one or more `controller`. The `minter` + cannot perform any actions on the MasterMinter contract. It interacts only + with the FiatToken contract. # Interaction with FiatToken contract + The `owner` of the FiatToken contract can set the `masterMinter` role to point -to the address of the `MasterMinter` contract. This enables the `MasterMinter` +to the address of the `MasterMinter` contract. This enables the `MasterMinter` contract to call minter management functions on the FiatToken contract: -- `configureMinter(minter, allowance)` - Enables the `minter` and sets its minting allowance. -- `removeMinter(minter)` - Disables the `minter` and sets its minting allowance to 0. -- `isMinter(minter)` - Returns `true` if the `minter` is enabled, and `false` otherwise. -- `minterAllowance(minter)` - Returns the minting allowance of the `minter`. +- `configureMinter(minter, allowance)` - Enables the `minter` and sets its + minting allowance. +- `removeMinter(minter)` - Disables the `minter` and sets its minting allowance + to 0. +- `isMinter(minter)` - Returns `true` if the `minter` is enabled, and `false` + otherwise. +- `minterAllowance(minter)` - Returns the minting allowance of the `minter`. -Together, these four functions are defined as the `MinterManagementInterface`. The -`MasterMinter` contains the address of a `minterManager` that implements the `MinterManagementInterface`. -The `MasterMinter` interacts with the USDC token via the `minterManager`. +Together, these four functions are defined as the `MinterManagementInterface`. +The `MasterMinter` contains the address of a `minterManager` that implements the +`MinterManagementInterface`. The `MasterMinter` interacts with the USDC token +via the `minterManager`. -When a `controller` calls a function on `MasterMinter`, the `MasterMinter` will call -the appropriate function on the `FiatToken` contract on its behalf. Both the `MasterMinter` -and the `FiatToken` do their own access control. +When a `controller` calls a function on `MasterMinter`, the `MasterMinter` will +call the appropriate function on the `FiatToken` contract on its behalf. Both +the `MasterMinter` and the `FiatToken` do their own access control. # Function Summary -- `configureController(controller, minter)` - The owner assigns the controller to manage the minter. This allows - the `controller` to call `configureMinter`, `incrementMinterAllowance` and `removeMinter`. Note: - `configureController(controller, 0x00)` is forbidden because it has the effect of removing the controller. -- `removeController(controller)` - The owner disables the controller by setting its `minter` to `0x00`. -- `setMinterManager(minterManager)` - The owner sets a new contract to the `minterManager` address. This has - no effect on the old `minterManager` contract. If the new `minterManager` does not implement the - `MinterManagementInterface` or does not give this instance of the `MasterMinter` contract permission to - call minter management functions then the `controller` calls to `configureMinter`, - `incrementMinterAllowance`, and `removeMinter` will throw. -- `configureMinter(allowance)` - A controller enables its minter and sets its allowance. The `MasterMinter` - contract will call the `minterManager` contract on the `controller`'s behalf. -- `incrementMinterAllowance` - A controller increments the allowance of an enabled minter - (`incrementMinterAllowance` will throw if the `minter` is disabled). The `MasterMinter` - contract will call the `minterManager` contract on the `controller`'s behalf. -- `removeMinter` - A controller disables a `minter`. The `MasterMinter` - contract will call the `minterManager` contract on the `controller`'s behalf. +- `configureController(controller, minter)` - The owner assigns the controller + to manage the minter. This allows the `controller` to call `configureMinter`, + `incrementMinterAllowance` and `removeMinter`. Note: + `configureController(controller, 0x00)` is forbidden because it has the effect + of removing the controller. +- `removeController(controller)` - The owner disables the controller by setting + its `minter` to `0x00`. +- `setMinterManager(minterManager)` - The owner sets a new contract to the + `minterManager` address. This has no effect on the old `minterManager` + contract. If the new `minterManager` does not implement the + `MinterManagementInterface` or does not give this instance of the + `MasterMinter` contract permission to call minter management functions then + the `controller` calls to `configureMinter`, `incrementMinterAllowance`, and + `removeMinter` will throw. +- `configureMinter(allowance)` - A controller enables its minter and sets its + allowance. The `MasterMinter` contract will call the `minterManager` contract + on the `controller`'s behalf. +- `incrementMinterAllowance` - A controller increments the allowance of an + enabled minter (`incrementMinterAllowance` will throw if the `minter` + is disabled). The `MasterMinter` contract will call the `minterManager` + contract on the `controller`'s behalf. +- `removeMinter` - A controller disables a `minter`. The `MasterMinter` contract + will call the `minterManager` contract on the `controller`'s behalf. # Deployment -The `MasterMinter` may be deployed independently of the `FiatToken` contract (e.g. USDC). - -- FiatToken then MasterMinter. Deploy `MasterMinter` and set the `minterManager` - to point to the `FiatToken` in the constructor. Then use the `MasterMinter` `owner` role to - configure at least one `controller` for each existing `minter` in the `FiatToken`. Once the - `MasterMinter` is fully configured, use the `FiatToken` `owner` role to broadcast - an `updateMasterMinter` transaction setting `masterMinter` role to the `MasterMinter` contract - address. -- MasterMinter then FiatToken. Deploy `MasterMinter` and set the `minterManager` - to point to address `0x00` in the constructor. Then deploy the `FiatToken` and set - the `masterMinter` to be the address of the `MasterMinter` contract in the constructor. - Next, use the `MasterMinter` `owner` to set the `minterManager` and configure `controllers`. - -# Configuring the MasterMinter -We recommend assigning at least two `controllers` to each `minter`. +The `MasterMinter` may be deployed independently of the `FiatToken` contract +(e.g. USDC). + +- FiatToken then MasterMinter. Deploy `MasterMinter` and set the + `minterManager` to point to the `FiatToken` in the constructor. Then use the + `MasterMinter` `owner` role to configure at least one `controller` for each + existing `minter` in the `FiatToken`. Once the `MasterMinter` is fully + configured, use the `FiatToken` `owner` role to broadcast an + `updateMasterMinter` transaction setting `masterMinter` role to the + `MasterMinter` contract address. +- MasterMinter then FiatToken. Deploy `MasterMinter` and set the + `minterManager` to point to address `0x00` in the constructor. Then deploy the + `FiatToken` and set the `masterMinter` to be the address of the `MasterMinter` + contract in the constructor. Next, use the `MasterMinter` `owner` to set the + `minterManager` and configure `controllers`. -- AllowanceController. Use this `controller` to enable the `minter` with a single - `configureMinter` transaction, and then use it exclusively to sign `incrementMinterAllowance` transactions. - There may be multiple `AllowanceControllers` that sign different size allowance increment transactions. -- SecurityController. Use this `controller` to sign a single `removeMinter` transaction and store - it for emergencies. +# Configuring the MasterMinter -The private keys to the `AllowanceController` and `SecurityController` should stay in cold storage. -This configuration lets the Controller keep multiple warm `incrementMinterAllowance` transactions on hand, -as well as the `removeMinter` transaction in case of a problem. Broadcasting the `removeMinter` transaction -will cause all future `incrementMinterAllowance` transactions to `throw`. Since the two types -of transactions are managed by different addresses, there is no need to worry about nonce management. +We recommend assigning at least two `controllers` to each `minter`. +- AllowanceController. Use this `controller` to enable the `minter` with + a single `configureMinter` transaction, and then use it exclusively to sign + `incrementMinterAllowance` transactions. There may be multiple + `AllowanceControllers` that sign different size allowance increment + transactions. +- SecurityController. Use this `controller` to sign a single + `removeMinter` transaction and store it for emergencies. + +The private keys to the `AllowanceController` and `SecurityController` should +stay in cold storage. This configuration lets the Controller keep multiple warm +`incrementMinterAllowance` transactions on hand, as well as the `removeMinter` +transaction in case of a problem. Broadcasting the `removeMinter` transaction +will cause all future `incrementMinterAllowance` transactions to `throw`. Since +the two types of transactions are managed by different addresses, there is no +need to worry about nonce management. # MasterMinter vs. MintController -Creating a `MasterMinter` contract that *inherits* from a `MintController` contract with no -changes may seem like a curious design choice. This leaves open the possibility of creating other -contracts that inherit from `MintController` without creating naming confusion due to their different -functionality. \ No newline at end of file + +Creating a `MasterMinter` contract that _inherits_ from a `MintController` +contract with no changes may seem like a curious design choice. This leaves open +the possibility of creating other contracts that inherit from `MintController` +without creating naming confusion due to their different functionality. diff --git a/migrations/2_deploy_usdc.js b/migrations/2_deploy_usdc.js index 60394b371..d2129ee4d 100644 --- a/migrations/2_deploy_usdc.js +++ b/migrations/2_deploy_usdc.js @@ -4,69 +4,69 @@ var FiatTokenProxy = artifacts.require("./FiatTokenProxy.sol"); // Any address will do, preferably one we generated var throwawayAddress = "0x64e078a8aa15a41b85890265648e965de686bae6"; -module.exports = function(deployer, network, accounts) { +module.exports = function (deployer, network, accounts) { + if (network == "development" || network == "coverage") { + // Change these to the cold storage addresses provided by ops + // these are the deterministic addresses from ganache, so the private keys are well known + // and match the values we use in the tests + var admin = "0x2f560290fef1b3ada194b6aa9c40aa71f8e95598"; + var masterMinter = "0x3e5e9111ae8eb78fe1cc3bb8915d5d461f3ef9a9"; + var pauser = "0xaca94ef8bd5ffee41947b4585a84bda5a3d3da6e"; + var blacklister = "0xd03ea8624c8c5987235048901fb614fdca89b117"; + var owner = "0xe11ba2b4d45eaed5996cd0823791e0c93114882d"; + } - if( network == "development" || network == "coverage") { - // Change these to the cold storage addresses provided by ops - // these are the deterministic addresses from ganache, so the private keys are well known - // and match the values we use in the tests - var admin = "0x2f560290fef1b3ada194b6aa9c40aa71f8e95598"; - var masterMinter = "0x3e5e9111ae8eb78fe1cc3bb8915d5d461f3ef9a9"; - var pauser = "0xaca94ef8bd5ffee41947b4585a84bda5a3d3da6e"; - var blacklister = "0xd03ea8624c8c5987235048901fb614fdca89b117"; - var owner = "0xe11ba2b4d45eaed5996cd0823791e0c93114882d"; - } + console.log("deploying impl"); - console.log("deploying impl") - - var fiatTokenImpl; - var tokenProxy; - // deploy implementation contract - deployer.deploy(FiatTokenV1) - .then(function(impl) { - fiatTokenImpl = impl; - console.log("initializing impl with dummy values") - return impl.initialize( - "", - "", - "", - 0, - throwawayAddress, - throwawayAddress, - throwawayAddress, - throwawayAddress - ); - }) - .then(function(initDone){ - console.log("deploying proxy"); - return deployer.deploy(FiatTokenProxy, fiatTokenImpl.address); - }) - .then(function(proxy){ - tokenProxy = proxy; - console.log("reassigning proxy admin"); - // need to change admin first, or the call to initialize won't work - // since admin can only call methods in the proxy, and not forwarded methods - return proxy.changeAdmin(admin); - }) - .then(function(changeAdminDone){ - console.log("initializing proxy"); - // Pretend that the proxy address is a FiatTokenV1 - // this is fine because the proxy will forward all the calls to the FiatTokenV1 impl - return FiatTokenV1.at(tokenProxy.address); - }) - .then(function(tokenProxyAsFiatTokenV1){ - return tokenProxyAsFiatTokenV1.initialize( - "USD//C", - "USDC", - "USD", - 6, - masterMinter, - pauser, - blacklister, - owner - ); - }) - .then(function(initDone) { - console.log("Deployer proxy at ", tokenProxy.address); - }); -}; \ No newline at end of file + var fiatTokenImpl; + var tokenProxy; + // deploy implementation contract + deployer + .deploy(FiatTokenV1) + .then(function (impl) { + fiatTokenImpl = impl; + console.log("initializing impl with dummy values"); + return impl.initialize( + "", + "", + "", + 0, + throwawayAddress, + throwawayAddress, + throwawayAddress, + throwawayAddress + ); + }) + .then(function (initDone) { + console.log("deploying proxy"); + return deployer.deploy(FiatTokenProxy, fiatTokenImpl.address); + }) + .then(function (proxy) { + tokenProxy = proxy; + console.log("reassigning proxy admin"); + // need to change admin first, or the call to initialize won't work + // since admin can only call methods in the proxy, and not forwarded methods + return proxy.changeAdmin(admin); + }) + .then(function (changeAdminDone) { + console.log("initializing proxy"); + // Pretend that the proxy address is a FiatTokenV1 + // this is fine because the proxy will forward all the calls to the FiatTokenV1 impl + return FiatTokenV1.at(tokenProxy.address); + }) + .then(function (tokenProxyAsFiatTokenV1) { + return tokenProxyAsFiatTokenV1.initialize( + "USD//C", + "USDC", + "USD", + 6, + masterMinter, + pauser, + blacklister, + owner + ); + }) + .then(function (initDone) { + console.log("Deployer proxy at ", tokenProxy.address); + }); +}; diff --git a/migrations/3_deploy_master_minter.js b/migrations/3_deploy_master_minter.js index b2a912fde..5ae043617 100644 --- a/migrations/3_deploy_master_minter.js +++ b/migrations/3_deploy_master_minter.js @@ -1,22 +1,22 @@ -var MasterMinter = artifacts.require('./MasterMinter.sol'); -var FiatToken = artifacts.require('./FiatTokenProxy.sol') +var MasterMinter = artifacts.require("./MasterMinter.sol"); +var FiatToken = artifacts.require("./FiatTokenProxy.sol"); -module.exports = function(deployer, network, accounts) { - - if( network == "development" || network == "coverage") { - // Change these if deploying for real, these are deterministic - // address from ganache - var minterOwner = "0x3e5e9111ae8eb78fe1cc3bb8915d5d461f3ef9a9"; - var fiatToken = FiatToken.address; - } - console.log("deploying MasterMinter for fiat token at " + fiatToken); - deployer.deploy(MasterMinter, fiatToken) - .then( function(mm) { - console.log("master minter deployed at " + mm.address) - console.log("reassigning owner to " + minterOwner); - return mm.transferOwnership(minterOwner); - }) - .then(function(ownerTransferred) { - console.log("All done.") - }); -} \ No newline at end of file +module.exports = function (deployer, network, accounts) { + if (network == "development" || network == "coverage") { + // Change these if deploying for real, these are deterministic + // address from ganache + var minterOwner = "0x3e5e9111ae8eb78fe1cc3bb8915d5d461f3ef9a9"; + var fiatToken = FiatToken.address; + } + console.log("deploying MasterMinter for fiat token at " + fiatToken); + deployer + .deploy(MasterMinter, fiatToken) + .then(function (mm) { + console.log("master minter deployed at " + mm.address); + console.log("reassigning owner to " + minterOwner); + return mm.transferOwnership(minterOwner); + }) + .then(function (ownerTransferred) { + console.log("All done."); + }); +}; diff --git a/package.json b/package.json index 5e21e8ee6..2427d9f34 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "typechain": "yarn compile && rm -rf './@types/generated' && typechain --target=truffle-v5 --outDir './@types/generated' 'build/contracts/**/*.json'", "typecheck": "tsc -p . --noEmit", "lint": "eslint --ext '.js,.ts' './**/*.{j,t}s'", - "fmt": "prettier --write './**/*.sol' './**/*.js' './**/*.ts' './verification/verification_reporter.js**/*.json' './**/*.md'", + "fmt": "prettier --write './**/*.sol' './**/*.js' './**/*.ts' './**/*.md'", "ganache": "ganache-cli --accounts=15 --deterministic --defaultBalanceEther=1000000 --quiet", "test": "truffle test", "coverage": "truffle run coverage", diff --git a/test/ABIUtils.js b/test/ABIUtils.js index 8ea39ba7e..5050308ab 100644 --- a/test/ABIUtils.js +++ b/test/ABIUtils.js @@ -1,77 +1,94 @@ +var Tx = require("ethereumjs-tx"); -var Tx = require('ethereumjs-tx'); - -async function makeRawTransaction(msgData, msgSender, hexPrivateKey, contractAddress) { - var nonce = web3.utils.toHex(await web3.eth.getTransactionCount(msgSender)); - var tx = new Tx({ - nonce: nonce, - gasPrice: web3.utils.toHex(web3.utils.toWei('20', 'gwei')), - gasLimit: 1000000, - to: contractAddress, - value: 0, - data: msgData, - }); - var privateKey = Buffer.from(hexPrivateKey, 'hex'); - tx.sign(privateKey); - var raw = '0x' + tx.serialize().toString('hex'); - return raw +async function makeRawTransaction( + msgData, + msgSender, + hexPrivateKey, + contractAddress +) { + var nonce = web3.utils.toHex(await web3.eth.getTransactionCount(msgSender)); + var tx = new Tx({ + nonce: nonce, + gasPrice: web3.utils.toHex(web3.utils.toWei("20", "gwei")), + gasLimit: 1000000, + to: contractAddress, + value: 0, + data: msgData, + }); + var privateKey = Buffer.from(hexPrivateKey, "hex"); + tx.sign(privateKey); + var raw = "0x" + tx.serialize().toString("hex"); + return raw; } function sendRawTransaction(raw) { - return new Promise(function (resolve, reject) { - web3.eth.sendSignedTransaction(raw, function (err, transactionHash) { - if (err !== null) return reject(err); - resolve(transactionHash); - }); + return new Promise(function (resolve, reject) { + web3.eth.sendSignedTransaction(raw, function (err, transactionHash) { + if (err !== null) return reject(err); + resolve(transactionHash); }); + }); } function functionSignature(methodName) { - return web3.utils.sha3(methodName).substr(0, 2 + 8); + return web3.utils.sha3(methodName).substr(0, 2 + 8); } function encodeAddress(address) { - address = address.substr(2, address.length - 2); - while (address.length < 64) address = "0" + address; - return address; + address = address.substr(2, address.length - 2); + while (address.length < 64) address = "0" + address; + return address; } function encodeUint(value) { - value = value.toString(16); - while (value.length < 64) value = "0" + value; - return value; + value = value.toString(16); + while (value.length < 64) value = "0" + value; + return value; } // Create ABI calls for functions function msgData0(methodName, value) { - return functionSignature(methodName) + encodeUint(value); + return functionSignature(methodName) + encodeUint(value); } function msgData(methodName, addressValue) { - return functionSignature(methodName) + encodeAddress(addressValue); + return functionSignature(methodName) + encodeAddress(addressValue); } function msgData1(methodName, address, value) { - return functionSignature(methodName) + encodeAddress(address) + encodeUint(value); + return ( + functionSignature(methodName) + encodeAddress(address) + encodeUint(value) + ); } function msgData2(methodName, address1, address2, value) { - return functionSignature(methodName) + encodeAddress(address1) + encodeAddress(address2) + encodeUint(value); + return ( + functionSignature(methodName) + + encodeAddress(address1) + + encodeAddress(address2) + + encodeUint(value) + ); } function msgData3(methodName, address1, value1, address2, value2) { - return functionSignature(methodName) + encodeAddress(address1) + encodeUint(value1) + encodeAddress(address2) + encodeUint(value2); + return ( + functionSignature(methodName) + + encodeAddress(address1) + + encodeUint(value1) + + encodeAddress(address2) + + encodeUint(value2) + ); } module.exports = { - makeRawTransaction: makeRawTransaction, - sendRawTransaction: sendRawTransaction, - functionSignature: functionSignature, - encodeAddress: encodeAddress, - encodeUint: encodeUint, - msgData0: msgData0, - msgData: msgData, - msgData1: msgData1, - msgData2: msgData2, - msgData3: msgData3 + makeRawTransaction: makeRawTransaction, + sendRawTransaction: sendRawTransaction, + functionSignature: functionSignature, + encodeAddress: encodeAddress, + encodeUint: encodeUint, + msgData0: msgData0, + msgData: msgData, + msgData1: msgData1, + msgData2: msgData2, + msgData3: msgData3, }; diff --git a/test/AccountUtils.js b/test/AccountUtils.js index 1fd8c1d8b..36601a306 100644 --- a/test/AccountUtils.js +++ b/test/AccountUtils.js @@ -1,104 +1,125 @@ // set to true to enable verbose logging in the tests var debugLogging = false; -var assertDiff = require('assert-diff'); +var assertDiff = require("assert-diff"); assertDiff.options.strict = true; -var Q = require('q'); -var clone = require('clone'); +var Q = require("q"); +var clone = require("clone"); // named list of all accounts var Accounts = { - deployerAccount: "0x90F8BF6A479F320EAD074411A4B0E7944EA8C9C1", // accounts[0] - arbitraryAccount: "0xFFCF8FDEE72AC11B5C542428B35EEF5769C409F0", // accounts[1] - 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] - controller1Account: "0x855FA758C77D68A04990E992AA4DCDEF899F654A", // accounts[11] - proxyOwnerAccount: "0x2F560290FEF1B3ADA194B6AA9C40AA71F8E95598", // accounts[14] + deployerAccount: "0x90F8BF6A479F320EAD074411A4B0E7944EA8C9C1", // accounts[0] + arbitraryAccount: "0xFFCF8FDEE72AC11B5C542428B35EEF5769C409F0", // accounts[1] + 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] + controller1Account: "0x855FA758C77D68A04990E992AA4DCDEF899F654A", // accounts[11] + proxyOwnerAccount: "0x2F560290FEF1B3ADA194B6AA9C40AA71F8E95598", // accounts[14] }; // named list of known private keys var AccountPrivateKeys = { - deployerPrivateKey: "4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b1d", // accounts[0] - arbitraryPrivateKey: "6cbed15c793ce57650b9877cf6fa156fbef513c4e6134f022a85b1ffdd59b2a1", // accounts[1] - issuerControllerPrivateKey: "6370fd033278c143179d81c5526140625662b8daa446c22ee2d73db3707e620c", // accounts[2] - tokenOwnerPrivateKey: "646f1ce2fdad0e6deeeb5c7e8e5543bdde65e86029e2fd9fc169899c440a7913", // Accounts.arbitraryAccount - blacklisterPrivateKey: "add53f9a7e588d003326d1cbf9e4a43c061aadd9bc938c843a79e7b4fd2ad743", // accounts[4] - arbitrary2PrivateKey: "395df67f0c2d2d9fe1ad08d1bc8b6627011959b79c53d7dd6a3536a33ab8a4fd", // accounts[5] - masterMinterPrivateKey: "e485d098507f54e7733a205420dfddbe58db035fa577fc294ebd14db90767a52", // accounts[6] - minterPrivateKeyt: "a453611d9419d0e56f499079478fd72c37b251a94bfde4d19872c44cf65386e3", // accounts[7] - pauserPrivateKey: "829e924fdf021ba3dbbc4225edfece9aca04b929d6e75613329ca6f1d31c0bb4", // accounts[8] - mintOwnerPrivateKey: "b0057716d5917badaf911b193b12b910811c1497b5bada8d7711f758981c3773", // accounts[9] - mintProtectorPrivateKey: "77c5495fbb039eed474fc940f29955ed0531693cc9212911efd35dff0373153f", // accounts[10] - controller1PrivateKey: "d99b5b29e6da2528bf458b26237a6cf8655a3e3276c1cdc0de1f98cefee81c01", // accounts[11] - controller2PrivateKey: "9b9c613a36396172eab2d34d72331c8ca83a358781883a535d2941f66db07b24", // accounts[12] - issuerOwnerPrivateKey: "0874049f95d55fb76916262dc70571701b5c4cc5900c0691af75f1a8a52c8268", // accounts[13] - proxyOwnerAccount: "21d7212f3b4e5332fd465877b64926e3532653e2798a11255a46f533852dfe46", // accounts[14] + deployerPrivateKey: + "4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b1d", // accounts[0] + arbitraryPrivateKey: + "6cbed15c793ce57650b9877cf6fa156fbef513c4e6134f022a85b1ffdd59b2a1", // accounts[1] + issuerControllerPrivateKey: + "6370fd033278c143179d81c5526140625662b8daa446c22ee2d73db3707e620c", // accounts[2] + tokenOwnerPrivateKey: + "646f1ce2fdad0e6deeeb5c7e8e5543bdde65e86029e2fd9fc169899c440a7913", // Accounts.arbitraryAccount + blacklisterPrivateKey: + "add53f9a7e588d003326d1cbf9e4a43c061aadd9bc938c843a79e7b4fd2ad743", // accounts[4] + arbitrary2PrivateKey: + "395df67f0c2d2d9fe1ad08d1bc8b6627011959b79c53d7dd6a3536a33ab8a4fd", // accounts[5] + masterMinterPrivateKey: + "e485d098507f54e7733a205420dfddbe58db035fa577fc294ebd14db90767a52", // accounts[6] + minterPrivateKeyt: + "a453611d9419d0e56f499079478fd72c37b251a94bfde4d19872c44cf65386e3", // accounts[7] + pauserPrivateKey: + "829e924fdf021ba3dbbc4225edfece9aca04b929d6e75613329ca6f1d31c0bb4", // accounts[8] + mintOwnerPrivateKey: + "b0057716d5917badaf911b193b12b910811c1497b5bada8d7711f758981c3773", // accounts[9] + mintProtectorPrivateKey: + "77c5495fbb039eed474fc940f29955ed0531693cc9212911efd35dff0373153f", // accounts[10] + controller1PrivateKey: + "d99b5b29e6da2528bf458b26237a6cf8655a3e3276c1cdc0de1f98cefee81c01", // accounts[11] + controller2PrivateKey: + "9b9c613a36396172eab2d34d72331c8ca83a358781883a535d2941f66db07b24", // accounts[12] + issuerOwnerPrivateKey: + "0874049f95d55fb76916262dc70571701b5c4cc5900c0691af75f1a8a52c8268", // accounts[13] + proxyOwnerAccount: + "21d7212f3b4e5332fd465877b64926e3532653e2798a11255a46f533852dfe46", // accounts[14] }; function addressEquals(address1, address2) { - if (address1.toUpperCase() == address2.toUpperCase()) { - return true; - } else { - assert.isFalse("expect " + address1 + " to equal " + address2); - } + if (address1.toUpperCase() == address2.toUpperCase()) { + return true; + } else { + assert.isFalse("expect " + address1 + " to equal " + address2); + } } function addressNotEquals(address1, address2) { - if (address1.toUpperCase() != address2.toUpperCase()) { - return true; - } else { - assert.isFalse("expect " + address1 + " to not equal " + address2); - } + if (address1.toUpperCase() != address2.toUpperCase()) { + return true; + } else { + assert.isFalse("expect " + address1 + " to not equal " + address2); + } } // Returns an object with all named account values set to the default value // e.g sets {owner: 0, minter: 0,...} function setAccountDefault(accounts, defaultValue) { - var result = {}; - for (var accountName in accounts) { - result[accountName] = defaultValue; - } - return result; + var result = {}; + for (var accountName in accounts) { + result[accountName] = defaultValue; + } + return result; } // Returns an object with all named account values set to // an object containing all named account values set to default // e.g. sets {owner: setAccountDefault(accounts, 0), minter: setAccountDefault(accounts, 0),...} function recursiveSetAccountDefault(accounts, value) { - var result = {}; - for(var account in accounts) { - result[account] = setAccountDefault(accounts, value); - } - return result; + var result = {}; + for (var account in accounts) { + result[account] = setAccountDefault(accounts, value); + } + return result; } // return an expectedState that combines customState with the emptyState -function buildExpectedPartialState(emptyState, customState, ignoreExtraCustomVars) { - // for each item in customVars, set the item in expectedState - var expectedState = clone(emptyState); +function buildExpectedPartialState( + emptyState, + customState, + ignoreExtraCustomVars +) { + // for each item in customVars, set the item in expectedState + var expectedState = clone(emptyState); - for( var variableName in customState) { - // do I ignore extra values - if(expectedState.hasOwnProperty(variableName)) { - var variableValue = customState[variableName]; - if(isLiteral(variableValue)) { - expectedState[variableName] = variableValue; - } else { - // assume variableValue is a mapping evaluated on 1 or more accounts - for(var accountName in variableValue) { - expectedState[variableName][accountName] = variableValue[accountName]; - } - } - } else if(! ignoreExtraCustomVars) { - throw new Error("variable " + variableName + " not found in expectedState"); + for (var variableName in customState) { + // do I ignore extra values + if (expectedState.hasOwnProperty(variableName)) { + var variableValue = customState[variableName]; + if (isLiteral(variableValue)) { + expectedState[variableName] = variableValue; + } else { + // assume variableValue is a mapping evaluated on 1 or more accounts + for (var accountName in variableValue) { + expectedState[variableName][accountName] = variableValue[accountName]; } - } - return expectedState; + } + } else if (!ignoreExtraCustomVars) { + throw new Error( + "variable " + variableName + " not found in expectedState" + ); + } + } + return expectedState; } // For testing variance of specific variables from their default values. @@ -109,23 +130,40 @@ function buildExpectedPartialState(emptyState, customState, ignoreExtraCustomVar // getActualState: async function(token, accounts) => state // accounts: list of accounts on which to evaluate mappings // ignoreExtraCustomVars: ignore _customVars names that are not in the emptyState -async function checkState(_tokens, _customVars, emptyState, getActualState, accounts, ignoreExtraCustomVars) { - // Iterate over array of tokens. - var numTokens = _tokens.length; - assert.equal(numTokens, _customVars.length); - var n; - for (n = 0; n < numTokens; n++) { - var token = _tokens[n]; - var customVars = _customVars[n]; - let expectedState = buildExpectedPartialState(emptyState, customVars, ignoreExtraCustomVars); +async function checkState( + _tokens, + _customVars, + emptyState, + getActualState, + accounts, + ignoreExtraCustomVars +) { + // Iterate over array of tokens. + var numTokens = _tokens.length; + assert.equal(numTokens, _customVars.length); + var n; + for (n = 0; n < numTokens; n++) { + var token = _tokens[n]; + var customVars = _customVars[n]; + let expectedState = buildExpectedPartialState( + emptyState, + customVars, + ignoreExtraCustomVars + ); - if (debugLogging) { - console.log(util.inspect(expectedState, { showHidden: false, depth: null })) - } - - let actualState = await getActualState(token, accounts); - assertDiff.deepEqual(actualState, expectedState, "difference between expected and actual state"); + if (debugLogging) { + console.log( + util.inspect(expectedState, { showHidden: false, depth: null }) + ); } + + let actualState = await getActualState(token, accounts); + assertDiff.deepEqual( + actualState, + expectedState, + "difference between expected and actual state" + ); + } } // accountQuery: an async function that takes as input an address and @@ -134,36 +172,35 @@ async function checkState(_tokens, _customVars, emptyState, getActualState, acco // returns an object containing the results of calling accountQuery on each account // E.g. {owner: value1, minter: value2} async function getAccountState(accountQuery, accounts) { - // 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 state; + // 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 state; } function isLiteral(object) { - if(typeof(object) == 'object' && ! object._isBigNumber) - return false; - return true; + if (typeof object == "object" && !object._isBigNumber) return false; + return true; } module.exports = { - Accounts: Accounts, - AccountPrivateKeys: AccountPrivateKeys, - setAccountDefault: setAccountDefault, - recursiveSetAccountDefault: recursiveSetAccountDefault, - buildExpectedPartialState: buildExpectedPartialState, - checkState: checkState, - getAccountState: getAccountState, - addressEquals: addressEquals, - addressNotEquals: addressNotEquals, -} \ No newline at end of file + Accounts: Accounts, + AccountPrivateKeys: AccountPrivateKeys, + setAccountDefault: setAccountDefault, + recursiveSetAccountDefault: recursiveSetAccountDefault, + buildExpectedPartialState: buildExpectedPartialState, + checkState: checkState, + getAccountState: getAccountState, + addressEquals: addressEquals, + addressNotEquals: addressNotEquals, +}; diff --git a/test/ControllerTestUtils.js b/test/ControllerTestUtils.js index 4102536bc..88a789710 100644 --- a/test/ControllerTestUtils.js +++ b/test/ControllerTestUtils.js @@ -1,48 +1,54 @@ -var Q = require('q'); +var Q = require("q"); // set to true to enable verbose logging in the tests var debugLogging = false; -var Controller = artifacts.require('./../minting/Controller'); -var AccountUtils = require('./AccountUtils.js'); +var Controller = artifacts.require("./../minting/Controller"); +var AccountUtils = require("./AccountUtils.js"); var Accounts = AccountUtils.Accounts; var setAccountDefault = AccountUtils.setAccountDefault; var checkState = AccountUtils.checkState; var getAccountState = AccountUtils.getAccountState; function ControllerState(owner, controllers) { - this.owner = owner; - this.controllers = controllers; - this.checkState = async function(controllerContract) {await checkControllerState(controllerContract, this)}; + this.owner = owner; + this.controllers = controllers; + this.checkState = async function (controllerContract) { + await checkControllerState(controllerContract, this); + }; } // Default state of Controller when it is deployed var controllerEmptyState = new ControllerState( - Accounts.mintOwnerAccount, - setAccountDefault(Accounts, "0x0000000000000000000000000000000000000000") + Accounts.mintOwnerAccount, + setAccountDefault(Accounts, "0x0000000000000000000000000000000000000000") ); // Checks the state of an array of controller contracts async function checkControllerState(controller, customState) { - await checkState(controller, customState, controllerEmptyState, getActualControllerState, Accounts, true); + await checkState( + controller, + customState, + controllerEmptyState, + getActualControllerState, + Accounts, + true + ); } // Gets the actual state of the controller contract. // Evaluates all mappings on the provided accounts. async function getActualControllerState(controllerContract, accounts) { - return Q.all([ - controllerContract.owner.call(), - getAccountState(controllerContract.controllers, accounts), - ]).spread(function ( - owner, - controllerState, - ) { - return new ControllerState(owner, controllerState); - }); + return Q.all([ + controllerContract.owner.call(), + getAccountState(controllerContract.controllers, accounts), + ]).spread(function (owner, controllerState) { + return new ControllerState(owner, controllerState); + }); } module.exports = { - controllerEmptyState: controllerEmptyState, - checkControllerState: checkControllerState, - getActualControllerState: getActualControllerState -} \ No newline at end of file + controllerEmptyState: controllerEmptyState, + checkControllerState: checkControllerState, + getActualControllerState: getActualControllerState, +}; diff --git a/test/MintControllerUtils.js b/test/MintControllerUtils.js index 8fc2e4b0a..b669e3bd0 100644 --- a/test/MintControllerUtils.js +++ b/test/MintControllerUtils.js @@ -1,21 +1,23 @@ -var tokenUtils = require('./TokenTestUtils.js'); +var tokenUtils = require("./TokenTestUtils.js"); var bigZero = tokenUtils.bigZero; var initializeTokenWithProxy = tokenUtils.initializeTokenWithProxy; -var MintController = artifacts.require('./minting/MintController'); -var AccountUtils = require('./AccountUtils.js'); +var MintController = artifacts.require("./minting/MintController"); +var AccountUtils = require("./AccountUtils.js"); var Accounts = AccountUtils.Accounts; var checkState = AccountUtils.checkState; var getAccountState = AccountUtils.getAccountState; -var ControllerUtils = require('./ControllerTestUtils.js'); +var ControllerUtils = require("./ControllerTestUtils.js"); var checkControllerState = ControllerUtils.checkControllerState; function MintControllerState(owner, controllers, minterManager) { - this.owner = owner; - this.controllers = controllers; - this.minterManager = minterManager; - this.checkState = async function(mintController) {await checkMintControllerState(mintController, this)}; + this.owner = owner; + this.controllers = controllers; + this.minterManager = minterManager; + this.checkState = async function (mintController) { + await checkMintControllerState(mintController, this); + }; } // Default state of MintController when it is deployed @@ -23,35 +25,49 @@ var mintControllerEmptyState = new MintControllerState(null, {}, bigZero); // Checks the state of the mintController contract async function checkMintControllerState(mintController, customState) { - await checkControllerState(mintController, customState); - await checkState(mintController, customState, mintControllerEmptyState, getActualMintControllerState, Accounts, true); + await checkControllerState(mintController, customState); + await checkState( + mintController, + customState, + mintControllerEmptyState, + getActualMintControllerState, + Accounts, + true + ); } - // Gets the actual state of the mintController contract. // Evaluates all mappings on the provided accounts. async function getActualMintControllerState(mintController, accounts) { - var minterManager = await mintController.minterManager.call(); - return new MintControllerState(null, {}, minterManager); + var minterManager = await mintController.minterManager.call(); + return new MintControllerState(null, {}, minterManager); } // Deploys a FiatTokenV1 with a MintController contract as the masterMinter. // Uses the same workflow we would do in production - first deploy FiatToken then set the masterMinter. -async function initializeTokenWithProxyAndMintController(rawToken, MintControllerArtifact) { - var tokenConfig = await initializeTokenWithProxy(rawToken); - var mintController = await MintControllerArtifact.new(tokenConfig.token.address, {from:Accounts.mintOwnerAccount}); - await tokenConfig.token.updateMasterMinter(mintController.address, {from:Accounts.tokenOwnerAccount}); - var tokenConfigWithMinter = { - proxy: tokenConfig.proxy, - token: tokenConfig.token, - mintController: mintController, - customState: new MintControllerState(null, {}, tokenConfig.token.address) - }; - return tokenConfigWithMinter; +async function initializeTokenWithProxyAndMintController( + rawToken, + MintControllerArtifact +) { + var tokenConfig = await initializeTokenWithProxy(rawToken); + var mintController = await MintControllerArtifact.new( + tokenConfig.token.address, + { from: Accounts.mintOwnerAccount } + ); + await tokenConfig.token.updateMasterMinter(mintController.address, { + from: Accounts.tokenOwnerAccount, + }); + var tokenConfigWithMinter = { + proxy: tokenConfig.proxy, + token: tokenConfig.token, + mintController: mintController, + customState: new MintControllerState(null, {}, tokenConfig.token.address), + }; + return tokenConfigWithMinter; } module.exports = { - initializeTokenWithProxyAndMintController: initializeTokenWithProxyAndMintController, - checkMintControllerState: checkMintControllerState, - MintControllerState: MintControllerState -} \ No newline at end of file + initializeTokenWithProxyAndMintController: initializeTokenWithProxyAndMintController, + checkMintControllerState: checkMintControllerState, + MintControllerState: MintControllerState, +}; diff --git a/test/TokenTestUtils.js b/test/TokenTestUtils.js index 249baadcc..71dc878ed 100644 --- a/test/TokenTestUtils.js +++ b/test/TokenTestUtils.js @@ -1,28 +1,31 @@ -const util = require('util'); -const abi = require('ethereumjs-abi') -var _ = require('lodash'); -var clone = require('clone'); -var name = 'Sample Fiat Token'; -var symbol = 'C-USD'; -var currency = 'USD'; -var BN = require('bn.js'); -var BigNumber = require('bignumber.js'); +const util = require("util"); +const abi = require("ethereumjs-abi"); +var _ = require("lodash"); +var clone = require("clone"); +var name = "Sample Fiat Token"; +var symbol = "C-USD"; +var currency = "USD"; +var BN = require("bn.js"); +var BigNumber = require("bignumber.js"); var trueInStorageFormat = "0x01"; var decimals = newBigNumber(10); var bigZero = newBigNumber(0); -var zeroAddress = '0x0000000000000000000000000000000000000000'; +var zeroAddress = "0x0000000000000000000000000000000000000000"; var bigHundred = newBigNumber(100); -var maxAmount = "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"; -var assertDiff = require('assert-diff'); +var maxAmount = + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"; +var assertDiff = require("assert-diff"); assertDiff.options.strict = true; -var Q = require('q'); -var FiatToken = artifacts.require('FiatTokenV1'); -var UpgradedFiatToken = artifacts.require('FiatTokenV2'); -var UpgradedFiatTokenNewFields = artifacts.require('FiatTokenV2NewFieldsTest'); -var UpgradedFiatTokenNewFieldsNewLogic = artifacts.require('FiatTokenV2NewFieldsNewLogicTest'); -var FiatTokenProxy = artifacts.require('FiatTokenProxy'); - -var AccountUtils = require('./AccountUtils'); +var Q = require("q"); +var FiatToken = artifacts.require("FiatTokenV1"); +var UpgradedFiatToken = artifacts.require("FiatTokenV2"); +var UpgradedFiatTokenNewFields = artifacts.require("FiatTokenV2NewFieldsTest"); +var UpgradedFiatTokenNewFieldsNewLogic = artifacts.require( + "FiatTokenV2NewFieldsNewLogicTest" +); +var FiatTokenProxy = artifacts.require("FiatTokenProxy"); + +var AccountUtils = require("./AccountUtils"); var Accounts = AccountUtils.Accounts; var setAccountDefault = AccountUtils.setAccountDefault; var recursiveSetAccountDefault = AccountUtils.recursiveSetAccountDefault; @@ -32,215 +35,288 @@ var addressEquals = AccountUtils.addressEquals; // TODO: test really big numbers Does this still have to be done?? -var adminSlot = "0x10d6a54a4754c8869d6886b5f5d7fbfa5b4522237ea5c60d11bc4e7a1ff9390b"; -var implSlot = "0x7050c9e0f4ca769c69bd3a8ef740bc37934f8e2c036e5a723fd8ee048ed3f8c3"; +var adminSlot = + "0x10d6a54a4754c8869d6886b5f5d7fbfa5b4522237ea5c60d11bc4e7a1ff9390b"; +var implSlot = + "0x7050c9e0f4ca769c69bd3a8ef740bc37934f8e2c036e5a723fd8ee048ed3f8c3"; // set to true to enable verbose logging in the tests var debugLogging = false; -// Common solidity error messages +// Common solidity error messages var solidityErrors = { - "argumentType": "argument must be", - -} + argumentType: "argument must be", +}; // Returns a new BN object function newBigNumber(value) { - var hex = new BigNumber(value).toString(16); - return new BN(hex, 16); + var hex = new BigNumber(value).toString(16); + return new BN(hex, 16); } - function calculateFeeAmount(amount) { - return Math.floor((fee / feeBase) * amount); + return Math.floor((fee / feeBase) * amount); } -function checkMinterConfiguredEvent(configureMinterEvent, minter, minterAllowedAmount) { - assert.equal(configureMinterEvent.logs[0].event, 'MinterConfigured') - assert.isTrue(addressEquals(configureMinterEvent.logs[0].args.minter, minter)); - assert.equal(configureMinterEvent.logs[0].args.minterAllowedAmount, minterAllowedAmount) +function checkMinterConfiguredEvent( + configureMinterEvent, + minter, + minterAllowedAmount +) { + assert.equal(configureMinterEvent.logs[0].event, "MinterConfigured"); + assert.isTrue( + addressEquals(configureMinterEvent.logs[0].args.minter, minter) + ); + assert.equal( + configureMinterEvent.logs[0].args.minterAllowedAmount, + minterAllowedAmount + ); } function checkMinterRemovedEvent(minterRemovedEvent, minter) { - assert.equal(minterRemovedEvent.logs[0].event, 'MinterRemoved') - assert.isTrue(addressEquals(minterRemovedEvent.logs[0].args.oldMinter, minter)); + assert.equal(minterRemovedEvent.logs[0].event, "MinterRemoved"); + assert.isTrue( + addressEquals(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); - assert.equal(transferEvent.logs[0].args.feeAccount, feeAccount); - assert.equal(transferEvent.logs[0].args.feeAmount, feeAmount); - assert.equal(transferEvent.logs[1].event, 'Transfer'); - assert.isTrue(addressEquals(transferEvent.logs[1].args.from, from)); - assert.isTrue(addressEquals(transferEvent.logs[1].args.to, to)); - assert.equal(transferEvent.logs[1].args.value, value); + assert.equal(transferEvent.logs[0].event, "Fee"); + assert.equal(transferEvent.logs[0].args.from, from); + assert.equal(transferEvent.logs[0].args.feeAccount, feeAccount); + assert.equal(transferEvent.logs[0].args.feeAmount, feeAmount); + assert.equal(transferEvent.logs[1].event, "Transfer"); + assert.isTrue(addressEquals(transferEvent.logs[1].args.from, from)); + assert.isTrue(addressEquals(transferEvent.logs[1].args.to, to)); + assert.equal(transferEvent.logs[1].args.value, value); } function checkTransferEvents(transferEvent, from, to, value) { - assert.equal(transferEvent.logs[0].event, 'Transfer'); - assert.isTrue(addressEquals(transferEvent.logs[0].args.from, from)); - assert.isTrue(addressEquals(transferEvent.logs[0].args.to, to)); - assert.equal(transferEvent.logs[0].args.value, value); + assert.equal(transferEvent.logs[0].event, "Transfer"); + assert.isTrue(addressEquals(transferEvent.logs[0].args.from, from)); + assert.isTrue(addressEquals(transferEvent.logs[0].args.to, to)); + assert.equal(transferEvent.logs[0].args.value, value); } function checkApprovalEvent(approvalEvent, approver, spender, value) { - assert.equal(approvalEvent.logs[0].event, 'Approval'); - assert.isTrue(addressEquals(approvalEvent.logs[0].args.owner, approver)); - assert.isTrue(addressEquals(approvalEvent.logs[0].args.spender, spender)); - assert.equal(approvalEvent.logs[0].args.value, value); + assert.equal(approvalEvent.logs[0].event, "Approval"); + assert.isTrue(addressEquals(approvalEvent.logs[0].args.owner, approver)); + assert.isTrue(addressEquals(approvalEvent.logs[0].args.spender, spender)); + assert.equal(approvalEvent.logs[0].args.value, value); } function checkBurnEvent(burnEvent, burner, amount) { - assert.equal(burnEvent.logs[0].event, 'Burn'); - assert.isTrue(addressEquals(burnEvent.logs[0].args.burner, burner)); - assert.isTrue(addressEquals(burnEvent.logs[0].args.amount, amount)); + assert.equal(burnEvent.logs[0].event, "Burn"); + assert.isTrue(addressEquals(burnEvent.logs[0].args.burner, burner)); + assert.isTrue(addressEquals(burnEvent.logs[0].args.amount, amount)); } function checkBlacklistEvent(blacklistEvent, account) { - assert.equal(blacklistEvent.logs[0].event, 'Blacklisted'); - assert.isTrue(addressEquals(blacklistEvent.logs[0].args._account, account)); + assert.equal(blacklistEvent.logs[0].event, "Blacklisted"); + assert.isTrue(addressEquals(blacklistEvent.logs[0].args._account, account)); } function checkUnblacklistEvent(unblacklistEvent, account) { - assert.equal(unblacklistEvent.logs[0].event, 'UnBlacklisted'); - assert.isTrue(addressEquals(unblacklistEvent.logs[0].args._account, account)); + assert.equal(unblacklistEvent.logs[0].event, "UnBlacklisted"); + assert.isTrue(addressEquals(unblacklistEvent.logs[0].args._account, account)); } function checkBlacklisterChangedEvent(blacklisterChangedEvent, blacklister) { - assert.equal(blacklisterChangedEvent.logs[0].event, 'BlacklisterChanged'); - assert.isTrue(addressEquals(blacklisterChangedEvent.logs[0].args.newBlacklister, blacklister)); + assert.equal(blacklisterChangedEvent.logs[0].event, "BlacklisterChanged"); + assert.isTrue( + addressEquals( + blacklisterChangedEvent.logs[0].args.newBlacklister, + blacklister + ) + ); } function checkPauserChangedEvent(pauserChangedEvent, pauser) { - assert.equal(pauserChangedEvent.logs[0].event, 'PauserChanged'); - assert.isTrue(addressEquals(pauserChangedEvent.logs[0].args.newAddress, pauser)); -} - -function checkTransferOwnershipEvent(transferOwnershipEvent, previousOwner, newOwner) { - assert.equal(transferOwnershipEvent.logs[0].event, 'OwnershipTransferred'); - assert.isTrue(addressEquals(transferOwnershipEvent.logs[0].args.previousOwner, previousOwner)) - assert.isTrue(addressEquals(transferOwnershipEvent.logs[0].args.newOwner, newOwner)); -} - -function checkUpdateMasterMinterEvent(checkUpdateMasterMinterEvent, newMasterMinter) { - assert.equal(checkUpdateMasterMinterEvent.logs[0].event, 'MasterMinterChanged'); - assert.isTrue(addressEquals(checkUpdateMasterMinterEvent.logs[0].args.newMasterMinter, newMasterMinter)); + assert.equal(pauserChangedEvent.logs[0].event, "PauserChanged"); + assert.isTrue( + addressEquals(pauserChangedEvent.logs[0].args.newAddress, pauser) + ); +} + +function checkTransferOwnershipEvent( + transferOwnershipEvent, + previousOwner, + newOwner +) { + assert.equal(transferOwnershipEvent.logs[0].event, "OwnershipTransferred"); + assert.isTrue( + addressEquals( + transferOwnershipEvent.logs[0].args.previousOwner, + previousOwner + ) + ); + assert.isTrue( + addressEquals(transferOwnershipEvent.logs[0].args.newOwner, newOwner) + ); +} + +function checkUpdateMasterMinterEvent( + checkUpdateMasterMinterEvent, + newMasterMinter +) { + assert.equal( + checkUpdateMasterMinterEvent.logs[0].event, + "MasterMinterChanged" + ); + assert.isTrue( + addressEquals( + checkUpdateMasterMinterEvent.logs[0].args.newMasterMinter, + newMasterMinter + ) + ); } function checkAdminChangedEvent(adminChangedEvent, previousAdmin, newAdmin) { - assert.equal(adminChangedEvent.logs[0].event, 'AdminChanged') - assert.isTrue(addressEquals(adminChangedEvent.logs[0].args.previousAdmin, previousAdmin)); - assert.isTrue(addressEquals(adminChangedEvent.logs[0].args.newAdmin, newAdmin)); + assert.equal(adminChangedEvent.logs[0].event, "AdminChanged"); + assert.isTrue( + addressEquals(adminChangedEvent.logs[0].args.previousAdmin, previousAdmin) + ); + assert.isTrue( + addressEquals(adminChangedEvent.logs[0].args.newAdmin, newAdmin) + ); } function checkUpgradeEvent(upgradeEvent, implementation) { - assert.equal(upgradeEvent.logs[0].event, 'Upgraded'); - assert.isTrue(addressEquals(upgradeEvent.logs[0].args.implementation, implementation)); -} - -function checkTransferProxyOwnershipEvent(transferProxyOwnershipEvent, previousOwner, newOwner) { - assert.equal(transferProxyOwnershipEvent.logs[0].event, 'ProxyOwnershipTransferred'); - assert.isTrue(addressEquals(transferProxyOwnershipEvent.logs[0].args.previousOwner, previousOwner)); - assert.isTrue(addressEquals(transferProxyOwnershipEvent.logs[0].args.newOwner, newOwner)); + assert.equal(upgradeEvent.logs[0].event, "Upgraded"); + assert.isTrue( + addressEquals(upgradeEvent.logs[0].args.implementation, implementation) + ); +} + +function checkTransferProxyOwnershipEvent( + transferProxyOwnershipEvent, + previousOwner, + newOwner +) { + assert.equal( + transferProxyOwnershipEvent.logs[0].event, + "ProxyOwnershipTransferred" + ); + assert.isTrue( + addressEquals( + transferProxyOwnershipEvent.logs[0].args.previousOwner, + previousOwner + ) + ); + assert.isTrue( + addressEquals(transferProxyOwnershipEvent.logs[0].args.newOwner, newOwner) + ); } function checkPauseEvent(pause) { - assert.equal(pause.logs[0].event, 'Pause'); + assert.equal(pause.logs[0].event, "Pause"); } function checkUnpauseEvent(unpause) { - assert.equal(unpause.logs[0].event, 'Unpause'); + assert.equal(unpause.logs[0].event, "Unpause"); } function checkMintEvent(minting, to, amount, minter) { - // Mint Event - assert.equal(minting.logs[0].event, 'Mint'); - assert.isTrue(addressEquals(minting.logs[0].args.minter, minter)); - assert.isTrue(addressEquals(minting.logs[0].args.to, to)); - assert.equal(minting.logs[0].args.amount, amount); - - // Transfer from 0 Event - assert.equal(minting.logs[1].event, 'Transfer'); - assert.isTrue(addressEquals(minting.logs[1].args.from, zeroAddress)); - assert.isTrue(addressEquals(minting.logs[1].args.to, to)); - assert.equal(minting.logs[1].args.value, amount); + // Mint Event + assert.equal(minting.logs[0].event, "Mint"); + assert.isTrue(addressEquals(minting.logs[0].args.minter, minter)); + assert.isTrue(addressEquals(minting.logs[0].args.to, to)); + assert.equal(minting.logs[0].args.amount, amount); + // Transfer from 0 Event + assert.equal(minting.logs[1].event, "Transfer"); + assert.isTrue(addressEquals(minting.logs[1].args.from, zeroAddress)); + assert.isTrue(addressEquals(minting.logs[1].args.to, to)); + assert.equal(minting.logs[1].args.value, amount); } function checkBurnEvents(burning, amount, burner) { - // Burn Event - assert.equal(burning.logs[0].event, 'Burn'); - assert.isTrue(addressEquals(burning.logs[0].args.burner, burner)); - assert.equal(burning.logs[0].args.amount, amount); - - // Transfer to 0 Event - assert.equal(burning.logs[1].event, 'Transfer'); - assert.isTrue(addressEquals(burning.logs[1].args.from, burner)); - assert.isTrue(addressEquals(burning.logs[1].args.to, zeroAddress)); - assert.equal(burning.logs[1].args.value, amount); + // Burn Event + assert.equal(burning.logs[0].event, "Burn"); + assert.isTrue(addressEquals(burning.logs[0].args.burner, burner)); + assert.equal(burning.logs[0].args.amount, amount); + // Transfer to 0 Event + assert.equal(burning.logs[1].event, "Transfer"); + assert.isTrue(addressEquals(burning.logs[1].args.from, burner)); + assert.isTrue(addressEquals(burning.logs[1].args.to, zeroAddress)); + assert.equal(burning.logs[1].args.value, amount); } var fiatTokenEmptyState = { - "name": name, - "symbol": symbol, - "currency": currency, - "decimals": decimals, - "masterMinter": Accounts.masterMinterAccount, - "pauser": Accounts.pauserAccount, - "blacklister" : Accounts.blacklisterAccount, - "tokenOwner": Accounts.tokenOwnerAccount, - "proxiedTokenAddress": bigZero, - "initializedV1": trueInStorageFormat, - "proxyOwner": Accounts.proxyOwnerAccount, - "balances": setAccountDefault(Accounts, bigZero), - "allowance": recursiveSetAccountDefault(Accounts, bigZero), - "totalSupply": bigZero, - "isAccountBlacklisted": setAccountDefault(Accounts, false), - "isAccountMinter": setAccountDefault(Accounts, false), - "minterAllowance": setAccountDefault(Accounts, bigZero), - "paused": false, + name: name, + symbol: symbol, + currency: currency, + decimals: decimals, + masterMinter: Accounts.masterMinterAccount, + pauser: Accounts.pauserAccount, + blacklister: Accounts.blacklisterAccount, + tokenOwner: Accounts.tokenOwnerAccount, + proxiedTokenAddress: bigZero, + initializedV1: trueInStorageFormat, + proxyOwner: Accounts.proxyOwnerAccount, + balances: setAccountDefault(Accounts, bigZero), + allowance: recursiveSetAccountDefault(Accounts, bigZero), + totalSupply: bigZero, + isAccountBlacklisted: setAccountDefault(Accounts, false), + isAccountMinter: setAccountDefault(Accounts, false), + minterAllowance: setAccountDefault(Accounts, bigZero), + paused: false, }; // Creates a state object, with default values replaced by // customVars where appropriate. function buildExpectedState(token, customVars) { - // for each item in customVars, set the item in expectedState - var expectedState = clone(fiatTokenEmptyState); - expectedState.proxiedTokenAddress = token.proxiedTokenAddress; - - var i; - for (i = 0; i < customVars.length; ++i) { - if (_.has(expectedState, customVars[i].variable)) { - if (expectedState[customVars[i].variable] == customVars[i].expectedValue) { - throw new Error("variable " + customVars[i].variable + " to test has same default state as expected state"); - } else { - _.set(expectedState, customVars[i].variable, customVars[i].expectedValue); - } - } else { - // TODO: test the error - throw new Error("variable " + customVars[i].variable + " not found in expectedState"); - } + // for each item in customVars, set the item in expectedState + var expectedState = clone(fiatTokenEmptyState); + expectedState.proxiedTokenAddress = token.proxiedTokenAddress; + + var i; + for (i = 0; i < customVars.length; ++i) { + if (_.has(expectedState, customVars[i].variable)) { + if ( + expectedState[customVars[i].variable] == customVars[i].expectedValue + ) { + throw new Error( + "variable " + + customVars[i].variable + + " to test has same default state as expected state" + ); + } else { + _.set( + expectedState, + customVars[i].variable, + customVars[i].expectedValue + ); + } + } else { + // TODO: test the error + throw new Error( + "variable " + customVars[i].variable + " not found in expectedState" + ); } - return expectedState; + } + return expectedState; } // Replaces all BN objects with 32 character hex strings function mapBNToHex(state) { - var result = {}; - for (var name in state) { - if(BN.isBN(state[name])) { - result[name] = web3.utils.toHex(state[name]); - } else if(typeof state[name] == 'object') { - result[name] = mapBNToHex(state[name]); - } else if(typeof state[name] == 'string' && state[name].substring(0,2)=='0x') { - result[name] = state[name].toUpperCase(); - } else { - result[name] = state[name]; - } + var result = {}; + for (var name in state) { + if (BN.isBN(state[name])) { + result[name] = web3.utils.toHex(state[name]); + } else if (typeof state[name] == "object") { + result[name] = mapBNToHex(state[name]); + } else if ( + typeof state[name] == "string" && + state[name].substring(0, 2) == "0x" + ) { + result[name] = state[name].toUpperCase(); + } else { + result[name] = state[name]; } - return result; + } + return result; } // For testing variance of specific variables from their default values. @@ -248,33 +324,46 @@ function mapBNToHex(state) { // {'variable': , 'expectedValue': } // to reference nested variables, name variable using dot syntax, e.g. 'allowance.arbitraryAccount.minterAccount' async function checkVariables(_tokens, _customVars) { - // Iterate over array of tokens. - var numTokens = _tokens.length; - assert.equal(numTokens, _customVars.length); - var n; - for (n = 0; n < numTokens; n++) { - var token = _tokens[n]; - var customVars = _customVars[n]; - - let expectedState = mapBNToHex(buildExpectedState(token, customVars)); - let actualState = mapBNToHex(await getActualState(token)); - if (debugLogging) { - console.log(util.inspect(expectedState, { showHidden: false, depth: null })) - console.log(util.inspect(actualState, { showHidden: false, depth: null })) - } - - assertDiff.deepEqual(actualState, expectedState, "difference between expected and actual state"); - - // Check that sum of individual balances equals totalSupply - var accounts = Object.keys(Accounts).map(accountName => Accounts[accountName]); - var balanceSum = bigZero; - var x; - for (x = 0; x < accounts.length; x++) { - balanceSum = balanceSum.add(await token.balanceOf(accounts[x])); - } - var totalSupply = newBigNumber(await token.totalSupply()) - assert(balanceSum.cmp(totalSupply)==0, "sum of balances is not equal to totalSupply"); + // Iterate over array of tokens. + var numTokens = _tokens.length; + assert.equal(numTokens, _customVars.length); + var n; + for (n = 0; n < numTokens; n++) { + var token = _tokens[n]; + var customVars = _customVars[n]; + + let expectedState = mapBNToHex(buildExpectedState(token, customVars)); + let actualState = mapBNToHex(await getActualState(token)); + if (debugLogging) { + console.log( + util.inspect(expectedState, { showHidden: false, depth: null }) + ); + console.log( + util.inspect(actualState, { showHidden: false, depth: null }) + ); } + + assertDiff.deepEqual( + actualState, + expectedState, + "difference between expected and actual state" + ); + + // Check that sum of individual balances equals totalSupply + var accounts = Object.keys(Accounts).map( + (accountName) => Accounts[accountName] + ); + var balanceSum = bigZero; + var x; + for (x = 0; x < accounts.length; x++) { + balanceSum = balanceSum.add(await token.balanceOf(accounts[x])); + } + var totalSupply = newBigNumber(await token.totalSupply()); + assert( + balanceSum.cmp(totalSupply) == 0, + "sum of balances is not equal to totalSupply" + ); + } } // All MINT p0 tests will call this function. @@ -282,117 +371,119 @@ async function checkVariables(_tokens, _customVars) { // _customVars is an array of exactly two values: the expected state of the FiatTokenV1 // and the expected state of the MintController async function checkMINTp0(_contracts, _customVars) { - assert.equal(_contracts.length, 2); - assert.equal(_customVars.length, 2); + assert.equal(_contracts.length, 2); + assert.equal(_customVars.length, 2); - // the first is a FiatTokenV1 - await checkVariables([_contracts[0]], [_customVars[0]]); + // the first is a FiatTokenV1 + await checkVariables([_contracts[0]], [_customVars[0]]); - // the second is a MintController - await _customVars[1].checkState(_contracts[1]); + // the second is a MintController + await _customVars[1].checkState(_contracts[1]); } // build up actualState object to compare to expectedState object async function getActualState(token) { - // lambda expressions to get allowance mappings in token contract - var allowanceMappingEval = async function(account1) { - var myAllowances = async function(account2) { - return token.allowance(account1, account2); - } - return getAccountState(myAllowances, Accounts); + // lambda expressions to get allowance mappings in token contract + var allowanceMappingEval = async function (account1) { + var myAllowances = async function (account2) { + return token.allowance(account1, account2); }; - - return Q.all([ - token.name.call(), - token.symbol.call(), - token.currency.call(), - token.decimals.call(), - token.masterMinter.call(), - token.pauser.call(), - token.blacklister.call(), - token.owner.call(), - getImplementation(token), - getAdmin(token), - getInitializedV1(token), - getAccountState(token.balanceOf, Accounts), - getAccountState(allowanceMappingEval, Accounts), - token.totalSupply(), - getAccountState(token.isBlacklisted, Accounts), - getAccountState(token.isMinter, Accounts), - getAccountState(token.minterAllowance, Accounts), - token.paused() - ]).spread(function ( - name, - symbol, - currency, - decimals, - masterMinter, - pauser, - blacklister, - tokenOwner, - proxiedTokenAddress, - proxyOwner, - initializedV1, - balances, - allowances, - totalSupply, - isAccountBlacklisted, - isAccountMinter, - minterAllowance, - paused - ) { - var actualState = { - 'name': name, - 'symbol': symbol, - 'currency': currency, - 'decimals': decimals, - 'masterMinter': masterMinter, - 'pauser': pauser, - 'blacklister': blacklister, - 'tokenOwner': tokenOwner, - 'proxiedTokenAddress': proxiedTokenAddress, - 'proxyOwner': proxyOwner, - 'initializedV1': initializedV1, - 'balances': balances, - 'allowance': allowances, - 'totalSupply': totalSupply, - 'isAccountBlacklisted': isAccountBlacklisted, - 'isAccountMinter': isAccountMinter, - 'minterAllowance': minterAllowance, - 'paused': paused - }; - return actualState; - }) + return getAccountState(myAllowances, Accounts); + }; + + return Q.all([ + token.name.call(), + token.symbol.call(), + token.currency.call(), + token.decimals.call(), + token.masterMinter.call(), + token.pauser.call(), + token.blacklister.call(), + token.owner.call(), + getImplementation(token), + getAdmin(token), + getInitializedV1(token), + getAccountState(token.balanceOf, Accounts), + getAccountState(allowanceMappingEval, Accounts), + token.totalSupply(), + getAccountState(token.isBlacklisted, Accounts), + getAccountState(token.isMinter, Accounts), + getAccountState(token.minterAllowance, Accounts), + token.paused(), + ]).spread(function ( + name, + symbol, + currency, + decimals, + masterMinter, + pauser, + blacklister, + tokenOwner, + proxiedTokenAddress, + proxyOwner, + initializedV1, + balances, + allowances, + totalSupply, + isAccountBlacklisted, + isAccountMinter, + minterAllowance, + paused + ) { + var actualState = { + name: name, + symbol: symbol, + currency: currency, + decimals: decimals, + masterMinter: masterMinter, + pauser: pauser, + blacklister: blacklister, + tokenOwner: tokenOwner, + proxiedTokenAddress: proxiedTokenAddress, + proxyOwner: proxyOwner, + initializedV1: initializedV1, + balances: balances, + allowance: allowances, + totalSupply: totalSupply, + isAccountBlacklisted: isAccountBlacklisted, + isAccountMinter: isAccountMinter, + minterAllowance: minterAllowance, + paused: paused, + }; + return actualState; + }); } async function setMinter(token, minter, amount) { - let update = await token.configureMinter(minter, amount, { from: Accounts.masterMinterAccount }); - assert.equal(update.logs[0].event, 'MinterConfigured'); - assert.isTrue(addressEquals(update.logs[0].args.minter, minter)); - assert.equal(update.logs[0].args.minterAllowedAmount, amount); - let minterAllowance = await token.minterAllowance(minter); + let update = await token.configureMinter(minter, amount, { + from: Accounts.masterMinterAccount, + }); + assert.equal(update.logs[0].event, "MinterConfigured"); + assert.isTrue(addressEquals(update.logs[0].args.minter, minter)); + assert.equal(update.logs[0].args.minterAllowedAmount, amount); + let minterAllowance = await token.minterAllowance(minter); - assert.equal(minterAllowance, amount); + assert.equal(minterAllowance, amount); } async function burn(token, amount, burner) { - let burning = await token.burn(amount, { from: burner }); - checkBurnEvents(burning, amount, burner); + let burning = await token.burn(amount, { from: burner }); + checkBurnEvents(burning, amount, burner); } async function mint(token, to, amount, minter) { - await setMinter(token, minter, amount); - await mintRaw(token, to, amount, minter); + await setMinter(token, minter, amount); + await mintRaw(token, to, amount, minter); } async function mintRaw(token, to, amount, minter) { - let initialTotalSupply = await token.totalSupply(); - let initialMinterAllowance = await token.minterAllowance(minter); - let minting = await token.mint(to, amount, { from: minter }); - checkMintEvent(minting, to, amount, minter); + let initialTotalSupply = await token.totalSupply(); + let initialMinterAllowance = await token.minterAllowance(minter); + let minting = await token.mint(to, amount, { from: minter }); + checkMintEvent(minting, to, amount, minter); - // TODO revisit this - /* let totalSupply = await token.totalSupply(); + // TODO revisit this + /* let totalSupply = await token.totalSupply(); totalSupply.should.be.bignumber.equal(initialTotalSupply); let minterAllowance = await token.minterAllowance(minter); assert.isTrue(newBigNumber(initialMinterAllowance).minus(newBigNumber(amount)).cmp(newBigNumber(minterAllowance)) @@ -400,278 +491,346 @@ async function mintRaw(token, to, amount, minter) { } async function blacklist(token, account) { - let blacklist = await token.blacklist(account, { from: Accounts.blacklisterAccount }); - checkBlacklistEvent(blacklist, account); + let blacklist = await token.blacklist(account, { + from: Accounts.blacklisterAccount, + }); + checkBlacklistEvent(blacklist, account); } async function unBlacklist(token, account) { - let unblacklist = await token.unBlacklist(account, { from: Accounts.blacklisterAccount }); - checkUnblacklistEvent(unblacklist, account); -} - -async function setLongDecimalFeesTransferWithFees(token, ownerAccount, arbitraryAccount) { - fee = 123589; - feeBase = 1000000; - await token.updateTransferFee(fee, feeBase); - let allowed = await token.allowance.call(ownerAccount, arbitraryAccount); - assert.isTrue(allowed.isZero()); - await mint(token, ownerAccount, 1900); - let initialBalanceFeeAccount = await token.balanceOf(feeAccount); - - await token.approve(arbitraryAccount, 1500); - allowed = await token.allowance.call(ownerAccount, arbitraryAccount); - assert.isTrue(allowed.cmp(newBigNumber(1500))==0); - - let transfer = await token.transfer(arbitraryAccount, 1000, { from: ownerAccount }); - - let feeAmount = calculateFeeAmount(1000); - checkTransferEvents(transfer, ownerAccount, arbitraryAccount, 1000, feeAmount); - - - let balance0 = await token.balanceOf(ownerAccount); - assert.equal(balance0, 1900 - 1000 - feeAmount); - let balance3 = await token.balanceOf(arbitraryAccount); - assert.equal(balance3, 1000); - let balanceFeeAccount = await token.balanceOf(feeAccount); - assert.isTrue(balanceFeeAccount.sub(initialBalanceFeeAccount).cmp(newBigNumber(feeAmount))==0); + let unblacklist = await token.unBlacklist(account, { + from: Accounts.blacklisterAccount, + }); + checkUnblacklistEvent(unblacklist, account); +} + +async function setLongDecimalFeesTransferWithFees( + token, + ownerAccount, + arbitraryAccount +) { + fee = 123589; + feeBase = 1000000; + await token.updateTransferFee(fee, feeBase); + let allowed = await token.allowance.call(ownerAccount, arbitraryAccount); + assert.isTrue(allowed.isZero()); + await mint(token, ownerAccount, 1900); + let initialBalanceFeeAccount = await token.balanceOf(feeAccount); + + await token.approve(arbitraryAccount, 1500); + allowed = await token.allowance.call(ownerAccount, arbitraryAccount); + assert.isTrue(allowed.cmp(newBigNumber(1500)) == 0); + + let transfer = await token.transfer(arbitraryAccount, 1000, { + from: ownerAccount, + }); + + let feeAmount = calculateFeeAmount(1000); + checkTransferEvents( + transfer, + ownerAccount, + arbitraryAccount, + 1000, + feeAmount + ); + + let balance0 = await token.balanceOf(ownerAccount); + assert.equal(balance0, 1900 - 1000 - feeAmount); + let balance3 = await token.balanceOf(arbitraryAccount); + assert.equal(balance3, 1000); + let balanceFeeAccount = await token.balanceOf(feeAccount); + assert.isTrue( + balanceFeeAccount + .sub(initialBalanceFeeAccount) + .cmp(newBigNumber(feeAmount)) == 0 + ); } async function sampleTransfer(token, ownerAccount, arbitraryAccount, minter) { - let allowed = await token.allowance.call(ownerAccount, arbitraryAccount); - assert.isTrue(allowed.isZero()); - await mint(token, ownerAccount, 1900, minter); - - await token.approve(arbitraryAccount, 1500); - allowed = await token.allowance.call(ownerAccount, arbitraryAccount); - assert.isTrue(allowed.cmp(newBigNumber(1500))==0); - - let transfer = await token.transfer(arbitraryAccount, 1000, { from: ownerAccount }); - - checkTransferEvents(transfer, ownerAccount, arbitraryAccount, 1000); - - let balance0 = await token.balanceOf(ownerAccount); - assert.equal(balance0, 1900 - 1000); - let balance3 = await token.balanceOf(arbitraryAccount); - assert.equal(balance3, 1000); -} - -async function transferFromWithFees(token, ownerAccount, arbitraryAccount, minter) { - fee = 1235; - feeBase = 10000; - await token.updateTransferFee(fee, feeBase); - let allowed = await token.allowance.call(ownerAccount, arbitraryAccount); - assert.isTrue(allowed.isZero()); - await mint(token, ownerAccount, 900, minter); - let initialBalanceFeeAccount = await token.balanceOf(feeAccount); - await token.approve(arbitraryAccount, 634); - allowed = await token.allowance.call(ownerAccount, arbitraryAccount); - assert.isTrue(allowed.cmp(newBigNumber(634))==0); - - transfer = await token.transferFrom(ownerAccount, arbitraryAccount, 534, { from: arbitraryAccount }); - - let feeAmount = calculateFeeAmount(534); - checkTransferEvents(transfer, ownerAccount, arbitraryAccount, 534, feeAmount); - - let balance0 = await token.balanceOf(ownerAccount); - assert.isTrue(balance0.cmp(900 - 534 - feeAmount)==0); - let balance3 = await token.balanceOf(arbitraryAccount); - assert.isTrue(balance3.cmp(newBigNumber(534))==0); - let balanceFeeAccount = await token.balanceOf(feeAccount); - assert.isTrue(balanceFeeAccount.sub(initialBalanceFeeAccount).cmp(newBigNumber(feeAmount))==0); -} - -async function sampleTransferFrom(token, ownerAccount, arbitraryAccount, minter) { - let allowed = await token.allowance.call(ownerAccount, arbitraryAccount); // TODO not this - assert.isTrue(allowed.isZero()); - await mint(token, ownerAccount, 900, minter); // TODO maybe this - await token.approve(arbitraryAccount, 634); // TODO not this - allowed = await token.allowance.call(ownerAccount, arbitraryAccount); // TODO not this - assert.isTrue(allowed.cmp(newBigNumber(634))==0); - - let transfer = await token.transferFrom(ownerAccount, arbitraryAccount, 534, { from: arbitraryAccount }); // TODO not this - - checkTransferEvents(transfer, ownerAccount, arbitraryAccount, 534); - - let balance0 = await token.balanceOf(ownerAccount); - assert.isTrue(balance0.cmp(newBigNumber(900-534))==0); - let balance3 = await token.balanceOf(arbitraryAccount); - assert.isTrue(balance3.cmp(newBigNumber(534))==0); + let allowed = await token.allowance.call(ownerAccount, arbitraryAccount); + assert.isTrue(allowed.isZero()); + await mint(token, ownerAccount, 1900, minter); + + await token.approve(arbitraryAccount, 1500); + allowed = await token.allowance.call(ownerAccount, arbitraryAccount); + assert.isTrue(allowed.cmp(newBigNumber(1500)) == 0); + + let transfer = await token.transfer(arbitraryAccount, 1000, { + from: ownerAccount, + }); + + checkTransferEvents(transfer, ownerAccount, arbitraryAccount, 1000); + + let balance0 = await token.balanceOf(ownerAccount); + assert.equal(balance0, 1900 - 1000); + let balance3 = await token.balanceOf(arbitraryAccount); + assert.equal(balance3, 1000); +} + +async function transferFromWithFees( + token, + ownerAccount, + arbitraryAccount, + minter +) { + fee = 1235; + feeBase = 10000; + await token.updateTransferFee(fee, feeBase); + let allowed = await token.allowance.call(ownerAccount, arbitraryAccount); + assert.isTrue(allowed.isZero()); + await mint(token, ownerAccount, 900, minter); + let initialBalanceFeeAccount = await token.balanceOf(feeAccount); + await token.approve(arbitraryAccount, 634); + allowed = await token.allowance.call(ownerAccount, arbitraryAccount); + assert.isTrue(allowed.cmp(newBigNumber(634)) == 0); + + transfer = await token.transferFrom(ownerAccount, arbitraryAccount, 534, { + from: arbitraryAccount, + }); + + let feeAmount = calculateFeeAmount(534); + checkTransferEvents(transfer, ownerAccount, arbitraryAccount, 534, feeAmount); + + let balance0 = await token.balanceOf(ownerAccount); + assert.isTrue(balance0.cmp(900 - 534 - feeAmount) == 0); + let balance3 = await token.balanceOf(arbitraryAccount); + assert.isTrue(balance3.cmp(newBigNumber(534)) == 0); + let balanceFeeAccount = await token.balanceOf(feeAccount); + assert.isTrue( + balanceFeeAccount + .sub(initialBalanceFeeAccount) + .cmp(newBigNumber(feeAmount)) == 0 + ); +} + +async function sampleTransferFrom( + token, + ownerAccount, + arbitraryAccount, + minter +) { + let allowed = await token.allowance.call(ownerAccount, arbitraryAccount); // TODO not this + assert.isTrue(allowed.isZero()); + await mint(token, ownerAccount, 900, minter); // TODO maybe this + await token.approve(arbitraryAccount, 634); // TODO not this + allowed = await token.allowance.call(ownerAccount, arbitraryAccount); // TODO not this + assert.isTrue(allowed.cmp(newBigNumber(634)) == 0); + + let transfer = await token.transferFrom(ownerAccount, arbitraryAccount, 534, { + from: arbitraryAccount, + }); // TODO not this + + checkTransferEvents(transfer, ownerAccount, arbitraryAccount, 534); + + let balance0 = await token.balanceOf(ownerAccount); + assert.isTrue(balance0.cmp(newBigNumber(900 - 534)) == 0); + let balance3 = await token.balanceOf(arbitraryAccount); + assert.isTrue(balance3.cmp(newBigNumber(534)) == 0); } async function approve(token, to, amount, from) { - await token.approve(to, amount, { from: from }); + await token.approve(to, amount, { from: from }); } async function redeem(token, account, amount) { - let redeemResult = await token.redeem(amount, { from: account }); - assert.equal(redeemResult.logs[0].event, 'Redeem'); - assert.equal(redeemResult.logs[0].args.redeemedAddress, account); - assert.equal(redeemResult.logs[0].args.amount, amount); + let redeemResult = await token.redeem(amount, { from: account }); + assert.equal(redeemResult.logs[0].event, "Redeem"); + assert.equal(redeemResult.logs[0].args.redeemedAddress, account); + assert.equal(redeemResult.logs[0].args.amount, amount); } function validateTransferEvent(transferEvent, from, to, value) { - let eventResult = transferEvent.logs[0]; - assert.equal(eventResult.event, 'Transfer'); - assert.isTrue(addressEquals(eventResult.args.from, from)); - assert.isTrue(addressEquals(eventResult.args.to, to)); - assert.equal(eventResult.args.value, value); + let eventResult = transferEvent.logs[0]; + assert.equal(eventResult.event, "Transfer"); + assert.isTrue(addressEquals(eventResult.args.from, from)); + assert.isTrue(addressEquals(eventResult.args.to, to)); + assert.equal(eventResult.args.value, value); } async function initializeTokenWithProxy(rawToken) { - return customInitializeTokenWithProxy(rawToken, Accounts.masterMinterAccount, Accounts.pauserAccount, Accounts.blacklisterAccount, Accounts.tokenOwnerAccount); -} - -async function customInitializeTokenWithProxy(rawToken, _masterMinter, _pauser, _blacklister, _owner) { - const proxy = await FiatTokenProxy.new(rawToken.address, { from: Accounts.proxyOwnerAccount }) - proxiedToken = await FiatToken.at(proxy.address); - await proxiedToken.initialize(name, symbol, currency, decimals, _masterMinter, _pauser, _blacklister, _owner); - proxiedToken.proxiedTokenAddress = rawToken.address; - assert.equal(proxiedToken.address, proxy.address); - assert.notEqual(proxiedToken.address, rawToken.address); - var tokenConfig = { - proxy: proxy, - token: proxiedToken - }; - return tokenConfig; + return customInitializeTokenWithProxy( + rawToken, + Accounts.masterMinterAccount, + Accounts.pauserAccount, + Accounts.blacklisterAccount, + Accounts.tokenOwnerAccount + ); +} + +async function customInitializeTokenWithProxy( + rawToken, + _masterMinter, + _pauser, + _blacklister, + _owner +) { + const proxy = await FiatTokenProxy.new(rawToken.address, { + from: Accounts.proxyOwnerAccount, + }); + proxiedToken = await FiatToken.at(proxy.address); + await proxiedToken.initialize( + name, + symbol, + currency, + decimals, + _masterMinter, + _pauser, + _blacklister, + _owner + ); + proxiedToken.proxiedTokenAddress = rawToken.address; + assert.equal(proxiedToken.address, proxy.address); + assert.notEqual(proxiedToken.address, rawToken.address); + var tokenConfig = { + proxy: proxy, + token: proxiedToken, + }; + return tokenConfig; } - async function upgradeTo(proxy, upgradedToken, proxyUpgraderAccount) { - if (proxyUpgraderAccount == null) { - proxyUpgraderAccount = Accounts.proxyOwnerAccount; - } - await proxy.upgradeTo(upgradedToken.address, { from: proxyUpgraderAccount }); - proxiedToken = await FiatToken.at(proxy.address); - assert.equal(proxiedToken.address, proxy.address); - return tokenConfig = { - proxy: proxy, - token: proxiedToken - } + if (proxyUpgraderAccount == null) { + proxyUpgraderAccount = Accounts.proxyOwnerAccount; + } + await proxy.upgradeTo(upgradedToken.address, { from: proxyUpgraderAccount }); + proxiedToken = await FiatToken.at(proxy.address); + assert.equal(proxiedToken.address, proxy.address); + return (tokenConfig = { + proxy: proxy, + token: proxiedToken, + }); } async function expectRevert(contractPromise) { - await expectError(contractPromise, "revert"); + await expectError(contractPromise, "revert"); } async function expectJump(contractPromise) { - await expectError(contractPromise, "invalid opcode"); + await expectError(contractPromise, "invalid opcode"); } async function expectError(contractPromise, errorMsg) { - try { - await contractPromise; - assert.fail('Expected error ${errorMsg}, but no error received'); - } catch (error) { - var correctErrorMsgReceived = error.message.includes(errorMsg); - assert(correctErrorMsgReceived, `Expected ${errorMsg}, got ${error.message} instead`); - } + try { + await contractPromise; + assert.fail("Expected error ${errorMsg}, but no error received"); + } catch (error) { + var correctErrorMsgReceived = error.message.includes(errorMsg); + assert( + correctErrorMsgReceived, + `Expected ${errorMsg}, got ${error.message} instead` + ); + } } function encodeCall(name, arguments, values) { - const methodId = abi.methodID(name, arguments).toString('hex'); - const params = abi.rawEncode(arguments, values).toString('hex'); - return '0x' + methodId + params; + const methodId = abi.methodID(name, arguments).toString("hex"); + const params = abi.rawEncode(arguments, values).toString("hex"); + return "0x" + methodId + params; } async function getAdmin(proxy) { - var adm = await web3.eth.getStorageAt(proxy.address, adminSlot); - return adm; + var adm = await web3.eth.getStorageAt(proxy.address, adminSlot); + return adm; } async function getImplementation(proxy) { - let impl = await web3.eth.getStorageAt(proxy.address, implSlot); - return impl; + let impl = await web3.eth.getStorageAt(proxy.address, implSlot); + return impl; } async function getInitializedV1(token) { - var slot8Data = await web3.eth.getStorageAt(token.address, 8); - var slot8DataLength = slot8Data.length; - var initialized; - var masterMinterStart; - var masterMinterAddress; - if (slot8DataLength == 3) { - //Validate proxy not yet initialized - for (var i = 0; i <= 20; i++) { - assert.equal("0x0", await web3.eth.getStorageAt(token.address, i)); - } - initialized = slot8Data; + var slot8Data = await web3.eth.getStorageAt(token.address, 8); + var slot8DataLength = slot8Data.length; + var initialized; + var masterMinterStart; + var masterMinterAddress; + if (slot8DataLength == 3) { + //Validate proxy not yet initialized + for (var i = 0; i <= 20; i++) { + assert.equal("0x0", await web3.eth.getStorageAt(token.address, i)); + } + initialized = slot8Data; + } else { + if (slot8DataLength == 44) { + initialized = "0x" + slot8Data.substring(2, 4); // first 2 hex-chars after 0x + masterMinterStart = 4; + } else if (slot8DataLength == 40) { + initialized = "0x00"; + masterMinterStart = 2; } else { - if (slot8DataLength == 44) { - initialized = "0x" + slot8Data.substring(2,4); // first 2 hex-chars after 0x - masterMinterStart = 4; - } else if (slot8DataLength == 40) { - initialized = "0x00"; - masterMinterStart = 2; - } else { - assert.fail("slot8Data incorrect size"); - } - masterMinterAddress = "0x" + slot8Data.substring(masterMinterStart, masterMinterStart + 40).toUpperCase(); - var tokenMMA = await token.masterMinter.call(); - assert.isTrue(addressEquals(tokenMMA, masterMinterAddress)); + assert.fail("slot8Data incorrect size"); } - return initialized; + masterMinterAddress = + "0x" + + slot8Data + .substring(masterMinterStart, masterMinterStart + 40) + .toUpperCase(); + var tokenMMA = await token.masterMinter.call(); + assert.isTrue(addressEquals(tokenMMA, masterMinterAddress)); + } + return initialized; } module.exports = { - newBigNumber: newBigNumber, - FiatToken: FiatToken, - FiatTokenProxy: FiatTokenProxy, - UpgradedFiatToken: UpgradedFiatToken, - UpgradedFiatTokenNewFields: UpgradedFiatTokenNewFields, - UpgradedFiatTokenNewFieldsNewLogic: UpgradedFiatTokenNewFieldsNewLogic, - name: name, - symbol: symbol, - currency: currency, - decimals: decimals, - bigZero: bigZero, - zeroAddress: zeroAddress, - bigHundred: bigHundred, - debugLogging: debugLogging, - solidityErrors: solidityErrors, - calculateFeeAmount: calculateFeeAmount, - checkTransferEventsWithFee: checkTransferEventsWithFee, - checkTransferEvents: checkTransferEvents, - checkMinterConfiguredEvent: checkMinterConfiguredEvent, - checkMintEvent: checkMintEvent, - checkApprovalEvent: checkApprovalEvent, - checkBurnEvents: checkBurnEvents, - checkBurnEvent: checkBurnEvent, - checkMinterRemovedEvent: checkMinterRemovedEvent, - checkBlacklistEvent: checkBlacklistEvent, - checkUnblacklistEvent: checkUnblacklistEvent, - checkPauseEvent: checkPauseEvent, - checkUnpauseEvent: checkUnpauseEvent, - checkPauserChangedEvent: checkPauserChangedEvent, - checkTransferOwnershipEvent: checkTransferOwnershipEvent, - checkUpdateMasterMinterEvent: checkUpdateMasterMinterEvent, - checkBlacklisterChangedEvent: checkBlacklisterChangedEvent, - checkUpgradeEvent: checkUpgradeEvent, - checkAdminChangedEvent: checkAdminChangedEvent, - buildExpectedState, - checkVariables: checkVariables, - checkMINTp0: checkMINTp0, - setMinter: setMinter, - mint: mint, - burn: burn, - mintRaw: mintRaw, - blacklist: blacklist, - unBlacklist: unBlacklist, - setLongDecimalFeesTransferWithFees: setLongDecimalFeesTransferWithFees, - sampleTransfer: sampleTransfer, - transferFromWithFees: transferFromWithFees, - sampleTransferFrom: sampleTransferFrom, - approve: approve, - redeem: redeem, - validateTransferEvent: validateTransferEvent, - initializeTokenWithProxy: initializeTokenWithProxy, - customInitializeTokenWithProxy: customInitializeTokenWithProxy, - upgradeTo: upgradeTo, - expectRevert: expectRevert, - expectJump: expectJump, - expectError: expectError, - encodeCall: encodeCall, - getInitializedV1: getInitializedV1, - getAdmin: getAdmin, - maxAmount: maxAmount, - fiatTokenEmptyState, + newBigNumber: newBigNumber, + FiatToken: FiatToken, + FiatTokenProxy: FiatTokenProxy, + UpgradedFiatToken: UpgradedFiatToken, + UpgradedFiatTokenNewFields: UpgradedFiatTokenNewFields, + UpgradedFiatTokenNewFieldsNewLogic: UpgradedFiatTokenNewFieldsNewLogic, + name: name, + symbol: symbol, + currency: currency, + decimals: decimals, + bigZero: bigZero, + zeroAddress: zeroAddress, + bigHundred: bigHundred, + debugLogging: debugLogging, + solidityErrors: solidityErrors, + calculateFeeAmount: calculateFeeAmount, + checkTransferEventsWithFee: checkTransferEventsWithFee, + checkTransferEvents: checkTransferEvents, + checkMinterConfiguredEvent: checkMinterConfiguredEvent, + checkMintEvent: checkMintEvent, + checkApprovalEvent: checkApprovalEvent, + checkBurnEvents: checkBurnEvents, + checkBurnEvent: checkBurnEvent, + checkMinterRemovedEvent: checkMinterRemovedEvent, + checkBlacklistEvent: checkBlacklistEvent, + checkUnblacklistEvent: checkUnblacklistEvent, + checkPauseEvent: checkPauseEvent, + checkUnpauseEvent: checkUnpauseEvent, + checkPauserChangedEvent: checkPauserChangedEvent, + checkTransferOwnershipEvent: checkTransferOwnershipEvent, + checkUpdateMasterMinterEvent: checkUpdateMasterMinterEvent, + checkBlacklisterChangedEvent: checkBlacklisterChangedEvent, + checkUpgradeEvent: checkUpgradeEvent, + checkAdminChangedEvent: checkAdminChangedEvent, + buildExpectedState, + checkVariables: checkVariables, + checkMINTp0: checkMINTp0, + setMinter: setMinter, + mint: mint, + burn: burn, + mintRaw: mintRaw, + blacklist: blacklist, + unBlacklist: unBlacklist, + setLongDecimalFeesTransferWithFees: setLongDecimalFeesTransferWithFees, + sampleTransfer: sampleTransfer, + transferFromWithFees: transferFromWithFees, + sampleTransferFrom: sampleTransferFrom, + approve: approve, + redeem: redeem, + validateTransferEvent: validateTransferEvent, + initializeTokenWithProxy: initializeTokenWithProxy, + customInitializeTokenWithProxy: customInitializeTokenWithProxy, + upgradeTo: upgradeTo, + expectRevert: expectRevert, + expectJump: expectJump, + expectError: expectError, + encodeCall: encodeCall, + getInitializedV1: getInitializedV1, + getAdmin: getAdmin, + maxAmount: maxAmount, + fiatTokenEmptyState, }; diff --git a/test/assert/ABITests.test.js b/test/assert/ABITests.test.js index f6eedda3e..1d16ab7bb 100644 --- a/test/assert/ABITests.test.js +++ b/test/assert/ABITests.test.js @@ -1,10 +1,10 @@ -var Tx = require('ethereumjs-tx'); -var tokenUtils = require('./../TokenTestUtils.js'); +var Tx = require("ethereumjs-tx"); +var tokenUtils = require("./../TokenTestUtils.js"); var FiatToken = tokenUtils.FiatToken; var name = tokenUtils.name; var symbol = tokenUtils.symbol; var currency = tokenUtils.currency; -var decimals = tokenUtils.decimals +var decimals = tokenUtils.decimals; var bigZero = tokenUtils.bigZero; var bigHundred = tokenUtils.bigHundred; var mint = tokenUtils.mint; @@ -16,11 +16,11 @@ var checkVariables = tokenUtils.checkVariables; var checkFailureIsExpected = tokenUtils.checkFailureIsExpected; var initializeTokenWithProxy = tokenUtils.initializeTokenWithProxy; -var AccountUtils = require('./../AccountUtils.js'); +var AccountUtils = require("./../AccountUtils.js"); var Accounts = AccountUtils.Accounts; var AccountPrivateKeys = AccountUtils.AccountPrivateKeys; -var abiUtils = require('./../ABIUtils.js'); +var abiUtils = require("./../ABIUtils.js"); var makeRawTransaction = abiUtils.makeRawTransaction; var sendRawTransaction = abiUtils.sendRawTransaction; var functionSignature = abiUtils.functionSignature; @@ -34,189 +34,217 @@ var msgData3 = abiUtils.msgData3; // Encodes methodName, 32 byte string of 0, and address. function mockStringAddressEncode(methodName, address) { - var version = encodeUint(32) + encodeUint(0); // encode 32 byte string of 0's - return functionSignature(methodName) + version + encodeAddress(address); + var version = encodeUint(32) + encodeUint(0); // encode 32 byte string of 0's + return functionSignature(methodName) + version + encodeAddress(address); } async function run_tests(newToken, accounts) { - - beforeEach(async function checkBefore() { - rawToken = await newToken(); - var tokenConfig = await initializeTokenWithProxy(rawToken); - proxy = tokenConfig.proxy; - token = tokenConfig.token; - assert.equal(proxy.address, token.address); - }); - - // sanity check for pausable - it('abi004 FiatToken pause() is public', async function () { - let badData = functionSignature('pause()'); - let raw = await makeRawTransaction( - badData, - Accounts.pauserAccount, - AccountPrivateKeys.pauserPrivateKey, - token.address); - await sendRawTransaction(raw); - var customVars = [ - { 'variable': 'paused', 'expectedValue': true } - ]; - await checkVariables([token], [customVars]); - }); - - it('abi040 Blacklistable constructor is not a function', async function () { - let badData = functionSignature('Blacklistable()'); - let raw = await makeRawTransaction( - badData, - Accounts.pauserAccount, - AccountPrivateKeys.pauserPrivateKey, - token.address); - await expectRevert(sendRawTransaction(raw)); - }); - - it('abi042 Ownable constructor is not a function', async function () { - let badData = functionSignature('Ownable()'); - let raw = await makeRawTransaction( - badData, - Accounts.pauserAccount, - AccountPrivateKeys.pauserPrivateKey, - token.address); - await expectRevert(sendRawTransaction(raw)); - }); - - it('abi005 Pausable constructor is not a function', async function () { - let badData = functionSignature('Pausable()'); - let raw = await makeRawTransaction( - badData, - Accounts.pauserAccount, - AccountPrivateKeys.pauserPrivateKey, - token.address); - await expectRevert(sendRawTransaction(raw)); - }); - - it('abi043 FiatTokenProxy constructor is not a function', async function () { - let badData = functionSignature('FiatTokenProxy()'); - let raw = await makeRawTransaction( - badData, - Accounts.pauserAccount, - AccountPrivateKeys.pauserPrivateKey, - token.address); - await expectRevert(sendRawTransaction(raw)); - }); - - it('abi027 UpgradeabilityProxy constructor', async function () { - let badData = msgData('UpgradeabilityProxy(address)', Accounts.arbitraryAccount); - let raw = await makeRawTransaction( - badData, - Accounts.arbitraryAccount, - AccountPrivateKeys.arbitraryPrivateKey, - token.address); - await expectRevert(sendRawTransaction(raw)); - }); - - it('abi055 Proxy constructor is not a function', async function () { - let badData = functionSignature('Proxy()'); - let raw = await makeRawTransaction( - badData, - Accounts.arbitraryAccount, - AccountPrivateKeys.arbitraryPrivateKey, - token.address); - await expectRevert(sendRawTransaction(raw)); - }); - - it('abi056 Proxy _delegate is internal', async function () { - let badData = msgData('_delegate(address)', Accounts.arbitraryAccount); - let raw = await makeRawTransaction( - badData, - Accounts.arbitraryAccount, - AccountPrivateKeys.arbitraryPrivateKey, - token.address); - await expectRevert(sendRawTransaction(raw)); - }); - - it('abi057 Proxy _willFallback is internal', async function () { - let badData = functionSignature('_willFallback()'); - let raw = await makeRawTransaction( - badData, - Accounts.arbitraryAccount, - AccountPrivateKeys.arbitraryPrivateKey, - token.address); - await expectRevert(sendRawTransaction(raw)); - }); - - it('abi058 Proxy _fallback is internal', async function () { - let badData = functionSignature('_fallback()'); - let raw = await makeRawTransaction( - badData, - Accounts.arbitraryAccount, - AccountPrivateKeys.arbitraryPrivateKey, - token.address); - await expectRevert(sendRawTransaction(raw)); - }); - - it('abi050 Upgradeability implementation is internal', async function () { - let badData = msgData('UpgradeabilityProxy(address)', Accounts.arbitraryAccount); - let raw = await makeRawTransaction( - badData, - Accounts.arbitraryAccount, - AccountPrivateKeys.arbitraryPrivateKey, - token.address); - await expectRevert(sendRawTransaction(raw)); - }); - - it('abi051 AdminUpgradeabillityProxy constructor is not a function', async function () { - let badData = msgData('AdminUpgradeabillityProxy(address)', Accounts.arbitraryAccount); - let raw = await makeRawTransaction( - badData, - Accounts.arbitraryAccount, - AccountPrivateKeys.arbitraryPrivateKey, - token.address); - await expectRevert(sendRawTransaction(raw)); - }); - - it('abi053 AdminUpgradeabillityProxy _setAdmin is internal', async function () { - let badData = msgData('AdminUpgradeabillityProxy(address)', Accounts.arbitraryAccount); - let raw = await makeRawTransaction( - badData, - Accounts.arbitraryAccount, - AccountPrivateKeys.arbitraryPrivateKey, - token.address); - await expectRevert(sendRawTransaction(raw)); - }); - - it('abi041 FiatToken constructor is not a function', async function () { - let badData = functionSignature('FiatToken()'); - let raw = await makeRawTransaction( - badData, - Accounts.pauserAccount, - AccountPrivateKeys.pauserPrivateKey, - token.address); - await expectRevert(sendRawTransaction(raw)); - }); - - it('abi025 setOwner is internal', async function () { - let badData = msgData('setOwner(address)', Accounts.pauserAccount); - let raw = await makeRawTransaction( - badData, - Accounts.pauserAccount, - AccountPrivateKeys.pauserPrivateKey, - token.address); - await expectRevert(sendRawTransaction(raw)); - }); - - it('abi028 UpgradeabilityProxy._upgradeTo is internal', async function () { - let badData = mockStringAddressEncode('_upgradeTo(string,address)', Accounts.pauserAccount); - let raw = await makeRawTransaction( - badData, - Accounts.tokenOwnerAccount, - AccountPrivateKeys.tokenOwnerPrivateKey, - token.address); - await expectRevert(sendRawTransaction(raw)); - }); + beforeEach(async function checkBefore() { + rawToken = await newToken(); + var tokenConfig = await initializeTokenWithProxy(rawToken); + proxy = tokenConfig.proxy; + token = tokenConfig.token; + assert.equal(proxy.address, token.address); + }); + + // sanity check for pausable + it("abi004 FiatToken pause() is public", async function () { + let badData = functionSignature("pause()"); + let raw = await makeRawTransaction( + badData, + Accounts.pauserAccount, + AccountPrivateKeys.pauserPrivateKey, + token.address + ); + await sendRawTransaction(raw); + var customVars = [{ variable: "paused", expectedValue: true }]; + await checkVariables([token], [customVars]); + }); + + it("abi040 Blacklistable constructor is not a function", async function () { + let badData = functionSignature("Blacklistable()"); + let raw = await makeRawTransaction( + badData, + Accounts.pauserAccount, + AccountPrivateKeys.pauserPrivateKey, + token.address + ); + await expectRevert(sendRawTransaction(raw)); + }); + + it("abi042 Ownable constructor is not a function", async function () { + let badData = functionSignature("Ownable()"); + let raw = await makeRawTransaction( + badData, + Accounts.pauserAccount, + AccountPrivateKeys.pauserPrivateKey, + token.address + ); + await expectRevert(sendRawTransaction(raw)); + }); + + it("abi005 Pausable constructor is not a function", async function () { + let badData = functionSignature("Pausable()"); + let raw = await makeRawTransaction( + badData, + Accounts.pauserAccount, + AccountPrivateKeys.pauserPrivateKey, + token.address + ); + await expectRevert(sendRawTransaction(raw)); + }); + + it("abi043 FiatTokenProxy constructor is not a function", async function () { + let badData = functionSignature("FiatTokenProxy()"); + let raw = await makeRawTransaction( + badData, + Accounts.pauserAccount, + AccountPrivateKeys.pauserPrivateKey, + token.address + ); + await expectRevert(sendRawTransaction(raw)); + }); + + it("abi027 UpgradeabilityProxy constructor", async function () { + let badData = msgData( + "UpgradeabilityProxy(address)", + Accounts.arbitraryAccount + ); + let raw = await makeRawTransaction( + badData, + Accounts.arbitraryAccount, + AccountPrivateKeys.arbitraryPrivateKey, + token.address + ); + await expectRevert(sendRawTransaction(raw)); + }); + + it("abi055 Proxy constructor is not a function", async function () { + let badData = functionSignature("Proxy()"); + let raw = await makeRawTransaction( + badData, + Accounts.arbitraryAccount, + AccountPrivateKeys.arbitraryPrivateKey, + token.address + ); + await expectRevert(sendRawTransaction(raw)); + }); + + it("abi056 Proxy _delegate is internal", async function () { + let badData = msgData("_delegate(address)", Accounts.arbitraryAccount); + let raw = await makeRawTransaction( + badData, + Accounts.arbitraryAccount, + AccountPrivateKeys.arbitraryPrivateKey, + token.address + ); + await expectRevert(sendRawTransaction(raw)); + }); + + it("abi057 Proxy _willFallback is internal", async function () { + let badData = functionSignature("_willFallback()"); + let raw = await makeRawTransaction( + badData, + Accounts.arbitraryAccount, + AccountPrivateKeys.arbitraryPrivateKey, + token.address + ); + await expectRevert(sendRawTransaction(raw)); + }); + + it("abi058 Proxy _fallback is internal", async function () { + let badData = functionSignature("_fallback()"); + let raw = await makeRawTransaction( + badData, + Accounts.arbitraryAccount, + AccountPrivateKeys.arbitraryPrivateKey, + token.address + ); + await expectRevert(sendRawTransaction(raw)); + }); + + it("abi050 Upgradeability implementation is internal", async function () { + let badData = msgData( + "UpgradeabilityProxy(address)", + Accounts.arbitraryAccount + ); + let raw = await makeRawTransaction( + badData, + Accounts.arbitraryAccount, + AccountPrivateKeys.arbitraryPrivateKey, + token.address + ); + await expectRevert(sendRawTransaction(raw)); + }); + + it("abi051 AdminUpgradeabillityProxy constructor is not a function", async function () { + let badData = msgData( + "AdminUpgradeabillityProxy(address)", + Accounts.arbitraryAccount + ); + let raw = await makeRawTransaction( + badData, + Accounts.arbitraryAccount, + AccountPrivateKeys.arbitraryPrivateKey, + token.address + ); + await expectRevert(sendRawTransaction(raw)); + }); + + it("abi053 AdminUpgradeabillityProxy _setAdmin is internal", async function () { + let badData = msgData( + "AdminUpgradeabillityProxy(address)", + Accounts.arbitraryAccount + ); + let raw = await makeRawTransaction( + badData, + Accounts.arbitraryAccount, + AccountPrivateKeys.arbitraryPrivateKey, + token.address + ); + await expectRevert(sendRawTransaction(raw)); + }); + + it("abi041 FiatToken constructor is not a function", async function () { + let badData = functionSignature("FiatToken()"); + let raw = await makeRawTransaction( + badData, + Accounts.pauserAccount, + AccountPrivateKeys.pauserPrivateKey, + token.address + ); + await expectRevert(sendRawTransaction(raw)); + }); + + it("abi025 setOwner is internal", async function () { + let badData = msgData("setOwner(address)", Accounts.pauserAccount); + let raw = await makeRawTransaction( + badData, + Accounts.pauserAccount, + AccountPrivateKeys.pauserPrivateKey, + token.address + ); + await expectRevert(sendRawTransaction(raw)); + }); + + it("abi028 UpgradeabilityProxy._upgradeTo is internal", async function () { + let badData = mockStringAddressEncode( + "_upgradeTo(string,address)", + Accounts.pauserAccount + ); + let raw = await makeRawTransaction( + badData, + Accounts.tokenOwnerAccount, + AccountPrivateKeys.tokenOwnerPrivateKey, + token.address + ); + await expectRevert(sendRawTransaction(raw)); + }); } -var testWrapper = require('./../TestWrapper'); -testWrapper.execute('FiatToken_ABIHackingTests', run_tests); +var testWrapper = require("./../TestWrapper"); +testWrapper.execute("FiatToken_ABIHackingTests", run_tests); module.exports = { - run_tests: run_tests, -} + run_tests: run_tests, +}; diff --git a/test/assert/EventsTests.js b/test/assert/EventsTests.js index 6549d0b93..e32f6709e 100644 --- a/test/assert/EventsTests.js +++ b/test/assert/EventsTests.js @@ -1,4 +1,4 @@ -var tokenUtils = require('./../TokenTestUtils.js'); +var tokenUtils = require("./../TokenTestUtils.js"); var FiatToken = tokenUtils.FiatToken; var FiatTokenProxy = tokenUtils.FiatTokenProxy; @@ -28,121 +28,208 @@ var UpgradedFiatTokenNewFields = tokenUtils.UpgradedFiatTokenNewFields; var checkPauseEvent = tokenUtils.checkPauseEvent; var checkTransferEvents = tokenUtils.checkTransferEvents; -var AccountUtils = require('./../AccountUtils.js'); +var AccountUtils = require("./../AccountUtils.js"); var Accounts = AccountUtils.Accounts; var amount = 100; async function run_tests(newToken, accounts) { - - 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('et000 should check MinterConfigured event', async function() { - let configureMinter = await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); + 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("et000 should check MinterConfigured event", async function () { + let configureMinter = await token.configureMinter( + Accounts.minterAccount, + amount, + { from: Accounts.masterMinterAccount } + ); checkMinterConfiguredEvent(configureMinter, Accounts.minterAccount, amount); }); - it('et001 should check Mint/Transfer events', async function () { - await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); - let mint = await token.mint(Accounts.arbitraryAccount, amount, {from: Accounts.minterAccount}); - checkMintEvent(mint, Accounts.arbitraryAccount, amount, Accounts.minterAccount); - }); - - it('et002 should check Burn/Transfer events', async function () { - await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); - await token.mint(Accounts.minterAccount, amount, { from: Accounts.minterAccount }); - let burn = await token.burn(amount, {from: Accounts.minterAccount}); + it("et001 should check Mint/Transfer events", async function () { + await token.configureMinter(Accounts.minterAccount, amount, { + from: Accounts.masterMinterAccount, + }); + let mint = await token.mint(Accounts.arbitraryAccount, amount, { + from: Accounts.minterAccount, + }); + checkMintEvent( + mint, + Accounts.arbitraryAccount, + amount, + Accounts.minterAccount + ); + }); + + it("et002 should check Burn/Transfer events", async function () { + await token.configureMinter(Accounts.minterAccount, amount, { + from: Accounts.masterMinterAccount, + }); + await token.mint(Accounts.minterAccount, amount, { + from: Accounts.minterAccount, + }); + let burn = await token.burn(amount, { from: Accounts.minterAccount }); checkBurnEvents(burn, amount, Accounts.minterAccount); }); - it('et003 should check MinterRemoved event', async function () { - await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); - let minterRemovedEvent = await token.removeMinter(Accounts.minterAccount, {from: Accounts.masterMinterAccount}); + it("et003 should check MinterRemoved event", async function () { + await token.configureMinter(Accounts.minterAccount, amount, { + from: Accounts.masterMinterAccount, + }); + let minterRemovedEvent = await token.removeMinter(Accounts.minterAccount, { + from: Accounts.masterMinterAccount, + }); checkMinterRemovedEvent(minterRemovedEvent, Accounts.minterAccount); }); - it('et004 should check MasterMinterChanged event', async function () { - let updateMasterMinter = await token.updateMasterMinter(Accounts.arbitraryAccount, {from: Accounts.tokenOwnerAccount}); + it("et004 should check MasterMinterChanged event", async function () { + let updateMasterMinter = await token.updateMasterMinter( + Accounts.arbitraryAccount, + { from: Accounts.tokenOwnerAccount } + ); checkUpdateMasterMinterEvent(updateMasterMinter, Accounts.arbitraryAccount); }); - it('et005 should check Blacklisted event', async function () { - let blacklist = await token.blacklist(Accounts.arbitraryAccount, { from: Accounts.blacklisterAccount }); + it("et005 should check Blacklisted event", async function () { + let blacklist = await token.blacklist(Accounts.arbitraryAccount, { + from: Accounts.blacklisterAccount, + }); checkBlacklistEvent(blacklist, Accounts.arbitraryAccount); }); - it('et006 should check UnBlacklisted event', async function () { - let unblacklist = await token.unBlacklist(Accounts.arbitraryAccount, { from: Accounts.blacklisterAccount }); - checkUnblacklistEvent(unblacklist, Accounts.arbitraryAccount); + it("et006 should check UnBlacklisted event", async function () { + let unblacklist = await token.unBlacklist(Accounts.arbitraryAccount, { + from: Accounts.blacklisterAccount, + }); + checkUnblacklistEvent(unblacklist, Accounts.arbitraryAccount); }); - it('et007 should check BlacklisterChanged event', async function () { - let blacklisterChanged = await token.updateBlacklister(Accounts.arbitraryAccount, {from: Accounts.tokenOwnerAccount}); + it("et007 should check BlacklisterChanged event", async function () { + let blacklisterChanged = await token.updateBlacklister( + Accounts.arbitraryAccount, + { from: Accounts.tokenOwnerAccount } + ); checkBlacklisterChangedEvent(blacklisterChanged, Accounts.arbitraryAccount); }); - it('et008 should check Upgraded event', async function () { + it("et008 should check Upgraded event", async function () { var upgradedToken = await UpgradedFiatTokenNewFields.new(); - const initializeData = encodeCall('initV2', ['bool', 'address', 'uint256'], [true, Accounts.pauserAccount, 12]); - let upgrade = await proxy.upgradeToAndCall(upgradedToken.address, initializeData, { from: Accounts.proxyOwnerAccount }); + const initializeData = encodeCall( + "initV2", + ["bool", "address", "uint256"], + [true, Accounts.pauserAccount, 12] + ); + let upgrade = await proxy.upgradeToAndCall( + upgradedToken.address, + initializeData, + { from: Accounts.proxyOwnerAccount } + ); checkUpgradeEvent(upgrade, upgradedToken.address); }); - it('et009 should check AdminChanged event', async function () { - let adminChanged = await proxy.changeAdmin(Accounts.arbitraryAccount, {from: Accounts.proxyOwnerAccount}); - checkAdminChangedEvent(adminChanged, Accounts.proxyOwnerAccount, Accounts.arbitraryAccount); - }); - - it('et010 should check OwnershipTransferred event', async function () { - let transferOwnership = await token.transferOwnership(Accounts.arbitraryAccount, {from: Accounts.tokenOwnerAccount}); - checkTransferOwnershipEvent(transferOwnership, Accounts.tokenOwnerAccount, Accounts.arbitraryAccount); - }); - - it('et011 should check Approval event', async function () { - let approval = await token.approve(Accounts.arbitraryAccount2, amount, {from: Accounts.arbitraryAccount}); - checkApprovalEvent(approval, Accounts.arbitraryAccount, Accounts.arbitraryAccount2, amount); - }); - - it('et012 should check Pause event', async function () { - let pause = await token.pause({from: Accounts.pauserAccount}); + it("et009 should check AdminChanged event", async function () { + let adminChanged = await proxy.changeAdmin(Accounts.arbitraryAccount, { + from: Accounts.proxyOwnerAccount, + }); + checkAdminChangedEvent( + adminChanged, + Accounts.proxyOwnerAccount, + Accounts.arbitraryAccount + ); + }); + + it("et010 should check OwnershipTransferred event", async function () { + let transferOwnership = await token.transferOwnership( + Accounts.arbitraryAccount, + { from: Accounts.tokenOwnerAccount } + ); + checkTransferOwnershipEvent( + transferOwnership, + Accounts.tokenOwnerAccount, + Accounts.arbitraryAccount + ); + }); + + it("et011 should check Approval event", async function () { + let approval = await token.approve(Accounts.arbitraryAccount2, amount, { + from: Accounts.arbitraryAccount, + }); + checkApprovalEvent( + approval, + Accounts.arbitraryAccount, + Accounts.arbitraryAccount2, + amount + ); + }); + + it("et012 should check Pause event", async function () { + let pause = await token.pause({ from: Accounts.pauserAccount }); checkPauseEvent(pause); }); - it('et013 should check Unpause event', async function () { - let unpause = await token.unpause({from: Accounts.pauserAccount}); + it("et013 should check Unpause event", async function () { + let unpause = await token.unpause({ from: Accounts.pauserAccount }); checkUnpauseEvent(unpause); }); - it('et014 should check PauserChanged event', async function () { - let updatePauser = await token.updatePauser(Accounts.arbitraryAccount, {from: Accounts.tokenOwnerAccount}); + it("et014 should check PauserChanged event", async function () { + let updatePauser = await token.updatePauser(Accounts.arbitraryAccount, { + from: Accounts.tokenOwnerAccount, + }); checkPauserChangedEvent(updatePauser, Accounts.arbitraryAccount); }); - it('et015 should check Transfer event', async function () { - await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); - await token.mint(Accounts.arbitraryAccount, amount, {from: Accounts.minterAccount}); - let transfer = await token.transfer(Accounts.arbitraryAccount2, amount, {from: Accounts.arbitraryAccount}); - checkTransferEvents(transfer, Accounts.arbitraryAccount, Accounts.arbitraryAccount2, amount); - }); - - it('et016 should check Transfer event in transferFrom', async function () { - await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); - await token.mint(Accounts.arbitraryAccount, amount, {from: Accounts.minterAccount}); - await token.approve(Accounts.arbitraryAccount2, amount, {from: Accounts.arbitraryAccount}); - let transferFrom = await token.transferFrom(Accounts.arbitraryAccount, Accounts.blacklisterAccount, amount, {from: Accounts.arbitraryAccount2}); - checkTransferEvents(transferFrom, Accounts.arbitraryAccount, Accounts.blacklisterAccount, amount); + it("et015 should check Transfer event", async function () { + await token.configureMinter(Accounts.minterAccount, amount, { + from: Accounts.masterMinterAccount, + }); + await token.mint(Accounts.arbitraryAccount, amount, { + from: Accounts.minterAccount, + }); + let transfer = await token.transfer(Accounts.arbitraryAccount2, amount, { + from: Accounts.arbitraryAccount, + }); + checkTransferEvents( + transfer, + Accounts.arbitraryAccount, + Accounts.arbitraryAccount2, + amount + ); + }); + + it("et016 should check Transfer event in transferFrom", async function () { + await token.configureMinter(Accounts.minterAccount, amount, { + from: Accounts.masterMinterAccount, + }); + await token.mint(Accounts.arbitraryAccount, amount, { + from: Accounts.minterAccount, + }); + await token.approve(Accounts.arbitraryAccount2, amount, { + from: Accounts.arbitraryAccount, + }); + let transferFrom = await token.transferFrom( + Accounts.arbitraryAccount, + Accounts.blacklisterAccount, + amount, + { from: Accounts.arbitraryAccount2 } + ); + checkTransferEvents( + transferFrom, + Accounts.arbitraryAccount, + Accounts.blacklisterAccount, + amount + ); }); } -var testWrapper = require('./../TestWrapper'); -testWrapper.execute('FiatToken_EventTests', run_tests); +var testWrapper = require("./../TestWrapper"); +testWrapper.execute("FiatToken_EventTests", run_tests); module.exports = { run_tests: run_tests, -} +}; diff --git a/test/assert/FiatTokenLegacy.test.js b/test/assert/FiatTokenLegacy.test.js index 1309ae88f..65949570c 100644 --- a/test/assert/FiatTokenLegacy.test.js +++ b/test/assert/FiatTokenLegacy.test.js @@ -1,8 +1,8 @@ -var tokenUtils = require('./../TokenTestUtils.js'); +var tokenUtils = require("./../TokenTestUtils.js"); var name = tokenUtils.name; var symbol = tokenUtils.symbol; var currency = tokenUtils.currency; -var decimals = tokenUtils.decimals +var decimals = tokenUtils.decimals; var bigZero = tokenUtils.bigZero; var bigHundred = tokenUtils.bigHundred; var zeroAddress = tokenUtils.zeroAddress; @@ -23,21 +23,20 @@ var FiatToken = tokenUtils.FiatToken; var getAdmin = tokenUtils.getAdmin; var newBigNumber = tokenUtils.newBigNumber; -var AccountUtils = require('./../AccountUtils.js'); +var AccountUtils = require("./../AccountUtils.js"); var Accounts = AccountUtils.Accounts; var addressEquals = AccountUtils.addressEquals; // these tests are for reference and do not track side effects on all variables async function run_tests(newToken, accounts) { - beforeEach(async function () { - rawToken = await FiatToken.new(); + rawToken = await FiatToken.new(); var tokenConfig = await initializeTokenWithProxy(rawToken); proxy = tokenConfig.proxy; token = tokenConfig.token; assert.equal(proxy.address, token.address); }); -/* + /* it('should start with a totalSupply of 0', async function () { let totalSupply = await token.totalSupply(); assert.isTrue(totalSupply.isZero()); @@ -181,37 +180,39 @@ async function run_tests(newToken, accounts) { assert.equal(balance3, 0); }); */ - it('should fail on invalid approved transfer amount and not change balances', async function () { + it("should fail on invalid approved transfer amount and not change balances", async function () { let allowed = await token.allowance.call(accounts[0], accounts[3]); - assert.isTrue(allowed.cmp(newBigNumber(0))==0); + assert.isTrue(allowed.cmp(newBigNumber(0)) == 0); await mint(token, accounts[0], 500, Accounts.minterAccount); await token.approve(accounts[3], 100); allowed = await token.allowance.call(accounts[0], accounts[3]); - assert.isTrue(allowed.cmp(newBigNumber(100))==0); + assert.isTrue(allowed.cmp(newBigNumber(100)) == 0); - await expectRevert(token.transferFrom(accounts[0], accounts[3], 450, { from: accounts[3] })); + await expectRevert( + token.transferFrom(accounts[0], accounts[3], 450, { from: accounts[3] }) + ); let balance0 = await token.balanceOf(accounts[0]); assert.equal(balance0, 500); let balance3 = await token.balanceOf(accounts[3]); assert.equal(balance3, 0); - }); - it('should fail on invalid transfer recipient (zero-account) and not change balances', async function () { - + it("should fail on invalid transfer recipient (zero-account) and not change balances", async function () { await mint(token, accounts[0], 500, Accounts.minterAccount); await token.approve(accounts[3], 100); let allowed = await token.allowance.call(accounts[0], accounts[3]); - assert.isTrue(allowed.cmp(newBigNumber(100))==0); + assert.isTrue(allowed.cmp(newBigNumber(100)) == 0); - await expectRevert(token.transferFrom(accounts[0], zeroAddress, 50, { from: accounts[3] })); + await expectRevert( + token.transferFrom(accounts[0], zeroAddress, 50, { from: accounts[3] }) + ); let balance0 = await token.balanceOf(accounts[0]); assert.equal(balance0, 500); }); - it('should test consistency of transfer(x) and approve(x) + transferFrom(x)', async function () { + it("should test consistency of transfer(x) and approve(x) + transferFrom(x)", async function () { let allowed = await token.allowance.call(accounts[0], accounts[3]); assert.isTrue(allowed.isZero()); let transferAmount = 650; @@ -232,9 +233,14 @@ async function run_tests(newToken, accounts) { await token.approve(accounts[4], transferAmount, { from: accounts[1] }); allowed = await token.allowance.call(accounts[1], accounts[4]); - assert.isTrue(allowed.cmp(newBigNumber(transferAmount))==0); + assert.isTrue(allowed.cmp(newBigNumber(transferAmount)) == 0); - transfer = await token.transferFrom(accounts[1], accounts[4], transferAmount, { from: accounts[4] }); + transfer = await token.transferFrom( + accounts[1], + accounts[4], + transferAmount, + { from: accounts[4] } + ); checkTransferEvents(transfer, accounts[1], accounts[4], transferAmount); @@ -244,38 +250,64 @@ async function run_tests(newToken, accounts) { assert.equal(balance3, transferAmount); }); - it('should pause and should not be able to transfer', async function () { + it("should pause and should not be able to transfer", async function () { await mint(token, accounts[2], 1900, Accounts.minterAccount); assert.equal(await token.paused.call(), false); await token.pause({ from: Accounts.pauserAccount }); assert.equal(await token.paused.call(), true); - await expectRevert(sampleTransferFrom(token, Accounts.deployerAccount, Accounts.arbitraryAccount2, Accounts.minterAccount)); + await expectRevert( + sampleTransferFrom( + token, + Accounts.deployerAccount, + Accounts.arbitraryAccount2, + Accounts.minterAccount + ) + ); }); - it('should pause and should not be able to transfer, then unpause and be able to transfer', async function () { + it("should pause and should not be able to transfer, then unpause and be able to transfer", async function () { await mint(token, accounts[2], 1900, Accounts.minterAccount); assert.equal(await token.paused.call(), false); await token.pause({ from: Accounts.pauserAccount }); assert.equal(await token.paused.call(), true); - await expectRevert(sampleTransferFrom(token, Accounts.deployerAccount, Accounts.arbitraryAccount2, Accounts.minterAccount)); + await expectRevert( + sampleTransferFrom( + token, + Accounts.deployerAccount, + Accounts.arbitraryAccount2, + Accounts.minterAccount + ) + ); await token.unpause({ from: Accounts.pauserAccount }); assert.equal(await token.paused.call(), false); - await sampleTransferFrom(token, Accounts.deployerAccount, Accounts.arbitraryAccount2, Accounts.minterAccount); + await sampleTransferFrom( + token, + Accounts.deployerAccount, + Accounts.arbitraryAccount2, + Accounts.minterAccount + ); }); - it('should pause and should not be able to transferFrom', async function () { + it("should pause and should not be able to transferFrom", async function () { await mint(token, accounts[2], 1900, Accounts.minterAccount); assert.equal(await token.paused.call(), false); await token.pause({ from: Accounts.pauserAccount }); assert.equal(await token.paused.call(), true); - await expectRevert(sampleTransfer(token, Accounts.deployerAccount, Accounts.arbitraryAccount2, Accounts.minterAccount)); + await expectRevert( + sampleTransfer( + token, + Accounts.deployerAccount, + Accounts.arbitraryAccount2, + Accounts.minterAccount + ) + ); }); - it('should pause and should not be able to approve', async function () { + it("should pause and should not be able to approve", async function () { await mint(token, accounts[2], 1900, Accounts.minterAccount); assert.equal(await token.paused.call(), false); await token.pause({ from: Accounts.pauserAccount }); @@ -284,7 +316,7 @@ async function run_tests(newToken, accounts) { await expectRevert(approve(token, accounts[2], 50, accounts[3])); }); - it('should pause and should not be able to mint', async function () { + it("should pause and should not be able to mint", async function () { await mint(token, accounts[2], 1900, Accounts.minterAccount); assert.equal(await token.paused.call(), false); await token.pause({ from: Accounts.pauserAccount }); @@ -293,7 +325,7 @@ async function run_tests(newToken, accounts) { await expectRevert(mint(token, accounts[2], 1900, Accounts.minterAccount)); }); - it('should try to pause with non-pauser and fail to pause', async function () { + it("should try to pause with non-pauser and fail to pause", async function () { await mint(token, accounts[2], 1900, Accounts.minterAccount); assert.equal(await token.paused.call(), false); @@ -302,7 +334,7 @@ async function run_tests(newToken, accounts) { assert.equal(await token.paused.call(), false); }); - it('should try to pause with non-pauser and fail to pause', async function () { + it("should try to pause with non-pauser and fail to pause", async function () { await mint(token, accounts[2], 1900, Accounts.minterAccount); assert.equal(await token.paused.call(), false); @@ -311,17 +343,19 @@ async function run_tests(newToken, accounts) { assert.equal(await token.paused.call(), false); }); - it('should approve and fail to transfer more than balance', async function () { + it("should approve and fail to transfer more than balance", async function () { await mint(token, accounts[2], 100, Accounts.minterAccount); await token.approve(accounts[1], 600, { from: accounts[2] }); - await expectRevert(token.transferFrom(accounts[2], accounts[1], 600, { from: accounts[1] })); + await expectRevert( + token.transferFrom(accounts[2], accounts[1], 600, { from: accounts[1] }) + ); let balance = await token.balanceOf(accounts[2]); - assert.isTrue(balance.cmp(newBigNumber(100))==0); + assert.isTrue(balance.cmp(newBigNumber(100)) == 0); }); - it('should blacklist and make transfer impossible', async function () { + it("should blacklist and make transfer impossible", async function () { await mint(token, accounts[2], 1900, Accounts.minterAccount); await blacklist(token, accounts[2]); @@ -331,7 +365,7 @@ async function run_tests(newToken, accounts) { assert.equal(balance, 1900); }); - it('should blacklist recipient and make transfer to recipient impossible', async function () { + it("should blacklist recipient and make transfer to recipient impossible", async function () { await mint(token, accounts[2], 1900, Accounts.minterAccount); await mint(token, accounts[9], 1600, Accounts.minterAccount); await blacklist(token, accounts[2]); @@ -339,51 +373,57 @@ async function run_tests(newToken, accounts) { await expectRevert(token.transfer(accounts[2], 600, { from: accounts[9] })); let balance = await token.balanceOf(accounts[2]); - assert.isTrue(balance.cmp(newBigNumber(1900))==0); + assert.isTrue(balance.cmp(newBigNumber(1900)) == 0); balance = await token.balanceOf(accounts[9]); - assert.isTrue(balance.cmp(newBigNumber(1600))==0); + assert.isTrue(balance.cmp(newBigNumber(1600)) == 0); }); - it('should blacklist and make transferFrom impossible with the approved transferer', async function () { - let isBlacklistedBefore = await token.isBlacklisted(accounts[2]) + it("should blacklist and make transferFrom impossible with the approved transferer", async function () { + let isBlacklistedBefore = await token.isBlacklisted(accounts[2]); assert.equal(isBlacklistedBefore, false); await mint(token, accounts[2], 1900, Accounts.minterAccount); await token.approve(accounts[1], 600, { from: accounts[2] }); await blacklist(token, accounts[2]); - await expectRevert(token.transferFrom(accounts[2], accounts[3], 600, { from: accounts[1] })); + await expectRevert( + token.transferFrom(accounts[2], accounts[3], 600, { from: accounts[1] }) + ); let balance = await token.balanceOf(accounts[2]); - assert.isTrue(balance.cmp(newBigNumber(1900))==0); + assert.isTrue(balance.cmp(newBigNumber(1900)) == 0); let isBlacklistedAfter = await token.isBlacklisted(accounts[2]); assert.equal(isBlacklistedAfter, true); }); - it('should make transferFrom impossible with the approved and blacklisted transferer', async function () { + it("should make transferFrom impossible with the approved and blacklisted transferer", async function () { await mint(token, accounts[2], 1900, Accounts.minterAccount); await token.approve(accounts[1], 600, { from: accounts[2] }); await blacklist(token, accounts[1]); - await expectRevert(token.transferFrom(accounts[2], accounts[3], 600, { from: accounts[1] })); + await expectRevert( + token.transferFrom(accounts[2], accounts[3], 600, { from: accounts[1] }) + ); let balance = await token.balanceOf(accounts[2]); - assert.isTrue(balance.cmp(newBigNumber(1900))==0); + assert.isTrue(balance.cmp(newBigNumber(1900)) == 0); }); - it('should blacklist recipient and make transfer to recipient using transferFrom impossible', async function () { + it("should blacklist recipient and make transfer to recipient using transferFrom impossible", async function () { await mint(token, accounts[2], 1900, Accounts.minterAccount); await token.approve(accounts[3], 600, { from: accounts[2] }); await blacklist(token, accounts[3]); - await expectRevert(token.transferFrom(accounts[2], accounts[3], 600, { from: accounts[2] })); + await expectRevert( + token.transferFrom(accounts[2], accounts[3], 600, { from: accounts[2] }) + ); let balance = await token.balanceOf(accounts[2]); - assert.isTrue(balance.cmp(newBigNumber(1900))==0); + assert.isTrue(balance.cmp(newBigNumber(1900)) == 0); }); - it('should blacklist and make approve impossible', async function () { + it("should blacklist and make approve impossible", async function () { await mint(token, accounts[1], 1900, Accounts.minterAccount); await blacklist(token, accounts[1]); @@ -392,7 +432,7 @@ async function run_tests(newToken, accounts) { assert.isTrue(approval.isZero()); }); - it('should make giving approval to blacklisted account impossible', async function () { + it("should make giving approval to blacklisted account impossible", async function () { await mint(token, accounts[2], 1900, Accounts.minterAccount); await blacklist(token, accounts[1]); @@ -402,30 +442,32 @@ async function run_tests(newToken, accounts) { assert.isTrue(approval.isZero()); }); - it('should blacklist then unblacklist to make a transfer possible', async function () { + it("should blacklist then unblacklist to make a transfer possible", async function () { await mint(token, accounts[2], 1900, Accounts.minterAccount); await blacklist(token, accounts[2]); await unBlacklist(token, accounts[2]); await token.transfer(accounts[3], 600, { from: accounts[2] }); let balance = await token.balanceOf(accounts[2]); - assert.isTrue(balance.cmp(newBigNumber(1300))==0); + assert.isTrue(balance.cmp(newBigNumber(1300)) == 0); balance = await token.balanceOf(accounts[3]); - assert.isTrue(balance.cmp(newBigNumber(600))==0); + assert.isTrue(balance.cmp(newBigNumber(600)) == 0); }); - it('should fail to blacklist with non-blacklister account', async function () { + it("should fail to blacklist with non-blacklister account", async function () { await mint(token, accounts[2], 1900, Accounts.minterAccount); - await expectRevert(token.blacklist(accounts[2], { from: Accounts.pauserAccount })); + await expectRevert( + token.blacklist(accounts[2], { from: Accounts.pauserAccount }) + ); await token.transfer(accounts[3], 600, { from: accounts[2] }); let balance = await token.balanceOf(accounts[2]); - assert.isTrue(balance.cmp(newBigNumber(1300))==0); + assert.isTrue(balance.cmp(newBigNumber(1300)) == 0); balance = await token.balanceOf(accounts[3]); - assert.isTrue(balance.cmp(newBigNumber(600))==0); + assert.isTrue(balance.cmp(newBigNumber(600)) == 0); }); - it('should unblacklist when paused', async function () { + it("should unblacklist when paused", async function () { await mint(token, accounts[2], 1900, Accounts.minterAccount); await token.blacklist(accounts[2], { from: Accounts.blacklisterAccount }); let blacklisted = await token.isBlacklisted(accounts[2]); @@ -439,17 +481,25 @@ async function run_tests(newToken, accounts) { assert.isFalse(blacklisted); let balance = await token.balanceOf(accounts[2]); - assert.isTrue(balance.cmp(newBigNumber(1900))==0); - }); - - it('should change the minter and mint as well as fail to mint with the old minter', async function () { - let update = await token.removeMinter(Accounts.minterAccount, { from: Accounts.masterMinterAccount }); - assert.equal(update.logs[0].event, 'MinterRemoved'); - assert.isTrue(addressEquals(update.logs[0].args.oldMinter, Accounts.minterAccount)); - update = await setMinter(token, accounts[3], 10000, { from: Accounts.masterMinterAccount }); + assert.isTrue(balance.cmp(newBigNumber(1900)) == 0); + }); + + it("should change the minter and mint as well as fail to mint with the old minter", async function () { + let update = await token.removeMinter(Accounts.minterAccount, { + from: Accounts.masterMinterAccount, + }); + assert.equal(update.logs[0].event, "MinterRemoved"); + assert.isTrue( + addressEquals(update.logs[0].args.oldMinter, Accounts.minterAccount) + ); + update = await setMinter(token, accounts[3], 10000, { + from: Accounts.masterMinterAccount, + }); await token.mint(accounts[1], 100, { from: accounts[3] }); - await expectRevert(token.mint(accounts[1], 200, { from: Accounts.minterAccount })); + await expectRevert( + token.mint(accounts[1], 200, { from: Accounts.minterAccount }) + ); let isMinter = await token.isMinter(Accounts.minterAccount); assert.equal(isMinter, false); @@ -457,60 +507,72 @@ async function run_tests(newToken, accounts) { assert.equal(balance, 100); }); - it('should remove a minter even if the contract is paused', async function () { - await token.configureMinter(accounts[3], 200, { from: Accounts.masterMinterAccount }); + it("should remove a minter even if the contract is paused", async function () { + await token.configureMinter(accounts[3], 200, { + from: Accounts.masterMinterAccount, + }); let isAccountMinter = await token.isMinter(accounts[3]); assert.equal(isAccountMinter, true); await token.pause({ from: Accounts.pauserAccount }); - await token.removeMinter(accounts[3], { from: Accounts.masterMinterAccount }); + await token.removeMinter(accounts[3], { + from: Accounts.masterMinterAccount, + }); isAccountMinter = await token.isMinter(accounts[3]); assert.equal(isAccountMinter, false); }); - it('should pause contract even when contract is already paused', async function () { + it("should pause contract even when contract is already paused", async function () { await token.pause({ from: Accounts.pauserAccount }); await token.pause({ from: Accounts.pauserAccount }); let isPaused = await token.paused(); assert.equal(isPaused, true); }); - it('should unpause contract even when contract is already unpaused', async function () { + it("should unpause contract even when contract is already unpaused", async function () { await token.unpause({ from: Accounts.pauserAccount }); let isPaused = await token.paused(); assert.equal(isPaused, false); }); - it('should fail to updateMinterAllowance from non-masterMinter', async function () { - let minterAllowanceBefore = await token.minterAllowance(Accounts.minterAccount) + it("should fail to updateMinterAllowance from non-masterMinter", async function () { + let minterAllowanceBefore = await token.minterAllowance( + Accounts.minterAccount + ); assert.equal(minterAllowanceBefore, 0); - await expectRevert(token.configureMinter(Accounts.minterAccount, 100, { from: Accounts.tokenOwnerAccount })); + await expectRevert( + token.configureMinter(Accounts.minterAccount, 100, { + from: Accounts.tokenOwnerAccount, + }) + ); - let minterAllowanceAfter = await token.minterAllowance(Accounts.minterAccount) + let minterAllowanceAfter = await token.minterAllowance( + Accounts.minterAccount + ); assert.equal(minterAllowanceAfter, 0); }); - it('should have correct name', async function () { + it("should have correct name", async function () { let actual = await token.name.call(); assert.equal(actual, name); }); - it('should have correct symbol', async function () { + it("should have correct symbol", async function () { let actual = await token.symbol.call(); assert.equal(actual, symbol); }); - it('should have correct decimals', async function () { + it("should have correct decimals", async function () { let actual = await token.decimals.call(); - assert.equal(actual.toString(16,32), decimals.toString(16,32)); + assert.equal(actual.toString(16, 32), decimals.toString(16, 32)); }); - it('should have correct currency', async function () { + it("should have correct currency", async function () { let actual = await token.currency.call(); assert.equal(actual, currency); }); - it('should mint and burn tokens', async function () { + it("should mint and burn tokens", async function () { let burnerAddress = accounts[3]; let amount = 500; await setMinter(token, burnerAddress, amount); @@ -523,27 +585,33 @@ async function run_tests(newToken, accounts) { await mint(token, burnerAddress, amount, Accounts.minterAccount); let totalSupply1 = await token.totalSupply(); let minterBalance1 = await token.balanceOf(burnerAddress); - assert.isTrue(totalSupply1.cmp(totalSupply.add(newBigNumber(amount)))==0); - assert.isTrue(minterBalance1.cmp(minterBalance.add(newBigNumber(amount)))==0); + assert.isTrue(totalSupply1.cmp(totalSupply.add(newBigNumber(amount))) == 0); + assert.isTrue( + minterBalance1.cmp(minterBalance.add(newBigNumber(amount))) == 0 + ); // burn tokens await burn(token, amount, burnerAddress); let totalSupply2 = await token.totalSupply(); - assert.isTrue(totalSupply2.cmp(totalSupply1.sub(newBigNumber(amount)))==0); + assert.isTrue( + totalSupply2.cmp(totalSupply1.sub(newBigNumber(amount))) == 0 + ); // check that minter's balance has been reduced let minterBalance2 = await token.balanceOf(burnerAddress); - assert.isTrue(minterBalance2.cmp(minterBalance1.sub(newBigNumber(amount)))==0); + assert.isTrue( + minterBalance2.cmp(minterBalance1.sub(newBigNumber(amount))) == 0 + ); }); - it('should try to burn tokens from a non-minter and fail', async function () { + it("should try to burn tokens from a non-minter and fail", async function () { let burnerAddress = accounts[3]; let amount = 1000; await expectRevert(token.burn(amount, { from: burnerAddress })); }); - it('should fail to burn from a blacklisted address', async function () { + it("should fail to burn from a blacklisted address", async function () { let burnerAddress = accounts[3]; await setMinter(token, burnerAddress, 200); await mint(token, burnerAddress, 200, Accounts.minterAccount); @@ -554,7 +622,7 @@ async function run_tests(newToken, accounts) { assert.equal(balance0, 200); }); - it('should try to burn more tokens than balance and fail', async function () { + it("should try to burn more tokens than balance and fail", async function () { let burnerAddress = accounts[3]; let amount = 500; await setMinter(token, burnerAddress, 250); @@ -563,10 +631,10 @@ async function run_tests(newToken, accounts) { await expectRevert(token.burn(amount, { from: burnerAddress })); }); - it('should upgrade and preserve data', async function () { + it("should upgrade and preserve data", async function () { await mint(token, accounts[2], 200, Accounts.minterAccount); let initialBalance = await token.balanceOf(accounts[2]); - assert.isTrue(initialBalance.cmp(newBigNumber(200))==0); + assert.isTrue(initialBalance.cmp(newBigNumber(200)) == 0); var newRawToken = await UpgradedFiatToken.new(); var tokenConfig = await upgradeTo(proxy, newRawToken); @@ -574,38 +642,48 @@ async function run_tests(newToken, accounts) { var newToken = newProxiedToken; let upgradedBalance = await newToken.balanceOf(accounts[2]); - assert.isTrue(upgradedBalance.cmp(newBigNumber(200))==0); - await newToken.configureMinter(Accounts.minterAccount, 500, { from: Accounts.masterMinterAccount }); + assert.isTrue(upgradedBalance.cmp(newBigNumber(200)) == 0); + await newToken.configureMinter(Accounts.minterAccount, 500, { + from: Accounts.masterMinterAccount, + }); await newToken.mint(accounts[2], 200, { from: Accounts.minterAccount }); let balance = await newToken.balanceOf(accounts[2]); - assert.isTrue(balance.cmp(newBigNumber(400))==0); + assert.isTrue(balance.cmp(newBigNumber(400)) == 0); }); - it('should updateRoleAddress for masterMinter', async function () { + it("should updateRoleAddress for masterMinter", async function () { let address1 = accounts[7]; let address2 = accounts[6]; - await token.updateMasterMinter(address1, { from: Accounts.tokenOwnerAccount }); + await token.updateMasterMinter(address1, { + from: Accounts.tokenOwnerAccount, + }); let masterMinter1 = await token.masterMinter(); assert.equal(masterMinter1, address1); - await token.updateMasterMinter(address2, { from: Accounts.tokenOwnerAccount }); + await token.updateMasterMinter(address2, { + from: Accounts.tokenOwnerAccount, + }); let masterMinter2 = await token.masterMinter(); assert.equal(masterMinter2, address2); }); - it('should updateRoleAddress for blacklister', async function () { + it("should updateRoleAddress for blacklister", async function () { let address1 = accounts[7]; let address2 = accounts[6]; - await token.updateBlacklister(address1, { from: Accounts.tokenOwnerAccount }); + await token.updateBlacklister(address1, { + from: Accounts.tokenOwnerAccount, + }); let blacklister1 = await token.blacklister(); assert.equal(blacklister1, address1); - await token.updateBlacklister(address2, { from: Accounts.tokenOwnerAccount }); + await token.updateBlacklister(address2, { + from: Accounts.tokenOwnerAccount, + }); let blacklister2 = await token.blacklister(); assert.equal(blacklister2, address2); }); - it('should updateRoleAddress for pauser', async function () { + it("should updateRoleAddress for pauser", async function () { let address1 = accounts[7]; let address2 = accounts[6]; await token.updatePauser(address1, { from: Accounts.tokenOwnerAccount }); @@ -617,45 +695,55 @@ async function run_tests(newToken, accounts) { assert.equal(pauser2, address2); }); - it('should updateUpgraderAddress for upgrader', async function () { + it("should updateUpgraderAddress for upgrader", async function () { let upgrader = await getAdmin(proxy); assert.isTrue(addressEquals(Accounts.proxyOwnerAccount, upgrader)); let address1 = accounts[10]; - let updated = await proxy.changeAdmin(address1, { from: Accounts.proxyOwnerAccount }); + let updated = await proxy.changeAdmin(address1, { + from: Accounts.proxyOwnerAccount, + }); upgrader = await getAdmin(proxy); assert.isTrue(addressEquals(upgrader, address1)); //Test upgrade with new upgrader account - await token.configureMinter(Accounts.minterAccount, 1000, {from: Accounts.masterMinterAccount}); - await token.mint(accounts[2], 200, {from: Accounts.minterAccount}); + await token.configureMinter(Accounts.minterAccount, 1000, { + from: Accounts.masterMinterAccount, + }); + await token.mint(accounts[2], 200, { from: Accounts.minterAccount }); let initialBalance = await token.balanceOf(accounts[2]); - assert.isTrue(initialBalance.cmp(newBigNumber(200))==0); - + assert.isTrue(initialBalance.cmp(newBigNumber(200)) == 0); + var newRawToken = await UpgradedFiatToken.new(); var tokenConfig = await upgradeTo(proxy, newRawToken, address1); var newProxiedToken = tokenConfig.token; var newToken = newProxiedToken; let upgradedBalance = await newToken.balanceOf(accounts[2]); - assert.isTrue(upgradedBalance.cmp(newBigNumber(200))==0); - await newToken.configureMinter(Accounts.minterAccount, 500, { from: Accounts.masterMinterAccount }); + assert.isTrue(upgradedBalance.cmp(newBigNumber(200)) == 0); + await newToken.configureMinter(Accounts.minterAccount, 500, { + from: Accounts.masterMinterAccount, + }); await newToken.mint(accounts[2], 200, { from: Accounts.minterAccount }); let balance = await newToken.balanceOf(accounts[2]); - assert.isTrue(balance.cmp(newBigNumber(400))==0); + assert.isTrue(balance.cmp(newBigNumber(400)) == 0); }); - it('should fail to updateUpgraderAddress for upgrader using non-upgrader account', async function () { + it("should fail to updateUpgraderAddress for upgrader using non-upgrader account", async function () { let address1 = accounts[7]; - await expectRevert(proxy.changeAdmin(address1, { from: Accounts.tokenOwnerAccount })); + await expectRevert( + proxy.changeAdmin(address1, { from: Accounts.tokenOwnerAccount }) + ); let upgrader = await getAdmin(proxy); assert.notEqual(upgrader, address1); }); - it('should updateRoleAddress for roleAddressChanger', async function () { + it("should updateRoleAddress for roleAddressChanger", async function () { let address1 = accounts[7]; let address2 = accounts[6]; - await token.transferOwnership(address1, { from: Accounts.tokenOwnerAccount }); + await token.transferOwnership(address1, { + from: Accounts.tokenOwnerAccount, + }); let roleAddressChanger1 = await token.owner(); assert.equal(roleAddressChanger1, address1); @@ -664,17 +752,19 @@ async function run_tests(newToken, accounts) { assert.equal(roleAddressChanger2, address2); }); - it('should fail to updateRoleAddress from a non-roleAddressChanger', async function () { + it("should fail to updateRoleAddress from a non-roleAddressChanger", async function () { let nonRoleAddressChanger = accounts[2]; let address1 = accounts[7]; - await expectRevert(token.updateMasterMinter(address1, { from: nonRoleAddressChanger })); + await expectRevert( + token.updateMasterMinter(address1, { from: nonRoleAddressChanger }) + ); }); } -var testWrapper = require('./../TestWrapper'); -testWrapper.execute('FiatToken_LegacyTests', run_tests); +var testWrapper = require("./../TestWrapper"); +testWrapper.execute("FiatToken_LegacyTests", run_tests); module.exports = { run_tests: run_tests, -} +}; diff --git a/test/assert/Pausable.test.js b/test/assert/Pausable.test.js index 64160dbc6..4c9212792 100644 --- a/test/assert/Pausable.test.js +++ b/test/assert/Pausable.test.js @@ -1,90 +1,102 @@ -var Tx = require('ethereumjs-tx'); +var Tx = require("ethereumjs-tx"); -var Pausable = artifacts.require('Pausable'); -var tokenUtils = require('./../TokenTestUtils.js'); -var BigNumber = require('bignumber.js'); +var Pausable = artifacts.require("Pausable"); +var tokenUtils = require("./../TokenTestUtils.js"); +var BigNumber = require("bignumber.js"); var expectRevert = tokenUtils.expectRevert; -var AccountUtils = require('./../AccountUtils.js'); +var AccountUtils = require("./../AccountUtils.js"); var Accounts = AccountUtils.Accounts; var addressEquals = AccountUtils.addressEquals; -const should = require('chai') - .use(require('chai-as-promised')) - .use(require('chai-bignumber')(BigNumber)) - .should(); - -contract('PausableTests', function (accounts) { - var pause; - beforeEach(async function checkBefore() { - pause = await Pausable.new(); - await pause.updatePauser(Accounts.pauserAccount); - }); - - it('constructor owner', async function () { - var actualOwner = await pause.owner.call(); - assert.isTrue(addressEquals(Accounts.deployerAccount, actualOwner), "wrong owner"); - }); - - it('constructor pauser', async function () { - var actualOwner = await pause.pauser.call(); - assert.isTrue(addressEquals(Accounts.pauserAccount, actualOwner), "wrong pauser"); - }); - - it('paused after pausing', async function () { - await checkUnPaused(); - - await pause.pause({from: Accounts.pauserAccount}); - await checkPaused(); - - // should stay paused even if we call it again - await pause.pause({from: Accounts.pauserAccount}); - await checkPaused(); - - await pause.unpause({from: Accounts.pauserAccount}); - await checkUnPaused(); - }); - - it('update pauser', async function() { - // pause from original pauser - await pause.pause({from: Accounts.pauserAccount}); - await checkPaused("should have paused from original pauser account"); - - await pause.updatePauser(Accounts.arbitraryAccount, {from: Accounts.deployerAccount}); - var newPauser = await pause.pauser.call(); - assert.isTrue(addressEquals(Accounts.arbitraryAccount, newPauser)); - // double check we're still paused - await checkPaused("should still be paused after changing pauser"); - - await pause.unpause({from: Accounts.arbitraryAccount}); - await checkUnPaused(); - - //original pauser shouldn't work anymore - await expectRevert(pause.pause({from:Accounts.pauserAccount})); - }); - - it('fail to update pauser from wrong account', async function() { - await expectRevert(pause.updatePauser(Accounts.arbitraryAccount, {from:Accounts.arbitraryAccount})); - }); - - it('fail to pause from wrong account', async function() { - await expectRevert(pause.pause({from:Accounts.arbitraryAccount})); - }); - - it('fail to unpause from wrong account', async function() { - await pause.pause({from: Accounts.pauserAccount}); - await checkPaused(); - - await expectRevert(pause.unpause({from:Accounts.arbitraryAccount})); +const should = require("chai") + .use(require("chai-as-promised")) + .use(require("chai-bignumber")(BigNumber)) + .should(); + +contract("PausableTests", function (accounts) { + var pause; + beforeEach(async function checkBefore() { + pause = await Pausable.new(); + await pause.updatePauser(Accounts.pauserAccount); + }); + + it("constructor owner", async function () { + var actualOwner = await pause.owner.call(); + assert.isTrue( + addressEquals(Accounts.deployerAccount, actualOwner), + "wrong owner" + ); + }); + + it("constructor pauser", async function () { + var actualOwner = await pause.pauser.call(); + assert.isTrue( + addressEquals(Accounts.pauserAccount, actualOwner), + "wrong pauser" + ); + }); + + it("paused after pausing", async function () { + await checkUnPaused(); + + await pause.pause({ from: Accounts.pauserAccount }); + await checkPaused(); + + // should stay paused even if we call it again + await pause.pause({ from: Accounts.pauserAccount }); + await checkPaused(); + + await pause.unpause({ from: Accounts.pauserAccount }); + await checkUnPaused(); + }); + + it("update pauser", async function () { + // pause from original pauser + await pause.pause({ from: Accounts.pauserAccount }); + await checkPaused("should have paused from original pauser account"); + + await pause.updatePauser(Accounts.arbitraryAccount, { + from: Accounts.deployerAccount, }); - - async function checkPaused(msg ) { - var paused = await pause.paused.call(); - assert.isTrue(paused, msg); - } - - async function checkUnPaused(msg) { - var paused = await pause.paused.call(); - assert.isFalse(paused, msg); - } + var newPauser = await pause.pauser.call(); + assert.isTrue(addressEquals(Accounts.arbitraryAccount, newPauser)); + // double check we're still paused + await checkPaused("should still be paused after changing pauser"); + + await pause.unpause({ from: Accounts.arbitraryAccount }); + await checkUnPaused(); + + //original pauser shouldn't work anymore + await expectRevert(pause.pause({ from: Accounts.pauserAccount })); + }); + + it("fail to update pauser from wrong account", async function () { + await expectRevert( + pause.updatePauser(Accounts.arbitraryAccount, { + from: Accounts.arbitraryAccount, + }) + ); + }); + + it("fail to pause from wrong account", async function () { + await expectRevert(pause.pause({ from: Accounts.arbitraryAccount })); + }); + + it("fail to unpause from wrong account", async function () { + await pause.pause({ from: Accounts.pauserAccount }); + await checkPaused(); + + await expectRevert(pause.unpause({ from: Accounts.arbitraryAccount })); + }); + + async function checkPaused(msg) { + var paused = await pause.paused.call(); + assert.isTrue(paused, msg); + } + + async function checkUnPaused(msg) { + var paused = await pause.paused.call(); + assert.isFalse(paused, msg); + } }); diff --git a/test/basic/NegativeTests.js b/test/basic/NegativeTests.js index 194bc99fb..1fe0a5f66 100644 --- a/test/basic/NegativeTests.js +++ b/test/basic/NegativeTests.js @@ -1,6 +1,6 @@ -var tokenUtils = require('./../TokenTestUtils.js'); +var tokenUtils = require("./../TokenTestUtils.js"); var newBigNumber = tokenUtils.newBigNumber; -var assertDiff = require('assert-diff'); +var assertDiff = require("assert-diff"); assertDiff.options.strict = true; var bigZero = tokenUtils.bigZero; @@ -19,15 +19,14 @@ var upgradeTo = tokenUtils.upgradeTo; var UpgradedFiatToken = tokenUtils.UpgradedFiatToken; var FiatToken = tokenUtils.FiatToken; -var AccountUtils = require('./../AccountUtils.js'); +var AccountUtils = require("./../AccountUtils.js"); var Accounts = AccountUtils.Accounts; var amount = 100; var zeroAddress = tokenUtils.zeroAddress; async function run_tests(newToken, accounts) { - - beforeEach('Make fresh token contract', async function () { + beforeEach("Make fresh token contract", async function () { rawToken = await newToken(); var tokenConfig = await initializeTokenWithProxy(rawToken); proxy = tokenConfig.proxy; @@ -35,556 +34,1005 @@ async function run_tests(newToken, accounts) { assert.equal(proxy.address, token.address); }); - // Mint - it('nt001 should fail to mint when paused', async function () { - await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); - await token.pause({from: Accounts.pauserAccount}); + it("nt001 should fail to mint when paused", async function () { + await token.configureMinter(Accounts.minterAccount, amount, { + from: Accounts.masterMinterAccount, + }); + await token.pause({ from: Accounts.pauserAccount }); var customVars = [ - {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount)}, - {'variable': 'paused', 'expectedValue': true} - ] - await expectRevert(token.mint(Accounts.arbitraryAccount, 50, {from: Accounts.minterAccount})); + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount), + }, + { variable: "paused", expectedValue: true }, + ]; + await expectRevert( + token.mint(Accounts.arbitraryAccount, 50, { + from: Accounts.minterAccount, + }) + ); await checkVariables([token], [customVars]); }); - it('nt002 should fail to mint when msg.sender is not a minter', async function () { + it("nt002 should fail to mint when msg.sender is not a minter", async function () { //Note: Accounts.minterAccount has not yet been configured as a minter - await expectRevert(token.mint(Accounts.arbitraryAccount, 50, {from: Accounts.minterAccount})); + await expectRevert( + token.mint(Accounts.arbitraryAccount, 50, { + from: Accounts.minterAccount, + }) + ); await checkVariables([token], [[]]); }); - it('nt003 should fail to mint when msg.sender is blacklisted', async function () { - await token.blacklist(Accounts.minterAccount, {from: Accounts.blacklisterAccount}); - await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); + it("nt003 should fail to mint when msg.sender is blacklisted", async function () { + await token.blacklist(Accounts.minterAccount, { + from: Accounts.blacklisterAccount, + }); + await token.configureMinter(Accounts.minterAccount, amount, { + from: Accounts.masterMinterAccount, + }); var customVars = [ - {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount)}, - {'variable': 'isAccountBlacklisted.minterAccount', 'expectedValue': true} - ] - await expectRevert(token.mint(Accounts.arbitraryAccount, 50, {from: Accounts.minterAccount})); + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount), + }, + { variable: "isAccountBlacklisted.minterAccount", expectedValue: true }, + ]; + await expectRevert( + token.mint(Accounts.arbitraryAccount, 50, { + from: Accounts.minterAccount, + }) + ); await checkVariables([token], [customVars]); }); - it('nt004 should fail to mint when recipient is blacklisted', async function () { - await token.blacklist(Accounts.arbitraryAccount, {from: Accounts.blacklisterAccount}); - await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); + it("nt004 should fail to mint when recipient is blacklisted", async function () { + await token.blacklist(Accounts.arbitraryAccount, { + from: Accounts.blacklisterAccount, + }); + await token.configureMinter(Accounts.minterAccount, amount, { + from: Accounts.masterMinterAccount, + }); var customVars = [ - {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount)}, - {'variable': 'isAccountBlacklisted.arbitraryAccount', 'expectedValue': true} - ] - await expectRevert(token.mint(Accounts.arbitraryAccount, 50, {from: Accounts.minterAccount})); + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount), + }, + { + variable: "isAccountBlacklisted.arbitraryAccount", + expectedValue: true, + }, + ]; + await expectRevert( + token.mint(Accounts.arbitraryAccount, 50, { + from: Accounts.minterAccount, + }) + ); await checkVariables([token], [customVars]); }); - it('nt005 should fail to mint when allowance of minter is less than amount', async function () { - await token.configureMinter(Accounts.minterAccount, amount - 1, {from: Accounts.masterMinterAccount}); + it("nt005 should fail to mint when allowance of minter is less than amount", async function () { + await token.configureMinter(Accounts.minterAccount, amount - 1, { + from: Accounts.masterMinterAccount, + }); var customVars = [ - {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - 1)} - ] - await expectRevert(token.mint(Accounts.arbitraryAccount, amount, {from: Accounts.minterAccount})); + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount - 1), + }, + ]; + await expectRevert( + token.mint(Accounts.arbitraryAccount, amount, { + from: Accounts.minterAccount, + }) + ); await checkVariables([token], [customVars]); }); - it('nt006 should fail to mint to 0x0 address', async function () { - await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); + it("nt006 should fail to mint to 0x0 address", async function () { + await token.configureMinter(Accounts.minterAccount, amount, { + from: Accounts.masterMinterAccount, + }); var customVars = [ - {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount)} - ] - await expectRevert(token.mint(zeroAddress, amount, {from: Accounts.minterAccount})); + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount), + }, + ]; + await expectRevert( + token.mint(zeroAddress, amount, { from: Accounts.minterAccount }) + ); await checkVariables([token], [customVars]); }); // Approve - it('nt008 should fail to approve when spender is blacklisted', async function () { - await token.blacklist(Accounts.minterAccount, {from: Accounts.blacklisterAccount}); + it("nt008 should fail to approve when spender is blacklisted", async function () { + await token.blacklist(Accounts.minterAccount, { + from: Accounts.blacklisterAccount, + }); var customVars = [ - {'variable': 'isAccountBlacklisted.minterAccount', 'expectedValue': true}, - ] - await expectRevert(token.approve(Accounts.minterAccount, 100, {from: Accounts.arbitraryAccount})); + { variable: "isAccountBlacklisted.minterAccount", expectedValue: true }, + ]; + await expectRevert( + token.approve(Accounts.minterAccount, 100, { + from: Accounts.arbitraryAccount, + }) + ); await checkVariables([token], [customVars]); }); - it('nt009 should fail to approve when msg.sender is blacklisted', async function () { - await token.blacklist(Accounts.arbitraryAccount, {from: Accounts.blacklisterAccount}); + it("nt009 should fail to approve when msg.sender is blacklisted", async function () { + await token.blacklist(Accounts.arbitraryAccount, { + from: Accounts.blacklisterAccount, + }); var customVars = [ - {'variable': 'isAccountBlacklisted.arbitraryAccount', 'expectedValue': true}, - ] - await expectRevert(token.approve(Accounts.minterAccount, 100, {from: Accounts.arbitraryAccount})); + { + variable: "isAccountBlacklisted.arbitraryAccount", + expectedValue: true, + }, + ]; + await expectRevert( + token.approve(Accounts.minterAccount, 100, { + from: Accounts.arbitraryAccount, + }) + ); await checkVariables([token], [customVars]); }); - it('nt010 should fail to approve when contract is paused', async function () { - await token.pause({from: Accounts.pauserAccount}); - var customVars = [ - {'variable': 'paused', 'expectedValue': true}, - ] - await expectRevert(token.approve(Accounts.minterAccount, 100, {from: Accounts.arbitraryAccount})); + it("nt010 should fail to approve when contract is paused", async function () { + await token.pause({ from: Accounts.pauserAccount }); + var customVars = [{ variable: "paused", expectedValue: true }]; + await expectRevert( + token.approve(Accounts.minterAccount, 100, { + from: Accounts.arbitraryAccount, + }) + ); await checkVariables([token], [customVars]); }); // TransferFrom - it('nt012 should fail to transferFrom to 0x0 address', async function () { - await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); + it("nt012 should fail to transferFrom to 0x0 address", async function () { + await token.configureMinter(Accounts.minterAccount, amount, { + from: Accounts.masterMinterAccount, + }); var customVars = [ - {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount)} - ] + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount), + }, + ]; await checkVariables([token], [customVars]); - await token.mint(Accounts.arbitraryAccount, 50, {from: Accounts.minterAccount}); - await token.approve(Accounts.arbitraryAccount2, 50, {from: Accounts.arbitraryAccount}); + await token.mint(Accounts.arbitraryAccount, 50, { + from: Accounts.minterAccount, + }); + await token.approve(Accounts.arbitraryAccount2, 50, { + from: Accounts.arbitraryAccount, + }); customVars = [ - {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - 50)}, - {'variable': 'balances.arbitraryAccount', 'expectedValue': newBigNumber(50)}, - {'variable': 'totalSupply', 'expectedValue': newBigNumber(50)}, - {'variable': 'allowance.arbitraryAccount.arbitraryAccount2', 'expectedValue': newBigNumber(50)} - ] - await expectRevert(token.transferFrom(Accounts.arbitraryAccount, zeroAddress, 50, {from: Accounts.arbitraryAccount2})); + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount - 50), + }, + { + variable: "balances.arbitraryAccount", + expectedValue: newBigNumber(50), + }, + { variable: "totalSupply", expectedValue: newBigNumber(50) }, + { + variable: "allowance.arbitraryAccount.arbitraryAccount2", + expectedValue: newBigNumber(50), + }, + ]; + await expectRevert( + token.transferFrom(Accounts.arbitraryAccount, zeroAddress, 50, { + from: Accounts.arbitraryAccount2, + }) + ); await checkVariables([token], [customVars]); }); - it('nt013 should fail to transferFrom an amount greater than balance', async function () { - await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); + it("nt013 should fail to transferFrom an amount greater than balance", async function () { + await token.configureMinter(Accounts.minterAccount, amount, { + from: Accounts.masterMinterAccount, + }); customVars = [ - {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount)} - ] + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount), + }, + ]; await checkVariables([token], [customVars]); - await token.mint(Accounts.arbitraryAccount, 50, {from: Accounts.minterAccount}); - await token.approve(Accounts.blacklisterAccount, amount, {from: Accounts.arbitraryAccount}); + await token.mint(Accounts.arbitraryAccount, 50, { + from: Accounts.minterAccount, + }); + await token.approve(Accounts.blacklisterAccount, amount, { + from: Accounts.arbitraryAccount, + }); customVars = [ - {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - 50)}, - {'variable': 'balances.arbitraryAccount', 'expectedValue': newBigNumber(50)}, - {'variable': 'totalSupply', 'expectedValue': newBigNumber(50)}, - {'variable': 'allowance.arbitraryAccount.blacklisterAccount', 'expectedValue': newBigNumber(amount)}, - ] - await expectRevert(token.transferFrom(Accounts.arbitraryAccount, Accounts.pauserAccount, amount, {from: Accounts.blacklisterAccount})); + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount - 50), + }, + { + variable: "balances.arbitraryAccount", + expectedValue: newBigNumber(50), + }, + { variable: "totalSupply", expectedValue: newBigNumber(50) }, + { + variable: "allowance.arbitraryAccount.blacklisterAccount", + expectedValue: newBigNumber(amount), + }, + ]; + await expectRevert( + token.transferFrom( + Accounts.arbitraryAccount, + Accounts.pauserAccount, + amount, + { from: Accounts.blacklisterAccount } + ) + ); await checkVariables([token], [customVars]); }); - it('nt014 should fail to transferFrom to blacklisted recipient', async function () { - await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); + it("nt014 should fail to transferFrom to blacklisted recipient", async function () { + await token.configureMinter(Accounts.minterAccount, amount, { + from: Accounts.masterMinterAccount, + }); customVars = [ - {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount)} - ] + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount), + }, + ]; await checkVariables([token], [customVars]); - await token.mint(Accounts.blacklisterAccount, 50, {from: Accounts.minterAccount}); - await token.approve(Accounts.arbitraryAccount2, 50, {from: Accounts.blacklisterAccount}); - await token.blacklist(Accounts.arbitraryAccount, {from: Accounts.blacklisterAccount}); + await token.mint(Accounts.blacklisterAccount, 50, { + from: Accounts.minterAccount, + }); + 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': newBigNumber(amount - 50)}, - {'variable': 'balances.blacklisterAccount', 'expectedValue': newBigNumber(50)}, - {'variable': 'totalSupply', 'expectedValue': newBigNumber(50)}, - {'variable': 'allowance.blacklisterAccount.arbitraryAccount2', 'expectedValue': newBigNumber(50)}, - {'variable': 'isAccountBlacklisted.arbitraryAccount', 'expectedValue': true} - ] - await expectRevert(token.transferFrom(Accounts.blacklisterAccount, Accounts.arbitraryAccount, 50, {from: Accounts.arbitraryAccount2})); + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount - 50), + }, + { + variable: "balances.blacklisterAccount", + expectedValue: newBigNumber(50), + }, + { variable: "totalSupply", expectedValue: newBigNumber(50) }, + { + variable: "allowance.blacklisterAccount.arbitraryAccount2", + expectedValue: newBigNumber(50), + }, + { + variable: "isAccountBlacklisted.arbitraryAccount", + expectedValue: true, + }, + ]; + await expectRevert( + token.transferFrom( + Accounts.blacklisterAccount, + Accounts.arbitraryAccount, + 50, + { from: Accounts.arbitraryAccount2 } + ) + ); await checkVariables([token], [customVars]); }); - it('nt015 should fail to transferFrom from blacklisted msg.sender', async function () { - await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); + it("nt015 should fail to transferFrom from blacklisted msg.sender", async function () { + await token.configureMinter(Accounts.minterAccount, amount, { + from: Accounts.masterMinterAccount, + }); customVars = [ - {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount)} - ] + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount), + }, + ]; await checkVariables([token], [customVars]); - 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}); + 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': newBigNumber(amount - 50)}, - {'variable': 'balances.arbitraryAccount2', 'expectedValue': newBigNumber(50)}, - {'variable': 'totalSupply', 'expectedValue': newBigNumber(50)}, - {'variable': 'allowance.arbitraryAccount2.arbitraryAccount', 'expectedValue': newBigNumber(50)}, - {'variable': 'isAccountBlacklisted.arbitraryAccount', 'expectedValue': true} - ] - await expectRevert(token.transferFrom(Accounts.arbitraryAccount2, Accounts.pauserAccount, 50, {from: Accounts.arbitraryAccount})); + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount - 50), + }, + { + variable: "balances.arbitraryAccount2", + expectedValue: newBigNumber(50), + }, + { variable: "totalSupply", expectedValue: newBigNumber(50) }, + { + variable: "allowance.arbitraryAccount2.arbitraryAccount", + expectedValue: newBigNumber(50), + }, + { + variable: "isAccountBlacklisted.arbitraryAccount", + expectedValue: true, + }, + ]; + await expectRevert( + token.transferFrom( + Accounts.arbitraryAccount2, + Accounts.pauserAccount, + 50, + { from: Accounts.arbitraryAccount } + ) + ); await checkVariables([token], [customVars]); }); - it('nt016 should fail to transferFrom when from is blacklisted', async function () { - await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); + it("nt016 should fail to transferFrom when from is blacklisted", async function () { + await token.configureMinter(Accounts.minterAccount, amount, { + from: Accounts.masterMinterAccount, + }); customVars = [ - {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount)} - ] + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount), + }, + ]; await checkVariables([token], [customVars]); - await token.mint(Accounts.arbitraryAccount, 50, {from: Accounts.minterAccount}); - await token.approve(Accounts.arbitraryAccount2, 50, {from: Accounts.arbitraryAccount}); - await token.blacklist(Accounts.arbitraryAccount, {from: Accounts.blacklisterAccount}); + await token.mint(Accounts.arbitraryAccount, 50, { + from: Accounts.minterAccount, + }); + 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': newBigNumber(amount - 50)}, - {'variable': 'balances.arbitraryAccount', 'expectedValue': newBigNumber(50)}, - {'variable': 'totalSupply', 'expectedValue': newBigNumber(50)}, - {'variable': 'allowance.arbitraryAccount.arbitraryAccount2', 'expectedValue': newBigNumber(50)}, - {'variable': 'isAccountBlacklisted.arbitraryAccount', 'expectedValue': true} - ] - await expectRevert(token.transferFrom(Accounts.arbitraryAccount, Accounts.pauserAccount, 50, {from: Accounts.arbitraryAccount2})); + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount - 50), + }, + { + variable: "balances.arbitraryAccount", + expectedValue: newBigNumber(50), + }, + { variable: "totalSupply", expectedValue: newBigNumber(50) }, + { + variable: "allowance.arbitraryAccount.arbitraryAccount2", + expectedValue: newBigNumber(50), + }, + { + variable: "isAccountBlacklisted.arbitraryAccount", + expectedValue: true, + }, + ]; + await expectRevert( + token.transferFrom( + Accounts.arbitraryAccount, + Accounts.pauserAccount, + 50, + { from: Accounts.arbitraryAccount2 } + ) + ); await checkVariables([token], [customVars]); }); - it('nt017 should fail to transferFrom an amount greater than allowed for msg.sender', async function () { - await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); + it("nt017 should fail to transferFrom an amount greater than allowed for msg.sender", async function () { + await token.configureMinter(Accounts.minterAccount, amount, { + from: Accounts.masterMinterAccount, + }); customVars = [ - {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount)} - ] + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount), + }, + ]; await checkVariables([token], [customVars]); - await token.mint(Accounts.arbitraryAccount, 50, {from: Accounts.minterAccount}); - await token.approve(Accounts.arbitraryAccount2, 50, {from: Accounts.arbitraryAccount}); + await token.mint(Accounts.arbitraryAccount, 50, { + from: Accounts.minterAccount, + }); + await token.approve(Accounts.arbitraryAccount2, 50, { + from: Accounts.arbitraryAccount, + }); customVars = [ - {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - 50)}, - {'variable': 'balances.arbitraryAccount', 'expectedValue': newBigNumber(50)}, - {'variable': 'totalSupply', 'expectedValue': newBigNumber(50)}, - {'variable': 'allowance.arbitraryAccount.arbitraryAccount2', 'expectedValue': newBigNumber(50)}, - ] - await expectRevert(token.transferFrom(Accounts.arbitraryAccount, Accounts.pauserAccount, 60, {from: Accounts.arbitraryAccount2})); + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount - 50), + }, + { + variable: "balances.arbitraryAccount", + expectedValue: newBigNumber(50), + }, + { variable: "totalSupply", expectedValue: newBigNumber(50) }, + { + variable: "allowance.arbitraryAccount.arbitraryAccount2", + expectedValue: newBigNumber(50), + }, + ]; + await expectRevert( + token.transferFrom( + Accounts.arbitraryAccount, + Accounts.pauserAccount, + 60, + { from: Accounts.arbitraryAccount2 } + ) + ); await checkVariables([token], [customVars]); }); - it('nt018 should fail to transferFrom when paused', async function () { - await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); + it("nt018 should fail to transferFrom when paused", async function () { + await token.configureMinter(Accounts.minterAccount, amount, { + from: Accounts.masterMinterAccount, + }); var customVars = [ - {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount)} - ] + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount), + }, + ]; await checkVariables([token], [customVars]); - await token.mint(Accounts.arbitraryAccount, 50, {from: Accounts.minterAccount}); - await token.approve(Accounts.arbitraryAccount2, 50, {from: Accounts.arbitraryAccount}); - await token.pause({from: Accounts.pauserAccount}); + await token.mint(Accounts.arbitraryAccount, 50, { + from: Accounts.minterAccount, + }); + 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': newBigNumber(amount - 50)}, - {'variable': 'balances.arbitraryAccount', 'expectedValue': newBigNumber(50)}, - {'variable': 'totalSupply', 'expectedValue': newBigNumber(50)}, - {'variable': 'allowance.arbitraryAccount.arbitraryAccount2', 'expectedValue': newBigNumber(50)}, - {'variable': 'paused', 'expectedValue': true} - ] - await expectRevert(token.transferFrom(Accounts.arbitraryAccount, Accounts.pauserAccount, 50, {from: Accounts.arbitraryAccount2})); + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount - 50), + }, + { + variable: "balances.arbitraryAccount", + expectedValue: newBigNumber(50), + }, + { variable: "totalSupply", expectedValue: newBigNumber(50) }, + { + variable: "allowance.arbitraryAccount.arbitraryAccount2", + expectedValue: newBigNumber(50), + }, + { variable: "paused", expectedValue: true }, + ]; + await expectRevert( + token.transferFrom( + Accounts.arbitraryAccount, + Accounts.pauserAccount, + 50, + { from: Accounts.arbitraryAccount2 } + ) + ); await checkVariables([token], [customVars]); }); // Transfer - it('nt020 should fail to transfer to 0x0 address', async function () { - await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); + it("nt020 should fail to transfer to 0x0 address", async function () { + await token.configureMinter(Accounts.minterAccount, amount, { + from: Accounts.masterMinterAccount, + }); var customVars = [ - {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount)} - ] + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount), + }, + ]; await checkVariables([token], [customVars]); - await token.mint(Accounts.arbitraryAccount, 50, {from: Accounts.minterAccount}); + await token.mint(Accounts.arbitraryAccount, 50, { + from: Accounts.minterAccount, + }); customVars = [ - {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - 50)}, - {'variable': 'balances.arbitraryAccount', 'expectedValue': newBigNumber(50)}, - {'variable': 'totalSupply', 'expectedValue': newBigNumber(50)} - ] - await expectRevert(token.transfer(zeroAddress, 50, {from: Accounts.arbitraryAccount})); + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount - 50), + }, + { + variable: "balances.arbitraryAccount", + expectedValue: newBigNumber(50), + }, + { variable: "totalSupply", expectedValue: newBigNumber(50) }, + ]; + await expectRevert( + token.transfer(zeroAddress, 50, { from: Accounts.arbitraryAccount }) + ); await checkVariables([token], [customVars]); }); - it('nt021 should fail to transfer an amount greater than balance', async function () { - await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); + it("nt021 should fail to transfer an amount greater than balance", async function () { + await token.configureMinter(Accounts.minterAccount, amount, { + from: Accounts.masterMinterAccount, + }); customVars = [ - {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount)} - ] + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount), + }, + ]; await checkVariables([token], [customVars]); - await token.mint(Accounts.arbitraryAccount, 50, {from: Accounts.minterAccount}); + await token.mint(Accounts.arbitraryAccount, 50, { + from: Accounts.minterAccount, + }); var customVars = [ - {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - 50)}, - {'variable': 'balances.arbitraryAccount', 'expectedValue': newBigNumber(50)}, - {'variable': 'totalSupply', 'expectedValue': newBigNumber(50)} - ] - await expectRevert(token.transfer(Accounts.pauserAccount, amount, {from: Accounts.arbitraryAccount})); + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount - 50), + }, + { + variable: "balances.arbitraryAccount", + expectedValue: newBigNumber(50), + }, + { variable: "totalSupply", expectedValue: newBigNumber(50) }, + ]; + await expectRevert( + token.transfer(Accounts.pauserAccount, amount, { + from: Accounts.arbitraryAccount, + }) + ); await checkVariables([token], [customVars]); }); - it('nt022 should fail to transfer to blacklisted recipient', async function () { - await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); + it("nt022 should fail to transfer to blacklisted recipient", async function () { + await token.configureMinter(Accounts.minterAccount, amount, { + from: Accounts.masterMinterAccount, + }); customVars = [ - {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount)} - ] + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount), + }, + ]; await checkVariables([token], [customVars]); - await token.mint(Accounts.arbitraryAccount2, 50, {from: Accounts.minterAccount}); - await token.blacklist(Accounts.arbitraryAccount, {from: Accounts.blacklisterAccount}); + await token.mint(Accounts.arbitraryAccount2, 50, { + from: Accounts.minterAccount, + }); + await token.blacklist(Accounts.arbitraryAccount, { + from: Accounts.blacklisterAccount, + }); customVars = [ - {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - 50)}, - {'variable': 'balances.arbitraryAccount2', 'expectedValue': newBigNumber(50)}, - {'variable': 'totalSupply', 'expectedValue': newBigNumber(50)}, - {'variable': 'isAccountBlacklisted.arbitraryAccount', 'expectedValue': true} - ] - await expectRevert(token.transfer(Accounts.arbitraryAccount, 50, {from: Accounts.arbitraryAccount2})); + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount - 50), + }, + { + variable: "balances.arbitraryAccount2", + expectedValue: newBigNumber(50), + }, + { variable: "totalSupply", expectedValue: newBigNumber(50) }, + { + variable: "isAccountBlacklisted.arbitraryAccount", + expectedValue: true, + }, + ]; + await expectRevert( + token.transfer(Accounts.arbitraryAccount, 50, { + from: Accounts.arbitraryAccount2, + }) + ); await checkVariables([token], [customVars]); }); - it('nt023 should fail to transfer when sender is blacklisted', async function () { - await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); + it("nt023 should fail to transfer when sender is blacklisted", async function () { + await token.configureMinter(Accounts.minterAccount, amount, { + from: Accounts.masterMinterAccount, + }); customVars = [ - {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount)} - ] + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount), + }, + ]; await checkVariables([token], [customVars]); - await token.mint(Accounts.arbitraryAccount, 50, {from: Accounts.minterAccount}); - await token.blacklist(Accounts.arbitraryAccount, {from: Accounts.blacklisterAccount}); + await token.mint(Accounts.arbitraryAccount, 50, { + from: Accounts.minterAccount, + }); + await token.blacklist(Accounts.arbitraryAccount, { + from: Accounts.blacklisterAccount, + }); customVars = [ - {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - 50)}, - {'variable': 'balances.arbitraryAccount', 'expectedValue': newBigNumber(50)}, - {'variable': 'totalSupply', 'expectedValue': newBigNumber(50)}, - {'variable': 'isAccountBlacklisted.arbitraryAccount', 'expectedValue': true} - ] - await expectRevert(token.transfer(Accounts.tokenOwnerAccount, 50, {from: Accounts.arbitraryAccount})); + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount - 50), + }, + { + variable: "balances.arbitraryAccount", + expectedValue: newBigNumber(50), + }, + { variable: "totalSupply", expectedValue: newBigNumber(50) }, + { + variable: "isAccountBlacklisted.arbitraryAccount", + expectedValue: true, + }, + ]; + await expectRevert( + token.transfer(Accounts.tokenOwnerAccount, 50, { + from: Accounts.arbitraryAccount, + }) + ); await checkVariables([token], [customVars]); }); - it('nt024 should fail to transfer when paused', async function () { - await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); + it("nt024 should fail to transfer when paused", async function () { + await token.configureMinter(Accounts.minterAccount, amount, { + from: Accounts.masterMinterAccount, + }); var customVars = [ - {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount)} - ] + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount), + }, + ]; await checkVariables([token], [customVars]); - await token.mint(Accounts.arbitraryAccount, 50, {from: Accounts.minterAccount}); - await token.pause({from: Accounts.pauserAccount}); + await token.mint(Accounts.arbitraryAccount, 50, { + from: Accounts.minterAccount, + }); + await token.pause({ from: Accounts.pauserAccount }); customVars = [ - {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - 50)}, - {'variable': 'balances.arbitraryAccount', 'expectedValue': newBigNumber(50)}, - {'variable': 'totalSupply', 'expectedValue': newBigNumber(50)}, - {'variable': 'paused', 'expectedValue': true} - ] - await expectRevert(token.transfer(Accounts.tokenOwnerAccount, 50, {from: Accounts.arbitraryAccount})); + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount - 50), + }, + { + variable: "balances.arbitraryAccount", + expectedValue: newBigNumber(50), + }, + { variable: "totalSupply", expectedValue: newBigNumber(50) }, + { variable: "paused", expectedValue: true }, + ]; + await expectRevert( + token.transfer(Accounts.tokenOwnerAccount, 50, { + from: Accounts.arbitraryAccount, + }) + ); await checkVariables([token], [customVars]); }); // ConfigureMinter - it('nt026 should fail to configureMinter when sender is not masterMinter', async function () { + it("nt026 should fail to configureMinter when sender is not masterMinter", async function () { assert.isFalse(Accounts.arbitraryAccount == Accounts.masterMinterAccount); - await expectRevert(token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.arbitraryAccount})); + await expectRevert( + token.configureMinter(Accounts.minterAccount, amount, { + from: Accounts.arbitraryAccount, + }) + ); await checkVariables([token], [[]]); }); - - it('nt028 should fail to configureMinter when paused', async function () { - await token.pause({from: Accounts.pauserAccount}); - customVars = [ - {'variable': 'paused', 'expectedValue': true} - ] - await expectRevert(token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount})); + it("nt028 should fail to configureMinter when paused", async function () { + await token.pause({ from: Accounts.pauserAccount }); + customVars = [{ variable: "paused", expectedValue: true }]; + await expectRevert( + token.configureMinter(Accounts.minterAccount, amount, { + from: Accounts.masterMinterAccount, + }) + ); await checkVariables([token], [customVars]); }); // RemoveMinter - it('nt029 should fail to removeMinter when sender is not masterMinter', async function () { - await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); + it("nt029 should fail to removeMinter when sender is not masterMinter", async function () { + await token.configureMinter(Accounts.minterAccount, amount, { + from: Accounts.masterMinterAccount, + }); var customVars = [ - {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount)} - ] - await expectRevert(token.removeMinter(Accounts.minterAccount, {from: Accounts.arbitraryAccount})); + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount), + }, + ]; + await expectRevert( + token.removeMinter(Accounts.minterAccount, { + from: Accounts.arbitraryAccount, + }) + ); await checkVariables([token], [customVars]); }); // Burn - it('nt031 should fail to burn when balance is less than amount', async function () { - await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); + it("nt031 should fail to burn when balance is less than amount", async function () { + await token.configureMinter(Accounts.minterAccount, amount, { + from: Accounts.masterMinterAccount, + }); var customVars = [ - {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount)} - ] - await expectRevert(token.burn(amount, {from: Accounts.minterAccount})); + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount), + }, + ]; + await expectRevert(token.burn(amount, { from: Accounts.minterAccount })); await checkVariables([token], [customVars]); }); - it('nt032 should fail to burn when amount is -1', async function () { - await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); - await token.mint(Accounts.minterAccount, amount, {from: Accounts.minterAccount}); + it("nt032 should fail to burn when amount is -1", async function () { + await token.configureMinter(Accounts.minterAccount, amount, { + from: Accounts.masterMinterAccount, + }); + await token.mint(Accounts.minterAccount, amount, { + from: Accounts.minterAccount, + }); var customVars = [ - {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(0)}, - {'variable': 'balances.minterAccount', 'expectedValue': newBigNumber(amount)}, - {'variable': 'totalSupply', 'expectedValue': newBigNumber(amount)} - ] - await expectRevert(token.burn(-1, {from: Accounts.minterAccount})); + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(0), + }, + { + variable: "balances.minterAccount", + expectedValue: newBigNumber(amount), + }, + { variable: "totalSupply", expectedValue: newBigNumber(amount) }, + ]; + await expectRevert(token.burn(-1, { from: Accounts.minterAccount })); await checkVariables([token], [customVars]); }); - it('nt033 should fail to burn when sender is blacklisted', async function () { - await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); + it("nt033 should fail to burn when sender is blacklisted", async function () { + await token.configureMinter(Accounts.minterAccount, amount, { + from: Accounts.masterMinterAccount, + }); var customVars = [ - {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount)} - ] + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount), + }, + ]; await checkVariables([token], [customVars]); - await token.mint(Accounts.minterAccount, 50, {from: Accounts.minterAccount}); - await token.blacklist(Accounts.minterAccount, {from: Accounts.blacklisterAccount}); + await token.mint(Accounts.minterAccount, 50, { + from: Accounts.minterAccount, + }); + await token.blacklist(Accounts.minterAccount, { + from: Accounts.blacklisterAccount, + }); customVars = [ - {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - 50)}, - {'variable': 'balances.minterAccount', 'expectedValue': newBigNumber(50)}, - {'variable': 'totalSupply', 'expectedValue': newBigNumber(50)}, - {'variable': 'isAccountBlacklisted.minterAccount', 'expectedValue': true} - ] - await expectRevert(token.burn(50, {from: Accounts.minterAccount})); + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount - 50), + }, + { variable: "balances.minterAccount", expectedValue: newBigNumber(50) }, + { variable: "totalSupply", expectedValue: newBigNumber(50) }, + { variable: "isAccountBlacklisted.minterAccount", expectedValue: true }, + ]; + await expectRevert(token.burn(50, { from: Accounts.minterAccount })); await checkVariables([token], [customVars]); }); - it('nt034 should fail to burn when paused', async function () { - await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); + it("nt034 should fail to burn when paused", async function () { + await token.configureMinter(Accounts.minterAccount, amount, { + from: Accounts.masterMinterAccount, + }); var customVars = [ - {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount)} - ] + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount), + }, + ]; await checkVariables([token], [customVars]); - await token.mint(Accounts.minterAccount, 50, {from: Accounts.minterAccount}); - await token.pause({from: Accounts.pauserAccount}); + await token.mint(Accounts.minterAccount, 50, { + from: Accounts.minterAccount, + }); + await token.pause({ from: Accounts.pauserAccount }); customVars = [ - {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - 50)}, - {'variable': 'balances.minterAccount', 'expectedValue': newBigNumber(50)}, - {'variable': 'totalSupply', 'expectedValue': newBigNumber(50)}, - {'variable': 'paused', 'expectedValue': true} - ] - await expectRevert(token.burn(50, {from: Accounts.minterAccount})); + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount - 50), + }, + { variable: "balances.minterAccount", expectedValue: newBigNumber(50) }, + { variable: "totalSupply", expectedValue: newBigNumber(50) }, + { variable: "paused", expectedValue: true }, + ]; + await expectRevert(token.burn(50, { from: Accounts.minterAccount })); await checkVariables([token], [customVars]); }); - it('nt035 should fail to burn when sender is not minter', async function () { - await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); + it("nt035 should fail to burn when sender is not minter", async function () { + await token.configureMinter(Accounts.minterAccount, amount, { + from: Accounts.masterMinterAccount, + }); var customVars = [ - {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount)} - ] + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount), + }, + ]; await checkVariables([token], [customVars]); - await token.mint(Accounts.minterAccount, 50, {from: Accounts.minterAccount}); + await token.mint(Accounts.minterAccount, 50, { + from: Accounts.minterAccount, + }); customVars = [ - {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - 50)}, - {'variable': 'balances.minterAccount', 'expectedValue': newBigNumber(50)}, - {'variable': 'totalSupply', 'expectedValue': newBigNumber(50)} - ] - await expectRevert(token.burn(50, {from: Accounts.arbitraryAccount})); + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount - 50), + }, + { variable: "balances.minterAccount", expectedValue: newBigNumber(50) }, + { variable: "totalSupply", expectedValue: newBigNumber(50) }, + ]; + await expectRevert(token.burn(50, { from: Accounts.arbitraryAccount })); await checkVariables([token], [customVars]); }); - it('nt036 should fail to burn after removeMinter', async function () { - await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); + it("nt036 should fail to burn after removeMinter", async function () { + await token.configureMinter(Accounts.minterAccount, amount, { + from: Accounts.masterMinterAccount, + }); var customVars = [ - {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount)} - ] + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount), + }, + ]; await checkVariables([token], [customVars]); - await token.mint(Accounts.minterAccount, 50, {from: Accounts.minterAccount}); + await token.mint(Accounts.minterAccount, 50, { + from: Accounts.minterAccount, + }); customVars = [ - {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - 50)}, - {'variable': 'balances.minterAccount', 'expectedValue': newBigNumber(50)}, - {'variable': 'totalSupply', 'expectedValue': newBigNumber(50)} - ] + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount - 50), + }, + { variable: "balances.minterAccount", expectedValue: newBigNumber(50) }, + { variable: "totalSupply", expectedValue: newBigNumber(50) }, + ]; await checkVariables([token], [customVars]); - await token.removeMinter(Accounts.minterAccount, {from: Accounts.masterMinterAccount}); + await token.removeMinter(Accounts.minterAccount, { + from: Accounts.masterMinterAccount, + }); customVars = [ - {'variable': 'isAccountMinter.minterAccount', 'expectedValue': false}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(0)}, - {'variable': 'balances.minterAccount', 'expectedValue': newBigNumber(50)}, - {'variable': 'totalSupply', 'expectedValue': newBigNumber(50)} - ] - await expectRevert(token.burn(50, {from: Accounts.minterAccount})); + { variable: "isAccountMinter.minterAccount", expectedValue: false }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(0), + }, + { variable: "balances.minterAccount", expectedValue: newBigNumber(50) }, + { variable: "totalSupply", expectedValue: newBigNumber(50) }, + ]; + await expectRevert(token.burn(50, { from: Accounts.minterAccount })); await checkVariables([token], [customVars]); }); // Update functions - it('nt050 should fail to updatePauser when sender is not owner', async function () { - await expectRevert(token.updatePauser(Accounts.arbitraryAccount, {from: Accounts.pauserAccount})); + it("nt050 should fail to updatePauser when sender is not owner", async function () { + await expectRevert( + token.updatePauser(Accounts.arbitraryAccount, { + from: Accounts.pauserAccount, + }) + ); await checkVariables([token], [[]]); }); - it('nt049 should fail to updateMasterMinter when sender is not owner', async function () { - await expectRevert(token.updateMasterMinter(Accounts.arbitraryAccount, {from: Accounts.pauserAccount})); + it("nt049 should fail to updateMasterMinter when sender is not owner", async function () { + await expectRevert( + token.updateMasterMinter(Accounts.arbitraryAccount, { + from: Accounts.pauserAccount, + }) + ); await checkVariables([token], [[]]); }); - it('nt048 should fail to updateBlacklister when sender is not owner', async function () { - await expectRevert(token.updateBlacklister(Accounts.arbitraryAccount, {from: Accounts.pauserAccount})); + it("nt048 should fail to updateBlacklister when sender is not owner", async function () { + await expectRevert( + token.updateBlacklister(Accounts.arbitraryAccount, { + from: Accounts.pauserAccount, + }) + ); await checkVariables([token], [[]]); }); // Pause and Unpause - it('nt040 should fail to pause when sender is not pauser', async function () { - await expectRevert(token.pause({from: Accounts.arbitraryAccount})); + it("nt040 should fail to pause when sender is not pauser", async function () { + await expectRevert(token.pause({ from: Accounts.arbitraryAccount })); await checkVariables([token], [[]]); }); - it('nt041 should fail to unpause when sender is not pauser', async function () { - await token.pause({from: Accounts.pauserAccount}); - customVars = [ - {'variable': 'paused', 'expectedValue': true} - ] - await expectRevert(token.unpause({from: Accounts.arbitraryAccount})); + it("nt041 should fail to unpause when sender is not pauser", async function () { + await token.pause({ from: Accounts.pauserAccount }); + customVars = [{ variable: "paused", expectedValue: true }]; + await expectRevert(token.unpause({ from: Accounts.arbitraryAccount })); await checkVariables([token], [customVars]); }); // Blacklist and Unblacklist - it('nt042 should fail to blacklist when sender is not blacklister', async function () { - await expectRevert(token.blacklist(Accounts.tokenOwnerAccount, {from: Accounts.arbitraryAccount})); + it("nt042 should fail to blacklist when sender is not blacklister", async function () { + await expectRevert( + token.blacklist(Accounts.tokenOwnerAccount, { + from: Accounts.arbitraryAccount, + }) + ); await checkVariables([token], [[]]); }); - it('nt043 should fail to unblacklist when sender is not blacklister', async function () { - await token.blacklist(Accounts.arbitraryAccount, {from: Accounts.blacklisterAccount}); + it("nt043 should fail to unblacklist when sender is not blacklister", async function () { + await token.blacklist(Accounts.arbitraryAccount, { + from: Accounts.blacklisterAccount, + }); customVars = [ - {'variable': 'isAccountBlacklisted.arbitraryAccount', 'expectedValue': true} - ] - await expectRevert(token.unBlacklist(Accounts.arbitraryAccount, {from: Accounts.tokenOwnerAccount})); + { + variable: "isAccountBlacklisted.arbitraryAccount", + expectedValue: true, + }, + ]; + await expectRevert( + token.unBlacklist(Accounts.arbitraryAccount, { + from: Accounts.tokenOwnerAccount, + }) + ); await checkVariables([token], [customVars]); }); // Upgrade - it('nt054 should fail to transferOwnership when sender is not owner', async function() { + it("nt054 should fail to transferOwnership when sender is not owner", async function () { // Create upgraded token var newRawToken = await UpgradedFiatToken.new(); var tokenConfig = await upgradeTo(proxy, newRawToken); @@ -592,77 +1040,137 @@ async function run_tests(newToken, accounts) { var newToken = newProxiedToken; var newToken_result = [ - { 'variable': 'proxiedTokenAddress', 'expectedValue': newRawToken.address } + { variable: "proxiedTokenAddress", expectedValue: newRawToken.address }, ]; // expectRevert on transferOwnership with wrong sender - await expectRevert(newToken.transferOwnership(Accounts.arbitraryAccount, {from: Accounts.arbitraryAccount2})); + await expectRevert( + newToken.transferOwnership(Accounts.arbitraryAccount, { + from: Accounts.arbitraryAccount2, + }) + ); await checkVariables([newToken], [newToken_result]); }); - it('nt055 should fail to mint when amount = 0', async function() { - await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); - await expectRevert(token.mint(Accounts.pauserAccount, 0, {from: Accounts.minterAccount})); + it("nt055 should fail to mint when amount = 0", async function () { + await token.configureMinter(Accounts.minterAccount, amount, { + from: Accounts.masterMinterAccount, + }); + await expectRevert( + token.mint(Accounts.pauserAccount, 0, { from: Accounts.minterAccount }) + ); var customVars = [ - {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount)} - ] + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount), + }, + ]; await checkVariables([token], [customVars]); }); - it('nt056 should fail to burn when amount = 0', async function() { - await token.configureMinter(Accounts.minterAccount, amount, {from: Accounts.masterMinterAccount}); - await token.mint(Accounts.minterAccount, amount, {from: Accounts.minterAccount}); - await expectRevert(token.burn(0, {from: Accounts.minterAccount})); + it("nt056 should fail to burn when amount = 0", async function () { + await token.configureMinter(Accounts.minterAccount, amount, { + from: Accounts.masterMinterAccount, + }); + await token.mint(Accounts.minterAccount, amount, { + from: Accounts.minterAccount, + }); + await expectRevert(token.burn(0, { from: Accounts.minterAccount })); var customVars = [ - {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true}, - {'variable': 'balances.minterAccount', 'expectedValue': newBigNumber(amount)}, - {'variable': 'totalSupply', 'expectedValue': newBigNumber(amount)} - ] + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "balances.minterAccount", + expectedValue: newBigNumber(amount), + }, + { variable: "totalSupply", expectedValue: newBigNumber(amount) }, + ]; await checkVariables([token], [customVars]); }); - it('nt064 transferOwnership should fail on 0x0', async function () { - await expectRevert(token.transferOwnership(zeroAddress, { from: Accounts.tokenOwnerAccount })); + it("nt064 transferOwnership should fail on 0x0", async function () { + await expectRevert( + token.transferOwnership(zeroAddress, { from: Accounts.tokenOwnerAccount }) + ); }); - it('nt057 updateMasterMinter should fail on 0x0', async function () { - await expectRevert(token.updateMasterMinter(zeroAddress, { from: Accounts.tokenOwnerAccount })); + it("nt057 updateMasterMinter should fail on 0x0", async function () { + await expectRevert( + token.updateMasterMinter(zeroAddress, { + from: Accounts.tokenOwnerAccount, + }) + ); }); - it('nt058 updatePauser should fail on 0x0', async function () { - await expectRevert(token.updatePauser(zeroAddress, { from: Accounts.tokenOwnerAccount })); + it("nt058 updatePauser should fail on 0x0", async function () { + await expectRevert( + token.updatePauser(zeroAddress, { from: Accounts.tokenOwnerAccount }) + ); }); - it('nt059 updateBlacklister should fail on 0x0', async function () { - await expectRevert(token.updateBlacklister(zeroAddress, { from: Accounts.tokenOwnerAccount })); + it("nt059 updateBlacklister should fail on 0x0", async function () { + await expectRevert( + token.updateBlacklister(zeroAddress, { from: Accounts.tokenOwnerAccount }) + ); }); - it('nt060 initialize should fail when _masterMinter is 0x0', async function () { + it("nt060 initialize should fail when _masterMinter is 0x0", async function () { rawToken = await newToken(); - await expectRevert(customInitializeTokenWithProxy(rawToken, zeroAddress, Accounts.pauserAccount, Accounts.blacklisterAccount, Accounts.tokenOwnerAccount)); + await expectRevert( + customInitializeTokenWithProxy( + rawToken, + zeroAddress, + Accounts.pauserAccount, + Accounts.blacklisterAccount, + Accounts.tokenOwnerAccount + ) + ); }); - it('nt061 initialize should fail when _pauser is 0x0', async function () { + it("nt061 initialize should fail when _pauser is 0x0", async function () { rawToken = await newToken(); - await expectRevert(customInitializeTokenWithProxy(rawToken, Accounts.masterMinterAccount, zeroAddress, Accounts.blacklisterAccount, Accounts.tokenOwnerAccount)); + await expectRevert( + customInitializeTokenWithProxy( + rawToken, + Accounts.masterMinterAccount, + zeroAddress, + Accounts.blacklisterAccount, + Accounts.tokenOwnerAccount + ) + ); }); - it('nt062 initialize should fail when _blacklister is 0x0', async function () { + it("nt062 initialize should fail when _blacklister is 0x0", async function () { rawToken = await newToken(); - await expectRevert(customInitializeTokenWithProxy(rawToken, Accounts.masterMinterAccount, Accounts.pauserAccount, zeroAddress, Accounts.tokenOwnerAccount)); + await expectRevert( + customInitializeTokenWithProxy( + rawToken, + Accounts.masterMinterAccount, + Accounts.pauserAccount, + zeroAddress, + Accounts.tokenOwnerAccount + ) + ); }); - it('nt063 initialize should fail when _owner is 0x0', async function () { + it("nt063 initialize should fail when _owner is 0x0", async function () { rawToken = await newToken(); - await expectRevert(customInitializeTokenWithProxy(rawToken, Accounts.masterMinterAccount, Accounts.pauserAccount, Accounts.blacklisterAccount, zeroAddress)); + await expectRevert( + customInitializeTokenWithProxy( + rawToken, + Accounts.masterMinterAccount, + Accounts.pauserAccount, + Accounts.blacklisterAccount, + zeroAddress + ) + ); }); } -var testWrapper = require('./../TestWrapper'); -testWrapper.execute('FiatToken_NegativeTests', run_tests); +var testWrapper = require("./../TestWrapper"); +testWrapper.execute("FiatToken_NegativeTests", run_tests); module.exports = { run_tests: run_tests, -} +}; diff --git a/test/basic/PositiveTests.js b/test/basic/PositiveTests.js index 07b1a329c..eed349663 100644 --- a/test/basic/PositiveTests.js +++ b/test/basic/PositiveTests.js @@ -1,6 +1,6 @@ -var tokenUtils = require('./../TokenTestUtils.js');; +var tokenUtils = require("./../TokenTestUtils.js"); var newBigNumber = tokenUtils.newBigNumber; -var assertDiff = require('assert-diff'); +var assertDiff = require("assert-diff"); assertDiff.options.strict = true; var bigZero = tokenUtils.bigZero; @@ -15,14 +15,13 @@ var decimals = tokenUtils.decimals; var initializeTokenWithProxy = tokenUtils.initializeTokenWithProxy; var FiatToken = tokenUtils.FiatToken; -var AccountUtils = require('./../AccountUtils.js'); +var AccountUtils = require("./../AccountUtils.js"); var Accounts = AccountUtils.Accounts; var amount = 100; async function run_tests(newToken, accounts) { - - beforeEach('Make fresh token contract', async function () { + beforeEach("Make fresh token contract", async function () { rawToken = await newToken(); var tokenConfig = await initializeTokenWithProxy(rawToken); proxy = tokenConfig.proxy; @@ -30,21 +29,21 @@ async function run_tests(newToken, accounts) { assert.equal(proxy.address, token.address); }); - it('pt000 should check that default variable values are correct', async function () { + it("pt000 should check that default variable values are correct", async function () { await checkVariables([token], [[]]); }); // Pause and Unpause - it('pt011 should pause and set paused to true', async function () { + it("pt011 should pause and set paused to true", async function () { await token.pause({ from: Accounts.pauserAccount }); - var customVars = [{ 'variable': 'paused', 'expectedValue': true }]; + var customVars = [{ variable: "paused", expectedValue: true }]; await checkVariables([token], [customVars]); }); - it('pt006 should unpause and set paused to false', async function () { + it("pt006 should unpause and set paused to false", async function () { await token.pause({ from: Accounts.pauserAccount }); - var customVars = [{ 'variable': 'paused', 'expectedValue': true }]; + var customVars = [{ variable: "paused", expectedValue: true }]; await checkVariables([token], [customVars]); await token.unpause({ from: Accounts.pauserAccount }); await checkVariables([token], [[]]); @@ -52,219 +51,342 @@ async function run_tests(newToken, accounts) { // Approve - it('pt020 should approve a spend and set allowed amount', async function () { - await token.approve(Accounts.minterAccount, amount, { from: Accounts.arbitraryAccount }); + it("pt020 should approve a spend and set allowed amount", async function () { + await token.approve(Accounts.minterAccount, amount, { + from: Accounts.arbitraryAccount, + }); var customVars = [ - { 'variable': 'allowance.arbitraryAccount.minterAccount', 'expectedValue': newBigNumber(amount) } + { + variable: "allowance.arbitraryAccount.minterAccount", + expectedValue: newBigNumber(amount), + }, ]; await checkVariables([token], [customVars]); }); // Blacklist and Unblacklist - it('pt019 should blacklist and set blacklisted to true', async function () { - await token.blacklist(Accounts.arbitraryAccount, { from: Accounts.blacklisterAccount }); + it("pt019 should blacklist and set blacklisted to true", async function () { + await token.blacklist(Accounts.arbitraryAccount, { + from: Accounts.blacklisterAccount, + }); var customVars = [ - { 'variable': 'isAccountBlacklisted.arbitraryAccount', 'expectedValue': true } + { + variable: "isAccountBlacklisted.arbitraryAccount", + expectedValue: true, + }, ]; await checkVariables([token], [customVars]); }); - it('pt018 should blacklist and set blacklisted to true, then unblacklist and set blacklisted to false', async function () { - await token.blacklist(Accounts.arbitraryAccount, { from: Accounts.blacklisterAccount }); + it("pt018 should blacklist and set blacklisted to true, then unblacklist and set blacklisted to false", async function () { + await token.blacklist(Accounts.arbitraryAccount, { + from: Accounts.blacklisterAccount, + }); var customVars = [ - { 'variable': 'isAccountBlacklisted.arbitraryAccount', 'expectedValue': true } + { + variable: "isAccountBlacklisted.arbitraryAccount", + expectedValue: true, + }, ]; await checkVariables([token], [customVars]); - await token.unBlacklist(Accounts.arbitraryAccount, { from: Accounts.blacklisterAccount }); + await token.unBlacklist(Accounts.arbitraryAccount, { + from: Accounts.blacklisterAccount, + }); await checkVariables([token], [[]]); }); // Configure minter - it('pt015 should configureMinter, setting the minter to true and mintingAllowance to amount', async function () { - await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); + it("pt015 should configureMinter, setting the minter to true and mintingAllowance to amount", async function () { + await token.configureMinter(Accounts.minterAccount, amount, { + from: Accounts.masterMinterAccount, + }); var customVars = [ - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) } + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount), + }, ]; await checkVariables([token], [customVars]); }); // Mint and Burn - it('pt012 should mint the amount, increasing balance of recipient by amount, increasing total supply by amount, and decreasing minterAllowed by amount', async function () { + it("pt012 should mint the amount, increasing balance of recipient by amount, increasing total supply by amount, and decreasing minterAllowed by amount", async function () { var mintAmount = 50; - await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); + await token.configureMinter(Accounts.minterAccount, amount, { + from: Accounts.masterMinterAccount, + }); var customVars = [ - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) } + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount), + }, ]; await checkVariables([token], [customVars]); - await token.mint(Accounts.arbitraryAccount, mintAmount, { from: Accounts.minterAccount }); + await token.mint(Accounts.arbitraryAccount, mintAmount, { + from: Accounts.minterAccount, + }); customVars = [ - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - mintAmount) }, - { 'variable': 'balances.arbitraryAccount', 'expectedValue': newBigNumber(mintAmount) }, - { 'variable': 'totalSupply', 'expectedValue': newBigNumber(mintAmount) } + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount - mintAmount), + }, + { + variable: "balances.arbitraryAccount", + expectedValue: newBigNumber(mintAmount), + }, + { variable: "totalSupply", expectedValue: newBigNumber(mintAmount) }, ]; await checkVariables([token], [customVars]); }); - it('pt017 should burn amount of tokens and reduce balance and total supply by amount', async function () { + it("pt017 should burn amount of tokens and reduce balance and total supply by amount", async function () { var mintAmount = 11; var burnAmount = 10; - await token.configureMinter(Accounts.minterAccount, mintAmount, { from: Accounts.masterMinterAccount }); - await token.mint(Accounts.minterAccount, mintAmount, { from: Accounts.minterAccount }); + await token.configureMinter(Accounts.minterAccount, mintAmount, { + from: Accounts.masterMinterAccount, + }); + await token.mint(Accounts.minterAccount, mintAmount, { + from: Accounts.minterAccount, + }); var setup = [ - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(0) }, - { 'variable': 'balances.minterAccount', 'expectedValue': newBigNumber(mintAmount) }, - { 'variable': 'totalSupply', 'expectedValue': newBigNumber(mintAmount) }, + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(0), + }, + { + variable: "balances.minterAccount", + expectedValue: newBigNumber(mintAmount), + }, + { variable: "totalSupply", expectedValue: newBigNumber(mintAmount) }, ]; await checkVariables([token], [setup]); await token.burn(burnAmount, { from: Accounts.minterAccount }); var afterBurn = [ - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(0) }, - { 'variable': 'balances.minterAccount', 'expectedValue': newBigNumber(mintAmount - burnAmount) }, - { 'variable': 'totalSupply', 'expectedValue': newBigNumber(mintAmount - burnAmount) }, + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(0), + }, + { + variable: "balances.minterAccount", + expectedValue: newBigNumber(mintAmount - burnAmount), + }, + { + variable: "totalSupply", + expectedValue: newBigNumber(mintAmount - burnAmount), + }, ]; await checkVariables([token], [afterBurn]); }); // Remove minter - it('pt010 should removeMinter, setting the minter to false and minterAllowed to 0', async function () { + it("pt010 should removeMinter, setting the minter to false and minterAllowed to 0", async function () { let mintAmount = 11; - await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); - await token.mint(Accounts.arbitraryAccount, mintAmount, { from: Accounts.minterAccount }) + await token.configureMinter(Accounts.minterAccount, amount, { + from: Accounts.masterMinterAccount, + }); + await token.mint(Accounts.arbitraryAccount, mintAmount, { + from: Accounts.minterAccount, + }); var customVars = [ - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - mintAmount) }, - { 'variable': 'balances.arbitraryAccount', 'expectedValue': newBigNumber(mintAmount) }, - { 'variable': 'totalSupply', 'expectedValue': newBigNumber(mintAmount) } + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount - mintAmount), + }, + { + variable: "balances.arbitraryAccount", + expectedValue: newBigNumber(mintAmount), + }, + { variable: "totalSupply", expectedValue: newBigNumber(mintAmount) }, ]; await checkVariables([token], [customVars]); - await token.removeMinter(Accounts.minterAccount, { from: Accounts.masterMinterAccount }); + await token.removeMinter(Accounts.minterAccount, { + from: Accounts.masterMinterAccount, + }); customVars = [ - { 'variable': 'balances.arbitraryAccount', 'expectedValue': newBigNumber(mintAmount) }, - { 'variable': 'totalSupply', 'expectedValue': newBigNumber(mintAmount) } + { + variable: "balances.arbitraryAccount", + expectedValue: newBigNumber(mintAmount), + }, + { variable: "totalSupply", expectedValue: newBigNumber(mintAmount) }, ]; await checkVariables([token], [customVars]); }); // Transfer and transferFrom - it('pt008 should transfer, reducing sender balance by amount and increasing recipient balance by amount', async function () { + it("pt008 should transfer, reducing sender balance by amount and increasing recipient balance by amount", async function () { let mintAmount = 50; - await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); + await token.configureMinter(Accounts.minterAccount, amount, { + from: Accounts.masterMinterAccount, + }); var customVars = [ - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) } + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount), + }, ]; await checkVariables([token], [customVars]); - await token.mint(Accounts.arbitraryAccount, mintAmount, { from: Accounts.minterAccount }); + await token.mint(Accounts.arbitraryAccount, mintAmount, { + from: Accounts.minterAccount, + }); customVars = [ - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - mintAmount) }, - { 'variable': 'balances.arbitraryAccount', 'expectedValue': newBigNumber(mintAmount) }, - { 'variable': 'totalSupply', 'expectedValue': newBigNumber(mintAmount) } + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount - mintAmount), + }, + { + variable: "balances.arbitraryAccount", + expectedValue: newBigNumber(mintAmount), + }, + { variable: "totalSupply", expectedValue: newBigNumber(mintAmount) }, ]; await checkVariables([token], [customVars]); - await token.transfer(Accounts.arbitraryAccount2, mintAmount, { from: Accounts.arbitraryAccount }); + await token.transfer(Accounts.arbitraryAccount2, mintAmount, { + from: Accounts.arbitraryAccount, + }); customVars = [ - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - mintAmount) }, - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'balances.arbitraryAccount', 'expectedValue': bigZero }, - { 'variable': 'balances.arbitraryAccount2', 'expectedValue': newBigNumber(mintAmount) }, - { 'variable': 'totalSupply', 'expectedValue': newBigNumber(mintAmount) } + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount - mintAmount), + }, + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { variable: "balances.arbitraryAccount", expectedValue: bigZero }, + { + variable: "balances.arbitraryAccount2", + expectedValue: newBigNumber(mintAmount), + }, + { variable: "totalSupply", expectedValue: newBigNumber(mintAmount) }, ]; await checkVariables([token], [customVars]); }); - it('pt007 should transferFrom, reducing sender balance by amount and increasing recipient balance by amount', async function () { + it("pt007 should transferFrom, reducing sender balance by amount and increasing recipient balance by amount", async function () { let mintAmount = 50; - await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); + await token.configureMinter(Accounts.minterAccount, amount, { + from: Accounts.masterMinterAccount, + }); var customVars = [ - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) } + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount), + }, ]; await checkVariables([token], [customVars]); - await token.mint(Accounts.arbitraryAccount, mintAmount, { from: Accounts.minterAccount }); + await token.mint(Accounts.arbitraryAccount, mintAmount, { + from: Accounts.minterAccount, + }); customVars = [ - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - mintAmount) }, - { 'variable': 'balances.arbitraryAccount', 'expectedValue': newBigNumber(mintAmount) }, - { 'variable': 'totalSupply', 'expectedValue': newBigNumber(mintAmount) } + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount - mintAmount), + }, + { + variable: "balances.arbitraryAccount", + expectedValue: newBigNumber(mintAmount), + }, + { variable: "totalSupply", expectedValue: newBigNumber(mintAmount) }, ]; await checkVariables([token], [customVars]); - await token.approve(Accounts.masterMinterAccount, mintAmount, { from: Accounts.arbitraryAccount }); - await token.transferFrom(Accounts.arbitraryAccount, Accounts.arbitraryAccount2, mintAmount, { from: Accounts.masterMinterAccount }); + await token.approve(Accounts.masterMinterAccount, mintAmount, { + from: Accounts.arbitraryAccount, + }); + await token.transferFrom( + Accounts.arbitraryAccount, + Accounts.arbitraryAccount2, + mintAmount, + { from: Accounts.masterMinterAccount } + ); customVars = [ - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - mintAmount) }, - { 'variable': 'balances.arbitraryAccount', 'expectedValue': bigZero }, - { 'variable': 'balances.arbitraryAccount2', 'expectedValue': newBigNumber(mintAmount) }, - { 'variable': 'totalSupply', 'expectedValue': newBigNumber(mintAmount) } + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount - mintAmount), + }, + { variable: "balances.arbitraryAccount", expectedValue: bigZero }, + { + variable: "balances.arbitraryAccount2", + expectedValue: newBigNumber(mintAmount), + }, + { variable: "totalSupply", expectedValue: newBigNumber(mintAmount) }, ]; await checkVariables([token], [customVars]); }); // Update methods - it('pt004 should updateMasterMinter', async function () { - await token.updateMasterMinter(Accounts.arbitraryAccount, { from: Accounts.tokenOwnerAccount }); + it("pt004 should updateMasterMinter", async function () { + await token.updateMasterMinter(Accounts.arbitraryAccount, { + from: Accounts.tokenOwnerAccount, + }); var result = [ - { 'variable': 'masterMinter', 'expectedValue': Accounts.arbitraryAccount } + { variable: "masterMinter", expectedValue: Accounts.arbitraryAccount }, ]; await checkVariables([token], [result]); }); - it('pt005 should updateBlacklister', async function () { - await token.updateBlacklister(Accounts.arbitraryAccount, { from: Accounts.tokenOwnerAccount }); + it("pt005 should updateBlacklister", async function () { + await token.updateBlacklister(Accounts.arbitraryAccount, { + from: Accounts.tokenOwnerAccount, + }); var result = [ - { 'variable': 'blacklister', 'expectedValue': Accounts.arbitraryAccount } + { variable: "blacklister", expectedValue: Accounts.arbitraryAccount }, ]; await checkVariables([token], [result]); }); - it('pt003 should updatePauser', async function () { - await token.updatePauser(Accounts.arbitraryAccount, { from: Accounts.tokenOwnerAccount }); + it("pt003 should updatePauser", async function () { + await token.updatePauser(Accounts.arbitraryAccount, { + from: Accounts.tokenOwnerAccount, + }); var result = [ - { 'variable': 'pauser', 'expectedValue': Accounts.arbitraryAccount } + { variable: "pauser", expectedValue: Accounts.arbitraryAccount }, ]; await checkVariables([token], [result]); }); // Transfer Ownership - it('pt009 should set owner to _newOwner', async function () { - await token.transferOwnership(Accounts.arbitraryAccount, { from: Accounts.tokenOwnerAccount }); + it("pt009 should set owner to _newOwner", async function () { + await token.transferOwnership(Accounts.arbitraryAccount, { + from: Accounts.tokenOwnerAccount, + }); var result = [ - { 'variable': 'tokenOwner', 'expectedValue': Accounts.arbitraryAccount } + { variable: "tokenOwner", expectedValue: Accounts.arbitraryAccount }, ]; await checkVariables([token], [result]); }); - } -var testWrapper = require('./../TestWrapper'); -testWrapper.execute('FiatToken_PositiveTests', run_tests); +var testWrapper = require("./../TestWrapper"); +testWrapper.execute("FiatToken_PositiveTests", run_tests); module.exports = { run_tests: run_tests, -} +}; diff --git a/test/e2e/MintP0_EndToEndTests.js b/test/e2e/MintP0_EndToEndTests.js index fc43feb10..5fe71a73f 100644 --- a/test/e2e/MintP0_EndToEndTests.js +++ b/test/e2e/MintP0_EndToEndTests.js @@ -1,10 +1,10 @@ -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 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 tokenUtils = require('../TokenTestUtils.js'); +var tokenUtils = require("../TokenTestUtils.js"); var newBigNumber = tokenUtils.newBigNumber; var checkMINTp0 = tokenUtils.checkMINTp0; var expectRevert = tokenUtils.expectRevert; @@ -14,341 +14,658 @@ var bigZero = tokenUtils.bigZero; var maxAmount = tokenUtils.maxAmount; var initializeTokenWithProxy = tokenUtils.initializeTokenWithProxy; -var clone = require('clone'); +var clone = require("clone"); -var mintUtils = require('../MintControllerUtils.js'); -var AccountUtils = require('../AccountUtils.js'); +var mintUtils = require("../MintControllerUtils.js"); +var AccountUtils = require("../AccountUtils.js"); var Accounts = AccountUtils.Accounts; var getAccountState = AccountUtils.getAccountState; var MintControllerState = AccountUtils.MintControllerState; var addressEquals = AccountUtils.addressEquals; -var initializeTokenWithProxyAndMintController = mintUtils.initializeTokenWithProxyAndMintController; +var initializeTokenWithProxyAndMintController = + mintUtils.initializeTokenWithProxyAndMintController; var checkMintControllerState = mintUtils.checkMintControllerState; var zeroAddress = "0x0000000000000000000000000000000000000000"; -var maxAmount = "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"; +var maxAmount = + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"; async function run_tests_MintController(newToken, accounts) { - run_MINT_tests(newToken, MintController, accounts); + run_MINT_tests(newToken, MintController, accounts); } async function run_tests_MasterMinter(newToken, accounts) { - run_MINT_tests(newToken, MasterMinter, 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("ete000 New owner can configure controllers", async function () { + await mintController.transferOwnership(Accounts.arbitraryAccount, { + from: Accounts.mintOwnerAccount, + }); + await mintController.configureController( + Accounts.arbitraryAccount2, + Accounts.minterAccount, + { from: Accounts.arbitraryAccount } + ); + expectedMintControllerState.controllers["arbitraryAccount2"] = + Accounts.minterAccount; + expectedMintControllerState.owner = Accounts.arbitraryAccount; + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("ete001 New owner can remove controllers", async function () { + await mintController.transferOwnership(Accounts.arbitraryAccount, { + from: Accounts.mintOwnerAccount, + }); + await mintController.configureController( + Accounts.arbitraryAccount2, + Accounts.minterAccount, + { from: Accounts.arbitraryAccount } + ); + await mintController.removeController(Accounts.arbitraryAccount2, { + from: Accounts.arbitraryAccount, + }); + expectedMintControllerState.owner = Accounts.arbitraryAccount; + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("ete002 New controller can configure minter", async function () { + await mintController.configureController( + Accounts.arbitraryAccount, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + await mintController.configureMinter(10, { + from: Accounts.arbitraryAccount, + }); + expectedMintControllerState.controllers["arbitraryAccount"] = + Accounts.minterAccount; + expectedTokenState.push( + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(10), + } + ); + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("ete003 Configure two controllers for the same minter and make sure they can both configureMinter", async function () { + await mintController.configureController( + Accounts.arbitraryAccount, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + await mintController.configureController( + Accounts.arbitraryAccount2, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + expectedMintControllerState.controllers["arbitraryAccount"] = + Accounts.minterAccount; + expectedMintControllerState.controllers["arbitraryAccount2"] = + Accounts.minterAccount; + + // first controller configures minter + await mintController.configureMinter(10, { + from: Accounts.arbitraryAccount, + }); + expectedTokenState.push( + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(10), + } + ); + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + + // second controller configures minter + await mintController.configureMinter(30, { + from: Accounts.arbitraryAccount2, + }); + expectedTokenState.push({ + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(30), + }); + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("ete004 Configure two controllers for the same minter, one adds a minter and the other removes it", async function () { + await mintController.configureController( + Accounts.arbitraryAccount, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + await mintController.configureController( + Accounts.arbitraryAccount2, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + expectedMintControllerState.controllers["arbitraryAccount"] = + Accounts.minterAccount; + expectedMintControllerState.controllers["arbitraryAccount2"] = + Accounts.minterAccount; + + // first controller configures minter + await mintController.configureMinter(10, { + from: Accounts.arbitraryAccount, + }); + expectedTokenState.push( + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(10), + } + ); + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + + // second controller remove minter + await mintController.removeMinter({ from: Accounts.arbitraryAccount2 }); + expectedTokenState.push( + { variable: "isAccountMinter.minterAccount", expectedValue: false }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(0), + } + ); + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("ete005 Configure two controllers for different minters and make sure 2nd cant remove", async function () { + await mintController.configureController( + Accounts.arbitraryAccount, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + await mintController.configureController( + Accounts.arbitraryAccount2, + Accounts.pauserAccount, + { from: Accounts.mintOwnerAccount } + ); + expectedMintControllerState.controllers["arbitraryAccount"] = + Accounts.minterAccount; + expectedMintControllerState.controllers["arbitraryAccount2"] = + Accounts.minterAccount; + + // first controller configures minter + await mintController.configureMinter(10, { + from: Accounts.arbitraryAccount, + }); + expectedTokenState.push( + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(10), + } + ); + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + + // second controller fails to remove minter (expectedTokenState unchanged) + await mintController.removeMinter({ from: Accounts.arbitraryAccount2 }); + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("ete006 Configure two controllers for different minters and make sure 2nd cant configure", async function () { + await mintController.configureController( + Accounts.arbitraryAccount, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + await mintController.configureController( + Accounts.arbitraryAccount2, + Accounts.pauserAccount, + { from: Accounts.mintOwnerAccount } + ); + expectedMintControllerState.controllers["arbitraryAccount"] = + Accounts.minterAccount; + expectedMintControllerState.controllers["arbitraryAccount2"] = + Accounts.minterAccount; + + // second controller fails to configure minter (configures pauser instead) + await mintController.configureMinter(20, { + from: Accounts.arbitraryAccount2, + }); + expectedTokenState.push( + { variable: "isAccountMinter.pauserAccount", expectedValue: true }, + { + variable: "minterAllowance.pauserAccount", + expectedValue: newBigNumber(20), + } + ); + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("ete007 Remove a controller and make sure it can't modify minter", async function () { + await mintController.configureController( + Accounts.arbitraryAccount, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + await mintController.removeController(Accounts.arbitraryAccount, { + from: Accounts.mintOwnerAccount, + }); + await expectError( + mintController.configureMinter(10, { from: Accounts.arbitraryAccount }), + "The value of controllers[msg.sender] must be non-zero" + ); + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("ete008 Change minter manager and make sure existing controllers still can configure their minters", async function () { + await mintController.configureController( + Accounts.arbitraryAccount, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + expectedMintControllerState.controllers["arbitraryAccount"] = + Accounts.minterAccount; + + // change minterManager to a new token + var newTokenConfig = await initializeTokenWithProxy(rawToken); + var newToken = newTokenConfig.token; + await newToken.updateMasterMinter(mintController.address, { + from: Accounts.tokenOwnerAccount, + }); + await mintController.setMinterManager(newToken.address, { + from: Accounts.mintOwnerAccount, + }); + expectedMintControllerState.minterManager = newToken.address; + + // now use controller to configure minter + await mintController.configureMinter(10, { + from: Accounts.arbitraryAccount, + }); + expectedMintControllerState.controllers["arbitraryAccount"] = + Accounts.minterAccount; + expectedTokenState.push( + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(10), + } + ); + await checkMINTp0( + [newToken, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("ete009 Change minter manager and make sure existing controllers still can remove their minters", async function () { + await mintController.configureController( + Accounts.arbitraryAccount, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + expectedMintControllerState.controllers["arbitraryAccount"] = + Accounts.minterAccount; + + // change minterManager to a new token + var newTokenConfig = await initializeTokenWithProxy(rawToken); + var newToken = newTokenConfig.token; + await newToken.updateMasterMinter(mintController.address, { + from: Accounts.tokenOwnerAccount, + }); + await mintController.setMinterManager(newToken.address, { + from: Accounts.mintOwnerAccount, + }); + expectedMintControllerState.minterManager = newToken.address; - 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('ete000 New owner can configure controllers', async function () { - await mintController.transferOwnership(Accounts.arbitraryAccount, {from: Accounts.mintOwnerAccount}); - await mintController.configureController(Accounts.arbitraryAccount2, Accounts.minterAccount, {from: Accounts.arbitraryAccount}); - expectedMintControllerState.controllers['arbitraryAccount2'] = Accounts.minterAccount; - expectedMintControllerState.owner = Accounts.arbitraryAccount; - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); - }); - - it('ete001 New owner can remove controllers', async function () { - await mintController.transferOwnership(Accounts.arbitraryAccount, {from: Accounts.mintOwnerAccount}); - await mintController.configureController(Accounts.arbitraryAccount2, Accounts.minterAccount, {from: Accounts.arbitraryAccount}); - await mintController.removeController(Accounts.arbitraryAccount2, {from: Accounts.arbitraryAccount}); - expectedMintControllerState.owner = Accounts.arbitraryAccount; - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); - }); - - it('ete002 New controller can configure minter', async function () { - await mintController.configureController(Accounts.arbitraryAccount, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - await mintController.configureMinter(10, {from: Accounts.arbitraryAccount}); - expectedMintControllerState.controllers['arbitraryAccount'] = Accounts.minterAccount; - expectedTokenState.push( - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(10) } - ); - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); - }); - - it('ete003 Configure two controllers for the same minter and make sure they can both configureMinter', async function () { - await mintController.configureController(Accounts.arbitraryAccount, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - await mintController.configureController(Accounts.arbitraryAccount2, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - expectedMintControllerState.controllers['arbitraryAccount'] = Accounts.minterAccount; - expectedMintControllerState.controllers['arbitraryAccount2'] = Accounts.minterAccount; - - // first controller configures minter - await mintController.configureMinter(10, {from: Accounts.arbitraryAccount}); - expectedTokenState.push( - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(10) } - ); - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); - - // second controller configures minter - await mintController.configureMinter(30, {from: Accounts.arbitraryAccount2}); - expectedTokenState.push( - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(30) } - ); - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); - }); - - it('ete004 Configure two controllers for the same minter, one adds a minter and the other removes it', async function () { - await mintController.configureController(Accounts.arbitraryAccount, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - await mintController.configureController(Accounts.arbitraryAccount2, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - expectedMintControllerState.controllers['arbitraryAccount'] = Accounts.minterAccount; - expectedMintControllerState.controllers['arbitraryAccount2'] = Accounts.minterAccount; - - // first controller configures minter - await mintController.configureMinter(10, {from: Accounts.arbitraryAccount}); - expectedTokenState.push( - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(10) } - ); - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); - - // second controller remove minter - await mintController.removeMinter({from: Accounts.arbitraryAccount2}); - expectedTokenState.push( - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': false }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(0) } - ); - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); - }); - - it('ete005 Configure two controllers for different minters and make sure 2nd cant remove', async function () { - await mintController.configureController(Accounts.arbitraryAccount, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - await mintController.configureController(Accounts.arbitraryAccount2, Accounts.pauserAccount, {from: Accounts.mintOwnerAccount}); - expectedMintControllerState.controllers['arbitraryAccount'] = Accounts.minterAccount; - expectedMintControllerState.controllers['arbitraryAccount2'] = Accounts.minterAccount; - - // first controller configures minter - await mintController.configureMinter(10, {from: Accounts.arbitraryAccount}); - expectedTokenState.push( - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(10) } - ); - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); - - // second controller fails to remove minter (expectedTokenState unchanged) - await mintController.removeMinter({from: Accounts.arbitraryAccount2}); - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); - }); - - it('ete006 Configure two controllers for different minters and make sure 2nd cant configure', async function () { - await mintController.configureController(Accounts.arbitraryAccount, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - await mintController.configureController(Accounts.arbitraryAccount2, Accounts.pauserAccount, {from: Accounts.mintOwnerAccount}); - expectedMintControllerState.controllers['arbitraryAccount'] = Accounts.minterAccount; - expectedMintControllerState.controllers['arbitraryAccount2'] = Accounts.minterAccount; - - // second controller fails to configure minter (configures pauser instead) - await mintController.configureMinter(20, {from: Accounts.arbitraryAccount2}); - expectedTokenState.push( - { 'variable': 'isAccountMinter.pauserAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.pauserAccount', 'expectedValue': newBigNumber(20) } - ); - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); - }); - - it('ete007 Remove a controller and make sure it can\'t modify minter', async function () { - await mintController.configureController(Accounts.arbitraryAccount, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - await mintController.removeController(Accounts.arbitraryAccount, {from: Accounts.mintOwnerAccount}); - await expectError(mintController.configureMinter(10, {from: Accounts.arbitraryAccount}), - "The value of controllers[msg.sender] must be non-zero"); - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); - }); - - it('ete008 Change minter manager and make sure existing controllers still can configure their minters', async function () { - await mintController.configureController(Accounts.arbitraryAccount, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - expectedMintControllerState.controllers['arbitraryAccount'] = Accounts.minterAccount; - - // change minterManager to a new token - var newTokenConfig = await initializeTokenWithProxy(rawToken); - var newToken = newTokenConfig.token; - await newToken.updateMasterMinter(mintController.address, {from:Accounts.tokenOwnerAccount}); - await mintController.setMinterManager(newToken.address, {from: Accounts.mintOwnerAccount}); - expectedMintControllerState.minterManager = newToken.address; - - // now use controller to configure minter - await mintController.configureMinter(10, {from: Accounts.arbitraryAccount}); - expectedMintControllerState.controllers['arbitraryAccount'] = Accounts.minterAccount; - expectedTokenState.push( - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(10) } - ); - await checkMINTp0([newToken, mintController], [expectedTokenState, expectedMintControllerState]); - }); - - it('ete009 Change minter manager and make sure existing controllers still can remove their minters', async function () { - await mintController.configureController(Accounts.arbitraryAccount, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - expectedMintControllerState.controllers['arbitraryAccount'] = Accounts.minterAccount; - - // change minterManager to a new token - var newTokenConfig = await initializeTokenWithProxy(rawToken); - var newToken = newTokenConfig.token; - await newToken.updateMasterMinter(mintController.address, {from:Accounts.tokenOwnerAccount}); - await mintController.setMinterManager(newToken.address, {from: Accounts.mintOwnerAccount}); - expectedMintControllerState.minterManager = newToken.address; - - // now use controller to configure and remove minter - await mintController.configureMinter(10, {from: Accounts.arbitraryAccount}); - await mintController.removeMinter({from: Accounts.arbitraryAccount}); - expectedMintControllerState.controllers['arbitraryAccount'] = Accounts.minterAccount; - await checkMINTp0([newToken, mintController], [expectedTokenState, expectedMintControllerState]); - }); - - it('ete010 Change minter manager and make sure existing controllers can increment allowances', async function () { - await mintController.configureController(Accounts.arbitraryAccount, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - expectedMintControllerState.controllers['arbitraryAccount'] = Accounts.minterAccount; - - // change minterManager to a new token - var newTokenConfig = await initializeTokenWithProxy(rawToken); - var newToken = newTokenConfig.token; - await newToken.updateMasterMinter(mintController.address, {from:Accounts.tokenOwnerAccount}); - await mintController.setMinterManager(newToken.address, {from: Accounts.mintOwnerAccount}); - expectedMintControllerState.minterManager = newToken.address; - - // now use controller to configure minter - await mintController.configureMinter(10, {from: Accounts.arbitraryAccount}); - await mintController.incrementMinterAllowance(20, {from: Accounts.arbitraryAccount}); - expectedMintControllerState.controllers['arbitraryAccount'] = Accounts.minterAccount; - expectedTokenState.push( - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(30) } - ); - await checkMINTp0([newToken, mintController], [expectedTokenState, expectedMintControllerState]); - }); - - it('ete011 New controller can increment minter allowance', async function () { - await mintController.configureController(Accounts.arbitraryAccount, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - await mintController.configureMinter(0, {from: Accounts.arbitraryAccount}); - await mintController.incrementMinterAllowance(10, {from: Accounts.arbitraryAccount}); - expectedMintControllerState.controllers['arbitraryAccount'] = Accounts.minterAccount; - expectedTokenState.push( - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(10) } - ); - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); - }); - - it('ete012 New controller can remove minter', async function () { - await mintController.configureController(Accounts.arbitraryAccount, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - await mintController.configureMinter(10, {from: Accounts.arbitraryAccount}); - await mintController.removeMinter({from: Accounts.arbitraryAccount}); - expectedMintControllerState.controllers['arbitraryAccount'] = Accounts.minterAccount; - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); - }); - - it('ete013 Change minter manager, configure a minter, then change back and make sure changes DID NOT propogate', async function () { - await mintController.configureController(Accounts.arbitraryAccount, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - expectedMintControllerState.controllers['arbitraryAccount'] = Accounts.minterAccount; - - // change minterManager to a new token - var newTokenConfig = await initializeTokenWithProxy(rawToken); - var newToken = newTokenConfig.token; - await newToken.updateMasterMinter(mintController.address, {from:Accounts.tokenOwnerAccount}); - await mintController.setMinterManager(newToken.address, {from: Accounts.mintOwnerAccount}); - expectedMintControllerState.minterManager = newToken.address; - - // now use controller to configure minter - await mintController.configureMinter(10, {from: Accounts.arbitraryAccount}); - expectedMintControllerState.controllers['arbitraryAccount'] = Accounts.minterAccount; - expectedTokenState.push( - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(10) } - ); - await checkMINTp0([newToken, mintController], [expectedTokenState, expectedMintControllerState]); - - // change minterManager to original token and make sure changes did not propagate - await mintController.setMinterManager(token.address, {from: Accounts.mintOwnerAccount}); - expectedMintControllerState.minterManager = token.address; - expectedTokenState.push( - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': false }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(0) } - ); - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); - }); - - it('ete014 Remove a minter and then try to increment its allowance reverts', async function () { - // add and remove minter - await mintController.configureController(Accounts.arbitraryAccount, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - await mintController.configureMinter(10, {from: Accounts.arbitraryAccount}); - await mintController.removeMinter({from: Accounts.arbitraryAccount}); - expectedMintControllerState.controllers['arbitraryAccount'] = Accounts.minterAccount; - - // now verify that incrementing its allowance reverts - expectError(mintController.incrementMinterAllowance(20, {from: Accounts.arbitraryAccount}), - "Can only increment allowance for minters in minterManager"); - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); - }); - - it('ete015 Configure a minter and make sure it can mint', async function () { - // configure a minter - await mintController.configureController(Accounts.arbitraryAccount, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - await mintController.configureMinter(10, {from: Accounts.arbitraryAccount}); - - // now verify it can mint - await token.mint(Accounts.arbitraryAccount, 5, {from: Accounts.minterAccount}); - expectedMintControllerState.controllers['arbitraryAccount'] = Accounts.minterAccount; - expectedTokenState.push( - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(5) }, - { 'variable': 'balances.arbitraryAccount', 'expectedValue': newBigNumber(5)}, - { 'variable': 'totalSupply', 'expectedValue': newBigNumber(5)} - ); - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); - }); - - it('ete016 Remove a minter and make sure it cannot mint', async function () { - // add and remove minter - await mintController.configureController(Accounts.arbitraryAccount, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - await mintController.configureMinter(10, {from: Accounts.arbitraryAccount}); - await mintController.removeMinter({from: Accounts.arbitraryAccount}); - expectedMintControllerState.controllers['arbitraryAccount'] = Accounts.minterAccount; - - // now verify that minter cannot mint - expectRevert(token.mint(Accounts.arbitraryAccount2, 5, {from: Accounts.minterAccount})); - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); - }); - - it('ete017 Configure a minter and make sure it can burn', async function () { - // configure a minter - await mintController.configureController(Accounts.arbitraryAccount, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - await mintController.configureMinter(10, {from: Accounts.arbitraryAccount}); - - // now verify it can burn - await token.mint(Accounts.minterAccount, 5, {from: Accounts.minterAccount}); - await token.burn(5, {from: Accounts.minterAccount}); - expectedMintControllerState.controllers['arbitraryAccount'] = Accounts.minterAccount; - expectedTokenState.push( - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(5) } - ); - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); - }); - - it('ete018 Remove a minter and make sure it cannot burn', async function () { - // add minter, use it to mint to itself, and remove it again - await mintController.configureController(Accounts.arbitraryAccount, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - await mintController.configureMinter(10, {from: Accounts.arbitraryAccount}); - await token.mint(Accounts.minterAccount, 5, {from: Accounts.minterAccount}); - await mintController.removeMinter({from: Accounts.arbitraryAccount}); - - // now verify that minter cannot burn - expectRevert(token.burn(5, {from: Accounts.minterAccount})); - expectedMintControllerState.controllers['arbitraryAccount'] = Accounts.minterAccount; - expectedTokenState.push( - { 'variable': 'balances.minterAccount', 'expectedValue': newBigNumber(5)}, - { 'variable': 'totalSupply', 'expectedValue': newBigNumber(5)} - ); - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + // now use controller to configure and remove minter + await mintController.configureMinter(10, { + from: Accounts.arbitraryAccount, + }); + await mintController.removeMinter({ from: Accounts.arbitraryAccount }); + expectedMintControllerState.controllers["arbitraryAccount"] = + Accounts.minterAccount; + await checkMINTp0( + [newToken, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("ete010 Change minter manager and make sure existing controllers can increment allowances", async function () { + await mintController.configureController( + Accounts.arbitraryAccount, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + expectedMintControllerState.controllers["arbitraryAccount"] = + Accounts.minterAccount; + + // change minterManager to a new token + var newTokenConfig = await initializeTokenWithProxy(rawToken); + var newToken = newTokenConfig.token; + await newToken.updateMasterMinter(mintController.address, { + from: Accounts.tokenOwnerAccount, }); + await mintController.setMinterManager(newToken.address, { + from: Accounts.mintOwnerAccount, + }); + expectedMintControllerState.minterManager = newToken.address; + // now use controller to configure minter + await mintController.configureMinter(10, { + from: Accounts.arbitraryAccount, + }); + await mintController.incrementMinterAllowance(20, { + from: Accounts.arbitraryAccount, + }); + expectedMintControllerState.controllers["arbitraryAccount"] = + Accounts.minterAccount; + expectedTokenState.push( + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(30), + } + ); + await checkMINTp0( + [newToken, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("ete011 New controller can increment minter allowance", async function () { + await mintController.configureController( + Accounts.arbitraryAccount, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + await mintController.configureMinter(0, { + from: Accounts.arbitraryAccount, + }); + await mintController.incrementMinterAllowance(10, { + from: Accounts.arbitraryAccount, + }); + expectedMintControllerState.controllers["arbitraryAccount"] = + Accounts.minterAccount; + expectedTokenState.push( + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(10), + } + ); + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("ete012 New controller can remove minter", async function () { + await mintController.configureController( + Accounts.arbitraryAccount, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + await mintController.configureMinter(10, { + from: Accounts.arbitraryAccount, + }); + await mintController.removeMinter({ from: Accounts.arbitraryAccount }); + expectedMintControllerState.controllers["arbitraryAccount"] = + Accounts.minterAccount; + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("ete013 Change minter manager, configure a minter, then change back and make sure changes DID NOT propogate", async function () { + await mintController.configureController( + Accounts.arbitraryAccount, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + expectedMintControllerState.controllers["arbitraryAccount"] = + Accounts.minterAccount; + + // change minterManager to a new token + var newTokenConfig = await initializeTokenWithProxy(rawToken); + var newToken = newTokenConfig.token; + await newToken.updateMasterMinter(mintController.address, { + from: Accounts.tokenOwnerAccount, + }); + await mintController.setMinterManager(newToken.address, { + from: Accounts.mintOwnerAccount, + }); + expectedMintControllerState.minterManager = newToken.address; + + // now use controller to configure minter + await mintController.configureMinter(10, { + from: Accounts.arbitraryAccount, + }); + expectedMintControllerState.controllers["arbitraryAccount"] = + Accounts.minterAccount; + expectedTokenState.push( + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(10), + } + ); + await checkMINTp0( + [newToken, mintController], + [expectedTokenState, expectedMintControllerState] + ); + + // change minterManager to original token and make sure changes did not propagate + await mintController.setMinterManager(token.address, { + from: Accounts.mintOwnerAccount, + }); + expectedMintControllerState.minterManager = token.address; + expectedTokenState.push( + { variable: "isAccountMinter.minterAccount", expectedValue: false }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(0), + } + ); + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("ete014 Remove a minter and then try to increment its allowance reverts", async function () { + // add and remove minter + await mintController.configureController( + Accounts.arbitraryAccount, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + await mintController.configureMinter(10, { + from: Accounts.arbitraryAccount, + }); + await mintController.removeMinter({ from: Accounts.arbitraryAccount }); + expectedMintControllerState.controllers["arbitraryAccount"] = + Accounts.minterAccount; + + // now verify that incrementing its allowance reverts + expectError( + mintController.incrementMinterAllowance(20, { + from: Accounts.arbitraryAccount, + }), + "Can only increment allowance for minters in minterManager" + ); + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("ete015 Configure a minter and make sure it can mint", async function () { + // configure a minter + await mintController.configureController( + Accounts.arbitraryAccount, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + await mintController.configureMinter(10, { + from: Accounts.arbitraryAccount, + }); + + // now verify it can mint + await token.mint(Accounts.arbitraryAccount, 5, { + from: Accounts.minterAccount, + }); + expectedMintControllerState.controllers["arbitraryAccount"] = + Accounts.minterAccount; + expectedTokenState.push( + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(5), + }, + { variable: "balances.arbitraryAccount", expectedValue: newBigNumber(5) }, + { variable: "totalSupply", expectedValue: newBigNumber(5) } + ); + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("ete016 Remove a minter and make sure it cannot mint", async function () { + // add and remove minter + await mintController.configureController( + Accounts.arbitraryAccount, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + await mintController.configureMinter(10, { + from: Accounts.arbitraryAccount, + }); + await mintController.removeMinter({ from: Accounts.arbitraryAccount }); + expectedMintControllerState.controllers["arbitraryAccount"] = + Accounts.minterAccount; + + // now verify that minter cannot mint + expectRevert( + token.mint(Accounts.arbitraryAccount2, 5, { + from: Accounts.minterAccount, + }) + ); + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("ete017 Configure a minter and make sure it can burn", async function () { + // configure a minter + await mintController.configureController( + Accounts.arbitraryAccount, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + await mintController.configureMinter(10, { + from: Accounts.arbitraryAccount, + }); + + // now verify it can burn + await token.mint(Accounts.minterAccount, 5, { + from: Accounts.minterAccount, + }); + await token.burn(5, { from: Accounts.minterAccount }); + expectedMintControllerState.controllers["arbitraryAccount"] = + Accounts.minterAccount; + expectedTokenState.push( + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(5), + } + ); + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("ete018 Remove a minter and make sure it cannot burn", async function () { + // add minter, use it to mint to itself, and remove it again + await mintController.configureController( + Accounts.arbitraryAccount, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + await mintController.configureMinter(10, { + from: Accounts.arbitraryAccount, + }); + await token.mint(Accounts.minterAccount, 5, { + from: Accounts.minterAccount, + }); + await mintController.removeMinter({ from: Accounts.arbitraryAccount }); + + // now verify that minter cannot burn + expectRevert(token.burn(5, { from: Accounts.minterAccount })); + expectedMintControllerState.controllers["arbitraryAccount"] = + Accounts.minterAccount; + expectedTokenState.push( + { variable: "balances.minterAccount", expectedValue: newBigNumber(5) }, + { variable: "totalSupply", expectedValue: newBigNumber(5) } + ); + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); } -var testWrapper = require('./../TestWrapper'); -testWrapper.execute('MINTp0_EndToEndTests MintController', run_tests_MintController); -testWrapper.execute('MINTp0_EndToEndTests MasterMinter', run_tests_MasterMinter); +var testWrapper = require("./../TestWrapper"); +testWrapper.execute( + "MINTp0_EndToEndTests MintController", + run_tests_MintController +); +testWrapper.execute( + "MINTp0_EndToEndTests MasterMinter", + run_tests_MasterMinter +); diff --git a/test/events/MintP0_EventsTests.js b/test/events/MintP0_EventsTests.js index 1173ee5b7..d3f5de1fa 100644 --- a/test/events/MintP0_EventsTests.js +++ b/test/events/MintP0_EventsTests.js @@ -1,10 +1,10 @@ -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 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 tokenUtils = require('../TokenTestUtils.js'); +var tokenUtils = require("../TokenTestUtils.js"); var newBigNumber = tokenUtils.newBigNumber; var checkMINTp0 = tokenUtils.checkMINTp0; var expectRevert = tokenUtils.expectRevert; @@ -13,180 +13,338 @@ var expectError = tokenUtils.expectError; var bigZero = tokenUtils.bigZero; var maxAmount = tokenUtils.maxAmount; -var clone = require('clone'); +var clone = require("clone"); -var mintUtils = require('../MintControllerUtils.js'); -var AccountUtils = require('../AccountUtils.js'); +var mintUtils = require("../MintControllerUtils.js"); +var AccountUtils = require("../AccountUtils.js"); var Accounts = AccountUtils.Accounts; var getAccountState = AccountUtils.getAccountState; var MintControllerState = AccountUtils.MintControllerState; var addressEquals = AccountUtils.addressEquals; -var initializeTokenWithProxyAndMintController = mintUtils.initializeTokenWithProxyAndMintController; +var initializeTokenWithProxyAndMintController = + mintUtils.initializeTokenWithProxyAndMintController; var checkMintControllerState = mintUtils.checkMintControllerState; var zeroAddress = "0x0000000000000000000000000000000000000000"; -var maxAmount = "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"; +var maxAmount = + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"; var mintControllerEvents = { - ownershipTransferred: "OwnershipTransferred", - controllerConfigured: "ControllerConfigured", - controllerRemoved: "ControllerRemoved", - minterManagerSet: "MinterManagerSet", - minterCofigured: "MinterConfigured", - minterRemoved: "MinterRemoved", - minterAllowanceIncremented: "MinterAllowanceIncremented", - minterAllowanceDecremented: "MinterAllowanceDecremented" + ownershipTransferred: "OwnershipTransferred", + controllerConfigured: "ControllerConfigured", + controllerRemoved: "ControllerRemoved", + minterManagerSet: "MinterManagerSet", + minterCofigured: "MinterConfigured", + minterRemoved: "MinterRemoved", + minterAllowanceIncremented: "MinterAllowanceIncremented", + minterAllowanceDecremented: "MinterAllowanceDecremented", }; - - - async function run_tests_MintController(newToken, accounts) { - run_MINT_tests(newToken, MintController, accounts); + run_MINT_tests(newToken, MintController, accounts); } async function run_tests_MasterMinter(newToken, accounts) { - run_MINT_tests(newToken, MasterMinter, 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 }]; + 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("et100 transferOwnership emits OwnershipTransferred event", async function () { + // get all previous transfer ownership events + var preEvents = await mintController.getPastEvents( + mintControllerEvents.ownershipTransferred, + { + filter: { + previousOwner: Accounts.mintOwnerAccount, + newOwner: Accounts.arbitraryAccount, + }, + } + ); + + // now transfer ownership and test again + await mintController.transferOwnership(Accounts.arbitraryAccount, { + from: Accounts.mintOwnerAccount, }); - - it('et100 transferOwnership emits OwnershipTransferred event', async function () { - // get all previous transfer ownership events - var preEvents = await mintController.getPastEvents(mintControllerEvents.ownershipTransferred, - {filter: {previousOwner: Accounts.mintOwnerAccount, newOwner: Accounts.arbitraryAccount}}); - - // now transfer ownership and test again - await mintController.transferOwnership(Accounts.arbitraryAccount, {from: Accounts.mintOwnerAccount}); - var postEvents = await mintController.getPastEvents(mintControllerEvents.ownershipTransferred, - {filter: {previousOwner: Accounts.mintOwnerAccount, newOwner: Accounts.arbitraryAccount}}); - - // one new event must have fired - assert.equal(preEvents.length+1, postEvents.length); + var postEvents = await mintController.getPastEvents( + mintControllerEvents.ownershipTransferred, + { + filter: { + previousOwner: Accounts.mintOwnerAccount, + newOwner: Accounts.arbitraryAccount, + }, + } + ); + + // one new event must have fired + assert.equal(preEvents.length + 1, postEvents.length); + }); + + it("et101 configureController emits ControllerConfigured event", async function () { + // get all previous configure controller events + var preEvents = await mintController.getPastEvents( + mintControllerEvents.controllerConfigured, + { + filter: { + _controller: Accounts.arbitraryAccount, + _worker: Accounts.arbitraryAccount2, + }, + } + ); + + // now configure controller and test again + await mintController.configureController( + Accounts.arbitraryAccount, + Accounts.arbitraryAccount2, + { from: Accounts.mintOwnerAccount } + ); + var postEvents = await mintController.getPastEvents( + mintControllerEvents.controllerConfigured, + { + filter: { + _controller: Accounts.arbitraryAccount, + _worker: Accounts.arbitraryAccount2, + }, + } + ); + + // one new event must have fired + assert.equal(preEvents.length + 1, postEvents.length); + }); + + it("et102 removeController emits ControllerRemoved event", async function () { + // get all previous removeController events + await mintController.configureController( + Accounts.arbitraryAccount, + Accounts.arbitraryAccount2, + { from: Accounts.mintOwnerAccount } + ); + var preEvents = await mintController.getPastEvents( + mintControllerEvents.controllerRemoved, + { filter: { _controller: Accounts.arbitraryAccount } } + ); + + // now remove controller and test again + await mintController.removeController(Accounts.arbitraryAccount, { + from: Accounts.mintOwnerAccount, }); - - it('et101 configureController emits ControllerConfigured event', async function () { - // get all previous configure controller events - var preEvents = await mintController.getPastEvents(mintControllerEvents.controllerConfigured, - {filter: {_controller: Accounts.arbitraryAccount, _worker: Accounts.arbitraryAccount2}}); - - // now configure controller and test again - await mintController.configureController(Accounts.arbitraryAccount, Accounts.arbitraryAccount2, {from: Accounts.mintOwnerAccount}); - var postEvents = await mintController.getPastEvents(mintControllerEvents.controllerConfigured, - {filter: {_controller: Accounts.arbitraryAccount, _worker: Accounts.arbitraryAccount2}}); - - // one new event must have fired - assert.equal(preEvents.length+1, postEvents.length); + var postEvents = await mintController.getPastEvents( + mintControllerEvents.controllerRemoved, + { filter: { _controller: Accounts.arbitraryAccount } } + ); + + // one new event must have fired + assert.equal(preEvents.length + 1, postEvents.length); + }); + + it("et103 setMinterManager emits MinterManagerSet event", async function () { + // get all previous set minter manager events + var preEvents = await mintController.getPastEvents( + mintControllerEvents.minterManagerSet, + { + filter: { + _oldMinterManager: token.address, + _newMinterManager: Accounts.arbitraryAccount, + }, + } + ); + + // now set minter manager and test again + await mintController.setMinterManager(Accounts.arbitraryAccount, { + from: Accounts.mintOwnerAccount, }); - - it('et102 removeController emits ControllerRemoved event', async function () { - // get all previous removeController events - await mintController.configureController(Accounts.arbitraryAccount, Accounts.arbitraryAccount2, {from: Accounts.mintOwnerAccount}); - var preEvents = await mintController.getPastEvents(mintControllerEvents.controllerRemoved, - {filter: {_controller: Accounts.arbitraryAccount}}); - - // now remove controller and test again - await mintController.removeController(Accounts.arbitraryAccount, {from: Accounts.mintOwnerAccount}); - var postEvents = await mintController.getPastEvents(mintControllerEvents.controllerRemoved, - {filter: {_controller: Accounts.arbitraryAccount}}); - - // one new event must have fired - assert.equal(preEvents.length+1, postEvents.length); + var postEvents = await mintController.getPastEvents( + mintControllerEvents.minterManagerSet, + { + filter: { + _oldMinterManager: token.address, + _newMinterManager: Accounts.arbitraryAccount, + }, + } + ); + + // one new event must have fired + assert.equal(preEvents.length + 1, postEvents.length); + }); + + it("et104 removeMinter emits MinterRemoved event", async function () { + // get all previous remove minter events + var allowance = 10; + await mintController.configureController( + Accounts.arbitraryAccount, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + await mintController.configureMinter(allowance, { + from: Accounts.arbitraryAccount, }); - - it('et103 setMinterManager emits MinterManagerSet event', async function () { - // get all previous set minter manager events - var preEvents = await mintController.getPastEvents(mintControllerEvents.minterManagerSet, - {filter: {_oldMinterManager: token.address, _newMinterManager: Accounts.arbitraryAccount}}); - - // now set minter manager and test again - await mintController.setMinterManager(Accounts.arbitraryAccount, {from: Accounts.mintOwnerAccount}); - var postEvents = await mintController.getPastEvents(mintControllerEvents.minterManagerSet, - {filter: {_oldMinterManager: token.address, _newMinterManager: Accounts.arbitraryAccount}}); - - // one new event must have fired - assert.equal(preEvents.length+1, postEvents.length); + var preEvents = await mintController.getPastEvents( + mintControllerEvents.minterRemoved, + { + filter: { + _msgSender: Accounts.arbitraryAccount, + _minter: Accounts.minterAccount, + }, + } + ); + + // now remove minter and test again + await mintController.removeMinter({ from: Accounts.arbitraryAccount }); + var postEvents = await mintController.getPastEvents( + mintControllerEvents.minterRemoved, + { + filter: { + _msgSender: Accounts.arbitraryAccount, + _minter: Accounts.minterAccount, + }, + } + ); + + // one new event must have fired + assert.equal(preEvents.length + 1, postEvents.length); + }); + + it("et105 configureMinter emits MinterConfigured event", async function () { + // get all previous configureMinter events + var allowance = 10; + await mintController.configureController( + Accounts.arbitraryAccount, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + var preEvents = await mintController.getPastEvents( + mintControllerEvents.minterCofigured, + { + filter: { + _msgSender: Accounts.arbitraryAccount, + _minter: Accounts.minterAccount, + _allowance: allowance, + }, + } + ); + + // now transfer ownership and test again + await mintController.configureMinter(allowance, { + from: Accounts.arbitraryAccount, }); - - - it('et104 removeMinter emits MinterRemoved event', async function () { - // get all previous remove minter events - var allowance = 10; - await mintController.configureController(Accounts.arbitraryAccount, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - await mintController.configureMinter(allowance, {from: Accounts.arbitraryAccount}); - var preEvents = await mintController.getPastEvents(mintControllerEvents.minterRemoved, - {filter: {_msgSender: Accounts.arbitraryAccount, _minter: Accounts.minterAccount}}); - - // now remove minter and test again - await mintController.removeMinter({from: Accounts.arbitraryAccount}); - var postEvents = await mintController.getPastEvents(mintControllerEvents.minterRemoved, - {filter: {_msgSender: Accounts.arbitraryAccount, _minter: Accounts.minterAccount}}); - - // one new event must have fired - assert.equal(preEvents.length+1, postEvents.length); + var postEvents = await mintController.getPastEvents( + mintControllerEvents.minterCofigured, + { + filter: { + _msgSender: Accounts.arbitraryAccount, + _minter: Accounts.minterAccount, + _allowance: allowance, + }, + } + ); + + // one new event must have fired + assert.equal(preEvents.length + 1, postEvents.length); + }); + + it("et106 incrementMinterAllowance emits MinterAllowanceIncremented event", async function () { + // get all previous increment minter allowance events + var allowance = 10; + await mintController.configureController( + Accounts.arbitraryAccount, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + await mintController.configureMinter(allowance, { + from: Accounts.arbitraryAccount, }); - - it('et105 configureMinter emits MinterConfigured event', async function () { - // get all previous configureMinter events - var allowance = 10; - await mintController.configureController(Accounts.arbitraryAccount, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - var preEvents = await mintController.getPastEvents(mintControllerEvents.minterCofigured, - {filter: {_msgSender: Accounts.arbitraryAccount, _minter: Accounts.minterAccount, _allowance: allowance}}); - - // now transfer ownership and test again - await mintController.configureMinter(allowance, {from: Accounts.arbitraryAccount}); - var postEvents = await mintController.getPastEvents(mintControllerEvents.minterCofigured, - {filter: {_msgSender: Accounts.arbitraryAccount, _minter: Accounts.minterAccount, _allowance: allowance}}); - - // one new event must have fired - assert.equal(preEvents.length+1, postEvents.length); + var preEvents = await mintController.getPastEvents( + mintControllerEvents.minterAllowanceIncremented, + { + filter: { + _msgSender: Accounts.arbitraryAccount, + _minter: Accounts.minterAccount, + _increment: allowance, + _newAllowance: allowance * 2, + }, + } + ); + + // now increment minter allowance and test again + await mintController.incrementMinterAllowance(allowance, { + from: Accounts.arbitraryAccount, }); - - it('et106 incrementMinterAllowance emits MinterAllowanceIncremented event', async function () { - // get all previous increment minter allowance events - var allowance = 10; - await mintController.configureController(Accounts.arbitraryAccount, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - await mintController.configureMinter(allowance, {from: Accounts.arbitraryAccount}); - var preEvents = await mintController.getPastEvents(mintControllerEvents.minterAllowanceIncremented, - {filter: {_msgSender: Accounts.arbitraryAccount, _minter: Accounts.minterAccount, _increment: allowance, _newAllowance: allowance*2}}); - - // now increment minter allowance and test again - await mintController.incrementMinterAllowance(allowance, {from: Accounts.arbitraryAccount}); - var postEvents = await mintController.getPastEvents(mintControllerEvents.minterAllowanceIncremented, - {filter: {_msgSender: Accounts.arbitraryAccount, _minter: Accounts.minterAccount, _increment: allowance, _newAllowance: allowance*2}}); - - // one new event must have fired - assert.equal(preEvents.length+1, postEvents.length); + var postEvents = await mintController.getPastEvents( + mintControllerEvents.minterAllowanceIncremented, + { + filter: { + _msgSender: Accounts.arbitraryAccount, + _minter: Accounts.minterAccount, + _increment: allowance, + _newAllowance: allowance * 2, + }, + } + ); + + // one new event must have fired + assert.equal(preEvents.length + 1, postEvents.length); + }); + + it("et107 decrementMinterAllowance emits MinterAllowanceDecremented event", async function () { + // get all previous decrement minter allowance events + var allowance = 10; + await mintController.configureController( + Accounts.arbitraryAccount, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + await mintController.configureMinter(allowance, { + from: Accounts.arbitraryAccount, }); - - it('et107 decrementMinterAllowance emits MinterAllowanceDecremented event', async function () { - // get all previous decrement minter allowance events - var allowance = 10; - await mintController.configureController(Accounts.arbitraryAccount, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - await mintController.configureMinter(allowance, {from: Accounts.arbitraryAccount}); - var preEvents = await mintController.getPastEvents(mintControllerEvents.minterAllowanceDecremented, - {filter: {_msgSender: Accounts.arbitraryAccount, _minter: Accounts.minterAccount, _decrement: allowance, _newAllowance: 0}}); - - // now decrement minter allowance and test again - await mintController.decrementMinterAllowance(allowance, {from: Accounts.arbitraryAccount}); - var postEvents = await mintController.getPastEvents(mintControllerEvents.minterAllowanceDecremented, - {filter: {_msgSender: Accounts.arbitraryAccount, _minter: Accounts.minterAccount, _decrement: allowance, _newAllowance: 0}}); - - // one new event must have fired - assert.equal(preEvents.length+1, postEvents.length); + var preEvents = await mintController.getPastEvents( + mintControllerEvents.minterAllowanceDecremented, + { + filter: { + _msgSender: Accounts.arbitraryAccount, + _minter: Accounts.minterAccount, + _decrement: allowance, + _newAllowance: 0, + }, + } + ); + + // now decrement minter allowance and test again + await mintController.decrementMinterAllowance(allowance, { + from: Accounts.arbitraryAccount, }); - + var postEvents = await mintController.getPastEvents( + mintControllerEvents.minterAllowanceDecremented, + { + filter: { + _msgSender: Accounts.arbitraryAccount, + _minter: Accounts.minterAccount, + _decrement: allowance, + _newAllowance: 0, + }, + } + ); + + // one new event must have fired + assert.equal(preEvents.length + 1, postEvents.length); + }); } -var testWrapper = require('./../TestWrapper'); -testWrapper.execute('MINTp0_EventTests MintController', run_tests_MintController); -testWrapper.execute('MINTp0_EventTests MasterMinter', run_tests_MasterMinter); +var testWrapper = require("./../TestWrapper"); +testWrapper.execute( + "MINTp0_EventTests MintController", + run_tests_MintController +); +testWrapper.execute("MINTp0_EventTests MasterMinter", run_tests_MasterMinter); diff --git a/test/extended/ExtendedPositiveTests.js b/test/extended/ExtendedPositiveTests.js index 28cc2f35b..7d4e052ae 100644 --- a/test/extended/ExtendedPositiveTests.js +++ b/test/extended/ExtendedPositiveTests.js @@ -1,6 +1,6 @@ -var tokenUtils = require('./../TokenTestUtils.js'); +var tokenUtils = require("./../TokenTestUtils.js"); var newBigNumber = tokenUtils.newBigNumber; -var assertDiff = require('assert-diff'); +var assertDiff = require("assert-diff"); assertDiff.options.strict = true; var bigZero = tokenUtils.bigZero; @@ -17,14 +17,13 @@ var UpgradedFiatToken = tokenUtils.UpgradedFiatToken; var FiatToken = tokenUtils.FiatToken; var upgradeTo = tokenUtils.upgradeTo; -var AccountUtils = require('./../AccountUtils.js'); +var AccountUtils = require("./../AccountUtils.js"); var Accounts = AccountUtils.Accounts; var amount = 100; async function run_tests(newToken, accounts) { - - beforeEach('Make fresh token contract', async function () { + beforeEach("Make fresh token contract", async function () { rawToken = await newToken(); var tokenConfig = await initializeTokenWithProxy(rawToken); proxy = tokenConfig.proxy; @@ -34,385 +33,558 @@ async function run_tests(newToken, accounts) { // Paused - it('ept001 should changeAdmin while paused', async function () { + it("ept001 should changeAdmin while paused", async function () { await token.pause({ from: Accounts.pauserAccount }); - await proxy.changeAdmin(Accounts.arbitraryAccount, { from: Accounts.proxyOwnerAccount }); + await proxy.changeAdmin(Accounts.arbitraryAccount, { + from: Accounts.proxyOwnerAccount, + }); var result = [ - { 'variable': 'paused', 'expectedValue': true }, - { 'variable': 'proxyOwner', 'expectedValue': Accounts.arbitraryAccount}, + { variable: "paused", expectedValue: true }, + { variable: "proxyOwner", expectedValue: Accounts.arbitraryAccount }, ]; await checkVariables([token], [result]); }); - it('ept002 should updateMasterMinter while paused', async function () { + it("ept002 should updateMasterMinter while paused", async function () { await token.pause({ from: Accounts.pauserAccount }); - await token.updateMasterMinter(Accounts.arbitraryAccount, { from: Accounts.tokenOwnerAccount }); + await token.updateMasterMinter(Accounts.arbitraryAccount, { + from: Accounts.tokenOwnerAccount, + }); var result = [ - { 'variable': 'masterMinter', 'expectedValue': Accounts.arbitraryAccount }, - { 'variable': 'paused', 'expectedValue': true } + { variable: "masterMinter", expectedValue: Accounts.arbitraryAccount }, + { variable: "paused", expectedValue: true }, ]; await checkVariables([token], [result]); }); - it('ept003 should updateBlacklister while paused', async function () { + it("ept003 should updateBlacklister while paused", async function () { await token.pause({ from: Accounts.pauserAccount }); - await token.updateBlacklister(Accounts.arbitraryAccount, { from: Accounts.tokenOwnerAccount }); + await token.updateBlacklister(Accounts.arbitraryAccount, { + from: Accounts.tokenOwnerAccount, + }); var result = [ - { 'variable': 'blacklister', 'expectedValue': Accounts.arbitraryAccount }, - { 'variable': 'paused', 'expectedValue': true } + { variable: "blacklister", expectedValue: Accounts.arbitraryAccount }, + { variable: "paused", expectedValue: true }, ]; await checkVariables([token], [result]); }); - it('ept004 should updatePauser while paused', async function () { + it("ept004 should updatePauser while paused", async function () { await token.pause({ from: Accounts.pauserAccount }); - await token.updatePauser(Accounts.arbitraryAccount, { from: Accounts.tokenOwnerAccount }); + await token.updatePauser(Accounts.arbitraryAccount, { + from: Accounts.tokenOwnerAccount, + }); var result = [ - { 'variable': 'pauser', 'expectedValue': Accounts.arbitraryAccount }, - { 'variable': 'paused', 'expectedValue': true } + { variable: "pauser", expectedValue: Accounts.arbitraryAccount }, + { variable: "paused", expectedValue: true }, ]; await checkVariables([token], [result]); }); - it('ept005 should transferOwnership while paused', async function () { + it("ept005 should transferOwnership while paused", async function () { await token.pause({ from: Accounts.pauserAccount }); - await token.transferOwnership(Accounts.arbitraryAccount, { from: Accounts.tokenOwnerAccount }); + await token.transferOwnership(Accounts.arbitraryAccount, { + from: Accounts.tokenOwnerAccount, + }); var result = [ - { 'variable': 'tokenOwner', 'expectedValue': Accounts.arbitraryAccount }, - { 'variable': 'paused', 'expectedValue': true } + { variable: "tokenOwner", expectedValue: Accounts.arbitraryAccount }, + { variable: "paused", expectedValue: true }, ]; await checkVariables([token], [result]); }); - it('ept006 should removeMinter while paused', async function () { - await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); + it("ept006 should removeMinter while paused", async function () { + await token.configureMinter(Accounts.minterAccount, amount, { + from: Accounts.masterMinterAccount, + }); await token.pause({ from: Accounts.pauserAccount }); var isAMinter = [ - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) }, - { 'variable': 'paused', 'expectedValue': true } + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount), + }, + { variable: "paused", expectedValue: true }, ]; await checkVariables([token], [isAMinter]); - await token.removeMinter(Accounts.minterAccount, { from: Accounts.masterMinterAccount }); + await token.removeMinter(Accounts.minterAccount, { + from: Accounts.masterMinterAccount, + }); var notAMinter = [ - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': false }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(0) }, - { 'variable': 'paused', 'expectedValue': true } + { variable: "isAccountMinter.minterAccount", expectedValue: false }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(0), + }, + { variable: "paused", expectedValue: true }, ]; await checkVariables([token], [notAMinter]); }); - it('ept008 should upgrade while paused', async function() { + it("ept008 should upgrade while paused", async function () { var newRawToken = await UpgradedFiatToken.new(); - await token.pause({from: Accounts.pauserAccount}); + await token.pause({ from: Accounts.pauserAccount }); var tokenConfig = await upgradeTo(proxy, newRawToken); var newProxiedToken = tokenConfig.token; var newToken = newProxiedToken; var newToken_result = [ - { 'variable': 'paused', 'expectedValue': true }, - {'variable': 'proxiedTokenAddress', 'expectedValue': newRawToken.address } + { variable: "paused", expectedValue: true }, + { variable: "proxiedTokenAddress", expectedValue: newRawToken.address }, ]; await checkVariables([newToken], [newToken_result]); }); // Blacklisted - it('ept013 should changeAdmin when msg.sender blacklisted', async function () { - await token.blacklist(Accounts.proxyOwnerAccount, { from: Accounts.blacklisterAccount }); - await proxy.changeAdmin(Accounts.arbitraryAccount, { from: Accounts.proxyOwnerAccount }); + it("ept013 should changeAdmin when msg.sender blacklisted", async function () { + await token.blacklist(Accounts.proxyOwnerAccount, { + from: Accounts.blacklisterAccount, + }); + await proxy.changeAdmin(Accounts.arbitraryAccount, { + from: Accounts.proxyOwnerAccount, + }); var result = [ - { 'variable': 'isAccountBlacklisted.proxyOwnerAccount', 'expectedValue': true }, - { 'variable': 'proxyOwner', 'expectedValue': Accounts.arbitraryAccount }, + { + variable: "isAccountBlacklisted.proxyOwnerAccount", + expectedValue: true, + }, + { variable: "proxyOwner", expectedValue: Accounts.arbitraryAccount }, ]; await checkVariables([token], [result]); }); - it('ept014 should updateMasterMinter when msg.sender blacklisted', async function () { - await token.blacklist(Accounts.tokenOwnerAccount, { from: Accounts.blacklisterAccount }); - await token.updateMasterMinter(Accounts.arbitraryAccount, { from: Accounts.tokenOwnerAccount }); + it("ept014 should updateMasterMinter when msg.sender blacklisted", async function () { + await token.blacklist(Accounts.tokenOwnerAccount, { + from: Accounts.blacklisterAccount, + }); + await token.updateMasterMinter(Accounts.arbitraryAccount, { + from: Accounts.tokenOwnerAccount, + }); var setup = [ - { 'variable': 'masterMinter', 'expectedValue': Accounts.arbitraryAccount }, - { 'variable': 'isAccountBlacklisted.tokenOwnerAccount', 'expectedValue': true } + { variable: "masterMinter", expectedValue: Accounts.arbitraryAccount }, + { + variable: "isAccountBlacklisted.tokenOwnerAccount", + expectedValue: true, + }, ]; await checkVariables([token], [setup]); }); - it('ept015 should updateBlacklister when msg.sender blacklisted', async function () { - await token.blacklist(Accounts.tokenOwnerAccount, { from: Accounts.blacklisterAccount }); - await token.updateBlacklister(Accounts.arbitraryAccount, { from: Accounts.tokenOwnerAccount }); + it("ept015 should updateBlacklister when msg.sender blacklisted", async function () { + await token.blacklist(Accounts.tokenOwnerAccount, { + from: Accounts.blacklisterAccount, + }); + await token.updateBlacklister(Accounts.arbitraryAccount, { + from: Accounts.tokenOwnerAccount, + }); var setup = [ - { 'variable': 'blacklister', 'expectedValue': Accounts.arbitraryAccount }, - { 'variable': 'isAccountBlacklisted.tokenOwnerAccount', 'expectedValue': true } + { variable: "blacklister", expectedValue: Accounts.arbitraryAccount }, + { + variable: "isAccountBlacklisted.tokenOwnerAccount", + expectedValue: true, + }, ]; await checkVariables([token], [setup]); }); - it('ept016 should updatePauser when msg.sender blacklisted', async function () { - await token.blacklist(Accounts.tokenOwnerAccount, { from: Accounts.blacklisterAccount }); - await token.updatePauser(Accounts.arbitraryAccount, { from: Accounts.tokenOwnerAccount }); + it("ept016 should updatePauser when msg.sender blacklisted", async function () { + await token.blacklist(Accounts.tokenOwnerAccount, { + from: Accounts.blacklisterAccount, + }); + await token.updatePauser(Accounts.arbitraryAccount, { + from: Accounts.tokenOwnerAccount, + }); var setup = [ - { 'variable': 'pauser', 'expectedValue': Accounts.arbitraryAccount }, - { 'variable': 'isAccountBlacklisted.tokenOwnerAccount', 'expectedValue': true } + { variable: "pauser", expectedValue: Accounts.arbitraryAccount }, + { + variable: "isAccountBlacklisted.tokenOwnerAccount", + expectedValue: true, + }, ]; await checkVariables([token], [setup]); }); - it('ept017 should transferOwnership when msg.sender blacklisted', async function () { - await token.blacklist(Accounts.tokenOwnerAccount, { from: Accounts.blacklisterAccount }); - await token.transferOwnership(Accounts.arbitraryAccount, { from: Accounts.tokenOwnerAccount }); + it("ept017 should transferOwnership when msg.sender blacklisted", async function () { + await token.blacklist(Accounts.tokenOwnerAccount, { + from: Accounts.blacklisterAccount, + }); + await token.transferOwnership(Accounts.arbitraryAccount, { + from: Accounts.tokenOwnerAccount, + }); var setup = [ - { 'variable': 'tokenOwner', 'expectedValue': Accounts.arbitraryAccount }, - { 'variable': 'isAccountBlacklisted.tokenOwnerAccount', 'expectedValue': true } + { variable: "tokenOwner", expectedValue: Accounts.arbitraryAccount }, + { + variable: "isAccountBlacklisted.tokenOwnerAccount", + expectedValue: true, + }, ]; await checkVariables([token], [setup]); }); - it ('ept018 should pause when msg.sender blacklisted', async function() { - await token.blacklist(Accounts.pauserAccount, { from: Accounts.blacklisterAccount }); + it("ept018 should pause when msg.sender blacklisted", async function () { + await token.blacklist(Accounts.pauserAccount, { + from: Accounts.blacklisterAccount, + }); await token.pause({ from: Accounts.pauserAccount }); var setup = [ - { 'variable': 'paused', 'expectedValue': true }, - { 'variable': 'isAccountBlacklisted.pauserAccount', 'expectedValue': true } + { variable: "paused", expectedValue: true }, + { variable: "isAccountBlacklisted.pauserAccount", expectedValue: true }, ]; await checkVariables([token], [setup]); }); - it ('ept019 should unpause when msg.sender blacklisted', async function() { + it("ept019 should unpause when msg.sender blacklisted", async function () { await token.pause({ from: Accounts.pauserAccount }); - var setup = [ - { 'variable': 'paused', 'expectedValue': true } - ]; + var setup = [{ variable: "paused", expectedValue: true }]; await checkVariables([token], [setup]); - await token.blacklist(Accounts.pauserAccount, { from: Accounts.blacklisterAccount }); + await token.blacklist(Accounts.pauserAccount, { + from: Accounts.blacklisterAccount, + }); await token.unpause({ from: Accounts.pauserAccount }); setup = [ - { 'variable': 'isAccountBlacklisted.pauserAccount', 'expectedValue': true } + { variable: "isAccountBlacklisted.pauserAccount", expectedValue: true }, ]; await checkVariables([token], [setup]); }); - it ('ept020 should blacklist when msg.sender blacklisted', async function() { - await token.blacklist(Accounts.blacklisterAccount, { from: Accounts.blacklisterAccount }); - await token.blacklist(Accounts.arbitraryAccount, { from: Accounts.blacklisterAccount }); + it("ept020 should blacklist when msg.sender blacklisted", async function () { + await token.blacklist(Accounts.blacklisterAccount, { + from: Accounts.blacklisterAccount, + }); + await token.blacklist(Accounts.arbitraryAccount, { + from: Accounts.blacklisterAccount, + }); var setup = [ - { 'variable': 'isAccountBlacklisted.blacklisterAccount', 'expectedValue': true }, - { 'variable': 'isAccountBlacklisted.arbitraryAccount', 'expectedValue': true } + { + variable: "isAccountBlacklisted.blacklisterAccount", + expectedValue: true, + }, + { + variable: "isAccountBlacklisted.arbitraryAccount", + expectedValue: true, + }, ]; await checkVariables([token], [setup]); }); - it ('ept021 should unBlacklist when msg.sender blacklisted', async function() { - await token.blacklist(Accounts.blacklisterAccount, { from: Accounts.blacklisterAccount }); + it("ept021 should unBlacklist when msg.sender blacklisted", async function () { + await token.blacklist(Accounts.blacklisterAccount, { + from: Accounts.blacklisterAccount, + }); var setup = [ - { 'variable': 'isAccountBlacklisted.blacklisterAccount', 'expectedValue': true } + { + variable: "isAccountBlacklisted.blacklisterAccount", + expectedValue: true, + }, ]; await checkVariables([token], [setup]); - await token.unBlacklist(Accounts.blacklisterAccount, { from: Accounts.blacklisterAccount }); + await token.unBlacklist(Accounts.blacklisterAccount, { + from: Accounts.blacklisterAccount, + }); await checkVariables([token], [[]]); }); - it('ept022 should upgrade when msg.sender blacklisted', async function () { - await token.blacklist(Accounts.proxyOwnerAccount, { from: Accounts.blacklisterAccount }); + it("ept022 should upgrade when msg.sender blacklisted", async function () { + 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.proxyOwnerAccount', 'expectedValue': true }, + { variable: "proxiedTokenAddress", expectedValue: newRawToken.address }, + { + variable: "isAccountBlacklisted.proxyOwnerAccount", + expectedValue: true, + }, ]; await checkVariables([newToken], [newToken_result]); }); - it ('ept023 should upgrade to blacklisted address', async function() { + it("ept023 should upgrade to blacklisted address", async function () { var newRawToken = await UpgradedFiatToken.new(); - await token.blacklist(newRawToken.address, { from: Accounts.blacklisterAccount }); + await token.blacklist(newRawToken.address, { + from: Accounts.blacklisterAccount, + }); var tokenConfig = await upgradeTo(proxy, newRawToken); var newProxiedToken = tokenConfig.token; var newToken = newProxiedToken; var newToken_result = [ - {'variable': 'proxiedTokenAddress', 'expectedValue': newRawToken.address } + { variable: "proxiedTokenAddress", expectedValue: newRawToken.address }, ]; assert(await newToken.isBlacklisted(newRawToken.address)); await checkVariables([newToken], [newToken_result]); }); - it('ept024 should blacklist a blacklisted address', async function () { - await token.blacklist(Accounts.arbitraryAccount, { from: Accounts.blacklisterAccount }); + it("ept024 should blacklist a blacklisted address", async function () { + await token.blacklist(Accounts.arbitraryAccount, { + from: Accounts.blacklisterAccount, + }); var setup = [ - { 'variable': 'isAccountBlacklisted.arbitraryAccount', 'expectedValue': true } - ]; - await token.blacklist(Accounts.arbitraryAccount, { from: Accounts.blacklisterAccount }); + { + variable: "isAccountBlacklisted.arbitraryAccount", + expectedValue: true, + }, + ]; + await token.blacklist(Accounts.arbitraryAccount, { + from: Accounts.blacklisterAccount, + }); await checkVariables([token], [setup]); }); - it('ept025 should changeAdmin to blacklisted address', async function () { - await token.blacklist(Accounts.arbitraryAccount, { from: Accounts.blacklisterAccount }); - await proxy.changeAdmin(Accounts.arbitraryAccount, { from: Accounts.proxyOwnerAccount }); + it("ept025 should changeAdmin to blacklisted address", async function () { + await token.blacklist(Accounts.arbitraryAccount, { + from: Accounts.blacklisterAccount, + }); + await proxy.changeAdmin(Accounts.arbitraryAccount, { + from: Accounts.proxyOwnerAccount, + }); var result = [ - { 'variable': 'isAccountBlacklisted.arbitraryAccount', 'expectedValue': true }, - { 'variable': 'proxyOwner', 'expectedValue': Accounts.arbitraryAccount }, + { + variable: "isAccountBlacklisted.arbitraryAccount", + expectedValue: true, + }, + { variable: "proxyOwner", expectedValue: Accounts.arbitraryAccount }, ]; await checkVariables([token], [result]); }); - it('ept026 should updateMasterMinter to blacklisted address', async function () { - await token.blacklist(Accounts.arbitraryAccount, { from: Accounts.blacklisterAccount }); - await token.updateMasterMinter(Accounts.arbitraryAccount, { from: Accounts.tokenOwnerAccount }); + it("ept026 should updateMasterMinter to blacklisted address", async function () { + await token.blacklist(Accounts.arbitraryAccount, { + from: Accounts.blacklisterAccount, + }); + await token.updateMasterMinter(Accounts.arbitraryAccount, { + from: Accounts.tokenOwnerAccount, + }); var setup = [ - { 'variable': 'masterMinter', 'expectedValue': Accounts.arbitraryAccount }, - { 'variable': 'isAccountBlacklisted.arbitraryAccount', 'expectedValue': true } + { variable: "masterMinter", expectedValue: Accounts.arbitraryAccount }, + { + variable: "isAccountBlacklisted.arbitraryAccount", + expectedValue: true, + }, ]; await checkVariables([token], [setup]); }); - it('ept027 should updateBlacklister to blacklisted address', async function () { - await token.blacklist(Accounts.arbitraryAccount, { from: Accounts.blacklisterAccount }); - await token.updateBlacklister(Accounts.arbitraryAccount, { from: Accounts.tokenOwnerAccount }); + it("ept027 should updateBlacklister to blacklisted address", async function () { + await token.blacklist(Accounts.arbitraryAccount, { + from: Accounts.blacklisterAccount, + }); + await token.updateBlacklister(Accounts.arbitraryAccount, { + from: Accounts.tokenOwnerAccount, + }); var setup = [ - { 'variable': 'blacklister', 'expectedValue': Accounts.arbitraryAccount }, - { 'variable': 'isAccountBlacklisted.arbitraryAccount', 'expectedValue': true } + { variable: "blacklister", expectedValue: Accounts.arbitraryAccount }, + { + variable: "isAccountBlacklisted.arbitraryAccount", + expectedValue: true, + }, ]; await checkVariables([token], [setup]); }); - it('ept028 should updatePauser to blacklisted address', async function () { - await token.blacklist(Accounts.arbitraryAccount, { from: Accounts.blacklisterAccount }); - await token.updatePauser(Accounts.arbitraryAccount, { from: Accounts.tokenOwnerAccount }); + it("ept028 should updatePauser to blacklisted address", async function () { + await token.blacklist(Accounts.arbitraryAccount, { + from: Accounts.blacklisterAccount, + }); + await token.updatePauser(Accounts.arbitraryAccount, { + from: Accounts.tokenOwnerAccount, + }); var setup = [ - { 'variable': 'pauser', 'expectedValue': Accounts.arbitraryAccount }, - { 'variable': 'isAccountBlacklisted.arbitraryAccount', 'expectedValue': true } + { variable: "pauser", expectedValue: Accounts.arbitraryAccount }, + { + variable: "isAccountBlacklisted.arbitraryAccount", + expectedValue: true, + }, ]; await checkVariables([token], [setup]); }); - it('ept029 should transferOwnership to blacklisted address', async function () { - await token.blacklist(Accounts.arbitraryAccount, { from: Accounts.blacklisterAccount }); - await token.transferOwnership(Accounts.arbitraryAccount, { from: Accounts.tokenOwnerAccount }); + it("ept029 should transferOwnership to blacklisted address", async function () { + await token.blacklist(Accounts.arbitraryAccount, { + from: Accounts.blacklisterAccount, + }); + await token.transferOwnership(Accounts.arbitraryAccount, { + from: Accounts.tokenOwnerAccount, + }); var setup = [ - { 'variable': 'tokenOwner', 'expectedValue': Accounts.arbitraryAccount }, - { 'variable': 'isAccountBlacklisted.arbitraryAccount', 'expectedValue': true } + { variable: "tokenOwner", expectedValue: Accounts.arbitraryAccount }, + { + variable: "isAccountBlacklisted.arbitraryAccount", + expectedValue: true, + }, ]; await checkVariables([token], [setup]); }); - it('ept030 should configureMinter when masterMinter is blacklisted', async function () { - await token.blacklist(Accounts.masterMinterAccount, { from: Accounts.blacklisterAccount }); - await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); + it("ept030 should configureMinter when masterMinter is blacklisted", async function () { + await token.blacklist(Accounts.masterMinterAccount, { + from: Accounts.blacklisterAccount, + }); + await token.configureMinter(Accounts.minterAccount, amount, { + from: Accounts.masterMinterAccount, + }); var result = [ - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) }, - { 'variable': 'isAccountBlacklisted.masterMinterAccount', 'expectedValue': true } + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount), + }, + { + variable: "isAccountBlacklisted.masterMinterAccount", + expectedValue: true, + }, ]; await checkVariables([token], [result]); }); - it('ept032 should configureMinter when minter is blacklisted', async function () { - await token.blacklist(Accounts.minterAccount, { from: Accounts.blacklisterAccount }); - await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); + it("ept032 should configureMinter when minter is blacklisted", async function () { + await token.blacklist(Accounts.minterAccount, { + from: Accounts.blacklisterAccount, + }); + await token.configureMinter(Accounts.minterAccount, amount, { + from: Accounts.masterMinterAccount, + }); var result = [ - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) }, - { 'variable': 'isAccountBlacklisted.minterAccount', 'expectedValue': true }, + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount), + }, + { variable: "isAccountBlacklisted.minterAccount", expectedValue: true }, ]; await checkVariables([token], [result]); }); - it('ept033 should removeMinter when masterMinter is blacklisted', async function() { - await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); - await token.blacklist(Accounts.masterMinterAccount, { from: Accounts.blacklisterAccount }); + it("ept033 should removeMinter when masterMinter is blacklisted", async function () { + await token.configureMinter(Accounts.minterAccount, amount, { + from: Accounts.masterMinterAccount, + }); + await token.blacklist(Accounts.masterMinterAccount, { + from: Accounts.blacklisterAccount, + }); var customVars = [ - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) }, - { 'variable': 'isAccountBlacklisted.masterMinterAccount', 'expectedValue': true }, + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount), + }, + { + variable: "isAccountBlacklisted.masterMinterAccount", + expectedValue: true, + }, ]; await checkVariables([token], [customVars]); - await token.removeMinter(Accounts.minterAccount, { from: Accounts.masterMinterAccount }); + await token.removeMinter(Accounts.minterAccount, { + from: Accounts.masterMinterAccount, + }); customVars = [ - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': false }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(0) }, - { 'variable': 'isAccountBlacklisted.masterMinterAccount', 'expectedValue': true }, + { variable: "isAccountMinter.minterAccount", expectedValue: false }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(0), + }, + { + variable: "isAccountBlacklisted.masterMinterAccount", + expectedValue: true, + }, ]; await checkVariables([token], [customVars]); }); - it('ept034 should removeMinter when minter is blacklisted', async function() { - await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); - await token.blacklist(Accounts.minterAccount, { from: Accounts.blacklisterAccount }); + it("ept034 should removeMinter when minter is blacklisted", async function () { + await token.configureMinter(Accounts.minterAccount, amount, { + from: Accounts.masterMinterAccount, + }); + await token.blacklist(Accounts.minterAccount, { + from: Accounts.blacklisterAccount, + }); var customVars = [ - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) }, - { 'variable': 'isAccountBlacklisted.minterAccount', 'expectedValue': true }, + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount), + }, + { variable: "isAccountBlacklisted.minterAccount", expectedValue: true }, ]; await checkVariables([token], [customVars]); - await token.removeMinter(Accounts.minterAccount, { from: Accounts.masterMinterAccount }); + await token.removeMinter(Accounts.minterAccount, { + from: Accounts.masterMinterAccount, + }); customVars = [ - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': false }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(0) }, - { 'variable': 'isAccountBlacklisted.minterAccount', 'expectedValue': true }, + { variable: "isAccountMinter.minterAccount", expectedValue: false }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(0), + }, + { variable: "isAccountBlacklisted.minterAccount", expectedValue: true }, ]; await checkVariables([token], [customVars]); }); - it('ept035 should unBlacklist while contract is paused', async function() { - await token.pause({from: Accounts.pauserAccount}); - await token.blacklist(Accounts.arbitraryAccount, { from: Accounts.blacklisterAccount }); + it("ept035 should unBlacklist while contract is paused", async function () { + await token.pause({ from: Accounts.pauserAccount }); + await token.blacklist(Accounts.arbitraryAccount, { + from: Accounts.blacklisterAccount, + }); var customVars = [ - { 'variable': 'isAccountBlacklisted.arbitraryAccount', 'expectedValue': true }, - { 'variable': 'paused', 'expectedValue': true}, + { + variable: "isAccountBlacklisted.arbitraryAccount", + expectedValue: true, + }, + { variable: "paused", expectedValue: true }, ]; await checkVariables([token], [customVars]); - await token.unBlacklist(Accounts.arbitraryAccount, { from: Accounts.blacklisterAccount }); - customVars = [ - { 'variable': 'paused', 'expectedValue': true}, - ]; + await token.unBlacklist(Accounts.arbitraryAccount, { + from: Accounts.blacklisterAccount, + }); + customVars = [{ variable: "paused", expectedValue: true }]; await checkVariables([token], [customVars]); }); - it('ept036 should blacklist while contract is paused', async function() { - await token.pause({from: Accounts.pauserAccount}); - var customVars = [ - { 'variable': 'paused', 'expectedValue': true}, - ]; + it("ept036 should blacklist while contract is paused", async function () { + await token.pause({ from: Accounts.pauserAccount }); + var customVars = [{ variable: "paused", expectedValue: true }]; await checkVariables([token], [customVars]); - await token.blacklist(Accounts.arbitraryAccount, { from: Accounts.blacklisterAccount }); + await token.blacklist(Accounts.arbitraryAccount, { + from: Accounts.blacklisterAccount, + }); customVars = [ - { 'variable': 'isAccountBlacklisted.arbitraryAccount', 'expectedValue': true }, - { 'variable': 'paused', 'expectedValue': true}, + { + variable: "isAccountBlacklisted.arbitraryAccount", + expectedValue: true, + }, + { variable: "paused", expectedValue: true }, ]; await checkVariables([token], [customVars]); }); - it('ept037 should pause while contract is paused', async function() { - await token.pause({from: Accounts.pauserAccount}); - var customVars = [ - { 'variable': 'paused', 'expectedValue': true}, - ]; + it("ept037 should pause while contract is paused", async function () { + await token.pause({ from: Accounts.pauserAccount }); + var customVars = [{ variable: "paused", expectedValue: true }]; await checkVariables([token], [customVars]); - await token.pause({from: Accounts.pauserAccount}); - customVars = [ - { 'variable': 'paused', 'expectedValue': true}, - ]; + await token.pause({ from: Accounts.pauserAccount }); + customVars = [{ variable: "paused", expectedValue: true }]; await checkVariables([token], [customVars]); }); +} - } - -var testWrapper = require('./../TestWrapper'); -testWrapper.execute('FiatToken_ExtendedPositiveTests', run_tests); +var testWrapper = require("./../TestWrapper"); +testWrapper.execute("FiatToken_ExtendedPositiveTests", run_tests); module.exports = { run_tests: run_tests, -} +}; diff --git a/test/minting/MintP0_ArgumentTests.js b/test/minting/MintP0_ArgumentTests.js index bdfd240a6..498db0598 100644 --- a/test/minting/MintP0_ArgumentTests.js +++ b/test/minting/MintP0_ArgumentTests.js @@ -1,10 +1,10 @@ -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 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 tokenUtils = require('../TokenTestUtils.js'); +var tokenUtils = require("../TokenTestUtils.js"); var newBigNumber = tokenUtils.newBigNumber; var checkMINTp0 = tokenUtils.checkMINTp0; var expectRevert = tokenUtils.expectRevert; @@ -13,246 +13,472 @@ var expectError = tokenUtils.expectError; var bigZero = tokenUtils.bigZero; var maxAmount = tokenUtils.maxAmount; -var clone = require('clone'); +var clone = require("clone"); -var mintUtils = require('../MintControllerUtils.js'); -var AccountUtils = require('../AccountUtils.js'); +var mintUtils = require("../MintControllerUtils.js"); +var AccountUtils = require("../AccountUtils.js"); var Accounts = AccountUtils.Accounts; var getAccountState = AccountUtils.getAccountState; var MintControllerState = AccountUtils.MintControllerState; var addressEquals = AccountUtils.addressEquals; -var initializeTokenWithProxyAndMintController = mintUtils.initializeTokenWithProxyAndMintController; +var initializeTokenWithProxyAndMintController = + mintUtils.initializeTokenWithProxyAndMintController; var checkMintControllerState = mintUtils.checkMintControllerState; var zeroAddress = "0x0000000000000000000000000000000000000000"; -var maxAmount = "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"; +var maxAmount = + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"; async function run_tests_MintController(newToken, accounts) { - run_MINT_tests(newToken, MintController, accounts); + run_MINT_tests(newToken, MintController, accounts); } async function run_tests_MasterMinter(newToken, accounts) { - run_MINT_tests(newToken, MasterMinter, 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 }]; + 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, }); - - it('arg000 transferOwnership(msg.sender) works', async function () { - await mintController.transferOwnership(Accounts.mintOwnerAccount, {from: Accounts.mintOwnerAccount}); - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + 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, }); - - it('arg001 transferOwnership(0) reverts', async function () { - await expectRevert(mintController.transferOwnership(zeroAddress, {from: Accounts.mintOwnerAccount})); + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("arg003 configureController(0, M) throws", async function () { + await expectError( + mintController.configureController(zeroAddress, Accounts.minterAccount, { + from: Accounts.mintOwnerAccount, + }), + "Controller must be a non-zero address" + ); + }); + + 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 expectError( + mintController.configureController( + Accounts.controller1Account, + zeroAddress, + { from: Accounts.mintOwnerAccount } + ), + "Worker must be a non-zero address" + ); + }); + + it("arg007 removeController(0) throws", async function () { + // expect no changes + await expectError( + mintController.removeController(zeroAddress, { + from: Accounts.mintOwnerAccount, + }), + "Controller must be a non-zero address" + ); + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("arg008 setMinterManager(0) works", async function () { + await mintController.setMinterManager(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]); + expectedMintControllerState.minterManager = zeroAddress; + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("arg009 setMinterManager(oldMinterManager) works", async function () { + await mintController.setMinterManager(token.address, { + from: Accounts.mintOwnerAccount, }); - - it('arg003 configureController(0, M) throws', async function () { - await expectError(mintController.configureController(zeroAddress, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}), - "Controller must be a non-zero address"); + 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, }); - - 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]); + 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, }); - - 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]); + 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, }); - it('arg006 configureController(C, 0) throws', async function () { - await expectError(mintController.configureController(Accounts.controller1Account, zeroAddress, {from: Accounts - .mintOwnerAccount}), "Worker must be a non-zero address"); + expectedMintControllerState.controllers["controller1Account"] = + Accounts.minterAccount; + expectedTokenState.push( + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(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, }); - - it('arg007 removeController(0) throws', async function () { - // expect no changes - await expectError(mintController.removeController(zeroAddress, {from: Accounts.mintOwnerAccount}), "Controller must be a non-zero address"); - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + await mintController.configureMinter(oldAllowance, { + from: Accounts.controller1Account, }); - it('arg008 setMinterManager(0) works', async function () { - await mintController.setMinterManager(zeroAddress, {from: Accounts.mintOwnerAccount}); - expectedMintControllerState.minterManager = zeroAddress; - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + expectedMintControllerState.controllers["controller1Account"] = + Accounts.minterAccount; + expectedTokenState.push( + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(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, }); - 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]); + expectedMintControllerState.controllers["controller1Account"] = + Accounts.minterAccount; + expectedTokenState.push( + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(maxAmount), + } + ); + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("arg015 incrementMinterAllowance(0) throws", async function () { + await mintController.configureController( + Accounts.controller1Account, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + await expectError( + mintController.incrementMinterAllowance(0, { + from: Accounts.controller1Account, + }), + "Allowance increment must be greater than 0" + ); + }); + + 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, }); - - 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]); + await mintController.incrementMinterAllowance(amount, { + from: Accounts.controller1Account, }); - 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]); + expectedMintControllerState.controllers["controller1Account"] = + Accounts.minterAccount; + expectedTokenState.push( + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(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, }); - - 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': newBigNumber(0) } - ); - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + await expectJump( + mintController.incrementMinterAllowance(maxAmount, { + from: Accounts.controller1Account, + }) + ); + }); + + it("arg018 incrementMinterAllowance(BIG) throws", async function () { + await mintController.configureController( + Accounts.controller1Account, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + await mintController.configureMinter(maxAmount, { + from: Accounts.controller1Account, }); - - 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': newBigNumber(oldAllowance) } - ); - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + await expectJump( + mintController.incrementMinterAllowance(1, { + from: Accounts.controller1Account, + }) + ); + }); + + it("arg019 configureController(0, 0) throws", async function () { + await expectError( + mintController.configureController(zeroAddress, zeroAddress, { + from: Accounts.mintOwnerAccount, + }), + "Controller must be a non-zero address" + ); + }); + + it("arg020 removeController(C) works", async function () { + // make controller1Account a controller + await mintController.configureController( + Accounts.controller1Account, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + var actualMinter = await mintController.getWorker( + Accounts.controller1Account + ); + addressEquals(Accounts.minterAccount, actualMinter); + + // remove controller1Account + await mintController.removeController(Accounts.controller1Account, { + from: Accounts.mintOwnerAccount, }); - - 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': newBigNumber(maxAmount) } - ); - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + actualMinter = await mintController.getWorker(Accounts.controller1Account); + addressEquals(actualMinter, zeroAddress); + }); + + it("arg021 removeController throws if worker is already address(0)", async function () { + // make controller1Account a controller + await mintController.configureController( + Accounts.controller1Account, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + var actualMinter = await mintController.getWorker( + Accounts.controller1Account + ); + addressEquals(Accounts.minterAccount, actualMinter); + + // remove controller1Account + await mintController.removeController(Accounts.controller1Account, { + from: Accounts.mintOwnerAccount, }); - - it('arg015 incrementMinterAllowance(0) throws', async function () { - await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - await expectError(mintController.incrementMinterAllowance(0, {from: Accounts.controller1Account}), "Allowance increment must be greater than 0"); + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + actualMinter = await mintController.getWorker(Accounts.controller1Account); + addressEquals(actualMinter, zeroAddress); + + // attempting to remove the controller1Account again should throw because the worker is already set to address(0). + await expectError( + mintController.removeController(Accounts.controller1Account, { + from: Accounts.mintOwnerAccount, + }), + "Worker must be a non-zero address" + ); + }); + + it("arg022 decrementMinterAllowance(oldAllowance) sets the allowance to 0", async function () { + var amount = 897; + await mintController.configureController( + Accounts.controller1Account, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + await mintController.configureMinter(amount, { + from: Accounts.controller1Account, }); - - 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': newBigNumber(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 incrementMinterAllowance(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})); - }); - - - it('arg019 configureController(0, 0) throws', async function () { - await expectError(mintController.configureController(zeroAddress, zeroAddress, {from: Accounts.mintOwnerAccount}), - "Controller must be a non-zero address"); - }); - - it('arg020 removeController(C) works', async function() { - // make controller1Account a controller - await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - var actualMinter = await mintController.getWorker(Accounts.controller1Account); - addressEquals(Accounts.minterAccount, actualMinter); - - // remove controller1Account - await mintController.removeController(Accounts.controller1Account, {from : Accounts.mintOwnerAccount}); - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); - actualMinter = await mintController.getWorker(Accounts.controller1Account); - addressEquals(actualMinter, zeroAddress); + await mintController.decrementMinterAllowance(amount, { + from: Accounts.controller1Account, }); - it('arg021 removeController throws if worker is already address(0)', async function () { - // make controller1Account a controller - await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - var actualMinter = await mintController.getWorker(Accounts.controller1Account); - addressEquals(Accounts.minterAccount, actualMinter); - - // remove controller1Account - await mintController.removeController(Accounts.controller1Account, {from : Accounts.mintOwnerAccount}); - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); - actualMinter = await mintController.getWorker(Accounts.controller1Account); - addressEquals(actualMinter, zeroAddress); - - // attempting to remove the controller1Account again should throw because the worker is already set to address(0). - await expectError(mintController.removeController(Accounts.controller1Account, {from: Accounts.mintOwnerAccount}), - "Worker must be a non-zero address"); - }) - - it('arg022 decrementMinterAllowance(oldAllowance) sets the allowance to 0', async function () { - var amount = 897; - await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - await mintController.configureMinter(amount, {from: Accounts.controller1Account}); - await mintController.decrementMinterAllowance(amount, {from: Accounts.controller1Account}); - - expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; - expectedTokenState.push( - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': bigZero } - ); - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + expectedMintControllerState.controllers["controller1Account"] = + Accounts.minterAccount; + expectedTokenState.push( + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { variable: "minterAllowance.minterAccount", expectedValue: bigZero } + ); + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("arg023 decrementMinterAllowance(MIN) sets the allowance to 0", async function () { + var amount = 0; + await mintController.configureController( + Accounts.controller1Account, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + await mintController.configureMinter(amount, { + from: Accounts.controller1Account, }); - - it('arg023 decrementMinterAllowance(MIN) sets the allowance to 0', async function () { - var amount = 0; - await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - await mintController.configureMinter(amount, {from: Accounts.controller1Account}); - await mintController.decrementMinterAllowance(1, {from: Accounts.controller1Account}); - expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; - expectedTokenState.push( - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': bigZero } - ); - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + await mintController.decrementMinterAllowance(1, { + from: Accounts.controller1Account, }); - - it('arg024 decrementMinterAllowance(0) throws', async function () { - await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - await expectError(mintController.decrementMinterAllowance(0, {from: Accounts.controller1Account}), "Allowance decrement must be greater than 0"); - }); - + expectedMintControllerState.controllers["controller1Account"] = + Accounts.minterAccount; + expectedTokenState.push( + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { variable: "minterAllowance.minterAccount", expectedValue: bigZero } + ); + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("arg024 decrementMinterAllowance(0) throws", async function () { + await mintController.configureController( + Accounts.controller1Account, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + await expectError( + mintController.decrementMinterAllowance(0, { + from: Accounts.controller1Account, + }), + "Allowance decrement must be greater than 0" + ); + }); } -var testWrapper = require('./../TestWrapper'); -testWrapper.execute('MINTp0_ArgumentTests MintController', run_tests_MintController); -testWrapper.execute('MINTp0_ArgumentTests MasterMinter', run_tests_MasterMinter); +var testWrapper = require("./../TestWrapper"); +testWrapper.execute( + "MINTp0_ArgumentTests MintController", + run_tests_MintController +); +testWrapper.execute( + "MINTp0_ArgumentTests MasterMinter", + run_tests_MasterMinter +); diff --git a/test/minting2/MintControllerTests.js b/test/minting2/MintControllerTests.js index 8d22c34b9..5f4bcd7fe 100644 --- a/test/minting2/MintControllerTests.js +++ b/test/minting2/MintControllerTests.js @@ -1,186 +1,338 @@ -var MintController = artifacts.require('minting/MintController'); +var MintController = artifacts.require("minting/MintController"); -var tokenUtils = require('./../TokenTestUtils.js'); +var tokenUtils = require("./../TokenTestUtils.js"); var newBigNumber = tokenUtils.newBigNumber; var checkMINTp0 = tokenUtils.checkMINTp0; var expectRevert = tokenUtils.expectRevert; var expectError = tokenUtils.expectError; var bigZero = tokenUtils.bigZero; -var clone = require('clone'); +var clone = require("clone"); -var mintUtils = require('./../MintControllerUtils.js'); -var AccountUtils = require('./../AccountUtils.js'); +var mintUtils = require("./../MintControllerUtils.js"); +var AccountUtils = require("./../AccountUtils.js"); var Accounts = AccountUtils.Accounts; var MintControllerState = AccountUtils.MintControllerState; -var initializeTokenWithProxyAndMintController = mintUtils.initializeTokenWithProxyAndMintController; +var initializeTokenWithProxyAndMintController = + mintUtils.initializeTokenWithProxyAndMintController; var checkMintControllerState = mintUtils.checkMintControllerState; async function run_tests(newToken, accounts) { + beforeEach("Make fresh token contract", async function () { + rawToken = await newToken(); + tokenConfig = await initializeTokenWithProxyAndMintController( + rawToken, + MintController + ); + token = tokenConfig.token; + mintController = tokenConfig.mintController; + expectedMintControllerState = clone(tokenConfig.customState); + expectedTokenState = [ + { variable: "masterMinter", expectedValue: mintController.address }, + ]; + }); - beforeEach('Make fresh token contract', async function () { - rawToken = await newToken(); - tokenConfig = await initializeTokenWithProxyAndMintController(rawToken, MintController); - token = tokenConfig.token; - mintController = tokenConfig.mintController; - expectedMintControllerState = clone(tokenConfig.customState); - expectedTokenState = [{ 'variable': 'masterMinter', 'expectedValue': mintController.address }]; + it("should mint through mint controller", async function () { + var amount = 5000; + await mintController.configureController( + Accounts.controller1Account, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + await mintController.configureMinter(amount, { + from: Accounts.controller1Account, }); + expectedMintControllerState.controllers["controller1Account"] = + Accounts.minterAccount; - it('should mint through mint controller', async function () { - var amount = 5000; - await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - await mintController.configureMinter(amount, {from: Accounts.controller1Account}); - expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; - - await token.mint(Accounts.arbitraryAccount, amount, {from: Accounts.minterAccount}); - expectedTokenState.push( - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'balances.arbitraryAccount', 'expectedValue': newBigNumber(amount) }, - { 'variable': 'totalSupply', 'expectedValue': newBigNumber(amount)} - ); - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + await token.mint(Accounts.arbitraryAccount, amount, { + from: Accounts.minterAccount, }); + expectedTokenState.push( + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "balances.arbitraryAccount", + expectedValue: newBigNumber(amount), + }, + { variable: "totalSupply", expectedValue: newBigNumber(amount) } + ); + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); - it('initial state', async function () { - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + it("initial state", async function () { + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("only owner configures controller", async function () { + await expectRevert( + mintController.configureController( + Accounts.controller1Account, + Accounts.minterAccount, + { from: Accounts.minterAccount } + ) + ); + }); + + it("remove controller", async function () { + var amount = 5000; + await mintController.configureController( + Accounts.controller1Account, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + expectedMintControllerState.controllers["controller1Account"] = + Accounts.minterAccount; + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + + await mintController.removeController(Accounts.controller1Account, { + from: Accounts.mintOwnerAccount, + }); + expectedMintControllerState.controllers["controller1Account"] = bigZero; + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("only owner can remove controller", async function () { + await expectRevert( + mintController.removeController(Accounts.controller1Account, { + from: Accounts.minterAccount, + }) + ); + }); + + it("sets token", async function () { + await mintController.setMinterManager(mintController.address, { + from: Accounts.mintOwnerAccount, }); + expectedMintControllerState.minterManager = mintController.address; + checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("only owner sets token", async function () { + await expectRevert( + mintController.setMinterManager(mintController.address, { + from: Accounts.minterAccount, + }) + ); + }); + + it("remove minter", async function () { + // create a minter + var amount = 500; + await mintController.configureController( + Accounts.controller1Account, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + await mintController.configureMinter(amount, { + from: Accounts.controller1Account, + }); + expectedMintControllerState.controllers["controller1Account"] = + Accounts.minterAccount; + expectedTokenState.push( + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount), + } + ); + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + + // remove minter + await mintController.removeMinter({ from: Accounts.controller1Account }); + expectedTokenState = [ + { variable: "masterMinter", expectedValue: mintController.address }, + ]; + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); - it('only owner configures controller', async function () { - await expectRevert(mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.minterAccount})); - }); + it("only controller removes a minter", async function () { + await expectError( + mintController.removeMinter({ from: Accounts.controller1Account }), + "The value of controllers[msg.sender] must be non-zero" + ); + }); - it('remove controller', async function () { - var amount = 5000; - await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + it("only controller configures a minter", async function () { + await expectError( + mintController.configureMinter(0, { from: Accounts.controller1Account }), + "The value of controllers[msg.sender] must be non-zero" + ); + }); - await mintController.removeController(Accounts.controller1Account, {from: Accounts.mintOwnerAccount}); - expectedMintControllerState.controllers['controller1Account'] = bigZero; - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + it("increment minter allowance", async function () { + // configure controller & minter + var amount = 500; + await mintController.configureController( + Accounts.controller1Account, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + await mintController.configureMinter(amount, { + from: Accounts.controller1Account, }); + expectedMintControllerState.controllers["controller1Account"] = + Accounts.minterAccount; + expectedTokenState.push( + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount), + } + ); + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); - it('only owner can remove controller', async function () { - await expectRevert(mintController.removeController(Accounts.controller1Account, {from: Accounts.minterAccount})); + // increment minter allowance + await mintController.incrementMinterAllowance(amount, { + from: Accounts.controller1Account, }); + expectedTokenState = [ + { variable: "masterMinter", expectedValue: mintController.address }, + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount * 2), + }, + ]; + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("only controller increments allowance", async function () { + await expectError( + mintController.incrementMinterAllowance(0, { + from: Accounts.controller1Account, + }), + "The value of controllers[msg.sender] must be non-zero" + ); + }); + + it("only active minters can have allowance incremented", async function () { + // configure controller but not minter + var amount = 500; + await mintController.configureController( + Accounts.controller1Account, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + expectedMintControllerState.controllers["controller1Account"] = + Accounts.minterAccount; + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + + // increment minter allowance + await expectError( + mintController.incrementMinterAllowance(amount, { + from: Accounts.controller1Account, + }), + "Can only increment allowance for minters in minterManager" + ); + }); + + it("decrement minter allowance", async function () { + // configure controller & minter + var amount = 500; + await mintController.configureController( + Accounts.controller1Account, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + await mintController.configureMinter(amount, { + from: Accounts.controller1Account, + }); + expectedMintControllerState.controllers["controller1Account"] = + Accounts.minterAccount; + expectedTokenState.push( + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount), + } + ); + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + + // decrement minter allowance + await mintController.decrementMinterAllowance(amount, { + from: Accounts.controller1Account, + }); + expectedTokenState = [ + { variable: "masterMinter", expectedValue: mintController.address }, + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { variable: "minterAllowance.minterAccount", expectedValue: bigZero }, + ]; + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("only controller decrements allowance", async function () { + await expectError( + mintController.decrementMinterAllowance(0, { + from: Accounts.controller1Account, + }), + "The value of controllers[msg.sender] must be non-zero" + ); + }); + + it("only active minters can have allowance decremented", async function () { + // configure controller but not minter + var amount = 500; + await mintController.configureController( + Accounts.controller1Account, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + expectedMintControllerState.controllers["controller1Account"] = + Accounts.minterAccount; + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); - it('sets token', async function () { - await mintController.setMinterManager(mintController.address, {from: Accounts.mintOwnerAccount}); - expectedMintControllerState.minterManager = mintController.address; - checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); - }); - - it('only owner sets token', async function () { - await expectRevert(mintController.setMinterManager(mintController.address, {from: Accounts.minterAccount})); - }); - - it('remove minter', async function() { - // create a minter - var amount = 500; - await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - await mintController.configureMinter(amount, {from: Accounts.controller1Account}); - expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; - expectedTokenState.push( - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) }, - ); - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); - - // remove minter - await mintController.removeMinter({from: Accounts.controller1Account}); - expectedTokenState = [ - { 'variable': 'masterMinter', 'expectedValue': mintController.address }, - ]; - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); - }); - - it('only controller removes a minter', async function () { - await expectError(mintController.removeMinter({from: Accounts.controller1Account}), "The value of controllers[msg.sender] must be non-zero"); - }); - - it('only controller configures a minter', async function () { - await expectError(mintController.configureMinter(0, {from: Accounts.controller1Account}), "The value of controllers[msg.sender] must be non-zero"); - }); - - it('increment minter allowance', async function () { - // configure controller & minter - var amount = 500; - await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - await mintController.configureMinter(amount, {from: Accounts.controller1Account}); - expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; - expectedTokenState.push( - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) }, - ); - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); - - // increment minter allowance - await mintController.incrementMinterAllowance(amount, {from: Accounts.controller1Account}); - expectedTokenState = [ - { 'variable': 'masterMinter', 'expectedValue': mintController.address }, - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount*2) }, - ]; - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); - }); - - it('only controller increments allowance', async function () { - await expectError(mintController.incrementMinterAllowance(0, {from: Accounts.controller1Account}), "The value of controllers[msg.sender] must be non-zero"); - }); - - it('only active minters can have allowance incremented', async function () { - // configure controller but not minter - var amount = 500; - await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - expectedMintControllerState.controllers['controller1Account']= Accounts.minterAccount; - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); - - // increment minter allowance - await expectError(mintController.incrementMinterAllowance(amount, {from: Accounts.controller1Account}), "Can only increment allowance for minters in minterManager"); - }); - - it('decrement minter allowance', async function () { - // configure controller & minter - var amount = 500; - await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - await mintController.configureMinter(amount, {from: Accounts.controller1Account}); - expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; - expectedTokenState.push( - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) }, - ); - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); - - // decrement minter allowance - await mintController.decrementMinterAllowance(amount, {from: Accounts.controller1Account}); - expectedTokenState = [ - { 'variable': 'masterMinter', 'expectedValue': mintController.address }, - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': bigZero }, - ]; - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); - }); - - it('only controller decrements allowance', async function () { - await expectError(mintController.decrementMinterAllowance(0, {from: Accounts.controller1Account}), "The value of controllers[msg.sender] must be non-zero"); - }); - - it('only active minters can have allowance decremented', async function () { - // configure controller but not minter - var amount = 500; - await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - expectedMintControllerState.controllers['controller1Account']= Accounts.minterAccount; - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); - - // decrement minter allowance - await expectError(mintController.decrementMinterAllowance(amount, {from: Accounts.controller1Account}), "Can only decrement allowance for minters in minterManager"); - }); + // decrement minter allowance + await expectError( + mintController.decrementMinterAllowance(amount, { + from: Accounts.controller1Account, + }), + "Can only decrement allowance for minters in minterManager" + ); + }); } -var testWrapper = require('../TestWrapper'); -testWrapper.execute('MintController_Tests', run_tests); +var testWrapper = require("../TestWrapper"); +testWrapper.execute("MintController_Tests", run_tests); module.exports = { run_tests: run_tests, -} \ No newline at end of file +}; diff --git a/test/minting2/MintP0_ABITests.js b/test/minting2/MintP0_ABITests.js index 9cb9bfe18..6f8236f60 100644 --- a/test/minting2/MintP0_ABITests.js +++ b/test/minting2/MintP0_ABITests.js @@ -1,74 +1,87 @@ -var MintController = artifacts.require('minting/MintController'); -var MasterMinter = artifacts.require('minting/MasterMinter'); -var FiatToken = artifacts.require('FiatTokenV1'); +var MintController = artifacts.require("minting/MintController"); +var MasterMinter = artifacts.require("minting/MasterMinter"); +var FiatToken = artifacts.require("FiatTokenV1"); -var tokenUtils = require('../TokenTestUtils.js'); +var tokenUtils = require("../TokenTestUtils.js"); var checkMINTp0 = tokenUtils.checkMINTp0; var expectError = tokenUtils.expectError; var bigZero = tokenUtils.bigZero; var maxAmount = tokenUtils.maxAmount; var solidityErrors = tokenUtils.solidityErrors; -var clone = require('clone'); +var clone = require("clone"); -var mintUtils = require('../MintControllerUtils.js'); -var AccountUtils = require('../AccountUtils.js'); +var mintUtils = require("../MintControllerUtils.js"); +var AccountUtils = require("../AccountUtils.js"); var Accounts = AccountUtils.Accounts; var AccountPrivateKeys = AccountUtils.AccountPrivateKeys; var getAccountState = AccountUtils.getAccountState; var MintControllerState = AccountUtils.MintControllerState; -var initializeTokenWithProxyAndMintController = mintUtils.initializeTokenWithProxyAndMintController; +var initializeTokenWithProxyAndMintController = + mintUtils.initializeTokenWithProxyAndMintController; var checkMintControllerState = mintUtils.checkMintControllerState; -var abiUtils = require('../ABIUtils.js'); +var abiUtils = require("../ABIUtils.js"); var makeRawTransaction = abiUtils.makeRawTransaction; var sendRawTransaction = abiUtils.sendRawTransaction; var msgData = abiUtils.msgData; var msgData1 = abiUtils.msgData1; async function run_tests_MintController(newToken, accounts) { - run_MINT_tests(newToken, MintController, accounts); + run_MINT_tests(newToken, MintController, accounts); } async function run_tests_MasterMinter(newToken, accounts) { - run_MINT_tests(newToken, MasterMinter, 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 }, + ]; + }); - 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('abi100 internal_setMinterAllowance is internal', async function () { - await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - let badData = msgData1('internal_setMinterAllowance(address,uint256)', Accounts.controller1Account, 569); - let raw = makeRawTransaction( - badData, - Accounts.mintOwnerAccount, - AccountPrivateKeys.mintOwnerPrivateKey, - mintController.address); - await expectError(sendRawTransaction(raw), solidityErrors.argumentType); - }); - - it('abi101 setOwner is internal', async function () { - let badData = msgData('setOwner(address)', Accounts.arbitraryAccount); - let raw = makeRawTransaction( - badData, - Accounts.mintOwnerAccount, - AccountPrivateKeys.mintOwnerPrivateKey, - mintController.address); - await expectError(sendRawTransaction(raw), solidityErrors.argumentType); - }); + it("abi100 internal_setMinterAllowance is internal", async function () { + await mintController.configureController( + Accounts.controller1Account, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + let badData = msgData1( + "internal_setMinterAllowance(address,uint256)", + Accounts.controller1Account, + 569 + ); + let raw = makeRawTransaction( + badData, + Accounts.mintOwnerAccount, + AccountPrivateKeys.mintOwnerPrivateKey, + mintController.address + ); + await expectError(sendRawTransaction(raw), solidityErrors.argumentType); + }); + it("abi101 setOwner is internal", async function () { + let badData = msgData("setOwner(address)", Accounts.arbitraryAccount); + let raw = makeRawTransaction( + badData, + Accounts.mintOwnerAccount, + AccountPrivateKeys.mintOwnerPrivateKey, + mintController.address + ); + await expectError(sendRawTransaction(raw), solidityErrors.argumentType); + }); } -var testWrapper = require('./../TestWrapper'); -testWrapper.execute('MINTp0_ABITests MintController', run_tests_MintController); -testWrapper.execute('MINTp0_ABITests MasterMinter', run_tests_MasterMinter); - +var testWrapper = require("./../TestWrapper"); +testWrapper.execute("MINTp0_ABITests MintController", run_tests_MintController); +testWrapper.execute("MINTp0_ABITests MasterMinter", run_tests_MasterMinter); diff --git a/test/minting3/MintP0_BasicTests.js b/test/minting3/MintP0_BasicTests.js index c20d0999c..6a07d024c 100644 --- a/test/minting3/MintP0_BasicTests.js +++ b/test/minting3/MintP0_BasicTests.js @@ -1,8 +1,8 @@ -var MintController = artifacts.require('minting/MintController'); -var MasterMinter = artifacts.require('minting/MasterMinter'); -var FiatToken = artifacts.require('FiatTokenV1'); +var MintController = artifacts.require("minting/MintController"); +var MasterMinter = artifacts.require("minting/MasterMinter"); +var FiatToken = artifacts.require("FiatTokenV1"); -var tokenUtils = require('../TokenTestUtils.js'); +var tokenUtils = require("../TokenTestUtils.js"); var newBigNumber = tokenUtils.newBigNumber; var checkMINTp0 = tokenUtils.checkMINTp0; var expectRevert = tokenUtils.expectRevert; @@ -11,743 +11,1412 @@ var expectError = tokenUtils.expectError; var bigZero = tokenUtils.bigZero; var maxAmount = tokenUtils.maxAmount; -var clone = require('clone'); +var clone = require("clone"); -var mintUtils = require('../MintControllerUtils.js'); -var AccountUtils = require('../AccountUtils.js'); +var mintUtils = require("../MintControllerUtils.js"); +var AccountUtils = require("../AccountUtils.js"); var Accounts = AccountUtils.Accounts; var getAccountState = AccountUtils.getAccountState; var MintControllerState = AccountUtils.MintControllerState; var addressEquals = AccountUtils.addressEquals; -var initializeTokenWithProxyAndMintController = mintUtils.initializeTokenWithProxyAndMintController; +var initializeTokenWithProxyAndMintController = + mintUtils.initializeTokenWithProxyAndMintController; var checkMintControllerState = mintUtils.checkMintControllerState; var zeroAddress = "0x0000000000000000000000000000000000000000"; async function run_tests_MintController(newToken, accounts) { - run_MINT_tests(newToken, MintController, accounts); + run_MINT_tests(newToken, MintController, accounts); } async function run_tests_MasterMinter(newToken, accounts) { - run_MINT_tests(newToken, MasterMinter, 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 }]; + 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("bt001 Constructor - owner is msg.sender", async function () { + var newMintController = await MintController.new(token.address, { + from: Accounts.arbitraryAccount, }); + var owner = await newMintController.owner(); + assert.isTrue(addressEquals(owner, Accounts.arbitraryAccount)); + }); - it('bt001 Constructor - owner is msg.sender', async function () { - var newMintController = await MintController.new(token.address, {from: Accounts.arbitraryAccount}); - var owner = await newMintController.owner(); - assert.isTrue(addressEquals(owner, Accounts.arbitraryAccount)); + it("bt002 transferOwnership works when owner is msg.sender", async function () { + await mintController.transferOwnership(Accounts.arbitraryAccount, { + from: Accounts.mintOwnerAccount, }); - - it('bt002 transferOwnership works when owner is msg.sender', async function () { - await mintController.transferOwnership(Accounts.arbitraryAccount, {from: Accounts.mintOwnerAccount}); - expectedMintControllerState.owner = Accounts.arbitraryAccount; - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + expectedMintControllerState.owner = Accounts.arbitraryAccount; + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("bt003 transferOwnership reverts when owner is not msg.sender", async function () { + await expectRevert( + mintController.transferOwnership(Accounts.arbitraryAccount, { + from: Accounts.arbitraryAccount, + }) + ); + }); + + it("bt004 configureController works when owner is msg.sender", async function () { + await mintController.configureController( + Accounts.controller1Account, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + expectedMintControllerState.controllers["controller1Account"] = + Accounts.minterAccount; + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("bt005 configureController reverts when owner is not msg.sender", async function () { + await expectRevert( + mintController.configureController( + Accounts.controller1Account, + Accounts.minterAccount, + { from: Accounts.arbitraryAccount } + ) + ); + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("bt006 setMinterManager works when owner is msg.sender", async function () { + await mintController.setMinterManager(Accounts.arbitraryAccount, { + from: Accounts.mintOwnerAccount, }); - - it('bt003 transferOwnership reverts when owner is not msg.sender', async function () { - await expectRevert(mintController.transferOwnership(Accounts.arbitraryAccount, {from: Accounts.arbitraryAccount})); + expectedMintControllerState.minterManager = Accounts.arbitraryAccount; + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("bt007 setMinterManager reverts when owner is not msg.sender", async function () { + await expectRevert( + mintController.setMinterManager(Accounts.arbitraryAccount, { + from: Accounts.arbitraryAccount, + }) + ); + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("bt008 removeController works when owner is msg.sender", async function () { + // add a controller + await mintController.configureController( + Accounts.controller1Account, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + expectedMintControllerState.controllers["controller1Account"] = + Accounts.minterAccount; + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + + // now remove it + await mintController.removeController(Accounts.controller1Account, { + from: Accounts.mintOwnerAccount, }); - - it('bt004 configureController works when owner is msg.sender', async function () { - await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + expectedMintControllerState.controllers["controller1Account"] = zeroAddress; + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("bt009 removeController reverts when owner is not msg.sender", async function () { + // add a controller + await mintController.configureController( + Accounts.controller1Account, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + expectedMintControllerState.controllers["controller1Account"] = + Accounts.minterAccount; + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + + // fail to remove it + await expectRevert( + mintController.removeController(Accounts.controller1Account, { + from: Accounts.arbitraryAccount, + }) + ); + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("bt010 removeMinter reverts when msg.sender is not a controller", async function () { + await expectError( + mintController.removeMinter({ from: Accounts.controller1Account }), + "The value of controllers[msg.sender] must be non-zero" + ); + }); + + it("bt011 removeMinter sets minters[M] to 0", async function () { + // add a minter + var amount = 789; + await mintController.configureController( + Accounts.controller1Account, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + await mintController.configureMinter(amount, { + from: Accounts.controller1Account, }); - it('bt005 configureController reverts when owner is not msg.sender', async function () { - await expectRevert(mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.arbitraryAccount})); - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + expectedMintControllerState.controllers["controller1Account"] = + Accounts.minterAccount; + expectedTokenState.push( + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount), + } + ); + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + + // remove minter + await mintController.removeMinter({ from: Accounts.controller1Account }); + expectedTokenState.pop(); + expectedTokenState.pop(); + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("bt012 configureMinter reverts when msg.sender is not a controller", async function () { + await expectError( + mintController.configureMinter(50, { from: Accounts.controller1Account }), + "The value of controllers[msg.sender] must be non-zero" + ); + }); + + it("bt013 configureMinter works when controllers[msg.sender]=M", async function () { + // add a controller + await mintController.configureController( + Accounts.controller1Account, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + + // now configure minter + var amount = 6789; + await mintController.configureMinter(amount, { + from: Accounts.controller1Account, }); - - it('bt006 setMinterManager works when owner is msg.sender', async function () { - await mintController.setMinterManager(Accounts.arbitraryAccount, {from: Accounts.mintOwnerAccount}); - expectedMintControllerState.minterManager = Accounts.arbitraryAccount; - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + expectedMintControllerState.controllers["controller1Account"] = + Accounts.minterAccount; + expectedTokenState.push( + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount), + } + ); + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("bt014 incrementMinterAllowance reverts if msg.sender is not a controller", async function () { + await expectError( + mintController.incrementMinterAllowance(50, { + from: Accounts.controller1Account, + }), + "The value of controllers[msg.sender] must be non-zero" + ); + }); + + it("bt015 incrementMinterAllowance works when controllers[msg.sender]=M", async function () { + await mintController.configureController( + Accounts.controller1Account, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + await mintController.configureMinter(0, { + from: Accounts.controller1Account, }); - it('bt007 setMinterManager reverts when owner is not msg.sender', async function () { - await expectRevert(mintController.setMinterManager(Accounts.arbitraryAccount, {from: Accounts.arbitraryAccount})); - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + // now configure minter + var amount = 6789; + await mintController.incrementMinterAllowance(amount, { + from: Accounts.controller1Account, }); - - it('bt008 removeController works when owner is msg.sender', async function () { - // add a controller - await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); - - // now remove it - await mintController.removeController(Accounts.controller1Account, {from: Accounts.mintOwnerAccount}); - expectedMintControllerState.controllers['controller1Account'] = zeroAddress; - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + expectedMintControllerState.controllers["controller1Account"] = + Accounts.minterAccount; + expectedTokenState.push( + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount), + } + ); + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("bt016 Constructor sets all controllers to 0", async function () { + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("bt017 removeController reverts when controllers[C] is 0", async function () { + // "remove" a controller that does not exist + await expectError( + mintController.removeController(Accounts.controller1Account, { + from: Accounts.mintOwnerAccount, + }), + "Worker must be a non-zero address" + ); + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("bt018 removeController removes an arbitrary controller", async function () { + // add a controller + await mintController.configureController( + Accounts.controller1Account, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + expectedMintControllerState.controllers["controller1Account"] = + Accounts.minterAccount; + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + + // now remove it + await mintController.removeController(Accounts.controller1Account, { + from: Accounts.mintOwnerAccount, }); - - it('bt009 removeController reverts when owner is not msg.sender', async function () { - // add a controller - await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); - - // fail to remove it - await expectRevert(mintController.removeController(Accounts.controller1Account, {from: Accounts.arbitraryAccount})); - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); - }); - - it('bt010 removeMinter reverts when msg.sender is not a controller', async function () { - await expectError(mintController.removeMinter({from: Accounts.controller1Account}), "The value of controllers[msg.sender] must be non-zero"); + expectedMintControllerState.controllers["controller1Account"] = zeroAddress; + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("bt019 configureController works when controller[C]=0", async function () { + // note: this is a duplicate of bt004 + await mintController.configureController( + Accounts.controller1Account, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + expectedMintControllerState.controllers["controller1Account"] = + Accounts.minterAccount; + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("bt020 configureController works when controller[C] != 0", async function () { + // set controllers[controller1Account]=minterAccount + await mintController.configureController( + Accounts.controller1Account, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + expectedMintControllerState.controllers["controller1Account"] = + Accounts.minterAccount; + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + + // now set controllers[controller1Account]=arbitraryAccount + await mintController.configureController( + Accounts.controller1Account, + Accounts.arbitraryAccount, + { from: Accounts.mintOwnerAccount } + ); + expectedMintControllerState.controllers["controller1Account"] = + Accounts.arbitraryAccount; + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("bt021 configureController(C,C) works", async function () { + await mintController.configureController( + Accounts.controller1Account, + Accounts.controller1Account, + { from: Accounts.mintOwnerAccount } + ); + expectedMintControllerState.controllers["controller1Account"] = + Accounts.controller1Account; + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("bt022 configureController works when setting controller[C]=msg.sender", async function () { + await mintController.configureController( + Accounts.mintOwnerAccount, + Accounts.controller1Account, + { from: Accounts.mintOwnerAccount } + ); + expectedMintControllerState.controllers["controller1Account"] = + Accounts.mintOwnerAccount; + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("bt023 configureController(C, newM) works when controller[C]=newM", async function () { + // set controllers[controller1Account]=minterAccount + await mintController.configureController( + Accounts.controller1Account, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + expectedMintControllerState.controllers["controller1Account"] = + Accounts.minterAccount; + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + + // now set controllers[controller1Account]=minterAccount + await mintController.configureController( + Accounts.controller1Account, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("bt024 Constructor sets minterManager", async function () { + var minterManagerAddress = await mintController.getMinterManager(); + assert.isTrue(addressEquals(token.address, minterManagerAddress)); + }); + + it("bt026 setMinterManager(x) works when existing minterManager != 0", async function () { + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + + await mintController.setMinterManager(Accounts.arbitraryAccount, { + from: Accounts.mintOwnerAccount, }); - - it('bt011 removeMinter sets minters[M] to 0', async function () { - // add a minter - var amount = 789; - await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - await mintController.configureMinter(amount, {from: Accounts.controller1Account}); - - expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; - expectedTokenState.push( - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) } - ); - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); - - // remove minter - await mintController.removeMinter({from: Accounts.controller1Account}); - expectedTokenState.pop(); - expectedTokenState.pop(); - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + expectedMintControllerState.minterManager = Accounts.arbitraryAccount; + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("bt027 setMinterManager(x) works when x = msg.sender", async function () { + await mintController.setMinterManager(Accounts.mintOwnerAccount, { + from: Accounts.mintOwnerAccount, }); - - it('bt012 configureMinter reverts when msg.sender is not a controller', async function () { - await expectError(mintController.configureMinter(50, {from: Accounts.controller1Account}), "The value of controllers[msg.sender] must be non-zero"); + expectedMintControllerState.minterManager = Accounts.mintOwnerAccount; + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("bt028 setMinterManager(x) works when x = minterManager", async function () { + var minterManagerAddress = await mintController.getMinterManager(); + await mintController.setMinterManager(minterManagerAddress, { + from: Accounts.mintOwnerAccount, }); - - it('bt013 configureMinter works when controllers[msg.sender]=M', async function () { - // add a controller - await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - - // now configure minter - var amount = 6789; - await mintController.configureMinter(amount, {from: Accounts.controller1Account}); - expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; - expectedTokenState.push( - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) } - ); - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("bt030 removeMinter reverts when minterManager is 0", async function () { + // set minterManager + var minterManagerAddress = await mintController.getMinterManager(); + await mintController.setMinterManager(minterManagerAddress, { + from: Accounts.mintOwnerAccount, }); - - it('bt014 incrementMinterAllowance reverts if msg.sender is not a controller', async function () { - await expectError(mintController.incrementMinterAllowance(50, {from: Accounts.controller1Account}), "The value of controllers[msg.sender] must be non-zero"); + expectedMintControllerState.minterManager = minterManagerAddress; + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + + // configure minter will fail with any args + await expectRevert( + mintController.removeMinter({ from: Accounts.controller1Account }) + ); + }); + + it("bt031 removeMinter reverts when minterManager is a user account", async function () { + // set minterManager to user account + await mintController.setMinterManager(Accounts.arbitraryAccount, { + from: Accounts.mintOwnerAccount, }); - - it('bt015 incrementMinterAllowance works when controllers[msg.sender]=M', async function () { - await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - await mintController.configureMinter(0, {from: Accounts.controller1Account}); - - // now configure minter - var amount = 6789; - await mintController.incrementMinterAllowance(amount, {from: Accounts.controller1Account}); - expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; - expectedTokenState.push( - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) } - ); - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + expectedMintControllerState.minterManager = Accounts.arbitraryAccount; + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + + // configure minter will fail with any args + await expectRevert( + mintController.removeMinter({ from: Accounts.controller1Account }) + ); + }); + + it("bt032 removeMinter works when minterManager is ok", async function () { + // add a minter + var amount = 3; + await mintController.configureController( + Accounts.controller1Account, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + await mintController.configureMinter(amount, { + from: Accounts.controller1Account, }); - - it('bt016 Constructor sets all controllers to 0', async function () { - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + expectedMintControllerState.controllers["controller1Account"] = + Accounts.minterAccount; + expectedTokenState.push( + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount), + } + ); + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + + // remove minter + await mintController.removeMinter({ from: Accounts.controller1Account }); + expectedTokenState.pop(); + expectedTokenState.pop(); + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("bt034 configureMinter reverts when minterManager is a user account", async function () { + // set minterManager to user account + await mintController.setMinterManager(Accounts.arbitraryAccount, { + from: Accounts.mintOwnerAccount, }); - - it('bt017 removeController reverts when controllers[C] is 0', async function () { - // "remove" a controller that does not exist - await expectError(mintController.removeController(Accounts.controller1Account, {from: Accounts.mintOwnerAccount}), "Worker must be a non-zero address"); - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + expectedMintControllerState.minterManager = Accounts.arbitraryAccount; + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + + // configure minter will fail with any args + await expectRevert( + mintController.configureMinter(50, { from: Accounts.controller1Account }) + ); + }); + + it("bt035 configureMinter works when minterManager is ok", async function () { + var amount = 456; + await mintController.configureController( + Accounts.controller1Account, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + await mintController.configureMinter(amount, { + from: Accounts.controller1Account, }); - - it('bt018 removeController removes an arbitrary controller', async function () { - // add a controller - await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); - - // now remove it - await mintController.removeController(Accounts.controller1Account, {from: Accounts.mintOwnerAccount}); - expectedMintControllerState.controllers['controller1Account'] = zeroAddress; - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + expectedMintControllerState.controllers["controller1Account"] = + Accounts.minterAccount; + expectedTokenState.push( + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount), + } + ); + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("bt037 incrementMinterAllowance reverts when minterManager is a user account", async function () { + // set minterManager to user account + await mintController.setMinterManager(Accounts.arbitraryAccount, { + from: Accounts.mintOwnerAccount, }); - - it('bt019 configureController works when controller[C]=0', async function () { - // note: this is a duplicate of bt004 - await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + expectedMintControllerState.minterManager = Accounts.arbitraryAccount; + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + + // incrementMinterAllowance will fail with any args + await expectRevert( + mintController.incrementMinterAllowance(50, { + from: Accounts.controller1Account, + }) + ); + }); + + it("bt038 incrementMinterAllowance works when minterManager is ok", async function () { + await mintController.configureController( + Accounts.controller1Account, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + await mintController.configureMinter(0, { + from: Accounts.controller1Account, }); - it('bt020 configureController works when controller[C] != 0', async function () { - // set controllers[controller1Account]=minterAccount - await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); - - // now set controllers[controller1Account]=arbitraryAccount - await mintController.configureController(Accounts.controller1Account, Accounts.arbitraryAccount, {from: Accounts.mintOwnerAccount}); - expectedMintControllerState.controllers['controller1Account'] = Accounts.arbitraryAccount; - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + // now incrementMinterAllowance + var amount = 45; + await mintController.incrementMinterAllowance(amount, { + from: Accounts.controller1Account, }); - - it('bt021 configureController(C,C) works', async function () { - await mintController.configureController(Accounts.controller1Account, Accounts.controller1Account, {from: Accounts.mintOwnerAccount}); - expectedMintControllerState.controllers['controller1Account'] = Accounts.controller1Account; - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + expectedMintControllerState.controllers["controller1Account"] = + Accounts.minterAccount; + expectedTokenState.push( + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount), + } + ); + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("bt039 configureMinter(M, amt) works when minterManager.isMinter(M)=false", async function () { + var amount = 64; + await mintController.configureController( + Accounts.controller1Account, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + + var minterManager = await FiatToken.at( + await mintController.getMinterManager() + ); + var isMinter = await minterManager.isMinter(Accounts.minterAccount); + assert.isFalse(isMinter); + + await mintController.configureMinter(amount, { + from: Accounts.controller1Account, }); - - it('bt022 configureController works when setting controller[C]=msg.sender', async function () { - await mintController.configureController(Accounts.mintOwnerAccount, Accounts.controller1Account, {from: Accounts.mintOwnerAccount}); - expectedMintControllerState.controllers['controller1Account'] = Accounts.mintOwnerAccount; - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + expectedMintControllerState.controllers["controller1Account"] = + Accounts.minterAccount; + expectedTokenState.push( + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount), + } + ); + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("bt040 configureMinter(M, amt) works when minterManager.isMinter(M)=true", async function () { + var amount = 64; + await mintController.configureController( + Accounts.controller1Account, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + await mintController.configureMinter(0, { + from: Accounts.controller1Account, }); - it('bt023 configureController(C, newM) works when controller[C]=newM', async function () { - // set controllers[controller1Account]=minterAccount - await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + var minterManager = await FiatToken.at( + await mintController.getMinterManager() + ); + var isMinter = await minterManager.isMinter(Accounts.minterAccount); + assert.isTrue(isMinter); - // now set controllers[controller1Account]=minterAccount - await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + await mintController.configureMinter(amount, { + from: Accounts.controller1Account, }); - - it('bt024 Constructor sets minterManager', async function () { - var minterManagerAddress = await mintController.getMinterManager(); - assert.isTrue(addressEquals(token.address, minterManagerAddress)); + expectedMintControllerState.controllers["controller1Account"] = + Accounts.minterAccount; + expectedTokenState.push( + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount), + } + ); + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("bt041 removeMinter(M) works when minterManager.isMinter(M)=false", async function () { + var amount = 64; + await mintController.configureController( + Accounts.controller1Account, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + + var minterManager = await FiatToken.at( + await mintController.getMinterManager() + ); + var isMinter = await minterManager.isMinter(Accounts.minterAccount); + assert.isFalse(isMinter); + + await mintController.removeMinter({ from: Accounts.controller1Account }); + expectedMintControllerState.controllers["controller1Account"] = + Accounts.minterAccount; + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("bt042 removeMinter(M) works when minterManager.isMinter(M)=true", async function () { + var amount = 64; + await mintController.configureController( + Accounts.controller1Account, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + await mintController.configureMinter(0, { + from: Accounts.controller1Account, }); - it('bt026 setMinterManager(x) works when existing minterManager != 0', async function () { - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); - - await mintController.setMinterManager(Accounts.arbitraryAccount, {from: Accounts.mintOwnerAccount}); - expectedMintControllerState.minterManager = Accounts.arbitraryAccount; - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + var minterManager = await FiatToken.at( + await mintController.getMinterManager() + ); + var isMinter = await minterManager.isMinter(Accounts.minterAccount); + assert.isTrue(isMinter); + + await mintController.removeMinter({ from: Accounts.controller1Account }); + expectedMintControllerState.controllers["controller1Account"] = + Accounts.minterAccount; + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("bt043 incrementMinterAllowance(M, amt) reverts when minterManager.isMinter(M)=false", async function () { + var amount = 64; + await mintController.configureController( + Accounts.controller1Account, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + + var minterManager = await FiatToken.at( + await mintController.getMinterManager() + ); + var isMinter = await minterManager.isMinter(Accounts.minterAccount); + assert.isFalse(isMinter); + + await expectError( + mintController.incrementMinterAllowance(amount, { + from: Accounts.controller1Account, + }), + "Can only increment allowance for minters in minterManager" + ); + expectedMintControllerState.controllers["controller1Account"] = + Accounts.minterAccount; + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("bt044 incrementMinterAllowance(M, amt) works when minterManager.isMinter(M)=true", async function () { + var amount = 65424; + await mintController.configureController( + Accounts.controller1Account, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + await mintController.configureMinter(0, { + from: Accounts.controller1Account, }); - it('bt027 setMinterManager(x) works when x = msg.sender', async function () { - await mintController.setMinterManager(Accounts.mintOwnerAccount, {from: Accounts.mintOwnerAccount}); - expectedMintControllerState.minterManager = Accounts.mintOwnerAccount; - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); - }); + var minterManager = await FiatToken.at( + await mintController.getMinterManager() + ); + var isMinter = await minterManager.isMinter(Accounts.minterAccount); + assert.isTrue(isMinter); - it('bt028 setMinterManager(x) works when x = minterManager', async function () { - var minterManagerAddress = await mintController.getMinterManager(); - await mintController.setMinterManager(minterManagerAddress, {from: Accounts.mintOwnerAccount}); - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + await mintController.incrementMinterAllowance(amount, { + from: Accounts.controller1Account, }); - - it('bt030 removeMinter reverts when minterManager is 0', async function () { - // set minterManager - var minterManagerAddress = await mintController.getMinterManager(); - await mintController.setMinterManager(minterManagerAddress, {from:Accounts.mintOwnerAccount}); - expectedMintControllerState.minterManager = minterManagerAddress; - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); - - // configure minter will fail with any args - await(expectRevert(mintController.removeMinter({from: Accounts.controller1Account}))); + expectedMintControllerState.controllers["controller1Account"] = + Accounts.minterAccount; + expectedTokenState.push( + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount), + } + ); + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("bt045 constructor - minterManager.isMinter[ALL] is false", async function () { + var minterManager = await FiatToken.at( + await mintController.getMinterManager() + ); + + var isMinterMappingEval = async function (accountAddress) { + return await minterManager.isMinter(accountAddress); + }; + + var isMinterResults = await getAccountState(isMinterMappingEval, Accounts); + for (var account in Accounts) { + assert.isFalse(isMinterResults[account]); + } + }); + + it("bt046 constructor - minterManager.minterAllowance[ALL] = 0", async function () { + var minterManager = await FiatToken.at( + await mintController.getMinterManager() + ); + + var minterAllowanceMapping = async function (accountAddress) { + return await minterManager.minterAllowance(accountAddress); + }; + + var minterAllowanceResults = await getAccountState( + minterAllowanceMapping, + Accounts + ); + for (var account in Accounts) { + assert(minterAllowanceResults[account].isZero()); + } + }); + + it("bt047 incrementMinterAllowance(M,amt) works when minterAllowance is 0", async function () { + var amount = 64; + await mintController.configureController( + Accounts.controller1Account, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + await mintController.configureMinter(0, { + from: Accounts.controller1Account, }); - it('bt031 removeMinter reverts when minterManager is a user account', async function () { - // set minterManager to user account - await mintController.setMinterManager(Accounts.arbitraryAccount, {from:Accounts.mintOwnerAccount}); - expectedMintControllerState.minterManager = Accounts.arbitraryAccount; - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + var minterManager = await FiatToken.at( + await mintController.getMinterManager() + ); + var minterAllowance = await minterManager.minterAllowance( + Accounts.minterAccount + ); + assert(minterAllowance.isZero()); - // configure minter will fail with any args - await(expectRevert(mintController.removeMinter({from: Accounts.controller1Account}))); + await mintController.incrementMinterAllowance(amount, { + from: Accounts.controller1Account, }); - - it('bt032 removeMinter works when minterManager is ok', async function () { - // add a minter - var amount = 3; - await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - await mintController.configureMinter(amount, {from: Accounts.controller1Account}); - - expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; - expectedTokenState.push( - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) } - ); - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); - - // remove minter - await mintController.removeMinter({from: Accounts.controller1Account}); - expectedTokenState.pop(); - expectedTokenState.pop(); - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + expectedMintControllerState.controllers["controller1Account"] = + Accounts.minterAccount; + expectedTokenState.push( + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount), + } + ); + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("bt048 incrementMinterAllowance(M, amt) works when minterAllowance > 0", async function () { + var initialAmount = 987341; + var incrementAmount = 64; + await mintController.configureController( + Accounts.controller1Account, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + await mintController.configureMinter(initialAmount, { + from: Accounts.controller1Account, }); - it('bt034 configureMinter reverts when minterManager is a user account', async function () { - // set minterManager to user account - await mintController.setMinterManager(Accounts.arbitraryAccount, {from:Accounts.mintOwnerAccount}); - expectedMintControllerState.minterManager = Accounts.arbitraryAccount; - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + var minterManager = await FiatToken.at( + await mintController.getMinterManager() + ); + var minterAllowance = await minterManager.minterAllowance( + Accounts.minterAccount + ); + assert(minterAllowance.cmp(newBigNumber(initialAmount)) == 0); - // configure minter will fail with any args - await(expectRevert(mintController.configureMinter(50, {from: Accounts.controller1Account}))); + await mintController.incrementMinterAllowance(incrementAmount, { + from: Accounts.controller1Account, }); - - it('bt035 configureMinter works when minterManager is ok', async function () { - var amount = 456; - await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - await mintController.configureMinter(amount, {from: Accounts.controller1Account}); - expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; - expectedTokenState.push( - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) } - ); - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + expectedMintControllerState.controllers["controller1Account"] = + Accounts.minterAccount; + expectedTokenState.push( + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(initialAmount + incrementAmount), + } + ); + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("bt049 incrementMinterAllowance(M,amt) reverts when minterAllowance[M] + amt > 2^256", async function () { + var initialAmount = + "0x" + newBigNumber(maxAmount).sub(newBigNumber(45)).toString(16, 64); + var incrementAmount = 64; + await mintController.configureController( + Accounts.controller1Account, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + await mintController.configureMinter(initialAmount, { + from: Accounts.controller1Account, }); - it('bt037 incrementMinterAllowance reverts when minterManager is a user account', async function () { - // set minterManager to user account - await mintController.setMinterManager(Accounts.arbitraryAccount, {from:Accounts.mintOwnerAccount}); - expectedMintControllerState.minterManager = Accounts.arbitraryAccount; - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); - - // incrementMinterAllowance will fail with any args - await(expectRevert(mintController.incrementMinterAllowance(50, {from: Accounts.controller1Account}))); + expectedMintControllerState.controllers["controller1Account"] = + Accounts.minterAccount; + expectedTokenState.push( + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(initialAmount), + } + ); + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + + await expectJump( + mintController.incrementMinterAllowance(incrementAmount, { + from: Accounts.controller1Account, + }) + ); + }); + + it("bt050 configureMinter(M,amt) works when minterAllowance=0", async function () { + var amount = 64; + await mintController.configureController( + Accounts.controller1Account, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + await mintController.configureMinter(0, { + from: Accounts.controller1Account, }); - it('bt038 incrementMinterAllowance works when minterManager is ok', async function () { - await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - await mintController.configureMinter(0, {from: Accounts.controller1Account}); + var minterManager = await FiatToken.at( + await mintController.getMinterManager() + ); + var minterAllowance = await minterManager.minterAllowance( + Accounts.minterAccount + ); + assert(minterAllowance.cmp(newBigNumber(0)) == 0); - // now incrementMinterAllowance - var amount = 45; - await mintController.incrementMinterAllowance(amount, {from: Accounts.controller1Account}); - expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; - expectedTokenState.push( - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) } - ); - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + await mintController.configureMinter(amount, { + from: Accounts.controller1Account, }); - - it('bt039 configureMinter(M, amt) works when minterManager.isMinter(M)=false', async function () { - var amount = 64; - await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - - var minterManager = await FiatToken.at(await mintController.getMinterManager()); - var isMinter = await minterManager.isMinter(Accounts.minterAccount); - assert.isFalse(isMinter); - - await mintController.configureMinter(amount, {from: Accounts.controller1Account}); - expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; - expectedTokenState.push( - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) } - ); - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + expectedMintControllerState.controllers["controller1Account"] = + Accounts.minterAccount; + expectedTokenState.push( + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount), + } + ); + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("bt051 configureMinter(M,amt) works when minterAllowance>0", async function () { + var amount = 64; + await mintController.configureController( + Accounts.controller1Account, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + await mintController.configureMinter(amount, { + from: Accounts.controller1Account, }); - it('bt040 configureMinter(M, amt) works when minterManager.isMinter(M)=true', async function () { - var amount = 64; - await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - await mintController.configureMinter(0, {from: Accounts.controller1Account}); - - var minterManager = await FiatToken.at(await mintController.getMinterManager()); - var isMinter = await minterManager.isMinter(Accounts.minterAccount); - assert.isTrue(isMinter); - - await mintController.configureMinter(amount, {from: Accounts.controller1Account}); - expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; - expectedTokenState.push( - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) } - ); - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); - }); - - it('bt041 removeMinter(M) works when minterManager.isMinter(M)=false', async function () { - var amount = 64; - await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - - var minterManager = await FiatToken.at(await mintController.getMinterManager()); - var isMinter = await minterManager.isMinter(Accounts.minterAccount); - assert.isFalse(isMinter); + var minterManager = await FiatToken.at( + await mintController.getMinterManager() + ); + var minterAllowance = await minterManager.minterAllowance( + Accounts.minterAccount + ); + assert(minterAllowance.cmp(newBigNumber(amount)) == 0); - await mintController.removeMinter({from: Accounts.controller1Account}); - expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + await mintController.configureMinter(2 * amount, { + from: Accounts.controller1Account, }); - - it('bt042 removeMinter(M) works when minterManager.isMinter(M)=true', async function () { - var amount = 64; - await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - await mintController.configureMinter(0, {from: Accounts.controller1Account}); - - var minterManager = await FiatToken.at(await mintController.getMinterManager()); - var isMinter = await minterManager.isMinter(Accounts.minterAccount); - assert.isTrue(isMinter); - - await mintController.removeMinter({from: Accounts.controller1Account}); - expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + expectedMintControllerState.controllers["controller1Account"] = + Accounts.minterAccount; + expectedTokenState.push( + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(2 * amount), + } + ); + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("bt052 configureMinter(M,amt) works when amt+minterAllowance > 2^256", async function () { + var amount = 64; + var minterAllowance = maxAmount; + await mintController.configureController( + Accounts.controller1Account, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + await mintController.configureMinter(maxAmount, { + from: Accounts.controller1Account, }); - it('bt043 incrementMinterAllowance(M, amt) reverts when minterManager.isMinter(M)=false', async function () { - var amount = 64; - await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - - var minterManager = await FiatToken.at(await mintController.getMinterManager()); - var isMinter = await minterManager.isMinter(Accounts.minterAccount); - assert.isFalse(isMinter); - - await expectError(mintController.incrementMinterAllowance(amount, {from: Accounts.controller1Account}), "Can only increment allowance for minters in minterManager"); - expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + await mintController.configureMinter(amount, { + from: Accounts.controller1Account, }); - - it('bt044 incrementMinterAllowance(M, amt) works when minterManager.isMinter(M)=true', async function () { - var amount = 65424; - await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - await mintController.configureMinter(0, {from: Accounts.controller1Account}); - - var minterManager = await FiatToken.at(await mintController.getMinterManager()); - var isMinter = await minterManager.isMinter(Accounts.minterAccount); - assert.isTrue(isMinter); - - await mintController.incrementMinterAllowance(amount, {from: Accounts.controller1Account}); - expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; - expectedTokenState.push( - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) } - ); - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + expectedMintControllerState.controllers["controller1Account"] = + Accounts.minterAccount; + expectedTokenState.push( + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount), + } + ); + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("bt053 removeMinter works when the minterAllowance is 0", async function () { + var amount = 64; + await mintController.configureController( + Accounts.controller1Account, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + await mintController.configureMinter(0, { + from: Accounts.controller1Account, }); - it('bt045 constructor - minterManager.isMinter[ALL] is false', async function () { - var minterManager = await FiatToken.at(await mintController.getMinterManager()); - - var isMinterMappingEval = async function(accountAddress) { - return await minterManager.isMinter(accountAddress); - }; - - var isMinterResults = await getAccountState(isMinterMappingEval, Accounts); - for(var account in Accounts) { - assert.isFalse(isMinterResults[account]); - } + var minterManager = await FiatToken.at( + await mintController.getMinterManager() + ); + var minterAllowance = await minterManager.minterAllowance( + Accounts.minterAccount + ); + assert(minterAllowance.isZero()); + + await mintController.removeMinter({ from: Accounts.controller1Account }); + expectedMintControllerState.controllers["controller1Account"] = + Accounts.minterAccount; + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("bt054 removeMinter works when the minterAllowance is not zero", async function () { + var amount = 64; + await mintController.configureController( + Accounts.controller1Account, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + await mintController.configureMinter(amount, { + from: Accounts.controller1Account, }); - it('bt046 constructor - minterManager.minterAllowance[ALL] = 0', async function () { - var minterManager = await FiatToken.at(await mintController.getMinterManager()); - - var minterAllowanceMapping = async function(accountAddress) { - return await minterManager.minterAllowance(accountAddress); - }; - - var minterAllowanceResults = await getAccountState(minterAllowanceMapping, Accounts); - for(var account in Accounts) { - assert(minterAllowanceResults[account].isZero()); - } + var minterManager = await FiatToken.at( + await mintController.getMinterManager() + ); + var minterAllowance = await minterManager.minterAllowance( + Accounts.minterAccount + ); + assert(minterAllowance.cmp(newBigNumber(amount)) == 0); + + await mintController.removeMinter({ from: Accounts.controller1Account }); + expectedMintControllerState.controllers["controller1Account"] = + Accounts.minterAccount; + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("bt055 removeMinter works when the minterAllowance is big", async function () { + var amount = maxAmount; + await mintController.configureController( + Accounts.controller1Account, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + await mintController.configureMinter(maxAmount, { + from: Accounts.controller1Account, }); - it('bt047 incrementMinterAllowance(M,amt) works when minterAllowance is 0', async function () { - var amount = 64; - await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - await mintController.configureMinter(0, {from: Accounts.controller1Account}); - - var minterManager = await FiatToken.at(await mintController.getMinterManager()); - var minterAllowance = await minterManager.minterAllowance(Accounts.minterAccount); - assert(minterAllowance.isZero()); - - await mintController.incrementMinterAllowance(amount, {from: Accounts.controller1Account}); - expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; - expectedTokenState.push( - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) } - ); - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + await mintController.removeMinter({ from: Accounts.controller1Account }); + expectedMintControllerState.controllers["controller1Account"] = + Accounts.minterAccount; + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("bt056 decrementMinterAllowance reverts if msg.sender is not a controller", async function () { + await expectError( + mintController.decrementMinterAllowance(0, { + from: Accounts.controller1Account, + }), + "The value of controllers[msg.sender] must be non-zero" + ); + }); + + it("bt057 decrementMinterAllowance works when controllers[msg.sender]=M", async function () { + await mintController.configureController( + Accounts.controller1Account, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + await mintController.configureMinter(6789, { + from: Accounts.controller1Account, }); - it('bt048 incrementMinterAllowance(M, amt) works when minterAllowance > 0', async function () { - var initialAmount = 987341; - var incrementAmount = 64; - await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - await mintController.configureMinter(initialAmount, {from: Accounts.controller1Account}); - - var minterManager = await FiatToken.at(await mintController.getMinterManager()); - var minterAllowance = await minterManager.minterAllowance(Accounts.minterAccount); - assert(minterAllowance.cmp(newBigNumber(initialAmount))==0); - - await mintController.incrementMinterAllowance(incrementAmount, {from: Accounts.controller1Account}); - expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; - expectedTokenState.push( - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(initialAmount + incrementAmount) } - ); - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + // now configure minter + var amount = 1; + await mintController.decrementMinterAllowance(amount, { + from: Accounts.controller1Account, }); - - it('bt049 incrementMinterAllowance(M,amt) reverts when minterAllowance[M] + amt > 2^256', async function () { - var initialAmount = "0x" + newBigNumber(maxAmount).sub(newBigNumber(45)).toString(16,64); - var incrementAmount = 64; - await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - await mintController.configureMinter(initialAmount, {from: Accounts.controller1Account}); - - expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; - expectedTokenState.push( - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(initialAmount) } - ); - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); - - await expectJump(mintController.incrementMinterAllowance(incrementAmount, {from: Accounts.controller1Account})); - + expectedMintControllerState.controllers["controller1Account"] = + Accounts.minterAccount; + expectedTokenState.push( + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(6788), + } + ); + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("bt058 decrementMinterAllowance reverts when minterManager is 0", async function () { + // set minterManager to zero + await mintController.setMinterManager(zeroAddress, { + from: Accounts.mintOwnerAccount, }); - - it('bt050 configureMinter(M,amt) works when minterAllowance=0', async function () { - var amount = 64; - await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - await mintController.configureMinter(0, {from: Accounts.controller1Account}); - - var minterManager = await FiatToken.at(await mintController.getMinterManager()); - var minterAllowance = await minterManager.minterAllowance(Accounts.minterAccount); - assert(minterAllowance.cmp(newBigNumber(0))==0); - - await mintController.configureMinter(amount, {from: Accounts.controller1Account}); - expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; - expectedTokenState.push( - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) } - ); - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + expectedMintControllerState.minterManager = zeroAddress; + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + + // decrementMinterAllowance will fail with any args + await expectRevert( + mintController.decrementMinterAllowance(1, { + from: Accounts.controller1Account, + }) + ); + }); + + it("bt059 decrementMinterAllowance reverts when minterManager is a user account", async function () { + // set minterManager to user account + await mintController.setMinterManager(Accounts.arbitraryAccount, { + from: Accounts.mintOwnerAccount, }); - - it('bt051 configureMinter(M,amt) works when minterAllowance>0', async function () { - var amount = 64; - await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - await mintController.configureMinter(amount, {from: Accounts.controller1Account}); - - var minterManager = await FiatToken.at(await mintController.getMinterManager()); - var minterAllowance = await minterManager.minterAllowance(Accounts.minterAccount); - assert(minterAllowance.cmp(newBigNumber(amount))==0); - - await mintController.configureMinter(2* amount, {from: Accounts.controller1Account}); - expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; - expectedTokenState.push( - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(2*amount) } - ); - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + expectedMintControllerState.minterManager = Accounts.arbitraryAccount; + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + + // decrementMinterAllowance will fail with any args + await expectRevert( + mintController.decrementMinterAllowance(1, { + from: Accounts.controller1Account, + }) + ); + }); + + it("bt060 decrementMinterAllowance works when minterManager is ok", async function () { + await mintController.configureController( + Accounts.controller1Account, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + await mintController.configureMinter(45, { + from: Accounts.controller1Account, }); - it('bt052 configureMinter(M,amt) works when amt+minterAllowance > 2^256', async function () { - var amount = 64; - var minterAllowance = maxAmount; - await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - await mintController.configureMinter(maxAmount, {from: Accounts.controller1Account}); - - await mintController.configureMinter(amount, {from: Accounts.controller1Account}); - expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; - expectedTokenState.push( - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) } - ); - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + // now decrementMinterAllowance + var amount = 45; + await mintController.decrementMinterAllowance(amount, { + from: Accounts.controller1Account, }); - - it('bt053 removeMinter works when the minterAllowance is 0', async function () { - var amount = 64; - await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - await mintController.configureMinter(0, {from: Accounts.controller1Account}); - - var minterManager = await FiatToken.at(await mintController.getMinterManager()); - var minterAllowance = await minterManager.minterAllowance(Accounts.minterAccount); - assert(minterAllowance.isZero()); - - await mintController.removeMinter({from: Accounts.controller1Account}); - expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + expectedMintControllerState.controllers["controller1Account"] = + Accounts.minterAccount; + expectedTokenState.push( + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { variable: "minterAllowance.minterAccount", expectedValue: bigZero } + ); + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("bt061 decrementMinterAllowance(M, amt) reverts when minterManager.isMinter(M)=false", async function () { + var amount = 1; + await mintController.configureController( + Accounts.controller1Account, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + + var minterManager = await FiatToken.at( + await mintController.getMinterManager() + ); + var isMinter = await minterManager.isMinter(Accounts.minterAccount); + + assert.isFalse(isMinter); + + await expectError( + mintController.decrementMinterAllowance(amount, { + from: Accounts.controller1Account, + }), + "Can only decrement allowance for minters in minterManager" + ); + expectedMintControllerState.controllers["controller1Account"] = + Accounts.minterAccount; + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("bt062 decrementMinterAllowance(M, amt) works when minterManager.isMinter(M)=true", async function () { + var amount = 65424; + await mintController.configureController( + Accounts.controller1Account, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + await mintController.configureMinter(amount, { + from: Accounts.controller1Account, }); - it('bt054 removeMinter works when the minterAllowance is not zero', async function () { - var amount = 64; - await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - await mintController.configureMinter(amount, {from: Accounts.controller1Account}); - - var minterManager = await FiatToken.at(await mintController.getMinterManager()); - var minterAllowance = await minterManager.minterAllowance(Accounts.minterAccount); - assert(minterAllowance.cmp(newBigNumber(amount))==0); + var minterManager = await FiatToken.at( + await mintController.getMinterManager() + ); + var isMinter = await minterManager.isMinter(Accounts.minterAccount); + assert.isTrue(isMinter); - await mintController.removeMinter({from: Accounts.controller1Account}); - expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + await mintController.decrementMinterAllowance(amount, { + from: Accounts.controller1Account, }); - - it('bt055 removeMinter works when the minterAllowance is big', async function () { - var amount = maxAmount; - await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - await mintController.configureMinter(maxAmount, {from: Accounts.controller1Account}); - - await mintController.removeMinter({from: Accounts.controller1Account}); - expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + expectedMintControllerState.controllers["controller1Account"] = + Accounts.minterAccount; + expectedTokenState.push( + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { variable: "minterAllowance.minterAccount", expectedValue: bigZero } + ); + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("bt063 decrementMinterAllowance(M,amt) works when minterAllowance is MAX", async function () { + var amount = maxAmount; + await mintController.configureController( + Accounts.controller1Account, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + await mintController.configureMinter(amount, { + from: Accounts.controller1Account, }); - it('bt056 decrementMinterAllowance reverts if msg.sender is not a controller', async function () { - await expectError(mintController.decrementMinterAllowance(0, {from: Accounts.controller1Account}), "The value of controllers[msg.sender] must be non-zero"); + var minterManager = await FiatToken.at( + await mintController.getMinterManager() + ); + var minterAllowance = await minterManager.minterAllowance( + Accounts.minterAccount + ); + assert(minterAllowance.cmp(newBigNumber(maxAmount)) == 0); + await mintController.decrementMinterAllowance(amount, { + from: Accounts.controller1Account, }); - - it('bt057 decrementMinterAllowance works when controllers[msg.sender]=M', async function () { - await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - await mintController.configureMinter(6789, {from: Accounts.controller1Account}); - - // now configure minter - var amount = 1; - await mintController.decrementMinterAllowance(amount, {from: Accounts.controller1Account}); - expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; - expectedTokenState.push( - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(6788) } - ); - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); - }); - - it('bt058 decrementMinterAllowance reverts when minterManager is 0', async function () { - // set minterManager to zero - await mintController.setMinterManager(zeroAddress, {from:Accounts.mintOwnerAccount}); - expectedMintControllerState.minterManager = zeroAddress; - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); - - // decrementMinterAllowance will fail with any args - await(expectRevert(mintController.decrementMinterAllowance(1, {from: Accounts.controller1Account}))); - }); - - it('bt059 decrementMinterAllowance reverts when minterManager is a user account', async function () { - // set minterManager to user account - await mintController.setMinterManager(Accounts.arbitraryAccount, {from:Accounts.mintOwnerAccount}); - expectedMintControllerState.minterManager = Accounts.arbitraryAccount; - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); - - // decrementMinterAllowance will fail with any args - await(expectRevert(mintController.decrementMinterAllowance(1, {from: Accounts.controller1Account}))); - }); - - it('bt060 decrementMinterAllowance works when minterManager is ok', async function () { - await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - await mintController.configureMinter(45, {from: Accounts.controller1Account}); - - // now decrementMinterAllowance - var amount = 45; - await mintController.decrementMinterAllowance(amount, {from: Accounts.controller1Account}); - expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; - expectedTokenState.push( - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': bigZero } - ); - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + expectedMintControllerState.controllers["controller1Account"] = + Accounts.minterAccount; + expectedTokenState.push( + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { variable: "minterAllowance.minterAccount", expectedValue: bigZero } + ); + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("bt064 decrementMinterAllowance(M, amt) works when minterAllowance > 0", async function () { + var initialAmount = 987341; + var decrementAmount = 64; + await mintController.configureController( + Accounts.controller1Account, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + await mintController.configureMinter(initialAmount, { + from: Accounts.controller1Account, }); - it('bt061 decrementMinterAllowance(M, amt) reverts when minterManager.isMinter(M)=false', async function () { - var amount = 1; - await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); + var minterManager = await FiatToken.at( + await mintController.getMinterManager() + ); + var minterAllowance = await minterManager.minterAllowance( + Accounts.minterAccount + ); + assert(minterAllowance.cmp(newBigNumber(initialAmount)) == 0); - var minterManager = await FiatToken.at(await mintController.getMinterManager()); - var isMinter = await minterManager.isMinter(Accounts.minterAccount); - - assert.isFalse(isMinter); - - await expectError(mintController.decrementMinterAllowance(amount, {from: Accounts.controller1Account}), "Can only decrement allowance for minters in minterManager"); - expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + await mintController.decrementMinterAllowance(decrementAmount, { + from: Accounts.controller1Account, }); - - it('bt062 decrementMinterAllowance(M, amt) works when minterManager.isMinter(M)=true', async function () { - var amount = 65424; - await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - await mintController.configureMinter(amount, {from: Accounts.controller1Account}); - - var minterManager = await FiatToken.at(await mintController.getMinterManager()); - var isMinter = await minterManager.isMinter(Accounts.minterAccount); - assert.isTrue(isMinter); - - await mintController.decrementMinterAllowance(amount, {from: Accounts.controller1Account}); - expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; - expectedTokenState.push( - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': bigZero} - ); - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); + expectedMintControllerState.controllers["controller1Account"] = + Accounts.minterAccount; + expectedTokenState.push( + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(initialAmount - decrementAmount), + } + ); + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); + + it("bt065 decrementMinterAllowance(M,amt) sets allowance to 0 when minterAllowance[M] - amt < 0", async function () { + var initialAmount = 45; + var decrementAmount = 64; + await mintController.configureController( + Accounts.controller1Account, + Accounts.minterAccount, + { from: Accounts.mintOwnerAccount } + ); + await mintController.configureMinter(initialAmount, { + from: Accounts.controller1Account, }); - it('bt063 decrementMinterAllowance(M,amt) works when minterAllowance is MAX', async function () { - var amount = maxAmount; - await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - await mintController.configureMinter(amount, {from: Accounts.controller1Account}); - - var minterManager = await FiatToken.at(await mintController.getMinterManager()); - var minterAllowance = await minterManager.minterAllowance(Accounts.minterAccount); - assert(minterAllowance.cmp(newBigNumber(maxAmount))==0); - await mintController.decrementMinterAllowance(amount, {from: Accounts.controller1Account}); - expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; - expectedTokenState.push( - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': bigZero } - ); - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); - }); - - it('bt064 decrementMinterAllowance(M, amt) works when minterAllowance > 0', async function () { - var initialAmount = 987341; - var decrementAmount = 64; - await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - await mintController.configureMinter(initialAmount, {from: Accounts.controller1Account}); - - var minterManager = await FiatToken.at(await mintController.getMinterManager()); - var minterAllowance = await minterManager.minterAllowance(Accounts.minterAccount); - assert(minterAllowance.cmp(newBigNumber(initialAmount))==0); - - await mintController.decrementMinterAllowance(decrementAmount, {from: Accounts.controller1Account}); - expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; - expectedTokenState.push( - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(initialAmount - decrementAmount) } - ); - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); - }); - - it('bt065 decrementMinterAllowance(M,amt) sets allowance to 0 when minterAllowance[M] - amt < 0', async function () { - var initialAmount = 45; - var decrementAmount = 64; - await mintController.configureController(Accounts.controller1Account, Accounts.minterAccount, {from: Accounts.mintOwnerAccount}); - await mintController.configureMinter(initialAmount, {from: Accounts.controller1Account}); - - var minterManager = await FiatToken.at(await mintController.getMinterManager()); - var minterAllowance = await minterManager.minterAllowance(Accounts.minterAccount); - assert(minterAllowance.cmp(newBigNumber(initialAmount))==0); - await mintController.decrementMinterAllowance(decrementAmount, {from: Accounts.controller1Account}); - expectedMintControllerState.controllers['controller1Account'] = Accounts.minterAccount; - expectedTokenState.push( - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': bigZero } - ); - await checkMINTp0([token, mintController], [expectedTokenState, expectedMintControllerState]); - + var minterManager = await FiatToken.at( + await mintController.getMinterManager() + ); + var minterAllowance = await minterManager.minterAllowance( + Accounts.minterAccount + ); + assert(minterAllowance.cmp(newBigNumber(initialAmount)) == 0); + await mintController.decrementMinterAllowance(decrementAmount, { + from: Accounts.controller1Account, }); + expectedMintControllerState.controllers["controller1Account"] = + Accounts.minterAccount; + expectedTokenState.push( + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { variable: "minterAllowance.minterAccount", expectedValue: bigZero } + ); + await checkMINTp0( + [token, mintController], + [expectedTokenState, expectedMintControllerState] + ); + }); } -var testWrapper = require('../TestWrapper'); -testWrapper.execute('MINTp0_BasicTests MintController', run_tests_MintController); -testWrapper.execute('MINTp0_BasicTests MasterMinter', run_tests_MasterMinter); +var testWrapper = require("../TestWrapper"); +testWrapper.execute( + "MINTp0_BasicTests MintController", + run_tests_MintController +); +testWrapper.execute("MINTp0_BasicTests MasterMinter", run_tests_MasterMinter); diff --git a/test/misc/MiscTests.js b/test/misc/MiscTests.js index af75b5fa3..380bde306 100644 --- a/test/misc/MiscTests.js +++ b/test/misc/MiscTests.js @@ -1,8 +1,8 @@ -var FiatTokenProxy = artifacts.require('FiatTokenProxy'); +var FiatTokenProxy = artifacts.require("FiatTokenProxy"); -var tokenUtils = require('./../TokenTestUtils.js');; +var tokenUtils = require("./../TokenTestUtils.js"); var newBigNumber = tokenUtils.newBigNumber; -var assertDiff = require('assert-diff'); +var assertDiff = require("assert-diff"); assertDiff.options.strict = true; var bigZero = tokenUtils.bigZero; @@ -19,16 +19,16 @@ var initializeTokenWithProxy = tokenUtils.initializeTokenWithProxy; var getInitializedV1 = tokenUtils.getInitializedV1; var FiatToken = tokenUtils.FiatToken; -var AccountUtils = require('./../AccountUtils.js'); +var AccountUtils = require("./../AccountUtils.js"); var Accounts = AccountUtils.Accounts; var addressEquals = AccountUtils.addressEquals; -var maxAmount = "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"; +var maxAmount = + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"; var amount = 100; async function run_tests(newToken, accounts) { - - beforeEach('Make fresh token contract', async function () { + beforeEach("Make fresh token contract", async function () { rawToken = await newToken(); var tokenConfig = await initializeTokenWithProxy(rawToken); proxy = tokenConfig.proxy; @@ -36,13 +36,16 @@ async function run_tests(newToken, accounts) { assert.isTrue(addressEquals(proxy.address, token.address)); }); - // No Payable Function - it('ms001 no payable function', async function () { + it("ms001 no payable function", async function () { var success = false; try { - await web3.eth.sendTransaction({ from: Accounts.arbitraryAccount, to: token.address, value: 1 }); + await web3.eth.sendTransaction({ + from: Accounts.arbitraryAccount, + to: token.address, + value: 1, + }); } catch (e) { success = true; } @@ -51,511 +54,928 @@ async function run_tests(newToken, accounts) { // Same Address - it('ms002 should transfer to self has correct final balance', async function() { + it("ms002 should transfer to self has correct final balance", async function () { let mintAmount = 50; - await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); - await token.mint(Accounts.arbitraryAccount, mintAmount, { from: Accounts.minterAccount }); - await token.transfer(Accounts.arbitraryAccount, mintAmount, { from: Accounts.arbitraryAccount }); + await token.configureMinter(Accounts.minterAccount, amount, { + from: Accounts.masterMinterAccount, + }); + await token.mint(Accounts.arbitraryAccount, mintAmount, { + from: Accounts.minterAccount, + }); + await token.transfer(Accounts.arbitraryAccount, mintAmount, { + from: Accounts.arbitraryAccount, + }); var customVars = [ - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - mintAmount) }, - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'balances.arbitraryAccount', 'expectedValue': newBigNumber(mintAmount) }, - { 'variable': 'totalSupply', 'expectedValue': newBigNumber(mintAmount) } + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount - mintAmount), + }, + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "balances.arbitraryAccount", + expectedValue: newBigNumber(mintAmount), + }, + { variable: "totalSupply", expectedValue: newBigNumber(mintAmount) }, ]; await checkVariables([token], [customVars]); }); - it('ms003 should transferFrom to self from approved account and have correct final balance', async function() { + it("ms003 should transferFrom to self from approved account and have correct final balance", async function () { let mintAmount = 50; - await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); - await token.mint(Accounts.arbitraryAccount, mintAmount, { from: Accounts.minterAccount }); - - await token.approve(Accounts.arbitraryAccount2, mintAmount, { from: Accounts.arbitraryAccount }); - await token.transferFrom(Accounts.arbitraryAccount, Accounts.arbitraryAccount, mintAmount, { from: Accounts.arbitraryAccount2 }); + await token.configureMinter(Accounts.minterAccount, amount, { + from: Accounts.masterMinterAccount, + }); + await token.mint(Accounts.arbitraryAccount, mintAmount, { + from: Accounts.minterAccount, + }); + + 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': newBigNumber(amount - mintAmount) }, - { 'variable': 'balances.arbitraryAccount', 'expectedValue': newBigNumber(mintAmount) }, - { 'variable': 'totalSupply', 'expectedValue': newBigNumber(mintAmount) } + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount - mintAmount), + }, + { + variable: "balances.arbitraryAccount", + expectedValue: newBigNumber(mintAmount), + }, + { variable: "totalSupply", expectedValue: newBigNumber(mintAmount) }, ]; await checkVariables([token], [customVars]); }); - it('ms004 should transferFrom to self from approved self and have correct final balance', async function() { + it("ms004 should transferFrom to self from approved self and have correct final balance", async function () { let mintAmount = 50; - await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); - await token.mint(Accounts.arbitraryAccount, mintAmount, { from: Accounts.minterAccount }); - - await token.approve(Accounts.arbitraryAccount, mintAmount, { from: Accounts.arbitraryAccount }); - await token.transferFrom(Accounts.arbitraryAccount, Accounts.arbitraryAccount, mintAmount, { from: Accounts.arbitraryAccount }); + await token.configureMinter(Accounts.minterAccount, amount, { + from: Accounts.masterMinterAccount, + }); + await token.mint(Accounts.arbitraryAccount, mintAmount, { + from: Accounts.minterAccount, + }); + + await token.approve(Accounts.arbitraryAccount, mintAmount, { + from: Accounts.arbitraryAccount, + }); + await token.transferFrom( + Accounts.arbitraryAccount, + Accounts.arbitraryAccount, + mintAmount, + { from: Accounts.arbitraryAccount } + ); customVars = [ - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - mintAmount) }, - { 'variable': 'balances.arbitraryAccount', 'expectedValue': newBigNumber(mintAmount) }, - { 'variable': 'totalSupply', 'expectedValue': newBigNumber(mintAmount) } + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount - mintAmount), + }, + { + variable: "balances.arbitraryAccount", + expectedValue: newBigNumber(mintAmount), + }, + { variable: "totalSupply", expectedValue: newBigNumber(mintAmount) }, ]; await checkVariables([token], [customVars]); }); - it('ms005 should mint to self with correct final balance', async function () { + it("ms005 should mint to self with correct final balance", async function () { var mintAmount = 50; - await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); + await token.configureMinter(Accounts.minterAccount, amount, { + from: Accounts.masterMinterAccount, + }); var customVars = [ - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) } + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount), + }, ]; await checkVariables([token], [customVars]); - await token.mint(Accounts.minterAccount, mintAmount, { from: Accounts.minterAccount }); + await token.mint(Accounts.minterAccount, mintAmount, { + from: Accounts.minterAccount, + }); customVars = [ - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - mintAmount) }, - { 'variable': 'balances.minterAccount', 'expectedValue': newBigNumber(mintAmount) }, - { 'variable': 'totalSupply', 'expectedValue': newBigNumber(mintAmount) } + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount - mintAmount), + }, + { + variable: "balances.minterAccount", + expectedValue: newBigNumber(mintAmount), + }, + { variable: "totalSupply", expectedValue: newBigNumber(mintAmount) }, ]; await checkVariables([token], [customVars]); }); - it('ms006 should approve correct allowance for self', async function () { + it("ms006 should approve correct allowance for self", async function () { var mintAmount = 50; - await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); + await token.configureMinter(Accounts.minterAccount, amount, { + from: Accounts.masterMinterAccount, + }); var customVars = [ - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) } + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount), + }, ]; await checkVariables([token], [customVars]); - await token.mint(Accounts.arbitraryAccount, mintAmount, { from: Accounts.minterAccount }); - await token.approve(Accounts.arbitraryAccount, amount, { from: Accounts.arbitraryAccount }); + await token.mint(Accounts.arbitraryAccount, mintAmount, { + from: Accounts.minterAccount, + }); + await token.approve(Accounts.arbitraryAccount, amount, { + from: Accounts.arbitraryAccount, + }); customVars = [ - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - mintAmount) }, - { 'variable': 'balances.arbitraryAccount', 'expectedValue': newBigNumber(mintAmount) }, - { 'variable': 'totalSupply', 'expectedValue': newBigNumber(mintAmount) }, - { 'variable': 'allowance.arbitraryAccount.arbitraryAccount', 'expectedValue': newBigNumber(amount) } + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount - mintAmount), + }, + { + variable: "balances.arbitraryAccount", + expectedValue: newBigNumber(mintAmount), + }, + { variable: "totalSupply", expectedValue: newBigNumber(mintAmount) }, + { + variable: "allowance.arbitraryAccount.arbitraryAccount", + expectedValue: newBigNumber(amount), + }, ]; await checkVariables([token], [customVars]); }); - it('ms007 should configureMinter for masterMinter', async function () { - await token.configureMinter(Accounts.masterMinterAccount, amount, { from: Accounts.masterMinterAccount }); + it("ms007 should configureMinter for masterMinter", async function () { + await token.configureMinter(Accounts.masterMinterAccount, amount, { + from: Accounts.masterMinterAccount, + }); var customVars = [ - { 'variable': 'isAccountMinter.masterMinterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.masterMinterAccount', 'expectedValue': newBigNumber(amount) } + { variable: "isAccountMinter.masterMinterAccount", expectedValue: true }, + { + variable: "minterAllowance.masterMinterAccount", + expectedValue: newBigNumber(amount), + }, ]; await checkVariables([token], [customVars]); }); // Multiple Minters - it('ms009 should configure two minters', async function () { - await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); - await token.configureMinter(Accounts.arbitraryAccount, amount, { from: Accounts.masterMinterAccount }); + it("ms009 should configure two minters", async function () { + await token.configureMinter(Accounts.minterAccount, amount, { + from: Accounts.masterMinterAccount, + }); + await token.configureMinter(Accounts.arbitraryAccount, amount, { + from: Accounts.masterMinterAccount, + }); var customVars = [ - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'isAccountMinter.arbitraryAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) }, - { 'variable': 'minterAllowance.arbitraryAccount', 'expectedValue': newBigNumber(amount) }, + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { variable: "isAccountMinter.arbitraryAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount), + }, + { + variable: "minterAllowance.arbitraryAccount", + expectedValue: newBigNumber(amount), + }, ]; await checkVariables([token], [customVars]); }); - it('ms010 should configure two minters and each mint distinct amounts', async function () { + it("ms010 should configure two minters and each mint distinct amounts", async function () { var mintAmount1 = 10; var mintAmount2 = 20; - await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); - await token.configureMinter(Accounts.arbitraryAccount, amount, { from: Accounts.masterMinterAccount }); - await token.mint(Accounts.arbitraryAccount2, mintAmount1, { from: Accounts.minterAccount }); - await token.mint(Accounts.arbitraryAccount2, mintAmount2, { from: Accounts.arbitraryAccount }); + await token.configureMinter(Accounts.minterAccount, amount, { + from: Accounts.masterMinterAccount, + }); + await token.configureMinter(Accounts.arbitraryAccount, amount, { + from: Accounts.masterMinterAccount, + }); + 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': newBigNumber(amount - mintAmount1) }, - { 'variable': 'minterAllowance.arbitraryAccount', 'expectedValue': newBigNumber(amount - mintAmount2) }, - { 'variable': 'balances.arbitraryAccount2', 'expectedValue': newBigNumber(mintAmount1 + mintAmount2) }, - { 'variable': 'totalSupply', 'expectedValue': newBigNumber(mintAmount1 + mintAmount2) }, + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { variable: "isAccountMinter.arbitraryAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount - mintAmount1), + }, + { + variable: "minterAllowance.arbitraryAccount", + expectedValue: newBigNumber(amount - mintAmount2), + }, + { + variable: "balances.arbitraryAccount2", + expectedValue: newBigNumber(mintAmount1 + mintAmount2), + }, + { + variable: "totalSupply", + expectedValue: newBigNumber(mintAmount1 + mintAmount2), + }, ]; await checkVariables([token], [customVars]); }); - it('ms011 should configure two minters, each minting distinct amounts and then remove one minter', async function () { + it("ms011 should configure two minters, each minting distinct amounts and then remove one minter", async function () { var mintAmount1 = 10; var mintAmount2 = 20; - await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); - await token.configureMinter(Accounts.arbitraryAccount, amount, { from: Accounts.masterMinterAccount }); - 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 }); + await token.configureMinter(Accounts.minterAccount, amount, { + from: Accounts.masterMinterAccount, + }); + await token.configureMinter(Accounts.arbitraryAccount, amount, { + from: Accounts.masterMinterAccount, + }); + 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': newBigNumber(amount - mintAmount1) }, - { 'variable': 'balances.arbitraryAccount2', 'expectedValue': newBigNumber(mintAmount1 + mintAmount2) }, - { 'variable': 'totalSupply', 'expectedValue': newBigNumber(mintAmount1 + mintAmount2) }, + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount - mintAmount1), + }, + { + variable: "balances.arbitraryAccount2", + expectedValue: newBigNumber(mintAmount1 + mintAmount2), + }, + { + variable: "totalSupply", + expectedValue: newBigNumber(mintAmount1 + mintAmount2), + }, ]; await checkVariables([token], [customVars]); }); - it('ms012 should configure two minters and adjust both allowances', async function () { + it("ms012 should configure two minters and adjust both allowances", async function () { var adjustment = 10; - await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); - await token.configureMinter(Accounts.arbitraryAccount, amount, { from: Accounts.masterMinterAccount }); + await token.configureMinter(Accounts.minterAccount, amount, { + from: Accounts.masterMinterAccount, + }); + await token.configureMinter(Accounts.arbitraryAccount, amount, { + from: Accounts.masterMinterAccount, + }); var customVars = [ - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'isAccountMinter.arbitraryAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) }, - { 'variable': 'minterAllowance.arbitraryAccount', 'expectedValue': newBigNumber(amount) }, - ]; - await checkVariables([token], [customVars]); - - await token.configureMinter(Accounts.minterAccount, amount - adjustment, { from: Accounts.masterMinterAccount }); - await token.configureMinter(Accounts.arbitraryAccount, amount + adjustment, { from: Accounts.masterMinterAccount }); + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { variable: "isAccountMinter.arbitraryAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount), + }, + { + variable: "minterAllowance.arbitraryAccount", + expectedValue: newBigNumber(amount), + }, + ]; + await checkVariables([token], [customVars]); + + await token.configureMinter(Accounts.minterAccount, amount - adjustment, { + from: Accounts.masterMinterAccount, + }); + await token.configureMinter( + Accounts.arbitraryAccount, + amount + adjustment, + { from: Accounts.masterMinterAccount } + ); var customVars = [ - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'isAccountMinter.arbitraryAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - adjustment) }, - { 'variable': 'minterAllowance.arbitraryAccount', 'expectedValue': newBigNumber(amount + adjustment) }, + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { variable: "isAccountMinter.arbitraryAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount - adjustment), + }, + { + variable: "minterAllowance.arbitraryAccount", + expectedValue: newBigNumber(amount + adjustment), + }, ]; await checkVariables([token], [customVars]); }); - it('ms013 should configure two minters, one with zero allowance fails to mint', async function () { + it("ms013 should configure two minters, one with zero allowance fails to mint", async function () { var mintAmount = 10; - await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); - await token.configureMinter(Accounts.arbitraryAccount, 0, { from: Accounts.masterMinterAccount }); - await token.mint(Accounts.arbitraryAccount2, mintAmount, { from: Accounts.minterAccount }); + await token.configureMinter(Accounts.minterAccount, amount, { + from: Accounts.masterMinterAccount, + }); + await token.configureMinter(Accounts.arbitraryAccount, 0, { + from: Accounts.masterMinterAccount, + }); + 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': newBigNumber(amount - mintAmount) }, - { 'variable': 'balances.arbitraryAccount2', 'expectedValue': newBigNumber(mintAmount) }, - { 'variable': 'totalSupply', 'expectedValue': newBigNumber(mintAmount) }, - ]; - await expectRevert(token.mint(Accounts.arbitraryAccount2, mintAmount, { from: Accounts.arbitraryAccount })); + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { variable: "isAccountMinter.arbitraryAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount - mintAmount), + }, + { + variable: "balances.arbitraryAccount2", + expectedValue: newBigNumber(mintAmount), + }, + { variable: "totalSupply", expectedValue: newBigNumber(mintAmount) }, + ]; + await expectRevert( + token.mint(Accounts.arbitraryAccount2, mintAmount, { + from: Accounts.arbitraryAccount, + }) + ); await checkVariables([token], [customVars]); }); - it('ms014 should configure two minters and fail to mint when paused', async function () { + it("ms014 should configure two minters and fail to mint when paused", async function () { var mintAmount = 10; - await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); - await token.configureMinter(Accounts.arbitraryAccount, amount, { from: Accounts.masterMinterAccount }); + await token.configureMinter(Accounts.minterAccount, amount, { + from: Accounts.masterMinterAccount, + }); + await token.configureMinter(Accounts.arbitraryAccount, amount, { + from: Accounts.masterMinterAccount, + }); await token.pause({ from: Accounts.pauserAccount }); var customVars = [ - { 'variable': 'paused', 'expectedValue': true }, - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'isAccountMinter.arbitraryAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) }, - { 'variable': 'minterAllowance.arbitraryAccount', 'expectedValue': newBigNumber(amount) } - ]; - await expectRevert(token.mint(Accounts.pauserAccount, mintAmount, { from: Accounts.minterAccount })); - await expectRevert(token.mint(Accounts.pauserAccount, mintAmount, { from: Accounts.arbitraryAccount })); + { variable: "paused", expectedValue: true }, + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { variable: "isAccountMinter.arbitraryAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount), + }, + { + variable: "minterAllowance.arbitraryAccount", + expectedValue: newBigNumber(amount), + }, + ]; + await expectRevert( + token.mint(Accounts.pauserAccount, mintAmount, { + from: Accounts.minterAccount, + }) + ); + await expectRevert( + token.mint(Accounts.pauserAccount, mintAmount, { + from: Accounts.arbitraryAccount, + }) + ); await checkVariables([token], [customVars]); }); - it('ms015 should configure two minters, blacklist one and ensure it cannot mint, then unblacklist and ensure it can mint', async function () { + it("ms015 should configure two minters, blacklist one and ensure it cannot mint, then unblacklist and ensure it can mint", async function () { var mintAmount = 10; - 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.arbitraryAccount2, mintAmount, { from: Accounts.arbitraryAccount }); + 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.arbitraryAccount2, mintAmount, { + from: Accounts.arbitraryAccount, + }); var customVars = [ - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'isAccountMinter.arbitraryAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) }, - { 'variable': 'minterAllowance.arbitraryAccount', 'expectedValue': newBigNumber(amount - mintAmount) }, - { 'variable': 'isAccountBlacklisted.minterAccount', 'expectedValue': true }, - { 'variable': 'totalSupply', 'expectedValue': newBigNumber(mintAmount) }, - { 'variable': 'balances.arbitraryAccount2', 'expectedValue': newBigNumber(mintAmount) }, - ]; - 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.arbitraryAccount2, mintAmount, { from: Accounts.minterAccount }); + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { variable: "isAccountMinter.arbitraryAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount), + }, + { + variable: "minterAllowance.arbitraryAccount", + expectedValue: newBigNumber(amount - mintAmount), + }, + { variable: "isAccountBlacklisted.minterAccount", expectedValue: true }, + { variable: "totalSupply", expectedValue: newBigNumber(mintAmount) }, + { + variable: "balances.arbitraryAccount2", + expectedValue: newBigNumber(mintAmount), + }, + ]; + 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.arbitraryAccount2, mintAmount, { + from: Accounts.minterAccount, + }); var customVars = [ - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'isAccountMinter.arbitraryAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - mintAmount) }, - { 'variable': 'minterAllowance.arbitraryAccount', 'expectedValue': newBigNumber(amount - mintAmount) }, - { 'variable': 'totalSupply', 'expectedValue': newBigNumber(mintAmount + mintAmount) }, - { 'variable': 'balances.arbitraryAccount2', 'expectedValue': newBigNumber(mintAmount + mintAmount) }, + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { variable: "isAccountMinter.arbitraryAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount - mintAmount), + }, + { + variable: "minterAllowance.arbitraryAccount", + expectedValue: newBigNumber(amount - mintAmount), + }, + { + variable: "totalSupply", + expectedValue: newBigNumber(mintAmount + mintAmount), + }, + { + variable: "balances.arbitraryAccount2", + expectedValue: newBigNumber(mintAmount + mintAmount), + }, ]; await checkVariables([token], [customVars]); }); - it('ms016 should configure two minters, each mints to themselves and then burns certain amount', async function () { + it("ms016 should configure two minters, each mints to themselves and then burns certain amount", async function () { var mintAmount1 = 10; var mintAmount2 = 20; var burnAmount = 10; - await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); - await token.configureMinter(Accounts.arbitraryAccount, amount, { from: Accounts.masterMinterAccount }); - await token.mint(Accounts.minterAccount, mintAmount1, { from: Accounts.minterAccount }); - await token.mint(Accounts.arbitraryAccount, mintAmount2, { from: Accounts.arbitraryAccount }); + await token.configureMinter(Accounts.minterAccount, amount, { + from: Accounts.masterMinterAccount, + }); + await token.configureMinter(Accounts.arbitraryAccount, amount, { + from: Accounts.masterMinterAccount, + }); + await token.mint(Accounts.minterAccount, mintAmount1, { + from: Accounts.minterAccount, + }); + await token.mint(Accounts.arbitraryAccount, mintAmount2, { + from: Accounts.arbitraryAccount, + }); var customVars = [ - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'isAccountMinter.arbitraryAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - mintAmount1) }, - { 'variable': 'minterAllowance.arbitraryAccount', 'expectedValue': newBigNumber(amount - mintAmount2) }, - { 'variable': 'balances.minterAccount', 'expectedValue': newBigNumber(mintAmount1) }, - { 'variable': 'balances.arbitraryAccount', 'expectedValue': newBigNumber(mintAmount2) }, - { 'variable': 'totalSupply', 'expectedValue': newBigNumber(mintAmount1 + mintAmount2) }, + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { variable: "isAccountMinter.arbitraryAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount - mintAmount1), + }, + { + variable: "minterAllowance.arbitraryAccount", + expectedValue: newBigNumber(amount - mintAmount2), + }, + { + variable: "balances.minterAccount", + expectedValue: newBigNumber(mintAmount1), + }, + { + variable: "balances.arbitraryAccount", + expectedValue: newBigNumber(mintAmount2), + }, + { + variable: "totalSupply", + expectedValue: newBigNumber(mintAmount1 + mintAmount2), + }, ]; await checkVariables([token], [customVars]); await token.burn(burnAmount, { from: Accounts.minterAccount }); await token.burn(burnAmount, { from: Accounts.arbitraryAccount }); var customVars = [ - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'isAccountMinter.arbitraryAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - mintAmount1) }, - { 'variable': 'minterAllowance.arbitraryAccount', 'expectedValue': newBigNumber(amount - mintAmount2) }, - { 'variable': 'balances.minterAccount', 'expectedValue': newBigNumber(mintAmount1 - burnAmount) }, - { 'variable': 'balances.arbitraryAccount', 'expectedValue': newBigNumber(mintAmount2 - burnAmount) }, - { 'variable': 'totalSupply', 'expectedValue': newBigNumber(mintAmount1 + mintAmount2 - burnAmount - burnAmount) }, + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { variable: "isAccountMinter.arbitraryAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount - mintAmount1), + }, + { + variable: "minterAllowance.arbitraryAccount", + expectedValue: newBigNumber(amount - mintAmount2), + }, + { + variable: "balances.minterAccount", + expectedValue: newBigNumber(mintAmount1 - burnAmount), + }, + { + variable: "balances.arbitraryAccount", + expectedValue: newBigNumber(mintAmount2 - burnAmount), + }, + { + variable: "totalSupply", + expectedValue: newBigNumber( + mintAmount1 + mintAmount2 - burnAmount - burnAmount + ), + }, ]; await checkVariables([token], [customVars]); }); // 0 Input - it('ms018 should approve 0 token allowance with unchanged state', async function () { - await token.approve(Accounts.minterAccount, 0, { from: Accounts.arbitraryAccount }); + it("ms018 should approve 0 token allowance with unchanged state", async function () { + await token.approve(Accounts.minterAccount, 0, { + from: Accounts.arbitraryAccount, + }); await checkVariables([token], [[]]); }); - it('ms019 should transferFrom 0 tokens with unchanged state', async function () { - await token.transferFrom(Accounts.arbitraryAccount, Accounts.pauserAccount, 0, { from: Accounts.arbitraryAccount2 }); + it("ms019 should transferFrom 0 tokens with unchanged state", async function () { + await token.transferFrom( + Accounts.arbitraryAccount, + Accounts.pauserAccount, + 0, + { from: Accounts.arbitraryAccount2 } + ); await checkVariables([token], [[]]); }); - it('ms020 should transfer 0 tokens with unchanged state', async function () { - await token.transfer(Accounts.arbitraryAccount, 0, { from: Accounts.arbitraryAccount2 }); + it("ms020 should transfer 0 tokens with unchanged state", async function () { + await token.transfer(Accounts.arbitraryAccount, 0, { + from: Accounts.arbitraryAccount2, + }); await checkVariables([token], [[]]); }); - it('ms036 should get allowance for same address', async function() { - await token.approve(Accounts.arbitraryAccount, amount, {from: Accounts.arbitraryAccount}); - var allowance = newBigNumber(await token.allowance(Accounts.arbitraryAccount, Accounts.arbitraryAccount)); - assert(allowance.cmp(newBigNumber(amount))==0); + it("ms036 should get allowance for same address", async function () { + await token.approve(Accounts.arbitraryAccount, amount, { + from: Accounts.arbitraryAccount, + }); + var allowance = newBigNumber( + await token.allowance( + Accounts.arbitraryAccount, + Accounts.arbitraryAccount + ) + ); + assert(allowance.cmp(newBigNumber(amount)) == 0); }); // Return value /* - * Calls (i.e token.mint.call(...) , token.approve.call(...) etc.) expose the - * return value of functions while transactions (token.mint(...) , - * token.approve(...) etc.) return transaction receipts and do not read - * function return values. Calls, unlike transactions, do not permanently - * modify data. However, both calls and transactions execute code on the - * network. That is, token.mint.call(...) will revert if and only if - * token.mint(...) reverts. - * - * "Choosing between a transaction and a call is as simple as deciding - * whether you want to read data, or write it." - * - truffle docs - * (https://truffleframework.com/docs/getting_started/contracts) - */ - - it('ms039 should return true on mint', async function() { + * Calls (i.e token.mint.call(...) , token.approve.call(...) etc.) expose the + * return value of functions while transactions (token.mint(...) , + * token.approve(...) etc.) return transaction receipts and do not read + * function return values. Calls, unlike transactions, do not permanently + * modify data. However, both calls and transactions execute code on the + * network. That is, token.mint.call(...) will revert if and only if + * token.mint(...) reverts. + * + * "Choosing between a transaction and a call is as simple as deciding + * whether you want to read data, or write it." + * - truffle docs + * (https://truffleframework.com/docs/getting_started/contracts) + */ + + it("ms039 should return true on mint", async function () { var mintAmount = 50; - await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); + await token.configureMinter(Accounts.minterAccount, amount, { + from: Accounts.masterMinterAccount, + }); var customVars = [ - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) } - ]; - assert(await token.mint.call(Accounts.arbitraryAccount, mintAmount, { from: Accounts.minterAccount })); + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount), + }, + ]; + assert( + await token.mint.call(Accounts.arbitraryAccount, mintAmount, { + from: Accounts.minterAccount, + }) + ); await checkVariables([token], [customVars]); }); - it('ms040 should return true on approve', async function() { - assert(await token.approve.call(Accounts.minterAccount, amount, { from: Accounts.arbitraryAccount })); + it("ms040 should return true on approve", async function () { + assert( + await token.approve.call(Accounts.minterAccount, amount, { + from: Accounts.arbitraryAccount, + }) + ); }); - it('ms041 should return true on transferFrom', async function() { + it("ms041 should return true on transferFrom", async function () { let mintAmount = 50; - await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); + await token.configureMinter(Accounts.minterAccount, amount, { + from: Accounts.masterMinterAccount, + }); var customVars = [ - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) } + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount), + }, ]; await checkVariables([token], [customVars]); - await token.mint(Accounts.arbitraryAccount, mintAmount, { from: Accounts.minterAccount }); - await token.approve(Accounts.masterMinterAccount, mintAmount, { from: Accounts.arbitraryAccount }); + await token.mint(Accounts.arbitraryAccount, mintAmount, { + from: Accounts.minterAccount, + }); + await token.approve(Accounts.masterMinterAccount, mintAmount, { + from: Accounts.arbitraryAccount, + }); customVars = [ - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - mintAmount) }, - { 'variable': 'balances.arbitraryAccount', 'expectedValue': newBigNumber(mintAmount) }, - { 'variable': 'totalSupply', 'expectedValue': newBigNumber(mintAmount) }, - { 'variable': 'allowance.arbitraryAccount.masterMinterAccount', 'expectedValue': newBigNumber(mintAmount)}, - ]; - assert(await token.transferFrom.call(Accounts.arbitraryAccount, Accounts.pauserAccount, mintAmount, { from: Accounts.masterMinterAccount })); + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount - mintAmount), + }, + { + variable: "balances.arbitraryAccount", + expectedValue: newBigNumber(mintAmount), + }, + { variable: "totalSupply", expectedValue: newBigNumber(mintAmount) }, + { + variable: "allowance.arbitraryAccount.masterMinterAccount", + expectedValue: newBigNumber(mintAmount), + }, + ]; + assert( + await token.transferFrom.call( + Accounts.arbitraryAccount, + Accounts.pauserAccount, + mintAmount, + { from: Accounts.masterMinterAccount } + ) + ); await checkVariables([token], [customVars]); }); - it('ms042 should return true on transfer', async function() { + it("ms042 should return true on transfer", async function () { let mintAmount = 50; - await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); + await token.configureMinter(Accounts.minterAccount, amount, { + from: Accounts.masterMinterAccount, + }); var customVars = [ - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount) } + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount), + }, ]; await checkVariables([token], [customVars]); - await token.mint(Accounts.arbitraryAccount, mintAmount, { from: Accounts.minterAccount }); + await token.mint(Accounts.arbitraryAccount, mintAmount, { + from: Accounts.minterAccount, + }); customVars = [ - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - mintAmount) }, - { 'variable': 'balances.arbitraryAccount', 'expectedValue': newBigNumber(mintAmount) }, - { 'variable': 'totalSupply', 'expectedValue': newBigNumber(mintAmount) } - ]; - assert(await token.transfer.call(Accounts.pauserAccount, mintAmount, { from: Accounts.arbitraryAccount })); + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount - mintAmount), + }, + { + variable: "balances.arbitraryAccount", + expectedValue: newBigNumber(mintAmount), + }, + { variable: "totalSupply", expectedValue: newBigNumber(mintAmount) }, + ]; + assert( + await token.transfer.call(Accounts.pauserAccount, mintAmount, { + from: Accounts.arbitraryAccount, + }) + ); await checkVariables([token], [customVars]); }); - it('ms043 should return true on configureMinter', async function() { - assert(await token.configureMinter.call(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount })); + it("ms043 should return true on configureMinter", async function () { + assert( + await token.configureMinter.call(Accounts.minterAccount, amount, { + from: Accounts.masterMinterAccount, + }) + ); }); - it('ms044 should return true on removeMinter', async function() { - assert(await token.removeMinter.call(Accounts.minterAccount, { from: Accounts.masterMinterAccount })); + it("ms044 should return true on removeMinter", async function () { + assert( + await token.removeMinter.call(Accounts.minterAccount, { + from: Accounts.masterMinterAccount, + }) + ); }); - it('ms045 initialized should be in slot 8, byte 21', async function() { + it("ms045 initialized should be in slot 8, byte 21", async function () { var initialized = await getInitializedV1(token); assert.equal("0x01", initialized); }); - it('ms046 initialized should be 0 before initialization', async function() { + it("ms046 initialized should be 0 before initialization", async function () { var rawToken = await newToken(); - var newProxy = await FiatTokenProxy.new(rawToken.address, { from: Accounts.arbitraryAccount }); + var newProxy = await FiatTokenProxy.new(rawToken.address, { + from: Accounts.arbitraryAccount, + }); var token = await FiatToken.at(newProxy.address); var initialized = await getInitializedV1(token); assert.equal("0x0", initialized); }); - it('ms047 configureMinter works on amount=2^256-1', async function() { - await token.configureMinter(Accounts.minterAccount, maxAmount, { from: Accounts.masterMinterAccount }); + it("ms047 configureMinter works on amount=2^256-1", async function () { + await token.configureMinter(Accounts.minterAccount, maxAmount, { + from: Accounts.masterMinterAccount, + }); var customVars = [ - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(maxAmount) } + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(maxAmount), + }, ]; await checkVariables([token], [customVars]); }); - it('ms048 mint works on amount=2^256-1', async function() { - await token.configureMinter(Accounts.minterAccount, maxAmount, { from: Accounts.masterMinterAccount }); + it("ms048 mint works on amount=2^256-1", async function () { + await token.configureMinter(Accounts.minterAccount, maxAmount, { + from: Accounts.masterMinterAccount, + }); var customVars = [ - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(maxAmount) } + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(maxAmount), + }, ]; await checkVariables([token], [customVars]); - await token.mint(Accounts.arbitraryAccount, maxAmount, { from: Accounts.minterAccount }); + await token.mint(Accounts.arbitraryAccount, maxAmount, { + from: Accounts.minterAccount, + }); customVars = [ - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(0) }, - { 'variable': 'balances.arbitraryAccount', 'expectedValue': newBigNumber(maxAmount) }, - { 'variable': 'totalSupply', 'expectedValue': newBigNumber(maxAmount) } + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(0), + }, + { + variable: "balances.arbitraryAccount", + expectedValue: newBigNumber(maxAmount), + }, + { variable: "totalSupply", expectedValue: newBigNumber(maxAmount) }, ]; await checkVariables([token], [customVars]); - }); + }); - it('ms049 burn on works on amount=2^256-1', async function() { - await token.configureMinter(Accounts.minterAccount, maxAmount, { from: Accounts.masterMinterAccount }); - await token.mint(Accounts.minterAccount, maxAmount, { from: Accounts.minterAccount }); + it("ms049 burn on works on amount=2^256-1", async function () { + await token.configureMinter(Accounts.minterAccount, maxAmount, { + from: Accounts.masterMinterAccount, + }); + await token.mint(Accounts.minterAccount, maxAmount, { + from: Accounts.minterAccount, + }); customVars = [ - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'balances.minterAccount', 'expectedValue': newBigNumber(maxAmount) }, - { 'variable': 'totalSupply', 'expectedValue': newBigNumber(maxAmount) } + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "balances.minterAccount", + expectedValue: newBigNumber(maxAmount), + }, + { variable: "totalSupply", expectedValue: newBigNumber(maxAmount) }, ]; await checkVariables([token], [customVars]); await token.burn(maxAmount, { from: Accounts.minterAccount }); customVars = [ - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, + { variable: "isAccountMinter.minterAccount", expectedValue: true }, ]; await checkVariables([token], [customVars]); - }); + }); - it('ms050 approve 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 }); + it("ms050 approve 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, + }); customVars = [ - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'balances.arbitraryAccount', 'expectedValue': newBigNumber(maxAmount) }, - { 'variable': 'totalSupply', 'expectedValue': newBigNumber(maxAmount) } + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "balances.arbitraryAccount", + expectedValue: newBigNumber(maxAmount), + }, + { variable: "totalSupply", expectedValue: newBigNumber(maxAmount) }, ]; await checkVariables([token], [customVars]); - await token.approve(Accounts.arbitraryAccount2, maxAmount, {from: Accounts.arbitraryAccount}); + await token.approve(Accounts.arbitraryAccount2, maxAmount, { + from: Accounts.arbitraryAccount, + }); customVars = [ - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'balances.arbitraryAccount', 'expectedValue': newBigNumber(maxAmount) }, - { 'variable': 'totalSupply', 'expectedValue': newBigNumber(maxAmount) }, - { 'variable': 'allowance.arbitraryAccount.arbitraryAccount2', 'expectedValue': newBigNumber(maxAmount) } + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "balances.arbitraryAccount", + expectedValue: newBigNumber(maxAmount), + }, + { variable: "totalSupply", expectedValue: newBigNumber(maxAmount) }, + { + variable: "allowance.arbitraryAccount.arbitraryAccount2", + expectedValue: newBigNumber(maxAmount), + }, ]; await checkVariables([token], [customVars]); - }); + }); - it('ms051 transfer 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 }); + it("ms051 transfer 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, + }); customVars = [ - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'balances.arbitraryAccount', 'expectedValue': newBigNumber(maxAmount) }, - { 'variable': 'totalSupply', 'expectedValue': newBigNumber(maxAmount) } + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "balances.arbitraryAccount", + expectedValue: newBigNumber(maxAmount), + }, + { variable: "totalSupply", expectedValue: newBigNumber(maxAmount) }, ]; await checkVariables([token], [customVars]); - await token.transfer(Accounts.arbitraryAccount2, maxAmount, {from: Accounts.arbitraryAccount}); + await token.transfer(Accounts.arbitraryAccount2, maxAmount, { + from: Accounts.arbitraryAccount, + }); customVars = [ - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'balances.arbitraryAccount2', 'expectedValue': newBigNumber(maxAmount) }, - { 'variable': 'totalSupply', 'expectedValue': newBigNumber(maxAmount) }, + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "balances.arbitraryAccount2", + expectedValue: newBigNumber(maxAmount), + }, + { variable: "totalSupply", expectedValue: newBigNumber(maxAmount) }, ]; await checkVariables([token], [customVars]); - }); + }); - 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.arbitraryAccount2, maxAmount, {from: Accounts.arbitraryAccount}); + 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.arbitraryAccount2, maxAmount, { + from: Accounts.arbitraryAccount, + }); customVars = [ - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'balances.arbitraryAccount', 'expectedValue': newBigNumber(maxAmount) }, - { 'variable': 'totalSupply', 'expectedValue': newBigNumber(maxAmount) }, - { 'variable': 'allowance.arbitraryAccount.arbitraryAccount2', 'expectedValue': newBigNumber(maxAmount) } - ]; - await checkVariables([token], [customVars]); - - await token.transferFrom(Accounts.arbitraryAccount, Accounts.arbitraryAccount2, maxAmount, {from: Accounts.arbitraryAccount2}); + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "balances.arbitraryAccount", + expectedValue: newBigNumber(maxAmount), + }, + { variable: "totalSupply", expectedValue: newBigNumber(maxAmount) }, + { + variable: "allowance.arbitraryAccount.arbitraryAccount2", + expectedValue: newBigNumber(maxAmount), + }, + ]; + await checkVariables([token], [customVars]); + + await token.transferFrom( + Accounts.arbitraryAccount, + Accounts.arbitraryAccount2, + maxAmount, + { from: Accounts.arbitraryAccount2 } + ); customVars = [ - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'balances.arbitraryAccount2', 'expectedValue': newBigNumber(maxAmount) }, - { 'variable': 'totalSupply', 'expectedValue': newBigNumber(maxAmount) }, + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { + variable: "balances.arbitraryAccount2", + expectedValue: newBigNumber(maxAmount), + }, + { variable: "totalSupply", expectedValue: newBigNumber(maxAmount) }, ]; await checkVariables([token], [customVars]); - }); + }); } -var testWrapper = require('./../TestWrapper'); -testWrapper.execute('FiatToken_MiscTests', run_tests); +var testWrapper = require("./../TestWrapper"); +testWrapper.execute("FiatToken_MiscTests", run_tests); module.exports = { run_tests: run_tests, -} +}; diff --git a/test/proxy/ProxyNegativeTests.js b/test/proxy/ProxyNegativeTests.js index eb2b1bdde..61d317b45 100644 --- a/test/proxy/ProxyNegativeTests.js +++ b/test/proxy/ProxyNegativeTests.js @@ -1,6 +1,6 @@ -var tokenUtils = require('./../TokenTestUtils');; +var tokenUtils = require("./../TokenTestUtils"); var newBigNumber = tokenUtils.newBigNumber; -var assertDiff = require('assert-diff'); +var assertDiff = require("assert-diff"); assertDiff.options.strict = true; var bigZero = tokenUtils.bigZero; @@ -21,126 +21,228 @@ var FiatToken = tokenUtils.FiatToken; var UpgradedFiatToken = tokenUtils.UpgradedFiatToken; var UpgradedFiatTokenNewFields = tokenUtils.UpgradedFiatTokenNewFields; -var AccountUtils = require('./../AccountUtils'); +var AccountUtils = require("./../AccountUtils"); var Accounts = AccountUtils.Accounts; var addressEquals = AccountUtils.addressEquals; var amount = 100; async function run_tests(newToken, accounts) { - - beforeEach('Make fresh token contract', async function () { + beforeEach("Make fresh token contract", async function () { rawToken = await newToken(); var tokenConfig = await initializeTokenWithProxy(rawToken); proxy = tokenConfig.proxy; token = tokenConfig.token; - assert.isTrue(addressEquals(proxy.address ,token.address)); + assert.isTrue(addressEquals(proxy.address, token.address)); }); - it('nut002 should fail to switch adminAccount with non-adminAccount as caller', async function () { - await expectRevert(proxy.changeAdmin(Accounts.masterMinterAccount, {from: Accounts.masterMinterAccount})); - assert.isTrue(addressEquals(await proxy.admin({from: Accounts.proxyOwnerAccount}), Accounts - .proxyOwnerAccount)); + it("nut002 should fail to switch adminAccount with non-adminAccount as caller", async function () { + await expectRevert( + proxy.changeAdmin(Accounts.masterMinterAccount, { + from: Accounts.masterMinterAccount, + }) + ); + assert.isTrue( + addressEquals( + await proxy.admin({ from: Accounts.proxyOwnerAccount }), + Accounts.proxyOwnerAccount + ) + ); customVars = []; await checkVariables([token], [customVars]); }); - it('nut003 should fail to upgradeTo to null contract address', async function () { + it("nut003 should fail to upgradeTo to null contract address", async function () { var upgradedToken = await UpgradedFiatToken.new(); - await expectRevert(proxy.upgradeTo(zeroAddress, {from: Accounts.proxyOwnerAccount})); + await expectRevert( + proxy.upgradeTo(zeroAddress, { from: Accounts.proxyOwnerAccount }) + ); customVars = []; await checkVariables([token], [customVars]); }); - it('nut004 should fail to upgradeToAndCall to null contract address', async function () { + it("nut004 should fail to upgradeToAndCall to null contract address", async function () { var upgradedToken = await UpgradedFiatToken.new(); - const initializeData = encodeCall('pauser', [], []); - await expectRevert(proxy.upgradeToAndCall(zeroAddress, initializeData, { from: Accounts.proxyOwnerAccount })); + const initializeData = encodeCall("pauser", [], []); + await expectRevert( + proxy.upgradeToAndCall(zeroAddress, initializeData, { + from: Accounts.proxyOwnerAccount, + }) + ); customVars = []; await checkVariables([token], [customVars]); }); - it('nut005 should fail to initialize contract twice', async function () { - await expectRevert(token.initialize(name, symbol, currency, decimals, Accounts.masterMinterAccount, Accounts.pauserAccount, Accounts.blacklisterAccount, Accounts.tokenOwnerAccount)); + it("nut005 should fail to initialize contract twice", async function () { + await expectRevert( + token.initialize( + name, + symbol, + currency, + decimals, + Accounts.masterMinterAccount, + Accounts.pauserAccount, + Accounts.blacklisterAccount, + Accounts.tokenOwnerAccount + ) + ); customVars = []; await checkVariables([token], [customVars]); }); - it('nut006 should fail to call contract function with adminAccount', async function () { - await expectRevert(token.allowance(Accounts.minterAccount, Accounts.arbitraryAccount, { from: Accounts.proxyOwnerAccount })); + it("nut006 should fail to call contract function with adminAccount", async function () { + await expectRevert( + token.allowance(Accounts.minterAccount, Accounts.arbitraryAccount, { + from: Accounts.proxyOwnerAccount, + }) + ); customVars = []; await checkVariables([token], [customVars]); }); - it('nut007 should fail to call proxy function with non-adminAccount', async function () { + it("nut007 should fail to call proxy function with non-adminAccount", async function () { await expectRevert(proxy.admin({ from: Accounts.masterMinterAccount })); customVars = []; await checkVariables([token], [customVars]); }); - it('nut008 shoud fail to update proxy storage if state-changing function called directly in FiatToken', async function () { - await rawToken.initialize(name, symbol, currency, decimals, Accounts.masterMinterAccount, Accounts.pauserAccount, Accounts.blacklisterAccount, Accounts.tokenOwnerAccount); - assert.isTrue(addressEquals(await rawToken.pauser(), Accounts.pauserAccount)); - await rawToken.updatePauser(Accounts.masterMinterAccount, {from: Accounts.tokenOwnerAccount}); - assert.isTrue(addressEquals(await rawToken.pauser(), Accounts.masterMinterAccount)); + it("nut008 shoud fail to update proxy storage if state-changing function called directly in FiatToken", async function () { + await rawToken.initialize( + name, + symbol, + currency, + decimals, + Accounts.masterMinterAccount, + Accounts.pauserAccount, + Accounts.blacklisterAccount, + Accounts.tokenOwnerAccount + ); + assert.isTrue( + addressEquals(await rawToken.pauser(), Accounts.pauserAccount) + ); + await rawToken.updatePauser(Accounts.masterMinterAccount, { + from: Accounts.tokenOwnerAccount, + }); + assert.isTrue( + addressEquals(await rawToken.pauser(), Accounts.masterMinterAccount) + ); customVars = []; await checkVariables([token], [customVars]); }); - it('nut009 should fail to call upgradeTo with non-adminAccount', async function () { + it("nut009 should fail to call upgradeTo with non-adminAccount", async function () { var upgradedToken = await UpgradedFiatToken.new(); - await expectRevert(proxy.upgradeTo(upgradedToken.address, {from:Accounts.masterMinterAccount})); + await expectRevert( + proxy.upgradeTo(upgradedToken.address, { + from: Accounts.masterMinterAccount, + }) + ); var finalToken = await FiatToken.at(proxy.address); - var implementation = await proxy.implementation({from: Accounts.proxyOwnerAccount}); + var implementation = await proxy.implementation({ + from: Accounts.proxyOwnerAccount, + }); finalToken.proxiedTokenAddress = implementation; customVars = []; await checkVariables([finalToken], [customVars]); }); - it('nut010 should fail to call updateToAndCall with non-adminAccount', async function () { + it("nut010 should fail to call updateToAndCall with non-adminAccount", async function () { var upgradedToken = await UpgradedFiatTokenNewFields.new(); - const initializeData = encodeCall('initialize', ['bool', 'address', 'uint256'], [true, Accounts.pauserAccount, 12]); - await expectRevert(proxy.upgradeToAndCall(upgradedToken.address, initializeData, { from: Accounts.masterMinterAccount })); + const initializeData = encodeCall( + "initialize", + ["bool", "address", "uint256"], + [true, Accounts.pauserAccount, 12] + ); + await expectRevert( + proxy.upgradeToAndCall(upgradedToken.address, initializeData, { + from: Accounts.masterMinterAccount, + }) + ); var finalToken = await FiatToken.at(proxy.address); - var implementation = await proxy.implementation({from: Accounts.proxyOwnerAccount}); + var implementation = await proxy.implementation({ + from: Accounts.proxyOwnerAccount, + }); finalToken.proxiedTokenAddress = implementation; customVars = []; await checkVariables([finalToken], [customVars]); }); - it('nut011 should fail to upgradeToAndCall with initialize (already set variables)', async function () { + it("nut011 should fail to upgradeToAndCall with initialize (already set variables)", async function () { let mintAmount = 50; - await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); - await token.mint(Accounts.arbitraryAccount, mintAmount, { from: Accounts.minterAccount }); - await token.transfer(Accounts.arbitraryAccount2, mintAmount, { from: Accounts.arbitraryAccount }); + await token.configureMinter(Accounts.minterAccount, amount, { + from: Accounts.masterMinterAccount, + }); + await token.mint(Accounts.arbitraryAccount, mintAmount, { + from: Accounts.minterAccount, + }); + await token.transfer(Accounts.arbitraryAccount2, mintAmount, { + from: Accounts.arbitraryAccount, + }); var upgradedToken = await UpgradedFiatTokenNewFields.new(); - var data = encodeCall('initialize', ['string','string','string','uint8','address','address','address','address','bool','address','uint256'], [name, symbol, currency, decimals, Accounts.masterMinterAccount, Accounts.arbitraryAccount2, Accounts.blacklisterAccount, Accounts.tokenOwnerAccount, true, Accounts.arbitraryAccount2, 12]); - await expectRevert(proxy.upgradeToAndCall(upgradedToken.address, data, { from: Accounts.proxyOwnerAccount })); + var data = encodeCall( + "initialize", + [ + "string", + "string", + "string", + "uint8", + "address", + "address", + "address", + "address", + "bool", + "address", + "uint256", + ], + [ + name, + symbol, + currency, + decimals, + Accounts.masterMinterAccount, + Accounts.arbitraryAccount2, + Accounts.blacklisterAccount, + Accounts.tokenOwnerAccount, + true, + Accounts.arbitraryAccount2, + 12, + ] + ); + await expectRevert( + proxy.upgradeToAndCall(upgradedToken.address, data, { + from: Accounts.proxyOwnerAccount, + }) + ); customVars = [ - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - mintAmount) }, - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'balances.arbitraryAccount', 'expectedValue': bigZero }, - { 'variable': 'balances.arbitraryAccount2', 'expectedValue': newBigNumber(mintAmount) }, - { 'variable': 'totalSupply', 'expectedValue': newBigNumber(mintAmount) }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount - mintAmount), + }, + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { variable: "balances.arbitraryAccount", expectedValue: bigZero }, + { + variable: "balances.arbitraryAccount2", + expectedValue: newBigNumber(mintAmount), + }, + { variable: "totalSupply", expectedValue: newBigNumber(mintAmount) }, ]; await checkVariables([token], [customVars]); - }); - + }); } -var testWrapper = require('./../TestWrapper'); -testWrapper.execute('FiatToken_ProxyNegativeTests', run_tests); +var testWrapper = require("./../TestWrapper"); +testWrapper.execute("FiatToken_ProxyNegativeTests", run_tests); module.exports = { run_tests: run_tests, -} +}; diff --git a/test/proxy/ProxyPositiveTests.js b/test/proxy/ProxyPositiveTests.js index 69adf3296..97567ed33 100644 --- a/test/proxy/ProxyPositiveTests.js +++ b/test/proxy/ProxyPositiveTests.js @@ -1,6 +1,6 @@ -var tokenUtils = require('./../TokenTestUtils');; +var tokenUtils = require("./../TokenTestUtils"); var newBigNumber = tokenUtils.newBigNumber; -var assertDiff = require('assert-diff'); +var assertDiff = require("assert-diff"); assertDiff.options.strict = true; var bigZero = tokenUtils.bigZero; @@ -20,14 +20,15 @@ var FiatToken = tokenUtils.FiatToken; var FiatTokenProxy = tokenUtils.FiatTokenProxy; var UpgradedFiatToken = tokenUtils.UpgradedFiatToken; var UpgradedFiatTokenNewFields = tokenUtils.UpgradedFiatTokenNewFields; -var UpgradedFiatTokenNewFieldsNewLogic = tokenUtils.UpgradedFiatTokenNewFieldsNewLogic; +var UpgradedFiatTokenNewFieldsNewLogic = + tokenUtils.UpgradedFiatTokenNewFieldsNewLogic; var getAdmin = tokenUtils.getAdmin; -var abiUtils = require('./../ABIUtils'); +var abiUtils = require("./../ABIUtils"); var makeRawTransaction = abiUtils.makeRawTransaction; var sendRawTransaction = abiUtils.sendRawTransaction; -var AccountUtils = require('./../AccountUtils'); +var AccountUtils = require("./../AccountUtils"); var Accounts = AccountUtils.Accounts; var AccountPrivateKeys = AccountUtils.AccountPrivateKeys; var addressEquals = AccountUtils.addressEquals; @@ -36,8 +37,7 @@ var addressNotEquals = AccountUtils.addressNotEquals; var amount = 100; async function run_tests(newToken, accounts) { - - beforeEach('Make fresh token contract', async function () { + beforeEach("Make fresh token contract", async function () { rawToken = await newToken(); var tokenConfig = await initializeTokenWithProxy(rawToken); proxy = tokenConfig.proxy; @@ -45,272 +45,491 @@ async function run_tests(newToken, accounts) { assert.isTrue(addressEquals(proxy.address, token.address)); }); - it('upt001 should upgradeTo new contract and preserve data field values', async function () { - let mintAmount = 50; + it("upt001 should upgradeTo new contract and preserve data field values", async function () { + let mintAmount = 50; - await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); - await token.mint(Accounts.arbitraryAccount, mintAmount, { from: Accounts.minterAccount }); - await token.transfer(Accounts.arbitraryAccount2, mintAmount, { from: Accounts.arbitraryAccount }); + await token.configureMinter(Accounts.minterAccount, amount, { + from: Accounts.masterMinterAccount, + }); + await token.mint(Accounts.arbitraryAccount, mintAmount, { + from: Accounts.minterAccount, + }); + await token.transfer(Accounts.arbitraryAccount2, mintAmount, { + from: Accounts.arbitraryAccount, + }); var upgradedToken = await UpgradedFiatToken.new(); - var tokenConfig = await upgradeTo(proxy, upgradedToken, Accounts.proxyOwnerAccount); + var tokenConfig = await upgradeTo( + proxy, + upgradedToken, + Accounts.proxyOwnerAccount + ); var newToken = tokenConfig.token; customVars = [ - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - mintAmount) }, - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'balances.arbitraryAccount', 'expectedValue': bigZero }, - { 'variable': 'balances.arbitraryAccount2', 'expectedValue': newBigNumber(mintAmount) }, - { 'variable': 'totalSupply', 'expectedValue': newBigNumber(mintAmount) }, - { 'variable': 'proxiedTokenAddress', 'expectedValue': upgradedToken.address } + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount - mintAmount), + }, + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { variable: "balances.arbitraryAccount", expectedValue: bigZero }, + { + variable: "balances.arbitraryAccount2", + expectedValue: newBigNumber(mintAmount), + }, + { variable: "totalSupply", expectedValue: newBigNumber(mintAmount) }, + { variable: "proxiedTokenAddress", expectedValue: upgradedToken.address }, ]; await checkVariables([newToken], [customVars]); }); - it('upt002 should upgradeToandCall to contract with new data fields set on initVX and ensure new fields are correct and old data is preserved', async function () { + it("upt002 should upgradeToandCall to contract with new data fields set on initVX and ensure new fields are correct and old data is preserved", async function () { let mintAmount = 50; - await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); - await token.mint(Accounts.arbitraryAccount, mintAmount, { from: Accounts.minterAccount }); - await token.transfer(Accounts.arbitraryAccount2, mintAmount, { from: Accounts.arbitraryAccount }); + await token.configureMinter(Accounts.minterAccount, amount, { + from: Accounts.masterMinterAccount, + }); + await token.mint(Accounts.arbitraryAccount, mintAmount, { + from: Accounts.minterAccount, + }); + await token.transfer(Accounts.arbitraryAccount2, mintAmount, { + from: Accounts.arbitraryAccount, + }); var upgradedToken = await UpgradedFiatTokenNewFields.new(); - const initializeData = encodeCall('initV2', ['bool', 'address', 'uint256'], [true, Accounts.pauserAccount, 12]); - await proxy.upgradeToAndCall(upgradedToken.address, initializeData, { from: Accounts.proxyOwnerAccount }) + const initializeData = encodeCall( + "initV2", + ["bool", "address", "uint256"], + [true, Accounts.pauserAccount, 12] + ); + await proxy.upgradeToAndCall(upgradedToken.address, initializeData, { + from: Accounts.proxyOwnerAccount, + }); newProxiedToken = await UpgradedFiatTokenNewFields.at(proxy.address); assert.isTrue(addressEquals(newProxiedToken.address, proxy.address)); addressNotEquals(newProxiedToken.address, upgradedToken.address); assert.equal(await newProxiedToken.newBool(), true); - assert.isTrue(addressEquals(await newProxiedToken.newAddress(), Accounts.pauserAccount)); + assert.isTrue( + addressEquals(await newProxiedToken.newAddress(), Accounts.pauserAccount) + ); assert.equal(newBigNumber(12).cmp(await newProxiedToken.newUint()), 0); customVars = [ - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - mintAmount) }, - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'balances.arbitraryAccount', 'expectedValue': bigZero }, - { 'variable': 'balances.arbitraryAccount2', 'expectedValue': newBigNumber(mintAmount) }, - { 'variable': 'totalSupply', 'expectedValue': newBigNumber(mintAmount) }, - { 'variable': 'proxiedTokenAddress', 'expectedValue': upgradedToken.address } + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount - mintAmount), + }, + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { variable: "balances.arbitraryAccount", expectedValue: bigZero }, + { + variable: "balances.arbitraryAccount2", + expectedValue: newBigNumber(mintAmount), + }, + { variable: "totalSupply", expectedValue: newBigNumber(mintAmount) }, + { variable: "proxiedTokenAddress", expectedValue: upgradedToken.address }, ]; await checkVariables([newProxiedToken], [customVars]); }); - it('upt003 should upgradeToAndCall to contract with new data fields set on initVX and new logic and ensure old data preserved,new logic works, and new fields correct', async function () { + it("upt003 should upgradeToAndCall to contract with new data fields set on initVX and new logic and ensure old data preserved,new logic works, and new fields correct", async function () { let mintAmount = 50; - await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); - await token.mint(Accounts.arbitraryAccount, mintAmount, { from: Accounts.minterAccount }); - await token.transfer(Accounts.arbitraryAccount2, mintAmount, { from: Accounts.arbitraryAccount }); + await token.configureMinter(Accounts.minterAccount, amount, { + from: Accounts.masterMinterAccount, + }); + await token.mint(Accounts.arbitraryAccount, mintAmount, { + from: Accounts.minterAccount, + }); + await token.transfer(Accounts.arbitraryAccount2, mintAmount, { + from: Accounts.arbitraryAccount, + }); var upgradedToken = await UpgradedFiatTokenNewFieldsNewLogic.new(); - const initializeData = encodeCall('initV2', ['bool', 'address', 'uint256'], [true, Accounts.pauserAccount, 12]); - await proxy.upgradeToAndCall(upgradedToken.address, initializeData, { from: Accounts.proxyOwnerAccount }) - newProxiedToken = await UpgradedFiatTokenNewFieldsNewLogic.at(proxy.address); + const initializeData = encodeCall( + "initV2", + ["bool", "address", "uint256"], + [true, Accounts.pauserAccount, 12] + ); + await proxy.upgradeToAndCall(upgradedToken.address, initializeData, { + from: Accounts.proxyOwnerAccount, + }); + newProxiedToken = await UpgradedFiatTokenNewFieldsNewLogic.at( + proxy.address + ); assert.isTrue(addressEquals(newProxiedToken.address, proxy.address)); addressNotEquals(newProxiedToken.address, upgradedToken.address); assert.equal(await newProxiedToken.newBool(), true); - assert.isTrue(addressEquals(await newProxiedToken.newAddress(), Accounts.pauserAccount)); + assert.isTrue( + addressEquals(await newProxiedToken.newAddress(), Accounts.pauserAccount) + ); assert.equal(newBigNumber(12).cmp(await newProxiedToken.newUint()), 0); await newProxiedToken.setNewAddress(Accounts.masterMinterAccount); - assert.isTrue(addressEquals(await newProxiedToken.newAddress(), Accounts.masterMinterAccount)); + assert.isTrue( + addressEquals( + await newProxiedToken.newAddress(), + Accounts.masterMinterAccount + ) + ); customVars = [ - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - mintAmount) }, - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'balances.arbitraryAccount', 'expectedValue': bigZero }, - { 'variable': 'balances.arbitraryAccount2', 'expectedValue': newBigNumber(mintAmount) }, - { 'variable': 'totalSupply', 'expectedValue': newBigNumber(mintAmount) }, - { 'variable': 'proxiedTokenAddress', 'expectedValue': upgradedToken.address } + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount - mintAmount), + }, + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { variable: "balances.arbitraryAccount", expectedValue: bigZero }, + { + variable: "balances.arbitraryAccount2", + expectedValue: newBigNumber(mintAmount), + }, + { variable: "totalSupply", expectedValue: newBigNumber(mintAmount) }, + { variable: "proxiedTokenAddress", expectedValue: upgradedToken.address }, ]; await checkVariables([newProxiedToken], [customVars]); }); - it('upt008 should deploy upgraded version of contract with new data fields and without previous deployment and ensure new fields correct', async function() { + it("upt008 should deploy upgraded version of contract with new data fields and without previous deployment and ensure new fields correct", async function () { var upgradedToken = await UpgradedFiatTokenNewFields.new(); - const newProxy = await FiatTokenProxy.new(upgradedToken.address, { from: Accounts.proxyOwnerAccount }); + const newProxy = await FiatTokenProxy.new(upgradedToken.address, { + from: Accounts.proxyOwnerAccount, + }); proxiedToken = await UpgradedFiatTokenNewFields.at(newProxy.address); - var data = encodeCall('initialize', ['string','string','string','uint8','address','address','address','address','bool','address','uint256'], [name, symbol, currency, decimals, Accounts.masterMinterAccount, Accounts.pauserAccount, Accounts.blacklisterAccount, Accounts.tokenOwnerAccount, true, Accounts.pauserAccount, 12]); - var upgradeToRawTx = await makeRawTransaction(data, Accounts.masterMinterAccount, AccountPrivateKeys.masterMinterPrivateKey, proxiedToken.address) + var data = encodeCall( + "initialize", + [ + "string", + "string", + "string", + "uint8", + "address", + "address", + "address", + "address", + "bool", + "address", + "uint256", + ], + [ + name, + symbol, + currency, + decimals, + Accounts.masterMinterAccount, + Accounts.pauserAccount, + Accounts.blacklisterAccount, + Accounts.tokenOwnerAccount, + true, + Accounts.pauserAccount, + 12, + ] + ); + var upgradeToRawTx = await makeRawTransaction( + data, + Accounts.masterMinterAccount, + AccountPrivateKeys.masterMinterPrivateKey, + proxiedToken.address + ); await sendRawTransaction(upgradeToRawTx); assert.equal(await proxiedToken.newUint(), 12); assert.equal(await proxiedToken.newBool(), true); - assert.isTrue(addressEquals(await proxiedToken.newAddress(), Accounts.pauserAccount)); + assert.isTrue( + addressEquals(await proxiedToken.newAddress(), Accounts.pauserAccount) + ); customVars = [ - { 'variable': 'proxiedTokenAddress', 'expectedValue': upgradedToken.address } + { variable: "proxiedTokenAddress", expectedValue: upgradedToken.address }, ]; await checkVariables([proxiedToken], [customVars]); - }); + }); - it('upt010 should deploy upgraded version of contract with new data fields and logic without previous deployment and ensure new logic works, and new fields correct', async function() { + it("upt010 should deploy upgraded version of contract with new data fields and logic without previous deployment and ensure new logic works, and new fields correct", async function () { var upgradedToken = await UpgradedFiatTokenNewFields.new(); - const newProxy = await FiatTokenProxy.new(upgradedToken.address, { from: Accounts.proxyOwnerAccount }); + const newProxy = await FiatTokenProxy.new(upgradedToken.address, { + from: Accounts.proxyOwnerAccount, + }); proxiedToken = await UpgradedFiatTokenNewFields.at(newProxy.address); - var data = encodeCall('initialize', ['string','string','string','uint8','address','address','address','address','bool','address','uint256'], [name, symbol, currency, decimals, Accounts.masterMinterAccount, Accounts.pauserAccount, Accounts.blacklisterAccount, Accounts.tokenOwnerAccount, true, Accounts.pauserAccount, 12]); - var upgradeToRawTx = await makeRawTransaction(data, Accounts.masterMinterAccount, AccountPrivateKeys.masterMinterPrivateKey, proxiedToken.address) + var data = encodeCall( + "initialize", + [ + "string", + "string", + "string", + "uint8", + "address", + "address", + "address", + "address", + "bool", + "address", + "uint256", + ], + [ + name, + symbol, + currency, + decimals, + Accounts.masterMinterAccount, + Accounts.pauserAccount, + Accounts.blacklisterAccount, + Accounts.tokenOwnerAccount, + true, + Accounts.pauserAccount, + 12, + ] + ); + var upgradeToRawTx = await makeRawTransaction( + data, + Accounts.masterMinterAccount, + AccountPrivateKeys.masterMinterPrivateKey, + proxiedToken.address + ); await sendRawTransaction(upgradeToRawTx); assert.equal(await proxiedToken.newUint(), 12); assert.equal(await proxiedToken.newBool(), true); - assert.isTrue(addressEquals(await proxiedToken.newAddress(), Accounts.pauserAccount)); + assert.isTrue( + addressEquals(await proxiedToken.newAddress(), Accounts.pauserAccount) + ); await newProxiedToken.setNewAddress(Accounts.masterMinterAccount); - assert.isTrue(addressEquals(await newProxiedToken.newAddress(), Accounts.masterMinterAccount)); + assert.isTrue( + addressEquals( + await newProxiedToken.newAddress(), + Accounts.masterMinterAccount + ) + ); customVars = [ - { 'variable': 'proxiedTokenAddress', 'expectedValue': upgradedToken.address } + { variable: "proxiedTokenAddress", expectedValue: upgradedToken.address }, ]; await checkVariables([proxiedToken], [customVars]); - }); + }); - it('upt004 should update proxy adminAccount with previous adminAccount', async function () { - await proxy.changeAdmin(Accounts.masterMinterAccount, {from: Accounts.proxyOwnerAccount}); + it("upt004 should update proxy adminAccount with previous adminAccount", async function () { + await proxy.changeAdmin(Accounts.masterMinterAccount, { + from: Accounts.proxyOwnerAccount, + }); customVars = [ - { 'variable': 'proxyOwner', 'expectedValue': Accounts.masterMinterAccount}, - ] + { variable: "proxyOwner", expectedValue: Accounts.masterMinterAccount }, + ]; await checkVariables([token], [customVars]); }); - it('upt005 should receive Transfer event on transfer when proxied after upgrade', async function () { + it("upt005 should receive Transfer event on transfer when proxied after upgrade", async function () { let mintAmount = 50; - await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); - await token.mint(Accounts.arbitraryAccount, mintAmount + 1, { from: Accounts.minterAccount }); - await token.transfer(Accounts.arbitraryAccount2, mintAmount, { from: Accounts.arbitraryAccount }); + await token.configureMinter(Accounts.minterAccount, amount, { + from: Accounts.masterMinterAccount, + }); + await token.mint(Accounts.arbitraryAccount, mintAmount + 1, { + from: Accounts.minterAccount, + }); + await token.transfer(Accounts.arbitraryAccount2, mintAmount, { + from: Accounts.arbitraryAccount, + }); var upgradedToken = await UpgradedFiatToken.new(); - var tokenConfig = await upgradeTo(proxy, upgradedToken, Accounts.proxyOwnerAccount); + var tokenConfig = await upgradeTo( + proxy, + upgradedToken, + Accounts.proxyOwnerAccount + ); var newToken = tokenConfig.token; - transfer = await newToken.transfer(Accounts.arbitraryAccount2, 1, { from: Accounts.arbitraryAccount}); - validateTransferEvent(transfer, Accounts.arbitraryAccount, Accounts.arbitraryAccount2, 1); + transfer = await newToken.transfer(Accounts.arbitraryAccount2, 1, { + from: Accounts.arbitraryAccount, + }); + validateTransferEvent( + transfer, + Accounts.arbitraryAccount, + Accounts.arbitraryAccount2, + 1 + ); customVars = [ - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - mintAmount - 1) }, - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'balances.arbitraryAccount', 'expectedValue': bigZero }, - { 'variable': 'balances.arbitraryAccount2', 'expectedValue': newBigNumber(mintAmount + 1) }, - { 'variable': 'totalSupply', 'expectedValue': newBigNumber(mintAmount + 1) }, - { 'variable': 'proxiedTokenAddress', 'expectedValue': upgradedToken.address } + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount - mintAmount - 1), + }, + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { variable: "balances.arbitraryAccount", expectedValue: bigZero }, + { + variable: "balances.arbitraryAccount2", + expectedValue: newBigNumber(mintAmount + 1), + }, + { variable: "totalSupply", expectedValue: newBigNumber(mintAmount + 1) }, + { variable: "proxiedTokenAddress", expectedValue: upgradedToken.address }, ]; await checkVariables([newToken], [customVars]); }); - it('upt006 should upgrade while paused and upgraded contract should be paused as a result; then unpause should unpause contract', async function () { - await token.pause({from: Accounts.pauserAccount}); + it("upt006 should upgrade while paused and upgraded contract should be paused as a result; then unpause should unpause contract", async function () { + await token.pause({ from: Accounts.pauserAccount }); var upgradedToken = await UpgradedFiatToken.new(); - var tokenConfig = await upgradeTo(proxy, upgradedToken, Accounts.proxyOwnerAccount); + var tokenConfig = await upgradeTo( + proxy, + upgradedToken, + Accounts.proxyOwnerAccount + ); var newToken = tokenConfig.token; customVars = [ - { 'variable': 'paused', 'expectedValue': true, }, - { 'variable': 'proxiedTokenAddress', 'expectedValue': upgradedToken.address } + { variable: "paused", expectedValue: true }, + { variable: "proxiedTokenAddress", expectedValue: upgradedToken.address }, ]; await checkVariables([newToken], [customVars]); - await newToken.unpause({from:Accounts.pauserAccount}); + await newToken.unpause({ from: Accounts.pauserAccount }); customVars2 = [ - { 'variable': 'proxiedTokenAddress', 'expectedValue': upgradedToken.address } + { variable: "proxiedTokenAddress", expectedValue: upgradedToken.address }, ]; await checkVariables([newToken], [customVars2]); }); - it('upt007 should upgrade contract to original address', async function () { + it("upt007 should upgrade contract to original address", async function () { let mintAmount = 50; - await token.configureMinter(Accounts.minterAccount, amount, { from: Accounts.masterMinterAccount }); - await token.mint(Accounts.arbitraryAccount, mintAmount, { from: Accounts.minterAccount }); - await token.transfer(Accounts.arbitraryAccount2, mintAmount, { from: Accounts.arbitraryAccount }); - - var tokenConfig = await upgradeTo(proxy, rawToken, Accounts.proxyOwnerAccount); + await token.configureMinter(Accounts.minterAccount, amount, { + from: Accounts.masterMinterAccount, + }); + await token.mint(Accounts.arbitraryAccount, mintAmount, { + from: Accounts.minterAccount, + }); + await token.transfer(Accounts.arbitraryAccount2, mintAmount, { + from: Accounts.arbitraryAccount, + }); + + var tokenConfig = await upgradeTo( + proxy, + rawToken, + Accounts.proxyOwnerAccount + ); var sameToken = tokenConfig.token; sameToken.proxiedTokenAddress = rawToken.address; customVars = [ - { 'variable': 'minterAllowance.minterAccount', 'expectedValue': newBigNumber(amount - mintAmount) }, - { 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true }, - { 'variable': 'balances.arbitraryAccount', 'expectedValue': bigZero }, - { 'variable': 'balances.arbitraryAccount2', 'expectedValue': newBigNumber(mintAmount) }, - { 'variable': 'totalSupply', 'expectedValue': newBigNumber(mintAmount) }, + { + variable: "minterAllowance.minterAccount", + expectedValue: newBigNumber(amount - mintAmount), + }, + { variable: "isAccountMinter.minterAccount", expectedValue: true }, + { variable: "balances.arbitraryAccount", expectedValue: bigZero }, + { + variable: "balances.arbitraryAccount2", + expectedValue: newBigNumber(mintAmount), + }, + { variable: "totalSupply", expectedValue: newBigNumber(mintAmount) }, ]; await checkVariables([sameToken], [customVars]); }); - - it('upt009 should check that admin is set correctly by proxy constructor', async function() { - assert.isTrue(addressEquals(await getAdmin(token), Accounts.proxyOwnerAccount)); + + it("upt009 should check that admin is set correctly by proxy constructor", async function () { + assert.isTrue( + addressEquals(await getAdmin(token), Accounts.proxyOwnerAccount) + ); }); - it('upt011 should upgradeToAndCall while paused and upgraded contract should be paused as a result', async function () { - await token.pause({from: Accounts.pauserAccount}); + it("upt011 should upgradeToAndCall while paused and upgraded contract should be paused as a result", async function () { + await token.pause({ from: Accounts.pauserAccount }); var upgradedToken = await UpgradedFiatTokenNewFields.new(); - const initializeData = encodeCall('initV2', ['bool', 'address', 'uint256'], [true, Accounts.pauserAccount, 12]); - await proxy.upgradeToAndCall(upgradedToken.address, initializeData, { from: Accounts.proxyOwnerAccount }) + const initializeData = encodeCall( + "initV2", + ["bool", "address", "uint256"], + [true, Accounts.pauserAccount, 12] + ); + await proxy.upgradeToAndCall(upgradedToken.address, initializeData, { + from: Accounts.proxyOwnerAccount, + }); newProxiedToken = await UpgradedFiatTokenNewFields.at(proxy.address); assert.isTrue(addressEquals(newProxiedToken.address, proxy.address)); addressNotEquals(newProxiedToken.address, upgradedToken.address); customVars = [ - { 'variable': 'paused', 'expectedValue': true, }, - { 'variable': 'proxiedTokenAddress', 'expectedValue': upgradedToken.address } + { variable: "paused", expectedValue: true }, + { variable: "proxiedTokenAddress", expectedValue: upgradedToken.address }, ]; await checkVariables([newProxiedToken], [customVars]); }); - it('upt012 should upgradeToAndCall while proxyOwner is blacklisted', async function () { - await token.blacklist(Accounts.proxyOwnerAccount, {from: Accounts.blacklisterAccount}); + it("upt012 should upgradeToAndCall while proxyOwner is blacklisted", async function () { + await token.blacklist(Accounts.proxyOwnerAccount, { + from: Accounts.blacklisterAccount, + }); var upgradedToken = await UpgradedFiatTokenNewFields.new(); - const initializeData = encodeCall('initV2', ['bool', 'address', 'uint256'], [true, Accounts.pauserAccount, 12]); - await proxy.upgradeToAndCall(upgradedToken.address, initializeData, { from: Accounts.proxyOwnerAccount }) + const initializeData = encodeCall( + "initV2", + ["bool", "address", "uint256"], + [true, Accounts.pauserAccount, 12] + ); + await proxy.upgradeToAndCall(upgradedToken.address, initializeData, { + from: Accounts.proxyOwnerAccount, + }); newProxiedToken = await UpgradedFiatTokenNewFields.at(proxy.address); customVars = [ - { 'variable': 'isAccountBlacklisted.proxyOwnerAccount', 'expectedValue': true, }, - { 'variable': 'proxiedTokenAddress', 'expectedValue': upgradedToken.address } + { + variable: "isAccountBlacklisted.proxyOwnerAccount", + expectedValue: true, + }, + { variable: "proxiedTokenAddress", expectedValue: upgradedToken.address }, ]; await checkVariables([newProxiedToken], [customVars]); }); - it('upt013 should upgradeToAndCall while new logic is blacklisted', async function () { + it("upt013 should upgradeToAndCall while new logic is blacklisted", async function () { var upgradedToken = await UpgradedFiatTokenNewFields.new(); - await token.blacklist(upgradedToken.address, {from: Accounts.blacklisterAccount}); - - const initializeData = encodeCall('initV2', ['bool', 'address', 'uint256'], [true, Accounts.pauserAccount, 12]); - await proxy.upgradeToAndCall(upgradedToken.address, initializeData, { from: Accounts.proxyOwnerAccount }) + await token.blacklist(upgradedToken.address, { + from: Accounts.blacklisterAccount, + }); + + const initializeData = encodeCall( + "initV2", + ["bool", "address", "uint256"], + [true, Accounts.pauserAccount, 12] + ); + await proxy.upgradeToAndCall(upgradedToken.address, initializeData, { + from: Accounts.proxyOwnerAccount, + }); newProxiedToken = await UpgradedFiatTokenNewFields.at(proxy.address); customVars = [ - { 'variable': 'proxiedTokenAddress', 'expectedValue': upgradedToken.address } + { variable: "proxiedTokenAddress", expectedValue: upgradedToken.address }, ]; await checkVariables([newProxiedToken], [customVars]); }); - it('upt014 should upgradeTo while new logic is blacklisted', async function () { + it("upt014 should upgradeTo while new logic is blacklisted", async function () { var upgradedToken = await UpgradedFiatToken.new(); - await token.blacklist(upgradedToken.address, {from: Accounts.blacklisterAccount}); - - var tokenConfig = await upgradeTo(proxy, upgradedToken, Accounts.proxyOwnerAccount); + await token.blacklist(upgradedToken.address, { + from: Accounts.blacklisterAccount, + }); + + var tokenConfig = await upgradeTo( + proxy, + upgradedToken, + Accounts.proxyOwnerAccount + ); var newToken = tokenConfig.token; customVars = [ - { 'variable': 'proxiedTokenAddress', 'expectedValue': upgradedToken.address } + { variable: "proxiedTokenAddress", expectedValue: upgradedToken.address }, ]; await checkVariables([newToken], [customVars]); }); - } -var testWrapper = require('./../TestWrapper'); -testWrapper.execute('FiatToken_ProxyPositiveTests', run_tests); +var testWrapper = require("./../TestWrapper"); +testWrapper.execute("FiatToken_ProxyPositiveTests", run_tests); module.exports = { run_tests: run_tests, -} +}; diff --git a/truffle.js b/truffle.js index 738457419..11ba9196f 100644 --- a/truffle.js +++ b/truffle.js @@ -1,25 +1,27 @@ // INFURA Setup - see validate/README.validate.md for more info var HDWalletProvider = require("truffle-hdwallet-provider"); // These keys will be used only for CALL var mnemonic = "talisman"; -var fs = require('fs'); +var fs = require("fs"); var access_token = "none"; try { - access_token = fs.readFileSync('./validate/apikey.infura','utf8'); + access_token = fs.readFileSync("./validate/apikey.infura", "utf8"); } catch (err) { - console.log("No Infura access token detected. Unit tests will still work. See ./validate/README.validate.md for more details.") + console.log( + "No Infura access token detected. Unit tests will still work. See ./validate/README.validate.md for more details." + ); } module.exports = { compilers: { solc: { - version: "0.4.24" - } + version: "0.4.24", + }, }, networks: { development: { host: "localhost", port: 8545, - network_id: "*" // Match any network id + network_id: "*", // Match any network id }, // solidity-coverage looks for a network called 'coverage' and makes one // identical to this one if it is not found. We want solidity coverage to @@ -30,27 +32,30 @@ module.exports = { network_id: "*", port: 8555, gas: 17592186044415, - gasPrice: 1 + gasPrice: 1, }, // network to refer to ganache by name so it works with truffle/ganache in separate docker containers localTestNet: { host: "ganache", port: 8545, - network_id: "*" // Match any network id + network_id: "*", // Match any network id }, // INFURA Setup infura_mainnet: { - provider: function() { - return new HDWalletProvider(mnemonic, "https://mainnet.infura.io/" + access_token) + provider: function () { + return new HDWalletProvider( + mnemonic, + "https://mainnet.infura.io/" + access_token + ); }, - network_id: 1 - } + network_id: 1, + }, }, mocha: { /* - * To disable the spreadsheet verification tool ensure that - * the reporter is set to 'Spec' by commenting/uncommenting the lines below. - */ + * To disable the spreadsheet verification tool ensure that + * the reporter is set to 'Spec' by commenting/uncommenting the lines below. + */ // reporter: 'Spec', reporter: "verification/verification_reporter.js", }, diff --git a/validate/README.contractDiff.md b/validate/README.contractDiff.md index 251736a92..d8808ef51 100644 --- a/validate/README.contractDiff.md +++ b/validate/README.contractDiff.md @@ -28,8 +28,8 @@ To run the script, type `node validate/contractDiff.js ... ` Where the `filename` is the location of source code downloaded from Etherscan. -Copies of `FiatTokenProxy`, `FiatTokenV1`, and `MasterMinter` are included for testing purposes. -You can test them: +Copies of `FiatTokenProxy`, `FiatTokenV1`, and `MasterMinter` are included for +testing purposes. You can test them: `node validate/contractDiff.js validate/FiatTokenProxy.etherscan validate/FiatTokenV1.etherscan validate/MasterMinter.etherscan` diff --git a/verification/spreadsheet_parser.js b/verification/spreadsheet_parser.js index be5df1f4e..72209d4d9 100644 --- a/verification/spreadsheet_parser.js +++ b/verification/spreadsheet_parser.js @@ -1,12 +1,12 @@ -var fs = require('fs'); -var parse = require('csv-parse/lib/sync'); +var fs = require("fs"); +var parse = require("csv-parse/lib/sync"); // NOTE: SPREADSHEETS_DIR must be relative to truffle.js -var SPREADSHEETS_DIR = './verification/Spreadsheets' +var SPREADSHEETS_DIR = "./verification/Spreadsheets"; -function UnitTest(code, description, pending){ - this.code = code; - this.description = description; - this.pending = pending; +function UnitTest(code, description, pending) { + this.code = code; + this.description = description; + this.pending = pending; } /* @@ -26,118 +26,121 @@ function UnitTest(code, description, pending){ * TODO: handle errors, null objects */ function load() { - var unitTestDirectory = {}; + var unitTestDirectory = {}; - // get names of all files in SPREADSHEETS_DIR - var files = fs.readdirSync(SPREADSHEETS_DIR, (err, data) => { - if(err){ - console.log("error reading " + SPREADSHEETS_DIR + " " + err); - return null; - } - return data; - }); - // process each file into a unitTestSet, then add the - // unitTestSet to unitTestDirectory - files.forEach(file => { - var csvFileContents = fs.readFileSync(SPREADSHEETS_DIR + "/" + file, "utf8"); - if(csvFileContents != null) { - var unitTestSet = {}; - var spreadsheet = parse(csvFileContents, {columns: true}); - spreadsheet.forEach(row => { - if(file.match("Completeness")){ - var unitTestArray = parseCompletenessRow(row); - unitTestArray.forEach(unitTest => {unitTestSet[unitTest.code] = unitTest}); - } else { - var unitTest = parseRow(row); - unitTestSet[unitTest.code] = unitTest; - } - }); - var unittestfilename = getTestSuiteTitle(file); - unitTestDirectory[unittestfilename] = unitTestSet; + // get names of all files in SPREADSHEETS_DIR + var files = fs.readdirSync(SPREADSHEETS_DIR, (err, data) => { + if (err) { + console.log("error reading " + SPREADSHEETS_DIR + " " + err); + return null; + } + return data; + }); + // process each file into a unitTestSet, then add the + // unitTestSet to unitTestDirectory + files.forEach((file) => { + var csvFileContents = fs.readFileSync( + SPREADSHEETS_DIR + "/" + file, + "utf8" + ); + if (csvFileContents != null) { + var unitTestSet = {}; + var spreadsheet = parse(csvFileContents, { columns: true }); + spreadsheet.forEach((row) => { + if (file.match("Completeness")) { + var unitTestArray = parseCompletenessRow(row); + unitTestArray.forEach((unitTest) => { + unitTestSet[unitTest.code] = unitTest; + }); + } else { + var unitTest = parseRow(row); + unitTestSet[unitTest.code] = unitTest; } - }); + }); + var unittestfilename = getTestSuiteTitle(file); + unitTestDirectory[unittestfilename] = unitTestSet; + } + }); - // return array of unitTestDirectory objects - return unitTestDirectory; + // return array of unitTestDirectory objects + return unitTestDirectory; } // // spreadsheet: UnitTestDirectory function isPending(spreadsheet, filename, code) { - if((filename in spreadsheet ) && (code in spreadsheet[filename])) - { - return spreadsheet[filename][code].pending; - } - return false; + if (filename in spreadsheet && code in spreadsheet[filename]) { + return spreadsheet[filename][code].pending; + } + return false; } // Reads a row and tries to find one or more test codes inside the row // Returns an array of UnitTest objects -function parseCompletenessRow(row){ - var unitTests = []; - var index =0; - for(var columnName in row) { - var rowValues = row[columnName].split(","); - for(var potentialCodeIndex in rowValues) { - var codes = rowValues[potentialCodeIndex].match(/([a-z]{2,4})([0-9]+)/g); - for(var codeIndex in codes) { - unitTests[index] = new UnitTest(codes[codeIndex], "", false); - ++index; - } - } +function parseCompletenessRow(row) { + var unitTests = []; + var index = 0; + for (var columnName in row) { + var rowValues = row[columnName].split(","); + for (var potentialCodeIndex in rowValues) { + var codes = rowValues[potentialCodeIndex].match(/([a-z]{2,4})([0-9]+)/g); + for (var codeIndex in codes) { + unitTests[index] = new UnitTest(codes[codeIndex], "", false); + ++index; + } } - return unitTests; + } + return unitTests; } // Transforms a row in spreadsheet into a UnitTest object // row: a literal object. One of the keys must be 'code/Code' and another 'description/Description' // Returns a UnitTest object or null if cannot find appropriate keys. function parseRow(row) { - var test_code = ""; - var testCodeKey = ""; - var pending = false; - var description = ""; - for(var columnName in row) { - if(columnName.trim() == 'code' || columnName.trim() == 'Code') { - test_code = row[columnName].trim(); - testCodeKey = columnName.trim(); - pending = test_code.match(/ -p/); - if (pending) { - test_code = test_code.replace(pending[0], ''); - pending = true; - } else { - pending = false; - } - } + var test_code = ""; + var testCodeKey = ""; + var pending = false; + var description = ""; + for (var columnName in row) { + if (columnName.trim() == "code" || columnName.trim() == "Code") { + test_code = row[columnName].trim(); + testCodeKey = columnName.trim(); + pending = test_code.match(/ -p/); + if (pending) { + test_code = test_code.replace(pending[0], ""); + pending = true; + } else { + pending = false; + } } - var descriptionKey = getDescriptionKey(row, testCodeKey); - description = row[descriptionKey].trim(); - if(test_code == '' || description == '') return null; - return new UnitTest(test_code, description, pending); + } + var descriptionKey = getDescriptionKey(row, testCodeKey); + description = row[descriptionKey].trim(); + if (test_code == "" || description == "") return null; + return new UnitTest(test_code, description, pending); } function getDescriptionKey(row, testCodeKey) { - // get the index of the testCodeKey - var testCodeKeyIndex = 0; - for(var i=0; i Date: Thu, 27 May 2021 20:16:10 -0400 Subject: [PATCH 64/74] linting, test cleanup --- migrations/2_deploy_usdc.js | 72 - ...er_minter.js => 7_deploy_master_minter.js} | 16 +- package.json | 1 + test/ABIUtils.js | 94 -- test/TokenTestUtils.js | 836 ------------ test/assert/ABITests.test.js | 250 ---- test/assert/EventsTests.js | 235 ---- test/assert/FiatTokenLegacy.test.js | 770 ----------- test/assert/Pausable.test.js | 102 -- test/basic/NegativeTests.js | 1176 ----------------- test/basic/PositiveTests.js | 392 ------ test/extended/ExtendedPositiveTests.js | 590 --------- test/{ => minting}/AccountUtils.js | 79 +- test/{ => minting}/ControllerTestUtils.js | 19 +- .../MintControllerTests.js | 68 +- test/{ => minting}/MintControllerUtils.js | 31 +- test/minting/MintP0_ArgumentTests.js | 104 +- .../MintP0_BasicTests.js | 317 +++-- test/{e2e => minting}/MintP0_EndToEndTests.js | 131 +- .../{events => minting}/MintP0_EventsTests.js | 94 +- test/minting2/MintP0_ABITests.js | 87 -- test/misc/MiscTests.js | 981 -------------- test/proxy/ProxyNegativeTests.js | 248 ---- test/proxy/ProxyPositiveTests.js | 535 -------- test/v1/TokenTestUtils.js | 248 +--- test/v1/helpers/tokenTest.js | 13 - truffle.js | 62 - verification/spreadsheet_parser.js | 146 -- verification/verification_reporter.js | 43 +- yarn.lock | 50 +- 30 files changed, 485 insertions(+), 7305 deletions(-) delete mode 100644 migrations/2_deploy_usdc.js rename migrations/{3_deploy_master_minter.js => 7_deploy_master_minter.js} (54%) delete mode 100644 test/ABIUtils.js delete mode 100644 test/TokenTestUtils.js delete mode 100644 test/assert/ABITests.test.js delete mode 100644 test/assert/EventsTests.js delete mode 100644 test/assert/FiatTokenLegacy.test.js delete mode 100644 test/assert/Pausable.test.js delete mode 100644 test/basic/NegativeTests.js delete mode 100644 test/basic/PositiveTests.js delete mode 100644 test/extended/ExtendedPositiveTests.js rename test/{ => minting}/AccountUtils.js (76%) rename test/{ => minting}/ControllerTestUtils.js (69%) rename test/{minting2 => minting}/MintControllerTests.js (85%) rename test/{ => minting}/MintControllerUtils.js (66%) rename test/{minting3 => minting}/MintP0_BasicTests.js (83%) rename test/{e2e => minting}/MintP0_EndToEndTests.js (84%) rename test/{events => minting}/MintP0_EventsTests.js (75%) delete mode 100644 test/minting2/MintP0_ABITests.js delete mode 100644 test/misc/MiscTests.js delete mode 100644 test/proxy/ProxyNegativeTests.js delete mode 100644 test/proxy/ProxyPositiveTests.js delete mode 100644 truffle.js delete mode 100644 verification/spreadsheet_parser.js diff --git a/migrations/2_deploy_usdc.js b/migrations/2_deploy_usdc.js deleted file mode 100644 index d2129ee4d..000000000 --- a/migrations/2_deploy_usdc.js +++ /dev/null @@ -1,72 +0,0 @@ -var FiatTokenV1 = artifacts.require("./FiatTokenV1.sol"); -var FiatTokenProxy = artifacts.require("./FiatTokenProxy.sol"); - -// Any address will do, preferably one we generated -var throwawayAddress = "0x64e078a8aa15a41b85890265648e965de686bae6"; - -module.exports = function (deployer, network, accounts) { - if (network == "development" || network == "coverage") { - // Change these to the cold storage addresses provided by ops - // these are the deterministic addresses from ganache, so the private keys are well known - // and match the values we use in the tests - var admin = "0x2f560290fef1b3ada194b6aa9c40aa71f8e95598"; - var masterMinter = "0x3e5e9111ae8eb78fe1cc3bb8915d5d461f3ef9a9"; - var pauser = "0xaca94ef8bd5ffee41947b4585a84bda5a3d3da6e"; - var blacklister = "0xd03ea8624c8c5987235048901fb614fdca89b117"; - var owner = "0xe11ba2b4d45eaed5996cd0823791e0c93114882d"; - } - - console.log("deploying impl"); - - var fiatTokenImpl; - var tokenProxy; - // deploy implementation contract - deployer - .deploy(FiatTokenV1) - .then(function (impl) { - fiatTokenImpl = impl; - console.log("initializing impl with dummy values"); - return impl.initialize( - "", - "", - "", - 0, - throwawayAddress, - throwawayAddress, - throwawayAddress, - throwawayAddress - ); - }) - .then(function (initDone) { - console.log("deploying proxy"); - return deployer.deploy(FiatTokenProxy, fiatTokenImpl.address); - }) - .then(function (proxy) { - tokenProxy = proxy; - console.log("reassigning proxy admin"); - // need to change admin first, or the call to initialize won't work - // since admin can only call methods in the proxy, and not forwarded methods - return proxy.changeAdmin(admin); - }) - .then(function (changeAdminDone) { - console.log("initializing proxy"); - // Pretend that the proxy address is a FiatTokenV1 - // this is fine because the proxy will forward all the calls to the FiatTokenV1 impl - return FiatTokenV1.at(tokenProxy.address); - }) - .then(function (tokenProxyAsFiatTokenV1) { - return tokenProxyAsFiatTokenV1.initialize( - "USD//C", - "USDC", - "USD", - 6, - masterMinter, - pauser, - blacklister, - owner - ); - }) - .then(function (initDone) { - console.log("Deployer proxy at ", tokenProxy.address); - }); -}; diff --git a/migrations/3_deploy_master_minter.js b/migrations/7_deploy_master_minter.js similarity index 54% rename from migrations/3_deploy_master_minter.js rename to migrations/7_deploy_master_minter.js index 5ae043617..8ac8bbb92 100644 --- a/migrations/3_deploy_master_minter.js +++ b/migrations/7_deploy_master_minter.js @@ -1,12 +1,14 @@ -var MasterMinter = artifacts.require("./MasterMinter.sol"); -var FiatToken = artifacts.require("./FiatTokenProxy.sol"); +const MasterMinter = artifacts.require("./MasterMinter.sol"); +const FiatToken = artifacts.require("./FiatTokenProxy.sol"); +let minterOwner; +let fiatToken; -module.exports = function (deployer, network, accounts) { - if (network == "development" || network == "coverage") { +module.exports = function (deployer, network) { + if (network === "development" || network === "coverage") { // Change these if deploying for real, these are deterministic // address from ganache - var minterOwner = "0x3e5e9111ae8eb78fe1cc3bb8915d5d461f3ef9a9"; - var fiatToken = FiatToken.address; + minterOwner = "0x3e5e9111ae8eb78fe1cc3bb8915d5d461f3ef9a9"; + fiatToken = FiatToken.address; } console.log("deploying MasterMinter for fiat token at " + fiatToken); deployer @@ -16,7 +18,7 @@ module.exports = function (deployer, network, accounts) { console.log("reassigning owner to " + minterOwner); return mm.transferOwnership(minterOwner); }) - .then(function (ownerTransferred) { + .then(function () { console.log("All done."); }); }; diff --git a/package.json b/package.json index 2427d9f34..d480eb462 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ "@types/mocha": "^8.0.0", "@typescript-eslint/eslint-plugin": "^3.7.0", "@typescript-eslint/parser": "^3.7.0", + "assert-diff": "1.2.6", "chai": "^4.2.0", "diff": "^4.0.2", "eslint": "^7.5.0", diff --git a/test/ABIUtils.js b/test/ABIUtils.js deleted file mode 100644 index 5050308ab..000000000 --- a/test/ABIUtils.js +++ /dev/null @@ -1,94 +0,0 @@ -var Tx = require("ethereumjs-tx"); - -async function makeRawTransaction( - msgData, - msgSender, - hexPrivateKey, - contractAddress -) { - var nonce = web3.utils.toHex(await web3.eth.getTransactionCount(msgSender)); - var tx = new Tx({ - nonce: nonce, - gasPrice: web3.utils.toHex(web3.utils.toWei("20", "gwei")), - gasLimit: 1000000, - to: contractAddress, - value: 0, - data: msgData, - }); - var privateKey = Buffer.from(hexPrivateKey, "hex"); - tx.sign(privateKey); - var raw = "0x" + tx.serialize().toString("hex"); - return raw; -} - -function sendRawTransaction(raw) { - return new Promise(function (resolve, reject) { - web3.eth.sendSignedTransaction(raw, function (err, transactionHash) { - if (err !== null) return reject(err); - resolve(transactionHash); - }); - }); -} - -function functionSignature(methodName) { - return web3.utils.sha3(methodName).substr(0, 2 + 8); -} - -function encodeAddress(address) { - address = address.substr(2, address.length - 2); - while (address.length < 64) address = "0" + address; - return address; -} - -function encodeUint(value) { - value = value.toString(16); - while (value.length < 64) value = "0" + value; - return value; -} - -// Create ABI calls for functions -function msgData0(methodName, value) { - return functionSignature(methodName) + encodeUint(value); -} - -function msgData(methodName, addressValue) { - return functionSignature(methodName) + encodeAddress(addressValue); -} - -function msgData1(methodName, address, value) { - return ( - functionSignature(methodName) + encodeAddress(address) + encodeUint(value) - ); -} - -function msgData2(methodName, address1, address2, value) { - return ( - functionSignature(methodName) + - encodeAddress(address1) + - encodeAddress(address2) + - encodeUint(value) - ); -} - -function msgData3(methodName, address1, value1, address2, value2) { - return ( - functionSignature(methodName) + - encodeAddress(address1) + - encodeUint(value1) + - encodeAddress(address2) + - encodeUint(value2) - ); -} - -module.exports = { - makeRawTransaction: makeRawTransaction, - sendRawTransaction: sendRawTransaction, - functionSignature: functionSignature, - encodeAddress: encodeAddress, - encodeUint: encodeUint, - msgData0: msgData0, - msgData: msgData, - msgData1: msgData1, - msgData2: msgData2, - msgData3: msgData3, -}; diff --git a/test/TokenTestUtils.js b/test/TokenTestUtils.js deleted file mode 100644 index 71dc878ed..000000000 --- a/test/TokenTestUtils.js +++ /dev/null @@ -1,836 +0,0 @@ -const util = require("util"); -const abi = require("ethereumjs-abi"); -var _ = require("lodash"); -var clone = require("clone"); -var name = "Sample Fiat Token"; -var symbol = "C-USD"; -var currency = "USD"; -var BN = require("bn.js"); -var BigNumber = require("bignumber.js"); -var trueInStorageFormat = "0x01"; -var decimals = newBigNumber(10); -var bigZero = newBigNumber(0); -var zeroAddress = "0x0000000000000000000000000000000000000000"; -var bigHundred = newBigNumber(100); -var maxAmount = - "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"; -var assertDiff = require("assert-diff"); -assertDiff.options.strict = true; -var Q = require("q"); -var FiatToken = artifacts.require("FiatTokenV1"); -var UpgradedFiatToken = artifacts.require("FiatTokenV2"); -var UpgradedFiatTokenNewFields = artifacts.require("FiatTokenV2NewFieldsTest"); -var UpgradedFiatTokenNewFieldsNewLogic = artifacts.require( - "FiatTokenV2NewFieldsNewLogicTest" -); -var FiatTokenProxy = artifacts.require("FiatTokenProxy"); - -var AccountUtils = require("./AccountUtils"); -var Accounts = AccountUtils.Accounts; -var setAccountDefault = AccountUtils.setAccountDefault; -var recursiveSetAccountDefault = AccountUtils.recursiveSetAccountDefault; -var checkState = AccountUtils.checkState; -var getAccountState = AccountUtils.getAccountState; -var addressEquals = AccountUtils.addressEquals; - -// TODO: test really big numbers Does this still have to be done?? - -var adminSlot = - "0x10d6a54a4754c8869d6886b5f5d7fbfa5b4522237ea5c60d11bc4e7a1ff9390b"; -var implSlot = - "0x7050c9e0f4ca769c69bd3a8ef740bc37934f8e2c036e5a723fd8ee048ed3f8c3"; - -// set to true to enable verbose logging in the tests -var debugLogging = false; - -// Common solidity error messages -var solidityErrors = { - argumentType: "argument must be", -}; - -// Returns a new BN object -function newBigNumber(value) { - var hex = new BigNumber(value).toString(16); - return new BN(hex, 16); -} - -function calculateFeeAmount(amount) { - return Math.floor((fee / feeBase) * amount); -} - -function checkMinterConfiguredEvent( - configureMinterEvent, - minter, - minterAllowedAmount -) { - assert.equal(configureMinterEvent.logs[0].event, "MinterConfigured"); - assert.isTrue( - addressEquals(configureMinterEvent.logs[0].args.minter, minter) - ); - assert.equal( - configureMinterEvent.logs[0].args.minterAllowedAmount, - minterAllowedAmount - ); -} - -function checkMinterRemovedEvent(minterRemovedEvent, minter) { - assert.equal(minterRemovedEvent.logs[0].event, "MinterRemoved"); - assert.isTrue( - addressEquals(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); - assert.equal(transferEvent.logs[0].args.feeAccount, feeAccount); - assert.equal(transferEvent.logs[0].args.feeAmount, feeAmount); - assert.equal(transferEvent.logs[1].event, "Transfer"); - assert.isTrue(addressEquals(transferEvent.logs[1].args.from, from)); - assert.isTrue(addressEquals(transferEvent.logs[1].args.to, to)); - assert.equal(transferEvent.logs[1].args.value, value); -} - -function checkTransferEvents(transferEvent, from, to, value) { - assert.equal(transferEvent.logs[0].event, "Transfer"); - assert.isTrue(addressEquals(transferEvent.logs[0].args.from, from)); - assert.isTrue(addressEquals(transferEvent.logs[0].args.to, to)); - assert.equal(transferEvent.logs[0].args.value, value); -} - -function checkApprovalEvent(approvalEvent, approver, spender, value) { - assert.equal(approvalEvent.logs[0].event, "Approval"); - assert.isTrue(addressEquals(approvalEvent.logs[0].args.owner, approver)); - assert.isTrue(addressEquals(approvalEvent.logs[0].args.spender, spender)); - assert.equal(approvalEvent.logs[0].args.value, value); -} - -function checkBurnEvent(burnEvent, burner, amount) { - assert.equal(burnEvent.logs[0].event, "Burn"); - assert.isTrue(addressEquals(burnEvent.logs[0].args.burner, burner)); - assert.isTrue(addressEquals(burnEvent.logs[0].args.amount, amount)); -} - -function checkBlacklistEvent(blacklistEvent, account) { - assert.equal(blacklistEvent.logs[0].event, "Blacklisted"); - assert.isTrue(addressEquals(blacklistEvent.logs[0].args._account, account)); -} - -function checkUnblacklistEvent(unblacklistEvent, account) { - assert.equal(unblacklistEvent.logs[0].event, "UnBlacklisted"); - assert.isTrue(addressEquals(unblacklistEvent.logs[0].args._account, account)); -} - -function checkBlacklisterChangedEvent(blacklisterChangedEvent, blacklister) { - assert.equal(blacklisterChangedEvent.logs[0].event, "BlacklisterChanged"); - assert.isTrue( - addressEquals( - blacklisterChangedEvent.logs[0].args.newBlacklister, - blacklister - ) - ); -} - -function checkPauserChangedEvent(pauserChangedEvent, pauser) { - assert.equal(pauserChangedEvent.logs[0].event, "PauserChanged"); - assert.isTrue( - addressEquals(pauserChangedEvent.logs[0].args.newAddress, pauser) - ); -} - -function checkTransferOwnershipEvent( - transferOwnershipEvent, - previousOwner, - newOwner -) { - assert.equal(transferOwnershipEvent.logs[0].event, "OwnershipTransferred"); - assert.isTrue( - addressEquals( - transferOwnershipEvent.logs[0].args.previousOwner, - previousOwner - ) - ); - assert.isTrue( - addressEquals(transferOwnershipEvent.logs[0].args.newOwner, newOwner) - ); -} - -function checkUpdateMasterMinterEvent( - checkUpdateMasterMinterEvent, - newMasterMinter -) { - assert.equal( - checkUpdateMasterMinterEvent.logs[0].event, - "MasterMinterChanged" - ); - assert.isTrue( - addressEquals( - checkUpdateMasterMinterEvent.logs[0].args.newMasterMinter, - newMasterMinter - ) - ); -} - -function checkAdminChangedEvent(adminChangedEvent, previousAdmin, newAdmin) { - assert.equal(adminChangedEvent.logs[0].event, "AdminChanged"); - assert.isTrue( - addressEquals(adminChangedEvent.logs[0].args.previousAdmin, previousAdmin) - ); - assert.isTrue( - addressEquals(adminChangedEvent.logs[0].args.newAdmin, newAdmin) - ); -} - -function checkUpgradeEvent(upgradeEvent, implementation) { - assert.equal(upgradeEvent.logs[0].event, "Upgraded"); - assert.isTrue( - addressEquals(upgradeEvent.logs[0].args.implementation, implementation) - ); -} - -function checkTransferProxyOwnershipEvent( - transferProxyOwnershipEvent, - previousOwner, - newOwner -) { - assert.equal( - transferProxyOwnershipEvent.logs[0].event, - "ProxyOwnershipTransferred" - ); - assert.isTrue( - addressEquals( - transferProxyOwnershipEvent.logs[0].args.previousOwner, - previousOwner - ) - ); - assert.isTrue( - addressEquals(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"); -} - -function checkMintEvent(minting, to, amount, minter) { - // Mint Event - assert.equal(minting.logs[0].event, "Mint"); - assert.isTrue(addressEquals(minting.logs[0].args.minter, minter)); - assert.isTrue(addressEquals(minting.logs[0].args.to, to)); - assert.equal(minting.logs[0].args.amount, amount); - - // Transfer from 0 Event - assert.equal(minting.logs[1].event, "Transfer"); - assert.isTrue(addressEquals(minting.logs[1].args.from, zeroAddress)); - assert.isTrue(addressEquals(minting.logs[1].args.to, to)); - assert.equal(minting.logs[1].args.value, amount); -} - -function checkBurnEvents(burning, amount, burner) { - // Burn Event - assert.equal(burning.logs[0].event, "Burn"); - assert.isTrue(addressEquals(burning.logs[0].args.burner, burner)); - assert.equal(burning.logs[0].args.amount, amount); - - // Transfer to 0 Event - assert.equal(burning.logs[1].event, "Transfer"); - assert.isTrue(addressEquals(burning.logs[1].args.from, burner)); - assert.isTrue(addressEquals(burning.logs[1].args.to, zeroAddress)); - assert.equal(burning.logs[1].args.value, amount); -} - -var fiatTokenEmptyState = { - name: name, - symbol: symbol, - currency: currency, - decimals: decimals, - masterMinter: Accounts.masterMinterAccount, - pauser: Accounts.pauserAccount, - blacklister: Accounts.blacklisterAccount, - tokenOwner: Accounts.tokenOwnerAccount, - proxiedTokenAddress: bigZero, - initializedV1: trueInStorageFormat, - proxyOwner: Accounts.proxyOwnerAccount, - balances: setAccountDefault(Accounts, bigZero), - allowance: recursiveSetAccountDefault(Accounts, bigZero), - totalSupply: bigZero, - isAccountBlacklisted: setAccountDefault(Accounts, false), - isAccountMinter: setAccountDefault(Accounts, false), - minterAllowance: setAccountDefault(Accounts, bigZero), - paused: false, -}; - -// Creates a state object, with default values replaced by -// customVars where appropriate. -function buildExpectedState(token, customVars) { - // for each item in customVars, set the item in expectedState - var expectedState = clone(fiatTokenEmptyState); - expectedState.proxiedTokenAddress = token.proxiedTokenAddress; - - var i; - for (i = 0; i < customVars.length; ++i) { - if (_.has(expectedState, customVars[i].variable)) { - if ( - expectedState[customVars[i].variable] == customVars[i].expectedValue - ) { - throw new Error( - "variable " + - customVars[i].variable + - " to test has same default state as expected state" - ); - } else { - _.set( - expectedState, - customVars[i].variable, - customVars[i].expectedValue - ); - } - } else { - // TODO: test the error - throw new Error( - "variable " + customVars[i].variable + " not found in expectedState" - ); - } - } - return expectedState; -} - -// Replaces all BN objects with 32 character hex strings -function mapBNToHex(state) { - var result = {}; - for (var name in state) { - if (BN.isBN(state[name])) { - result[name] = web3.utils.toHex(state[name]); - } else if (typeof state[name] == "object") { - result[name] = mapBNToHex(state[name]); - } else if ( - typeof state[name] == "string" && - state[name].substring(0, 2) == "0x" - ) { - result[name] = state[name].toUpperCase(); - } else { - result[name] = state[name]; - } - } - return result; -} - -// For testing variance of specific variables from their default values. -// customVars is an array of objects of the form, -// {'variable': , 'expectedValue': } -// to reference nested variables, name variable using dot syntax, e.g. 'allowance.arbitraryAccount.minterAccount' -async function checkVariables(_tokens, _customVars) { - // Iterate over array of tokens. - var numTokens = _tokens.length; - assert.equal(numTokens, _customVars.length); - var n; - for (n = 0; n < numTokens; n++) { - var token = _tokens[n]; - var customVars = _customVars[n]; - - let expectedState = mapBNToHex(buildExpectedState(token, customVars)); - let actualState = mapBNToHex(await getActualState(token)); - if (debugLogging) { - console.log( - util.inspect(expectedState, { showHidden: false, depth: null }) - ); - console.log( - util.inspect(actualState, { showHidden: false, depth: null }) - ); - } - - assertDiff.deepEqual( - actualState, - expectedState, - "difference between expected and actual state" - ); - - // Check that sum of individual balances equals totalSupply - var accounts = Object.keys(Accounts).map( - (accountName) => Accounts[accountName] - ); - var balanceSum = bigZero; - var x; - for (x = 0; x < accounts.length; x++) { - balanceSum = balanceSum.add(await token.balanceOf(accounts[x])); - } - var totalSupply = newBigNumber(await token.totalSupply()); - assert( - balanceSum.cmp(totalSupply) == 0, - "sum of balances is not equal to totalSupply" - ); - } -} - -// All MINT p0 tests will call this function. -// _contracts is an array of exactly two values: a FiatTokenV1 and a MintController -// _customVars is an array of exactly two values: the expected state of the FiatTokenV1 -// and the expected state of the MintController -async function checkMINTp0(_contracts, _customVars) { - assert.equal(_contracts.length, 2); - assert.equal(_customVars.length, 2); - - // the first is a FiatTokenV1 - await checkVariables([_contracts[0]], [_customVars[0]]); - - // the second is a MintController - await _customVars[1].checkState(_contracts[1]); -} - -// build up actualState object to compare to expectedState object -async function getActualState(token) { - // lambda expressions to get allowance mappings in token contract - var allowanceMappingEval = async function (account1) { - var myAllowances = async function (account2) { - return token.allowance(account1, account2); - }; - return getAccountState(myAllowances, Accounts); - }; - - return Q.all([ - token.name.call(), - token.symbol.call(), - token.currency.call(), - token.decimals.call(), - token.masterMinter.call(), - token.pauser.call(), - token.blacklister.call(), - token.owner.call(), - getImplementation(token), - getAdmin(token), - getInitializedV1(token), - getAccountState(token.balanceOf, Accounts), - getAccountState(allowanceMappingEval, Accounts), - token.totalSupply(), - getAccountState(token.isBlacklisted, Accounts), - getAccountState(token.isMinter, Accounts), - getAccountState(token.minterAllowance, Accounts), - token.paused(), - ]).spread(function ( - name, - symbol, - currency, - decimals, - masterMinter, - pauser, - blacklister, - tokenOwner, - proxiedTokenAddress, - proxyOwner, - initializedV1, - balances, - allowances, - totalSupply, - isAccountBlacklisted, - isAccountMinter, - minterAllowance, - paused - ) { - var actualState = { - name: name, - symbol: symbol, - currency: currency, - decimals: decimals, - masterMinter: masterMinter, - pauser: pauser, - blacklister: blacklister, - tokenOwner: tokenOwner, - proxiedTokenAddress: proxiedTokenAddress, - proxyOwner: proxyOwner, - initializedV1: initializedV1, - balances: balances, - allowance: allowances, - totalSupply: totalSupply, - isAccountBlacklisted: isAccountBlacklisted, - isAccountMinter: isAccountMinter, - minterAllowance: minterAllowance, - paused: paused, - }; - return actualState; - }); -} - -async function setMinter(token, minter, amount) { - let update = await token.configureMinter(minter, amount, { - from: Accounts.masterMinterAccount, - }); - assert.equal(update.logs[0].event, "MinterConfigured"); - assert.isTrue(addressEquals(update.logs[0].args.minter, minter)); - assert.equal(update.logs[0].args.minterAllowedAmount, amount); - let minterAllowance = await token.minterAllowance(minter); - - assert.equal(minterAllowance, amount); -} - -async function burn(token, amount, burner) { - let burning = await token.burn(amount, { from: burner }); - checkBurnEvents(burning, amount, burner); -} - -async function mint(token, to, amount, minter) { - await setMinter(token, minter, amount); - await mintRaw(token, to, amount, minter); -} - -async function mintRaw(token, to, amount, minter) { - let initialTotalSupply = await token.totalSupply(); - let initialMinterAllowance = await token.minterAllowance(minter); - let minting = await token.mint(to, amount, { from: minter }); - checkMintEvent(minting, to, amount, minter); - - // TODO revisit this - /* let totalSupply = await token.totalSupply(); - totalSupply.should.be.bignumber.equal(initialTotalSupply); - let minterAllowance = await token.minterAllowance(minter); - assert.isTrue(newBigNumber(initialMinterAllowance).minus(newBigNumber(amount)).cmp(newBigNumber(minterAllowance)) - ==0);*/ -} - -async function blacklist(token, account) { - let blacklist = await token.blacklist(account, { - from: Accounts.blacklisterAccount, - }); - checkBlacklistEvent(blacklist, account); -} - -async function unBlacklist(token, account) { - let unblacklist = await token.unBlacklist(account, { - from: Accounts.blacklisterAccount, - }); - checkUnblacklistEvent(unblacklist, account); -} - -async function setLongDecimalFeesTransferWithFees( - token, - ownerAccount, - arbitraryAccount -) { - fee = 123589; - feeBase = 1000000; - await token.updateTransferFee(fee, feeBase); - let allowed = await token.allowance.call(ownerAccount, arbitraryAccount); - assert.isTrue(allowed.isZero()); - await mint(token, ownerAccount, 1900); - let initialBalanceFeeAccount = await token.balanceOf(feeAccount); - - await token.approve(arbitraryAccount, 1500); - allowed = await token.allowance.call(ownerAccount, arbitraryAccount); - assert.isTrue(allowed.cmp(newBigNumber(1500)) == 0); - - let transfer = await token.transfer(arbitraryAccount, 1000, { - from: ownerAccount, - }); - - let feeAmount = calculateFeeAmount(1000); - checkTransferEvents( - transfer, - ownerAccount, - arbitraryAccount, - 1000, - feeAmount - ); - - let balance0 = await token.balanceOf(ownerAccount); - assert.equal(balance0, 1900 - 1000 - feeAmount); - let balance3 = await token.balanceOf(arbitraryAccount); - assert.equal(balance3, 1000); - let balanceFeeAccount = await token.balanceOf(feeAccount); - assert.isTrue( - balanceFeeAccount - .sub(initialBalanceFeeAccount) - .cmp(newBigNumber(feeAmount)) == 0 - ); -} - -async function sampleTransfer(token, ownerAccount, arbitraryAccount, minter) { - let allowed = await token.allowance.call(ownerAccount, arbitraryAccount); - assert.isTrue(allowed.isZero()); - await mint(token, ownerAccount, 1900, minter); - - await token.approve(arbitraryAccount, 1500); - allowed = await token.allowance.call(ownerAccount, arbitraryAccount); - assert.isTrue(allowed.cmp(newBigNumber(1500)) == 0); - - let transfer = await token.transfer(arbitraryAccount, 1000, { - from: ownerAccount, - }); - - checkTransferEvents(transfer, ownerAccount, arbitraryAccount, 1000); - - let balance0 = await token.balanceOf(ownerAccount); - assert.equal(balance0, 1900 - 1000); - let balance3 = await token.balanceOf(arbitraryAccount); - assert.equal(balance3, 1000); -} - -async function transferFromWithFees( - token, - ownerAccount, - arbitraryAccount, - minter -) { - fee = 1235; - feeBase = 10000; - await token.updateTransferFee(fee, feeBase); - let allowed = await token.allowance.call(ownerAccount, arbitraryAccount); - assert.isTrue(allowed.isZero()); - await mint(token, ownerAccount, 900, minter); - let initialBalanceFeeAccount = await token.balanceOf(feeAccount); - await token.approve(arbitraryAccount, 634); - allowed = await token.allowance.call(ownerAccount, arbitraryAccount); - assert.isTrue(allowed.cmp(newBigNumber(634)) == 0); - - transfer = await token.transferFrom(ownerAccount, arbitraryAccount, 534, { - from: arbitraryAccount, - }); - - let feeAmount = calculateFeeAmount(534); - checkTransferEvents(transfer, ownerAccount, arbitraryAccount, 534, feeAmount); - - let balance0 = await token.balanceOf(ownerAccount); - assert.isTrue(balance0.cmp(900 - 534 - feeAmount) == 0); - let balance3 = await token.balanceOf(arbitraryAccount); - assert.isTrue(balance3.cmp(newBigNumber(534)) == 0); - let balanceFeeAccount = await token.balanceOf(feeAccount); - assert.isTrue( - balanceFeeAccount - .sub(initialBalanceFeeAccount) - .cmp(newBigNumber(feeAmount)) == 0 - ); -} - -async function sampleTransferFrom( - token, - ownerAccount, - arbitraryAccount, - minter -) { - let allowed = await token.allowance.call(ownerAccount, arbitraryAccount); // TODO not this - assert.isTrue(allowed.isZero()); - await mint(token, ownerAccount, 900, minter); // TODO maybe this - await token.approve(arbitraryAccount, 634); // TODO not this - allowed = await token.allowance.call(ownerAccount, arbitraryAccount); // TODO not this - assert.isTrue(allowed.cmp(newBigNumber(634)) == 0); - - let transfer = await token.transferFrom(ownerAccount, arbitraryAccount, 534, { - from: arbitraryAccount, - }); // TODO not this - - checkTransferEvents(transfer, ownerAccount, arbitraryAccount, 534); - - let balance0 = await token.balanceOf(ownerAccount); - assert.isTrue(balance0.cmp(newBigNumber(900 - 534)) == 0); - let balance3 = await token.balanceOf(arbitraryAccount); - assert.isTrue(balance3.cmp(newBigNumber(534)) == 0); -} - -async function approve(token, to, amount, from) { - await token.approve(to, amount, { from: from }); -} - -async function redeem(token, account, amount) { - let redeemResult = await token.redeem(amount, { from: account }); - assert.equal(redeemResult.logs[0].event, "Redeem"); - assert.equal(redeemResult.logs[0].args.redeemedAddress, account); - assert.equal(redeemResult.logs[0].args.amount, amount); -} - -function validateTransferEvent(transferEvent, from, to, value) { - let eventResult = transferEvent.logs[0]; - assert.equal(eventResult.event, "Transfer"); - assert.isTrue(addressEquals(eventResult.args.from, from)); - assert.isTrue(addressEquals(eventResult.args.to, to)); - assert.equal(eventResult.args.value, value); -} - -async function initializeTokenWithProxy(rawToken) { - return customInitializeTokenWithProxy( - rawToken, - Accounts.masterMinterAccount, - Accounts.pauserAccount, - Accounts.blacklisterAccount, - Accounts.tokenOwnerAccount - ); -} - -async function customInitializeTokenWithProxy( - rawToken, - _masterMinter, - _pauser, - _blacklister, - _owner -) { - const proxy = await FiatTokenProxy.new(rawToken.address, { - from: Accounts.proxyOwnerAccount, - }); - proxiedToken = await FiatToken.at(proxy.address); - await proxiedToken.initialize( - name, - symbol, - currency, - decimals, - _masterMinter, - _pauser, - _blacklister, - _owner - ); - proxiedToken.proxiedTokenAddress = rawToken.address; - assert.equal(proxiedToken.address, proxy.address); - assert.notEqual(proxiedToken.address, rawToken.address); - var tokenConfig = { - proxy: proxy, - token: proxiedToken, - }; - return tokenConfig; -} - -async function upgradeTo(proxy, upgradedToken, proxyUpgraderAccount) { - if (proxyUpgraderAccount == null) { - proxyUpgraderAccount = Accounts.proxyOwnerAccount; - } - await proxy.upgradeTo(upgradedToken.address, { from: proxyUpgraderAccount }); - proxiedToken = await FiatToken.at(proxy.address); - assert.equal(proxiedToken.address, proxy.address); - return (tokenConfig = { - proxy: proxy, - token: proxiedToken, - }); -} - -async function expectRevert(contractPromise) { - await expectError(contractPromise, "revert"); -} - -async function expectJump(contractPromise) { - await expectError(contractPromise, "invalid opcode"); -} - -async function expectError(contractPromise, errorMsg) { - try { - await contractPromise; - assert.fail("Expected error ${errorMsg}, but no error received"); - } catch (error) { - var correctErrorMsgReceived = error.message.includes(errorMsg); - assert( - correctErrorMsgReceived, - `Expected ${errorMsg}, got ${error.message} instead` - ); - } -} - -function encodeCall(name, arguments, values) { - const methodId = abi.methodID(name, arguments).toString("hex"); - const params = abi.rawEncode(arguments, values).toString("hex"); - return "0x" + methodId + params; -} - -async function getAdmin(proxy) { - var adm = await web3.eth.getStorageAt(proxy.address, adminSlot); - return adm; -} - -async function getImplementation(proxy) { - let impl = await web3.eth.getStorageAt(proxy.address, implSlot); - return impl; -} - -async function getInitializedV1(token) { - var slot8Data = await web3.eth.getStorageAt(token.address, 8); - var slot8DataLength = slot8Data.length; - var initialized; - var masterMinterStart; - var masterMinterAddress; - if (slot8DataLength == 3) { - //Validate proxy not yet initialized - for (var i = 0; i <= 20; i++) { - assert.equal("0x0", await web3.eth.getStorageAt(token.address, i)); - } - initialized = slot8Data; - } else { - if (slot8DataLength == 44) { - initialized = "0x" + slot8Data.substring(2, 4); // first 2 hex-chars after 0x - masterMinterStart = 4; - } else if (slot8DataLength == 40) { - initialized = "0x00"; - masterMinterStart = 2; - } else { - assert.fail("slot8Data incorrect size"); - } - masterMinterAddress = - "0x" + - slot8Data - .substring(masterMinterStart, masterMinterStart + 40) - .toUpperCase(); - var tokenMMA = await token.masterMinter.call(); - assert.isTrue(addressEquals(tokenMMA, masterMinterAddress)); - } - return initialized; -} - -module.exports = { - newBigNumber: newBigNumber, - FiatToken: FiatToken, - FiatTokenProxy: FiatTokenProxy, - UpgradedFiatToken: UpgradedFiatToken, - UpgradedFiatTokenNewFields: UpgradedFiatTokenNewFields, - UpgradedFiatTokenNewFieldsNewLogic: UpgradedFiatTokenNewFieldsNewLogic, - name: name, - symbol: symbol, - currency: currency, - decimals: decimals, - bigZero: bigZero, - zeroAddress: zeroAddress, - bigHundred: bigHundred, - debugLogging: debugLogging, - solidityErrors: solidityErrors, - calculateFeeAmount: calculateFeeAmount, - checkTransferEventsWithFee: checkTransferEventsWithFee, - checkTransferEvents: checkTransferEvents, - checkMinterConfiguredEvent: checkMinterConfiguredEvent, - checkMintEvent: checkMintEvent, - checkApprovalEvent: checkApprovalEvent, - checkBurnEvents: checkBurnEvents, - checkBurnEvent: checkBurnEvent, - checkMinterRemovedEvent: checkMinterRemovedEvent, - checkBlacklistEvent: checkBlacklistEvent, - checkUnblacklistEvent: checkUnblacklistEvent, - checkPauseEvent: checkPauseEvent, - checkUnpauseEvent: checkUnpauseEvent, - checkPauserChangedEvent: checkPauserChangedEvent, - checkTransferOwnershipEvent: checkTransferOwnershipEvent, - checkUpdateMasterMinterEvent: checkUpdateMasterMinterEvent, - checkBlacklisterChangedEvent: checkBlacklisterChangedEvent, - checkUpgradeEvent: checkUpgradeEvent, - checkAdminChangedEvent: checkAdminChangedEvent, - buildExpectedState, - checkVariables: checkVariables, - checkMINTp0: checkMINTp0, - setMinter: setMinter, - mint: mint, - burn: burn, - mintRaw: mintRaw, - blacklist: blacklist, - unBlacklist: unBlacklist, - setLongDecimalFeesTransferWithFees: setLongDecimalFeesTransferWithFees, - sampleTransfer: sampleTransfer, - transferFromWithFees: transferFromWithFees, - sampleTransferFrom: sampleTransferFrom, - approve: approve, - redeem: redeem, - validateTransferEvent: validateTransferEvent, - initializeTokenWithProxy: initializeTokenWithProxy, - customInitializeTokenWithProxy: customInitializeTokenWithProxy, - upgradeTo: upgradeTo, - expectRevert: expectRevert, - expectJump: expectJump, - expectError: expectError, - encodeCall: encodeCall, - getInitializedV1: getInitializedV1, - getAdmin: getAdmin, - maxAmount: maxAmount, - fiatTokenEmptyState, -}; diff --git a/test/assert/ABITests.test.js b/test/assert/ABITests.test.js deleted file mode 100644 index 1d16ab7bb..000000000 --- a/test/assert/ABITests.test.js +++ /dev/null @@ -1,250 +0,0 @@ -var Tx = require("ethereumjs-tx"); -var tokenUtils = require("./../TokenTestUtils.js"); -var FiatToken = tokenUtils.FiatToken; -var name = tokenUtils.name; -var symbol = tokenUtils.symbol; -var currency = tokenUtils.currency; -var decimals = tokenUtils.decimals; -var bigZero = tokenUtils.bigZero; -var bigHundred = tokenUtils.bigHundred; -var mint = tokenUtils.mint; -var expectRevert = tokenUtils.expectRevert; -var masterMinterRole = tokenUtils.masterMinterRole; -var blacklisterRole = tokenUtils.blacklisterRole; -var pauserRole = tokenUtils.pauserRole; -var checkVariables = tokenUtils.checkVariables; -var checkFailureIsExpected = tokenUtils.checkFailureIsExpected; -var initializeTokenWithProxy = tokenUtils.initializeTokenWithProxy; - -var AccountUtils = require("./../AccountUtils.js"); -var Accounts = AccountUtils.Accounts; -var AccountPrivateKeys = AccountUtils.AccountPrivateKeys; - -var abiUtils = require("./../ABIUtils.js"); -var makeRawTransaction = abiUtils.makeRawTransaction; -var sendRawTransaction = abiUtils.sendRawTransaction; -var functionSignature = abiUtils.functionSignature; -var encodeAddress = abiUtils.encodeAddress; -var encodeUint = abiUtils.encodeUint; -var msgData0 = abiUtils.msgData0; -var msgData = abiUtils.msgData; -var msgData1 = abiUtils.msgData1; -var msgData2 = abiUtils.msgData2; -var msgData3 = abiUtils.msgData3; - -// Encodes methodName, 32 byte string of 0, and address. -function mockStringAddressEncode(methodName, address) { - var version = encodeUint(32) + encodeUint(0); // encode 32 byte string of 0's - return functionSignature(methodName) + version + encodeAddress(address); -} - -async function run_tests(newToken, accounts) { - beforeEach(async function checkBefore() { - rawToken = await newToken(); - var tokenConfig = await initializeTokenWithProxy(rawToken); - proxy = tokenConfig.proxy; - token = tokenConfig.token; - assert.equal(proxy.address, token.address); - }); - - // sanity check for pausable - it("abi004 FiatToken pause() is public", async function () { - let badData = functionSignature("pause()"); - let raw = await makeRawTransaction( - badData, - Accounts.pauserAccount, - AccountPrivateKeys.pauserPrivateKey, - token.address - ); - await sendRawTransaction(raw); - var customVars = [{ variable: "paused", expectedValue: true }]; - await checkVariables([token], [customVars]); - }); - - it("abi040 Blacklistable constructor is not a function", async function () { - let badData = functionSignature("Blacklistable()"); - let raw = await makeRawTransaction( - badData, - Accounts.pauserAccount, - AccountPrivateKeys.pauserPrivateKey, - token.address - ); - await expectRevert(sendRawTransaction(raw)); - }); - - it("abi042 Ownable constructor is not a function", async function () { - let badData = functionSignature("Ownable()"); - let raw = await makeRawTransaction( - badData, - Accounts.pauserAccount, - AccountPrivateKeys.pauserPrivateKey, - token.address - ); - await expectRevert(sendRawTransaction(raw)); - }); - - it("abi005 Pausable constructor is not a function", async function () { - let badData = functionSignature("Pausable()"); - let raw = await makeRawTransaction( - badData, - Accounts.pauserAccount, - AccountPrivateKeys.pauserPrivateKey, - token.address - ); - await expectRevert(sendRawTransaction(raw)); - }); - - it("abi043 FiatTokenProxy constructor is not a function", async function () { - let badData = functionSignature("FiatTokenProxy()"); - let raw = await makeRawTransaction( - badData, - Accounts.pauserAccount, - AccountPrivateKeys.pauserPrivateKey, - token.address - ); - await expectRevert(sendRawTransaction(raw)); - }); - - it("abi027 UpgradeabilityProxy constructor", async function () { - let badData = msgData( - "UpgradeabilityProxy(address)", - Accounts.arbitraryAccount - ); - let raw = await makeRawTransaction( - badData, - Accounts.arbitraryAccount, - AccountPrivateKeys.arbitraryPrivateKey, - token.address - ); - await expectRevert(sendRawTransaction(raw)); - }); - - it("abi055 Proxy constructor is not a function", async function () { - let badData = functionSignature("Proxy()"); - let raw = await makeRawTransaction( - badData, - Accounts.arbitraryAccount, - AccountPrivateKeys.arbitraryPrivateKey, - token.address - ); - await expectRevert(sendRawTransaction(raw)); - }); - - it("abi056 Proxy _delegate is internal", async function () { - let badData = msgData("_delegate(address)", Accounts.arbitraryAccount); - let raw = await makeRawTransaction( - badData, - Accounts.arbitraryAccount, - AccountPrivateKeys.arbitraryPrivateKey, - token.address - ); - await expectRevert(sendRawTransaction(raw)); - }); - - it("abi057 Proxy _willFallback is internal", async function () { - let badData = functionSignature("_willFallback()"); - let raw = await makeRawTransaction( - badData, - Accounts.arbitraryAccount, - AccountPrivateKeys.arbitraryPrivateKey, - token.address - ); - await expectRevert(sendRawTransaction(raw)); - }); - - it("abi058 Proxy _fallback is internal", async function () { - let badData = functionSignature("_fallback()"); - let raw = await makeRawTransaction( - badData, - Accounts.arbitraryAccount, - AccountPrivateKeys.arbitraryPrivateKey, - token.address - ); - await expectRevert(sendRawTransaction(raw)); - }); - - it("abi050 Upgradeability implementation is internal", async function () { - let badData = msgData( - "UpgradeabilityProxy(address)", - Accounts.arbitraryAccount - ); - let raw = await makeRawTransaction( - badData, - Accounts.arbitraryAccount, - AccountPrivateKeys.arbitraryPrivateKey, - token.address - ); - await expectRevert(sendRawTransaction(raw)); - }); - - it("abi051 AdminUpgradeabillityProxy constructor is not a function", async function () { - let badData = msgData( - "AdminUpgradeabillityProxy(address)", - Accounts.arbitraryAccount - ); - let raw = await makeRawTransaction( - badData, - Accounts.arbitraryAccount, - AccountPrivateKeys.arbitraryPrivateKey, - token.address - ); - await expectRevert(sendRawTransaction(raw)); - }); - - it("abi053 AdminUpgradeabillityProxy _setAdmin is internal", async function () { - let badData = msgData( - "AdminUpgradeabillityProxy(address)", - Accounts.arbitraryAccount - ); - let raw = await makeRawTransaction( - badData, - Accounts.arbitraryAccount, - AccountPrivateKeys.arbitraryPrivateKey, - token.address - ); - await expectRevert(sendRawTransaction(raw)); - }); - - it("abi041 FiatToken constructor is not a function", async function () { - let badData = functionSignature("FiatToken()"); - let raw = await makeRawTransaction( - badData, - Accounts.pauserAccount, - AccountPrivateKeys.pauserPrivateKey, - token.address - ); - await expectRevert(sendRawTransaction(raw)); - }); - - it("abi025 setOwner is internal", async function () { - let badData = msgData("setOwner(address)", Accounts.pauserAccount); - let raw = await makeRawTransaction( - badData, - Accounts.pauserAccount, - AccountPrivateKeys.pauserPrivateKey, - token.address - ); - await expectRevert(sendRawTransaction(raw)); - }); - - it("abi028 UpgradeabilityProxy._upgradeTo is internal", async function () { - let badData = mockStringAddressEncode( - "_upgradeTo(string,address)", - Accounts.pauserAccount - ); - let raw = await makeRawTransaction( - badData, - Accounts.tokenOwnerAccount, - AccountPrivateKeys.tokenOwnerPrivateKey, - token.address - ); - await expectRevert(sendRawTransaction(raw)); - }); -} - -var testWrapper = require("./../TestWrapper"); -testWrapper.execute("FiatToken_ABIHackingTests", run_tests); - -module.exports = { - run_tests: run_tests, -}; diff --git a/test/assert/EventsTests.js b/test/assert/EventsTests.js deleted file mode 100644 index e32f6709e..000000000 --- a/test/assert/EventsTests.js +++ /dev/null @@ -1,235 +0,0 @@ -var tokenUtils = require("./../TokenTestUtils.js"); -var FiatToken = tokenUtils.FiatToken; -var FiatTokenProxy = tokenUtils.FiatTokenProxy; - -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 AccountUtils = require("./../AccountUtils.js"); -var Accounts = AccountUtils.Accounts; - -var amount = 100; - -async function run_tests(newToken, accounts) { - 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("et000 should check MinterConfigured event", async function () { - let configureMinter = await token.configureMinter( - Accounts.minterAccount, - amount, - { from: Accounts.masterMinterAccount } - ); - checkMinterConfiguredEvent(configureMinter, Accounts.minterAccount, amount); - }); - - it("et001 should check Mint/Transfer events", async function () { - await token.configureMinter(Accounts.minterAccount, amount, { - from: Accounts.masterMinterAccount, - }); - let mint = await token.mint(Accounts.arbitraryAccount, amount, { - from: Accounts.minterAccount, - }); - checkMintEvent( - mint, - Accounts.arbitraryAccount, - amount, - Accounts.minterAccount - ); - }); - - it("et002 should check Burn/Transfer events", async function () { - await token.configureMinter(Accounts.minterAccount, amount, { - from: Accounts.masterMinterAccount, - }); - await token.mint(Accounts.minterAccount, amount, { - from: Accounts.minterAccount, - }); - let burn = await token.burn(amount, { from: Accounts.minterAccount }); - checkBurnEvents(burn, amount, Accounts.minterAccount); - }); - - it("et003 should check MinterRemoved event", async function () { - await token.configureMinter(Accounts.minterAccount, amount, { - from: Accounts.masterMinterAccount, - }); - let minterRemovedEvent = await token.removeMinter(Accounts.minterAccount, { - from: Accounts.masterMinterAccount, - }); - checkMinterRemovedEvent(minterRemovedEvent, Accounts.minterAccount); - }); - - it("et004 should check MasterMinterChanged event", async function () { - let updateMasterMinter = await token.updateMasterMinter( - Accounts.arbitraryAccount, - { from: Accounts.tokenOwnerAccount } - ); - checkUpdateMasterMinterEvent(updateMasterMinter, Accounts.arbitraryAccount); - }); - - it("et005 should check Blacklisted event", async function () { - let blacklist = await token.blacklist(Accounts.arbitraryAccount, { - from: Accounts.blacklisterAccount, - }); - checkBlacklistEvent(blacklist, Accounts.arbitraryAccount); - }); - - it("et006 should check UnBlacklisted event", async function () { - let unblacklist = await token.unBlacklist(Accounts.arbitraryAccount, { - from: Accounts.blacklisterAccount, - }); - checkUnblacklistEvent(unblacklist, Accounts.arbitraryAccount); - }); - - it("et007 should check BlacklisterChanged event", async function () { - let blacklisterChanged = await token.updateBlacklister( - Accounts.arbitraryAccount, - { from: Accounts.tokenOwnerAccount } - ); - checkBlacklisterChangedEvent(blacklisterChanged, Accounts.arbitraryAccount); - }); - - it("et008 should check Upgraded event", async function () { - var upgradedToken = await UpgradedFiatTokenNewFields.new(); - const initializeData = encodeCall( - "initV2", - ["bool", "address", "uint256"], - [true, Accounts.pauserAccount, 12] - ); - let upgrade = await proxy.upgradeToAndCall( - upgradedToken.address, - initializeData, - { from: Accounts.proxyOwnerAccount } - ); - checkUpgradeEvent(upgrade, upgradedToken.address); - }); - - it("et009 should check AdminChanged event", async function () { - let adminChanged = await proxy.changeAdmin(Accounts.arbitraryAccount, { - from: Accounts.proxyOwnerAccount, - }); - checkAdminChangedEvent( - adminChanged, - Accounts.proxyOwnerAccount, - Accounts.arbitraryAccount - ); - }); - - it("et010 should check OwnershipTransferred event", async function () { - let transferOwnership = await token.transferOwnership( - Accounts.arbitraryAccount, - { from: Accounts.tokenOwnerAccount } - ); - checkTransferOwnershipEvent( - transferOwnership, - Accounts.tokenOwnerAccount, - Accounts.arbitraryAccount - ); - }); - - it("et011 should check Approval event", async function () { - let approval = await token.approve(Accounts.arbitraryAccount2, amount, { - from: Accounts.arbitraryAccount, - }); - checkApprovalEvent( - approval, - Accounts.arbitraryAccount, - Accounts.arbitraryAccount2, - amount - ); - }); - - it("et012 should check Pause event", async function () { - let pause = await token.pause({ from: Accounts.pauserAccount }); - checkPauseEvent(pause); - }); - - it("et013 should check Unpause event", async function () { - let unpause = await token.unpause({ from: Accounts.pauserAccount }); - checkUnpauseEvent(unpause); - }); - - it("et014 should check PauserChanged event", async function () { - let updatePauser = await token.updatePauser(Accounts.arbitraryAccount, { - from: Accounts.tokenOwnerAccount, - }); - checkPauserChangedEvent(updatePauser, Accounts.arbitraryAccount); - }); - - it("et015 should check Transfer event", async function () { - await token.configureMinter(Accounts.minterAccount, amount, { - from: Accounts.masterMinterAccount, - }); - await token.mint(Accounts.arbitraryAccount, amount, { - from: Accounts.minterAccount, - }); - let transfer = await token.transfer(Accounts.arbitraryAccount2, amount, { - from: Accounts.arbitraryAccount, - }); - checkTransferEvents( - transfer, - Accounts.arbitraryAccount, - Accounts.arbitraryAccount2, - amount - ); - }); - - it("et016 should check Transfer event in transferFrom", async function () { - await token.configureMinter(Accounts.minterAccount, amount, { - from: Accounts.masterMinterAccount, - }); - await token.mint(Accounts.arbitraryAccount, amount, { - from: Accounts.minterAccount, - }); - await token.approve(Accounts.arbitraryAccount2, amount, { - from: Accounts.arbitraryAccount, - }); - let transferFrom = await token.transferFrom( - Accounts.arbitraryAccount, - Accounts.blacklisterAccount, - amount, - { from: Accounts.arbitraryAccount2 } - ); - checkTransferEvents( - transferFrom, - Accounts.arbitraryAccount, - Accounts.blacklisterAccount, - amount - ); - }); -} - -var testWrapper = require("./../TestWrapper"); -testWrapper.execute("FiatToken_EventTests", run_tests); - -module.exports = { - run_tests: run_tests, -}; diff --git a/test/assert/FiatTokenLegacy.test.js b/test/assert/FiatTokenLegacy.test.js deleted file mode 100644 index 65949570c..000000000 --- a/test/assert/FiatTokenLegacy.test.js +++ /dev/null @@ -1,770 +0,0 @@ -var tokenUtils = require("./../TokenTestUtils.js"); -var name = tokenUtils.name; -var symbol = tokenUtils.symbol; -var currency = tokenUtils.currency; -var decimals = tokenUtils.decimals; -var bigZero = tokenUtils.bigZero; -var bigHundred = tokenUtils.bigHundred; -var zeroAddress = tokenUtils.zeroAddress; -var mint = tokenUtils.mint; -var burn = tokenUtils.burn; -var setMinter = tokenUtils.setMinter; -var expectRevert = tokenUtils.expectRevert; -var blacklist = tokenUtils.blacklist; -var sampleTransferFrom = tokenUtils.sampleTransferFrom; -var approve = tokenUtils.approve; -var unBlacklist = tokenUtils.unBlacklist; -var sampleTransfer = tokenUtils.sampleTransfer; -var checkTransferEvents = tokenUtils.checkTransferEvents; -var initializeTokenWithProxy = tokenUtils.initializeTokenWithProxy; -var upgradeTo = tokenUtils.upgradeTo; -var UpgradedFiatToken = tokenUtils.UpgradedFiatToken; -var FiatToken = tokenUtils.FiatToken; -var getAdmin = tokenUtils.getAdmin; -var newBigNumber = tokenUtils.newBigNumber; - -var AccountUtils = require("./../AccountUtils.js"); -var Accounts = AccountUtils.Accounts; -var addressEquals = AccountUtils.addressEquals; - -// these tests are for reference and do not track side effects on all variables -async function run_tests(newToken, accounts) { - beforeEach(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 start with a totalSupply of 0', async function () { - let totalSupply = await token.totalSupply(); - assert.isTrue(totalSupply.isZero()); - }); - - it('should add multiple mints to a given address in address balance', async function () { - await mint(token, accounts[0], 100, Accounts.minterAccount); - await mint(token, accounts[0], 200, Accounts.minterAccount); - - let balance0 = await token.balanceOf(accounts[0]); - assert.equal(balance0, 300); - }); - - it('should fail to mint to a null address', async function () { - let initialTotalSupply = await token.totalSupply(); - - await expectRevert(mint(token, "0x0", 100, Accounts.minterAccount)); - - totalSupply = await token.totalSupply(); - assert.isTrue(totalSupply.cmp(newBigNumber(initialTotalSupply))==0); - - await expectRevert(mint(token, 0x0, 100, Accounts.minterAccount)); - - totalSupply = await token.totalSupply(); - assert.isTrue(totalSupply.cmp(newBigNumber(initialTotalSupply))==0); - - await expectRevert(mint(token, "0x0000000000000000000000000000000000000000", 100, Accounts.minterAccount)); - - totalSupply = await token.totalSupply(); - assert.isTrue(totalSupply.cmp(newBigNumber(initialTotalSupply))==0); - - await expectRevert(mint(token, 0x0000000000000000000000000000000000000000, 100, Accounts.minterAccount)); - - totalSupply = await token.totalSupply(); - assert.isTrue(totalSupply.cmp(newBigNumber(initialTotalSupply))==0); - }); - - it('should add multiple mints to a given address in address balance', async function () { - await mint(token, accounts[0], 100, Accounts.minterAccount); - await mint(token, accounts[0], 200, Accounts.minterAccount); - - let balance0 = await token.balanceOf(accounts[0]); - assert.isTrue(balance0.cmp(newBigNumber(300))==0); - }); - - it('should add multiple mints to total supply', async function () { - let initialTotalSupply = await token.totalSupply(); - await mint(token, accounts[0], 100, Accounts.minterAccount); - await mint(token, accounts[0], 400, Accounts.minterAccount); - await mint(token, accounts[1], 600, Accounts.minterAccount); - - let totalSupply = await token.totalSupply(); - assert.isTrue(totalSupply.sub(initialTotalSupply).cmp(newBigNumber(1100))==0); - }); - - it('should fail to mint from blacklisted minter', async function () { - await setMinter(token, accounts[2], 200); - await blacklist(token, accounts[2]); - - await expectRevert(token.mint(accounts[0], 100, { from: accounts[2] })); - - let balance0 = await token.balanceOf(accounts[0]); - assert.equal(balance0, 0); - }); - - it('should fail to mint to blacklisted address', async function () { - await blacklist(token, accounts[3]); - - await expectRevert(mint(token, accounts[3], 100, Accounts.minterAccount)) - - let balance0 = await token.balanceOf(accounts[0]); - assert.equal(balance0, 0); - }); - - it('should fail to mint from a non-minter call', async function () { - await mint(token, accounts[0], 400, Accounts.minterAccount); - - await expectRevert(token.mint(accounts[0], 100, { from: accounts[0] })) - - let balance0 = await token.balanceOf(accounts[0]); - assert.equal(balance0, 400); - }); - - it('should complete transferFrom', async function () { - await sampleTransferFrom(token, Accounts.deployerAccount, Accounts.arbitraryAccount2, Accounts.minterAccount); - }); - - it('should approve', async function () { - await approve(token, accounts[3], 100, accounts[2]); - let allowance = await token.allowance(accounts[2], accounts[3]); - assert.isTrue(allowance.cmp(newBigNumber(100))==0); - }); - - it('should complete sample transfer', async function () { - await sampleTransfer(token, Accounts.deployerAccount, Accounts.arbitraryAccount2, Accounts.minterAccount); - }); - - it('should complete transfer from non-owner', async function () { - await mint(token, accounts[2], 1900, Accounts.minterAccount); - let transfer = await token.transfer(accounts[3], 1000, { from: accounts[2] }); - - checkTransferEvents(transfer, accounts[2], accounts[3], 1000); - - let balance0 = await token.balanceOf(accounts[2]); - assert.equal(balance0, 1900 - 1000); - let balance3 = await token.balanceOf(accounts[3]); - assert.equal(balance3, 1000); - }); - - it('should set allowance and balances before and after approved transfer', async function () { - let allowed = await token.allowance.call(accounts[0], accounts[3]); - assert.isTrue(allowed.isZero()); - await mint(token, accounts[0], 500, Accounts.minterAccount); - await token.approve(accounts[3], 100); - allowed = await token.allowance.call(accounts[0], accounts[3]); - assert.isTrue(allowed.cmp(newBigNumber(100))==0); - - let transfer = await token.transferFrom(accounts[0], accounts[3], 50, { from: accounts[3] }); - - checkTransferEvents(transfer, accounts[0], accounts[3], 50); - - let balance0 = await token.balanceOf(accounts[0]); - assert.isTrue(balance0.cmp(newBigNumber(450))==0); - let balance3 = await token.balanceOf(accounts[3]); - assert.isTrue(balance3.cmp(newBigNumber(50))==0); - }); - - it('should fail on unauthorized approved transfer and not change balances', async function () { - let allowed = await token.allowance.call(accounts[0], accounts[3]); - assert.isTrue(allowed.cmp(newBigNumber(0))==0); - await mint(token, accounts[0], 500, Accounts.minterAccount); - await token.approve(accounts[3], 100); - allowed = await token.allowance.call(accounts[0], accounts[3]); - assert.isTrue(allowed.cmp(newBigNumber(100))==0); - - await expectRevert(token.transferFrom(accounts[0], accounts[3], 50, { from: accounts[4] })); - - let balance0 = await token.balanceOf(accounts[0]); - assert.equal(balance0, 500); - let balance3 = await token.balanceOf(accounts[3]); - assert.equal(balance3, 0); - }); -*/ - it("should fail on invalid approved transfer amount and not change balances", async function () { - let allowed = await token.allowance.call(accounts[0], accounts[3]); - assert.isTrue(allowed.cmp(newBigNumber(0)) == 0); - await mint(token, accounts[0], 500, Accounts.minterAccount); - await token.approve(accounts[3], 100); - allowed = await token.allowance.call(accounts[0], accounts[3]); - assert.isTrue(allowed.cmp(newBigNumber(100)) == 0); - - await expectRevert( - token.transferFrom(accounts[0], accounts[3], 450, { from: accounts[3] }) - ); - - let balance0 = await token.balanceOf(accounts[0]); - assert.equal(balance0, 500); - let balance3 = await token.balanceOf(accounts[3]); - assert.equal(balance3, 0); - }); - - it("should fail on invalid transfer recipient (zero-account) and not change balances", async function () { - await mint(token, accounts[0], 500, Accounts.minterAccount); - await token.approve(accounts[3], 100); - let allowed = await token.allowance.call(accounts[0], accounts[3]); - assert.isTrue(allowed.cmp(newBigNumber(100)) == 0); - - await expectRevert( - token.transferFrom(accounts[0], zeroAddress, 50, { from: accounts[3] }) - ); - - let balance0 = await token.balanceOf(accounts[0]); - assert.equal(balance0, 500); - }); - - it("should test consistency of transfer(x) and approve(x) + transferFrom(x)", async function () { - let allowed = await token.allowance.call(accounts[0], accounts[3]); - assert.isTrue(allowed.isZero()); - let transferAmount = 650; - let totalAmount = transferAmount; - await mint(token, accounts[0], totalAmount, Accounts.minterAccount); - - let transfer = await token.transfer(accounts[3], transferAmount); - checkTransferEvents(transfer, accounts[0], accounts[3], transferAmount); - - let balance0 = await token.balanceOf(accounts[0]); - assert.equal(balance0, totalAmount - transferAmount); - let balance3 = await token.balanceOf(accounts[3]); - assert.equal(balance3, transferAmount); - - await token.allowance.call(accounts[1], accounts[4]); - assert.isTrue(allowed.isZero()); - await mint(token, accounts[1], totalAmount, Accounts.minterAccount); - - await token.approve(accounts[4], transferAmount, { from: accounts[1] }); - allowed = await token.allowance.call(accounts[1], accounts[4]); - assert.isTrue(allowed.cmp(newBigNumber(transferAmount)) == 0); - - transfer = await token.transferFrom( - accounts[1], - accounts[4], - transferAmount, - { from: accounts[4] } - ); - - checkTransferEvents(transfer, accounts[1], accounts[4], transferAmount); - - let balance1 = await token.balanceOf(accounts[1]); - assert.equal(balance0, totalAmount - transferAmount); - let balance4 = await token.balanceOf(accounts[4]); - assert.equal(balance3, transferAmount); - }); - - it("should pause and should not be able to transfer", async function () { - await mint(token, accounts[2], 1900, Accounts.minterAccount); - assert.equal(await token.paused.call(), false); - await token.pause({ from: Accounts.pauserAccount }); - assert.equal(await token.paused.call(), true); - - await expectRevert( - sampleTransferFrom( - token, - Accounts.deployerAccount, - Accounts.arbitraryAccount2, - Accounts.minterAccount - ) - ); - }); - - it("should pause and should not be able to transfer, then unpause and be able to transfer", async function () { - await mint(token, accounts[2], 1900, Accounts.minterAccount); - assert.equal(await token.paused.call(), false); - await token.pause({ from: Accounts.pauserAccount }); - assert.equal(await token.paused.call(), true); - - await expectRevert( - sampleTransferFrom( - token, - Accounts.deployerAccount, - Accounts.arbitraryAccount2, - Accounts.minterAccount - ) - ); - - await token.unpause({ from: Accounts.pauserAccount }); - assert.equal(await token.paused.call(), false); - await sampleTransferFrom( - token, - Accounts.deployerAccount, - Accounts.arbitraryAccount2, - Accounts.minterAccount - ); - }); - - it("should pause and should not be able to transferFrom", async function () { - await mint(token, accounts[2], 1900, Accounts.minterAccount); - assert.equal(await token.paused.call(), false); - await token.pause({ from: Accounts.pauserAccount }); - assert.equal(await token.paused.call(), true); - - await expectRevert( - sampleTransfer( - token, - Accounts.deployerAccount, - Accounts.arbitraryAccount2, - Accounts.minterAccount - ) - ); - }); - - it("should pause and should not be able to approve", async function () { - await mint(token, accounts[2], 1900, Accounts.minterAccount); - assert.equal(await token.paused.call(), false); - await token.pause({ from: Accounts.pauserAccount }); - assert.equal(await token.paused.call(), true); - - await expectRevert(approve(token, accounts[2], 50, accounts[3])); - }); - - it("should pause and should not be able to mint", async function () { - await mint(token, accounts[2], 1900, Accounts.minterAccount); - assert.equal(await token.paused.call(), false); - await token.pause({ from: Accounts.pauserAccount }); - assert.equal(await token.paused.call(), true); - - await expectRevert(mint(token, accounts[2], 1900, Accounts.minterAccount)); - }); - - it("should try to pause with non-pauser and fail to pause", async function () { - await mint(token, accounts[2], 1900, Accounts.minterAccount); - assert.equal(await token.paused.call(), false); - - await expectRevert(token.pause({ from: accounts[0] })); - - assert.equal(await token.paused.call(), false); - }); - - it("should try to pause with non-pauser and fail to pause", async function () { - await mint(token, accounts[2], 1900, Accounts.minterAccount); - assert.equal(await token.paused.call(), false); - - await expectRevert(token.pause({ from: accounts[0] })); - - assert.equal(await token.paused.call(), false); - }); - - it("should approve and fail to transfer more than balance", async function () { - await mint(token, accounts[2], 100, Accounts.minterAccount); - await token.approve(accounts[1], 600, { from: accounts[2] }); - - await expectRevert( - token.transferFrom(accounts[2], accounts[1], 600, { from: accounts[1] }) - ); - - let balance = await token.balanceOf(accounts[2]); - assert.isTrue(balance.cmp(newBigNumber(100)) == 0); - }); - - it("should blacklist and make transfer impossible", async function () { - await mint(token, accounts[2], 1900, Accounts.minterAccount); - await blacklist(token, accounts[2]); - - await expectRevert(token.transfer(accounts[3], 600, { from: accounts[2] })); - - let balance = await token.balanceOf(accounts[2]); - assert.equal(balance, 1900); - }); - - it("should blacklist recipient and make transfer to recipient impossible", async function () { - await mint(token, accounts[2], 1900, Accounts.minterAccount); - await mint(token, accounts[9], 1600, Accounts.minterAccount); - await blacklist(token, accounts[2]); - - await expectRevert(token.transfer(accounts[2], 600, { from: accounts[9] })); - - let balance = await token.balanceOf(accounts[2]); - assert.isTrue(balance.cmp(newBigNumber(1900)) == 0); - balance = await token.balanceOf(accounts[9]); - assert.isTrue(balance.cmp(newBigNumber(1600)) == 0); - }); - - it("should blacklist and make transferFrom impossible with the approved transferer", async function () { - let isBlacklistedBefore = await token.isBlacklisted(accounts[2]); - assert.equal(isBlacklistedBefore, false); - - await mint(token, accounts[2], 1900, Accounts.minterAccount); - await token.approve(accounts[1], 600, { from: accounts[2] }); - await blacklist(token, accounts[2]); - - await expectRevert( - token.transferFrom(accounts[2], accounts[3], 600, { from: accounts[1] }) - ); - - let balance = await token.balanceOf(accounts[2]); - assert.isTrue(balance.cmp(newBigNumber(1900)) == 0); - - let isBlacklistedAfter = await token.isBlacklisted(accounts[2]); - assert.equal(isBlacklistedAfter, true); - }); - - it("should make transferFrom impossible with the approved and blacklisted transferer", async function () { - await mint(token, accounts[2], 1900, Accounts.minterAccount); - await token.approve(accounts[1], 600, { from: accounts[2] }); - await blacklist(token, accounts[1]); - - await expectRevert( - token.transferFrom(accounts[2], accounts[3], 600, { from: accounts[1] }) - ); - - let balance = await token.balanceOf(accounts[2]); - assert.isTrue(balance.cmp(newBigNumber(1900)) == 0); - }); - - it("should blacklist recipient and make transfer to recipient using transferFrom impossible", async function () { - await mint(token, accounts[2], 1900, Accounts.minterAccount); - await token.approve(accounts[3], 600, { from: accounts[2] }); - await blacklist(token, accounts[3]); - - await expectRevert( - token.transferFrom(accounts[2], accounts[3], 600, { from: accounts[2] }) - ); - - let balance = await token.balanceOf(accounts[2]); - assert.isTrue(balance.cmp(newBigNumber(1900)) == 0); - }); - - it("should blacklist and make approve impossible", async function () { - await mint(token, accounts[1], 1900, Accounts.minterAccount); - await blacklist(token, accounts[1]); - - await expectRevert(token.approve(accounts[2], 600, { from: accounts[1] })); - let approval = await token.allowance(accounts[1], accounts[2]); - assert.isTrue(approval.isZero()); - }); - - it("should make giving approval to blacklisted account impossible", async function () { - await mint(token, accounts[2], 1900, Accounts.minterAccount); - await blacklist(token, accounts[1]); - - await expectRevert(token.approve(accounts[1], 600, { from: accounts[2] })); - - let approval = await token.allowance(accounts[2], accounts[1]); - assert.isTrue(approval.isZero()); - }); - - it("should blacklist then unblacklist to make a transfer possible", async function () { - await mint(token, accounts[2], 1900, Accounts.minterAccount); - await blacklist(token, accounts[2]); - await unBlacklist(token, accounts[2]); - await token.transfer(accounts[3], 600, { from: accounts[2] }); - let balance = await token.balanceOf(accounts[2]); - assert.isTrue(balance.cmp(newBigNumber(1300)) == 0); - balance = await token.balanceOf(accounts[3]); - assert.isTrue(balance.cmp(newBigNumber(600)) == 0); - }); - - it("should fail to blacklist with non-blacklister account", async function () { - await mint(token, accounts[2], 1900, Accounts.minterAccount); - - await expectRevert( - token.blacklist(accounts[2], { from: Accounts.pauserAccount }) - ); - - await token.transfer(accounts[3], 600, { from: accounts[2] }); - let balance = await token.balanceOf(accounts[2]); - assert.isTrue(balance.cmp(newBigNumber(1300)) == 0); - balance = await token.balanceOf(accounts[3]); - assert.isTrue(balance.cmp(newBigNumber(600)) == 0); - }); - - it("should unblacklist when paused", async function () { - await mint(token, accounts[2], 1900, Accounts.minterAccount); - await token.blacklist(accounts[2], { from: Accounts.blacklisterAccount }); - let blacklisted = await token.isBlacklisted(accounts[2]); - assert.isTrue(blacklisted); - - await token.pause({ from: Accounts.pauserAccount }); - - await token.unBlacklist(accounts[2], { from: Accounts.blacklisterAccount }); - - blacklisted = await token.isBlacklisted(accounts[2]); - assert.isFalse(blacklisted); - - let balance = await token.balanceOf(accounts[2]); - assert.isTrue(balance.cmp(newBigNumber(1900)) == 0); - }); - - it("should change the minter and mint as well as fail to mint with the old minter", async function () { - let update = await token.removeMinter(Accounts.minterAccount, { - from: Accounts.masterMinterAccount, - }); - assert.equal(update.logs[0].event, "MinterRemoved"); - assert.isTrue( - addressEquals(update.logs[0].args.oldMinter, Accounts.minterAccount) - ); - update = await setMinter(token, accounts[3], 10000, { - from: Accounts.masterMinterAccount, - }); - await token.mint(accounts[1], 100, { from: accounts[3] }); - - await expectRevert( - token.mint(accounts[1], 200, { from: Accounts.minterAccount }) - ); - - let isMinter = await token.isMinter(Accounts.minterAccount); - assert.equal(isMinter, false); - let balance = await token.balanceOf(accounts[1]); - assert.equal(balance, 100); - }); - - it("should remove a minter even if the contract is paused", async function () { - await token.configureMinter(accounts[3], 200, { - from: Accounts.masterMinterAccount, - }); - let isAccountMinter = await token.isMinter(accounts[3]); - assert.equal(isAccountMinter, true); - await token.pause({ from: Accounts.pauserAccount }); - await token.removeMinter(accounts[3], { - from: Accounts.masterMinterAccount, - }); - isAccountMinter = await token.isMinter(accounts[3]); - assert.equal(isAccountMinter, false); - }); - - it("should pause contract even when contract is already paused", async function () { - await token.pause({ from: Accounts.pauserAccount }); - await token.pause({ from: Accounts.pauserAccount }); - let isPaused = await token.paused(); - assert.equal(isPaused, true); - }); - - it("should unpause contract even when contract is already unpaused", async function () { - await token.unpause({ from: Accounts.pauserAccount }); - let isPaused = await token.paused(); - assert.equal(isPaused, false); - }); - - it("should fail to updateMinterAllowance from non-masterMinter", async function () { - let minterAllowanceBefore = await token.minterAllowance( - Accounts.minterAccount - ); - assert.equal(minterAllowanceBefore, 0); - - await expectRevert( - token.configureMinter(Accounts.minterAccount, 100, { - from: Accounts.tokenOwnerAccount, - }) - ); - - let minterAllowanceAfter = await token.minterAllowance( - Accounts.minterAccount - ); - assert.equal(minterAllowanceAfter, 0); - }); - - it("should have correct name", async function () { - let actual = await token.name.call(); - assert.equal(actual, name); - }); - - it("should have correct symbol", async function () { - let actual = await token.symbol.call(); - assert.equal(actual, symbol); - }); - - it("should have correct decimals", async function () { - let actual = await token.decimals.call(); - assert.equal(actual.toString(16, 32), decimals.toString(16, 32)); - }); - - it("should have correct currency", async function () { - let actual = await token.currency.call(); - assert.equal(actual, currency); - }); - - it("should mint and burn tokens", async function () { - let burnerAddress = accounts[3]; - let amount = 500; - await setMinter(token, burnerAddress, amount); - let totalSupply = await token.totalSupply(); - let minterBalance = await token.balanceOf(burnerAddress); - assert.isTrue(totalSupply.isZero()); - assert.isTrue(minterBalance.isZero()); - - // mint tokens to burnerAddress - await mint(token, burnerAddress, amount, Accounts.minterAccount); - let totalSupply1 = await token.totalSupply(); - let minterBalance1 = await token.balanceOf(burnerAddress); - assert.isTrue(totalSupply1.cmp(totalSupply.add(newBigNumber(amount))) == 0); - assert.isTrue( - minterBalance1.cmp(minterBalance.add(newBigNumber(amount))) == 0 - ); - - // burn tokens - await burn(token, amount, burnerAddress); - let totalSupply2 = await token.totalSupply(); - assert.isTrue( - totalSupply2.cmp(totalSupply1.sub(newBigNumber(amount))) == 0 - ); - - // check that minter's balance has been reduced - let minterBalance2 = await token.balanceOf(burnerAddress); - assert.isTrue( - minterBalance2.cmp(minterBalance1.sub(newBigNumber(amount))) == 0 - ); - }); - - it("should try to burn tokens from a non-minter and fail", async function () { - let burnerAddress = accounts[3]; - let amount = 1000; - - await expectRevert(token.burn(amount, { from: burnerAddress })); - }); - - it("should fail to burn from a blacklisted address", async function () { - let burnerAddress = accounts[3]; - await setMinter(token, burnerAddress, 200); - await mint(token, burnerAddress, 200, Accounts.minterAccount); - await blacklist(token, burnerAddress); - - await expectRevert(token.burn(100, { from: burnerAddress })); - let balance0 = await token.balanceOf(burnerAddress); - assert.equal(balance0, 200); - }); - - it("should try to burn more tokens than balance and fail", async function () { - let burnerAddress = accounts[3]; - let amount = 500; - await setMinter(token, burnerAddress, 250); - await mint(token, burnerAddress, 100, Accounts.minterAccount); - - await expectRevert(token.burn(amount, { from: burnerAddress })); - }); - - it("should upgrade and preserve data", async function () { - await mint(token, accounts[2], 200, Accounts.minterAccount); - let initialBalance = await token.balanceOf(accounts[2]); - assert.isTrue(initialBalance.cmp(newBigNumber(200)) == 0); - - var newRawToken = await UpgradedFiatToken.new(); - var tokenConfig = await upgradeTo(proxy, newRawToken); - var newProxiedToken = tokenConfig.token; - var newToken = newProxiedToken; - - let upgradedBalance = await newToken.balanceOf(accounts[2]); - assert.isTrue(upgradedBalance.cmp(newBigNumber(200)) == 0); - await newToken.configureMinter(Accounts.minterAccount, 500, { - from: Accounts.masterMinterAccount, - }); - await newToken.mint(accounts[2], 200, { from: Accounts.minterAccount }); - let balance = await newToken.balanceOf(accounts[2]); - assert.isTrue(balance.cmp(newBigNumber(400)) == 0); - }); - - it("should updateRoleAddress for masterMinter", async function () { - let address1 = accounts[7]; - let address2 = accounts[6]; - await token.updateMasterMinter(address1, { - from: Accounts.tokenOwnerAccount, - }); - let masterMinter1 = await token.masterMinter(); - assert.equal(masterMinter1, address1); - - await token.updateMasterMinter(address2, { - from: Accounts.tokenOwnerAccount, - }); - let masterMinter2 = await token.masterMinter(); - assert.equal(masterMinter2, address2); - }); - - it("should updateRoleAddress for blacklister", async function () { - let address1 = accounts[7]; - let address2 = accounts[6]; - await token.updateBlacklister(address1, { - from: Accounts.tokenOwnerAccount, - }); - let blacklister1 = await token.blacklister(); - assert.equal(blacklister1, address1); - - await token.updateBlacklister(address2, { - from: Accounts.tokenOwnerAccount, - }); - let blacklister2 = await token.blacklister(); - assert.equal(blacklister2, address2); - }); - - it("should updateRoleAddress for pauser", async function () { - let address1 = accounts[7]; - let address2 = accounts[6]; - await token.updatePauser(address1, { from: Accounts.tokenOwnerAccount }); - let pauser1 = await token.pauser(); - assert.equal(pauser1, address1); - - await token.updatePauser(address2, { from: Accounts.tokenOwnerAccount }); - let pauser2 = await token.pauser(); - assert.equal(pauser2, address2); - }); - - it("should updateUpgraderAddress for upgrader", async function () { - let upgrader = await getAdmin(proxy); - assert.isTrue(addressEquals(Accounts.proxyOwnerAccount, upgrader)); - let address1 = accounts[10]; - let updated = await proxy.changeAdmin(address1, { - from: Accounts.proxyOwnerAccount, - }); - upgrader = await getAdmin(proxy); - assert.isTrue(addressEquals(upgrader, address1)); - - //Test upgrade with new upgrader account - await token.configureMinter(Accounts.minterAccount, 1000, { - from: Accounts.masterMinterAccount, - }); - await token.mint(accounts[2], 200, { from: Accounts.minterAccount }); - - let initialBalance = await token.balanceOf(accounts[2]); - assert.isTrue(initialBalance.cmp(newBigNumber(200)) == 0); - - var newRawToken = await UpgradedFiatToken.new(); - var tokenConfig = await upgradeTo(proxy, newRawToken, address1); - var newProxiedToken = tokenConfig.token; - var newToken = newProxiedToken; - - let upgradedBalance = await newToken.balanceOf(accounts[2]); - assert.isTrue(upgradedBalance.cmp(newBigNumber(200)) == 0); - await newToken.configureMinter(Accounts.minterAccount, 500, { - from: Accounts.masterMinterAccount, - }); - await newToken.mint(accounts[2], 200, { from: Accounts.minterAccount }); - let balance = await newToken.balanceOf(accounts[2]); - assert.isTrue(balance.cmp(newBigNumber(400)) == 0); - }); - - it("should fail to updateUpgraderAddress for upgrader using non-upgrader account", async function () { - let address1 = accounts[7]; - await expectRevert( - proxy.changeAdmin(address1, { from: Accounts.tokenOwnerAccount }) - ); - let upgrader = await getAdmin(proxy); - assert.notEqual(upgrader, address1); - }); - - it("should updateRoleAddress for roleAddressChanger", async function () { - let address1 = accounts[7]; - let address2 = accounts[6]; - await token.transferOwnership(address1, { - from: Accounts.tokenOwnerAccount, - }); - let roleAddressChanger1 = await token.owner(); - assert.equal(roleAddressChanger1, address1); - - await token.transferOwnership(address2, { from: address1 }); - let roleAddressChanger2 = await token.owner(); - assert.equal(roleAddressChanger2, address2); - }); - - it("should fail to updateRoleAddress from a non-roleAddressChanger", async function () { - let nonRoleAddressChanger = accounts[2]; - let address1 = accounts[7]; - - await expectRevert( - token.updateMasterMinter(address1, { from: nonRoleAddressChanger }) - ); - }); -} - -var testWrapper = require("./../TestWrapper"); -testWrapper.execute("FiatToken_LegacyTests", run_tests); - -module.exports = { - run_tests: run_tests, -}; diff --git a/test/assert/Pausable.test.js b/test/assert/Pausable.test.js deleted file mode 100644 index 4c9212792..000000000 --- a/test/assert/Pausable.test.js +++ /dev/null @@ -1,102 +0,0 @@ -var Tx = require("ethereumjs-tx"); - -var Pausable = artifacts.require("Pausable"); -var tokenUtils = require("./../TokenTestUtils.js"); -var BigNumber = require("bignumber.js"); -var expectRevert = tokenUtils.expectRevert; - -var AccountUtils = require("./../AccountUtils.js"); -var Accounts = AccountUtils.Accounts; -var addressEquals = AccountUtils.addressEquals; - -const should = require("chai") - .use(require("chai-as-promised")) - .use(require("chai-bignumber")(BigNumber)) - .should(); - -contract("PausableTests", function (accounts) { - var pause; - beforeEach(async function checkBefore() { - pause = await Pausable.new(); - await pause.updatePauser(Accounts.pauserAccount); - }); - - it("constructor owner", async function () { - var actualOwner = await pause.owner.call(); - assert.isTrue( - addressEquals(Accounts.deployerAccount, actualOwner), - "wrong owner" - ); - }); - - it("constructor pauser", async function () { - var actualOwner = await pause.pauser.call(); - assert.isTrue( - addressEquals(Accounts.pauserAccount, actualOwner), - "wrong pauser" - ); - }); - - it("paused after pausing", async function () { - await checkUnPaused(); - - await pause.pause({ from: Accounts.pauserAccount }); - await checkPaused(); - - // should stay paused even if we call it again - await pause.pause({ from: Accounts.pauserAccount }); - await checkPaused(); - - await pause.unpause({ from: Accounts.pauserAccount }); - await checkUnPaused(); - }); - - it("update pauser", async function () { - // pause from original pauser - await pause.pause({ from: Accounts.pauserAccount }); - await checkPaused("should have paused from original pauser account"); - - await pause.updatePauser(Accounts.arbitraryAccount, { - from: Accounts.deployerAccount, - }); - var newPauser = await pause.pauser.call(); - assert.isTrue(addressEquals(Accounts.arbitraryAccount, newPauser)); - // double check we're still paused - await checkPaused("should still be paused after changing pauser"); - - await pause.unpause({ from: Accounts.arbitraryAccount }); - await checkUnPaused(); - - //original pauser shouldn't work anymore - await expectRevert(pause.pause({ from: Accounts.pauserAccount })); - }); - - it("fail to update pauser from wrong account", async function () { - await expectRevert( - pause.updatePauser(Accounts.arbitraryAccount, { - from: Accounts.arbitraryAccount, - }) - ); - }); - - it("fail to pause from wrong account", async function () { - await expectRevert(pause.pause({ from: Accounts.arbitraryAccount })); - }); - - it("fail to unpause from wrong account", async function () { - await pause.pause({ from: Accounts.pauserAccount }); - await checkPaused(); - - await expectRevert(pause.unpause({ from: Accounts.arbitraryAccount })); - }); - - async function checkPaused(msg) { - var paused = await pause.paused.call(); - assert.isTrue(paused, msg); - } - - async function checkUnPaused(msg) { - var paused = await pause.paused.call(); - assert.isFalse(paused, msg); - } -}); diff --git a/test/basic/NegativeTests.js b/test/basic/NegativeTests.js deleted file mode 100644 index 1fe0a5f66..000000000 --- a/test/basic/NegativeTests.js +++ /dev/null @@ -1,1176 +0,0 @@ -var tokenUtils = require("./../TokenTestUtils.js"); -var newBigNumber = tokenUtils.newBigNumber; -var assertDiff = require("assert-diff"); -assertDiff.options.strict = true; - -var bigZero = tokenUtils.bigZero; -var bigHundred = tokenUtils.bigHundred; -var mint = tokenUtils.mint; -var checkVariables = tokenUtils.checkVariables; -var expectRevert = tokenUtils.expectRevert; -var name = tokenUtils.name; -var symbol = tokenUtils.symbol; -var currency = tokenUtils.currency; -var decimals = tokenUtils.decimals; - -var initializeTokenWithProxy = tokenUtils.initializeTokenWithProxy; -var customInitializeTokenWithProxy = tokenUtils.customInitializeTokenWithProxy; -var upgradeTo = tokenUtils.upgradeTo; -var UpgradedFiatToken = tokenUtils.UpgradedFiatToken; -var FiatToken = tokenUtils.FiatToken; - -var AccountUtils = require("./../AccountUtils.js"); -var Accounts = AccountUtils.Accounts; - -var amount = 100; -var zeroAddress = tokenUtils.zeroAddress; - -async function run_tests(newToken, accounts) { - beforeEach("Make fresh token contract", async function () { - rawToken = await newToken(); - var tokenConfig = await initializeTokenWithProxy(rawToken); - proxy = tokenConfig.proxy; - token = tokenConfig.token; - assert.equal(proxy.address, token.address); - }); - - // Mint - - it("nt001 should fail to mint when paused", async function () { - await token.configureMinter(Accounts.minterAccount, amount, { - from: Accounts.masterMinterAccount, - }); - await token.pause({ from: Accounts.pauserAccount }); - var customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount), - }, - { variable: "paused", expectedValue: true }, - ]; - await expectRevert( - token.mint(Accounts.arbitraryAccount, 50, { - from: Accounts.minterAccount, - }) - ); - await checkVariables([token], [customVars]); - }); - - it("nt002 should fail to mint when msg.sender is not a minter", async function () { - //Note: Accounts.minterAccount has not yet been configured as a minter - await expectRevert( - token.mint(Accounts.arbitraryAccount, 50, { - from: Accounts.minterAccount, - }) - ); - await checkVariables([token], [[]]); - }); - - it("nt003 should fail to mint when msg.sender is blacklisted", async function () { - await token.blacklist(Accounts.minterAccount, { - from: Accounts.blacklisterAccount, - }); - await token.configureMinter(Accounts.minterAccount, amount, { - from: Accounts.masterMinterAccount, - }); - var customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount), - }, - { variable: "isAccountBlacklisted.minterAccount", expectedValue: true }, - ]; - await expectRevert( - token.mint(Accounts.arbitraryAccount, 50, { - from: Accounts.minterAccount, - }) - ); - await checkVariables([token], [customVars]); - }); - - it("nt004 should fail to mint when recipient is blacklisted", async function () { - await token.blacklist(Accounts.arbitraryAccount, { - from: Accounts.blacklisterAccount, - }); - await token.configureMinter(Accounts.minterAccount, amount, { - from: Accounts.masterMinterAccount, - }); - var customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount), - }, - { - variable: "isAccountBlacklisted.arbitraryAccount", - expectedValue: true, - }, - ]; - await expectRevert( - token.mint(Accounts.arbitraryAccount, 50, { - from: Accounts.minterAccount, - }) - ); - await checkVariables([token], [customVars]); - }); - - it("nt005 should fail to mint when allowance of minter is less than amount", async function () { - await token.configureMinter(Accounts.minterAccount, amount - 1, { - from: Accounts.masterMinterAccount, - }); - var customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount - 1), - }, - ]; - await expectRevert( - token.mint(Accounts.arbitraryAccount, amount, { - from: Accounts.minterAccount, - }) - ); - await checkVariables([token], [customVars]); - }); - - it("nt006 should fail to mint to 0x0 address", async function () { - await token.configureMinter(Accounts.minterAccount, amount, { - from: Accounts.masterMinterAccount, - }); - var customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount), - }, - ]; - await expectRevert( - token.mint(zeroAddress, amount, { from: Accounts.minterAccount }) - ); - await checkVariables([token], [customVars]); - }); - - // Approve - - it("nt008 should fail to approve when spender is blacklisted", async function () { - await token.blacklist(Accounts.minterAccount, { - from: Accounts.blacklisterAccount, - }); - var customVars = [ - { variable: "isAccountBlacklisted.minterAccount", expectedValue: true }, - ]; - await expectRevert( - token.approve(Accounts.minterAccount, 100, { - from: Accounts.arbitraryAccount, - }) - ); - await checkVariables([token], [customVars]); - }); - - it("nt009 should fail to approve when msg.sender is blacklisted", async function () { - await token.blacklist(Accounts.arbitraryAccount, { - from: Accounts.blacklisterAccount, - }); - var customVars = [ - { - variable: "isAccountBlacklisted.arbitraryAccount", - expectedValue: true, - }, - ]; - await expectRevert( - token.approve(Accounts.minterAccount, 100, { - from: Accounts.arbitraryAccount, - }) - ); - await checkVariables([token], [customVars]); - }); - - it("nt010 should fail to approve when contract is paused", async function () { - await token.pause({ from: Accounts.pauserAccount }); - var customVars = [{ variable: "paused", expectedValue: true }]; - await expectRevert( - token.approve(Accounts.minterAccount, 100, { - from: Accounts.arbitraryAccount, - }) - ); - await checkVariables([token], [customVars]); - }); - - // TransferFrom - - it("nt012 should fail to transferFrom to 0x0 address", async function () { - await token.configureMinter(Accounts.minterAccount, amount, { - from: Accounts.masterMinterAccount, - }); - var customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount), - }, - ]; - await checkVariables([token], [customVars]); - - await token.mint(Accounts.arbitraryAccount, 50, { - from: Accounts.minterAccount, - }); - await token.approve(Accounts.arbitraryAccount2, 50, { - from: Accounts.arbitraryAccount, - }); - customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount - 50), - }, - { - variable: "balances.arbitraryAccount", - expectedValue: newBigNumber(50), - }, - { variable: "totalSupply", expectedValue: newBigNumber(50) }, - { - variable: "allowance.arbitraryAccount.arbitraryAccount2", - expectedValue: newBigNumber(50), - }, - ]; - await expectRevert( - token.transferFrom(Accounts.arbitraryAccount, zeroAddress, 50, { - from: Accounts.arbitraryAccount2, - }) - ); - await checkVariables([token], [customVars]); - }); - - it("nt013 should fail to transferFrom an amount greater than balance", async function () { - await token.configureMinter(Accounts.minterAccount, amount, { - from: Accounts.masterMinterAccount, - }); - customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount), - }, - ]; - await checkVariables([token], [customVars]); - - await token.mint(Accounts.arbitraryAccount, 50, { - from: Accounts.minterAccount, - }); - await token.approve(Accounts.blacklisterAccount, amount, { - from: Accounts.arbitraryAccount, - }); - customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount - 50), - }, - { - variable: "balances.arbitraryAccount", - expectedValue: newBigNumber(50), - }, - { variable: "totalSupply", expectedValue: newBigNumber(50) }, - { - variable: "allowance.arbitraryAccount.blacklisterAccount", - expectedValue: newBigNumber(amount), - }, - ]; - await expectRevert( - token.transferFrom( - Accounts.arbitraryAccount, - Accounts.pauserAccount, - amount, - { from: Accounts.blacklisterAccount } - ) - ); - await checkVariables([token], [customVars]); - }); - - it("nt014 should fail to transferFrom to blacklisted recipient", async function () { - await token.configureMinter(Accounts.minterAccount, amount, { - from: Accounts.masterMinterAccount, - }); - customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount), - }, - ]; - await checkVariables([token], [customVars]); - - await token.mint(Accounts.blacklisterAccount, 50, { - from: Accounts.minterAccount, - }); - 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: newBigNumber(amount - 50), - }, - { - variable: "balances.blacklisterAccount", - expectedValue: newBigNumber(50), - }, - { variable: "totalSupply", expectedValue: newBigNumber(50) }, - { - variable: "allowance.blacklisterAccount.arbitraryAccount2", - expectedValue: newBigNumber(50), - }, - { - variable: "isAccountBlacklisted.arbitraryAccount", - expectedValue: true, - }, - ]; - await expectRevert( - token.transferFrom( - Accounts.blacklisterAccount, - Accounts.arbitraryAccount, - 50, - { from: Accounts.arbitraryAccount2 } - ) - ); - await checkVariables([token], [customVars]); - }); - - it("nt015 should fail to transferFrom from blacklisted msg.sender", async function () { - await token.configureMinter(Accounts.minterAccount, amount, { - from: Accounts.masterMinterAccount, - }); - customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount), - }, - ]; - await checkVariables([token], [customVars]); - - 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: newBigNumber(amount - 50), - }, - { - variable: "balances.arbitraryAccount2", - expectedValue: newBigNumber(50), - }, - { variable: "totalSupply", expectedValue: newBigNumber(50) }, - { - variable: "allowance.arbitraryAccount2.arbitraryAccount", - expectedValue: newBigNumber(50), - }, - { - variable: "isAccountBlacklisted.arbitraryAccount", - expectedValue: true, - }, - ]; - await expectRevert( - token.transferFrom( - Accounts.arbitraryAccount2, - Accounts.pauserAccount, - 50, - { from: Accounts.arbitraryAccount } - ) - ); - await checkVariables([token], [customVars]); - }); - - it("nt016 should fail to transferFrom when from is blacklisted", async function () { - await token.configureMinter(Accounts.minterAccount, amount, { - from: Accounts.masterMinterAccount, - }); - customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount), - }, - ]; - await checkVariables([token], [customVars]); - - await token.mint(Accounts.arbitraryAccount, 50, { - from: Accounts.minterAccount, - }); - 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: newBigNumber(amount - 50), - }, - { - variable: "balances.arbitraryAccount", - expectedValue: newBigNumber(50), - }, - { variable: "totalSupply", expectedValue: newBigNumber(50) }, - { - variable: "allowance.arbitraryAccount.arbitraryAccount2", - expectedValue: newBigNumber(50), - }, - { - variable: "isAccountBlacklisted.arbitraryAccount", - expectedValue: true, - }, - ]; - await expectRevert( - token.transferFrom( - Accounts.arbitraryAccount, - Accounts.pauserAccount, - 50, - { from: Accounts.arbitraryAccount2 } - ) - ); - await checkVariables([token], [customVars]); - }); - - it("nt017 should fail to transferFrom an amount greater than allowed for msg.sender", async function () { - await token.configureMinter(Accounts.minterAccount, amount, { - from: Accounts.masterMinterAccount, - }); - customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount), - }, - ]; - await checkVariables([token], [customVars]); - - await token.mint(Accounts.arbitraryAccount, 50, { - from: Accounts.minterAccount, - }); - await token.approve(Accounts.arbitraryAccount2, 50, { - from: Accounts.arbitraryAccount, - }); - customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount - 50), - }, - { - variable: "balances.arbitraryAccount", - expectedValue: newBigNumber(50), - }, - { variable: "totalSupply", expectedValue: newBigNumber(50) }, - { - variable: "allowance.arbitraryAccount.arbitraryAccount2", - expectedValue: newBigNumber(50), - }, - ]; - await expectRevert( - token.transferFrom( - Accounts.arbitraryAccount, - Accounts.pauserAccount, - 60, - { from: Accounts.arbitraryAccount2 } - ) - ); - await checkVariables([token], [customVars]); - }); - - it("nt018 should fail to transferFrom when paused", async function () { - await token.configureMinter(Accounts.minterAccount, amount, { - from: Accounts.masterMinterAccount, - }); - var customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount), - }, - ]; - await checkVariables([token], [customVars]); - - await token.mint(Accounts.arbitraryAccount, 50, { - from: Accounts.minterAccount, - }); - 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: newBigNumber(amount - 50), - }, - { - variable: "balances.arbitraryAccount", - expectedValue: newBigNumber(50), - }, - { variable: "totalSupply", expectedValue: newBigNumber(50) }, - { - variable: "allowance.arbitraryAccount.arbitraryAccount2", - expectedValue: newBigNumber(50), - }, - { variable: "paused", expectedValue: true }, - ]; - await expectRevert( - token.transferFrom( - Accounts.arbitraryAccount, - Accounts.pauserAccount, - 50, - { from: Accounts.arbitraryAccount2 } - ) - ); - await checkVariables([token], [customVars]); - }); - - // Transfer - - it("nt020 should fail to transfer to 0x0 address", async function () { - await token.configureMinter(Accounts.minterAccount, amount, { - from: Accounts.masterMinterAccount, - }); - var customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount), - }, - ]; - await checkVariables([token], [customVars]); - - await token.mint(Accounts.arbitraryAccount, 50, { - from: Accounts.minterAccount, - }); - customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount - 50), - }, - { - variable: "balances.arbitraryAccount", - expectedValue: newBigNumber(50), - }, - { variable: "totalSupply", expectedValue: newBigNumber(50) }, - ]; - await expectRevert( - token.transfer(zeroAddress, 50, { from: Accounts.arbitraryAccount }) - ); - await checkVariables([token], [customVars]); - }); - - it("nt021 should fail to transfer an amount greater than balance", async function () { - await token.configureMinter(Accounts.minterAccount, amount, { - from: Accounts.masterMinterAccount, - }); - customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount), - }, - ]; - await checkVariables([token], [customVars]); - - await token.mint(Accounts.arbitraryAccount, 50, { - from: Accounts.minterAccount, - }); - var customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount - 50), - }, - { - variable: "balances.arbitraryAccount", - expectedValue: newBigNumber(50), - }, - { variable: "totalSupply", expectedValue: newBigNumber(50) }, - ]; - await expectRevert( - token.transfer(Accounts.pauserAccount, amount, { - from: Accounts.arbitraryAccount, - }) - ); - await checkVariables([token], [customVars]); - }); - - it("nt022 should fail to transfer to blacklisted recipient", async function () { - await token.configureMinter(Accounts.minterAccount, amount, { - from: Accounts.masterMinterAccount, - }); - customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount), - }, - ]; - await checkVariables([token], [customVars]); - - await token.mint(Accounts.arbitraryAccount2, 50, { - from: Accounts.minterAccount, - }); - await token.blacklist(Accounts.arbitraryAccount, { - from: Accounts.blacklisterAccount, - }); - customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount - 50), - }, - { - variable: "balances.arbitraryAccount2", - expectedValue: newBigNumber(50), - }, - { variable: "totalSupply", expectedValue: newBigNumber(50) }, - { - variable: "isAccountBlacklisted.arbitraryAccount", - expectedValue: true, - }, - ]; - await expectRevert( - token.transfer(Accounts.arbitraryAccount, 50, { - from: Accounts.arbitraryAccount2, - }) - ); - await checkVariables([token], [customVars]); - }); - - it("nt023 should fail to transfer when sender is blacklisted", async function () { - await token.configureMinter(Accounts.minterAccount, amount, { - from: Accounts.masterMinterAccount, - }); - customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount), - }, - ]; - await checkVariables([token], [customVars]); - - await token.mint(Accounts.arbitraryAccount, 50, { - from: Accounts.minterAccount, - }); - await token.blacklist(Accounts.arbitraryAccount, { - from: Accounts.blacklisterAccount, - }); - customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount - 50), - }, - { - variable: "balances.arbitraryAccount", - expectedValue: newBigNumber(50), - }, - { variable: "totalSupply", expectedValue: newBigNumber(50) }, - { - variable: "isAccountBlacklisted.arbitraryAccount", - expectedValue: true, - }, - ]; - await expectRevert( - token.transfer(Accounts.tokenOwnerAccount, 50, { - from: Accounts.arbitraryAccount, - }) - ); - await checkVariables([token], [customVars]); - }); - - it("nt024 should fail to transfer when paused", async function () { - await token.configureMinter(Accounts.minterAccount, amount, { - from: Accounts.masterMinterAccount, - }); - var customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount), - }, - ]; - await checkVariables([token], [customVars]); - - await token.mint(Accounts.arbitraryAccount, 50, { - from: Accounts.minterAccount, - }); - await token.pause({ from: Accounts.pauserAccount }); - customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount - 50), - }, - { - variable: "balances.arbitraryAccount", - expectedValue: newBigNumber(50), - }, - { variable: "totalSupply", expectedValue: newBigNumber(50) }, - { variable: "paused", expectedValue: true }, - ]; - await expectRevert( - token.transfer(Accounts.tokenOwnerAccount, 50, { - from: Accounts.arbitraryAccount, - }) - ); - await checkVariables([token], [customVars]); - }); - - // ConfigureMinter - - it("nt026 should fail to configureMinter when sender is not masterMinter", async function () { - assert.isFalse(Accounts.arbitraryAccount == Accounts.masterMinterAccount); - await expectRevert( - token.configureMinter(Accounts.minterAccount, amount, { - from: Accounts.arbitraryAccount, - }) - ); - await checkVariables([token], [[]]); - }); - - it("nt028 should fail to configureMinter when paused", async function () { - await token.pause({ from: Accounts.pauserAccount }); - customVars = [{ variable: "paused", expectedValue: true }]; - await expectRevert( - token.configureMinter(Accounts.minterAccount, amount, { - from: Accounts.masterMinterAccount, - }) - ); - await checkVariables([token], [customVars]); - }); - - // RemoveMinter - - it("nt029 should fail to removeMinter when sender is not masterMinter", async function () { - await token.configureMinter(Accounts.minterAccount, amount, { - from: Accounts.masterMinterAccount, - }); - var customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount), - }, - ]; - await expectRevert( - token.removeMinter(Accounts.minterAccount, { - from: Accounts.arbitraryAccount, - }) - ); - await checkVariables([token], [customVars]); - }); - - // Burn - - it("nt031 should fail to burn when balance is less than amount", async function () { - await token.configureMinter(Accounts.minterAccount, amount, { - from: Accounts.masterMinterAccount, - }); - var customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount), - }, - ]; - await expectRevert(token.burn(amount, { from: Accounts.minterAccount })); - await checkVariables([token], [customVars]); - }); - - it("nt032 should fail to burn when amount is -1", async function () { - await token.configureMinter(Accounts.minterAccount, amount, { - from: Accounts.masterMinterAccount, - }); - await token.mint(Accounts.minterAccount, amount, { - from: Accounts.minterAccount, - }); - var customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(0), - }, - { - variable: "balances.minterAccount", - expectedValue: newBigNumber(amount), - }, - { variable: "totalSupply", expectedValue: newBigNumber(amount) }, - ]; - await expectRevert(token.burn(-1, { from: Accounts.minterAccount })); - await checkVariables([token], [customVars]); - }); - - it("nt033 should fail to burn when sender is blacklisted", async function () { - await token.configureMinter(Accounts.minterAccount, amount, { - from: Accounts.masterMinterAccount, - }); - var customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount), - }, - ]; - await checkVariables([token], [customVars]); - - await token.mint(Accounts.minterAccount, 50, { - from: Accounts.minterAccount, - }); - await token.blacklist(Accounts.minterAccount, { - from: Accounts.blacklisterAccount, - }); - customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount - 50), - }, - { variable: "balances.minterAccount", expectedValue: newBigNumber(50) }, - { variable: "totalSupply", expectedValue: newBigNumber(50) }, - { variable: "isAccountBlacklisted.minterAccount", expectedValue: true }, - ]; - await expectRevert(token.burn(50, { from: Accounts.minterAccount })); - await checkVariables([token], [customVars]); - }); - - it("nt034 should fail to burn when paused", async function () { - await token.configureMinter(Accounts.minterAccount, amount, { - from: Accounts.masterMinterAccount, - }); - var customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount), - }, - ]; - await checkVariables([token], [customVars]); - - await token.mint(Accounts.minterAccount, 50, { - from: Accounts.minterAccount, - }); - await token.pause({ from: Accounts.pauserAccount }); - customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount - 50), - }, - { variable: "balances.minterAccount", expectedValue: newBigNumber(50) }, - { variable: "totalSupply", expectedValue: newBigNumber(50) }, - { variable: "paused", expectedValue: true }, - ]; - await expectRevert(token.burn(50, { from: Accounts.minterAccount })); - await checkVariables([token], [customVars]); - }); - - it("nt035 should fail to burn when sender is not minter", async function () { - await token.configureMinter(Accounts.minterAccount, amount, { - from: Accounts.masterMinterAccount, - }); - var customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount), - }, - ]; - await checkVariables([token], [customVars]); - - await token.mint(Accounts.minterAccount, 50, { - from: Accounts.minterAccount, - }); - customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount - 50), - }, - { variable: "balances.minterAccount", expectedValue: newBigNumber(50) }, - { variable: "totalSupply", expectedValue: newBigNumber(50) }, - ]; - await expectRevert(token.burn(50, { from: Accounts.arbitraryAccount })); - await checkVariables([token], [customVars]); - }); - - it("nt036 should fail to burn after removeMinter", async function () { - await token.configureMinter(Accounts.minterAccount, amount, { - from: Accounts.masterMinterAccount, - }); - var customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount), - }, - ]; - await checkVariables([token], [customVars]); - - await token.mint(Accounts.minterAccount, 50, { - from: Accounts.minterAccount, - }); - customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount - 50), - }, - { variable: "balances.minterAccount", expectedValue: newBigNumber(50) }, - { variable: "totalSupply", expectedValue: newBigNumber(50) }, - ]; - await checkVariables([token], [customVars]); - - await token.removeMinter(Accounts.minterAccount, { - from: Accounts.masterMinterAccount, - }); - customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: false }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(0), - }, - { variable: "balances.minterAccount", expectedValue: newBigNumber(50) }, - { variable: "totalSupply", expectedValue: newBigNumber(50) }, - ]; - await expectRevert(token.burn(50, { from: Accounts.minterAccount })); - await checkVariables([token], [customVars]); - }); - - // Update functions - - it("nt050 should fail to updatePauser when sender is not owner", async function () { - await expectRevert( - token.updatePauser(Accounts.arbitraryAccount, { - from: Accounts.pauserAccount, - }) - ); - await checkVariables([token], [[]]); - }); - - it("nt049 should fail to updateMasterMinter when sender is not owner", async function () { - await expectRevert( - token.updateMasterMinter(Accounts.arbitraryAccount, { - from: Accounts.pauserAccount, - }) - ); - await checkVariables([token], [[]]); - }); - - it("nt048 should fail to updateBlacklister when sender is not owner", async function () { - await expectRevert( - token.updateBlacklister(Accounts.arbitraryAccount, { - from: Accounts.pauserAccount, - }) - ); - await checkVariables([token], [[]]); - }); - - // Pause and Unpause - - it("nt040 should fail to pause when sender is not pauser", async function () { - await expectRevert(token.pause({ from: Accounts.arbitraryAccount })); - await checkVariables([token], [[]]); - }); - - it("nt041 should fail to unpause when sender is not pauser", async function () { - await token.pause({ from: Accounts.pauserAccount }); - customVars = [{ variable: "paused", expectedValue: true }]; - await expectRevert(token.unpause({ from: Accounts.arbitraryAccount })); - await checkVariables([token], [customVars]); - }); - - // Blacklist and Unblacklist - - it("nt042 should fail to blacklist when sender is not blacklister", async function () { - await expectRevert( - token.blacklist(Accounts.tokenOwnerAccount, { - from: Accounts.arbitraryAccount, - }) - ); - await checkVariables([token], [[]]); - }); - - it("nt043 should fail to unblacklist when sender is not blacklister", async function () { - await token.blacklist(Accounts.arbitraryAccount, { - from: Accounts.blacklisterAccount, - }); - customVars = [ - { - variable: "isAccountBlacklisted.arbitraryAccount", - expectedValue: true, - }, - ]; - await expectRevert( - token.unBlacklist(Accounts.arbitraryAccount, { - from: Accounts.tokenOwnerAccount, - }) - ); - await checkVariables([token], [customVars]); - }); - - // Upgrade - - it("nt054 should fail to transferOwnership when sender is not owner", async function () { - // Create upgraded token - var newRawToken = await UpgradedFiatToken.new(); - var tokenConfig = await upgradeTo(proxy, newRawToken); - var newProxiedToken = tokenConfig.token; - var newToken = newProxiedToken; - - var newToken_result = [ - { variable: "proxiedTokenAddress", expectedValue: newRawToken.address }, - ]; - - // expectRevert on transferOwnership with wrong sender - await expectRevert( - newToken.transferOwnership(Accounts.arbitraryAccount, { - from: Accounts.arbitraryAccount2, - }) - ); - await checkVariables([newToken], [newToken_result]); - }); - - it("nt055 should fail to mint when amount = 0", async function () { - await token.configureMinter(Accounts.minterAccount, amount, { - from: Accounts.masterMinterAccount, - }); - await expectRevert( - token.mint(Accounts.pauserAccount, 0, { from: Accounts.minterAccount }) - ); - - var customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount), - }, - ]; - await checkVariables([token], [customVars]); - }); - - it("nt056 should fail to burn when amount = 0", async function () { - await token.configureMinter(Accounts.minterAccount, amount, { - from: Accounts.masterMinterAccount, - }); - await token.mint(Accounts.minterAccount, amount, { - from: Accounts.minterAccount, - }); - await expectRevert(token.burn(0, { from: Accounts.minterAccount })); - var customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "balances.minterAccount", - expectedValue: newBigNumber(amount), - }, - { variable: "totalSupply", expectedValue: newBigNumber(amount) }, - ]; - await checkVariables([token], [customVars]); - }); - - it("nt064 transferOwnership should fail on 0x0", async function () { - await expectRevert( - token.transferOwnership(zeroAddress, { from: Accounts.tokenOwnerAccount }) - ); - }); - - it("nt057 updateMasterMinter should fail on 0x0", async function () { - await expectRevert( - token.updateMasterMinter(zeroAddress, { - from: Accounts.tokenOwnerAccount, - }) - ); - }); - - it("nt058 updatePauser should fail on 0x0", async function () { - await expectRevert( - token.updatePauser(zeroAddress, { from: Accounts.tokenOwnerAccount }) - ); - }); - - it("nt059 updateBlacklister should fail on 0x0", async function () { - await expectRevert( - token.updateBlacklister(zeroAddress, { from: Accounts.tokenOwnerAccount }) - ); - }); - - it("nt060 initialize should fail when _masterMinter is 0x0", async function () { - rawToken = await newToken(); - await expectRevert( - customInitializeTokenWithProxy( - rawToken, - zeroAddress, - Accounts.pauserAccount, - Accounts.blacklisterAccount, - Accounts.tokenOwnerAccount - ) - ); - }); - - it("nt061 initialize should fail when _pauser is 0x0", async function () { - rawToken = await newToken(); - await expectRevert( - customInitializeTokenWithProxy( - rawToken, - Accounts.masterMinterAccount, - zeroAddress, - Accounts.blacklisterAccount, - Accounts.tokenOwnerAccount - ) - ); - }); - - it("nt062 initialize should fail when _blacklister is 0x0", async function () { - rawToken = await newToken(); - await expectRevert( - customInitializeTokenWithProxy( - rawToken, - Accounts.masterMinterAccount, - Accounts.pauserAccount, - zeroAddress, - Accounts.tokenOwnerAccount - ) - ); - }); - - it("nt063 initialize should fail when _owner is 0x0", async function () { - rawToken = await newToken(); - await expectRevert( - customInitializeTokenWithProxy( - rawToken, - Accounts.masterMinterAccount, - Accounts.pauserAccount, - Accounts.blacklisterAccount, - zeroAddress - ) - ); - }); -} - -var testWrapper = require("./../TestWrapper"); -testWrapper.execute("FiatToken_NegativeTests", run_tests); - -module.exports = { - run_tests: run_tests, -}; diff --git a/test/basic/PositiveTests.js b/test/basic/PositiveTests.js deleted file mode 100644 index eed349663..000000000 --- a/test/basic/PositiveTests.js +++ /dev/null @@ -1,392 +0,0 @@ -var tokenUtils = require("./../TokenTestUtils.js"); -var newBigNumber = tokenUtils.newBigNumber; -var assertDiff = require("assert-diff"); -assertDiff.options.strict = true; - -var bigZero = tokenUtils.bigZero; -var bigHundred = tokenUtils.bigHundred; -var mint = tokenUtils.mint; -var checkVariables = tokenUtils.checkVariables; -var name = tokenUtils.name; -var symbol = tokenUtils.symbol; -var currency = tokenUtils.currency; -var decimals = tokenUtils.decimals; - -var initializeTokenWithProxy = tokenUtils.initializeTokenWithProxy; -var FiatToken = tokenUtils.FiatToken; - -var AccountUtils = require("./../AccountUtils.js"); -var Accounts = AccountUtils.Accounts; - -var amount = 100; - -async function run_tests(newToken, accounts) { - beforeEach("Make fresh token contract", async function () { - rawToken = await newToken(); - var tokenConfig = await initializeTokenWithProxy(rawToken); - proxy = tokenConfig.proxy; - token = tokenConfig.token; - assert.equal(proxy.address, token.address); - }); - - it("pt000 should check that default variable values are correct", async function () { - await checkVariables([token], [[]]); - }); - - // Pause and Unpause - - it("pt011 should pause and set paused to true", async function () { - await token.pause({ from: Accounts.pauserAccount }); - var customVars = [{ variable: "paused", expectedValue: true }]; - await checkVariables([token], [customVars]); - }); - - it("pt006 should unpause and set paused to false", async function () { - await token.pause({ from: Accounts.pauserAccount }); - var customVars = [{ variable: "paused", expectedValue: true }]; - await checkVariables([token], [customVars]); - await token.unpause({ from: Accounts.pauserAccount }); - await checkVariables([token], [[]]); - }); - - // Approve - - it("pt020 should approve a spend and set allowed amount", async function () { - await token.approve(Accounts.minterAccount, amount, { - from: Accounts.arbitraryAccount, - }); - var customVars = [ - { - variable: "allowance.arbitraryAccount.minterAccount", - expectedValue: newBigNumber(amount), - }, - ]; - await checkVariables([token], [customVars]); - }); - - // Blacklist and Unblacklist - - it("pt019 should blacklist and set blacklisted to true", async function () { - await token.blacklist(Accounts.arbitraryAccount, { - from: Accounts.blacklisterAccount, - }); - var customVars = [ - { - variable: "isAccountBlacklisted.arbitraryAccount", - expectedValue: true, - }, - ]; - await checkVariables([token], [customVars]); - }); - - it("pt018 should blacklist and set blacklisted to true, then unblacklist and set blacklisted to false", async function () { - await token.blacklist(Accounts.arbitraryAccount, { - from: Accounts.blacklisterAccount, - }); - var customVars = [ - { - variable: "isAccountBlacklisted.arbitraryAccount", - expectedValue: true, - }, - ]; - await checkVariables([token], [customVars]); - - await token.unBlacklist(Accounts.arbitraryAccount, { - from: Accounts.blacklisterAccount, - }); - await checkVariables([token], [[]]); - }); - - // Configure minter - - it("pt015 should configureMinter, setting the minter to true and mintingAllowance to amount", async function () { - await token.configureMinter(Accounts.minterAccount, amount, { - from: Accounts.masterMinterAccount, - }); - var customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount), - }, - ]; - await checkVariables([token], [customVars]); - }); - - // Mint and Burn - - it("pt012 should mint the amount, increasing balance of recipient by amount, increasing total supply by amount, and decreasing minterAllowed by amount", async function () { - var mintAmount = 50; - - await token.configureMinter(Accounts.minterAccount, amount, { - from: Accounts.masterMinterAccount, - }); - var customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount), - }, - ]; - await checkVariables([token], [customVars]); - - await token.mint(Accounts.arbitraryAccount, mintAmount, { - from: Accounts.minterAccount, - }); - customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount - mintAmount), - }, - { - variable: "balances.arbitraryAccount", - expectedValue: newBigNumber(mintAmount), - }, - { variable: "totalSupply", expectedValue: newBigNumber(mintAmount) }, - ]; - await checkVariables([token], [customVars]); - }); - - it("pt017 should burn amount of tokens and reduce balance and total supply by amount", async function () { - var mintAmount = 11; - var burnAmount = 10; - - await token.configureMinter(Accounts.minterAccount, mintAmount, { - from: Accounts.masterMinterAccount, - }); - await token.mint(Accounts.minterAccount, mintAmount, { - from: Accounts.minterAccount, - }); - var setup = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(0), - }, - { - variable: "balances.minterAccount", - expectedValue: newBigNumber(mintAmount), - }, - { variable: "totalSupply", expectedValue: newBigNumber(mintAmount) }, - ]; - await checkVariables([token], [setup]); - - await token.burn(burnAmount, { from: Accounts.minterAccount }); - var afterBurn = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(0), - }, - { - variable: "balances.minterAccount", - expectedValue: newBigNumber(mintAmount - burnAmount), - }, - { - variable: "totalSupply", - expectedValue: newBigNumber(mintAmount - burnAmount), - }, - ]; - await checkVariables([token], [afterBurn]); - }); - - // Remove minter - - it("pt010 should removeMinter, setting the minter to false and minterAllowed to 0", async function () { - let mintAmount = 11; - - await token.configureMinter(Accounts.minterAccount, amount, { - from: Accounts.masterMinterAccount, - }); - await token.mint(Accounts.arbitraryAccount, mintAmount, { - from: Accounts.minterAccount, - }); - var customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount - mintAmount), - }, - { - variable: "balances.arbitraryAccount", - expectedValue: newBigNumber(mintAmount), - }, - { variable: "totalSupply", expectedValue: newBigNumber(mintAmount) }, - ]; - await checkVariables([token], [customVars]); - - await token.removeMinter(Accounts.minterAccount, { - from: Accounts.masterMinterAccount, - }); - customVars = [ - { - variable: "balances.arbitraryAccount", - expectedValue: newBigNumber(mintAmount), - }, - { variable: "totalSupply", expectedValue: newBigNumber(mintAmount) }, - ]; - await checkVariables([token], [customVars]); - }); - - // Transfer and transferFrom - - it("pt008 should transfer, reducing sender balance by amount and increasing recipient balance by amount", async function () { - let mintAmount = 50; - - await token.configureMinter(Accounts.minterAccount, amount, { - from: Accounts.masterMinterAccount, - }); - var customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount), - }, - ]; - await checkVariables([token], [customVars]); - - await token.mint(Accounts.arbitraryAccount, mintAmount, { - from: Accounts.minterAccount, - }); - customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount - mintAmount), - }, - { - variable: "balances.arbitraryAccount", - expectedValue: newBigNumber(mintAmount), - }, - { variable: "totalSupply", expectedValue: newBigNumber(mintAmount) }, - ]; - await checkVariables([token], [customVars]); - - await token.transfer(Accounts.arbitraryAccount2, mintAmount, { - from: Accounts.arbitraryAccount, - }); - customVars = [ - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount - mintAmount), - }, - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { variable: "balances.arbitraryAccount", expectedValue: bigZero }, - { - variable: "balances.arbitraryAccount2", - expectedValue: newBigNumber(mintAmount), - }, - { variable: "totalSupply", expectedValue: newBigNumber(mintAmount) }, - ]; - await checkVariables([token], [customVars]); - }); - - it("pt007 should transferFrom, reducing sender balance by amount and increasing recipient balance by amount", async function () { - let mintAmount = 50; - - await token.configureMinter(Accounts.minterAccount, amount, { - from: Accounts.masterMinterAccount, - }); - var customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount), - }, - ]; - await checkVariables([token], [customVars]); - - await token.mint(Accounts.arbitraryAccount, mintAmount, { - from: Accounts.minterAccount, - }); - customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount - mintAmount), - }, - { - variable: "balances.arbitraryAccount", - expectedValue: newBigNumber(mintAmount), - }, - { variable: "totalSupply", expectedValue: newBigNumber(mintAmount) }, - ]; - await checkVariables([token], [customVars]); - - await token.approve(Accounts.masterMinterAccount, mintAmount, { - from: Accounts.arbitraryAccount, - }); - await token.transferFrom( - Accounts.arbitraryAccount, - Accounts.arbitraryAccount2, - mintAmount, - { from: Accounts.masterMinterAccount } - ); - customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount - mintAmount), - }, - { variable: "balances.arbitraryAccount", expectedValue: bigZero }, - { - variable: "balances.arbitraryAccount2", - expectedValue: newBigNumber(mintAmount), - }, - { variable: "totalSupply", expectedValue: newBigNumber(mintAmount) }, - ]; - await checkVariables([token], [customVars]); - }); - - // Update methods - - it("pt004 should updateMasterMinter", async function () { - await token.updateMasterMinter(Accounts.arbitraryAccount, { - from: Accounts.tokenOwnerAccount, - }); - var result = [ - { variable: "masterMinter", expectedValue: Accounts.arbitraryAccount }, - ]; - await checkVariables([token], [result]); - }); - - it("pt005 should updateBlacklister", async function () { - await token.updateBlacklister(Accounts.arbitraryAccount, { - from: Accounts.tokenOwnerAccount, - }); - var result = [ - { variable: "blacklister", expectedValue: Accounts.arbitraryAccount }, - ]; - await checkVariables([token], [result]); - }); - - it("pt003 should updatePauser", async function () { - await token.updatePauser(Accounts.arbitraryAccount, { - from: Accounts.tokenOwnerAccount, - }); - var result = [ - { variable: "pauser", expectedValue: Accounts.arbitraryAccount }, - ]; - await checkVariables([token], [result]); - }); - - // Transfer Ownership - - it("pt009 should set owner to _newOwner", async function () { - await token.transferOwnership(Accounts.arbitraryAccount, { - from: Accounts.tokenOwnerAccount, - }); - var result = [ - { variable: "tokenOwner", expectedValue: Accounts.arbitraryAccount }, - ]; - await checkVariables([token], [result]); - }); -} - -var testWrapper = require("./../TestWrapper"); -testWrapper.execute("FiatToken_PositiveTests", run_tests); - -module.exports = { - run_tests: run_tests, -}; diff --git a/test/extended/ExtendedPositiveTests.js b/test/extended/ExtendedPositiveTests.js deleted file mode 100644 index 7d4e052ae..000000000 --- a/test/extended/ExtendedPositiveTests.js +++ /dev/null @@ -1,590 +0,0 @@ -var tokenUtils = require("./../TokenTestUtils.js"); -var newBigNumber = tokenUtils.newBigNumber; -var assertDiff = require("assert-diff"); -assertDiff.options.strict = true; - -var bigZero = tokenUtils.bigZero; -var bigHundred = tokenUtils.bigHundred; -var mint = tokenUtils.mint; -var checkVariables = tokenUtils.checkVariables; -var name = tokenUtils.name; -var symbol = tokenUtils.symbol; -var currency = tokenUtils.currency; -var decimals = tokenUtils.decimals; - -var initializeTokenWithProxy = tokenUtils.initializeTokenWithProxy; -var UpgradedFiatToken = tokenUtils.UpgradedFiatToken; -var FiatToken = tokenUtils.FiatToken; -var upgradeTo = tokenUtils.upgradeTo; - -var AccountUtils = require("./../AccountUtils.js"); -var Accounts = AccountUtils.Accounts; - -var amount = 100; - -async function run_tests(newToken, accounts) { - beforeEach("Make fresh token contract", async function () { - rawToken = await newToken(); - var tokenConfig = await initializeTokenWithProxy(rawToken); - proxy = tokenConfig.proxy; - token = tokenConfig.token; - assert.equal(proxy.address, token.address); - }); - - // Paused - - it("ept001 should changeAdmin while paused", async function () { - await token.pause({ from: Accounts.pauserAccount }); - await proxy.changeAdmin(Accounts.arbitraryAccount, { - from: Accounts.proxyOwnerAccount, - }); - var result = [ - { variable: "paused", expectedValue: true }, - { variable: "proxyOwner", expectedValue: Accounts.arbitraryAccount }, - ]; - await checkVariables([token], [result]); - }); - - it("ept002 should updateMasterMinter while paused", async function () { - await token.pause({ from: Accounts.pauserAccount }); - await token.updateMasterMinter(Accounts.arbitraryAccount, { - from: Accounts.tokenOwnerAccount, - }); - var result = [ - { variable: "masterMinter", expectedValue: Accounts.arbitraryAccount }, - { variable: "paused", expectedValue: true }, - ]; - await checkVariables([token], [result]); - }); - - it("ept003 should updateBlacklister while paused", async function () { - await token.pause({ from: Accounts.pauserAccount }); - await token.updateBlacklister(Accounts.arbitraryAccount, { - from: Accounts.tokenOwnerAccount, - }); - var result = [ - { variable: "blacklister", expectedValue: Accounts.arbitraryAccount }, - { variable: "paused", expectedValue: true }, - ]; - await checkVariables([token], [result]); - }); - - it("ept004 should updatePauser while paused", async function () { - await token.pause({ from: Accounts.pauserAccount }); - await token.updatePauser(Accounts.arbitraryAccount, { - from: Accounts.tokenOwnerAccount, - }); - var result = [ - { variable: "pauser", expectedValue: Accounts.arbitraryAccount }, - { variable: "paused", expectedValue: true }, - ]; - await checkVariables([token], [result]); - }); - - it("ept005 should transferOwnership while paused", async function () { - await token.pause({ from: Accounts.pauserAccount }); - await token.transferOwnership(Accounts.arbitraryAccount, { - from: Accounts.tokenOwnerAccount, - }); - var result = [ - { variable: "tokenOwner", expectedValue: Accounts.arbitraryAccount }, - { variable: "paused", expectedValue: true }, - ]; - await checkVariables([token], [result]); - }); - - it("ept006 should removeMinter while paused", async function () { - await token.configureMinter(Accounts.minterAccount, amount, { - from: Accounts.masterMinterAccount, - }); - await token.pause({ from: Accounts.pauserAccount }); - var isAMinter = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount), - }, - { variable: "paused", expectedValue: true }, - ]; - await checkVariables([token], [isAMinter]); - - await token.removeMinter(Accounts.minterAccount, { - from: Accounts.masterMinterAccount, - }); - var notAMinter = [ - { variable: "isAccountMinter.minterAccount", expectedValue: false }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(0), - }, - { variable: "paused", expectedValue: true }, - ]; - await checkVariables([token], [notAMinter]); - }); - - it("ept008 should upgrade while paused", async function () { - var newRawToken = await UpgradedFiatToken.new(); - await token.pause({ from: Accounts.pauserAccount }); - var tokenConfig = await upgradeTo(proxy, newRawToken); - var newProxiedToken = tokenConfig.token; - var newToken = newProxiedToken; - - var newToken_result = [ - { variable: "paused", expectedValue: true }, - { variable: "proxiedTokenAddress", expectedValue: newRawToken.address }, - ]; - await checkVariables([newToken], [newToken_result]); - }); - - // Blacklisted - - it("ept013 should changeAdmin when msg.sender blacklisted", async function () { - await token.blacklist(Accounts.proxyOwnerAccount, { - from: Accounts.blacklisterAccount, - }); - await proxy.changeAdmin(Accounts.arbitraryAccount, { - from: Accounts.proxyOwnerAccount, - }); - var result = [ - { - variable: "isAccountBlacklisted.proxyOwnerAccount", - expectedValue: true, - }, - { variable: "proxyOwner", expectedValue: Accounts.arbitraryAccount }, - ]; - await checkVariables([token], [result]); - }); - - it("ept014 should updateMasterMinter when msg.sender blacklisted", async function () { - await token.blacklist(Accounts.tokenOwnerAccount, { - from: Accounts.blacklisterAccount, - }); - await token.updateMasterMinter(Accounts.arbitraryAccount, { - from: Accounts.tokenOwnerAccount, - }); - var setup = [ - { variable: "masterMinter", expectedValue: Accounts.arbitraryAccount }, - { - variable: "isAccountBlacklisted.tokenOwnerAccount", - expectedValue: true, - }, - ]; - await checkVariables([token], [setup]); - }); - - it("ept015 should updateBlacklister when msg.sender blacklisted", async function () { - await token.blacklist(Accounts.tokenOwnerAccount, { - from: Accounts.blacklisterAccount, - }); - await token.updateBlacklister(Accounts.arbitraryAccount, { - from: Accounts.tokenOwnerAccount, - }); - var setup = [ - { variable: "blacklister", expectedValue: Accounts.arbitraryAccount }, - { - variable: "isAccountBlacklisted.tokenOwnerAccount", - expectedValue: true, - }, - ]; - await checkVariables([token], [setup]); - }); - - it("ept016 should updatePauser when msg.sender blacklisted", async function () { - await token.blacklist(Accounts.tokenOwnerAccount, { - from: Accounts.blacklisterAccount, - }); - await token.updatePauser(Accounts.arbitraryAccount, { - from: Accounts.tokenOwnerAccount, - }); - var setup = [ - { variable: "pauser", expectedValue: Accounts.arbitraryAccount }, - { - variable: "isAccountBlacklisted.tokenOwnerAccount", - expectedValue: true, - }, - ]; - await checkVariables([token], [setup]); - }); - - it("ept017 should transferOwnership when msg.sender blacklisted", async function () { - await token.blacklist(Accounts.tokenOwnerAccount, { - from: Accounts.blacklisterAccount, - }); - await token.transferOwnership(Accounts.arbitraryAccount, { - from: Accounts.tokenOwnerAccount, - }); - var setup = [ - { variable: "tokenOwner", expectedValue: Accounts.arbitraryAccount }, - { - variable: "isAccountBlacklisted.tokenOwnerAccount", - expectedValue: true, - }, - ]; - await checkVariables([token], [setup]); - }); - - it("ept018 should pause when msg.sender blacklisted", async function () { - await token.blacklist(Accounts.pauserAccount, { - from: Accounts.blacklisterAccount, - }); - await token.pause({ from: Accounts.pauserAccount }); - var setup = [ - { variable: "paused", expectedValue: true }, - { variable: "isAccountBlacklisted.pauserAccount", expectedValue: true }, - ]; - await checkVariables([token], [setup]); - }); - - it("ept019 should unpause when msg.sender blacklisted", async function () { - await token.pause({ from: Accounts.pauserAccount }); - var setup = [{ variable: "paused", expectedValue: true }]; - await checkVariables([token], [setup]); - - await token.blacklist(Accounts.pauserAccount, { - from: Accounts.blacklisterAccount, - }); - await token.unpause({ from: Accounts.pauserAccount }); - setup = [ - { variable: "isAccountBlacklisted.pauserAccount", expectedValue: true }, - ]; - await checkVariables([token], [setup]); - }); - - it("ept020 should blacklist when msg.sender blacklisted", async function () { - await token.blacklist(Accounts.blacklisterAccount, { - from: Accounts.blacklisterAccount, - }); - await token.blacklist(Accounts.arbitraryAccount, { - from: Accounts.blacklisterAccount, - }); - var setup = [ - { - variable: "isAccountBlacklisted.blacklisterAccount", - expectedValue: true, - }, - { - variable: "isAccountBlacklisted.arbitraryAccount", - expectedValue: true, - }, - ]; - await checkVariables([token], [setup]); - }); - - it("ept021 should unBlacklist when msg.sender blacklisted", async function () { - await token.blacklist(Accounts.blacklisterAccount, { - from: Accounts.blacklisterAccount, - }); - var setup = [ - { - variable: "isAccountBlacklisted.blacklisterAccount", - expectedValue: true, - }, - ]; - await checkVariables([token], [setup]); - - await token.unBlacklist(Accounts.blacklisterAccount, { - from: Accounts.blacklisterAccount, - }); - await checkVariables([token], [[]]); - }); - - it("ept022 should upgrade when msg.sender blacklisted", async function () { - 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.proxyOwnerAccount", - expectedValue: true, - }, - ]; - await checkVariables([newToken], [newToken_result]); - }); - - it("ept023 should upgrade to blacklisted address", async function () { - var newRawToken = await UpgradedFiatToken.new(); - - await token.blacklist(newRawToken.address, { - from: Accounts.blacklisterAccount, - }); - var tokenConfig = await upgradeTo(proxy, newRawToken); - var newProxiedToken = tokenConfig.token; - var newToken = newProxiedToken; - - var newToken_result = [ - { variable: "proxiedTokenAddress", expectedValue: newRawToken.address }, - ]; - - assert(await newToken.isBlacklisted(newRawToken.address)); - await checkVariables([newToken], [newToken_result]); - }); - - it("ept024 should blacklist a blacklisted address", async function () { - await token.blacklist(Accounts.arbitraryAccount, { - from: Accounts.blacklisterAccount, - }); - var setup = [ - { - variable: "isAccountBlacklisted.arbitraryAccount", - expectedValue: true, - }, - ]; - await token.blacklist(Accounts.arbitraryAccount, { - from: Accounts.blacklisterAccount, - }); - await checkVariables([token], [setup]); - }); - - it("ept025 should changeAdmin to blacklisted address", async function () { - await token.blacklist(Accounts.arbitraryAccount, { - from: Accounts.blacklisterAccount, - }); - await proxy.changeAdmin(Accounts.arbitraryAccount, { - from: Accounts.proxyOwnerAccount, - }); - var result = [ - { - variable: "isAccountBlacklisted.arbitraryAccount", - expectedValue: true, - }, - { variable: "proxyOwner", expectedValue: Accounts.arbitraryAccount }, - ]; - await checkVariables([token], [result]); - }); - - it("ept026 should updateMasterMinter to blacklisted address", async function () { - await token.blacklist(Accounts.arbitraryAccount, { - from: Accounts.blacklisterAccount, - }); - await token.updateMasterMinter(Accounts.arbitraryAccount, { - from: Accounts.tokenOwnerAccount, - }); - var setup = [ - { variable: "masterMinter", expectedValue: Accounts.arbitraryAccount }, - { - variable: "isAccountBlacklisted.arbitraryAccount", - expectedValue: true, - }, - ]; - await checkVariables([token], [setup]); - }); - - it("ept027 should updateBlacklister to blacklisted address", async function () { - await token.blacklist(Accounts.arbitraryAccount, { - from: Accounts.blacklisterAccount, - }); - await token.updateBlacklister(Accounts.arbitraryAccount, { - from: Accounts.tokenOwnerAccount, - }); - var setup = [ - { variable: "blacklister", expectedValue: Accounts.arbitraryAccount }, - { - variable: "isAccountBlacklisted.arbitraryAccount", - expectedValue: true, - }, - ]; - await checkVariables([token], [setup]); - }); - - it("ept028 should updatePauser to blacklisted address", async function () { - await token.blacklist(Accounts.arbitraryAccount, { - from: Accounts.blacklisterAccount, - }); - await token.updatePauser(Accounts.arbitraryAccount, { - from: Accounts.tokenOwnerAccount, - }); - var setup = [ - { variable: "pauser", expectedValue: Accounts.arbitraryAccount }, - { - variable: "isAccountBlacklisted.arbitraryAccount", - expectedValue: true, - }, - ]; - await checkVariables([token], [setup]); - }); - - it("ept029 should transferOwnership to blacklisted address", async function () { - await token.blacklist(Accounts.arbitraryAccount, { - from: Accounts.blacklisterAccount, - }); - await token.transferOwnership(Accounts.arbitraryAccount, { - from: Accounts.tokenOwnerAccount, - }); - var setup = [ - { variable: "tokenOwner", expectedValue: Accounts.arbitraryAccount }, - { - variable: "isAccountBlacklisted.arbitraryAccount", - expectedValue: true, - }, - ]; - await checkVariables([token], [setup]); - }); - - it("ept030 should configureMinter when masterMinter is blacklisted", async function () { - await token.blacklist(Accounts.masterMinterAccount, { - from: Accounts.blacklisterAccount, - }); - await token.configureMinter(Accounts.minterAccount, amount, { - from: Accounts.masterMinterAccount, - }); - var result = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount), - }, - { - variable: "isAccountBlacklisted.masterMinterAccount", - expectedValue: true, - }, - ]; - await checkVariables([token], [result]); - }); - - it("ept032 should configureMinter when minter is blacklisted", async function () { - await token.blacklist(Accounts.minterAccount, { - from: Accounts.blacklisterAccount, - }); - await token.configureMinter(Accounts.minterAccount, amount, { - from: Accounts.masterMinterAccount, - }); - var result = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount), - }, - { variable: "isAccountBlacklisted.minterAccount", expectedValue: true }, - ]; - await checkVariables([token], [result]); - }); - - it("ept033 should removeMinter when masterMinter is blacklisted", async function () { - await token.configureMinter(Accounts.minterAccount, amount, { - from: Accounts.masterMinterAccount, - }); - await token.blacklist(Accounts.masterMinterAccount, { - from: Accounts.blacklisterAccount, - }); - var customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount), - }, - { - variable: "isAccountBlacklisted.masterMinterAccount", - expectedValue: true, - }, - ]; - await checkVariables([token], [customVars]); - - await token.removeMinter(Accounts.minterAccount, { - from: Accounts.masterMinterAccount, - }); - customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: false }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(0), - }, - { - variable: "isAccountBlacklisted.masterMinterAccount", - expectedValue: true, - }, - ]; - await checkVariables([token], [customVars]); - }); - - it("ept034 should removeMinter when minter is blacklisted", async function () { - await token.configureMinter(Accounts.minterAccount, amount, { - from: Accounts.masterMinterAccount, - }); - await token.blacklist(Accounts.minterAccount, { - from: Accounts.blacklisterAccount, - }); - var customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount), - }, - { variable: "isAccountBlacklisted.minterAccount", expectedValue: true }, - ]; - await checkVariables([token], [customVars]); - - await token.removeMinter(Accounts.minterAccount, { - from: Accounts.masterMinterAccount, - }); - customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: false }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(0), - }, - { variable: "isAccountBlacklisted.minterAccount", expectedValue: true }, - ]; - await checkVariables([token], [customVars]); - }); - - it("ept035 should unBlacklist while contract is paused", async function () { - await token.pause({ from: Accounts.pauserAccount }); - await token.blacklist(Accounts.arbitraryAccount, { - from: Accounts.blacklisterAccount, - }); - var customVars = [ - { - variable: "isAccountBlacklisted.arbitraryAccount", - expectedValue: true, - }, - { variable: "paused", expectedValue: true }, - ]; - await checkVariables([token], [customVars]); - - await token.unBlacklist(Accounts.arbitraryAccount, { - from: Accounts.blacklisterAccount, - }); - customVars = [{ variable: "paused", expectedValue: true }]; - await checkVariables([token], [customVars]); - }); - - it("ept036 should blacklist while contract is paused", async function () { - await token.pause({ from: Accounts.pauserAccount }); - var customVars = [{ variable: "paused", expectedValue: true }]; - await checkVariables([token], [customVars]); - - await token.blacklist(Accounts.arbitraryAccount, { - from: Accounts.blacklisterAccount, - }); - customVars = [ - { - variable: "isAccountBlacklisted.arbitraryAccount", - expectedValue: true, - }, - { variable: "paused", expectedValue: true }, - ]; - await checkVariables([token], [customVars]); - }); - - it("ept037 should pause while contract is paused", async function () { - await token.pause({ from: Accounts.pauserAccount }); - var customVars = [{ variable: "paused", expectedValue: true }]; - await checkVariables([token], [customVars]); - - await token.pause({ from: Accounts.pauserAccount }); - customVars = [{ variable: "paused", expectedValue: true }]; - await checkVariables([token], [customVars]); - }); -} - -var testWrapper = require("./../TestWrapper"); -testWrapper.execute("FiatToken_ExtendedPositiveTests", run_tests); - -module.exports = { - run_tests: run_tests, -}; diff --git a/test/AccountUtils.js b/test/minting/AccountUtils.js similarity index 76% rename from test/AccountUtils.js rename to test/minting/AccountUtils.js index 36601a306..a2c42b858 100644 --- a/test/AccountUtils.js +++ b/test/minting/AccountUtils.js @@ -1,13 +1,14 @@ // set to true to enable verbose logging in the tests -var debugLogging = false; -var assertDiff = require("assert-diff"); +const debugLogging = false; +const assertDiff = require("assert-diff"); assertDiff.options.strict = true; -var Q = require("q"); -var clone = require("clone"); +const Q = require("q"); +const clone = require("clone"); +const util = require("util"); // named list of all accounts -var Accounts = { +const Accounts = { deployerAccount: "0x90F8BF6A479F320EAD074411A4B0E7944EA8C9C1", // accounts[0] arbitraryAccount: "0xFFCF8FDEE72AC11B5C542428B35EEF5769C409F0", // accounts[1] tokenOwnerAccount: "0xE11BA2B4D45EAED5996CD0823791E0C93114882D", // Accounts.arbitraryAccount @@ -22,7 +23,7 @@ var Accounts = { }; // named list of known private keys -var AccountPrivateKeys = { +const AccountPrivateKeys = { deployerPrivateKey: "4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b1d", // accounts[0] arbitraryPrivateKey: @@ -56,42 +57,23 @@ var AccountPrivateKeys = { }; function addressEquals(address1, address2) { - if (address1.toUpperCase() == address2.toUpperCase()) { + if (address1.toUpperCase() === address2.toUpperCase()) { return true; } else { assert.isFalse("expect " + address1 + " to equal " + address2); } } -function addressNotEquals(address1, address2) { - if (address1.toUpperCase() != address2.toUpperCase()) { - return true; - } else { - assert.isFalse("expect " + address1 + " to not equal " + address2); - } -} - // Returns an object with all named account values set to the default value // e.g sets {owner: 0, minter: 0,...} function setAccountDefault(accounts, defaultValue) { - var result = {}; - for (var accountName in accounts) { + const result = {}; + for (const accountName in accounts) { result[accountName] = defaultValue; } return result; } -// Returns an object with all named account values set to -// an object containing all named account values set to default -// e.g. sets {owner: setAccountDefault(accounts, 0), minter: setAccountDefault(accounts, 0),...} -function recursiveSetAccountDefault(accounts, value) { - var result = {}; - for (var account in accounts) { - result[account] = setAccountDefault(accounts, value); - } - return result; -} - // return an expectedState that combines customState with the emptyState function buildExpectedPartialState( emptyState, @@ -99,17 +81,17 @@ function buildExpectedPartialState( ignoreExtraCustomVars ) { // for each item in customVars, set the item in expectedState - var expectedState = clone(emptyState); + const expectedState = clone(emptyState); - for (var variableName in customState) { + for (const variableName in customState) { // do I ignore extra values - if (expectedState.hasOwnProperty(variableName)) { - var variableValue = customState[variableName]; + if (Object.prototype.hasOwnProperty.call(expectedState, variableName)) { + const variableValue = customState[variableName]; if (isLiteral(variableValue)) { expectedState[variableName] = variableValue; } else { // assume variableValue is a mapping evaluated on 1 or more accounts - for (var accountName in variableValue) { + for (const accountName in variableValue) { expectedState[variableName][accountName] = variableValue[accountName]; } } @@ -139,13 +121,13 @@ async function checkState( ignoreExtraCustomVars ) { // Iterate over array of tokens. - var numTokens = _tokens.length; + const numTokens = _tokens.length; assert.equal(numTokens, _customVars.length); - var n; + let n; for (n = 0; n < numTokens; n++) { - var token = _tokens[n]; - var customVars = _customVars[n]; - let expectedState = buildExpectedPartialState( + const token = _tokens[n]; + const customVars = _customVars[n]; + const expectedState = buildExpectedPartialState( emptyState, customVars, ignoreExtraCustomVars @@ -157,7 +139,7 @@ async function checkState( ); } - let actualState = await getActualState(token, accounts); + const actualState = await getActualState(token, accounts); assertDiff.deepEqual( actualState, expectedState, @@ -173,15 +155,15 @@ async function checkState( // E.g. {owner: value1, minter: value2} async function getAccountState(accountQuery, accounts) { // create an array of promises - var promises = []; - for (var account in accounts) { - var promiseQuery = accountQuery(Accounts[account]); + const promises = []; + for (const account in accounts) { + const promiseQuery = accountQuery(Accounts[account]); promises.push(promiseQuery); } - var results = await Q.allSettled(promises); - var state = {}; - var u = 0; - for (var account in accounts) { + const results = await Q.allSettled(promises); + const state = {}; + let u = 0; + for (const account in accounts) { state[account] = results[u].value; ++u; } @@ -189,7 +171,7 @@ async function getAccountState(accountQuery, accounts) { } function isLiteral(object) { - if (typeof object == "object" && !object._isBigNumber) return false; + if (typeof object === "object" && !object._isBigNumber) return false; return true; } @@ -197,10 +179,7 @@ module.exports = { Accounts: Accounts, AccountPrivateKeys: AccountPrivateKeys, setAccountDefault: setAccountDefault, - recursiveSetAccountDefault: recursiveSetAccountDefault, - buildExpectedPartialState: buildExpectedPartialState, checkState: checkState, getAccountState: getAccountState, addressEquals: addressEquals, - addressNotEquals: addressNotEquals, }; diff --git a/test/ControllerTestUtils.js b/test/minting/ControllerTestUtils.js similarity index 69% rename from test/ControllerTestUtils.js rename to test/minting/ControllerTestUtils.js index 88a789710..bdc746152 100644 --- a/test/ControllerTestUtils.js +++ b/test/minting/ControllerTestUtils.js @@ -1,14 +1,10 @@ -var Q = require("q"); +const Q = require("q"); -// set to true to enable verbose logging in the tests -var debugLogging = false; - -var Controller = artifacts.require("./../minting/Controller"); -var AccountUtils = require("./AccountUtils.js"); -var Accounts = AccountUtils.Accounts; -var setAccountDefault = AccountUtils.setAccountDefault; -var checkState = AccountUtils.checkState; -var getAccountState = AccountUtils.getAccountState; +const AccountUtils = require("./AccountUtils.js"); +const Accounts = AccountUtils.Accounts; +const setAccountDefault = AccountUtils.setAccountDefault; +const checkState = AccountUtils.checkState; +const getAccountState = AccountUtils.getAccountState; function ControllerState(owner, controllers) { this.owner = owner; @@ -19,7 +15,7 @@ function ControllerState(owner, controllers) { } // Default state of Controller when it is deployed -var controllerEmptyState = new ControllerState( +const controllerEmptyState = new ControllerState( Accounts.mintOwnerAccount, setAccountDefault(Accounts, "0x0000000000000000000000000000000000000000") ); @@ -50,5 +46,4 @@ async function getActualControllerState(controllerContract, accounts) { module.exports = { controllerEmptyState: controllerEmptyState, checkControllerState: checkControllerState, - getActualControllerState: getActualControllerState, }; diff --git a/test/minting2/MintControllerTests.js b/test/minting/MintControllerTests.js similarity index 85% rename from test/minting2/MintControllerTests.js rename to test/minting/MintControllerTests.js index 5f4bcd7fe..c3a04db17 100644 --- a/test/minting2/MintControllerTests.js +++ b/test/minting/MintControllerTests.js @@ -1,23 +1,28 @@ -var MintController = artifacts.require("minting/MintController"); +const MintController = artifacts.require("minting/MintController"); -var tokenUtils = require("./../TokenTestUtils.js"); -var newBigNumber = tokenUtils.newBigNumber; -var checkMINTp0 = tokenUtils.checkMINTp0; -var expectRevert = tokenUtils.expectRevert; -var expectError = tokenUtils.expectError; -var bigZero = tokenUtils.bigZero; +const tokenUtils = require("../v1/TokenTestUtils.js"); +const newBigNumber = tokenUtils.newBigNumber; +const checkMINTp0 = tokenUtils.checkMINTp0; +const expectRevert = tokenUtils.expectRevert; +const expectError = tokenUtils.expectError; +const bigZero = tokenUtils.bigZero; -var clone = require("clone"); +const clone = require("clone"); -var mintUtils = require("./../MintControllerUtils.js"); -var AccountUtils = require("./../AccountUtils.js"); -var Accounts = AccountUtils.Accounts; -var MintControllerState = AccountUtils.MintControllerState; -var initializeTokenWithProxyAndMintController = +const mintUtils = require("./MintControllerUtils.js"); +const AccountUtils = require("./AccountUtils.js"); +const Accounts = AccountUtils.Accounts; +const initializeTokenWithProxyAndMintController = mintUtils.initializeTokenWithProxyAndMintController; -var checkMintControllerState = mintUtils.checkMintControllerState; -async function run_tests(newToken, accounts) { +let rawToken; +let tokenConfig; +let token; +let mintController; +let expectedMintControllerState; +let expectedTokenState; + +async function run_tests(newToken) { beforeEach("Make fresh token contract", async function () { rawToken = await newToken(); tokenConfig = await initializeTokenWithProxyAndMintController( @@ -33,7 +38,7 @@ async function run_tests(newToken, accounts) { }); it("should mint through mint controller", async function () { - var amount = 5000; + const amount = 5000; await mintController.configureController( Accounts.controller1Account, Accounts.minterAccount, @@ -42,7 +47,7 @@ async function run_tests(newToken, accounts) { await mintController.configureMinter(amount, { from: Accounts.controller1Account, }); - expectedMintControllerState.controllers["controller1Account"] = + expectedMintControllerState.controllers.controller1Account = Accounts.minterAccount; await token.mint(Accounts.arbitraryAccount, amount, { @@ -80,13 +85,12 @@ async function run_tests(newToken, accounts) { }); it("remove controller", async function () { - var amount = 5000; await mintController.configureController( Accounts.controller1Account, Accounts.minterAccount, { from: Accounts.mintOwnerAccount } ); - expectedMintControllerState.controllers["controller1Account"] = + expectedMintControllerState.controllers.controller1Account = Accounts.minterAccount; await checkMINTp0( [token, mintController], @@ -96,7 +100,7 @@ async function run_tests(newToken, accounts) { await mintController.removeController(Accounts.controller1Account, { from: Accounts.mintOwnerAccount, }); - expectedMintControllerState.controllers["controller1Account"] = bigZero; + expectedMintControllerState.controllers.controller1Account = bigZero; await checkMINTp0( [token, mintController], [expectedTokenState, expectedMintControllerState] @@ -132,7 +136,7 @@ async function run_tests(newToken, accounts) { it("remove minter", async function () { // create a minter - var amount = 500; + const amount = 500; await mintController.configureController( Accounts.controller1Account, Accounts.minterAccount, @@ -141,7 +145,7 @@ async function run_tests(newToken, accounts) { await mintController.configureMinter(amount, { from: Accounts.controller1Account, }); - expectedMintControllerState.controllers["controller1Account"] = + expectedMintControllerState.controllers.controller1Account = Accounts.minterAccount; expectedTokenState.push( { variable: "isAccountMinter.minterAccount", expectedValue: true }, @@ -182,7 +186,7 @@ async function run_tests(newToken, accounts) { it("increment minter allowance", async function () { // configure controller & minter - var amount = 500; + const amount = 500; await mintController.configureController( Accounts.controller1Account, Accounts.minterAccount, @@ -191,7 +195,7 @@ async function run_tests(newToken, accounts) { await mintController.configureMinter(amount, { from: Accounts.controller1Account, }); - expectedMintControllerState.controllers["controller1Account"] = + expectedMintControllerState.controllers.controller1Account = Accounts.minterAccount; expectedTokenState.push( { variable: "isAccountMinter.minterAccount", expectedValue: true }, @@ -234,13 +238,13 @@ async function run_tests(newToken, accounts) { it("only active minters can have allowance incremented", async function () { // configure controller but not minter - var amount = 500; + const amount = 500; await mintController.configureController( Accounts.controller1Account, Accounts.minterAccount, { from: Accounts.mintOwnerAccount } ); - expectedMintControllerState.controllers["controller1Account"] = + expectedMintControllerState.controllers.controller1Account = Accounts.minterAccount; await checkMINTp0( [token, mintController], @@ -258,7 +262,7 @@ async function run_tests(newToken, accounts) { it("decrement minter allowance", async function () { // configure controller & minter - var amount = 500; + const amount = 500; await mintController.configureController( Accounts.controller1Account, Accounts.minterAccount, @@ -267,7 +271,7 @@ async function run_tests(newToken, accounts) { await mintController.configureMinter(amount, { from: Accounts.controller1Account, }); - expectedMintControllerState.controllers["controller1Account"] = + expectedMintControllerState.controllers.controller1Account = Accounts.minterAccount; expectedTokenState.push( { variable: "isAccountMinter.minterAccount", expectedValue: true }, @@ -307,13 +311,13 @@ async function run_tests(newToken, accounts) { it("only active minters can have allowance decremented", async function () { // configure controller but not minter - var amount = 500; + const amount = 500; await mintController.configureController( Accounts.controller1Account, Accounts.minterAccount, { from: Accounts.mintOwnerAccount } ); - expectedMintControllerState.controllers["controller1Account"] = + expectedMintControllerState.controllers.controller1Account = Accounts.minterAccount; await checkMINTp0( [token, mintController], @@ -330,8 +334,8 @@ async function run_tests(newToken, accounts) { }); } -var testWrapper = require("../TestWrapper"); -testWrapper.execute("MintController_Tests", run_tests); +const wrapTests = require("../v1/helpers/wrapTests"); +wrapTests("MintController_Tests MintController", run_tests); module.exports = { run_tests: run_tests, diff --git a/test/MintControllerUtils.js b/test/minting/MintControllerUtils.js similarity index 66% rename from test/MintControllerUtils.js rename to test/minting/MintControllerUtils.js index b669e3bd0..44430ade6 100644 --- a/test/MintControllerUtils.js +++ b/test/minting/MintControllerUtils.js @@ -1,15 +1,13 @@ -var tokenUtils = require("./TokenTestUtils.js"); -var bigZero = tokenUtils.bigZero; -var initializeTokenWithProxy = tokenUtils.initializeTokenWithProxy; +const tokenUtils = require("../v1/TokenTestUtils.js"); +const bigZero = tokenUtils.bigZero; +const initializeTokenWithProxy = tokenUtils.initializeTokenWithProxy; -var MintController = artifacts.require("./minting/MintController"); -var AccountUtils = require("./AccountUtils.js"); -var Accounts = AccountUtils.Accounts; -var checkState = AccountUtils.checkState; -var getAccountState = AccountUtils.getAccountState; +const AccountUtils = require("./AccountUtils.js"); +const Accounts = AccountUtils.Accounts; +const checkState = AccountUtils.checkState; -var ControllerUtils = require("./ControllerTestUtils.js"); -var checkControllerState = ControllerUtils.checkControllerState; +const ControllerUtils = require("./ControllerTestUtils.js"); +const checkControllerState = ControllerUtils.checkControllerState; function MintControllerState(owner, controllers, minterManager) { this.owner = owner; @@ -21,8 +19,7 @@ function MintControllerState(owner, controllers, minterManager) { } // Default state of MintController when it is deployed -var mintControllerEmptyState = new MintControllerState(null, {}, bigZero); - +const mintControllerEmptyState = new MintControllerState(null, {}, bigZero); // Checks the state of the mintController contract async function checkMintControllerState(mintController, customState) { await checkControllerState(mintController, customState); @@ -38,8 +35,8 @@ async function checkMintControllerState(mintController, customState) { // Gets the actual state of the mintController contract. // Evaluates all mappings on the provided accounts. -async function getActualMintControllerState(mintController, accounts) { - var minterManager = await mintController.minterManager.call(); +async function getActualMintControllerState(mintController) { + const minterManager = await mintController.minterManager.call(); return new MintControllerState(null, {}, minterManager); } @@ -49,15 +46,15 @@ async function initializeTokenWithProxyAndMintController( rawToken, MintControllerArtifact ) { - var tokenConfig = await initializeTokenWithProxy(rawToken); - var mintController = await MintControllerArtifact.new( + const tokenConfig = await initializeTokenWithProxy(rawToken); + const mintController = await MintControllerArtifact.new( tokenConfig.token.address, { from: Accounts.mintOwnerAccount } ); await tokenConfig.token.updateMasterMinter(mintController.address, { from: Accounts.tokenOwnerAccount, }); - var tokenConfigWithMinter = { + const tokenConfigWithMinter = { proxy: tokenConfig.proxy, token: tokenConfig.token, mintController: mintController, diff --git a/test/minting/MintP0_ArgumentTests.js b/test/minting/MintP0_ArgumentTests.js index 498db0598..7bce73e2b 100644 --- a/test/minting/MintP0_ArgumentTests.js +++ b/test/minting/MintP0_ArgumentTests.js @@ -1,32 +1,25 @@ -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 tokenUtils = require("../TokenTestUtils.js"); -var newBigNumber = tokenUtils.newBigNumber; -var checkMINTp0 = tokenUtils.checkMINTp0; -var expectRevert = tokenUtils.expectRevert; -var expectJump = tokenUtils.expectJump; -var expectError = tokenUtils.expectError; -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 addressEquals = AccountUtils.addressEquals; -var initializeTokenWithProxyAndMintController = +const MintController = artifacts.require("minting/MintController"); +const MasterMinter = artifacts.require("minting/MasterMinter"); +const FiatToken = artifacts.require("FiatTokenV1"); + +const tokenUtils = require("../v1/TokenTestUtils"); +const newBigNumber = tokenUtils.newBigNumber; +const checkMINTp0 = tokenUtils.checkMINTp0; +const expectRevert = tokenUtils.expectRevert; +const expectError = tokenUtils.expectError; +const bigZero = tokenUtils.bigZero; + +const clone = require("clone"); + +const mintUtils = require("./MintControllerUtils.js"); +const AccountUtils = require("./AccountUtils.js"); +const Accounts = AccountUtils.Accounts; +const addressEquals = AccountUtils.addressEquals; +const initializeTokenWithProxyAndMintController = mintUtils.initializeTokenWithProxyAndMintController; -var checkMintControllerState = mintUtils.checkMintControllerState; -var zeroAddress = "0x0000000000000000000000000000000000000000"; -var maxAmount = +const zeroAddress = "0x0000000000000000000000000000000000000000"; +const maxAmount = "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"; async function run_tests_MintController(newToken, accounts) { @@ -37,7 +30,14 @@ async function run_tests_MasterMinter(newToken, accounts) { run_MINT_tests(newToken, MasterMinter, accounts); } -async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { +let rawToken; +let tokenConfig; +let token; +let mintController; +let expectedMintControllerState; +let expectedTokenState; + +async function run_MINT_tests(newToken, MintControllerArtifact) { beforeEach("Make fresh token contract", async function () { rawToken = await newToken(); tokenConfig = await initializeTokenWithProxyAndMintController( @@ -95,7 +95,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { Accounts.minterAccount, { from: Accounts.mintOwnerAccount } ); - expectedMintControllerState.controllers["mintOwnerAccount"] = + expectedMintControllerState.controllers.mintOwnerAccount = Accounts.minterAccount; await checkMINTp0( [token, mintController], @@ -109,7 +109,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { Accounts.minterAccount, { from: Accounts.mintOwnerAccount } ); - expectedMintControllerState.controllers["minterAccount"] = + expectedMintControllerState.controllers.minterAccount = Accounts.minterAccount; await checkMINTp0( [token, mintController], @@ -176,7 +176,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { }); it("arg011 setMinterManager(newToken) works", async function () { - var newToken = await FiatToken.new(); + const newToken = await FiatToken.new(); await mintController.setMinterManager(newToken.address, { from: Accounts.mintOwnerAccount, }); @@ -197,7 +197,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { from: Accounts.controller1Account, }); - expectedMintControllerState.controllers["controller1Account"] = + expectedMintControllerState.controllers.controller1Account = Accounts.minterAccount; expectedTokenState.push( { variable: "isAccountMinter.minterAccount", expectedValue: true }, @@ -213,7 +213,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { }); it("arg013 configureMinter(oldAllowance) makes no changes", async function () { - var oldAllowance = 64738; + const oldAllowance = 64738; await mintController.configureController( Accounts.controller1Account, Accounts.minterAccount, @@ -226,7 +226,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { from: Accounts.controller1Account, }); - expectedMintControllerState.controllers["controller1Account"] = + expectedMintControllerState.controllers.controller1Account = Accounts.minterAccount; expectedTokenState.push( { variable: "isAccountMinter.minterAccount", expectedValue: true }, @@ -251,7 +251,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { from: Accounts.controller1Account, }); - expectedMintControllerState.controllers["controller1Account"] = + expectedMintControllerState.controllers.controller1Account = Accounts.minterAccount; expectedTokenState.push( { variable: "isAccountMinter.minterAccount", expectedValue: true }, @@ -281,7 +281,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { }); it("arg016 incrementMinterAllowance(oldAllowance) doubles the allowance", async function () { - var amount = 897; + const amount = 897; await mintController.configureController( Accounts.controller1Account, Accounts.minterAccount, @@ -294,7 +294,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { from: Accounts.controller1Account, }); - expectedMintControllerState.controllers["controller1Account"] = + expectedMintControllerState.controllers.controller1Account = Accounts.minterAccount; expectedTokenState.push( { variable: "isAccountMinter.minterAccount", expectedValue: true }, @@ -310,7 +310,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { }); it("arg017 incrementMinterAllowance(MAX) throws", async function () { - var amount = 1; + const amount = 1; await mintController.configureController( Accounts.controller1Account, Accounts.minterAccount, @@ -319,7 +319,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { await mintController.configureMinter(amount, { from: Accounts.controller1Account, }); - await expectJump( + await expectRevert( mintController.incrementMinterAllowance(maxAmount, { from: Accounts.controller1Account, }) @@ -335,7 +335,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { await mintController.configureMinter(maxAmount, { from: Accounts.controller1Account, }); - await expectJump( + await expectRevert( mintController.incrementMinterAllowance(1, { from: Accounts.controller1Account, }) @@ -358,7 +358,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { Accounts.minterAccount, { from: Accounts.mintOwnerAccount } ); - var actualMinter = await mintController.getWorker( + let actualMinter = await mintController.getWorker( Accounts.controller1Account ); addressEquals(Accounts.minterAccount, actualMinter); @@ -382,7 +382,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { Accounts.minterAccount, { from: Accounts.mintOwnerAccount } ); - var actualMinter = await mintController.getWorker( + let actualMinter = await mintController.getWorker( Accounts.controller1Account ); addressEquals(Accounts.minterAccount, actualMinter); @@ -408,7 +408,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { }); it("arg022 decrementMinterAllowance(oldAllowance) sets the allowance to 0", async function () { - var amount = 897; + const amount = 897; await mintController.configureController( Accounts.controller1Account, Accounts.minterAccount, @@ -421,7 +421,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { from: Accounts.controller1Account, }); - expectedMintControllerState.controllers["controller1Account"] = + expectedMintControllerState.controllers.controller1Account = Accounts.minterAccount; expectedTokenState.push( { variable: "isAccountMinter.minterAccount", expectedValue: true }, @@ -434,7 +434,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { }); it("arg023 decrementMinterAllowance(MIN) sets the allowance to 0", async function () { - var amount = 0; + const amount = 0; await mintController.configureController( Accounts.controller1Account, Accounts.minterAccount, @@ -446,7 +446,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { await mintController.decrementMinterAllowance(1, { from: Accounts.controller1Account, }); - expectedMintControllerState.controllers["controller1Account"] = + expectedMintControllerState.controllers.controller1Account = Accounts.minterAccount; expectedTokenState.push( { variable: "isAccountMinter.minterAccount", expectedValue: true }, @@ -473,12 +473,6 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { }); } -var testWrapper = require("./../TestWrapper"); -testWrapper.execute( - "MINTp0_ArgumentTests MintController", - run_tests_MintController -); -testWrapper.execute( - "MINTp0_ArgumentTests MasterMinter", - run_tests_MasterMinter -); +const wrapTests = require("../v1/helpers/wrapTests"); +wrapTests("MINTp0_ArgumentTests MintController", run_tests_MintController); +wrapTests("MINTp0_ArgumentTests MasterMinter", run_tests_MasterMinter); diff --git a/test/minting3/MintP0_BasicTests.js b/test/minting/MintP0_BasicTests.js similarity index 83% rename from test/minting3/MintP0_BasicTests.js rename to test/minting/MintP0_BasicTests.js index 6a07d024c..d2d058ebb 100644 --- a/test/minting3/MintP0_BasicTests.js +++ b/test/minting/MintP0_BasicTests.js @@ -1,29 +1,26 @@ -var MintController = artifacts.require("minting/MintController"); -var MasterMinter = artifacts.require("minting/MasterMinter"); -var FiatToken = artifacts.require("FiatTokenV1"); - -var tokenUtils = require("../TokenTestUtils.js"); -var newBigNumber = tokenUtils.newBigNumber; -var checkMINTp0 = tokenUtils.checkMINTp0; -var expectRevert = tokenUtils.expectRevert; -var expectJump = tokenUtils.expectJump; -var expectError = tokenUtils.expectError; -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 addressEquals = AccountUtils.addressEquals; -var initializeTokenWithProxyAndMintController = +const MintController = artifacts.require("minting/MintController"); +const MasterMinter = artifacts.require("minting/MasterMinter"); +const FiatToken = artifacts.require("FiatTokenV1"); + +const tokenUtils = require("../v1/TokenTestUtils.js"); +const newBigNumber = tokenUtils.newBigNumber; +const checkMINTp0 = tokenUtils.checkMINTp0; +const expectRevert = tokenUtils.expectRevert; +const expectError = tokenUtils.expectError; +const bigZero = tokenUtils.bigZero; +const maxAmount = tokenUtils.maxAmount; + +const clone = require("clone"); + +const mintUtils = require("./MintControllerUtils.js"); +const AccountUtils = require("./AccountUtils.js"); +const Accounts = AccountUtils.Accounts; +const getAccountState = AccountUtils.getAccountState; +const addressEquals = AccountUtils.addressEquals; +const initializeTokenWithProxyAndMintController = mintUtils.initializeTokenWithProxyAndMintController; -var checkMintControllerState = mintUtils.checkMintControllerState; -var zeroAddress = "0x0000000000000000000000000000000000000000"; +const zeroAddress = "0x0000000000000000000000000000000000000000"; async function run_tests_MintController(newToken, accounts) { run_MINT_tests(newToken, MintController, accounts); @@ -33,7 +30,14 @@ async function run_tests_MasterMinter(newToken, accounts) { run_MINT_tests(newToken, MasterMinter, accounts); } -async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { +let rawToken; +let tokenConfig; +let token; +let mintController; +let expectedMintControllerState; +let expectedTokenState; + +async function run_MINT_tests(newToken, MintControllerArtifact) { beforeEach("Make fresh token contract", async function () { rawToken = await newToken(); tokenConfig = await initializeTokenWithProxyAndMintController( @@ -49,10 +53,10 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { }); it("bt001 Constructor - owner is msg.sender", async function () { - var newMintController = await MintController.new(token.address, { + const newMintController = await MintController.new(token.address, { from: Accounts.arbitraryAccount, }); - var owner = await newMintController.owner(); + const owner = await newMintController.owner(); assert.isTrue(addressEquals(owner, Accounts.arbitraryAccount)); }); @@ -81,7 +85,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { Accounts.minterAccount, { from: Accounts.mintOwnerAccount } ); - expectedMintControllerState.controllers["controller1Account"] = + expectedMintControllerState.controllers.controller1Account = Accounts.minterAccount; await checkMINTp0( [token, mintController], @@ -133,7 +137,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { Accounts.minterAccount, { from: Accounts.mintOwnerAccount } ); - expectedMintControllerState.controllers["controller1Account"] = + expectedMintControllerState.controllers.controller1Account = Accounts.minterAccount; await checkMINTp0( [token, mintController], @@ -144,7 +148,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { await mintController.removeController(Accounts.controller1Account, { from: Accounts.mintOwnerAccount, }); - expectedMintControllerState.controllers["controller1Account"] = zeroAddress; + expectedMintControllerState.controllers.controller1Account = zeroAddress; await checkMINTp0( [token, mintController], [expectedTokenState, expectedMintControllerState] @@ -158,7 +162,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { Accounts.minterAccount, { from: Accounts.mintOwnerAccount } ); - expectedMintControllerState.controllers["controller1Account"] = + expectedMintControllerState.controllers.controller1Account = Accounts.minterAccount; await checkMINTp0( [token, mintController], @@ -186,7 +190,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { it("bt011 removeMinter sets minters[M] to 0", async function () { // add a minter - var amount = 789; + const amount = 789; await mintController.configureController( Accounts.controller1Account, Accounts.minterAccount, @@ -196,7 +200,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { from: Accounts.controller1Account, }); - expectedMintControllerState.controllers["controller1Account"] = + expectedMintControllerState.controllers.controller1Account = Accounts.minterAccount; expectedTokenState.push( { variable: "isAccountMinter.minterAccount", expectedValue: true }, @@ -236,11 +240,11 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { ); // now configure minter - var amount = 6789; + const amount = 6789; await mintController.configureMinter(amount, { from: Accounts.controller1Account, }); - expectedMintControllerState.controllers["controller1Account"] = + expectedMintControllerState.controllers.controller1Account = Accounts.minterAccount; expectedTokenState.push( { variable: "isAccountMinter.minterAccount", expectedValue: true }, @@ -275,11 +279,11 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { }); // now configure minter - var amount = 6789; + const amount = 6789; await mintController.incrementMinterAllowance(amount, { from: Accounts.controller1Account, }); - expectedMintControllerState.controllers["controller1Account"] = + expectedMintControllerState.controllers.controller1Account = Accounts.minterAccount; expectedTokenState.push( { variable: "isAccountMinter.minterAccount", expectedValue: true }, @@ -322,7 +326,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { Accounts.minterAccount, { from: Accounts.mintOwnerAccount } ); - expectedMintControllerState.controllers["controller1Account"] = + expectedMintControllerState.controllers.controller1Account = Accounts.minterAccount; await checkMINTp0( [token, mintController], @@ -333,7 +337,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { await mintController.removeController(Accounts.controller1Account, { from: Accounts.mintOwnerAccount, }); - expectedMintControllerState.controllers["controller1Account"] = zeroAddress; + expectedMintControllerState.controllers.controller1Account = zeroAddress; await checkMINTp0( [token, mintController], [expectedTokenState, expectedMintControllerState] @@ -347,7 +351,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { Accounts.minterAccount, { from: Accounts.mintOwnerAccount } ); - expectedMintControllerState.controllers["controller1Account"] = + expectedMintControllerState.controllers.controller1Account = Accounts.minterAccount; await checkMINTp0( [token, mintController], @@ -362,7 +366,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { Accounts.minterAccount, { from: Accounts.mintOwnerAccount } ); - expectedMintControllerState.controllers["controller1Account"] = + expectedMintControllerState.controllers.controller1Account = Accounts.minterAccount; await checkMINTp0( [token, mintController], @@ -375,7 +379,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { Accounts.arbitraryAccount, { from: Accounts.mintOwnerAccount } ); - expectedMintControllerState.controllers["controller1Account"] = + expectedMintControllerState.controllers.controller1Account = Accounts.arbitraryAccount; await checkMINTp0( [token, mintController], @@ -389,7 +393,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { Accounts.controller1Account, { from: Accounts.mintOwnerAccount } ); - expectedMintControllerState.controllers["controller1Account"] = + expectedMintControllerState.controllers.controller1Account = Accounts.controller1Account; await checkMINTp0( [token, mintController], @@ -403,7 +407,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { Accounts.controller1Account, { from: Accounts.mintOwnerAccount } ); - expectedMintControllerState.controllers["controller1Account"] = + expectedMintControllerState.controllers.controller1Account = Accounts.mintOwnerAccount; await checkMINTp0( [token, mintController], @@ -418,7 +422,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { Accounts.minterAccount, { from: Accounts.mintOwnerAccount } ); - expectedMintControllerState.controllers["controller1Account"] = + expectedMintControllerState.controllers.controller1Account = Accounts.minterAccount; await checkMINTp0( [token, mintController], @@ -438,7 +442,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { }); it("bt024 Constructor sets minterManager", async function () { - var minterManagerAddress = await mintController.getMinterManager(); + const minterManagerAddress = await mintController.getMinterManager(); assert.isTrue(addressEquals(token.address, minterManagerAddress)); }); @@ -470,7 +474,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { }); it("bt028 setMinterManager(x) works when x = minterManager", async function () { - var minterManagerAddress = await mintController.getMinterManager(); + const minterManagerAddress = await mintController.getMinterManager(); await mintController.setMinterManager(minterManagerAddress, { from: Accounts.mintOwnerAccount, }); @@ -482,7 +486,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { it("bt030 removeMinter reverts when minterManager is 0", async function () { // set minterManager - var minterManagerAddress = await mintController.getMinterManager(); + const minterManagerAddress = await mintController.getMinterManager(); await mintController.setMinterManager(minterManagerAddress, { from: Accounts.mintOwnerAccount, }); @@ -517,7 +521,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { it("bt032 removeMinter works when minterManager is ok", async function () { // add a minter - var amount = 3; + const amount = 3; await mintController.configureController( Accounts.controller1Account, Accounts.minterAccount, @@ -527,7 +531,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { from: Accounts.controller1Account, }); - expectedMintControllerState.controllers["controller1Account"] = + expectedMintControllerState.controllers.controller1Account = Accounts.minterAccount; expectedTokenState.push( { variable: "isAccountMinter.minterAccount", expectedValue: true }, @@ -569,7 +573,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { }); it("bt035 configureMinter works when minterManager is ok", async function () { - var amount = 456; + const amount = 456; await mintController.configureController( Accounts.controller1Account, Accounts.minterAccount, @@ -578,7 +582,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { await mintController.configureMinter(amount, { from: Accounts.controller1Account, }); - expectedMintControllerState.controllers["controller1Account"] = + expectedMintControllerState.controllers.controller1Account = Accounts.minterAccount; expectedTokenState.push( { variable: "isAccountMinter.minterAccount", expectedValue: true }, @@ -623,11 +627,11 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { }); // now incrementMinterAllowance - var amount = 45; + const amount = 45; await mintController.incrementMinterAllowance(amount, { from: Accounts.controller1Account, }); - expectedMintControllerState.controllers["controller1Account"] = + expectedMintControllerState.controllers.controller1Account = Accounts.minterAccount; expectedTokenState.push( { variable: "isAccountMinter.minterAccount", expectedValue: true }, @@ -643,23 +647,23 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { }); it("bt039 configureMinter(M, amt) works when minterManager.isMinter(M)=false", async function () { - var amount = 64; + const amount = 64; await mintController.configureController( Accounts.controller1Account, Accounts.minterAccount, { from: Accounts.mintOwnerAccount } ); - var minterManager = await FiatToken.at( + const minterManager = await FiatToken.at( await mintController.getMinterManager() ); - var isMinter = await minterManager.isMinter(Accounts.minterAccount); + const isMinter = await minterManager.isMinter(Accounts.minterAccount); assert.isFalse(isMinter); await mintController.configureMinter(amount, { from: Accounts.controller1Account, }); - expectedMintControllerState.controllers["controller1Account"] = + expectedMintControllerState.controllers.controller1Account = Accounts.minterAccount; expectedTokenState.push( { variable: "isAccountMinter.minterAccount", expectedValue: true }, @@ -675,7 +679,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { }); it("bt040 configureMinter(M, amt) works when minterManager.isMinter(M)=true", async function () { - var amount = 64; + const amount = 64; await mintController.configureController( Accounts.controller1Account, Accounts.minterAccount, @@ -685,16 +689,16 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { from: Accounts.controller1Account, }); - var minterManager = await FiatToken.at( + const minterManager = await FiatToken.at( await mintController.getMinterManager() ); - var isMinter = await minterManager.isMinter(Accounts.minterAccount); + const isMinter = await minterManager.isMinter(Accounts.minterAccount); assert.isTrue(isMinter); await mintController.configureMinter(amount, { from: Accounts.controller1Account, }); - expectedMintControllerState.controllers["controller1Account"] = + expectedMintControllerState.controllers.controller1Account = Accounts.minterAccount; expectedTokenState.push( { variable: "isAccountMinter.minterAccount", expectedValue: true }, @@ -710,21 +714,20 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { }); it("bt041 removeMinter(M) works when minterManager.isMinter(M)=false", async function () { - var amount = 64; await mintController.configureController( Accounts.controller1Account, Accounts.minterAccount, { from: Accounts.mintOwnerAccount } ); - var minterManager = await FiatToken.at( + const minterManager = await FiatToken.at( await mintController.getMinterManager() ); - var isMinter = await minterManager.isMinter(Accounts.minterAccount); + const isMinter = await minterManager.isMinter(Accounts.minterAccount); assert.isFalse(isMinter); await mintController.removeMinter({ from: Accounts.controller1Account }); - expectedMintControllerState.controllers["controller1Account"] = + expectedMintControllerState.controllers.controller1Account = Accounts.minterAccount; await checkMINTp0( [token, mintController], @@ -733,7 +736,6 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { }); it("bt042 removeMinter(M) works when minterManager.isMinter(M)=true", async function () { - var amount = 64; await mintController.configureController( Accounts.controller1Account, Accounts.minterAccount, @@ -743,14 +745,14 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { from: Accounts.controller1Account, }); - var minterManager = await FiatToken.at( + const minterManager = await FiatToken.at( await mintController.getMinterManager() ); - var isMinter = await minterManager.isMinter(Accounts.minterAccount); + const isMinter = await minterManager.isMinter(Accounts.minterAccount); assert.isTrue(isMinter); await mintController.removeMinter({ from: Accounts.controller1Account }); - expectedMintControllerState.controllers["controller1Account"] = + expectedMintControllerState.controllers.controller1Account = Accounts.minterAccount; await checkMINTp0( [token, mintController], @@ -759,17 +761,17 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { }); it("bt043 incrementMinterAllowance(M, amt) reverts when minterManager.isMinter(M)=false", async function () { - var amount = 64; + const amount = 64; await mintController.configureController( Accounts.controller1Account, Accounts.minterAccount, { from: Accounts.mintOwnerAccount } ); - var minterManager = await FiatToken.at( + const minterManager = await FiatToken.at( await mintController.getMinterManager() ); - var isMinter = await minterManager.isMinter(Accounts.minterAccount); + const isMinter = await minterManager.isMinter(Accounts.minterAccount); assert.isFalse(isMinter); await expectError( @@ -778,7 +780,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { }), "Can only increment allowance for minters in minterManager" ); - expectedMintControllerState.controllers["controller1Account"] = + expectedMintControllerState.controllers.controller1Account = Accounts.minterAccount; await checkMINTp0( [token, mintController], @@ -787,7 +789,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { }); it("bt044 incrementMinterAllowance(M, amt) works when minterManager.isMinter(M)=true", async function () { - var amount = 65424; + const amount = 65424; await mintController.configureController( Accounts.controller1Account, Accounts.minterAccount, @@ -797,16 +799,16 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { from: Accounts.controller1Account, }); - var minterManager = await FiatToken.at( + const minterManager = await FiatToken.at( await mintController.getMinterManager() ); - var isMinter = await minterManager.isMinter(Accounts.minterAccount); + const isMinter = await minterManager.isMinter(Accounts.minterAccount); assert.isTrue(isMinter); await mintController.incrementMinterAllowance(amount, { from: Accounts.controller1Account, }); - expectedMintControllerState.controllers["controller1Account"] = + expectedMintControllerState.controllers.controller1Account = Accounts.minterAccount; expectedTokenState.push( { variable: "isAccountMinter.minterAccount", expectedValue: true }, @@ -822,40 +824,43 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { }); it("bt045 constructor - minterManager.isMinter[ALL] is false", async function () { - var minterManager = await FiatToken.at( + const minterManager = await FiatToken.at( await mintController.getMinterManager() ); - var isMinterMappingEval = async function (accountAddress) { + const isMinterMappingEval = async function (accountAddress) { return await minterManager.isMinter(accountAddress); }; - var isMinterResults = await getAccountState(isMinterMappingEval, Accounts); - for (var account in Accounts) { + const isMinterResults = await getAccountState( + isMinterMappingEval, + Accounts + ); + for (const account in Accounts) { assert.isFalse(isMinterResults[account]); } }); it("bt046 constructor - minterManager.minterAllowance[ALL] = 0", async function () { - var minterManager = await FiatToken.at( + const minterManager = await FiatToken.at( await mintController.getMinterManager() ); - var minterAllowanceMapping = async function (accountAddress) { + const minterAllowanceMapping = async function (accountAddress) { return await minterManager.minterAllowance(accountAddress); }; - var minterAllowanceResults = await getAccountState( + const minterAllowanceResults = await getAccountState( minterAllowanceMapping, Accounts ); - for (var account in Accounts) { + for (const account in Accounts) { assert(minterAllowanceResults[account].isZero()); } }); it("bt047 incrementMinterAllowance(M,amt) works when minterAllowance is 0", async function () { - var amount = 64; + const amount = 64; await mintController.configureController( Accounts.controller1Account, Accounts.minterAccount, @@ -865,10 +870,10 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { from: Accounts.controller1Account, }); - var minterManager = await FiatToken.at( + const minterManager = await FiatToken.at( await mintController.getMinterManager() ); - var minterAllowance = await minterManager.minterAllowance( + const minterAllowance = await minterManager.minterAllowance( Accounts.minterAccount ); assert(minterAllowance.isZero()); @@ -876,7 +881,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { await mintController.incrementMinterAllowance(amount, { from: Accounts.controller1Account, }); - expectedMintControllerState.controllers["controller1Account"] = + expectedMintControllerState.controllers.controller1Account = Accounts.minterAccount; expectedTokenState.push( { variable: "isAccountMinter.minterAccount", expectedValue: true }, @@ -892,8 +897,8 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { }); it("bt048 incrementMinterAllowance(M, amt) works when minterAllowance > 0", async function () { - var initialAmount = 987341; - var incrementAmount = 64; + const initialAmount = 987341; + const incrementAmount = 64; await mintController.configureController( Accounts.controller1Account, Accounts.minterAccount, @@ -903,18 +908,18 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { from: Accounts.controller1Account, }); - var minterManager = await FiatToken.at( + const minterManager = await FiatToken.at( await mintController.getMinterManager() ); - var minterAllowance = await minterManager.minterAllowance( + const minterAllowance = await minterManager.minterAllowance( Accounts.minterAccount ); - assert(minterAllowance.cmp(newBigNumber(initialAmount)) == 0); + assert(minterAllowance.cmp(newBigNumber(initialAmount)) === 0); await mintController.incrementMinterAllowance(incrementAmount, { from: Accounts.controller1Account, }); - expectedMintControllerState.controllers["controller1Account"] = + expectedMintControllerState.controllers.controller1Account = Accounts.minterAccount; expectedTokenState.push( { variable: "isAccountMinter.minterAccount", expectedValue: true }, @@ -930,9 +935,9 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { }); it("bt049 incrementMinterAllowance(M,amt) reverts when minterAllowance[M] + amt > 2^256", async function () { - var initialAmount = + const initialAmount = "0x" + newBigNumber(maxAmount).sub(newBigNumber(45)).toString(16, 64); - var incrementAmount = 64; + const incrementAmount = 64; await mintController.configureController( Accounts.controller1Account, Accounts.minterAccount, @@ -942,7 +947,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { from: Accounts.controller1Account, }); - expectedMintControllerState.controllers["controller1Account"] = + expectedMintControllerState.controllers.controller1Account = Accounts.minterAccount; expectedTokenState.push( { variable: "isAccountMinter.minterAccount", expectedValue: true }, @@ -956,7 +961,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { [expectedTokenState, expectedMintControllerState] ); - await expectJump( + await expectRevert( mintController.incrementMinterAllowance(incrementAmount, { from: Accounts.controller1Account, }) @@ -964,7 +969,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { }); it("bt050 configureMinter(M,amt) works when minterAllowance=0", async function () { - var amount = 64; + const amount = 64; await mintController.configureController( Accounts.controller1Account, Accounts.minterAccount, @@ -974,18 +979,18 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { from: Accounts.controller1Account, }); - var minterManager = await FiatToken.at( + const minterManager = await FiatToken.at( await mintController.getMinterManager() ); - var minterAllowance = await minterManager.minterAllowance( + const minterAllowance = await minterManager.minterAllowance( Accounts.minterAccount ); - assert(minterAllowance.cmp(newBigNumber(0)) == 0); + assert(minterAllowance.cmp(newBigNumber(0)) === 0); await mintController.configureMinter(amount, { from: Accounts.controller1Account, }); - expectedMintControllerState.controllers["controller1Account"] = + expectedMintControllerState.controllers.controller1Account = Accounts.minterAccount; expectedTokenState.push( { variable: "isAccountMinter.minterAccount", expectedValue: true }, @@ -1001,7 +1006,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { }); it("bt051 configureMinter(M,amt) works when minterAllowance>0", async function () { - var amount = 64; + const amount = 64; await mintController.configureController( Accounts.controller1Account, Accounts.minterAccount, @@ -1011,18 +1016,18 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { from: Accounts.controller1Account, }); - var minterManager = await FiatToken.at( + const minterManager = await FiatToken.at( await mintController.getMinterManager() ); - var minterAllowance = await minterManager.minterAllowance( + const minterAllowance = await minterManager.minterAllowance( Accounts.minterAccount ); - assert(minterAllowance.cmp(newBigNumber(amount)) == 0); + assert(minterAllowance.cmp(newBigNumber(amount)) === 0); await mintController.configureMinter(2 * amount, { from: Accounts.controller1Account, }); - expectedMintControllerState.controllers["controller1Account"] = + expectedMintControllerState.controllers.controller1Account = Accounts.minterAccount; expectedTokenState.push( { variable: "isAccountMinter.minterAccount", expectedValue: true }, @@ -1038,8 +1043,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { }); it("bt052 configureMinter(M,amt) works when amt+minterAllowance > 2^256", async function () { - var amount = 64; - var minterAllowance = maxAmount; + const amount = 64; await mintController.configureController( Accounts.controller1Account, Accounts.minterAccount, @@ -1052,7 +1056,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { await mintController.configureMinter(amount, { from: Accounts.controller1Account, }); - expectedMintControllerState.controllers["controller1Account"] = + expectedMintControllerState.controllers.controller1Account = Accounts.minterAccount; expectedTokenState.push( { variable: "isAccountMinter.minterAccount", expectedValue: true }, @@ -1068,7 +1072,6 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { }); it("bt053 removeMinter works when the minterAllowance is 0", async function () { - var amount = 64; await mintController.configureController( Accounts.controller1Account, Accounts.minterAccount, @@ -1078,16 +1081,16 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { from: Accounts.controller1Account, }); - var minterManager = await FiatToken.at( + const minterManager = await FiatToken.at( await mintController.getMinterManager() ); - var minterAllowance = await minterManager.minterAllowance( + const minterAllowance = await minterManager.minterAllowance( Accounts.minterAccount ); assert(minterAllowance.isZero()); await mintController.removeMinter({ from: Accounts.controller1Account }); - expectedMintControllerState.controllers["controller1Account"] = + expectedMintControllerState.controllers.controller1Account = Accounts.minterAccount; await checkMINTp0( [token, mintController], @@ -1096,7 +1099,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { }); it("bt054 removeMinter works when the minterAllowance is not zero", async function () { - var amount = 64; + const amount = 64; await mintController.configureController( Accounts.controller1Account, Accounts.minterAccount, @@ -1106,16 +1109,16 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { from: Accounts.controller1Account, }); - var minterManager = await FiatToken.at( + const minterManager = await FiatToken.at( await mintController.getMinterManager() ); - var minterAllowance = await minterManager.minterAllowance( + const minterAllowance = await minterManager.minterAllowance( Accounts.minterAccount ); - assert(minterAllowance.cmp(newBigNumber(amount)) == 0); + assert(minterAllowance.cmp(newBigNumber(amount)) === 0); await mintController.removeMinter({ from: Accounts.controller1Account }); - expectedMintControllerState.controllers["controller1Account"] = + expectedMintControllerState.controllers.controller1Account = Accounts.minterAccount; await checkMINTp0( [token, mintController], @@ -1124,7 +1127,6 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { }); it("bt055 removeMinter works when the minterAllowance is big", async function () { - var amount = maxAmount; await mintController.configureController( Accounts.controller1Account, Accounts.minterAccount, @@ -1135,7 +1137,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { }); await mintController.removeMinter({ from: Accounts.controller1Account }); - expectedMintControllerState.controllers["controller1Account"] = + expectedMintControllerState.controllers.controller1Account = Accounts.minterAccount; await checkMINTp0( [token, mintController], @@ -1163,11 +1165,11 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { }); // now configure minter - var amount = 1; + const amount = 1; await mintController.decrementMinterAllowance(amount, { from: Accounts.controller1Account, }); - expectedMintControllerState.controllers["controller1Account"] = + expectedMintControllerState.controllers.controller1Account = Accounts.minterAccount; expectedTokenState.push( { variable: "isAccountMinter.minterAccount", expectedValue: true }, @@ -1231,11 +1233,11 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { }); // now decrementMinterAllowance - var amount = 45; + const amount = 45; await mintController.decrementMinterAllowance(amount, { from: Accounts.controller1Account, }); - expectedMintControllerState.controllers["controller1Account"] = + expectedMintControllerState.controllers.controller1Account = Accounts.minterAccount; expectedTokenState.push( { variable: "isAccountMinter.minterAccount", expectedValue: true }, @@ -1248,17 +1250,17 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { }); it("bt061 decrementMinterAllowance(M, amt) reverts when minterManager.isMinter(M)=false", async function () { - var amount = 1; + const amount = 1; await mintController.configureController( Accounts.controller1Account, Accounts.minterAccount, { from: Accounts.mintOwnerAccount } ); - var minterManager = await FiatToken.at( + const minterManager = await FiatToken.at( await mintController.getMinterManager() ); - var isMinter = await minterManager.isMinter(Accounts.minterAccount); + const isMinter = await minterManager.isMinter(Accounts.minterAccount); assert.isFalse(isMinter); @@ -1268,7 +1270,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { }), "Can only decrement allowance for minters in minterManager" ); - expectedMintControllerState.controllers["controller1Account"] = + expectedMintControllerState.controllers.controller1Account = Accounts.minterAccount; await checkMINTp0( [token, mintController], @@ -1277,7 +1279,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { }); it("bt062 decrementMinterAllowance(M, amt) works when minterManager.isMinter(M)=true", async function () { - var amount = 65424; + const amount = 65424; await mintController.configureController( Accounts.controller1Account, Accounts.minterAccount, @@ -1287,16 +1289,16 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { from: Accounts.controller1Account, }); - var minterManager = await FiatToken.at( + const minterManager = await FiatToken.at( await mintController.getMinterManager() ); - var isMinter = await minterManager.isMinter(Accounts.minterAccount); + const isMinter = await minterManager.isMinter(Accounts.minterAccount); assert.isTrue(isMinter); await mintController.decrementMinterAllowance(amount, { from: Accounts.controller1Account, }); - expectedMintControllerState.controllers["controller1Account"] = + expectedMintControllerState.controllers.controller1Account = Accounts.minterAccount; expectedTokenState.push( { variable: "isAccountMinter.minterAccount", expectedValue: true }, @@ -1309,7 +1311,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { }); it("bt063 decrementMinterAllowance(M,amt) works when minterAllowance is MAX", async function () { - var amount = maxAmount; + const amount = maxAmount; await mintController.configureController( Accounts.controller1Account, Accounts.minterAccount, @@ -1319,17 +1321,17 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { from: Accounts.controller1Account, }); - var minterManager = await FiatToken.at( + const minterManager = await FiatToken.at( await mintController.getMinterManager() ); - var minterAllowance = await minterManager.minterAllowance( + const minterAllowance = await minterManager.minterAllowance( Accounts.minterAccount ); - assert(minterAllowance.cmp(newBigNumber(maxAmount)) == 0); + assert(minterAllowance.cmp(newBigNumber(maxAmount)) === 0); await mintController.decrementMinterAllowance(amount, { from: Accounts.controller1Account, }); - expectedMintControllerState.controllers["controller1Account"] = + expectedMintControllerState.controllers.controller1Account = Accounts.minterAccount; expectedTokenState.push( { variable: "isAccountMinter.minterAccount", expectedValue: true }, @@ -1342,8 +1344,8 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { }); it("bt064 decrementMinterAllowance(M, amt) works when minterAllowance > 0", async function () { - var initialAmount = 987341; - var decrementAmount = 64; + const initialAmount = 987341; + const decrementAmount = 64; await mintController.configureController( Accounts.controller1Account, Accounts.minterAccount, @@ -1353,18 +1355,18 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { from: Accounts.controller1Account, }); - var minterManager = await FiatToken.at( + const minterManager = await FiatToken.at( await mintController.getMinterManager() ); - var minterAllowance = await minterManager.minterAllowance( + const minterAllowance = await minterManager.minterAllowance( Accounts.minterAccount ); - assert(minterAllowance.cmp(newBigNumber(initialAmount)) == 0); + assert(minterAllowance.cmp(newBigNumber(initialAmount)) === 0); await mintController.decrementMinterAllowance(decrementAmount, { from: Accounts.controller1Account, }); - expectedMintControllerState.controllers["controller1Account"] = + expectedMintControllerState.controllers.controller1Account = Accounts.minterAccount; expectedTokenState.push( { variable: "isAccountMinter.minterAccount", expectedValue: true }, @@ -1380,8 +1382,8 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { }); it("bt065 decrementMinterAllowance(M,amt) sets allowance to 0 when minterAllowance[M] - amt < 0", async function () { - var initialAmount = 45; - var decrementAmount = 64; + const initialAmount = 45; + const decrementAmount = 64; await mintController.configureController( Accounts.controller1Account, Accounts.minterAccount, @@ -1391,17 +1393,17 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { from: Accounts.controller1Account, }); - var minterManager = await FiatToken.at( + const minterManager = await FiatToken.at( await mintController.getMinterManager() ); - var minterAllowance = await minterManager.minterAllowance( + const minterAllowance = await minterManager.minterAllowance( Accounts.minterAccount ); - assert(minterAllowance.cmp(newBigNumber(initialAmount)) == 0); + assert(minterAllowance.cmp(newBigNumber(initialAmount)) === 0); await mintController.decrementMinterAllowance(decrementAmount, { from: Accounts.controller1Account, }); - expectedMintControllerState.controllers["controller1Account"] = + expectedMintControllerState.controllers.controller1Account = Accounts.minterAccount; expectedTokenState.push( { variable: "isAccountMinter.minterAccount", expectedValue: true }, @@ -1414,9 +1416,6 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { }); } -var testWrapper = require("../TestWrapper"); -testWrapper.execute( - "MINTp0_BasicTests MintController", - run_tests_MintController -); -testWrapper.execute("MINTp0_BasicTests MasterMinter", run_tests_MasterMinter); +const wrapTests = require("../v1/helpers/wrapTests"); +wrapTests("MINTp0_BasicTests MintController", run_tests_MintController); +wrapTests("MINTp0_BasicTests MasterMinter", run_tests_MasterMinter); diff --git a/test/e2e/MintP0_EndToEndTests.js b/test/minting/MintP0_EndToEndTests.js similarity index 84% rename from test/e2e/MintP0_EndToEndTests.js rename to test/minting/MintP0_EndToEndTests.js index 5fe71a73f..9de45a70a 100644 --- a/test/e2e/MintP0_EndToEndTests.js +++ b/test/minting/MintP0_EndToEndTests.js @@ -1,34 +1,27 @@ -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 tokenUtils = require("../TokenTestUtils.js"); -var newBigNumber = tokenUtils.newBigNumber; -var checkMINTp0 = tokenUtils.checkMINTp0; -var expectRevert = tokenUtils.expectRevert; -var expectJump = tokenUtils.expectJump; -var expectError = tokenUtils.expectError; -var bigZero = tokenUtils.bigZero; -var maxAmount = tokenUtils.maxAmount; -var initializeTokenWithProxy = tokenUtils.initializeTokenWithProxy; - -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 addressEquals = AccountUtils.addressEquals; -var initializeTokenWithProxyAndMintController = +const MintController = artifacts.require("minting/MintController"); +const MasterMinter = artifacts.require("minting/MasterMinter"); + +const tokenUtils = require("../v1/TokenTestUtils.js"); +const newBigNumber = tokenUtils.newBigNumber; +const checkMINTp0 = tokenUtils.checkMINTp0; +const expectRevert = tokenUtils.expectRevert; +const expectError = tokenUtils.expectError; +const initializeTokenWithProxy = tokenUtils.initializeTokenWithProxy; + +const clone = require("clone"); + +const mintUtils = require("../minting/MintControllerUtils.js"); +const AccountUtils = require("../minting/AccountUtils.js"); +const Accounts = AccountUtils.Accounts; +const initializeTokenWithProxyAndMintController = mintUtils.initializeTokenWithProxyAndMintController; -var checkMintControllerState = mintUtils.checkMintControllerState; -var zeroAddress = "0x0000000000000000000000000000000000000000"; -var maxAmount = - "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"; +let mintController; +let expectedMintControllerState; +let expectedTokenState; +let token; +let rawToken; +let tokenConfig; async function run_tests_MintController(newToken, accounts) { run_MINT_tests(newToken, MintController, accounts); @@ -38,7 +31,7 @@ async function run_tests_MasterMinter(newToken, accounts) { run_MINT_tests(newToken, MasterMinter, accounts); } -async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { +async function run_MINT_tests(newToken, MintControllerArtifact) { beforeEach("Make fresh token contract", async function () { rawToken = await newToken(); tokenConfig = await initializeTokenWithProxyAndMintController( @@ -62,7 +55,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { Accounts.minterAccount, { from: Accounts.arbitraryAccount } ); - expectedMintControllerState.controllers["arbitraryAccount2"] = + expectedMintControllerState.controllers.arbitraryAccount2 = Accounts.minterAccount; expectedMintControllerState.owner = Accounts.arbitraryAccount; await checkMINTp0( @@ -99,7 +92,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { await mintController.configureMinter(10, { from: Accounts.arbitraryAccount, }); - expectedMintControllerState.controllers["arbitraryAccount"] = + expectedMintControllerState.controllers.arbitraryAccount = Accounts.minterAccount; expectedTokenState.push( { variable: "isAccountMinter.minterAccount", expectedValue: true }, @@ -125,9 +118,9 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { Accounts.minterAccount, { from: Accounts.mintOwnerAccount } ); - expectedMintControllerState.controllers["arbitraryAccount"] = + expectedMintControllerState.controllers.arbitraryAccount = Accounts.minterAccount; - expectedMintControllerState.controllers["arbitraryAccount2"] = + expectedMintControllerState.controllers.arbitraryAccount2 = Accounts.minterAccount; // first controller configures minter @@ -171,9 +164,9 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { Accounts.minterAccount, { from: Accounts.mintOwnerAccount } ); - expectedMintControllerState.controllers["arbitraryAccount"] = + expectedMintControllerState.controllers.arbitraryAccount = Accounts.minterAccount; - expectedMintControllerState.controllers["arbitraryAccount2"] = + expectedMintControllerState.controllers.arbitraryAccount2 = Accounts.minterAccount; // first controller configures minter @@ -218,9 +211,9 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { Accounts.pauserAccount, { from: Accounts.mintOwnerAccount } ); - expectedMintControllerState.controllers["arbitraryAccount"] = + expectedMintControllerState.controllers.arbitraryAccount = Accounts.minterAccount; - expectedMintControllerState.controllers["arbitraryAccount2"] = + expectedMintControllerState.controllers.arbitraryAccount2 = Accounts.minterAccount; // first controller configures minter @@ -258,9 +251,9 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { Accounts.pauserAccount, { from: Accounts.mintOwnerAccount } ); - expectedMintControllerState.controllers["arbitraryAccount"] = + expectedMintControllerState.controllers.arbitraryAccount = Accounts.minterAccount; - expectedMintControllerState.controllers["arbitraryAccount2"] = + expectedMintControllerState.controllers.arbitraryAccount2 = Accounts.minterAccount; // second controller fails to configure minter (configures pauser instead) @@ -305,12 +298,12 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { Accounts.minterAccount, { from: Accounts.mintOwnerAccount } ); - expectedMintControllerState.controllers["arbitraryAccount"] = + expectedMintControllerState.controllers.arbitraryAccount = Accounts.minterAccount; // change minterManager to a new token - var newTokenConfig = await initializeTokenWithProxy(rawToken); - var newToken = newTokenConfig.token; + const newTokenConfig = await initializeTokenWithProxy(rawToken); + const newToken = newTokenConfig.token; await newToken.updateMasterMinter(mintController.address, { from: Accounts.tokenOwnerAccount, }); @@ -323,7 +316,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { await mintController.configureMinter(10, { from: Accounts.arbitraryAccount, }); - expectedMintControllerState.controllers["arbitraryAccount"] = + expectedMintControllerState.controllers.arbitraryAccount = Accounts.minterAccount; expectedTokenState.push( { variable: "isAccountMinter.minterAccount", expectedValue: true }, @@ -344,12 +337,12 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { Accounts.minterAccount, { from: Accounts.mintOwnerAccount } ); - expectedMintControllerState.controllers["arbitraryAccount"] = + expectedMintControllerState.controllers.arbitraryAccount = Accounts.minterAccount; // change minterManager to a new token - var newTokenConfig = await initializeTokenWithProxy(rawToken); - var newToken = newTokenConfig.token; + const newTokenConfig = await initializeTokenWithProxy(rawToken); + const newToken = newTokenConfig.token; await newToken.updateMasterMinter(mintController.address, { from: Accounts.tokenOwnerAccount, }); @@ -363,7 +356,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { from: Accounts.arbitraryAccount, }); await mintController.removeMinter({ from: Accounts.arbitraryAccount }); - expectedMintControllerState.controllers["arbitraryAccount"] = + expectedMintControllerState.controllers.arbitraryAccount = Accounts.minterAccount; await checkMINTp0( [newToken, mintController], @@ -377,12 +370,12 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { Accounts.minterAccount, { from: Accounts.mintOwnerAccount } ); - expectedMintControllerState.controllers["arbitraryAccount"] = + expectedMintControllerState.controllers.arbitraryAccount = Accounts.minterAccount; // change minterManager to a new token - var newTokenConfig = await initializeTokenWithProxy(rawToken); - var newToken = newTokenConfig.token; + const newTokenConfig = await initializeTokenWithProxy(rawToken); + const newToken = newTokenConfig.token; await newToken.updateMasterMinter(mintController.address, { from: Accounts.tokenOwnerAccount, }); @@ -398,7 +391,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { await mintController.incrementMinterAllowance(20, { from: Accounts.arbitraryAccount, }); - expectedMintControllerState.controllers["arbitraryAccount"] = + expectedMintControllerState.controllers.arbitraryAccount = Accounts.minterAccount; expectedTokenState.push( { variable: "isAccountMinter.minterAccount", expectedValue: true }, @@ -425,7 +418,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { await mintController.incrementMinterAllowance(10, { from: Accounts.arbitraryAccount, }); - expectedMintControllerState.controllers["arbitraryAccount"] = + expectedMintControllerState.controllers.arbitraryAccount = Accounts.minterAccount; expectedTokenState.push( { variable: "isAccountMinter.minterAccount", expectedValue: true }, @@ -450,7 +443,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { from: Accounts.arbitraryAccount, }); await mintController.removeMinter({ from: Accounts.arbitraryAccount }); - expectedMintControllerState.controllers["arbitraryAccount"] = + expectedMintControllerState.controllers.arbitraryAccount = Accounts.minterAccount; await checkMINTp0( [token, mintController], @@ -464,12 +457,12 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { Accounts.minterAccount, { from: Accounts.mintOwnerAccount } ); - expectedMintControllerState.controllers["arbitraryAccount"] = + expectedMintControllerState.controllers.arbitraryAccount = Accounts.minterAccount; // change minterManager to a new token - var newTokenConfig = await initializeTokenWithProxy(rawToken); - var newToken = newTokenConfig.token; + const newTokenConfig = await initializeTokenWithProxy(rawToken); + const newToken = newTokenConfig.token; await newToken.updateMasterMinter(mintController.address, { from: Accounts.tokenOwnerAccount, }); @@ -482,7 +475,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { await mintController.configureMinter(10, { from: Accounts.arbitraryAccount, }); - expectedMintControllerState.controllers["arbitraryAccount"] = + expectedMintControllerState.controllers.arbitraryAccount = Accounts.minterAccount; expectedTokenState.push( { variable: "isAccountMinter.minterAccount", expectedValue: true }, @@ -525,7 +518,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { from: Accounts.arbitraryAccount, }); await mintController.removeMinter({ from: Accounts.arbitraryAccount }); - expectedMintControllerState.controllers["arbitraryAccount"] = + expectedMintControllerState.controllers.arbitraryAccount = Accounts.minterAccount; // now verify that incrementing its allowance reverts @@ -556,7 +549,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { await token.mint(Accounts.arbitraryAccount, 5, { from: Accounts.minterAccount, }); - expectedMintControllerState.controllers["arbitraryAccount"] = + expectedMintControllerState.controllers.arbitraryAccount = Accounts.minterAccount; expectedTokenState.push( { variable: "isAccountMinter.minterAccount", expectedValue: true }, @@ -584,7 +577,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { from: Accounts.arbitraryAccount, }); await mintController.removeMinter({ from: Accounts.arbitraryAccount }); - expectedMintControllerState.controllers["arbitraryAccount"] = + expectedMintControllerState.controllers.arbitraryAccount = Accounts.minterAccount; // now verify that minter cannot mint @@ -615,7 +608,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { from: Accounts.minterAccount, }); await token.burn(5, { from: Accounts.minterAccount }); - expectedMintControllerState.controllers["arbitraryAccount"] = + expectedMintControllerState.controllers.arbitraryAccount = Accounts.minterAccount; expectedTokenState.push( { variable: "isAccountMinter.minterAccount", expectedValue: true }, @@ -647,7 +640,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { // now verify that minter cannot burn expectRevert(token.burn(5, { from: Accounts.minterAccount })); - expectedMintControllerState.controllers["arbitraryAccount"] = + expectedMintControllerState.controllers.arbitraryAccount = Accounts.minterAccount; expectedTokenState.push( { variable: "balances.minterAccount", expectedValue: newBigNumber(5) }, @@ -660,12 +653,6 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { }); } -var testWrapper = require("./../TestWrapper"); -testWrapper.execute( - "MINTp0_EndToEndTests MintController", - run_tests_MintController -); -testWrapper.execute( - "MINTp0_EndToEndTests MasterMinter", - run_tests_MasterMinter -); +const wrapTests = require("../v1/helpers/wrapTests"); +wrapTests("MINTp0_EndToEndTests MintController", run_tests_MintController); +wrapTests("MINTp0_EndToEndTests MasterMinter", run_tests_MasterMinter); diff --git a/test/events/MintP0_EventsTests.js b/test/minting/MintP0_EventsTests.js similarity index 75% rename from test/events/MintP0_EventsTests.js rename to test/minting/MintP0_EventsTests.js index d3f5de1fa..0ea216719 100644 --- a/test/events/MintP0_EventsTests.js +++ b/test/minting/MintP0_EventsTests.js @@ -1,35 +1,18 @@ -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"); +const MintController = artifacts.require("minting/MintController"); +const MasterMinter = artifacts.require("minting/MasterMinter"); -var tokenUtils = require("../TokenTestUtils.js"); -var newBigNumber = tokenUtils.newBigNumber; -var checkMINTp0 = tokenUtils.checkMINTp0; -var expectRevert = tokenUtils.expectRevert; -var expectJump = tokenUtils.expectJump; -var expectError = tokenUtils.expectError; -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 addressEquals = AccountUtils.addressEquals; -var initializeTokenWithProxyAndMintController = +const mintUtils = require("./MintControllerUtils.js"); +const AccountUtils = require("./AccountUtils.js"); +const Accounts = AccountUtils.Accounts; +const initializeTokenWithProxyAndMintController = mintUtils.initializeTokenWithProxyAndMintController; -var checkMintControllerState = mintUtils.checkMintControllerState; -var zeroAddress = "0x0000000000000000000000000000000000000000"; -var maxAmount = - "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"; +let rawToken; +let tokenConfig; +let token; +let mintController; -var mintControllerEvents = { +const mintControllerEvents = { ownershipTransferred: "OwnershipTransferred", controllerConfigured: "ControllerConfigured", controllerRemoved: "ControllerRemoved", @@ -48,7 +31,7 @@ async function run_tests_MasterMinter(newToken, accounts) { run_MINT_tests(newToken, MasterMinter, accounts); } -async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { +async function run_MINT_tests(newToken, MintControllerArtifact) { beforeEach("Make fresh token contract", async function () { rawToken = await newToken(); tokenConfig = await initializeTokenWithProxyAndMintController( @@ -57,15 +40,11 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { ); token = tokenConfig.token; mintController = tokenConfig.mintController; - expectedMintControllerState = clone(tokenConfig.customState); - expectedTokenState = [ - { variable: "masterMinter", expectedValue: mintController.address }, - ]; }); it("et100 transferOwnership emits OwnershipTransferred event", async function () { // get all previous transfer ownership events - var preEvents = await mintController.getPastEvents( + const preEvents = await mintController.getPastEvents( mintControllerEvents.ownershipTransferred, { filter: { @@ -79,7 +58,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { await mintController.transferOwnership(Accounts.arbitraryAccount, { from: Accounts.mintOwnerAccount, }); - var postEvents = await mintController.getPastEvents( + const postEvents = await mintController.getPastEvents( mintControllerEvents.ownershipTransferred, { filter: { @@ -95,7 +74,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { it("et101 configureController emits ControllerConfigured event", async function () { // get all previous configure controller events - var preEvents = await mintController.getPastEvents( + const preEvents = await mintController.getPastEvents( mintControllerEvents.controllerConfigured, { filter: { @@ -111,7 +90,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { Accounts.arbitraryAccount2, { from: Accounts.mintOwnerAccount } ); - var postEvents = await mintController.getPastEvents( + const postEvents = await mintController.getPastEvents( mintControllerEvents.controllerConfigured, { filter: { @@ -132,7 +111,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { Accounts.arbitraryAccount2, { from: Accounts.mintOwnerAccount } ); - var preEvents = await mintController.getPastEvents( + const preEvents = await mintController.getPastEvents( mintControllerEvents.controllerRemoved, { filter: { _controller: Accounts.arbitraryAccount } } ); @@ -141,7 +120,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { await mintController.removeController(Accounts.arbitraryAccount, { from: Accounts.mintOwnerAccount, }); - var postEvents = await mintController.getPastEvents( + const postEvents = await mintController.getPastEvents( mintControllerEvents.controllerRemoved, { filter: { _controller: Accounts.arbitraryAccount } } ); @@ -152,7 +131,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { it("et103 setMinterManager emits MinterManagerSet event", async function () { // get all previous set minter manager events - var preEvents = await mintController.getPastEvents( + const preEvents = await mintController.getPastEvents( mintControllerEvents.minterManagerSet, { filter: { @@ -166,7 +145,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { await mintController.setMinterManager(Accounts.arbitraryAccount, { from: Accounts.mintOwnerAccount, }); - var postEvents = await mintController.getPastEvents( + const postEvents = await mintController.getPastEvents( mintControllerEvents.minterManagerSet, { filter: { @@ -182,7 +161,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { it("et104 removeMinter emits MinterRemoved event", async function () { // get all previous remove minter events - var allowance = 10; + const allowance = 10; await mintController.configureController( Accounts.arbitraryAccount, Accounts.minterAccount, @@ -191,7 +170,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { await mintController.configureMinter(allowance, { from: Accounts.arbitraryAccount, }); - var preEvents = await mintController.getPastEvents( + const preEvents = await mintController.getPastEvents( mintControllerEvents.minterRemoved, { filter: { @@ -203,7 +182,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { // now remove minter and test again await mintController.removeMinter({ from: Accounts.arbitraryAccount }); - var postEvents = await mintController.getPastEvents( + const postEvents = await mintController.getPastEvents( mintControllerEvents.minterRemoved, { filter: { @@ -219,13 +198,13 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { it("et105 configureMinter emits MinterConfigured event", async function () { // get all previous configureMinter events - var allowance = 10; + const allowance = 10; await mintController.configureController( Accounts.arbitraryAccount, Accounts.minterAccount, { from: Accounts.mintOwnerAccount } ); - var preEvents = await mintController.getPastEvents( + const preEvents = await mintController.getPastEvents( mintControllerEvents.minterCofigured, { filter: { @@ -240,7 +219,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { await mintController.configureMinter(allowance, { from: Accounts.arbitraryAccount, }); - var postEvents = await mintController.getPastEvents( + const postEvents = await mintController.getPastEvents( mintControllerEvents.minterCofigured, { filter: { @@ -257,7 +236,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { it("et106 incrementMinterAllowance emits MinterAllowanceIncremented event", async function () { // get all previous increment minter allowance events - var allowance = 10; + const allowance = 10; await mintController.configureController( Accounts.arbitraryAccount, Accounts.minterAccount, @@ -266,7 +245,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { await mintController.configureMinter(allowance, { from: Accounts.arbitraryAccount, }); - var preEvents = await mintController.getPastEvents( + const preEvents = await mintController.getPastEvents( mintControllerEvents.minterAllowanceIncremented, { filter: { @@ -282,7 +261,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { await mintController.incrementMinterAllowance(allowance, { from: Accounts.arbitraryAccount, }); - var postEvents = await mintController.getPastEvents( + const postEvents = await mintController.getPastEvents( mintControllerEvents.minterAllowanceIncremented, { filter: { @@ -300,7 +279,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { it("et107 decrementMinterAllowance emits MinterAllowanceDecremented event", async function () { // get all previous decrement minter allowance events - var allowance = 10; + const allowance = 10; await mintController.configureController( Accounts.arbitraryAccount, Accounts.minterAccount, @@ -309,7 +288,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { await mintController.configureMinter(allowance, { from: Accounts.arbitraryAccount, }); - var preEvents = await mintController.getPastEvents( + const preEvents = await mintController.getPastEvents( mintControllerEvents.minterAllowanceDecremented, { filter: { @@ -325,7 +304,7 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { await mintController.decrementMinterAllowance(allowance, { from: Accounts.arbitraryAccount, }); - var postEvents = await mintController.getPastEvents( + const postEvents = await mintController.getPastEvents( mintControllerEvents.minterAllowanceDecremented, { filter: { @@ -342,9 +321,6 @@ async function run_MINT_tests(newToken, MintControllerArtifact, accounts) { }); } -var testWrapper = require("./../TestWrapper"); -testWrapper.execute( - "MINTp0_EventTests MintController", - run_tests_MintController -); -testWrapper.execute("MINTp0_EventTests MasterMinter", run_tests_MasterMinter); +const wrapTests = require("../v1/helpers/wrapTests"); +wrapTests("MINTp0_EventTests MintController", run_tests_MintController); +wrapTests("MINTp0_EventTests MasterMinter", run_tests_MasterMinter); diff --git a/test/minting2/MintP0_ABITests.js b/test/minting2/MintP0_ABITests.js deleted file mode 100644 index 6f8236f60..000000000 --- a/test/minting2/MintP0_ABITests.js +++ /dev/null @@ -1,87 +0,0 @@ -var MintController = artifacts.require("minting/MintController"); -var MasterMinter = artifacts.require("minting/MasterMinter"); -var FiatToken = artifacts.require("FiatTokenV1"); - -var tokenUtils = require("../TokenTestUtils.js"); -var checkMINTp0 = tokenUtils.checkMINTp0; -var expectError = tokenUtils.expectError; -var bigZero = tokenUtils.bigZero; -var maxAmount = tokenUtils.maxAmount; -var solidityErrors = tokenUtils.solidityErrors; - -var clone = require("clone"); - -var mintUtils = require("../MintControllerUtils.js"); -var AccountUtils = require("../AccountUtils.js"); -var Accounts = AccountUtils.Accounts; -var AccountPrivateKeys = AccountUtils.AccountPrivateKeys; -var getAccountState = AccountUtils.getAccountState; -var MintControllerState = AccountUtils.MintControllerState; -var initializeTokenWithProxyAndMintController = - mintUtils.initializeTokenWithProxyAndMintController; -var checkMintControllerState = mintUtils.checkMintControllerState; - -var abiUtils = require("../ABIUtils.js"); -var makeRawTransaction = abiUtils.makeRawTransaction; -var sendRawTransaction = abiUtils.sendRawTransaction; -var msgData = abiUtils.msgData; -var msgData1 = abiUtils.msgData1; - -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("abi100 internal_setMinterAllowance is internal", async function () { - await mintController.configureController( - Accounts.controller1Account, - Accounts.minterAccount, - { from: Accounts.mintOwnerAccount } - ); - let badData = msgData1( - "internal_setMinterAllowance(address,uint256)", - Accounts.controller1Account, - 569 - ); - let raw = makeRawTransaction( - badData, - Accounts.mintOwnerAccount, - AccountPrivateKeys.mintOwnerPrivateKey, - mintController.address - ); - await expectError(sendRawTransaction(raw), solidityErrors.argumentType); - }); - - it("abi101 setOwner is internal", async function () { - let badData = msgData("setOwner(address)", Accounts.arbitraryAccount); - let raw = makeRawTransaction( - badData, - Accounts.mintOwnerAccount, - AccountPrivateKeys.mintOwnerPrivateKey, - mintController.address - ); - await expectError(sendRawTransaction(raw), solidityErrors.argumentType); - }); -} - -var testWrapper = require("./../TestWrapper"); -testWrapper.execute("MINTp0_ABITests MintController", run_tests_MintController); -testWrapper.execute("MINTp0_ABITests MasterMinter", run_tests_MasterMinter); diff --git a/test/misc/MiscTests.js b/test/misc/MiscTests.js deleted file mode 100644 index 380bde306..000000000 --- a/test/misc/MiscTests.js +++ /dev/null @@ -1,981 +0,0 @@ -var FiatTokenProxy = artifacts.require("FiatTokenProxy"); - -var tokenUtils = require("./../TokenTestUtils.js"); -var newBigNumber = tokenUtils.newBigNumber; -var assertDiff = require("assert-diff"); -assertDiff.options.strict = true; - -var bigZero = tokenUtils.bigZero; -var bigHundred = tokenUtils.bigHundred; -var mint = tokenUtils.mint; -var checkVariables = tokenUtils.checkVariables; -var expectRevert = tokenUtils.expectRevert; -var name = tokenUtils.name; -var symbol = tokenUtils.symbol; -var currency = tokenUtils.currency; -var decimals = tokenUtils.decimals; - -var initializeTokenWithProxy = tokenUtils.initializeTokenWithProxy; -var getInitializedV1 = tokenUtils.getInitializedV1; -var FiatToken = tokenUtils.FiatToken; - -var AccountUtils = require("./../AccountUtils.js"); -var Accounts = AccountUtils.Accounts; -var addressEquals = AccountUtils.addressEquals; - -var maxAmount = - "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"; -var amount = 100; - -async function run_tests(newToken, accounts) { - beforeEach("Make fresh token contract", async function () { - rawToken = await newToken(); - var tokenConfig = await initializeTokenWithProxy(rawToken); - proxy = tokenConfig.proxy; - token = tokenConfig.token; - assert.isTrue(addressEquals(proxy.address, token.address)); - }); - - // No Payable Function - - it("ms001 no payable function", async function () { - var success = false; - try { - await web3.eth.sendTransaction({ - from: Accounts.arbitraryAccount, - to: token.address, - value: 1, - }); - } catch (e) { - success = true; - } - assert.equal(true, success); - }); - - // Same Address - - it("ms002 should transfer to self has correct final balance", async function () { - let mintAmount = 50; - await token.configureMinter(Accounts.minterAccount, amount, { - from: Accounts.masterMinterAccount, - }); - await token.mint(Accounts.arbitraryAccount, mintAmount, { - from: Accounts.minterAccount, - }); - await token.transfer(Accounts.arbitraryAccount, mintAmount, { - from: Accounts.arbitraryAccount, - }); - - var customVars = [ - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount - mintAmount), - }, - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "balances.arbitraryAccount", - expectedValue: newBigNumber(mintAmount), - }, - { variable: "totalSupply", expectedValue: newBigNumber(mintAmount) }, - ]; - await checkVariables([token], [customVars]); - }); - - it("ms003 should transferFrom to self from approved account and have correct final balance", async function () { - let mintAmount = 50; - - await token.configureMinter(Accounts.minterAccount, amount, { - from: Accounts.masterMinterAccount, - }); - await token.mint(Accounts.arbitraryAccount, mintAmount, { - from: Accounts.minterAccount, - }); - - 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: newBigNumber(amount - mintAmount), - }, - { - variable: "balances.arbitraryAccount", - expectedValue: newBigNumber(mintAmount), - }, - { variable: "totalSupply", expectedValue: newBigNumber(mintAmount) }, - ]; - await checkVariables([token], [customVars]); - }); - - it("ms004 should transferFrom to self from approved self and have correct final balance", async function () { - let mintAmount = 50; - - await token.configureMinter(Accounts.minterAccount, amount, { - from: Accounts.masterMinterAccount, - }); - await token.mint(Accounts.arbitraryAccount, mintAmount, { - from: Accounts.minterAccount, - }); - - await token.approve(Accounts.arbitraryAccount, mintAmount, { - from: Accounts.arbitraryAccount, - }); - await token.transferFrom( - Accounts.arbitraryAccount, - Accounts.arbitraryAccount, - mintAmount, - { from: Accounts.arbitraryAccount } - ); - customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount - mintAmount), - }, - { - variable: "balances.arbitraryAccount", - expectedValue: newBigNumber(mintAmount), - }, - { variable: "totalSupply", expectedValue: newBigNumber(mintAmount) }, - ]; - await checkVariables([token], [customVars]); - }); - - it("ms005 should mint to self with correct final balance", async function () { - var mintAmount = 50; - - await token.configureMinter(Accounts.minterAccount, amount, { - from: Accounts.masterMinterAccount, - }); - var customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount), - }, - ]; - await checkVariables([token], [customVars]); - - await token.mint(Accounts.minterAccount, mintAmount, { - from: Accounts.minterAccount, - }); - customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount - mintAmount), - }, - { - variable: "balances.minterAccount", - expectedValue: newBigNumber(mintAmount), - }, - { variable: "totalSupply", expectedValue: newBigNumber(mintAmount) }, - ]; - await checkVariables([token], [customVars]); - }); - - it("ms006 should approve correct allowance for self", async function () { - var mintAmount = 50; - - await token.configureMinter(Accounts.minterAccount, amount, { - from: Accounts.masterMinterAccount, - }); - var customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount), - }, - ]; - await checkVariables([token], [customVars]); - - await token.mint(Accounts.arbitraryAccount, mintAmount, { - from: Accounts.minterAccount, - }); - await token.approve(Accounts.arbitraryAccount, amount, { - from: Accounts.arbitraryAccount, - }); - customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount - mintAmount), - }, - { - variable: "balances.arbitraryAccount", - expectedValue: newBigNumber(mintAmount), - }, - { variable: "totalSupply", expectedValue: newBigNumber(mintAmount) }, - { - variable: "allowance.arbitraryAccount.arbitraryAccount", - expectedValue: newBigNumber(amount), - }, - ]; - await checkVariables([token], [customVars]); - }); - - it("ms007 should configureMinter for masterMinter", async function () { - await token.configureMinter(Accounts.masterMinterAccount, amount, { - from: Accounts.masterMinterAccount, - }); - var customVars = [ - { variable: "isAccountMinter.masterMinterAccount", expectedValue: true }, - { - variable: "minterAllowance.masterMinterAccount", - expectedValue: newBigNumber(amount), - }, - ]; - await checkVariables([token], [customVars]); - }); - - // Multiple Minters - - it("ms009 should configure two minters", async function () { - await token.configureMinter(Accounts.minterAccount, amount, { - from: Accounts.masterMinterAccount, - }); - await token.configureMinter(Accounts.arbitraryAccount, amount, { - from: Accounts.masterMinterAccount, - }); - var customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { variable: "isAccountMinter.arbitraryAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount), - }, - { - variable: "minterAllowance.arbitraryAccount", - expectedValue: newBigNumber(amount), - }, - ]; - await checkVariables([token], [customVars]); - }); - - it("ms010 should configure two minters and each mint distinct amounts", async function () { - var mintAmount1 = 10; - var mintAmount2 = 20; - - await token.configureMinter(Accounts.minterAccount, amount, { - from: Accounts.masterMinterAccount, - }); - await token.configureMinter(Accounts.arbitraryAccount, amount, { - from: Accounts.masterMinterAccount, - }); - 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: newBigNumber(amount - mintAmount1), - }, - { - variable: "minterAllowance.arbitraryAccount", - expectedValue: newBigNumber(amount - mintAmount2), - }, - { - variable: "balances.arbitraryAccount2", - expectedValue: newBigNumber(mintAmount1 + mintAmount2), - }, - { - variable: "totalSupply", - expectedValue: newBigNumber(mintAmount1 + mintAmount2), - }, - ]; - await checkVariables([token], [customVars]); - }); - - it("ms011 should configure two minters, each minting distinct amounts and then remove one minter", async function () { - var mintAmount1 = 10; - var mintAmount2 = 20; - - await token.configureMinter(Accounts.minterAccount, amount, { - from: Accounts.masterMinterAccount, - }); - await token.configureMinter(Accounts.arbitraryAccount, amount, { - from: Accounts.masterMinterAccount, - }); - 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: newBigNumber(amount - mintAmount1), - }, - { - variable: "balances.arbitraryAccount2", - expectedValue: newBigNumber(mintAmount1 + mintAmount2), - }, - { - variable: "totalSupply", - expectedValue: newBigNumber(mintAmount1 + mintAmount2), - }, - ]; - await checkVariables([token], [customVars]); - }); - - it("ms012 should configure two minters and adjust both allowances", async function () { - var adjustment = 10; - - await token.configureMinter(Accounts.minterAccount, amount, { - from: Accounts.masterMinterAccount, - }); - await token.configureMinter(Accounts.arbitraryAccount, amount, { - from: Accounts.masterMinterAccount, - }); - var customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { variable: "isAccountMinter.arbitraryAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount), - }, - { - variable: "minterAllowance.arbitraryAccount", - expectedValue: newBigNumber(amount), - }, - ]; - await checkVariables([token], [customVars]); - - await token.configureMinter(Accounts.minterAccount, amount - adjustment, { - from: Accounts.masterMinterAccount, - }); - await token.configureMinter( - Accounts.arbitraryAccount, - amount + adjustment, - { from: Accounts.masterMinterAccount } - ); - var customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { variable: "isAccountMinter.arbitraryAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount - adjustment), - }, - { - variable: "minterAllowance.arbitraryAccount", - expectedValue: newBigNumber(amount + adjustment), - }, - ]; - await checkVariables([token], [customVars]); - }); - - it("ms013 should configure two minters, one with zero allowance fails to mint", async function () { - var mintAmount = 10; - - await token.configureMinter(Accounts.minterAccount, amount, { - from: Accounts.masterMinterAccount, - }); - await token.configureMinter(Accounts.arbitraryAccount, 0, { - from: Accounts.masterMinterAccount, - }); - 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: newBigNumber(amount - mintAmount), - }, - { - variable: "balances.arbitraryAccount2", - expectedValue: newBigNumber(mintAmount), - }, - { variable: "totalSupply", expectedValue: newBigNumber(mintAmount) }, - ]; - await expectRevert( - token.mint(Accounts.arbitraryAccount2, mintAmount, { - from: Accounts.arbitraryAccount, - }) - ); - await checkVariables([token], [customVars]); - }); - - it("ms014 should configure two minters and fail to mint when paused", async function () { - var mintAmount = 10; - - await token.configureMinter(Accounts.minterAccount, amount, { - from: Accounts.masterMinterAccount, - }); - await token.configureMinter(Accounts.arbitraryAccount, amount, { - from: Accounts.masterMinterAccount, - }); - await token.pause({ from: Accounts.pauserAccount }); - var customVars = [ - { variable: "paused", expectedValue: true }, - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { variable: "isAccountMinter.arbitraryAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount), - }, - { - variable: "minterAllowance.arbitraryAccount", - expectedValue: newBigNumber(amount), - }, - ]; - await expectRevert( - token.mint(Accounts.pauserAccount, mintAmount, { - from: Accounts.minterAccount, - }) - ); - await expectRevert( - token.mint(Accounts.pauserAccount, mintAmount, { - from: Accounts.arbitraryAccount, - }) - ); - await checkVariables([token], [customVars]); - }); - - it("ms015 should configure two minters, blacklist one and ensure it cannot mint, then unblacklist and ensure it can mint", async function () { - var mintAmount = 10; - - 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.arbitraryAccount2, mintAmount, { - from: Accounts.arbitraryAccount, - }); - var customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { variable: "isAccountMinter.arbitraryAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount), - }, - { - variable: "minterAllowance.arbitraryAccount", - expectedValue: newBigNumber(amount - mintAmount), - }, - { variable: "isAccountBlacklisted.minterAccount", expectedValue: true }, - { variable: "totalSupply", expectedValue: newBigNumber(mintAmount) }, - { - variable: "balances.arbitraryAccount2", - expectedValue: newBigNumber(mintAmount), - }, - ]; - 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.arbitraryAccount2, mintAmount, { - from: Accounts.minterAccount, - }); - var customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { variable: "isAccountMinter.arbitraryAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount - mintAmount), - }, - { - variable: "minterAllowance.arbitraryAccount", - expectedValue: newBigNumber(amount - mintAmount), - }, - { - variable: "totalSupply", - expectedValue: newBigNumber(mintAmount + mintAmount), - }, - { - variable: "balances.arbitraryAccount2", - expectedValue: newBigNumber(mintAmount + mintAmount), - }, - ]; - await checkVariables([token], [customVars]); - }); - - it("ms016 should configure two minters, each mints to themselves and then burns certain amount", async function () { - var mintAmount1 = 10; - var mintAmount2 = 20; - var burnAmount = 10; - - await token.configureMinter(Accounts.minterAccount, amount, { - from: Accounts.masterMinterAccount, - }); - await token.configureMinter(Accounts.arbitraryAccount, amount, { - from: Accounts.masterMinterAccount, - }); - await token.mint(Accounts.minterAccount, mintAmount1, { - from: Accounts.minterAccount, - }); - await token.mint(Accounts.arbitraryAccount, mintAmount2, { - from: Accounts.arbitraryAccount, - }); - var customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { variable: "isAccountMinter.arbitraryAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount - mintAmount1), - }, - { - variable: "minterAllowance.arbitraryAccount", - expectedValue: newBigNumber(amount - mintAmount2), - }, - { - variable: "balances.minterAccount", - expectedValue: newBigNumber(mintAmount1), - }, - { - variable: "balances.arbitraryAccount", - expectedValue: newBigNumber(mintAmount2), - }, - { - variable: "totalSupply", - expectedValue: newBigNumber(mintAmount1 + mintAmount2), - }, - ]; - await checkVariables([token], [customVars]); - - await token.burn(burnAmount, { from: Accounts.minterAccount }); - await token.burn(burnAmount, { from: Accounts.arbitraryAccount }); - var customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { variable: "isAccountMinter.arbitraryAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount - mintAmount1), - }, - { - variable: "minterAllowance.arbitraryAccount", - expectedValue: newBigNumber(amount - mintAmount2), - }, - { - variable: "balances.minterAccount", - expectedValue: newBigNumber(mintAmount1 - burnAmount), - }, - { - variable: "balances.arbitraryAccount", - expectedValue: newBigNumber(mintAmount2 - burnAmount), - }, - { - variable: "totalSupply", - expectedValue: newBigNumber( - mintAmount1 + mintAmount2 - burnAmount - burnAmount - ), - }, - ]; - await checkVariables([token], [customVars]); - }); - - // 0 Input - - it("ms018 should approve 0 token allowance with unchanged state", async function () { - await token.approve(Accounts.minterAccount, 0, { - from: Accounts.arbitraryAccount, - }); - await checkVariables([token], [[]]); - }); - - it("ms019 should transferFrom 0 tokens with unchanged state", async function () { - await token.transferFrom( - Accounts.arbitraryAccount, - Accounts.pauserAccount, - 0, - { from: Accounts.arbitraryAccount2 } - ); - await checkVariables([token], [[]]); - }); - - it("ms020 should transfer 0 tokens with unchanged state", async function () { - await token.transfer(Accounts.arbitraryAccount, 0, { - from: Accounts.arbitraryAccount2, - }); - await checkVariables([token], [[]]); - }); - - it("ms036 should get allowance for same address", async function () { - await token.approve(Accounts.arbitraryAccount, amount, { - from: Accounts.arbitraryAccount, - }); - var allowance = newBigNumber( - await token.allowance( - Accounts.arbitraryAccount, - Accounts.arbitraryAccount - ) - ); - assert(allowance.cmp(newBigNumber(amount)) == 0); - }); - - // Return value - - /* - * Calls (i.e token.mint.call(...) , token.approve.call(...) etc.) expose the - * return value of functions while transactions (token.mint(...) , - * token.approve(...) etc.) return transaction receipts and do not read - * function return values. Calls, unlike transactions, do not permanently - * modify data. However, both calls and transactions execute code on the - * network. That is, token.mint.call(...) will revert if and only if - * token.mint(...) reverts. - * - * "Choosing between a transaction and a call is as simple as deciding - * whether you want to read data, or write it." - * - truffle docs - * (https://truffleframework.com/docs/getting_started/contracts) - */ - - it("ms039 should return true on mint", async function () { - var mintAmount = 50; - - await token.configureMinter(Accounts.minterAccount, amount, { - from: Accounts.masterMinterAccount, - }); - var customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount), - }, - ]; - assert( - await token.mint.call(Accounts.arbitraryAccount, mintAmount, { - from: Accounts.minterAccount, - }) - ); - await checkVariables([token], [customVars]); - }); - - it("ms040 should return true on approve", async function () { - assert( - await token.approve.call(Accounts.minterAccount, amount, { - from: Accounts.arbitraryAccount, - }) - ); - }); - - it("ms041 should return true on transferFrom", async function () { - let mintAmount = 50; - - await token.configureMinter(Accounts.minterAccount, amount, { - from: Accounts.masterMinterAccount, - }); - var customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount), - }, - ]; - await checkVariables([token], [customVars]); - - await token.mint(Accounts.arbitraryAccount, mintAmount, { - from: Accounts.minterAccount, - }); - await token.approve(Accounts.masterMinterAccount, mintAmount, { - from: Accounts.arbitraryAccount, - }); - customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount - mintAmount), - }, - { - variable: "balances.arbitraryAccount", - expectedValue: newBigNumber(mintAmount), - }, - { variable: "totalSupply", expectedValue: newBigNumber(mintAmount) }, - { - variable: "allowance.arbitraryAccount.masterMinterAccount", - expectedValue: newBigNumber(mintAmount), - }, - ]; - assert( - await token.transferFrom.call( - Accounts.arbitraryAccount, - Accounts.pauserAccount, - mintAmount, - { from: Accounts.masterMinterAccount } - ) - ); - await checkVariables([token], [customVars]); - }); - - it("ms042 should return true on transfer", async function () { - let mintAmount = 50; - - await token.configureMinter(Accounts.minterAccount, amount, { - from: Accounts.masterMinterAccount, - }); - var customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount), - }, - ]; - await checkVariables([token], [customVars]); - - await token.mint(Accounts.arbitraryAccount, mintAmount, { - from: Accounts.minterAccount, - }); - customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount - mintAmount), - }, - { - variable: "balances.arbitraryAccount", - expectedValue: newBigNumber(mintAmount), - }, - { variable: "totalSupply", expectedValue: newBigNumber(mintAmount) }, - ]; - assert( - await token.transfer.call(Accounts.pauserAccount, mintAmount, { - from: Accounts.arbitraryAccount, - }) - ); - await checkVariables([token], [customVars]); - }); - - it("ms043 should return true on configureMinter", async function () { - assert( - await token.configureMinter.call(Accounts.minterAccount, amount, { - from: Accounts.masterMinterAccount, - }) - ); - }); - - it("ms044 should return true on removeMinter", async function () { - assert( - await token.removeMinter.call(Accounts.minterAccount, { - from: Accounts.masterMinterAccount, - }) - ); - }); - - it("ms045 initialized should be in slot 8, byte 21", async function () { - var initialized = await getInitializedV1(token); - assert.equal("0x01", initialized); - }); - - it("ms046 initialized should be 0 before initialization", async function () { - var rawToken = await newToken(); - var newProxy = await FiatTokenProxy.new(rawToken.address, { - from: Accounts.arbitraryAccount, - }); - var token = await FiatToken.at(newProxy.address); - var initialized = await getInitializedV1(token); - assert.equal("0x0", initialized); - }); - - it("ms047 configureMinter works on amount=2^256-1", async function () { - await token.configureMinter(Accounts.minterAccount, maxAmount, { - from: Accounts.masterMinterAccount, - }); - var customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(maxAmount), - }, - ]; - await checkVariables([token], [customVars]); - }); - - it("ms048 mint works on amount=2^256-1", async function () { - await token.configureMinter(Accounts.minterAccount, maxAmount, { - from: Accounts.masterMinterAccount, - }); - var customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(maxAmount), - }, - ]; - await checkVariables([token], [customVars]); - - await token.mint(Accounts.arbitraryAccount, maxAmount, { - from: Accounts.minterAccount, - }); - customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(0), - }, - { - variable: "balances.arbitraryAccount", - expectedValue: newBigNumber(maxAmount), - }, - { variable: "totalSupply", expectedValue: newBigNumber(maxAmount) }, - ]; - await checkVariables([token], [customVars]); - }); - - it("ms049 burn on works on amount=2^256-1", async function () { - await token.configureMinter(Accounts.minterAccount, maxAmount, { - from: Accounts.masterMinterAccount, - }); - await token.mint(Accounts.minterAccount, maxAmount, { - from: Accounts.minterAccount, - }); - customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "balances.minterAccount", - expectedValue: newBigNumber(maxAmount), - }, - { variable: "totalSupply", expectedValue: newBigNumber(maxAmount) }, - ]; - await checkVariables([token], [customVars]); - - await token.burn(maxAmount, { from: Accounts.minterAccount }); - customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - ]; - await checkVariables([token], [customVars]); - }); - - it("ms050 approve 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, - }); - customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "balances.arbitraryAccount", - expectedValue: newBigNumber(maxAmount), - }, - { variable: "totalSupply", expectedValue: newBigNumber(maxAmount) }, - ]; - await checkVariables([token], [customVars]); - - await token.approve(Accounts.arbitraryAccount2, maxAmount, { - from: Accounts.arbitraryAccount, - }); - customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "balances.arbitraryAccount", - expectedValue: newBigNumber(maxAmount), - }, - { variable: "totalSupply", expectedValue: newBigNumber(maxAmount) }, - { - variable: "allowance.arbitraryAccount.arbitraryAccount2", - expectedValue: newBigNumber(maxAmount), - }, - ]; - await checkVariables([token], [customVars]); - }); - - it("ms051 transfer 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, - }); - customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "balances.arbitraryAccount", - expectedValue: newBigNumber(maxAmount), - }, - { variable: "totalSupply", expectedValue: newBigNumber(maxAmount) }, - ]; - await checkVariables([token], [customVars]); - - await token.transfer(Accounts.arbitraryAccount2, maxAmount, { - from: Accounts.arbitraryAccount, - }); - customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "balances.arbitraryAccount2", - expectedValue: newBigNumber(maxAmount), - }, - { variable: "totalSupply", expectedValue: newBigNumber(maxAmount) }, - ]; - await checkVariables([token], [customVars]); - }); - - 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.arbitraryAccount2, maxAmount, { - from: Accounts.arbitraryAccount, - }); - customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "balances.arbitraryAccount", - expectedValue: newBigNumber(maxAmount), - }, - { variable: "totalSupply", expectedValue: newBigNumber(maxAmount) }, - { - variable: "allowance.arbitraryAccount.arbitraryAccount2", - expectedValue: newBigNumber(maxAmount), - }, - ]; - await checkVariables([token], [customVars]); - - await token.transferFrom( - Accounts.arbitraryAccount, - Accounts.arbitraryAccount2, - maxAmount, - { from: Accounts.arbitraryAccount2 } - ); - customVars = [ - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { - variable: "balances.arbitraryAccount2", - expectedValue: newBigNumber(maxAmount), - }, - { variable: "totalSupply", expectedValue: newBigNumber(maxAmount) }, - ]; - await checkVariables([token], [customVars]); - }); -} - -var testWrapper = require("./../TestWrapper"); -testWrapper.execute("FiatToken_MiscTests", run_tests); - -module.exports = { - run_tests: run_tests, -}; diff --git a/test/proxy/ProxyNegativeTests.js b/test/proxy/ProxyNegativeTests.js deleted file mode 100644 index 61d317b45..000000000 --- a/test/proxy/ProxyNegativeTests.js +++ /dev/null @@ -1,248 +0,0 @@ -var tokenUtils = require("./../TokenTestUtils"); -var newBigNumber = tokenUtils.newBigNumber; -var assertDiff = require("assert-diff"); -assertDiff.options.strict = true; - -var bigZero = tokenUtils.bigZero; -var bigHundred = tokenUtils.bigHundred; -var zeroAddress = tokenUtils.zeroAddress; -var mint = tokenUtils.mint; -var expectRevert = tokenUtils.expectRevert; -var checkVariables = tokenUtils.checkVariables; -var name = tokenUtils.name; -var symbol = tokenUtils.symbol; -var currency = tokenUtils.currency; -var decimals = tokenUtils.decimals; -var initializeTokenWithProxy = tokenUtils.initializeTokenWithProxy; -var upgradeTo = tokenUtils.upgradeTo; -var encodeCall = tokenUtils.encodeCall; -var validateTransferEvent = tokenUtils.validateTransferEvent; -var FiatToken = tokenUtils.FiatToken; -var UpgradedFiatToken = tokenUtils.UpgradedFiatToken; -var UpgradedFiatTokenNewFields = tokenUtils.UpgradedFiatTokenNewFields; - -var AccountUtils = require("./../AccountUtils"); -var Accounts = AccountUtils.Accounts; -var addressEquals = AccountUtils.addressEquals; - -var amount = 100; - -async function run_tests(newToken, accounts) { - beforeEach("Make fresh token contract", async function () { - rawToken = await newToken(); - var tokenConfig = await initializeTokenWithProxy(rawToken); - proxy = tokenConfig.proxy; - token = tokenConfig.token; - assert.isTrue(addressEquals(proxy.address, token.address)); - }); - - it("nut002 should fail to switch adminAccount with non-adminAccount as caller", async function () { - await expectRevert( - proxy.changeAdmin(Accounts.masterMinterAccount, { - from: Accounts.masterMinterAccount, - }) - ); - assert.isTrue( - addressEquals( - await proxy.admin({ from: Accounts.proxyOwnerAccount }), - Accounts.proxyOwnerAccount - ) - ); - customVars = []; - await checkVariables([token], [customVars]); - }); - - it("nut003 should fail to upgradeTo to null contract address", async function () { - var upgradedToken = await UpgradedFiatToken.new(); - await expectRevert( - proxy.upgradeTo(zeroAddress, { from: Accounts.proxyOwnerAccount }) - ); - - customVars = []; - await checkVariables([token], [customVars]); - }); - - it("nut004 should fail to upgradeToAndCall to null contract address", async function () { - var upgradedToken = await UpgradedFiatToken.new(); - const initializeData = encodeCall("pauser", [], []); - await expectRevert( - proxy.upgradeToAndCall(zeroAddress, initializeData, { - from: Accounts.proxyOwnerAccount, - }) - ); - - customVars = []; - await checkVariables([token], [customVars]); - }); - - it("nut005 should fail to initialize contract twice", async function () { - await expectRevert( - token.initialize( - name, - symbol, - currency, - decimals, - Accounts.masterMinterAccount, - Accounts.pauserAccount, - Accounts.blacklisterAccount, - Accounts.tokenOwnerAccount - ) - ); - customVars = []; - await checkVariables([token], [customVars]); - }); - - it("nut006 should fail to call contract function with adminAccount", async function () { - await expectRevert( - token.allowance(Accounts.minterAccount, Accounts.arbitraryAccount, { - from: Accounts.proxyOwnerAccount, - }) - ); - - customVars = []; - await checkVariables([token], [customVars]); - }); - - it("nut007 should fail to call proxy function with non-adminAccount", async function () { - await expectRevert(proxy.admin({ from: Accounts.masterMinterAccount })); - - customVars = []; - await checkVariables([token], [customVars]); - }); - - it("nut008 shoud fail to update proxy storage if state-changing function called directly in FiatToken", async function () { - await rawToken.initialize( - name, - symbol, - currency, - decimals, - Accounts.masterMinterAccount, - Accounts.pauserAccount, - Accounts.blacklisterAccount, - Accounts.tokenOwnerAccount - ); - assert.isTrue( - addressEquals(await rawToken.pauser(), Accounts.pauserAccount) - ); - await rawToken.updatePauser(Accounts.masterMinterAccount, { - from: Accounts.tokenOwnerAccount, - }); - assert.isTrue( - addressEquals(await rawToken.pauser(), Accounts.masterMinterAccount) - ); - - customVars = []; - await checkVariables([token], [customVars]); - }); - - it("nut009 should fail to call upgradeTo with non-adminAccount", async function () { - var upgradedToken = await UpgradedFiatToken.new(); - await expectRevert( - proxy.upgradeTo(upgradedToken.address, { - from: Accounts.masterMinterAccount, - }) - ); - var finalToken = await FiatToken.at(proxy.address); - var implementation = await proxy.implementation({ - from: Accounts.proxyOwnerAccount, - }); - finalToken.proxiedTokenAddress = implementation; - - customVars = []; - await checkVariables([finalToken], [customVars]); - }); - - it("nut010 should fail to call updateToAndCall with non-adminAccount", async function () { - var upgradedToken = await UpgradedFiatTokenNewFields.new(); - const initializeData = encodeCall( - "initialize", - ["bool", "address", "uint256"], - [true, Accounts.pauserAccount, 12] - ); - await expectRevert( - proxy.upgradeToAndCall(upgradedToken.address, initializeData, { - from: Accounts.masterMinterAccount, - }) - ); - var finalToken = await FiatToken.at(proxy.address); - var implementation = await proxy.implementation({ - from: Accounts.proxyOwnerAccount, - }); - finalToken.proxiedTokenAddress = implementation; - - customVars = []; - await checkVariables([finalToken], [customVars]); - }); - - it("nut011 should fail to upgradeToAndCall with initialize (already set variables)", async function () { - let mintAmount = 50; - - await token.configureMinter(Accounts.minterAccount, amount, { - from: Accounts.masterMinterAccount, - }); - await token.mint(Accounts.arbitraryAccount, mintAmount, { - from: Accounts.minterAccount, - }); - await token.transfer(Accounts.arbitraryAccount2, mintAmount, { - from: Accounts.arbitraryAccount, - }); - - var upgradedToken = await UpgradedFiatTokenNewFields.new(); - var data = encodeCall( - "initialize", - [ - "string", - "string", - "string", - "uint8", - "address", - "address", - "address", - "address", - "bool", - "address", - "uint256", - ], - [ - name, - symbol, - currency, - decimals, - Accounts.masterMinterAccount, - Accounts.arbitraryAccount2, - Accounts.blacklisterAccount, - Accounts.tokenOwnerAccount, - true, - Accounts.arbitraryAccount2, - 12, - ] - ); - await expectRevert( - proxy.upgradeToAndCall(upgradedToken.address, data, { - from: Accounts.proxyOwnerAccount, - }) - ); - - customVars = [ - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount - mintAmount), - }, - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { variable: "balances.arbitraryAccount", expectedValue: bigZero }, - { - variable: "balances.arbitraryAccount2", - expectedValue: newBigNumber(mintAmount), - }, - { variable: "totalSupply", expectedValue: newBigNumber(mintAmount) }, - ]; - await checkVariables([token], [customVars]); - }); -} - -var testWrapper = require("./../TestWrapper"); -testWrapper.execute("FiatToken_ProxyNegativeTests", run_tests); - -module.exports = { - run_tests: run_tests, -}; diff --git a/test/proxy/ProxyPositiveTests.js b/test/proxy/ProxyPositiveTests.js deleted file mode 100644 index 97567ed33..000000000 --- a/test/proxy/ProxyPositiveTests.js +++ /dev/null @@ -1,535 +0,0 @@ -var tokenUtils = require("./../TokenTestUtils"); -var newBigNumber = tokenUtils.newBigNumber; -var assertDiff = require("assert-diff"); -assertDiff.options.strict = true; - -var bigZero = tokenUtils.bigZero; -var bigHundred = tokenUtils.bigHundred; -var mint = tokenUtils.mint; -var checkVariables = tokenUtils.checkVariables; -var name = tokenUtils.name; -var symbol = tokenUtils.symbol; -var currency = tokenUtils.currency; -var decimals = tokenUtils.decimals; - -var initializeTokenWithProxy = tokenUtils.initializeTokenWithProxy; -var upgradeTo = tokenUtils.upgradeTo; -var encodeCall = tokenUtils.encodeCall; -var validateTransferEvent = tokenUtils.validateTransferEvent; -var FiatToken = tokenUtils.FiatToken; -var FiatTokenProxy = tokenUtils.FiatTokenProxy; -var UpgradedFiatToken = tokenUtils.UpgradedFiatToken; -var UpgradedFiatTokenNewFields = tokenUtils.UpgradedFiatTokenNewFields; -var UpgradedFiatTokenNewFieldsNewLogic = - tokenUtils.UpgradedFiatTokenNewFieldsNewLogic; -var getAdmin = tokenUtils.getAdmin; - -var abiUtils = require("./../ABIUtils"); -var makeRawTransaction = abiUtils.makeRawTransaction; -var sendRawTransaction = abiUtils.sendRawTransaction; - -var AccountUtils = require("./../AccountUtils"); -var Accounts = AccountUtils.Accounts; -var AccountPrivateKeys = AccountUtils.AccountPrivateKeys; -var addressEquals = AccountUtils.addressEquals; -var addressNotEquals = AccountUtils.addressNotEquals; - -var amount = 100; - -async function run_tests(newToken, accounts) { - beforeEach("Make fresh token contract", async function () { - rawToken = await newToken(); - var tokenConfig = await initializeTokenWithProxy(rawToken); - proxy = tokenConfig.proxy; - token = tokenConfig.token; - assert.isTrue(addressEquals(proxy.address, token.address)); - }); - - it("upt001 should upgradeTo new contract and preserve data field values", async function () { - let mintAmount = 50; - - await token.configureMinter(Accounts.minterAccount, amount, { - from: Accounts.masterMinterAccount, - }); - await token.mint(Accounts.arbitraryAccount, mintAmount, { - from: Accounts.minterAccount, - }); - await token.transfer(Accounts.arbitraryAccount2, mintAmount, { - from: Accounts.arbitraryAccount, - }); - - var upgradedToken = await UpgradedFiatToken.new(); - var tokenConfig = await upgradeTo( - proxy, - upgradedToken, - Accounts.proxyOwnerAccount - ); - var newToken = tokenConfig.token; - - customVars = [ - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount - mintAmount), - }, - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { variable: "balances.arbitraryAccount", expectedValue: bigZero }, - { - variable: "balances.arbitraryAccount2", - expectedValue: newBigNumber(mintAmount), - }, - { variable: "totalSupply", expectedValue: newBigNumber(mintAmount) }, - { variable: "proxiedTokenAddress", expectedValue: upgradedToken.address }, - ]; - await checkVariables([newToken], [customVars]); - }); - - it("upt002 should upgradeToandCall to contract with new data fields set on initVX and ensure new fields are correct and old data is preserved", async function () { - let mintAmount = 50; - - await token.configureMinter(Accounts.minterAccount, amount, { - from: Accounts.masterMinterAccount, - }); - await token.mint(Accounts.arbitraryAccount, mintAmount, { - from: Accounts.minterAccount, - }); - await token.transfer(Accounts.arbitraryAccount2, mintAmount, { - from: Accounts.arbitraryAccount, - }); - - var upgradedToken = await UpgradedFiatTokenNewFields.new(); - const initializeData = encodeCall( - "initV2", - ["bool", "address", "uint256"], - [true, Accounts.pauserAccount, 12] - ); - await proxy.upgradeToAndCall(upgradedToken.address, initializeData, { - from: Accounts.proxyOwnerAccount, - }); - newProxiedToken = await UpgradedFiatTokenNewFields.at(proxy.address); - assert.isTrue(addressEquals(newProxiedToken.address, proxy.address)); - addressNotEquals(newProxiedToken.address, upgradedToken.address); - - assert.equal(await newProxiedToken.newBool(), true); - assert.isTrue( - addressEquals(await newProxiedToken.newAddress(), Accounts.pauserAccount) - ); - assert.equal(newBigNumber(12).cmp(await newProxiedToken.newUint()), 0); - - customVars = [ - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount - mintAmount), - }, - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { variable: "balances.arbitraryAccount", expectedValue: bigZero }, - { - variable: "balances.arbitraryAccount2", - expectedValue: newBigNumber(mintAmount), - }, - { variable: "totalSupply", expectedValue: newBigNumber(mintAmount) }, - { variable: "proxiedTokenAddress", expectedValue: upgradedToken.address }, - ]; - await checkVariables([newProxiedToken], [customVars]); - }); - - it("upt003 should upgradeToAndCall to contract with new data fields set on initVX and new logic and ensure old data preserved,new logic works, and new fields correct", async function () { - let mintAmount = 50; - - await token.configureMinter(Accounts.minterAccount, amount, { - from: Accounts.masterMinterAccount, - }); - await token.mint(Accounts.arbitraryAccount, mintAmount, { - from: Accounts.minterAccount, - }); - await token.transfer(Accounts.arbitraryAccount2, mintAmount, { - from: Accounts.arbitraryAccount, - }); - - var upgradedToken = await UpgradedFiatTokenNewFieldsNewLogic.new(); - const initializeData = encodeCall( - "initV2", - ["bool", "address", "uint256"], - [true, Accounts.pauserAccount, 12] - ); - await proxy.upgradeToAndCall(upgradedToken.address, initializeData, { - from: Accounts.proxyOwnerAccount, - }); - newProxiedToken = await UpgradedFiatTokenNewFieldsNewLogic.at( - proxy.address - ); - assert.isTrue(addressEquals(newProxiedToken.address, proxy.address)); - addressNotEquals(newProxiedToken.address, upgradedToken.address); - - assert.equal(await newProxiedToken.newBool(), true); - assert.isTrue( - addressEquals(await newProxiedToken.newAddress(), Accounts.pauserAccount) - ); - assert.equal(newBigNumber(12).cmp(await newProxiedToken.newUint()), 0); - - await newProxiedToken.setNewAddress(Accounts.masterMinterAccount); - assert.isTrue( - addressEquals( - await newProxiedToken.newAddress(), - Accounts.masterMinterAccount - ) - ); - - customVars = [ - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount - mintAmount), - }, - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { variable: "balances.arbitraryAccount", expectedValue: bigZero }, - { - variable: "balances.arbitraryAccount2", - expectedValue: newBigNumber(mintAmount), - }, - { variable: "totalSupply", expectedValue: newBigNumber(mintAmount) }, - { variable: "proxiedTokenAddress", expectedValue: upgradedToken.address }, - ]; - await checkVariables([newProxiedToken], [customVars]); - }); - - it("upt008 should deploy upgraded version of contract with new data fields and without previous deployment and ensure new fields correct", async function () { - var upgradedToken = await UpgradedFiatTokenNewFields.new(); - const newProxy = await FiatTokenProxy.new(upgradedToken.address, { - from: Accounts.proxyOwnerAccount, - }); - proxiedToken = await UpgradedFiatTokenNewFields.at(newProxy.address); - - var data = encodeCall( - "initialize", - [ - "string", - "string", - "string", - "uint8", - "address", - "address", - "address", - "address", - "bool", - "address", - "uint256", - ], - [ - name, - symbol, - currency, - decimals, - Accounts.masterMinterAccount, - Accounts.pauserAccount, - Accounts.blacklisterAccount, - Accounts.tokenOwnerAccount, - true, - Accounts.pauserAccount, - 12, - ] - ); - var upgradeToRawTx = await makeRawTransaction( - data, - Accounts.masterMinterAccount, - AccountPrivateKeys.masterMinterPrivateKey, - proxiedToken.address - ); - await sendRawTransaction(upgradeToRawTx); - - assert.equal(await proxiedToken.newUint(), 12); - assert.equal(await proxiedToken.newBool(), true); - assert.isTrue( - addressEquals(await proxiedToken.newAddress(), Accounts.pauserAccount) - ); - - customVars = [ - { variable: "proxiedTokenAddress", expectedValue: upgradedToken.address }, - ]; - await checkVariables([proxiedToken], [customVars]); - }); - - it("upt010 should deploy upgraded version of contract with new data fields and logic without previous deployment and ensure new logic works, and new fields correct", async function () { - var upgradedToken = await UpgradedFiatTokenNewFields.new(); - const newProxy = await FiatTokenProxy.new(upgradedToken.address, { - from: Accounts.proxyOwnerAccount, - }); - proxiedToken = await UpgradedFiatTokenNewFields.at(newProxy.address); - - var data = encodeCall( - "initialize", - [ - "string", - "string", - "string", - "uint8", - "address", - "address", - "address", - "address", - "bool", - "address", - "uint256", - ], - [ - name, - symbol, - currency, - decimals, - Accounts.masterMinterAccount, - Accounts.pauserAccount, - Accounts.blacklisterAccount, - Accounts.tokenOwnerAccount, - true, - Accounts.pauserAccount, - 12, - ] - ); - var upgradeToRawTx = await makeRawTransaction( - data, - Accounts.masterMinterAccount, - AccountPrivateKeys.masterMinterPrivateKey, - proxiedToken.address - ); - await sendRawTransaction(upgradeToRawTx); - - assert.equal(await proxiedToken.newUint(), 12); - assert.equal(await proxiedToken.newBool(), true); - assert.isTrue( - addressEquals(await proxiedToken.newAddress(), Accounts.pauserAccount) - ); - - await newProxiedToken.setNewAddress(Accounts.masterMinterAccount); - assert.isTrue( - addressEquals( - await newProxiedToken.newAddress(), - Accounts.masterMinterAccount - ) - ); - - customVars = [ - { variable: "proxiedTokenAddress", expectedValue: upgradedToken.address }, - ]; - await checkVariables([proxiedToken], [customVars]); - }); - - it("upt004 should update proxy adminAccount with previous adminAccount", async function () { - await proxy.changeAdmin(Accounts.masterMinterAccount, { - from: Accounts.proxyOwnerAccount, - }); - customVars = [ - { variable: "proxyOwner", expectedValue: Accounts.masterMinterAccount }, - ]; - await checkVariables([token], [customVars]); - }); - - it("upt005 should receive Transfer event on transfer when proxied after upgrade", async function () { - let mintAmount = 50; - - await token.configureMinter(Accounts.minterAccount, amount, { - from: Accounts.masterMinterAccount, - }); - await token.mint(Accounts.arbitraryAccount, mintAmount + 1, { - from: Accounts.minterAccount, - }); - await token.transfer(Accounts.arbitraryAccount2, mintAmount, { - from: Accounts.arbitraryAccount, - }); - - var upgradedToken = await UpgradedFiatToken.new(); - var tokenConfig = await upgradeTo( - proxy, - upgradedToken, - Accounts.proxyOwnerAccount - ); - var newToken = tokenConfig.token; - - transfer = await newToken.transfer(Accounts.arbitraryAccount2, 1, { - from: Accounts.arbitraryAccount, - }); - validateTransferEvent( - transfer, - Accounts.arbitraryAccount, - Accounts.arbitraryAccount2, - 1 - ); - - customVars = [ - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount - mintAmount - 1), - }, - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { variable: "balances.arbitraryAccount", expectedValue: bigZero }, - { - variable: "balances.arbitraryAccount2", - expectedValue: newBigNumber(mintAmount + 1), - }, - { variable: "totalSupply", expectedValue: newBigNumber(mintAmount + 1) }, - { variable: "proxiedTokenAddress", expectedValue: upgradedToken.address }, - ]; - await checkVariables([newToken], [customVars]); - }); - - it("upt006 should upgrade while paused and upgraded contract should be paused as a result; then unpause should unpause contract", async function () { - await token.pause({ from: Accounts.pauserAccount }); - var upgradedToken = await UpgradedFiatToken.new(); - var tokenConfig = await upgradeTo( - proxy, - upgradedToken, - Accounts.proxyOwnerAccount - ); - var newToken = tokenConfig.token; - - customVars = [ - { variable: "paused", expectedValue: true }, - { variable: "proxiedTokenAddress", expectedValue: upgradedToken.address }, - ]; - await checkVariables([newToken], [customVars]); - - await newToken.unpause({ from: Accounts.pauserAccount }); - - customVars2 = [ - { variable: "proxiedTokenAddress", expectedValue: upgradedToken.address }, - ]; - await checkVariables([newToken], [customVars2]); - }); - - it("upt007 should upgrade contract to original address", async function () { - let mintAmount = 50; - - await token.configureMinter(Accounts.minterAccount, amount, { - from: Accounts.masterMinterAccount, - }); - await token.mint(Accounts.arbitraryAccount, mintAmount, { - from: Accounts.minterAccount, - }); - await token.transfer(Accounts.arbitraryAccount2, mintAmount, { - from: Accounts.arbitraryAccount, - }); - - var tokenConfig = await upgradeTo( - proxy, - rawToken, - Accounts.proxyOwnerAccount - ); - var sameToken = tokenConfig.token; - sameToken.proxiedTokenAddress = rawToken.address; - - customVars = [ - { - variable: "minterAllowance.minterAccount", - expectedValue: newBigNumber(amount - mintAmount), - }, - { variable: "isAccountMinter.minterAccount", expectedValue: true }, - { variable: "balances.arbitraryAccount", expectedValue: bigZero }, - { - variable: "balances.arbitraryAccount2", - expectedValue: newBigNumber(mintAmount), - }, - { variable: "totalSupply", expectedValue: newBigNumber(mintAmount) }, - ]; - await checkVariables([sameToken], [customVars]); - }); - - it("upt009 should check that admin is set correctly by proxy constructor", async function () { - assert.isTrue( - addressEquals(await getAdmin(token), Accounts.proxyOwnerAccount) - ); - }); - - it("upt011 should upgradeToAndCall while paused and upgraded contract should be paused as a result", async function () { - await token.pause({ from: Accounts.pauserAccount }); - - var upgradedToken = await UpgradedFiatTokenNewFields.new(); - const initializeData = encodeCall( - "initV2", - ["bool", "address", "uint256"], - [true, Accounts.pauserAccount, 12] - ); - await proxy.upgradeToAndCall(upgradedToken.address, initializeData, { - from: Accounts.proxyOwnerAccount, - }); - newProxiedToken = await UpgradedFiatTokenNewFields.at(proxy.address); - assert.isTrue(addressEquals(newProxiedToken.address, proxy.address)); - addressNotEquals(newProxiedToken.address, upgradedToken.address); - - customVars = [ - { variable: "paused", expectedValue: true }, - { variable: "proxiedTokenAddress", expectedValue: upgradedToken.address }, - ]; - await checkVariables([newProxiedToken], [customVars]); - }); - - it("upt012 should upgradeToAndCall while proxyOwner is blacklisted", async function () { - await token.blacklist(Accounts.proxyOwnerAccount, { - from: Accounts.blacklisterAccount, - }); - - var upgradedToken = await UpgradedFiatTokenNewFields.new(); - const initializeData = encodeCall( - "initV2", - ["bool", "address", "uint256"], - [true, Accounts.pauserAccount, 12] - ); - await proxy.upgradeToAndCall(upgradedToken.address, initializeData, { - from: Accounts.proxyOwnerAccount, - }); - newProxiedToken = await UpgradedFiatTokenNewFields.at(proxy.address); - - customVars = [ - { - variable: "isAccountBlacklisted.proxyOwnerAccount", - expectedValue: true, - }, - { variable: "proxiedTokenAddress", expectedValue: upgradedToken.address }, - ]; - await checkVariables([newProxiedToken], [customVars]); - }); - - it("upt013 should upgradeToAndCall while new logic is blacklisted", async function () { - var upgradedToken = await UpgradedFiatTokenNewFields.new(); - await token.blacklist(upgradedToken.address, { - from: Accounts.blacklisterAccount, - }); - - const initializeData = encodeCall( - "initV2", - ["bool", "address", "uint256"], - [true, Accounts.pauserAccount, 12] - ); - await proxy.upgradeToAndCall(upgradedToken.address, initializeData, { - from: Accounts.proxyOwnerAccount, - }); - newProxiedToken = await UpgradedFiatTokenNewFields.at(proxy.address); - - customVars = [ - { variable: "proxiedTokenAddress", expectedValue: upgradedToken.address }, - ]; - await checkVariables([newProxiedToken], [customVars]); - }); - - it("upt014 should upgradeTo while new logic is blacklisted", async function () { - var upgradedToken = await UpgradedFiatToken.new(); - await token.blacklist(upgradedToken.address, { - from: Accounts.blacklisterAccount, - }); - - var tokenConfig = await upgradeTo( - proxy, - upgradedToken, - Accounts.proxyOwnerAccount - ); - var newToken = tokenConfig.token; - - customVars = [ - { variable: "proxiedTokenAddress", expectedValue: upgradedToken.address }, - ]; - await checkVariables([newToken], [customVars]); - }); -} - -var testWrapper = require("./../TestWrapper"); -testWrapper.execute("FiatToken_ProxyPositiveTests", run_tests); - -module.exports = { - run_tests: run_tests, -}; diff --git a/test/v1/TokenTestUtils.js b/test/v1/TokenTestUtils.js index 02224d005..c5ab49002 100644 --- a/test/v1/TokenTestUtils.js +++ b/test/v1/TokenTestUtils.js @@ -1,8 +1,8 @@ const util = require("util"); -const abi = require("ethereumjs-abi"); const _ = require("lodash"); const BN = require("bn.js"); const Q = require("q"); +const BigNumber = require("bignumber.js"); const FiatTokenV1 = artifacts.require("FiatTokenV1"); const UpgradedFiatToken = artifacts.require("UpgradedFiatToken"); @@ -21,9 +21,8 @@ const decimals = 2; const trueInStorageFormat = "0x01"; const bigZero = new BN(0); const bigHundred = new BN(100); - -// TODO: test really big numbers Does this still have to be done?? - +const maxAmount = + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"; const nullAccount = "0x0000000000000000000000000000000000000000"; const deployerAccount = "0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1"; // accounts[0] const arbitraryAccount = "0xFFcf8FDEE72ac11b5c542428B35EEF5769C409f0"; // accounts[1] @@ -66,47 +65,23 @@ const implSlot = // set to true to enable verbose logging in the tests const debugLogging = false; -function calculateFeeAmount(amount, fee, feeBase) { - return Math.floor((fee / feeBase) * amount); -} - -function checkMinterConfiguredEvent( - configureMinterEvent, - minter, - minterAllowedAmount -) { - assert.strictEqual(configureMinterEvent.logs[0].event, "MinterConfigured"); - assert.strictEqual(configureMinterEvent.logs[0].args.minter, minter); - assert.isTrue( - configureMinterEvent.logs[0].args.minterAllowedAmount.eq( - new BN(minterAllowedAmount) - ) - ); -} - -function checkMinterRemovedEvent(minterRemovedEvent, minter) { - assert.strictEqual(minterRemovedEvent.logs[0].event, "MinterRemoved"); - assert.strictEqual(minterRemovedEvent.logs[0].args.oldMinter, minter); -} - -function checkTransferEvents(transferEvent, from, to, value) { - assert.strictEqual(transferEvent.logs[0].event, "Transfer"); - assert.strictEqual(transferEvent.logs[0].args.from, from); - assert.strictEqual(transferEvent.logs[0].args.to, to); - assert.isTrue(transferEvent.logs[0].args.value.eq(new BN(value))); -} - -function checkApprovalEvent(approvalEvent, approver, spender, value) { - assert.strictEqual(approvalEvent.logs[0].event, "Approval"); - assert.strictEqual(approvalEvent.logs[0].args.owner, approver); - assert.strictEqual(approvalEvent.logs[0].args.spender, spender); - assert.isTrue(approvalEvent.logs[0].args.value.eq(new BN(value))); +// Returns a new BN object +function newBigNumber(value) { + const hex = new BigNumber(value).toString(16); + return new BN(hex, 16); } -function checkBurnEvent(burnEvent, burner, amount) { - assert.strictEqual(burnEvent.logs[0].event, "Burn"); - assert.strictEqual(burnEvent.logs[0].args.burner, burner); - assert.isTrue(burnEvent.logs[0].args.amount.eq(new BN(amount))); +async function expectError(contractPromise, errorMsg) { + try { + await contractPromise; + assert.fail("Expected error " + errorMsg + ", but no error received"); + } catch (error) { + const correctErrorMsgReceived = error.message.includes(errorMsg); + assert( + correctErrorMsgReceived, + `Expected ${errorMsg}, got ${error.message} instead` + ); + } } function checkBlacklistEvent(blacklistEvent, account) { @@ -119,68 +94,6 @@ function checkUnblacklistEvent(unblacklistEvent, account) { assert.strictEqual(unblacklistEvent.logs[0].args._account, account); } -function checkBlacklisterChangedEvent(blacklisterChangedEvent, blacklister) { - assert.strictEqual( - blacklisterChangedEvent.logs[0].event, - "BlacklisterChanged" - ); - assert.strictEqual( - blacklisterChangedEvent.logs[0].args.newBlacklister, - blacklister - ); -} - -function checkPauserChangedEvent(pauserChangedEvent, pauser) { - assert.strictEqual(pauserChangedEvent.logs[0].event, "PauserChanged"); - assert.strictEqual(pauserChangedEvent.logs[0].args.newAddress, pauser); -} - -function checkTransferOwnershipEvent( - transferOwnershipEvent, - previousOwner, - newOwner -) { - assert.strictEqual( - transferOwnershipEvent.logs[0].event, - "OwnershipTransferred" - ); - assert.strictEqual( - transferOwnershipEvent.logs[0].args.previousOwner, - previousOwner - ); - assert.strictEqual(transferOwnershipEvent.logs[0].args.newOwner, newOwner); -} - -function checkUpdateMasterMinterEvent(updateMasterMinter, newMasterMinter) { - assert.strictEqual(updateMasterMinter.logs[0].event, "MasterMinterChanged"); - assert.strictEqual( - updateMasterMinter.logs[0].args.newMasterMinter, - newMasterMinter - ); -} - -function checkAdminChangedEvent(adminChangedEvent, previousAdmin, newAdmin) { - assert.strictEqual(adminChangedEvent.logs[0].event, "AdminChanged"); - assert.strictEqual( - adminChangedEvent.logs[0].args.previousAdmin, - previousAdmin - ); - assert.strictEqual(adminChangedEvent.logs[0].args.newAdmin, newAdmin); -} - -function checkUpgradeEvent(upgradeEvent, implementation) { - assert.strictEqual(upgradeEvent.logs[0].event, "Upgraded"); - assert.strictEqual(upgradeEvent.logs[0].args.implementation, implementation); -} - -function checkPauseEvent(pause) { - assert.strictEqual(pause.logs[0].event, "Pause"); -} - -function checkUnpauseEvent(unpause) { - assert.strictEqual(unpause.logs[0].event, "Unpause"); -} - function checkMintEvent(minting, to, amount, minter) { // Mint Event assert.strictEqual(minting.logs[0].event, "Mint"); @@ -781,57 +694,6 @@ async function unBlacklist(token, account) { checkUnblacklistEvent(unblacklist, account); } -async function sampleTransfer(token, ownerAccount, arbitraryAccount, minter) { - let allowed = await token.allowance.call(ownerAccount, arbitraryAccount); - assert.isTrue(new BN(allowed).eqn(0)); - await mint(token, ownerAccount, 1900, minter); - - await token.approve(arbitraryAccount, 1500); - allowed = await token.allowance.call(ownerAccount, arbitraryAccount); - assert.isTrue(new BN(allowed).eqn(1500)); - - const transfer = await token.transfer(arbitraryAccount, 1000, { - from: ownerAccount, - }); - - checkTransferEvents(transfer, ownerAccount, arbitraryAccount, 1000); - - const balance0 = await token.balanceOf(ownerAccount); - assert.isTrue(balance0.eqn(1900 - 1000)); - const balance3 = await token.balanceOf(arbitraryAccount); - assert.isTrue(balance3.eqn(1000)); -} - -async function sampleTransferFrom( - token, - ownerAccount, - arbitraryAccount, - minter -) { - let allowed = await token.allowance.call(ownerAccount, arbitraryAccount); // TODO not this - assert.isTrue(new BN(allowed).eqn(0)); - await mint(token, ownerAccount, 900, minter); // TODO maybe this - await token.approve(arbitraryAccount, 634); // TODO not this - allowed = await token.allowance.call(ownerAccount, arbitraryAccount); // TODO not this - assert.isTrue(new BN(allowed).eqn(634)); - - const transfer = await token.transferFrom( - ownerAccount, - arbitraryAccount, - 534, - { - from: arbitraryAccount, - } - ); // TODO not this - - checkTransferEvents(transfer, ownerAccount, arbitraryAccount, 534); - - const balance0 = await token.balanceOf(ownerAccount); - assert.isTrue(new BN(balance0).eqn(900 - 534)); - const balance3 = await token.balanceOf(arbitraryAccount); - assert.isTrue(new BN(balance3).eqn(534)); -} - async function approve(token, to, amount, from) { await token.approve(to, amount, { from }); } @@ -843,14 +705,6 @@ async function redeem(token, account, amount) { assert.isTrue(redeemResult.logs[0].args.amount.eq(new BN(amount))); } -function validateTransferEvent(transferEvent, from, to, value) { - const eventResult = transferEvent.logs[0]; - assert.strictEqual(eventResult.event, "Transfer"); - assert.strictEqual(eventResult.args.from, from); - assert.strictEqual(eventResult.args.to, to); - assert.isTrue(eventResult.args.value.eq(new BN(value))); -} - async function initializeTokenWithProxy(rawToken) { return customInitializeTokenWithProxy( rawToken, @@ -918,24 +772,6 @@ async function expectRevert(contractPromise) { assert.fail("Expected error of type revert, but no error was received"); } -async function expectJump(contractPromise) { - try { - await contractPromise; - assert.fail("Expected invalid opcode not received"); - } catch (error) { - assert.isTrue( - error.message.includes("invalid opcode"), - `Expected "invalid opcode", got ${error} instead` - ); - } -} - -function encodeCall(name, args, values) { - const methodId = abi.methodID(name, args).toString("hex"); - const params = abi.rawEncode(args, values).toString("hex"); - return "0x" + methodId + params; -} - async function getAdmin(proxy) { const adm = await web3.eth.getStorageAt(proxy.address, adminSlot); return web3.utils.toChecksumAddress("0x" + adm.slice(2).padStart(40, "0")); @@ -971,6 +807,20 @@ async function getInitializedV1(token) { return initialized; } +// _contracts is an array of exactly two values: a FiatTokenV1 and a MintController +// _customVars is an array of exactly two values: the expected state of the FiatTokenV1 +// and the expected state of the MintController +async function checkMINTp0(_contracts, _customVars) { + assert.equal(_contracts.length, 2); + assert.equal(_customVars.length, 2); + + // the first is a FiatTokenV1 + await checkVariables([_contracts[0]], [_customVars[0]]); + + // the second is a MintController + await _customVars[1].checkState(_contracts[1]); +} + module.exports = { FiatTokenV1, FiatTokenProxy, @@ -984,44 +834,18 @@ module.exports = { bigZero, bigHundred, debugLogging, - calculateFeeAmount, - checkTransferEvents, - checkMinterConfiguredEvent, - checkMintEvent, - checkApprovalEvent, - checkBurnEvents, - checkBurnEvent, - checkMinterRemovedEvent, - checkBlacklistEvent, - checkUnblacklistEvent, - checkPauseEvent, - checkUnpauseEvent, - checkPauserChangedEvent, - checkTransferOwnershipEvent, - checkUpdateMasterMinterEvent, - checkBlacklisterChangedEvent, - checkUpgradeEvent, - checkAdminChangedEvent, - buildExpectedState, - checkVariables, - setMinter, + maxAmount, + checkMINTp0, mint, burn, - mintRaw, blacklist, unBlacklist, - sampleTransfer, - sampleTransferFrom, approve, redeem, - validateTransferEvent, initializeTokenWithProxy, - customInitializeTokenWithProxy, upgradeTo, expectRevert, - expectJump, - encodeCall, - getInitializedV1, + expectError, nullAccount, deployerAccount, arbitraryAccount, @@ -1034,7 +858,6 @@ module.exports = { proxyOwnerAccount, proxyOwnerAccountPrivateKey, upgraderAccount, - getAdmin, arbitraryAccountPrivateKey, upgraderAccountPrivateKey, tokenOwnerPrivateKey, @@ -1044,4 +867,5 @@ module.exports = { minterAccountPrivateKey, pauserAccountPrivateKey, deployerAccountPrivateKey, + newBigNumber, }; diff --git a/test/v1/helpers/tokenTest.js b/test/v1/helpers/tokenTest.js index 25e9799ea..a223104b1 100644 --- a/test/v1/helpers/tokenTest.js +++ b/test/v1/helpers/tokenTest.js @@ -918,18 +918,6 @@ async function expectRevert(contractPromise) { assert.fail("Expected error of type revert, but no error was received"); } -async function expectJump(contractPromise) { - try { - await contractPromise; - assert.fail("Expected invalid opcode not received"); - } catch (error) { - assert.isTrue( - error.message.includes("invalid opcode"), - `Expected "invalid opcode", got ${error} instead` - ); - } -} - function encodeCall(name, args, values) { const methodId = abi.methodID(name, args).toString("hex"); const params = abi.rawEncode(args, values).toString("hex"); @@ -1019,7 +1007,6 @@ module.exports = { customInitializeTokenWithProxy, upgradeTo, expectRevert, - expectJump, encodeCall, getInitializedV1, nullAccount, diff --git a/truffle.js b/truffle.js deleted file mode 100644 index 11ba9196f..000000000 --- a/truffle.js +++ /dev/null @@ -1,62 +0,0 @@ -// INFURA Setup - see validate/README.validate.md for more info -var HDWalletProvider = require("truffle-hdwallet-provider"); // These keys will be used only for CALL -var mnemonic = "talisman"; -var fs = require("fs"); -var access_token = "none"; -try { - access_token = fs.readFileSync("./validate/apikey.infura", "utf8"); -} catch (err) { - console.log( - "No Infura access token detected. Unit tests will still work. See ./validate/README.validate.md for more details." - ); -} - -module.exports = { - compilers: { - solc: { - version: "0.4.24", - }, - }, - networks: { - development: { - host: "localhost", - port: 8545, - network_id: "*", // Match any network id - }, - // solidity-coverage looks for a network called 'coverage' and makes one - // identical to this one if it is not found. We want solidity coverage to - // accept this truffle.js file as valid so it will use our custom reporter, - // so we add the 'coverage' network manually here. - coverage: { - host: "localhost", - network_id: "*", - port: 8555, - gas: 17592186044415, - gasPrice: 1, - }, - // network to refer to ganache by name so it works with truffle/ganache in separate docker containers - localTestNet: { - host: "ganache", - port: 8545, - network_id: "*", // Match any network id - }, - // INFURA Setup - infura_mainnet: { - provider: function () { - return new HDWalletProvider( - mnemonic, - "https://mainnet.infura.io/" + access_token - ); - }, - network_id: 1, - }, - }, - mocha: { - /* - * To disable the spreadsheet verification tool ensure that - * the reporter is set to 'Spec' by commenting/uncommenting the lines below. - */ - // reporter: 'Spec', - reporter: "verification/verification_reporter.js", - }, -}; diff --git a/verification/spreadsheet_parser.js b/verification/spreadsheet_parser.js deleted file mode 100644 index 72209d4d9..000000000 --- a/verification/spreadsheet_parser.js +++ /dev/null @@ -1,146 +0,0 @@ -var fs = require("fs"); -var parse = require("csv-parse/lib/sync"); -// NOTE: SPREADSHEETS_DIR must be relative to truffle.js -var SPREADSHEETS_DIR = "./verification/Spreadsheets"; - -function UnitTest(code, description, pending) { - this.code = code; - this.description = description; - this.pending = pending; -} - -/* - UnitTestDirectory is a literal object. - Keys - names of unit test suites - Values - a UnitTestSet - - UnitTestSet is a literal object - Keys - codes associated with unit tests - Values - an instance of a UnitTest object -* - - -/** -* Reads all files in Spreadsheets directory and returns an oject with their contents -* Returns a UnitTestDirectory object -* TODO: handle errors, null objects -*/ -function load() { - var unitTestDirectory = {}; - - // get names of all files in SPREADSHEETS_DIR - var files = fs.readdirSync(SPREADSHEETS_DIR, (err, data) => { - if (err) { - console.log("error reading " + SPREADSHEETS_DIR + " " + err); - return null; - } - return data; - }); - // process each file into a unitTestSet, then add the - // unitTestSet to unitTestDirectory - files.forEach((file) => { - var csvFileContents = fs.readFileSync( - SPREADSHEETS_DIR + "/" + file, - "utf8" - ); - if (csvFileContents != null) { - var unitTestSet = {}; - var spreadsheet = parse(csvFileContents, { columns: true }); - spreadsheet.forEach((row) => { - if (file.match("Completeness")) { - var unitTestArray = parseCompletenessRow(row); - unitTestArray.forEach((unitTest) => { - unitTestSet[unitTest.code] = unitTest; - }); - } else { - var unitTest = parseRow(row); - unitTestSet[unitTest.code] = unitTest; - } - }); - var unittestfilename = getTestSuiteTitle(file); - unitTestDirectory[unittestfilename] = unitTestSet; - } - }); - - // return array of unitTestDirectory objects - return unitTestDirectory; -} - -// -// spreadsheet: UnitTestDirectory -function isPending(spreadsheet, filename, code) { - if (filename in spreadsheet && code in spreadsheet[filename]) { - return spreadsheet[filename][code].pending; - } - return false; -} - -// Reads a row and tries to find one or more test codes inside the row -// Returns an array of UnitTest objects -function parseCompletenessRow(row) { - var unitTests = []; - var index = 0; - for (var columnName in row) { - var rowValues = row[columnName].split(","); - for (var potentialCodeIndex in rowValues) { - var codes = rowValues[potentialCodeIndex].match(/([a-z]{2,4})([0-9]+)/g); - for (var codeIndex in codes) { - unitTests[index] = new UnitTest(codes[codeIndex], "", false); - ++index; - } - } - } - return unitTests; -} - -// Transforms a row in spreadsheet into a UnitTest object -// row: a literal object. One of the keys must be 'code/Code' and another 'description/Description' -// Returns a UnitTest object or null if cannot find appropriate keys. -function parseRow(row) { - var test_code = ""; - var testCodeKey = ""; - var pending = false; - var description = ""; - for (var columnName in row) { - if (columnName.trim() == "code" || columnName.trim() == "Code") { - test_code = row[columnName].trim(); - testCodeKey = columnName.trim(); - pending = test_code.match(/ -p/); - if (pending) { - test_code = test_code.replace(pending[0], ""); - pending = true; - } else { - pending = false; - } - } - } - var descriptionKey = getDescriptionKey(row, testCodeKey); - description = row[descriptionKey].trim(); - if (test_code == "" || description == "") return null; - return new UnitTest(test_code, description, pending); -} - -function getDescriptionKey(row, testCodeKey) { - // get the index of the testCodeKey - var testCodeKeyIndex = 0; - for (var i = 0; i < Object.keys(row).length; ++i) { - if (Object.keys(row)[i] == testCodeKey) { - return Object.keys(row)[i + 1]; - } - } - // return last column - return Object.keys(row)[i]; -} - -// Returns the raw name of the unit test suite associated with this csv file -// csvFileName: filename in the format `/path/to/file/spreadsheetname - unittestfilename.csv` -// returns 'spreadsheetname - unittestfilename' -function getTestSuiteTitle(csvFileName) { - return csvFileName.replace(/\.csv/, ""); -} - -module.exports = { - load: load, - UnitTest: UnitTest, - isPending: isPending, -}; diff --git a/verification/verification_reporter.js b/verification/verification_reporter.js index 7d40e250e..489fc430e 100644 --- a/verification/verification_reporter.js +++ b/verification/verification_reporter.js @@ -1,19 +1,3 @@ -const util = require("util"); -const mocha = require("mocha"); -const spec_reporter = mocha.reporters.Spec; -const base_reporter = mocha.reporters.Base; -const color = base_reporter.color; -const inherits = mocha.utils.inherits; -const sheets = require("./spreadsheet_parser"); -const _ = require("lodash"); -const jsdiff = require("diff"); -const colors = require("colors"); - -// Global variables for text output. -const red_x = color("bright fail", base_reporter.symbols.err); -const green_ok = color("green", base_reporter.symbols.ok); -const red_ok = color("bright fail", base_reporter.symbols.ok); -const indent = " "; const mocha = require("mocha"); const specReporter = mocha.reporters.Spec; const baseReporter = mocha.reporters.Base; @@ -184,8 +168,8 @@ function verificationReporter(runner) { ); } // If test is included in spreadsheet, 'cross-off' by deleting. - if (missingUnitTests[suite][id]) { - delete missingUnitTests[suite][id]; + if (spreadsheet[file][id]) { + delete spreadsheet[file][id]; } } else { // If test is not in spreadsheet. @@ -264,34 +248,13 @@ function verificationReporter(runner) { ) ); } - + delete spreadsheet.completeness; // If all the tests in a tab are present, 'cross-off' tab by deleting. for (const file in spreadsheet) { if (_.isEmpty(spreadsheet[file])) { delete spreadsheet[file]; } } - - // Report missing unit tests for files that were executed - for (var testSuite in missingUnitTests) { - if (!_.has(executedTestSuites, testSuite)) { - console.log(color("fail", "Did not run: " + testSuite)); - delete missingUnitTests[testSuite]; - } - } - - // report missing Completeness unit tests ONLY if every test file ran - var onlyCompletenessTestsAreMissing = true; - for (var testSuite in missingUnitTests) { - if (!testSuite.match(/Completeness/)) - onlyCompletenessTestsAreMissing = false; - } - if (onlyCompletenessTestsAreMissing) { - for (var testSuite in missingUnitTests) { - console.log(color("fail", "Did not run: " + testSuite)); - } - } - // If all tests are 'crossed-off', print success. if (_.isEmpty(spreadsheet)) { console.log( diff --git a/yarn.lock b/yarn.lock index 063ba407c..e2dc785af 100644 --- a/yarn.lock +++ b/yarn.lock @@ -769,6 +769,14 @@ asn1@~0.2.3: dependencies: safer-buffer "~2.1.0" +assert-diff@1.2.6: + version "1.2.6" + resolved "https://registry.yarnpkg.com/assert-diff/-/assert-diff-1.2.6.tgz#1b44d6f24a7e3018f557768ee350ae9a732c2fc6" + integrity sha512-cKyCfCQrLsHubcvDo4n5lGJPxN5gwpm4Hmsjs9/DJCFs4a5jiNvhKRxKP2DZGxNxOf9Iv3pxOoBSCQ+8eiNIKA== + dependencies: + assert-plus "1.0.0" + json-diff "0.5.2" + assert-plus@1.0.0, assert-plus@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/assert-plus/-/assert-plus-1.0.0.tgz#f12e0f3c5d77b0b1cdd9146942e4e96c1e4dd525" @@ -1778,6 +1786,13 @@ class-is@^1.1.0: resolved "https://registry.yarnpkg.com/class-is/-/class-is-1.1.0.tgz#9d3c0fba0440d211d843cec3dedfa48055005825" integrity sha512-rhjH9AG1fvabIDoGRVH587413LPjTZgmDF9fOFCbFJQV4yuocX1mHxxvXI4g3cGwbVY9wAYIoKlg1N79frJKQw== +cli-color@~0.1.6: + version "0.1.7" + resolved "https://registry.yarnpkg.com/cli-color/-/cli-color-0.1.7.tgz#adc3200fa471cc211b0da7f566b71e98b9d67347" + integrity sha1-rcMgD6RxzCEbDaf1ZrcemLnWc0c= + dependencies: + es5-ext "0.8.x" + cli-cursor@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/cli-cursor/-/cli-cursor-2.1.0.tgz#b35dac376479facc3e94747d41d0d0f5238ffcb5" @@ -2251,6 +2266,13 @@ diffie-hellman@^5.0.0: miller-rabin "^4.0.0" randombytes "^2.0.0" +difflib@~0.2.1: + version "0.2.4" + resolved "https://registry.yarnpkg.com/difflib/-/difflib-0.2.4.tgz#b5e30361a6db023176d562892db85940a718f47e" + integrity sha1-teMDYabbAjF21WKJLbhZQKcY9H4= + dependencies: + heap ">= 0.2.0" + dir-glob@^3.0.1: version "3.0.1" resolved "https://registry.yarnpkg.com/dir-glob/-/dir-glob-3.0.1.tgz#56dbf73d992a4a93ba1584f4534063fd2e41717f" @@ -2299,6 +2321,13 @@ drbg.js@^1.0.1: create-hash "^1.1.2" create-hmac "^1.1.4" +dreamopt@~0.6.0: + version "0.6.0" + resolved "https://registry.yarnpkg.com/dreamopt/-/dreamopt-0.6.0.tgz#d813ccdac8d39d8ad526775514a13dda664d6b4b" + integrity sha1-2BPM2sjTnYrVJndVFKE92mZNa0s= + dependencies: + wordwrap ">=0.0.2" + duplexer3@^0.1.4: version "0.1.4" resolved "https://registry.yarnpkg.com/duplexer3/-/duplexer3-0.1.4.tgz#ee01dd1cac0ed3cbc7fdbea37dc0a8f1ce002ce2" @@ -2464,6 +2493,11 @@ es-to-primitive@^1.2.1: is-date-object "^1.0.1" is-symbol "^1.0.2" +es5-ext@0.8.x: + version "0.8.2" + resolved "https://registry.yarnpkg.com/es5-ext/-/es5-ext-0.8.2.tgz#aba8d9e1943a895ac96837a62a39b3f55ecd94ab" + integrity sha1-q6jZ4ZQ6iVrJaDemKjmz9V7NlKs= + es5-ext@^0.10.35, es5-ext@^0.10.50: version "0.10.53" resolved "https://registry.yarnpkg.com/es5-ext/-/es5-ext-0.10.53.tgz#93c5a3acfdbef275220ad72644ad02ee18368de1" @@ -3920,6 +3954,11 @@ he@1.2.0: resolved "https://registry.yarnpkg.com/he/-/he-1.2.0.tgz#84ae65fa7eafb165fddb61566ae14baf05664f0f" integrity sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw== +"heap@>= 0.2.0": + version "0.2.6" + resolved "https://registry.yarnpkg.com/heap/-/heap-0.2.6.tgz#087e1f10b046932fc8594dd9e6d378afc9d1e5ac" + integrity sha1-CH4fELBGky/IWU3Z5tN4r8nR5aw= + hmac-drbg@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/hmac-drbg/-/hmac-drbg-1.0.1.tgz#d2745701025a6c775a6c545793ed502fc0c649a1" @@ -4381,6 +4420,15 @@ json-buffer@3.0.0: resolved "https://registry.yarnpkg.com/json-buffer/-/json-buffer-3.0.0.tgz#5b1f397afc75d677bde8bcfc0e47e1f9a3d9a898" integrity sha1-Wx85evx11ne96Lz8Dkfh+aPZqJg= +json-diff@0.5.2: + version "0.5.2" + resolved "https://registry.yarnpkg.com/json-diff/-/json-diff-0.5.2.tgz#e0bc9e434cd2c4c6354487835e01bf3fed335cda" + integrity sha512-N7oapTQdD4rLMUtA7d1HATCPY/BpHuSNL1mhvIuoS0u5NideDvyR+gB/ntXB7ejFz/LM0XzPLNUJQcC68n5sBw== + dependencies: + cli-color "~0.1.6" + difflib "~0.2.1" + dreamopt "~0.6.0" + json-parse-better-errors@^1.0.1: version "1.0.2" resolved "https://registry.yarnpkg.com/json-parse-better-errors/-/json-parse-better-errors-1.0.2.tgz#bb867cfb3450e69107c131d1c514bab3dc8bcaa9" @@ -8069,7 +8117,7 @@ word-wrap@^1.2.3, word-wrap@~1.2.3: resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.3.tgz#610636f6b1f703891bd34771ccb17fb93b47079c" integrity sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ== -wordwrap@^1.0.0: +wordwrap@>=0.0.2, wordwrap@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-1.0.0.tgz#27584810891456a4171c8d0226441ade90cbcaeb" integrity sha1-J1hIEIkUVqQXHI0CJkQa3pDLyus= From 2d4bf1ecf8e1390433130a642cf0204de9b79132 Mon Sep 17 00:00:00 2001 From: Walker Mayerchak Date: Thu, 27 May 2021 20:59:22 -0400 Subject: [PATCH 65/74] cleanup --- verification/Spreadsheets/MINTp0_ABITests.csv | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 verification/Spreadsheets/MINTp0_ABITests.csv diff --git a/verification/Spreadsheets/MINTp0_ABITests.csv b/verification/Spreadsheets/MINTp0_ABITests.csv deleted file mode 100644 index b0d83e76d..000000000 --- a/verification/Spreadsheets/MINTp0_ABITests.csv +++ /dev/null @@ -1,3 +0,0 @@ -File,Function,Code,Description -MintController.sol,internal_setMinterAllowance,abi100,abi100 internal_setMinterAllowance is internal -Ownable.sol,setOwner,abi101,abi101 setOwner is internal \ No newline at end of file From 092756a5ed2a0893bc4bb35cf070630db25cec50 Mon Sep 17 00:00:00 2001 From: Walker Mayerchak Date: Thu, 27 May 2021 21:23:28 -0400 Subject: [PATCH 66/74] resolve a few more conflicts --- .eslintignore | 2 +- .gitattributes | 4 -- .gitignore | 3 -- .travis.yml | 28 ------------ LICENSE | 2 +- README.md | 44 +++---------------- contracts/Migrations.sol | 2 +- .../test/ContractThatCallsPublicFunctions.sol | 2 +- contracts/test/ContractThatReverts.sol | 2 +- .../test/ContractWithExternalFunctions.sol | 2 +- .../test/ContractWithPublicFunctions.sol | 2 +- 11 files changed, 12 insertions(+), 81 deletions(-) diff --git a/.eslintignore b/.eslintignore index 60388cc6b..6fb3e25a1 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,4 +1,4 @@ .DS_Store node_modules/ coverage/ -@types/generated/ \ No newline at end of file +@types/generated/ diff --git a/.gitattributes b/.gitattributes index e858964d9..620289bde 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,6 +1,2 @@ -<<<<<<< HEAD *.sol linguist-language=Solidity -======= @types/generated/**/* linguist-generated=true - ->>>>>>> b5aba6ce7b5a867fda355a54a8449818b313bf1a diff --git a/.gitignore b/.gitignore index d7da6751d..bbfbcc8a7 100644 --- a/.gitignore +++ b/.gitignore @@ -12,11 +12,8 @@ credentials.json echidna/ validate/apikey.infura ganache-blockchain-log.txt -<<<<<<< HEAD -======= .coverage_artifacts .coverage_contracts yarn-error.log @types/generated/ config.js ->>>>>>> b5aba6ce7b5a867fda355a54a8449818b313bf1a diff --git a/.travis.yml b/.travis.yml index 2eda8a5ec..fbd73d11b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,32 +1,5 @@ language: node_js node_js: -<<<<<<< HEAD - - 8 - -before_install: - - curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version 1.9.2 - - export PATH="$HOME/.yarn/bin:$PATH" - - -install: - - npm install -g truffle@5.0.0 - - yarn install --frozen-lockfile - -env: - - TEST_SUITE=test/assert/* - - TEST_SUITE=test/basic/* - - TEST_SUITE=test/extended/* - - TEST_SUITE=test/minting/* - - TEST_SUITE=test/minting2/* - - TEST_SUITE=test/minting3/* - - TEST_SUITE=test/misc/* - - TEST_SUITE=test/proxy/* - -script: - - "truffle compile && npm run truffle-test $TEST_SUITE" - - -======= - 12 before_install: @@ -39,4 +12,3 @@ install: script: - yarn compile && yarn typechain - yarn ganache & sleep 5 && yarn test ->>>>>>> b5aba6ce7b5a867fda355a54a8449818b313bf1a diff --git a/LICENSE b/LICENSE index 702f20e7b..c96b81a78 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2018-2020 CENTRE SECZ +Copyright (c) 2018-2021 CENTRE SECZ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index bd093a357..e39a96581 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,12 @@ # centre-tokens -<<<<<<< HEAD Fiat tokens on the [CENTRE](https://centre.io) network. ======= - -> > > > > > > b5aba6ce7b5a867fda355a54a8449818b313bf1a - Fiat tokens on the [CENTRE](https://centre.io) network. ## Setup -<<<<<<< HEAD install yarn: `npm install -g yarn` - -install project npm dependencies: `yarn install` ======= Requirements: - +Requirements: - Node >= v12 - Yarn - > > > > > > > b5aba6ce7b5a867fda355a54a8449818b313bf1a ``` $ git clone git@github.com:centrehq/centre-tokens.git @@ -32,21 +24,6 @@ To generate type definitions: $ yarn compile && yarn typechain ``` -<<<<<<< HEAD - -# Contracts - -The implementation uses 2 separate contracts - a proxy contract -(`FiatTokenProxy.sol`)and an implementation contract(`FiatToken.sol`). This -allows upgrading the contract, as a new implementation contact can be deployed -and the Proxy updated to point to it. - -## FiatToken - -The FiatToken offers a number of capabilities, which briefly are described -below. There are more [detailed design docs](./doc/tokendesign.md) in the `doc` -folder. ======= - ## Linting and Formatting To check code for problems: @@ -102,20 +79,18 @@ accidental check-ins, `config.js` is in `.gitignore`. Run `yarn migrate --network NETWORK`, where NETWORK is either `mainnet` or `ropsten`. -## Contracts +# Contracts The implementation uses 2 separate contracts - a proxy contract -(`FiatTokenProxy.sol`) and an implementation contract (`FiatToken.sol`). This +(`FiatTokenProxy.sol`)and an implementation contract(`FiatToken.sol`). This allows upgrading the contract, as a new implementation contact can be deployed and the Proxy updated to point to it. -### FiatToken +## FiatToken The FiatToken offers a number of capabilities, which briefly are described below. There are more [detailed design docs](./doc/tokendesign.md) in the `doc` -folder. - -> > > > > > > b5aba6ce7b5a867fda355a54a8449818b313bf1a +folder. ======= ### ERC20 compatible @@ -150,15 +125,6 @@ decreases. When it gets too low they will need the allowance increased again by the `masterMinter`. ### Ownable - -<<<<<<< HEAD The contract has an Owner, who can change the `owner`, `pauser`, -`blacklister`, or `masterMinter` addresses. The `owner` can not change the -`proxyOwner` address. - -======= - The contract has an Owner, who can change the `owner`, `pauser`, `blacklister`, or `masterMinter` addresses. The `owner` can not change the `proxyOwner` address. - -> > > > > > > b5aba6ce7b5a867fda355a54a8449818b313bf1a diff --git a/contracts/Migrations.sol b/contracts/Migrations.sol index 66d81765b..0fd41b947 100644 --- a/contracts/Migrations.sol +++ b/contracts/Migrations.sol @@ -1,7 +1,7 @@ /** * SPDX-License-Identifier: MIT * - * Copyright (c) 2018-2020 CENTRE SECZ + * Copyright (c) 2018-2021 CENTRE SECZ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/contracts/test/ContractThatCallsPublicFunctions.sol b/contracts/test/ContractThatCallsPublicFunctions.sol index 6602ffec3..6bc510389 100644 --- a/contracts/test/ContractThatCallsPublicFunctions.sol +++ b/contracts/test/ContractThatCallsPublicFunctions.sol @@ -1,7 +1,7 @@ /** * SPDX-License-Identifier: MIT * - * Copyright (c) 2018-2020 CENTRE SECZ + * Copyright (c) 2018-2021 CENTRE SECZ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/contracts/test/ContractThatReverts.sol b/contracts/test/ContractThatReverts.sol index 722709da1..3992d130c 100644 --- a/contracts/test/ContractThatReverts.sol +++ b/contracts/test/ContractThatReverts.sol @@ -1,7 +1,7 @@ /** * SPDX-License-Identifier: MIT * - * Copyright (c) 2018-2020 CENTRE SECZ + * Copyright (c) 2018-2021 CENTRE SECZ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/contracts/test/ContractWithExternalFunctions.sol b/contracts/test/ContractWithExternalFunctions.sol index 10eb59286..db2ec2144 100644 --- a/contracts/test/ContractWithExternalFunctions.sol +++ b/contracts/test/ContractWithExternalFunctions.sol @@ -1,7 +1,7 @@ /** * SPDX-License-Identifier: MIT * - * Copyright (c) 2018-2020 CENTRE SECZ + * Copyright (c) 2018-2021 CENTRE SECZ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/contracts/test/ContractWithPublicFunctions.sol b/contracts/test/ContractWithPublicFunctions.sol index 4c2f8f4df..54c9f45dd 100644 --- a/contracts/test/ContractWithPublicFunctions.sol +++ b/contracts/test/ContractWithPublicFunctions.sol @@ -1,7 +1,7 @@ /** * SPDX-License-Identifier: MIT * - * Copyright (c) 2018-2020 CENTRE SECZ + * Copyright (c) 2018-2021 CENTRE SECZ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal From 2920b9ff90f17a59f0c3e4140bb6a44d65a5d124 Mon Sep 17 00:00:00 2001 From: Walker Mayerchak Date: Thu, 27 May 2021 21:58:19 -0400 Subject: [PATCH 67/74] cleanup --- .gitattributes | 3 +-- README.md | 10 +++++--- migrations/7_deploy_master_minter.js | 38 ++++++++++++++++++---------- package.json | 2 +- 4 files changed, 32 insertions(+), 21 deletions(-) diff --git a/.gitattributes b/.gitattributes index 620289bde..5c073d524 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,2 +1 @@ -*.sol linguist-language=Solidity -@types/generated/**/* linguist-generated=true +@types/generated/**/* linguist-generated=true \ No newline at end of file diff --git a/README.md b/README.md index e39a96581..ae56bd13e 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ Fiat tokens on the [CENTRE](https://centre.io) network. ## Setup Requirements: + - Node >= v12 - Yarn @@ -79,18 +80,18 @@ accidental check-ins, `config.js` is in `.gitignore`. Run `yarn migrate --network NETWORK`, where NETWORK is either `mainnet` or `ropsten`. -# Contracts +## Contracts The implementation uses 2 separate contracts - a proxy contract -(`FiatTokenProxy.sol`)and an implementation contract(`FiatToken.sol`). This +(`FiatTokenProxy.sol`) and an implementation contract(`FiatToken.sol`). This allows upgrading the contract, as a new implementation contact can be deployed and the Proxy updated to point to it. -## FiatToken +### FiatToken The FiatToken offers a number of capabilities, which briefly are described below. There are more [detailed design docs](./doc/tokendesign.md) in the `doc` -folder. ======= +folder. ### ERC20 compatible @@ -125,6 +126,7 @@ decreases. When it gets too low they will need the allowance increased again by the `masterMinter`. ### Ownable + The contract has an Owner, who can change the `owner`, `pauser`, `blacklister`, or `masterMinter` addresses. The `owner` can not change the `proxyOwner` address. diff --git a/migrations/7_deploy_master_minter.js b/migrations/7_deploy_master_minter.js index 8ac8bbb92..4b3296049 100644 --- a/migrations/7_deploy_master_minter.js +++ b/migrations/7_deploy_master_minter.js @@ -1,24 +1,34 @@ +const fs = require("fs"); +const path = require("path"); const MasterMinter = artifacts.require("./MasterMinter.sol"); const FiatToken = artifacts.require("./FiatTokenProxy.sol"); -let minterOwner; -let fiatToken; +let masterMinterAddress = ""; +let fiatTokenAddress = ""; + +// Read config file if it exists +if (fs.existsSync(path.join(__dirname, "..", "config.js"))) { + ({ + MASTERMINTER_ADDRESS: masterMinterAddress, + PROXY_CONTRACT_ADDRESS: fiatTokenAddress, + } = require("../config.js")); +} module.exports = function (deployer, network) { if (network === "development" || network === "coverage") { // Change these if deploying for real, these are deterministic // address from ganache - minterOwner = "0x3e5e9111ae8eb78fe1cc3bb8915d5d461f3ef9a9"; - fiatToken = FiatToken.address; + masterMinterAddress = "0x3e5e9111ae8eb78fe1cc3bb8915d5d461f3ef9a9"; + fiatTokenAddress = FiatToken.address; } - console.log("deploying MasterMinter for fiat token at " + fiatToken); + console.log("deploying MasterMinter for fiat token at " + fiatTokenAddress); deployer - .deploy(MasterMinter, fiatToken) - .then(function (mm) { - console.log("master minter deployed at " + mm.address); - console.log("reassigning owner to " + minterOwner); - return mm.transferOwnership(minterOwner); - }) - .then(function () { - console.log("All done."); - }); + .deploy(MasterMinter, fiatTokenAddress) + .then(function (mm) { + console.log("master minter deployed at " + mm.address); + console.log("reassigning owner to " + masterMinterAddress); + return mm.transferOwnership(masterMinterAddress); + }) + .then(function () { + console.log("All done."); + }); }; diff --git a/package.json b/package.json index d480eb462..1e918f06a 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "typechain": "yarn compile && rm -rf './@types/generated' && typechain --target=truffle-v5 --outDir './@types/generated' 'build/contracts/**/*.json'", "typecheck": "tsc -p . --noEmit", "lint": "eslint --ext '.js,.ts' './**/*.{j,t}s'", - "fmt": "prettier --write './**/*.sol' './**/*.js' './**/*.ts' './**/*.md'", + "fmt": "prettier --write './**/*.sol' './**/*.js' './**/*.ts' './**/*.json' './**/*.md'", "ganache": "ganache-cli --accounts=15 --deterministic --defaultBalanceEther=1000000 --quiet", "test": "truffle test", "coverage": "truffle run coverage", From 3608fb4241a4774d22765584838d0244fe2849f3 Mon Sep 17 00:00:00 2001 From: Walker Mayerchak Date: Thu, 27 May 2021 22:09:54 -0400 Subject: [PATCH 68/74] whitespace --- .gitattributes | 2 +- README.md | 3 ++- migrations/7_deploy_master_minter.js | 18 +++++++++--------- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/.gitattributes b/.gitattributes index 5c073d524..3c2122c8a 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1 @@ -@types/generated/**/* linguist-generated=true \ No newline at end of file +@types/generated/**/* linguist-generated=true diff --git a/README.md b/README.md index ae56bd13e..b938192bc 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,8 @@ Run `yarn migrate --network NETWORK`, where NETWORK is either `mainnet` or ## Contracts The implementation uses 2 separate contracts - a proxy contract -(`FiatTokenProxy.sol`) and an implementation contract(`FiatToken.sol`). This +(`FiatTokenProxy.sol`) and an implementation contract (`FiatToken.sol`). This +(`FiatTokenProxy.sol`) and an implementation contract (`FiatToken.sol`). This allows upgrading the contract, as a new implementation contact can be deployed and the Proxy updated to point to it. diff --git a/migrations/7_deploy_master_minter.js b/migrations/7_deploy_master_minter.js index 4b3296049..0d4c12385 100644 --- a/migrations/7_deploy_master_minter.js +++ b/migrations/7_deploy_master_minter.js @@ -22,13 +22,13 @@ module.exports = function (deployer, network) { } console.log("deploying MasterMinter for fiat token at " + fiatTokenAddress); deployer - .deploy(MasterMinter, fiatTokenAddress) - .then(function (mm) { - console.log("master minter deployed at " + mm.address); - console.log("reassigning owner to " + masterMinterAddress); - return mm.transferOwnership(masterMinterAddress); - }) - .then(function () { - console.log("All done."); - }); + .deploy(MasterMinter, fiatTokenAddress) + .then(function (mm) { + console.log("master minter deployed at " + mm.address); + console.log("reassigning owner to " + masterMinterAddress); + return mm.transferOwnership(masterMinterAddress); + }) + .then(function () { + console.log("All done."); + }); }; From 89bf348ee67c5a30c3d53af0e7b84bfa62aabf38 Mon Sep 17 00:00:00 2001 From: Walker Mayerchak Date: Thu, 27 May 2021 22:14:38 -0400 Subject: [PATCH 69/74] delete redundant comment --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index b938192bc..8cecf7b71 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,6 @@ Run `yarn migrate --network NETWORK`, where NETWORK is either `mainnet` or ## Contracts The implementation uses 2 separate contracts - a proxy contract -(`FiatTokenProxy.sol`) and an implementation contract (`FiatToken.sol`). This (`FiatTokenProxy.sol`) and an implementation contract (`FiatToken.sol`). This allows upgrading the contract, as a new implementation contact can be deployed and the Proxy updated to point to it. From 98b673afeadc094766a13125c36017631604e914 Mon Sep 17 00:00:00 2001 From: Walker Mayerchak Date: Tue, 1 Jun 2021 09:36:03 -0400 Subject: [PATCH 70/74] delete unnecessary relative path in deploy script --- migrations/7_deploy_master_minter.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/migrations/7_deploy_master_minter.js b/migrations/7_deploy_master_minter.js index 0d4c12385..706a10b5a 100644 --- a/migrations/7_deploy_master_minter.js +++ b/migrations/7_deploy_master_minter.js @@ -1,7 +1,7 @@ const fs = require("fs"); const path = require("path"); -const MasterMinter = artifacts.require("./MasterMinter.sol"); -const FiatToken = artifacts.require("./FiatTokenProxy.sol"); +const MasterMinter = artifacts.require("MasterMinter.sol"); +const FiatTokenProxy = artifacts.require("FiatTokenProxy.sol"); let masterMinterAddress = ""; let fiatTokenAddress = ""; @@ -18,7 +18,7 @@ module.exports = function (deployer, network) { // Change these if deploying for real, these are deterministic // address from ganache masterMinterAddress = "0x3e5e9111ae8eb78fe1cc3bb8915d5d461f3ef9a9"; - fiatTokenAddress = FiatToken.address; + fiatTokenAddress = FiatTokenProxy.address; } console.log("deploying MasterMinter for fiat token at " + fiatTokenAddress); deployer From f433c29a51bc1a45ae43e08bfbe5d03233f0f7a2 Mon Sep 17 00:00:00 2001 From: Walker Mayerchak Date: Tue, 1 Jun 2021 10:32:42 -0400 Subject: [PATCH 71/74] cr --- .../FiatToken - UnitTestCompleteness.csv | 36 ----------- .../FiatToken_ABIHackingTests.csv | 18 ------ .../Spreadsheets/FiatToken_EventTests.csv | 18 ------ .../FiatToken_ExtendedPositiveTests.csv | 37 ----------- .../Spreadsheets/FiatToken_MiscTests.csv | 34 ---------- .../Spreadsheets/FiatToken_NegativeTests.csv | 49 --------------- .../Spreadsheets/FiatToken_PositiveTests.csv | 29 --------- .../FiatToken_ProxyNegativeTests.csv | 11 ---- .../FiatToken_ProxyPositiveTests.csv | 15 ----- .../Spreadsheets/MINTp0_ArgumentTests.csv | 26 -------- .../Spreadsheets/MINTp0_BasicTests.csv | 62 ------------------- .../Spreadsheets/MINTp0_EndToEndTests.csv | 20 ------ .../Spreadsheets/MINTp0_EventTests.csv | 9 --- 13 files changed, 364 deletions(-) delete mode 100644 verification/Spreadsheets/FiatToken - UnitTestCompleteness.csv delete mode 100644 verification/Spreadsheets/FiatToken_ABIHackingTests.csv delete mode 100644 verification/Spreadsheets/FiatToken_EventTests.csv delete mode 100644 verification/Spreadsheets/FiatToken_ExtendedPositiveTests.csv delete mode 100644 verification/Spreadsheets/FiatToken_MiscTests.csv delete mode 100644 verification/Spreadsheets/FiatToken_NegativeTests.csv delete mode 100644 verification/Spreadsheets/FiatToken_PositiveTests.csv delete mode 100644 verification/Spreadsheets/FiatToken_ProxyNegativeTests.csv delete mode 100644 verification/Spreadsheets/FiatToken_ProxyPositiveTests.csv delete mode 100644 verification/Spreadsheets/MINTp0_ArgumentTests.csv delete mode 100644 verification/Spreadsheets/MINTp0_BasicTests.csv delete mode 100644 verification/Spreadsheets/MINTp0_EndToEndTests.csv delete mode 100644 verification/Spreadsheets/MINTp0_EventTests.csv diff --git a/verification/Spreadsheets/FiatToken - UnitTestCompleteness.csv b/verification/Spreadsheets/FiatToken - UnitTestCompleteness.csv deleted file mode 100644 index 0e1a79236..000000000 --- a/verification/Spreadsheets/FiatToken - UnitTestCompleteness.csv +++ /dev/null @@ -1,36 +0,0 @@ -File,Function,Modifier,Simple Test,ABI Test,Pausable,Code: paused=true,Blacklistable,blacklisted[msg.sender]=true,blacklisted[address]=true,Only 1 User,Wrong msg.sender -AdminUpgradeabilityProxy.sol,_setAdmin,internal,,abi053,,,,,,, -AdminUpgradeabilityProxy.sol,_willFallback,internal,,abi057,,,,,,, -Blacklistable.sol,blacklist,public,pt019,,no,ept036,no,ept020,ept024,blacklister,nt042 -Blacklistable.sol,unBlacklist,public,pt018,,no,ept035,no,ept021,,blacklister,nt043 -Blacklistable.sol,updateBlacklister,public,pt005,,no,ept003,no,ept015,ept027,owner,nt048 -Blacklistable.sol,isBlacklisted,view,,,,,,,,, -FiatTokenProxy.sol,changeAdmin,public,upt004,,no,ept001,no,ept013,ept025,upgrader,nut002 -FiatTokenProxy.sol,upgradeTo,public,upt001,,no,ept008,no,ept022,upt013,upgrader,nut009 -FiatTokenProxy.sol,upgradeToAndCall,public ,upt002,,no,upt010,no,upt011,upt012,upgrader,nut010 -FiatTokenV1.sol,initialize,public,upt002,,no,,no,,,, -FiatTokenV1.sol,removeMinter,public,pt010,,no,ept006,no,ept033,ept034,masterMinter,nt029 -FiatTokenV1.sol,updateMasterMinter,public,pt004,,no,ept002,no,ept014,ept026,masterMinter,nt049 -FiatTokenV1.sol,approve,public,pt020,,yes,nt010,yes,nt009,nt008,user, -FiatTokenV1.sol,burn,public,pt017,,yes,nt034,yes,nt033,,minter,"nt035, nt031" -FiatTokenV1.sol,configureMinter,public,pt015,,yes,nt028,no,ept030,ept032,masterMinter,nt026 -FiatTokenV1.sol,mint,public,pt012,,yes,nt001,yes,nt003,nt004,minter,"nt002, nt005" -FiatTokenV1.sol,transfer,public,pt008,,yes,nt024,yes,nt023,nt022,user,nt021 -FiatTokenV1.sol,transferFrom,public,pt007,,yes,nt018,yes,nt015,"nt014, nt016",user,nt017 -FiatTokenV1.sol,allowance,view,,,,,,,,, -FiatTokenV1.sol,blanceOf,view,,,,,,,,, -FiatTokenV1.sol,isMinter,view,,,,,,,,, -FiatTokenV1.sol,minterAllowance,view,,,,,,,,, -FiatTokenV1.sol,totalSupply,view,,,,,,,,, -Ownable.sol,transferOwnership,public,pt009,,no,ept005,no,ept017,ept029,owner,nt054 -Ownable.sol,owner,view,,,,,,,,, -Ownable.sol,setOwner,internal,,abi025,,,,,,, -Pausable.sol,pause,public,pt011,,no,ept037,no,ept018,,pauser,nt040 -Pausable.sol,unpause,public,pt006,,no,pt006,no,ept019,,pauser,nt041 -Pausable.sol,updatePauser,public,pt003,,no,ept004,no,ept016,ept028,owner,nt050 -Proxy.sol,_delegate,internal,,abi056,,,,,,, -Proxy.sol,_fallback,internal,,abi058,,,,,,, -Proxy.sol,_willFallback,internal,,abi057,,,,,,, -Proxy.sol,implementation,view,,,,,,,,, -UpgradeabilityProxy.sol,_setImplementation,internal,,abi050,,,,,,, -UpgradeabilityProxy.sol,_upgradeTo,internal,,abi028,,,,,,, \ No newline at end of file diff --git a/verification/Spreadsheets/FiatToken_ABIHackingTests.csv b/verification/Spreadsheets/FiatToken_ABIHackingTests.csv deleted file mode 100644 index 01b4a2bac..000000000 --- a/verification/Spreadsheets/FiatToken_ABIHackingTests.csv +++ /dev/null @@ -1,18 +0,0 @@ -File,Function,Code,Test -Proxy.sol,_delegate,abi056,abi056 Proxy _delegate is internal -Proxy.sol,_fallback,abi058,abi058 Proxy _fallback is internal -AdminUpgradeabilityProxy.sol,_setAdmin,abi053,abi053 AdminUpgradeabillityProxy _setAdmin is internal -UpgradeabilityProxy.sol,_setImplementation,abi050,abi050 Upgradeability implementation is internal -UpgradeabilityProxy.sol,_upgradeTo,abi028,abi028 UpgradeabilityProxy._upgradeTo is internal -AdminUpgradeabilityProxy.sol,_willFallback,abi057,abi057 Proxy _willFallback is internal -Proxy.sol,_willFallback,abi057,abi057 Proxy _willFallback is internal -AdminUpgradeabilityProxy.sol,AdminUpgradeabilityProxy,abi051,abi051 AdminUpgradeabillityProxy constructor is not a function -Blacklistable.sol,Blacklistable,abi040,abi040 Blacklistable constructor is not a function -FiatTokenV1.sol,FiatToken,abi041,abi041 FiatToken constructor is not a function -Ownable.sol,Ownable,abi042,abi042 Ownable constructor is not a function -Pausable.sol,Pausable,abi005,abi005 Pausable constructor is not a function -FiatTokenV1.sol,pause,abi004,abi004 FiatToken pause() is public -FiatTokenProxy.sol,Proxy,abi043,abi043 FiatTokenProxy constructor is not a function -Proxy.sol,Proxy,abi055,abi055 Proxy constructor is not a function -Ownable.sol,setOwner,abi025,abi025 setOwner is internal -UpgradeabilityProxy.sol,UpgradeabilityProxy,abi027,abi027 UpgradeabilityProxy constructor \ No newline at end of file diff --git a/verification/Spreadsheets/FiatToken_EventTests.csv b/verification/Spreadsheets/FiatToken_EventTests.csv deleted file mode 100644 index 484979fb4..000000000 --- a/verification/Spreadsheets/FiatToken_EventTests.csv +++ /dev/null @@ -1,18 +0,0 @@ -Event(s),File,Function,Code,Test -MinterConfigured,FiatTokenV1,configureMinter,et000,et000 should check MinterConfigured event -"Mint, Transfer",FiatTokenV1,mint,et001,et001 should check Mint/Transfer events -"Burn, Transfer",FiatTokenV1,burn,et002 ,et002 should check Burn/Transfer events -MinterRemoved,FiatTokenV1,removeMinter,et003,et003 should check MinterRemoved event -MasterMinterChanged,FiatTokenV1,updateMasterMinter,et004,et004 should check MasterMinterChanged event -Blacklisted,Blacklistable,blacklist,et005,et005 should check Blacklisted event -UnBlacklisted,Blacklistable,unBlacklist,et006,et006 should check UnBlacklisted event -BlacklisterChanged,Blacklistable,updateBlacklister,et007,et007 should check BlacklisterChanged event -Upgraded,_upgradeTo,UpgradeabilityProxy,et008,et008 should check Upgraded event -AdminChanged,changeAdmin,AdminUpgradeabilityProxy,et009,et009 should check AdminChanged event -OwnershipTransferred,Ownable,transferOwnership,et010,et010 should check OwnershipTransferred event -Approval,FiatTokenV1,approve,et011,et011 should check Approval event -Pause,Pausable,pause,et012,et012 should check Pause event -Unpause,Pausable,unpause,et013,et013 should check Unpause event -PauserChanged,Pausable,updatePauser,et014,et014 should check PauserChanged event -Transfer,FiatTokenV1,transfer,et015,et015 should check Transfer event -Transfer,FiatTokenV1,transferFrom,et016,et016 should check Transfer event in transferFrom \ No newline at end of file diff --git a/verification/Spreadsheets/FiatToken_ExtendedPositiveTests.csv b/verification/Spreadsheets/FiatToken_ExtendedPositiveTests.csv deleted file mode 100644 index 15d17ee83..000000000 --- a/verification/Spreadsheets/FiatToken_ExtendedPositiveTests.csv +++ /dev/null @@ -1,37 +0,0 @@ -variable type,visibility,variable name,Modification Function,Arguments,Result,Special Condition,Code,Test -mapping(address => bool),internal,blacklisted,blacklist,_account,blacklisted[_account] = true,blacklisted[_account] == true,ept024,ept024 should blacklist a blacklisted address -address,ifAdmin,implementation(),upgradeTo,newImplementation,"sstore(slot, newImplementation)",blacklisted[newImplementation] == true,ept023,ept023 should upgrade to blacklisted address -address,public,blacklister,updateBlacklister,_newBlacklister,blacklister = _newBlacklister,blacklisted[_newBlacklister] == true,ept027,ept027 should updateBlacklister to blacklisted address -address,public,masterMinter,updateMasterMinter,_newMasterMinter,masterMinter = _newMasterMinter,blacklisted[_newMasterMinter ] == true,ept026,ept026 should updateMasterMinter to blacklisted address -mapping(address => uint256),internal,minterAllowed,removeMinter,minter,minterAllowed[minter] = 0,blacklisted[masterMinter ] == true,ept033,ept033 should removeMinter when masterMinter is blacklisted -mapping(address => bool),internal,minters,removeMinter,minter,minters[minter] = false,blacklisted[masterMinter ] == true,ept033,ept033 should removeMinter when masterMinter is blacklisted -address,private,_owner,transferOwnership,newOwner,_owner = newOwner,blacklisted[newOwner] == true,ept029,ept029 should transferOwnership to blacklisted address -address,public,pauser,updatePauser,_newPauser,pauser = _newPauser,blacklisted[_newPauser] == true,ept028,ept028 should updatePauser to blacklisted address -mapping(address => uint256),internal,minterAllowed,configureMinter,"minter, minterAllowedAmount",minterAllowed[minter] = minterAllowedAmount,blacklisted[masterMinter] == true,ept030,ept030 should configureMinter when masterMinter is blacklisted -mapping(address => bool),internal,minters,configureMinter,"minter, minterAllowedAmount",minters[minter] = true ,blacklisted[masterMinter] == true,ept030,ept030 should configureMinter when masterMinter is blacklisted -mapping(address => uint256),internal,minterAllowed,configureMinter,"minter, minterAllowedAmount",minterAllowed[minter] = minterAllowedAmount,blacklisted[minter] == true,ept032,ept032 should configureMinter when minter is blacklisted -mapping(address => bool),internal,minters,configureMinter,"minter, minterAllowedAmount",minters[minter] = true ,blacklisted[minter] == true,ept032,ept032 should configureMinter when minter is blacklisted -mapping(address => uint256),internal,minterAllowed,removeMinter,minter,minterAllowed[minter] = 0,blacklisted[minter] == true,ept034,ept034 should removeMinter when minter is blacklisted -mapping(address => bool),internal,minters,removeMinter,minter,minters[minter] = false,blacklisted[minter] == true,ept034,ept034 should removeMinter when minter is blacklisted -address,ifAdmin,admin(),changeAdmin,newAdmin,"sstore(slot, newAdmin)",blacklisted[msg.sender] == true,ept013,ept013 should changeAdmin when msg.sender blacklisted -address,public,masterMinter,updateMasterMinter,_newMasterMinter,masterMinter = _newMasterMinter,blacklisted[msg.sender] == true,ept014,ept014 should updateMasterMinter when msg.sender blacklisted -address,public,blacklister,updateBlacklister,_newBlacklister,blacklister = _newBlacklister,blacklisted[msg.sender] == true,ept015,ept015 should updateBlacklister when msg.sender blacklisted -address,public,pauser,updatePauser,_newPauser,pauser = _newPauser,blacklisted[msg.sender] == true,ept016,ept016 should updatePauser when msg.sender blacklisted -address,private,_owner,transferOwnership,newOwner,_owner = newOwner,blacklisted[msg.sender] == true,ept017,ept017 should transferOwnership when msg.sender blacklisted -bool,public,paused,pause,NA,paused = true,blacklisted[msg.sender] == true,ept018,ept018 should pause when msg.sender blacklisted -bool,public,paused,unpause,NA,paused = false ,blacklisted[msg.sender] == true,ept019,ept019 should unpause when msg.sender blacklisted -mapping(address => bool),internal,blacklisted,blacklist,_account,blacklisted[_account] = true,blacklisted[msg.sender] == true,ept020,ept020 should blacklist when msg.sender blacklisted -mapping(address => bool),internal,blacklisted,unBlacklist,_account,blacklisted[_account] = false,blacklisted[msg.sender] == true,ept021,ept021 should unBlacklist when msg.sender blacklisted -address,ifAdmin,implementation(),upgradeTo,newImplementation,"sstore(slot, newImplementation)",blacklisted[msg.sender] == true,ept022,ept022 should upgrade when msg.sender blacklisted -address,ifAdmin,admin(),changeAdmin,newAdmin,"sstore(slot, newAdmin)",blacklisted[newAdmin] == true,ept025,ept025 should changeAdmin to blacklisted address -address,ifAdmin,admin(),changeAdmin,newAdmin,"sstore(slot, newAdmin)",paused == true,ept001,ept001 should changeAdmin while paused -address,public,masterMinter,updateMasterMinter,_newMasterMinter,masterMinter = _newMasterMinter,paused == true,ept002,ept002 should updateMasterMinter while paused -address,public,blacklister,updateBlacklister,_newBlacklister,blacklister = _newBlacklister,paused == true,ept003,ept003 should updateBlacklister while paused -address,public,pauser,updatePauser,_newPauser,pauser = _newPauser,paused == true,ept004,ept004 should updatePauser while paused -address,private,_owner,transferOwnership,newOwner,_owner = newOwner,paused == true,ept005,ept005 should transferOwnership while paused -mapping(address => uint256),internal,minterAllowed,removeMinter,minter,minterAllowed[minter] = 0,paused == true,ept006,ept006 should removeMinter while paused -mapping(address => bool),internal,minters,removeMinter,minter,minters[minter] = false,paused == true,ept006,ept006 should removeMinter while paused -address,ifAdmin,implementation(),upgradeTo,newImplementation,"sstore(slot, newImplementation)",paused == true,ept008,ept008 should upgrade while paused -mapping(address => bool),internal,blacklisted,unBlacklist,_account,blacklisted[_account]= false,paused == true,ept035,ept035 should unBlacklist while contract is paused -mapping(address => bool),internal,blacklisted,blacklist,_account,blacklisted[_account]= true,paused == true,ept036,ept036 should blacklist while contract is paused -bool,public,paused,pause,NA,paused = true ,paused == true,ept037,ept037 should pause while contract is paused \ No newline at end of file diff --git a/verification/Spreadsheets/FiatToken_MiscTests.csv b/verification/Spreadsheets/FiatToken_MiscTests.csv deleted file mode 100644 index d65929415..000000000 --- a/verification/Spreadsheets/FiatToken_MiscTests.csv +++ /dev/null @@ -1,34 +0,0 @@ -Code,Test,Test Type -ms001,ms001 no payable function,No Payable Function -ms002,ms002 should transfer to self has correct final balance,Same Address -ms003,ms003 should transferFrom to self from approved account and have correct final balance,Same Address -ms004,ms004 should transferFrom to self from approved self and have correct final balance,Same Address -ms005,ms005 should mint to self with correct final balance,Same Address -ms006,ms006 should approve correct allowance for self,Same Address -ms007,ms007 should configureMinter for masterMinter,Same Address -ms009,ms009 should configure two minters,Multiple Minters -ms010,ms010 should configure two minters and each mint distinct amounts,Multiple Minters -ms011,"ms011 should configure two minters, each minting distinct amounts and then remove one minter",Multiple Minters -ms012,ms012 should configure two minters and adjust both allowances,Multiple Minters -ms013,"ms013 should configure two minters, one with zero allowance fails to mint",Multiple Minters -ms014,ms014 should configure two minters and fail to mint when paused,Multiple Minters -ms015,"ms015 should configure two minters, blacklist one and ensure it cannot mint, then unblacklist and ensure it can mint",Multiple Minters -ms016,"ms016 should configure two minters, each mints to themselves and then burns certain amount",Multiple Minters -ms018,ms018 should approve 0 token allowance with unchanged state,0 Input -ms019,ms019 should transferFrom 0 tokens with unchanged state ,0 Input -ms020,ms020 should transfer 0 tokens with unchanged state,0 Input -ms036,ms036 should get allowance for same address,Same Address -ms039 ,ms039 should return true on mint,Return Value -ms040 ,ms040 should return true on approve,Return Value -ms041 ,ms041 should return true on transferFrom,Return Value -ms042 ,ms042 should return true on transfer,Return Value -ms043 ,ms043 should return true on configureMinter,Return Value -ms044 ,ms044 should return true on removeMinter,Return Value -ms045,"ms045 initialized should be in slot 8, byte 21",Slot Storage -ms046,ms046 initialized should be 0 before initialization,Slot Storage -ms047,ms047 configureMinter works on amount=2^256-1,2^256-1 Input -ms048,ms048 mint works on amount=2^256-1,2^256-1 Input -ms049,ms049 burn on works on amount=2^256-1,2^256-1 Input -ms050,ms050 approve works on amount=2^256-1,2^256-1 Input -ms051,ms051 transfer works on amount=2^256-1,2^256-1 Input -ms052,ms052 transferFrom works on amount=2^256-1,2^256-1 Input \ No newline at end of file diff --git a/verification/Spreadsheets/FiatToken_NegativeTests.csv b/verification/Spreadsheets/FiatToken_NegativeTests.csv deleted file mode 100644 index 7c968283e..000000000 --- a/verification/Spreadsheets/FiatToken_NegativeTests.csv +++ /dev/null @@ -1,49 +0,0 @@ -Function,Restriction,Code,Test -approve,blacklisted[msg.sender] == false,nt009,nt009 should fail to approve when msg.sender is blacklisted -approve,blacklisted[_spender] == false,nt008,nt008 should fail to approve when spender is blacklisted -approve,paused == false,nt010,nt010 should fail to approve when contract is paused -blacklist,msg.sender == blacklister,nt042,nt042 should fail to blacklist when sender is not blacklister -burn,_amount > 0,nt056,nt056 should fail to burn when amount = 0 -burn,_amount >= 0,nt032,nt032 should fail to burn when amount is -1 -burn,balances[msg.sender] >= _amount,nt031,nt031 should fail to burn when balance is less than amount -burn,blacklisted[msg.sender] ==false,nt033,nt033 should fail to burn when sender is blacklisted -burn,minters[msg.sender] == true,nt035,nt035 should fail to burn when sender is not minter -burn,minters[msg.sender] == true,nt036,nt036 should fail to burn after removeMinter -burn,paused == false,nt034,nt034 should fail to burn when paused -configureMinter,msg.sender == masterMinter,nt026,nt026 should fail to configureMinter when sender is not masterMinter -configureMinter,paused == false,nt028,nt028 should fail to configureMinter when paused -initialize,_blacklister != address(0),nt062,nt062 initialize should fail when _blacklister is 0x0 -initialize,_masterMinter != address(0),nt060,nt060 initialize should fail when _masterMinter is 0x0 -initialize,_owner != address(0),nt063,nt063 initialize should fail when _owner is 0x0 -initialize,_pauser != address(0),nt061,nt061 initialize should fail when _pauser is 0x0 -mint,_amount > 0,nt055,nt055 should fail to mint when amount = 0 -mint,blacklisted[msg.sender] == false,nt003,nt003 should fail to mint when msg.sender is blacklisted -mint,blacklisted[_to] == false,nt004,nt004 should fail to mint when recipient is blacklisted -mint,minterAllowed[msg.sender] >= amount,nt005,nt005 should fail to mint when allowance of minter is less than amount -mint,minters[msg.sender] == true,nt002,nt002 should fail to mint when msg.sender is not a minter -mint,paused == false,nt001,nt001 should fail to mint when paused -mint,_to != address(0),nt006,nt006 should fail to mint to 0x0 address -pause,msg.sender == pauser,nt040,nt040 should fail to pause when sender is not pauser -removeMinter,msg.sender == masterMinter,nt029,nt029 should fail to removeMinter when sender is not masterMinter -transfer,_value <= balances[msg.sender],nt021,nt021 should fail to transfer an amount greater than balance -transfer,_to != address(0),nt020,nt020 should fail to transfer to 0x0 address -transfer,blacklisted[msg.sender] == false,nt023,nt023 should fail to transfer when sender is blacklisted -transfer,blacklisted[_to] == false,nt022,nt022 should fail to transfer to blacklisted recipient -transfer,paused == false,nt024,nt024 should fail to transfer when paused -transferFrom,_value <= balances[_from],nt013,nt013 should fail to transferFrom an amount greater than balance -transferFrom,_to != address(0),nt012,nt012 should fail to transferFrom to 0x0 address -transferFrom,_value <= allowed[_from][msg.sender],nt017,nt017 should fail to transferFrom an amount greater than allowed for msg.sender -transferFrom,blacklisted[_from] == false,nt016,nt016 should fail to transferFrom when from is blacklisted -transferFrom,blacklisted[msg.sender] == false,nt015,nt015 should fail to transferFrom from blacklisted msg.sender -transferFrom,blacklisted[_to] == false,nt014,nt014 should fail to transferFrom to blacklisted recipient -transferFrom,paused == false,nt018,nt018 should fail to transferFrom when paused -transferOwnership,newOwner != address(0),nt064,nt064 transferOwnership should fail on 0x0 -transferOwnership,msg.sender == _owner,nt054,nt054 should fail to transferOwnership when sender is not owner -unBlacklist,msg.sender == blacklister,nt043,nt043 should fail to unblacklist when sender is not blacklister -unpause,msg.sender == pauser,nt041,nt041 should fail to unpause when sender is not pauser -updateBlacklister,_newBlacklister != address(0),nt059,nt059 updateBlacklister should fail on 0x0 -updateBlacklister,msg.sender == _owner,nt048,nt048 should fail to updateBlacklister when sender is not owner -updateMasterMinter,_newMasterMinter != address(0),nt057,nt057 updateMasterMinter should fail on 0x0 -updateMasterMinter,msg.sender == _owner,nt049,nt049 should fail to updateMasterMinter when sender is not owner -updatePauser,_newPauser != address(0),nt058,nt058 updatePauser should fail on 0x0 -updatePauser,msg.sender == _owner,nt050,nt050 should fail to updatePauser when sender is not owner \ No newline at end of file diff --git a/verification/Spreadsheets/FiatToken_PositiveTests.csv b/verification/Spreadsheets/FiatToken_PositiveTests.csv deleted file mode 100644 index 26198138e..000000000 --- a/verification/Spreadsheets/FiatToken_PositiveTests.csv +++ /dev/null @@ -1,29 +0,0 @@ -type,visibility,variable name,Modification Function,Arguments,Result,Code,Test -mapping(address => mapping(address => uint256)),internal,allowed,approve,"_spender = spender, _value = value",allowed[msg.sender][spender] = value,pt020,pt020 should approve a spend and set allowed amount -mapping(address => mapping(address => uint256)),internal,allowed,transferFrom,"_from = from, _to = to, _value = value",allowed[from][spender] -= value,pt007,"pt007 should transferFrom, reducing sender balance by amount and increasing recipient balance by amount" -mapping(address => uint256),internal,balances,burn,_amount = amount,balances[msg.sender] -= amount,pt017,pt017 should burn amount of tokens and reduce balance and total supply by amount -mapping(address => uint256),internal,balances,mint," _to = to, _amount = amount",balances[to] += amount,pt012,"pt012 should mint the amount, increasing balance of recipient by amount, increasing total supply by amount, and decreasing minterAllowed by amount" -mapping(address => uint256),internal,balances,transfer,"_to = to, _value = value","balances[msg.sender] -= amount, balances[to] += amount",pt008,"pt008 should transfer, reducing sender balance by amount and increasing recipient balance by amount" -mapping(address => uint256),internal,balances,transferFrom,"_from = from, _to = to, _value = value","balances[from] -= amount, balances[to] += amount ",pt007,"pt007 should transferFrom, reducing sender balance by amount and increasing recipient balance by amount" -mapping(address => bool),internal,blacklisted,blacklist,_account = account,blacklisted[account] = true,pt019,pt019 should blacklist and set blacklisted to true -mapping(address => bool),internal,blacklisted,unBlacklist,_account = account,blacklisted[account] = false,pt018,"pt018 should blacklist and set blacklisted to true, then unblacklist and set blacklisted to false" -address,public,blacklister,initialize,_blacklister = blacklister,assign,pt000,pt000 should check that default variable values are correct -address,public,blacklister,updateBlacklister,_newBlacklister = newBlacklister,blacklister = _newBlacklister,pt005,pt005 should updateBlacklister -string,public,currency,initialize,_currency = currency,assign,pt000,pt000 should check that default variable values are correct -uint8,public,decimals,initialize,_decimals = decimals,assign,pt000 ,pt000 should check that default variable values are correct -address,public,masterMinter,initialize,_masterMinter = masterMinter,assign,pt000,pt000 should check that default variable values are correct -address,public,masterMinter,updateMasterMinter,_newMasterMinter,masterMinter = _newMasterMinter ,pt004,pt004 should updateMasterMinter -mapping(address => uint256),internal,minterAllowed,configureMinter,"_minter = minter, _minterAllowedAmount = minterAllowedAmount",minterAllowed[minter] = minterAllowedAmount,pt015,"pt015 should configureMinter, setting the minter to true and mintingAllowance to amount" -mapping(address => uint256),internal,minterAllowed,mint,"_to = to, _amount = amount",minterAllowed[msg.sender] -= amount,pt012,"pt012 should mint the amount, increasing balance of recipient by amount, increasing total supply by amount, and decreasing minterAllowed by amount" -mapping(address => uint256),internal,minterAllowed,removeMinter,_minter = minter,minterAllowed[minter] = 0,pt010,"pt010 should removeMinter, setting the minter to false and minterAllowed to 0" -mapping(address => bool),internal,minters,configureMinter,"_minter = minter, _minterAllowedAmount = minterAllowedAmount",minters[minter] = true,pt015,"pt015 should configureMinter, setting the minter to true and mintingAllowance to amount" -mapping(address => bool),internal,minters,removeMinter,_minter = minter,minters[minter] = false,pt010,"pt010 should removeMinter, setting the minter to false and minterAllowed to 0" -string,public,name,initialize,_name = name,assign,pt000,pt000 should check that default variable values are correct -address,private,owner,transferOwnership ,_newOwner = newOwner,_owner = newOwner,pt009,pt009 should set owner to _newOwner -bool,public,paused = false,pause,NA,paused = true,pt011,pt011 should pause and set paused to true -bool,public,paused = false,unpause,NA,paused = false,pt006,pt006 should unpause and set paused to false -address,public,pauser,initialize,_pauser = pauser,assign,pt000,pt000 should check that default variable values are correct -address,public,pauser,updatePauser,_newPauser = newPauser,pauser = _newPauser,pt003,pt003 should updatePauser -string,public,symbol,initialize,symbol = _symbol,assign,pt000,pt000 should check that default variable values are correct -uint256,internal,totalSupply_,burn,_amount = amount,totalSupply_ -= _amount,pt017,pt017 should burn amount of tokens and reduce balance and total supply by amount -uint256,internal,totalSupply_,mint," _to = to, _amount = amount",totalSupply_ += _amount,pt012,"pt012 should mint the amount, increasing balance of recipient by amount, increasing total supply by amount, and decreasing minterAllowed by amount" \ No newline at end of file diff --git a/verification/Spreadsheets/FiatToken_ProxyNegativeTests.csv b/verification/Spreadsheets/FiatToken_ProxyNegativeTests.csv deleted file mode 100644 index 2d44c582f..000000000 --- a/verification/Spreadsheets/FiatToken_ProxyNegativeTests.csv +++ /dev/null @@ -1,11 +0,0 @@ -Function,Restriction,Code,Test -changeAdmin,msg.sender == admin,nut002,nut002 should fail to switch adminAccount with non-adminAccount as caller -upgradeTo,newImplementation is realContract,nut003,nut003 should fail to upgradeTo to null contract address -upgradeToAndCall,newImplementation is realContract,nut004,nut004 should fail to upgradeToAndCall to null contract address -initialize,initialized == false,nut005,nut005 should fail to initialize contract twice -allowance,msg.sender != admin,nut006,nut006 should fail to call contract function with adminAccount -admin,msg.sender == admin,nut007,nut007 should fail to call proxy function with non-adminAccount -transfer,N/A,nut008,nut008 shoud fail to update proxy storage if state-changing function called directly in FiatToken -upgradeTo,msg.sender == admin,nut009,nut009 should fail to call upgradeTo with non-adminAccount -upgradeToAndCall,msg.sender == admin,nut010,nut010 should fail to call updateToAndCall with non-adminAccount -upgradeToAndCall,initialized == false,nut011,nut011 should fail to upgradeToAndCall with initialize (already set variables) \ No newline at end of file diff --git a/verification/Spreadsheets/FiatToken_ProxyPositiveTests.csv b/verification/Spreadsheets/FiatToken_ProxyPositiveTests.csv deleted file mode 100644 index 247a93ad9..000000000 --- a/verification/Spreadsheets/FiatToken_ProxyPositiveTests.csv +++ /dev/null @@ -1,15 +0,0 @@ -Variable Name,Code,Test -_implementation,upt001,upt001 should upgradeTo new contract and preserve data field values -"_implementation, [new fields]",upt002,upt002 should upgradeToandCall to contract with new data fields set on initVX and ensure new fields are correct and old data is preserved -"_implementation, [new fields]",upt003,"upt003 should upgradeToAndCall to contract with new data fields set on initVX and new logic and ensure old data preserved,new logic works, and new fields correct" -_admin,upt004,upt004 should update proxy adminAccount with previous adminAccount -"_implementation, balances",upt005,upt005 should receive Transfer event on transfer when proxied after upgrade -pause,upt006,upt006 should upgrade while paused and upgraded contract should be paused as a result; then unpause should unpause contract -should not change state,upt007,upt007 should upgrade contract to original address -"initialization fields, _implementation",upt008,upt008 should deploy upgraded version of contract with new data fields and without previous deployment and ensure new fields correct -_admin,upt009,upt009 should check that admin is set correctly by proxy constructor -"initialization fields, _implementation",upt010,"upt010 should deploy upgraded version of contract with new data fields and logic without previous deployment and ensure new logic works, and new fields correct" -"_implementation, [new fields]",upt011,upt011 should upgradeToAndCall while paused and upgraded contract should be paused as a result -"_implementation, [new fields]",upt012,upt012 should upgradeToAndCall while proxyOwner is blacklisted -"_implementation, [new fields]",upt013,upt013 should upgradeToAndCall while new logic is blacklisted -_implementation,upt014,upt014 should upgradeTo while new logic is blacklisted diff --git a/verification/Spreadsheets/MINTp0_ArgumentTests.csv b/verification/Spreadsheets/MINTp0_ArgumentTests.csv deleted file mode 100644 index ba3545b83..000000000 --- a/verification/Spreadsheets/MINTp0_ArgumentTests.csv +++ /dev/null @@ -1,26 +0,0 @@ -File,Function,Arguments,Code,Description -Ownable.sol,transferOwnership,newOwner == msg.sender,arg000,arg000 transferOwnership(msg.sender) works -Ownable.sol,transferOwnership,newOwner == 0,arg001,arg001 transferOwnership(0) reverts -Ownable.sol,transferOwnership,newOwner == owner,arg002,arg002 transferOwnership(owner) works -Controller.sol,configureController,newController == 0,arg003,"arg003 configureController(0, M) throws" -Controller.sol,configureController,newController == msg.sender,arg004,"arg004 configureController(msg.sender, M) works" -Controller.sol,configureController,newController == newMinter,arg005,"arg005 configureController(M, M) works" -Controller.sol,configureController,newMinter == 0,arg006,"arg006 configureController(C, 0) throws" -Controller.sol,removeController,controller == 0,arg007,arg007 removeController(0) throws -MintController.sol,setMinterManager,newMinterManager = 0,arg008,arg008 setMinterManager(0) works -MintController.sol,setMinterManager,newMinterManager == minterManager,arg009,arg009 setMinterManager(oldMinterManager) works -MintController.sol,setMinterManager,newMinterManager == user,arg010,arg010 setMinterManager(user_account) works -MintController.sol,setMinterManager,newMinterManager == newToken,arg011,arg011 setMinterManager(newToken) works -MintController.sol,configureMinter,newAllowance == 0,arg012,arg012 configureMinter(0) sets allowance to 0 -MintController.sol,configureMinter,newAllowance == oldAllowance,arg013,arg013 configureMinter(oldAllowance) makes no changes -MintController.sol,configureMinter,newAllowance == 2^256-1,arg014,arg014 configureMinter(MAX) works -MintController.sol,incrementMinterAllowance,increment ==0,arg015,arg015 incrementMinterAllowance(0) throws -MintController.sol,incrementMinterAllowance,increment == oldAllowance,arg016,arg016 incrementMinterAllowance(oldAllowance) doubles the allowance -MintController.sol,incrementMinterAllowance,increment == 2^256-1,arg017,arg017 incrementMinterAllowance(MAX) throws -MintController.sol,incrementMinterAllowance,increment + oldAllowance == 2^256 -1,arg018,arg018 incrementMinterAllowance(BIG) throws -Controller.sol,configureController,newController == 0,arg019,"arg019 configureController(0, 0) throws" -Controller.sol,removeController,controller == msg.sender,arg020,arg020 removeController(C) works -Controller.sol,removeController,controller where controllers[controller] == 0,arg021,arg021 removeController throws if worker is already address(0) -MintController.sol,decrementMinterAllowance,decrement == oldAllowance,arg022,arg022 decrementMinterAllowance(oldAllowance) sets the allowance to 0 -MintController.sol,decrementMinterAllowance,oldAllowance - decrement == 0 - 1,arg023,arg023 decrementMinterAllowance(MIN) sets the allowance to 0 -MintController.sol,decrementMinterAllowance,decrement ==0,arg024,arg024 decrementMinterAllowance(0) throws diff --git a/verification/Spreadsheets/MINTp0_BasicTests.csv b/verification/Spreadsheets/MINTp0_BasicTests.csv deleted file mode 100644 index fed6ed274..000000000 --- a/verification/Spreadsheets/MINTp0_BasicTests.csv +++ /dev/null @@ -1,62 +0,0 @@ -File,Function,Special Condition,Code,Description -Controller.sol,configureController,msg.sender == owner,bt004,bt004 configureController works when owner is msg.sender -Controller.sol,configureController,msg.sender != owner,bt005,bt005 configureController reverts when owner is not msg.sender -Controller.sol,configureController,controllers[C]=0,bt019,bt019 configureController works when controller[C]=0 -Controller.sol,configureController,controllers[C] != 0,bt020,bt020 configureController works when controller[C] != 0 -Controller.sol,configureController,controllers[C]=C,bt021,"bt021 configureController(C,C) works" -Controller.sol,configureController,controllers[C] == msg.sender,bt022,bt022 configureController works when setting controller[C]=msg.sender -Controller.sol,configureController,controllers[C] == newM,bt023,"bt023 configureController(C, newM) works when controller[C]=newM" -Controller.sol,constructor,controllers[ALL] = 0,bt016,bt016 Constructor sets all controllers to 0 -Controller.sol,removeController,msg.sender == owner,bt008,bt008 removeController works when owner is msg.sender -Controller.sol,removeController,msg.sender != owner,bt009,bt009 removeController reverts when owner is not msg.sender -Controller.sol,removeController,controllers[C]=0,bt017,bt017 removeController reverts when controllers[C] is 0 -Controller.sol,removeController,controllers[C]=M,bt018,bt018 removeController removes an arbitrary controller -FiatTokenV1.sol,constructor,minterManager.isMinter[ALL] == false,bt045,bt045 constructor - minterManager.isMinter[ALL] is false -FiatTokenV1.sol,constructor,minterManager.minterAllowance[ALL] == 0,bt046,bt046 constructor - minterManager.minterAllowance[ALL] = 0 -MintController.sol,configureMinter,controllers[msg.sender]==0,bt012,bt012 configureMinter reverts when msg.sender is not a controller -MintController.sol,configureMinter,controllers[msg.sender]==M,bt013,bt013 configureMinter works when controllers[msg.sender]=M -MintController.sol,configureMinter,minterManager != MinterManagerInterface,bt034,bt034 configureMinter reverts when minterManager is a user account -MintController.sol,configureMinter,minterManager == OK,bt035,bt035 configureMinter works when minterManager is ok -MintController.sol,configureMinter,minterManager.isMinter == false,bt039,"bt039 configureMinter(M, amt) works when minterManager.isMinter(M)=false" -MintController.sol,configureMinter,minterManager.isMinter == true,bt040,"bt040 configureMinter(M, amt) works when minterManager.isMinter(M)=true" -MintController.sol,configureMinter,minterManager.minterAllowance[M] == 0,bt050,"bt050 configureMinter(M,amt) works when minterAllowance=0" -MintController.sol,configureMinter,minterManager.minterAllowance[M] == X,bt051,"bt051 configureMinter(M,amt) works when minterAllowance>0" -MintController.sol,configureMinter,minterManager.minterAllowance[M] == BIG,bt052,"bt052 configureMinter(M,amt) works when amt+minterAllowance > 2^256" -MintController.sol,constructor,minterManager == init,bt024,bt024 Constructor sets minterManager -MintController.sol,incrementMinterAllowance,controllers[msg.sender]==0,bt014,bt014 incrementMinterAllowance reverts if msg.sender is not a controller -MintController.sol,incrementMinterAllowance,controllers[msg.sender]==M,bt015,bt015 incrementMinterAllowance works when controllers[msg.sender]=M -MintController.sol,incrementMinterAllowance,minterManager != MinterManagerInterface,bt037,bt037 incrementMinterAllowance reverts when minterManager is a user account -MintController.sol,incrementMinterAllowance,minterManager == OK,bt038,bt038 incrementMinterAllowance works when minterManager is ok -MintController.sol,incrementMinterAllowance,minterManager.isMinter == false,bt043,"bt043 incrementMinterAllowance(M, amt) reverts when minterManager.isMinter(M)=false" -MintController.sol,incrementMinterAllowance,minterManager.isMinter == true,bt044,"bt044 incrementMinterAllowance(M, amt) works when minterManager.isMinter(M)=true" -MintController.sol,incrementMinterAllowance,minterManager.minterAllowance[M] == 0,bt047,"bt047 incrementMinterAllowance(M,amt) works when minterAllowance is 0" -MintController.sol,incrementMinterAllowance,minterManager.minterAllowance[M] == X,bt048,"bt048 incrementMinterAllowance(M, amt) works when minterAllowance > 0" -MintController.sol,incrementMinterAllowance,minterManager.minterAllowance[M] == BIG,bt049,"bt049 incrementMinterAllowance(M,amt) reverts when minterAllowance[M] + amt > 2^256" -MintController.sol,removeMinter,controllers[msg.sender]==0,bt010,bt010 removeMinter reverts when msg.sender is not a controller -MintController.sol,removeMinter,controllers[msg.sender]==M,bt011,bt011 removeMinter sets minters[M] to 0 -MintController.sol,removeMinter,minterManager = 0,bt030,bt030 removeMinter reverts when minterManager is 0 -MintController.sol,removeMinter,minterManager != MinterManagerInterface,bt031,bt031 removeMinter reverts when minterManager is a user account -MintController.sol,removeMinter,minterManager == OK,bt032,bt032 removeMinter works when minterManager is ok -MintController.sol,removeMinter,minterManager.isMinter == false,bt041,bt041 removeMinter(M) works when minterManager.isMinter(M)=false -MintController.sol,removeMinter,minterManager.isMinter == true,bt042,bt042 removeMinter(M) works when minterManager.isMinter(M)=true -MintController.sol,removeMinter,minterManager.minterAllowance[M] == 0,bt053,bt053 removeMinter works when the minterAllowance is 0 -MintController.sol,removeMinter,minterManager.minterAllowance[M] == X,bt054,bt054 removeMinter works when the minterAllowance is not zero -MintController.sol,removeMinter,minterManager.minterAllowance[M] == BIG,bt055,bt055 removeMinter works when the minterAllowance is big -MintController.sol,setMinterManager,msg.sender == owner,bt006,bt006 setMinterManager works when owner is msg.sender -MintController.sol,setMinterManager,msg.sender != owner,bt007,bt007 setMinterManager reverts when owner is not msg.sender -MintController.sol,setMinterManager,minterManager != 0,bt026,bt026 setMinterManager(x) works when existing minterManager != 0 -MintController.sol,setMinterManager,minterManager == msg.sender,bt027,bt027 setMinterManager(x) works when x = msg.sender -MintController.sol,setMinterManager,minterManager == newMinterManager,bt028,bt028 setMinterManager(x) works when x = minterManager -Ownable.sol,constructor,msg.sender == owner,bt001,bt001 Constructor - owner is msg.sender -Ownable.sol,transferOwnership,msg.sender == owner,bt002,bt002 transferOwnership works when owner is msg.sender -Ownable.sol,transferOwnership,msg.sender != owner,bt003,bt003 transferOwnership reverts when owner is not msg.sender -MintController.sol,decrementMinterAllowance,controllers[msg.sender]==0,bt056,bt056 decrementMinterAllowance reverts if msg.sender is not a controller -MintController.sol,decrementMinterAllowance,controllers[msg.sender]==M,bt057,bt057 decrementMinterAllowance works when controllers[msg.sender]=M -MintController.sol,decrementMinterAllowance,minterManager = 0,bt058,bt058 decrementMinterAllowance reverts when minterManager is 0 -MintController.sol,decrementMinterAllowance,minterManager != MinterManagerInterface,bt059,bt059 decrementMinterAllowance reverts when minterManager is a user account -MintController.sol,decrementMinterAllowance,minterManager == OK,bt060,bt060 decrementMinterAllowance works when minterManager is ok -MintController.sol,decrementMinterAllowance,minterManager.isMinter == false,bt061,"bt061 decrementMinterAllowance(M, amt) reverts when minterManager.isMinter(M)=false" -MintController.sol,decrementMinterAllowance,minterManager.isMinter == true,bt062,"bt062 decrementMinterAllowance(M, amt) works when minterManager.isMinter(M)=true" -MintController.sol,decrementMinterAllowance,minterManager.minterAllowance[M] == 0,bt063,"bt063 decrementMinterAllowance(M,amt) works when minterAllowance is MAX" -MintController.sol,decrementMinterAllowance,minterManager.minterAllowance[M] == X,bt064,"bt064 decrementMinterAllowance(M, amt) works when minterAllowance > 0" -MintController.sol,decrementMinterAllowance,minterManager.minterAllowance[M] == BIG,bt065,"bt065 decrementMinterAllowance(M,amt) sets allowance to 0 when minterAllowance[M] - amt < 0" \ No newline at end of file diff --git a/verification/Spreadsheets/MINTp0_EndToEndTests.csv b/verification/Spreadsheets/MINTp0_EndToEndTests.csv deleted file mode 100644 index e5211baa1..000000000 --- a/verification/Spreadsheets/MINTp0_EndToEndTests.csv +++ /dev/null @@ -1,20 +0,0 @@ -File,Function 1,Function 2,Function 3,Code,Description -Ownable.sol,transferOwnership,configureController,,ete000,ete000 New owner can configure controllers -Ownable.sol,transferOwnership,removeController,,ete001,ete001 New owner can remove controllers -Controller.sol,configureController,configureMinter,,ete002,ete002 New controller can configure minter -Controller.sol,configureController,incrementMinterAllowance,,ete011,ete011 New controller can increment minter allowance -Controller.sol,configureController,removeMinter,,ete012,ete012 New controller can remove minter -Controller.sol,configureController,configureController,configureMinter,ete003,ete003 Configure two controllers for the same minter and make sure they can both configureMinter -Controller.sol,configureController,configureMinter,removeMinter,ete004,"ete004 Configure two controllers for the same minter, one adds a minter and the other removes it" -Controller.sol,configureController,configureMinter,removeMinter,ete005,ete005 Configure two controllers for different minters and make sure 2nd cant remove -Controller.sol,configureController,configureMinter,configureMinter,ete006,ete006 Configure two controllers for different minters and make sure 2nd cant configure -Controller.sol,removeController,configureMinter,,ete007,ete007 Remove a controller and make sure it can't modify minter -MintController.sol,setMinterManager,configureMinter,,ete008,ete008 Change minter manager and make sure existing controllers still can configure their minters -MintController.sol,setMinterManager,removeMinter,,ete009,ete009 Change minter manager and make sure existing controllers still can remove their minters -MintController.sol,setMinterManager,incrementMinterAllowance,,ete010,ete010 Change minter manager and make sure existing controllers can increment allowances -MintController.sol,setMinterManager,configureMinter,setMinterManager,ete013,"ete013 Change minter manager, configure a minter, then change back and make sure changes DID NOT propogate" -MintController.sol,removeMinter,incrementMinterAllowance,,ete014,ete014 Remove a minter and then try to increment its allowance reverts -MintController.sol,configureMinter,mint,,ete015,ete015 Configure a minter and make sure it can mint -MintController.sol,configureMinter,burn,,ete017,ete017 Configure a minter and make sure it can burn -MintController.sol,removeMinter,mint,,ete016,ete016 Remove a minter and make sure it cannot mint -MintController.sol,removeMinter,burn,,ete018,ete018 Remove a minter and make sure it cannot burn \ No newline at end of file diff --git a/verification/Spreadsheets/MINTp0_EventTests.csv b/verification/Spreadsheets/MINTp0_EventTests.csv deleted file mode 100644 index d38f78e21..000000000 --- a/verification/Spreadsheets/MINTp0_EventTests.csv +++ /dev/null @@ -1,9 +0,0 @@ -File,Function,Event,Code,Description -Ownable.sol,transferOwnership,OwnershipTransferred,et100,et100 transferOwnership emits OwnershipTransferred event -Controller.sol,configureController,ControllerConfigured,et101,et101 configureController emits ControllerConfigured event -Controller.sol,removeController,ControllerRemoved,et102,et102 removeController emits ControllerRemoved event -MintController,setMinterManager,MinterManagerSet,et103,et103 setMinterManager emits MinterManagerSet event -MintController,removeMinter,MinterRemoved,et104,et104 removeMinter emits MinterRemoved event -MintController,configureMinter,MinterConfigured,et105,et105 configureMinter emits MinterConfigured event -MintController,incrementMinterAllowance,MinterAllowanceIncremented,et106,et106 incrementMinterAllowance emits MinterAllowanceIncremented event -MintController,decrementMinterAllowance,MinterAllowanceDecremented,et107,et107 decrementMinterAllowance emits MinterAllowanceDecremented event \ No newline at end of file From 788ced6ceb1dd2c4aed85edc7ebfa6395e463ae9 Mon Sep 17 00:00:00 2001 From: Walker Mayerchak Date: Tue, 1 Jun 2021 11:01:31 -0400 Subject: [PATCH 72/74] leave verification README alone --- verification/README.verification.txt | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/verification/README.verification.txt b/verification/README.verification.txt index c0163007e..718909f8c 100644 --- a/verification/README.verification.txt +++ b/verification/README.verification.txt @@ -1,7 +1,7 @@ The spreadsheet verification tool requires certain naming and usage conventions to function correctly. -Unit test codes: +Test Codes: - Should follow the format of lowercase letters followed by a number with no spaces. (ex. pt001, ept016, misc0000, legacy2, fiat19) @@ -11,15 +11,17 @@ Unit test codes: - Should be listed under the 'Code' column of each spreadsheet tab. +Test Titles: -CSV files: -- All CSV files must be in the `verification/Spreadsheets` directory. +- Should exactly match the test description assigned to the test in the + spreadsheet. -- Each unit test contract block is associated with a single *.csv file. - If the contract block title is 'FiatToken_EventTests' then it will be tested - against FiatToken_EventTests.csv. The verification tool will ignore all - text in the contract block title after a space. 'FiatToken_EventTests Upgraded' - will also be verified against FiatToken_EventTests.csv +Spreadsheet Tabs: + +- Should have the same name as the test file they represent. + This name should be formatted BlankTests where Blank consists of uppercase + and/or lowercase letters and is followed without a space by the word 'Tests'. + (ex. PositiveTests, tokenTests, ABITests) - Should include a column 'code' or 'Code' listing all unique test codes that correspond to tests expected in the test file. @@ -31,7 +33,7 @@ CSV files: - Should keep the column headers in the top row. -UnitTestCompleteness CSV (unsupported): +UnitTestCompleteness tab: - The verification tool will print out any test codes that are featured in the UnitTestCompleteness tab but missing from the test suite. @@ -42,7 +44,11 @@ UnitTestCompleteness CSV (unsupported): Contract Block Titles: -- Must match the CSV file name that it is tested against (see CSV files above). +- Should include the name of the test file they run, and this name should not + be immediately preceded by letters. + (ex. If the contract block runs the PositiveTests file, it should be named + 'FiatToken_PositiveTests', 'PositiveTestsupgraded', 'PositiveTests' etc., + but not 'upgradedPositiveTests'.) - Should include the word 'Legacy' if they run tests that do not need to be recorded in the spreadsheet and can be ignored by the verification tool. @@ -68,7 +74,7 @@ Pending Tests: - To DISABLE the spreadsheet verification tool, go to the file truffle.js and comment out the following line: - reporter: 'verification/verification_reporter.js', + reporter: './verification/verification_reporter.js', Then, uncomment the line above it. //reporter: 'Spec', From 572fd5f034feee44f88ff6f8c7d5fb45e5d55756 Mon Sep 17 00:00:00 2001 From: Walker Mayerchak Date: Tue, 1 Jun 2021 17:07:33 -0400 Subject: [PATCH 73/74] delete start-ganache script --- scripts/start-ganache.sh | 1 - 1 file changed, 1 deletion(-) delete mode 100755 scripts/start-ganache.sh diff --git a/scripts/start-ganache.sh b/scripts/start-ganache.sh deleted file mode 100755 index 738a0fdde..000000000 --- a/scripts/start-ganache.sh +++ /dev/null @@ -1 +0,0 @@ -./node_modules/ganache-cli/cli.js --defaultBalanceEther 1000000 --deterministic --a 15 > ganache-blockchain-log.txt & \ No newline at end of file From 7d5e39e203651601a44a157bf5fb55497ab595f4 Mon Sep 17 00:00:00 2001 From: Walker Mayerchak Date: Tue, 1 Jun 2021 17:12:41 -0400 Subject: [PATCH 74/74] copyright fixes --- contracts/minting/Controller.sol | 2 +- contracts/minting/MasterMinter.sol | 2 +- contracts/minting/MintController.sol | 2 +- contracts/minting/MinterManagementInterface.sol | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/contracts/minting/Controller.sol b/contracts/minting/Controller.sol index 8e25ad9c2..96e3e703a 100644 --- a/contracts/minting/Controller.sol +++ b/contracts/minting/Controller.sol @@ -1,5 +1,5 @@ /** - * Copyright CENTRE SECZ 2021 + * Copyright CENTRE SECZ 2018 - 2021 * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/contracts/minting/MasterMinter.sol b/contracts/minting/MasterMinter.sol index 481e5ed28..ac3849604 100644 --- a/contracts/minting/MasterMinter.sol +++ b/contracts/minting/MasterMinter.sol @@ -1,5 +1,5 @@ /** - * Copyright CENTRE SECZ 2021 + * Copyright CENTRE SECZ 2018 - 2021 * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/contracts/minting/MintController.sol b/contracts/minting/MintController.sol index 894c8bb1a..dae187ba1 100644 --- a/contracts/minting/MintController.sol +++ b/contracts/minting/MintController.sol @@ -1,5 +1,5 @@ /** - * Copyright CENTRE SECZ 2021 + * Copyright CENTRE SECZ 2018 - 2021 * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/contracts/minting/MinterManagementInterface.sol b/contracts/minting/MinterManagementInterface.sol index 7a75b1a20..def04e6da 100644 --- a/contracts/minting/MinterManagementInterface.sol +++ b/contracts/minting/MinterManagementInterface.sol @@ -1,5 +1,5 @@ /** - * Copyright CENTRE SECZ 2021 + * Copyright CENTRE SECZ 2018 - 2021 * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal