Skip to content

Commit

Permalink
Blacklist updates (part 2)
Browse files Browse the repository at this point in the history
* Update Blacklistable methods

* Update FiatTokenV1 implementations

* Rename and refactor methods

* Update storageSlots test

* Update misc test

* Update unit tests

* Add FiatTokenV2_2 tests

* Fix test

* Fix ci

* Allow unlimited contract size on Ganache

* Update contract size check

* Change blacklist file and add comment about test file

* Fix copyright headers in PR

* Update NatSpec docs

* Also remove proxy from deprecatedBlacklisted

* Update _setBalance
  • Loading branch information
circle-aloychan committed Oct 19, 2023
1 parent 1ed8f78 commit dd03da9
Show file tree
Hide file tree
Showing 35 changed files with 1,701 additions and 167 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
run: yarn static-check

- name: Run size check
run: yarn contract-size --checkMaxSize
run: yarn contract-size

- name: Run tests
run: yarn test
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ ganache-blockchain-log.txt
.coverage_contracts
@types/generated/
config.js
blacklist.*.js
!blacklist.test.js
out/
cache/

Expand Down
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@
"licenser.license": "Custom",
"licenser.customHeader": "SPDX-License-Identifier: MIT\n\nCopyright (c) 2018-@YEAR@ CENTRE SECZ\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n",
"licenser.useSingleLineStyle": false,
"files.autoSave": "onFocusChange"
"files.autoSave": "onFocusChange",
"solidity.formatter": "none"
}
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ To run tests and generate test coverage, run:
$ yarn coverage
```

To check the size of contracts in the repo, run the following command. Add the
flag if you want it to return an error code if a contract is larger than 24KiB:
To check the size of contracts in the repo, run the following command.

```
$ yarn contract-size [--checkMaxSize]
```sh
$ yarn contract-size # Ignores tests
$ yarn contract-size:all # Includes all contracts
```

## Deployment
Expand All @@ -97,6 +97,11 @@ addresses of proxy admin, owner, master minter, blacklister, and pauser in
`config.js`. This file must not be checked into the repository. To prevent
accidental check-ins, `config.js` is in `.gitignore`.

Create a copy of the file `blacklist.test.js`, and name it
`blacklist.remote.js`. Fill in `blacklist.remote.js` with the list addresses to
blacklist. This file must not be checked into the repository. To prevent
accidental check-ins, `blacklist.remote.js` is in `.gitignore`.

Run `yarn migrate --network NETWORK`, where NETWORK is either `mainnet` or
`ropsten`.

Expand Down
37 changes: 37 additions & 0 deletions blacklist.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* SPDX-License-Identifier: MIT
*
* Copyright (c) 2018-2023 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
* 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
* 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.
*
*/

/**
* These are addresses used purely for tests. Deployers should
* create a `blacklist.remote.js` file and fill those in with
* correct addresses to blacklist before proceeding with the deploy.
*/
module.exports = [
"0x04dba1194ee10112fe6c3207c0687def0e78bacf",
"0x08a8a2436fc920e6c73c3a9e9a00b8d937812ee0",
"0xb6f5ec1a0a9cd1526536d3f0426c429529471f40",
"0xbf4f36efa3ac655a1d86f6c32b648a90271443f4",
"0xf8a9ab377ce63592583767b34602e130e38ebdca",
"0xfc672c73ca5c7234edc82552e4a0c8fc247d32ac",
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/**
* SPDX-License-Identifier: MIT
*
* Copyright (c) 2018-2023 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
* 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
* 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 { FiatTokenV2_2 } from "../v2/FiatTokenV2_2.sol";

// solhint-disable func-name-mixedcase

/**
* @title MockFiatTokenWithEditableBalanceAndBlacklistStates
* @dev A mock class that allows the internal balanceAndBlacklistStates to be manipulated in tests.
*/
contract MockFiatTokenWithEditableBalanceAndBlacklistStates is FiatTokenV2_2 {
/**
* @dev Allows the balanceAndBlacklistStates to be manipulated. This
* enables us to properly test the ERC20 functionalities.
*/
function setBalanceAndBlacklistStates(address _account, uint256 _state)
external
{
balanceAndBlacklistStates[_account] = _state;
}

/**
* @dev Allows the balanceAndBlacklistStates to be read as plain values.
*/
function getBalanceAndBlacklistStates(address _account)
external
view
returns (uint256)
{
return balanceAndBlacklistStates[_account];
}

/**
* @dev Exposes the internal function for unit testing.
*/
function internal_setBlacklistState(address _account, bool _shouldBlacklist)
external
{
_setBlacklistState(_account, _shouldBlacklist);
}

/**
* @dev Exposes the internal function for unit testing.
*/
function internal_setBalance(address _account, uint256 _balance) external {
_setBalance(_account, _balance);
}

/**
* @dev Exposes the internal function for unit testing.
*/
function internal_isBlacklisted(address _account)
external
view
returns (bool)
{
return _isBlacklisted(_account);
}

/**
* @dev Exposes the internal function for unit testing.
*/
function internal_balanceOf(address _account)
external
view
returns (uint256)
{
return _balanceOf(_account);
}
}
35 changes: 35 additions & 0 deletions contracts/test/UpgradedFiatTokenV2_2.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* SPDX-License-Identifier: MIT
*
* Copyright (c) 2018-2023 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
* 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
* 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 { FiatTokenV2_2 } from "../v2/FiatTokenV2_2.sol";

/**
* @title UpgradedFiatTokenV2_2
* @dev ERC20 Token backed by fiat reserves
*/
contract UpgradedFiatTokenV2_2 is FiatTokenV2_2 {

}
76 changes: 76 additions & 0 deletions contracts/test/UpgradedFiatTokenV2_2NewFieldsTest.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/**
* SPDX-License-Identifier: MIT
*
* Copyright (c) 2018-2023 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
* 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
* 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 { FiatTokenV2_2 } from "../v2/FiatTokenV2_2.sol";

/**
* @title UpgradedFiatTokenV2_2NewFieldsTest
* @dev ERC20 Token backed by fiat reserves
*/
contract UpgradedFiatTokenV2_2NewFieldsTest is FiatTokenV2_2 {
bool public newBool;
address public newAddress;
uint256 public newUint;
bool internal initializedV2;

function initialize(
string calldata tokenName,
string calldata tokenSymbol,
string calldata tokenCurrency,
uint8 tokenDecimals,
address newMasterMinter,
address newPauser,
address newBlacklister,
address newOwner,
bool _newBool,
address _newAddress,
uint256 _newUint
) external {
super.initialize(
tokenName,
tokenSymbol,
tokenCurrency,
tokenDecimals,
newMasterMinter,
newPauser,
newBlacklister,
newOwner
);
initV2(_newBool, _newAddress, _newUint);
}

function initV2(
bool _newBool,
address _newAddress,
uint256 _newUint
) public {
require(!initializedV2, "contract is already initialized");
newBool = _newBool;
newAddress = _newAddress;
newUint = _newUint;
initializedV2 = true;
}
}
33 changes: 28 additions & 5 deletions contracts/v1/Blacklistable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { Ownable } from "./Ownable.sol";
* @title Blacklistable Token
* @dev Allows accounts to be blacklisted by a "blacklister" role
*/
contract Blacklistable is Ownable {
abstract contract Blacklistable is Ownable {
address public blacklister;
mapping(address => bool) internal _deprecatedBlacklisted;

Expand All @@ -55,7 +55,7 @@ contract Blacklistable is Ownable {
*/
modifier notBlacklisted(address _account) {
require(
!_deprecatedBlacklisted[_account],
!_isBlacklisted(_account),
"Blacklistable: account is blacklisted"
);
_;
Expand All @@ -66,15 +66,15 @@ contract Blacklistable is Ownable {
* @param _account The address to check
*/
function isBlacklisted(address _account) external view returns (bool) {
return _deprecatedBlacklisted[_account];
return _isBlacklisted(_account);
}

/**
* @dev Adds account to blacklist
* @param _account The address to blacklist
*/
function blacklist(address _account) external onlyBlacklister {
_deprecatedBlacklisted[_account] = true;
_blacklist(_account);
emit Blacklisted(_account);
}

Expand All @@ -83,7 +83,7 @@ contract Blacklistable is Ownable {
* @param _account The address to remove from the blacklist
*/
function unBlacklist(address _account) external onlyBlacklister {
_deprecatedBlacklisted[_account] = false;
_unBlacklist(_account);
emit UnBlacklisted(_account);
}

Expand All @@ -95,4 +95,27 @@ contract Blacklistable is Ownable {
blacklister = _newBlacklister;
emit BlacklisterChanged(blacklister);
}

/**
* @dev Checks if account is blacklisted.
* @param _account The address to check.
* @return true if the account is blacklisted, false otherwise.
*/
function _isBlacklisted(address _account)
internal
virtual
view
returns (bool);

/**
* @dev Helper method that blacklists an account.
* @param _account The address to blacklist.
*/
function _blacklist(address _account) internal virtual;

/**
* @dev Helper method that unblacklists an account.
* @param _account The address to unblacklist.
*/
function _unBlacklist(address _account) internal virtual;
}
Loading

0 comments on commit dd03da9

Please sign in to comment.