diff --git a/.solhintignore b/.solhintignore index 0a63aad2..1f94c2ed 100644 --- a/.solhintignore +++ b/.solhintignore @@ -1 +1 @@ -src/contracts/test/vendor/ +src/contracts/test diff --git a/src/contracts/test b/src/contracts/test new file mode 120000 index 00000000..c0c2d191 --- /dev/null +++ b/src/contracts/test @@ -0,0 +1 @@ +../../test/src \ No newline at end of file diff --git a/src/contracts/test/GPv2AllowListAuthenticationTestInterface.sol b/src/contracts/test/GPv2AllowListAuthenticationTestInterface.sol deleted file mode 100644 index e8c91d6c..00000000 --- a/src/contracts/test/GPv2AllowListAuthenticationTestInterface.sol +++ /dev/null @@ -1,13 +0,0 @@ -// SPDX-License-Identifier: LGPL-3.0-or-later -pragma solidity >=0.7.6 <0.9.0; - -import "../GPv2AllowListAuthentication.sol"; -import "../libraries/GPv2EIP1967.sol"; - -contract GPv2AllowListAuthenticationTestInterface is - GPv2AllowListAuthentication -{ - constructor(address owner) { - GPv2EIP1967.setAdmin(owner); - } -} diff --git a/src/contracts/test/GPv2TransferTestInterface.sol b/src/contracts/test/GPv2TransferTestInterface.sol deleted file mode 100644 index 7b079528..00000000 --- a/src/contracts/test/GPv2TransferTestInterface.sol +++ /dev/null @@ -1,33 +0,0 @@ -// SPDX-License-Identifier: LGPL-3.0-or-later -pragma solidity >=0.7.6 <0.9.0; -pragma abicoder v2; - -import "../libraries/GPv2Transfer.sol"; - -contract GPv2TransferTestInterface { - function fastTransferFromAccountTest( - IVault vault, - GPv2Transfer.Data calldata transfer, - address recipient - ) external { - GPv2Transfer.fastTransferFromAccount(vault, transfer, recipient); - } - - function transferFromAccountsTest( - IVault vault, - GPv2Transfer.Data[] calldata transfers, - address recipient - ) external { - GPv2Transfer.transferFromAccounts(vault, transfers, recipient); - } - - function transferToAccountsTest( - IVault vault, - GPv2Transfer.Data[] memory transfers - ) external { - GPv2Transfer.transferToAccounts(vault, transfers); - } - - // solhint-disable-next-line no-empty-blocks - receive() external payable {} -} diff --git a/test/reader/StorageAccessible.t.sol b/test/reader/StorageAccessible.t.sol index 7591d661..2af27890 100644 --- a/test/reader/StorageAccessible.t.sol +++ b/test/reader/StorageAccessible.t.sol @@ -4,7 +4,7 @@ pragma solidity >=0.7.6 <0.9.0; pragma abicoder v2; import {Test, Vm} from "forge-std/Test.sol"; -import {StorageAccessibleWrapper, ExternalStorageReader} from "src/contracts/test/vendor/StorageAccessibleWrapper.sol"; +import {StorageAccessibleWrapper, ExternalStorageReader} from "test/src/vendor/StorageAccessibleWrapper.sol"; import {ViewStorageAccessible} from "src/contracts/mixins/StorageAccessible.sol"; contract StorageAccessibleTest is Test { diff --git a/test/reader/StorageReadable.t.sol b/test/reader/StorageReadable.t.sol index 842193b4..8ee1da68 100644 --- a/test/reader/StorageReadable.t.sol +++ b/test/reader/StorageReadable.t.sol @@ -3,7 +3,7 @@ pragma solidity >=0.7.6 <0.9.0; pragma abicoder v2; import {Test} from "forge-std/Test.sol"; -import {StorageAccessibleWrapper} from "src/contracts/test/vendor/StorageAccessibleWrapper.sol"; +import {StorageAccessibleWrapper} from "test/src/vendor/StorageAccessibleWrapper.sol"; contract StorageReadableTest is Test { StorageAccessibleWrapper instance; diff --git a/test/reader/ViewStorageAccessible.t.sol b/test/reader/ViewStorageAccessible.t.sol index e38f701b..d22caeeb 100644 --- a/test/reader/ViewStorageAccessible.t.sol +++ b/test/reader/ViewStorageAccessible.t.sol @@ -4,7 +4,7 @@ pragma solidity >=0.7.6 <0.9.0; pragma abicoder v2; import {Test} from "forge-std/Test.sol"; -import {StorageAccessibleWrapper, ExternalStorageReader} from "src/contracts/test/vendor/StorageAccessibleWrapper.sol"; +import {StorageAccessibleWrapper, ExternalStorageReader} from "test/src/vendor/StorageAccessibleWrapper.sol"; import {ViewStorageAccessible} from "src/contracts/mixins/StorageAccessible.sol"; contract StorageAccessibleTest is Test { diff --git a/src/contracts/test/ERC20PresetPermit.sol b/test/src/ERC20PresetPermit.sol similarity index 75% rename from src/contracts/test/ERC20PresetPermit.sol rename to test/src/ERC20PresetPermit.sol index 9c946278..4567df52 100644 --- a/src/contracts/test/ERC20PresetPermit.sol +++ b/test/src/ERC20PresetPermit.sol @@ -5,15 +5,9 @@ import "@openzeppelin/contracts/drafts/ERC20Permit.sol"; import "@openzeppelin/contracts/presets/ERC20PresetMinterPauser.sol"; contract ERC20PresetPermit is ERC20Permit { - constructor( - string memory symbol - ) - ERC20(symbol, symbol) - ERC20Permit(symbol) + constructor(string memory symbol) ERC20(symbol, symbol) ERC20Permit(symbol) // solhint-disable-next-line no-empty-blocks - { - - } + {} function mint(address to, uint256 amount) external { _mint(to, amount); diff --git a/src/contracts/test/EventEmitter.sol b/test/src/EventEmitter.sol similarity index 100% rename from src/contracts/test/EventEmitter.sol rename to test/src/EventEmitter.sol diff --git a/src/contracts/test/FeeClaimingERC20.sol b/test/src/FeeClaimingERC20.sol similarity index 80% rename from src/contracts/test/FeeClaimingERC20.sol rename to test/src/FeeClaimingERC20.sol index 6c4fcb5a..41edc009 100644 --- a/src/contracts/test/FeeClaimingERC20.sol +++ b/test/src/FeeClaimingERC20.sol @@ -7,11 +7,7 @@ contract FeeClaimingERC20 is ERC20PresetMinterPauser { // solhint-disable-next-line no-empty-blocks constructor() ERC20PresetMinterPauser("FEE", "FEE") {} - function _transfer( - address sender, - address recipient, - uint256 amount - ) internal override { + function _transfer(address sender, address recipient, uint256 amount) internal override { uint256 finalAmount = (amount * 99) / 100; uint256 burnAmount = amount - finalAmount; diff --git a/test/src/GPv2AllowListAuthenticationTestInterface.sol b/test/src/GPv2AllowListAuthenticationTestInterface.sol new file mode 100644 index 00000000..f4c553c2 --- /dev/null +++ b/test/src/GPv2AllowListAuthenticationTestInterface.sol @@ -0,0 +1,11 @@ +// SPDX-License-Identifier: LGPL-3.0-or-later +pragma solidity >=0.7.6 <0.9.0; + +import "src/contracts/GPv2AllowListAuthentication.sol"; +import "src/contracts/libraries/GPv2EIP1967.sol"; + +contract GPv2AllowListAuthenticationTestInterface is GPv2AllowListAuthentication { + constructor(address owner) { + GPv2EIP1967.setAdmin(owner); + } +} diff --git a/src/contracts/test/GPv2AllowListAuthenticationV2.sol b/test/src/GPv2AllowListAuthenticationV2.sol similarity index 81% rename from src/contracts/test/GPv2AllowListAuthenticationV2.sol rename to test/src/GPv2AllowListAuthenticationV2.sol index 17ea7aa8..9b015014 100644 --- a/src/contracts/test/GPv2AllowListAuthenticationV2.sol +++ b/test/src/GPv2AllowListAuthenticationV2.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: LGPL-3.0-or-later pragma solidity >=0.7.6 <0.9.0; -import "../GPv2AllowListAuthentication.sol"; +import "src/contracts/GPv2AllowListAuthentication.sol"; contract GPv2AllowListAuthenticationV2 is GPv2AllowListAuthentication { function newMethod() external pure returns (uint256) { diff --git a/src/contracts/test/GPv2InteractionTestInterface.sol b/test/src/GPv2InteractionTestInterface.sol similarity index 72% rename from src/contracts/test/GPv2InteractionTestInterface.sol rename to test/src/GPv2InteractionTestInterface.sol index b7a63cff..cdea6149 100644 --- a/src/contracts/test/GPv2InteractionTestInterface.sol +++ b/test/src/GPv2InteractionTestInterface.sol @@ -2,7 +2,7 @@ pragma solidity >=0.7.6 <0.9.0; pragma abicoder v2; -import "../libraries/GPv2Interaction.sol"; +import "src/contracts/libraries/GPv2Interaction.sol"; contract GPv2InteractionTestInterface { // solhint-disable-next-line no-empty-blocks @@ -12,9 +12,7 @@ contract GPv2InteractionTestInterface { GPv2Interaction.execute(interaction); } - function selectorTest( - GPv2Interaction.Data calldata interaction - ) external pure returns (bytes4) { + function selectorTest(GPv2Interaction.Data calldata interaction) external pure returns (bytes4) { return GPv2Interaction.selector(interaction); } } diff --git a/src/contracts/test/GPv2OrderTestInterface.sol b/test/src/GPv2OrderTestInterface.sol similarity index 58% rename from src/contracts/test/GPv2OrderTestInterface.sol rename to test/src/GPv2OrderTestInterface.sol index db39a4f7..75413a42 100644 --- a/src/contracts/test/GPv2OrderTestInterface.sol +++ b/test/src/GPv2OrderTestInterface.sol @@ -2,7 +2,7 @@ pragma solidity >=0.7.6 <0.9.0; pragma abicoder v2; -import "../libraries/GPv2Order.sol"; +import "src/contracts/libraries/GPv2Order.sol"; contract GPv2OrderTestInterface { using GPv2Order for GPv2Order.Data; @@ -12,26 +12,24 @@ contract GPv2OrderTestInterface { return GPv2Order.TYPE_HASH; } - function hashTest( - GPv2Order.Data memory order, - bytes32 domainSeparator - ) external pure returns (bytes32 orderDigest) { + function hashTest(GPv2Order.Data memory order, bytes32 domainSeparator) + external + pure + returns (bytes32 orderDigest) + { orderDigest = order.hash(domainSeparator); } - function packOrderUidParamsTest( - uint256 bufferLength, - bytes32 orderDigest, - address owner, - uint32 validTo - ) external pure returns (bytes memory orderUid) { + function packOrderUidParamsTest(uint256 bufferLength, bytes32 orderDigest, address owner, uint32 validTo) + external + pure + returns (bytes memory orderUid) + { orderUid = new bytes(bufferLength); orderUid.packOrderUidParams(orderDigest, owner, validTo); } - function extractOrderUidParamsTest( - bytes calldata orderUid - ) + function extractOrderUidParamsTest(bytes calldata orderUid) external pure returns (bytes32 orderDigest, address owner, uint32 validTo) diff --git a/src/contracts/test/GPv2SettlementTestInterface.sol b/test/src/GPv2SettlementTestInterface.sol similarity index 70% rename from src/contracts/test/GPv2SettlementTestInterface.sol rename to test/src/GPv2SettlementTestInterface.sol index c970c524..cbcdd77e 100644 --- a/src/contracts/test/GPv2SettlementTestInterface.sol +++ b/test/src/GPv2SettlementTestInterface.sol @@ -2,21 +2,15 @@ pragma solidity >=0.7.6 <0.9.0; pragma abicoder v2; -import "../GPv2Settlement.sol"; -import "../libraries/GPv2Interaction.sol"; -import "../libraries/GPv2Trade.sol"; -import "../libraries/GPv2Transfer.sol"; +import "src/contracts/GPv2Settlement.sol"; +import "src/contracts/libraries/GPv2Interaction.sol"; +import "src/contracts/libraries/GPv2Trade.sol"; +import "src/contracts/libraries/GPv2Transfer.sol"; contract GPv2SettlementTestInterface is GPv2Settlement { - constructor( - GPv2Authentication authenticator_, - IVault vault - ) - GPv2Settlement(authenticator_, vault) + constructor(GPv2Authentication authenticator_, IVault vault) GPv2Settlement(authenticator_, vault) // solhint-disable-next-line no-empty-blocks - { - - } + {} function setFilledAmount(bytes calldata orderUid, uint256 amount) external { filledAmount[orderUid] = amount; @@ -26,18 +20,8 @@ contract GPv2SettlementTestInterface is GPv2Settlement { IERC20[] calldata tokens, uint256[] calldata clearingPrices, GPv2Trade.Data[] calldata trades - ) - external - returns ( - GPv2Transfer.Data[] memory inTransfers, - GPv2Transfer.Data[] memory outTransfers - ) - { - (inTransfers, outTransfers) = computeTradeExecutions( - tokens, - clearingPrices, - trades - ); + ) external returns (GPv2Transfer.Data[] memory inTransfers, GPv2Transfer.Data[] memory outTransfers) { + (inTransfers, outTransfers) = computeTradeExecutions(tokens, clearingPrices, trades); } function computeTradeExecutionMemoryTest() external returns (uint256 mem) { @@ -63,9 +47,7 @@ contract GPv2SettlementTestInterface is GPv2Settlement { } } - function executeInteractionsTest( - GPv2Interaction.Data[] calldata interactions - ) external { + function executeInteractionsTest(GPv2Interaction.Data[] calldata interactions) external { executeInteractions(interactions); } diff --git a/src/contracts/test/GPv2SigningTestInterface.sol b/test/src/GPv2SigningTestInterface.sol similarity index 62% rename from src/contracts/test/GPv2SigningTestInterface.sol rename to test/src/GPv2SigningTestInterface.sol index 556b8ea1..a40d3b45 100644 --- a/src/contracts/test/GPv2SigningTestInterface.sol +++ b/test/src/GPv2SigningTestInterface.sol @@ -2,15 +2,16 @@ pragma solidity >=0.7.6 <0.9.0; pragma abicoder v2; -import "../libraries/GPv2Order.sol"; -import "../libraries/GPv2Trade.sol"; -import "../mixins/GPv2Signing.sol"; +import "src/contracts/libraries/GPv2Order.sol"; +import "src/contracts/libraries/GPv2Trade.sol"; +import "src/contracts/mixins/GPv2Signing.sol"; contract GPv2SigningTestInterface is GPv2Signing { - function recoverOrderFromTradeTest( - IERC20[] calldata tokens, - GPv2Trade.Data calldata trade - ) external view returns (RecoveredOrder memory recoveredOrder) { + function recoverOrderFromTradeTest(IERC20[] calldata tokens, GPv2Trade.Data calldata trade) + external + view + returns (RecoveredOrder memory recoveredOrder) + { recoveredOrder = allocateRecoveredOrder(); recoverOrderFromTrade(recoveredOrder, tokens, trade); } diff --git a/src/contracts/test/GPv2TradeTestInterface.sol b/test/src/GPv2TradeTestInterface.sol similarity index 61% rename from src/contracts/test/GPv2TradeTestInterface.sol rename to test/src/GPv2TradeTestInterface.sol index a92b4476..3f92ea53 100644 --- a/src/contracts/test/GPv2TradeTestInterface.sol +++ b/test/src/GPv2TradeTestInterface.sol @@ -2,20 +2,19 @@ pragma solidity >=0.7.6 <0.9.0; pragma abicoder v2; -import "../libraries/GPv2Order.sol"; -import "../libraries/GPv2Trade.sol"; +import "src/contracts/libraries/GPv2Order.sol"; +import "src/contracts/libraries/GPv2Trade.sol"; contract GPv2TradeTestInterface { - function extractOrderTest( - IERC20[] calldata tokens, - GPv2Trade.Data calldata trade - ) external pure returns (GPv2Order.Data memory order) { + function extractOrderTest(IERC20[] calldata tokens, GPv2Trade.Data calldata trade) + external + pure + returns (GPv2Order.Data memory order) + { GPv2Trade.extractOrder(trade, tokens, order); } - function extractFlagsTest( - uint256 flags - ) + function extractFlagsTest(uint256 flags) external pure returns ( diff --git a/test/src/GPv2TransferTestInterface.sol b/test/src/GPv2TransferTestInterface.sol new file mode 100644 index 00000000..984e0b99 --- /dev/null +++ b/test/src/GPv2TransferTestInterface.sol @@ -0,0 +1,26 @@ +// SPDX-License-Identifier: LGPL-3.0-or-later +pragma solidity >=0.7.6 <0.9.0; +pragma abicoder v2; + +import "src/contracts/libraries/GPv2Transfer.sol"; + +contract GPv2TransferTestInterface { + function fastTransferFromAccountTest(IVault vault, GPv2Transfer.Data calldata transfer, address recipient) + external + { + GPv2Transfer.fastTransferFromAccount(vault, transfer, recipient); + } + + function transferFromAccountsTest(IVault vault, GPv2Transfer.Data[] calldata transfers, address recipient) + external + { + GPv2Transfer.transferFromAccounts(vault, transfers, recipient); + } + + function transferToAccountsTest(IVault vault, GPv2Transfer.Data[] memory transfers) external { + GPv2Transfer.transferToAccounts(vault, transfers); + } + + // solhint-disable-next-line no-empty-blocks + receive() external payable {} +} diff --git a/src/contracts/test/NonPayable.sol b/test/src/NonPayable.sol similarity index 100% rename from src/contracts/test/NonPayable.sol rename to test/src/NonPayable.sol diff --git a/src/contracts/test/NonStandardERC20.sol b/test/src/NonStandardERC20.sol similarity index 84% rename from src/contracts/test/NonStandardERC20.sol rename to test/src/NonStandardERC20.sol index a32ebb2a..19eb8a3b 100644 --- a/src/contracts/test/NonStandardERC20.sol +++ b/test/src/NonStandardERC20.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: LGPL-3.0-or-later pragma solidity >=0.7.6 <0.9.0; -import "../libraries/SafeMath.sol"; +import "src/contracts/libraries/SafeMath.sol"; abstract contract NonStandardERC20 { using SafeMath for uint256; @@ -41,19 +41,14 @@ contract ERC20NoReturn is NonStandardERC20 { contract ERC20ReturningUint is NonStandardERC20 { // Largest 256-bit prime :) - uint256 private constant OK = - 115792089237316195423570985008687907853269984665640564039457584007913129639747; + uint256 private constant OK = 115792089237316195423570985008687907853269984665640564039457584007913129639747; function transfer(address to, uint256 amount) external returns (uint256) { transfer_(to, amount); return OK; } - function transferFrom( - address from, - address to, - uint256 amount - ) external returns (uint256) { + function transferFrom(address from, address to, uint256 amount) external returns (uint256) { transferFrom_(from, to, amount); return OK; } diff --git a/src/contracts/test/SmartSellOrder.sol b/test/src/SmartSellOrder.sol similarity index 73% rename from src/contracts/test/SmartSellOrder.sol rename to test/src/SmartSellOrder.sol index c050f183..d828e975 100644 --- a/src/contracts/test/SmartSellOrder.sol +++ b/test/src/SmartSellOrder.sol @@ -2,12 +2,12 @@ pragma solidity >=0.7.6 <0.9.0; pragma abicoder v2; -import "../interfaces/GPv2EIP1271.sol"; -import "../interfaces/IERC20.sol"; -import "../libraries/GPv2Order.sol"; -import "../libraries/GPv2SafeERC20.sol"; -import "../libraries/SafeMath.sol"; -import "../GPv2Settlement.sol"; +import "src/contracts/interfaces/GPv2EIP1271.sol"; +import "src/contracts/interfaces/IERC20.sol"; +import "src/contracts/libraries/GPv2Order.sol"; +import "src/contracts/libraries/GPv2SafeERC20.sol"; +import "src/contracts/libraries/SafeMath.sol"; +import "src/contracts/GPv2Settlement.sol"; /// @title Proof of Concept Smart Order /// @author Gnosis Developers @@ -42,10 +42,7 @@ contract SmartSellOrder is EIP1271Verifier { totalSellAmount = totalSellAmount_; totalFeeAmount = totalFeeAmount_; - sellToken_.approve( - address(settlement.vaultRelayer()), - type(uint256).max - ); + sellToken_.approve(address(settlement.vaultRelayer()), type(uint256).max); } modifier onlyOwner() { @@ -65,10 +62,12 @@ contract SmartSellOrder is EIP1271Verifier { selfdestruct(payable(owner)); } - function isValidSignature( - bytes32 hash, - bytes memory signature - ) external view override returns (bytes4 magicValue) { + function isValidSignature(bytes32 hash, bytes memory signature) + external + view + override + returns (bytes4 magicValue) + { uint256 sellAmount = abi.decode(signature, (uint256)); GPv2Order.Data memory order = orderForSellAmount(sellAmount); @@ -77,9 +76,7 @@ contract SmartSellOrder is EIP1271Verifier { } } - function orderForSellAmount( - uint256 sellAmount - ) public view returns (GPv2Order.Data memory order) { + function orderForSellAmount(uint256 sellAmount) public view returns (GPv2Order.Data memory order) { order.sellToken = sellToken; order.buyToken = buyToken; order.receiver = owner; @@ -98,22 +95,14 @@ contract SmartSellOrder is EIP1271Verifier { order.buyTokenBalance = GPv2Order.BALANCE_ERC20; } - function buyAmountForSellAmount( - uint256 sellAmount - ) private view returns (uint256 buyAmount) { - uint256 feeAdjustedBalance = sellToken - .balanceOf(address(this)) - .mul(totalSellAmount) - .div(totalSellAmount.add(totalFeeAmount)); - uint256 soldAmount = totalSellAmount > feeAdjustedBalance - ? totalSellAmount - feeAdjustedBalance - : 0; + function buyAmountForSellAmount(uint256 sellAmount) private view returns (uint256 buyAmount) { + uint256 feeAdjustedBalance = + sellToken.balanceOf(address(this)).mul(totalSellAmount).div(totalSellAmount.add(totalFeeAmount)); + uint256 soldAmount = totalSellAmount > feeAdjustedBalance ? totalSellAmount - feeAdjustedBalance : 0; // NOTE: This is currently a silly price strategy where the xrate // increases linearly from 1:1 to 1:2 as the smart order gets filled. // This can be extended to more complex "price curves". - buyAmount = sellAmount - .mul(totalSellAmount.add(sellAmount).add(soldAmount)) - .div(totalSellAmount); + buyAmount = sellAmount.mul(totalSellAmount.add(sellAmount).add(soldAmount)).div(totalSellAmount); } } diff --git a/src/contracts/test/StateChangingERC1271.sol b/test/src/StateChangingERC1271.sol similarity index 83% rename from src/contracts/test/StateChangingERC1271.sol rename to test/src/StateChangingERC1271.sol index 12c3190f..215939a6 100644 --- a/src/contracts/test/StateChangingERC1271.sol +++ b/test/src/StateChangingERC1271.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: LGPL-3.0-or-later pragma solidity >=0.7.6 <0.9.0; -import "../interfaces/GPv2EIP1271.sol"; +import "src/contracts/interfaces/GPv2EIP1271.sol"; /// @dev This contract implements the standard described in EIP-1271 with the /// minor change that the verification function changes the state. This is @@ -10,10 +10,7 @@ contract StateChangingEIP1271 { uint256 public state = 0; // solhint-disable-next-line no-unused-vars - function isValidSignature( - bytes32 _hash, - bytes memory _signature - ) public returns (bytes4 magicValue) { + function isValidSignature(bytes32 _hash, bytes memory _signature) public returns (bytes4 magicValue) { state += 1; magicValue = GPv2EIP1271.MAGICVALUE; diff --git a/src/contracts/test/TestERC20.sol b/test/src/TestERC20.sol similarity index 64% rename from src/contracts/test/TestERC20.sol rename to test/src/TestERC20.sol index 97464476..fd13b64b 100644 --- a/src/contracts/test/TestERC20.sol +++ b/test/src/TestERC20.sol @@ -4,10 +4,7 @@ pragma solidity ^0.7.6; import "@openzeppelin/contracts/presets/ERC20PresetMinterPauser.sol"; contract TestERC20 is ERC20PresetMinterPauser { - constructor( - string memory symbol, - uint8 decimals - ) ERC20PresetMinterPauser(symbol, symbol) { + constructor(string memory symbol, uint8 decimals) ERC20PresetMinterPauser(symbol, symbol) { _setupDecimals(decimals); } } diff --git a/src/contracts/test/vendor/ChiToken.sol b/test/src/vendor/ChiToken.sol similarity index 69% rename from src/contracts/test/vendor/ChiToken.sol rename to test/src/vendor/ChiToken.sol index b635213a..f71bef21 100644 --- a/src/contracts/test/vendor/ChiToken.sol +++ b/test/src/vendor/ChiToken.sol @@ -6,7 +6,6 @@ import "@openzeppelin/contracts/math/Math.sol"; import "@openzeppelin/contracts/math/SafeMath.sol"; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; - abstract contract ERC20WithoutTotalSupply is IERC20 { using SafeMath for uint256; @@ -70,16 +69,15 @@ abstract contract ERC20WithoutTotalSupply is IERC20 { } } - contract ChiToken is IERC20, ERC20WithoutTotalSupply { - string constant public name = "Chi Token by 1inch"; - string constant public symbol = "CHI"; - uint8 constant public decimals = 0; + string public constant name = "Chi Token by 1inch"; + string public constant symbol = "CHI"; + uint8 public constant decimals = 0; uint256 public totalMinted; uint256 public totalBurned; - function totalSupply() public view override returns(uint256) { + function totalSupply() public view override returns (uint256) { return totalMinted - totalBurned; } @@ -88,27 +86,43 @@ contract ChiToken is IERC20, ERC20WithoutTotalSupply { assembly { mstore(0, 0x746d4946c0e9F43F4Dee607b0eF1fA1c3318585733ff6000526015600bf30000) - for {let i := div(value, 32)} i {i := sub(i, 1)} { - pop(create2(0, 0, 30, add(offset, 0))) pop(create2(0, 0, 30, add(offset, 1))) - pop(create2(0, 0, 30, add(offset, 2))) pop(create2(0, 0, 30, add(offset, 3))) - pop(create2(0, 0, 30, add(offset, 4))) pop(create2(0, 0, 30, add(offset, 5))) - pop(create2(0, 0, 30, add(offset, 6))) pop(create2(0, 0, 30, add(offset, 7))) - pop(create2(0, 0, 30, add(offset, 8))) pop(create2(0, 0, 30, add(offset, 9))) - pop(create2(0, 0, 30, add(offset, 10))) pop(create2(0, 0, 30, add(offset, 11))) - pop(create2(0, 0, 30, add(offset, 12))) pop(create2(0, 0, 30, add(offset, 13))) - pop(create2(0, 0, 30, add(offset, 14))) pop(create2(0, 0, 30, add(offset, 15))) - pop(create2(0, 0, 30, add(offset, 16))) pop(create2(0, 0, 30, add(offset, 17))) - pop(create2(0, 0, 30, add(offset, 18))) pop(create2(0, 0, 30, add(offset, 19))) - pop(create2(0, 0, 30, add(offset, 20))) pop(create2(0, 0, 30, add(offset, 21))) - pop(create2(0, 0, 30, add(offset, 22))) pop(create2(0, 0, 30, add(offset, 23))) - pop(create2(0, 0, 30, add(offset, 24))) pop(create2(0, 0, 30, add(offset, 25))) - pop(create2(0, 0, 30, add(offset, 26))) pop(create2(0, 0, 30, add(offset, 27))) - pop(create2(0, 0, 30, add(offset, 28))) pop(create2(0, 0, 30, add(offset, 29))) - pop(create2(0, 0, 30, add(offset, 30))) pop(create2(0, 0, 30, add(offset, 31))) + for { let i := div(value, 32) } i { i := sub(i, 1) } { + pop(create2(0, 0, 30, add(offset, 0))) + pop(create2(0, 0, 30, add(offset, 1))) + pop(create2(0, 0, 30, add(offset, 2))) + pop(create2(0, 0, 30, add(offset, 3))) + pop(create2(0, 0, 30, add(offset, 4))) + pop(create2(0, 0, 30, add(offset, 5))) + pop(create2(0, 0, 30, add(offset, 6))) + pop(create2(0, 0, 30, add(offset, 7))) + pop(create2(0, 0, 30, add(offset, 8))) + pop(create2(0, 0, 30, add(offset, 9))) + pop(create2(0, 0, 30, add(offset, 10))) + pop(create2(0, 0, 30, add(offset, 11))) + pop(create2(0, 0, 30, add(offset, 12))) + pop(create2(0, 0, 30, add(offset, 13))) + pop(create2(0, 0, 30, add(offset, 14))) + pop(create2(0, 0, 30, add(offset, 15))) + pop(create2(0, 0, 30, add(offset, 16))) + pop(create2(0, 0, 30, add(offset, 17))) + pop(create2(0, 0, 30, add(offset, 18))) + pop(create2(0, 0, 30, add(offset, 19))) + pop(create2(0, 0, 30, add(offset, 20))) + pop(create2(0, 0, 30, add(offset, 21))) + pop(create2(0, 0, 30, add(offset, 22))) + pop(create2(0, 0, 30, add(offset, 23))) + pop(create2(0, 0, 30, add(offset, 24))) + pop(create2(0, 0, 30, add(offset, 25))) + pop(create2(0, 0, 30, add(offset, 26))) + pop(create2(0, 0, 30, add(offset, 27))) + pop(create2(0, 0, 30, add(offset, 28))) + pop(create2(0, 0, 30, add(offset, 29))) + pop(create2(0, 0, 30, add(offset, 30))) + pop(create2(0, 0, 30, add(offset, 31))) offset := add(offset, 32) } - for {let i := and(value, 0x1F)} i {i := sub(i, 1)} { + for { let i := and(value, 0x1F) } i { i := sub(i, 1) } { pop(create2(0, 0, 30, offset)) offset := add(offset, 1) } @@ -138,14 +152,14 @@ contract ChiToken is IERC20, ERC20WithoutTotalSupply { mstore(data, 0xff0000000000004946c0e9F43F4Dee607b0eF1fA1c0000000000000000000000) mstore(add(data, 53), 0x3c1644c68e5d6cb380c36d1bf847fdbc0c7ac28030025a2fc5e63cce23c16348) let ptr := add(data, 21) - for { } lt(i, end) { i := add(i, 1) } { + for {} lt(i, end) { i := add(i, 1) } { mstore(ptr, i) pop(call(gas(), keccak256(data, 85), 0, 0, 0, 0, 0)) } } } - function free(uint256 value) public returns (uint256) { + function free(uint256 value) public returns (uint256) { if (value > 0) { _burn(msg.sender, value); _destroyChildren(value); diff --git a/src/contracts/test/vendor/StorageAccessibleWrapper.sol b/test/src/vendor/StorageAccessibleWrapper.sol similarity index 78% rename from src/contracts/test/vendor/StorageAccessibleWrapper.sol rename to test/src/vendor/StorageAccessibleWrapper.sol index ed2c1313..3c53e679 100644 --- a/src/contracts/test/vendor/StorageAccessibleWrapper.sol +++ b/test/src/vendor/StorageAccessibleWrapper.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: LGPL-3.0-only pragma solidity >=0.7.6 <0.9.0; -import "../../mixins/StorageAccessible.sol"; +import "src/contracts/mixins/StorageAccessible.sol"; contract StorageAccessibleWrapper is StorageAccessible { struct FooBar { @@ -71,23 +71,16 @@ contract ExternalStorageReader { revert(); } - function invokeDoRevertViaStorageAccessible(StorageAccessible target) - public - { - target.simulateDelegatecall( - address(this), - abi.encodeWithSignature("doRevert()") - ); + function invokeDoRevertViaStorageAccessible(StorageAccessible target) public { + target.simulateDelegatecall(address(this), abi.encodeWithSignature("doRevert()")); } - function invokeStaticDelegatecall( - ViewStorageAccessible target, - bytes calldata encodedCall - ) public view returns (uint256) { - uint256 result = abi.decode( - target.simulateDelegatecall(address(this), encodedCall), - (uint256) - ); + function invokeStaticDelegatecall(ViewStorageAccessible target, bytes calldata encodedCall) + public + view + returns (uint256) + { + uint256 result = abi.decode(target.simulateDelegatecall(address(this), encodedCall), (uint256)); return result; } }