* added initial foundry transformERC20 tests * added foundry tests into CircleCI flow * add verbosity for failing tests in CI * revert wrong CI commands * feat: Foundry, added some more deployments (#558) * Added some more deployments * Rename WETH9 to WETH9V06 * Set to 0.6.x * fix typo * remove commit with bad prettier changes * working bridge Fills through weth transformer * remove unused reference * clean up tests * added working otc fill through transformERC20 in FQT * resolve file imports, add samplers, arbitrumBridgeAdatper, and new FQT version * add extra 'v' for debugging verbosity * add extra 'v' for debugging verbosity in circleci config * remove old traces * refactor rpc's out of foundry.toml and into .env for CI compatibility * remove verbosity from CI command as its now defined in foundry.toml * setup rpc's * ignore foundry artifacts in prettier * change naming in prettierignore * move /samplers to the tests subdirectory, modify remappings to reflext change * one more try 🤞 * change CI steps * remove yarn from CI step * get to the right directory * update foundry before tests * fix tip() deprecation and use deal() * use deal() instead of vm.deal() * try to get foundry to have the right directory structure by updating it * I HATE THIS * remove foundryup * Fix prettier issues * Remove obsoleted import * Use forge native commands to install deps and test and add the --root option * Try using forge with working-directory flag in CI * Use nightly foundry docker image * Update rpc endpoints config in foundry * move tests into /forked and /local * rename tests * add foundry profiles to CI * try to fix CI * 🔧 add foundry local and forked tests to workflow * prettier and lint * revert deps update * remove all samplers and add uniswapV2 sampler to ForkUtils * address jacobs comments * cleanup and comment * prettier and lint * bump contracts-zero-ex version * set func-name-mixedcase to off in solhint for elenas new changes * max line length to warn * add --fix for check-md * Update ci.yml * fix some nitpcks and leftover code * fix inconsistent naming * fix bridge adapter reverts and foundry cache * migrate foundry integration tests to /tests * refactor contract-addresses to use the contract-addresses package style nested json * fix solhint * fix contract linting errors * dont check broken links in libraries * move forge order in gh action for testing * add env instead of vars * try again * fix github actions ordering * update licence and address comments * remove verbosity from foundry.toml * fix contract lint * move back to emitting an event until samplers can be integrated as some chains dont have uniswap as a source * add uniswap v3 sampling code for future use * remove uniswap v3 code as its not used * fix lint Co-authored-by: Noah Khamliche <0xnoah@Noahs-MacBook-Pro-2.local> Co-authored-by: Jacob Evans <jacob@dekz.net> Co-authored-by: elenadimitrova <elena@arenabg.com>
143 lines
5.0 KiB
Solidity
143 lines
5.0 KiB
Solidity
// SPDX-License-Identifier: Apache-2.0
|
|
/*
|
|
Copyright 2023 ZeroEx Intl.
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
pragma solidity ^0.6.5;
|
|
pragma experimental ABIEncoderV2;
|
|
|
|
import "./BaseTest.sol";
|
|
import "../contracts/src/external/FlashWallet.sol";
|
|
import "./mocks/TestCallTarget.sol";
|
|
|
|
contract FlashWalletTest is BaseTest {
|
|
address public owner = account1;
|
|
FlashWallet public wallet;
|
|
TestCallTarget public callTarget;
|
|
|
|
bytes public constant MAGIC_BYTES = hex"1234567800000000000000000000000000000000000000000000000000000000";
|
|
bytes public constant REVERTING_DATA = hex"1337";
|
|
|
|
event CallTargetCalled(address sender, bytes data, uint256 value);
|
|
|
|
function setUp() public {
|
|
vm.startPrank(owner);
|
|
|
|
wallet = new FlashWallet();
|
|
callTarget = new TestCallTarget();
|
|
|
|
vm.stopPrank();
|
|
}
|
|
|
|
function test_OwnedByDeployer() public {
|
|
assertEq(wallet.owner(), account1);
|
|
}
|
|
|
|
function test_executeCall_nonOwnerCannotExecute() public {
|
|
vm.expectRevert(LibOwnableRichErrorsV06.OnlyOwnerError(account2, owner));
|
|
vm.startPrank(account2);
|
|
wallet.executeCall(address(callTarget), "0x1", 123);
|
|
}
|
|
|
|
function test_executeCall_ownerCanCallWithZeroValue() public {
|
|
vm.expectEmit(true, true, true, true);
|
|
emit CallTargetCalled(address(wallet), "0x1", 0);
|
|
vm.startPrank(owner);
|
|
wallet.executeCall(address(callTarget), "0x1", 0);
|
|
}
|
|
|
|
function test_executeCall_ownerCanCallWithNonZeroValue() public {
|
|
vm.expectEmit(true, true, true, true);
|
|
emit CallTargetCalled(address(wallet), "0x1", 1);
|
|
vm.startPrank(owner);
|
|
wallet.executeCall{value: 1}(address(callTarget), "0x1", 1);
|
|
}
|
|
|
|
function test_executeCall_ownerCanTransferLessETHThanAttached() public {
|
|
vm.expectEmit(true, true, true, true);
|
|
emit CallTargetCalled(address(wallet), "0x1", 1);
|
|
vm.startPrank(owner);
|
|
// Send value 2 but execute call with 1
|
|
wallet.executeCall{value: 2}(address(callTarget), "0x1", 1);
|
|
}
|
|
|
|
function test_executeCall_walletReturnsCallResult() public {
|
|
vm.startPrank(owner);
|
|
bytes memory result = wallet.executeCall(address(callTarget), "0x1", 0);
|
|
assertEq0(result, MAGIC_BYTES);
|
|
}
|
|
|
|
function test_executeCall_walletWrapsCallRevert() public {
|
|
(, bytes memory resultData) = address(callTarget).call(REVERTING_DATA);
|
|
bytes memory error = LibWalletRichErrors.WalletExecuteCallFailedError(
|
|
address(wallet),
|
|
address(callTarget),
|
|
REVERTING_DATA,
|
|
0,
|
|
resultData
|
|
);
|
|
|
|
vm.expectRevert(error);
|
|
|
|
vm.startPrank(owner);
|
|
wallet.executeCall(address(callTarget), REVERTING_DATA, 0);
|
|
}
|
|
|
|
function test_executeCall_walletCanReceiveETH() public {
|
|
vm.startPrank(owner);
|
|
(bool sent, ) = address(wallet).call{value: 1}("");
|
|
assertTrue(sent, "Failed to send ETH to wallet");
|
|
assertEq(address(wallet).balance, 1);
|
|
}
|
|
|
|
function test_executeDelegateCall_nonOwnerCannotExecute() public {
|
|
vm.expectRevert(LibOwnableRichErrorsV06.OnlyOwnerError(account2, owner));
|
|
vm.startPrank(account2);
|
|
wallet.executeDelegateCall(address(callTarget), "0x1");
|
|
}
|
|
|
|
function test_executeDelegateCall_ownerCanExecute() public {
|
|
vm.expectEmit(true, true, true, true);
|
|
emit CallTargetCalled(owner, "0x1", 0);
|
|
vm.startPrank(owner);
|
|
wallet.executeDelegateCall(address(callTarget), "0x1");
|
|
}
|
|
|
|
function test_executeDelegateCall_ownerCanExecuteWithValue() public {
|
|
vm.expectEmit(true, true, true, true);
|
|
emit CallTargetCalled(owner, "0x1", 1);
|
|
vm.startPrank(owner);
|
|
wallet.executeDelegateCall{value: 1}(address(callTarget), "0x1");
|
|
}
|
|
|
|
function test_executeDelegateCall_walletReturnsCallResult() public {
|
|
vm.startPrank(owner);
|
|
bytes memory result = wallet.executeDelegateCall(address(callTarget), "0x1");
|
|
assertEq0(result, MAGIC_BYTES);
|
|
}
|
|
|
|
function test_executeDelegateCall_walletWrapsCallRevert() public {
|
|
(, bytes memory resultData) = address(callTarget).call(REVERTING_DATA);
|
|
bytes memory error = LibWalletRichErrors.WalletExecuteDelegateCallFailedError(
|
|
address(wallet),
|
|
address(callTarget),
|
|
REVERTING_DATA,
|
|
resultData
|
|
);
|
|
|
|
vm.expectRevert(error);
|
|
|
|
vm.startPrank(owner);
|
|
wallet.executeDelegateCall(address(callTarget), REVERTING_DATA);
|
|
}
|
|
}
|