Skip to content

Commit

Permalink
added test base flow ERC20ToERC721
Browse files Browse the repository at this point in the history
  • Loading branch information
Erikd-dev committed Aug 10, 2024
1 parent e499b82 commit 43722b8
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions test/concrete/flowBasic/FlowTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import {FlowBasicTest} from "test/abstract/FlowBasicTest.sol";
import {IFlowV5, ERC20Transfer, ERC721Transfer, ERC1155Transfer} from "src/interface/unstable/IFlowV5.sol";
import {EvaluableV2} from "rain.interpreter.interface/lib/caller/LibEvaluable.sol";
import {IERC1155} from "openzeppelin-contracts/contracts/token/ERC1155/IERC1155.sol";
import {IERC20} from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";
import {REVERTING_MOCK_BYTECODE} from "test/abstract/TestConstants.sol";
import {EvaluableConfigV3, SignedContextV1} from "rain.interpreter.interface/interface/IInterpreterCallerV2.sol";

contract FlowTest is FlowBasicTest {
address internal immutable iERC721;
address internal immutable iERC1155;
address internal immutable iIERC20;

constructor() {
vm.pauseGasMetering();
Expand All @@ -20,6 +22,10 @@ contract FlowTest is FlowBasicTest {
iERC1155 = address(uint160(uint256(keccak256("store.rain.test"))));
vm.etch(address(iERC1155), REVERTING_MOCK_BYTECODE);
vm.resumeGasMetering();

iIERC20 = address(uint160(uint256(keccak256("erc20.test"))));
vm.etch(address(iIERC20), REVERTING_MOCK_BYTECODE);
vm.resumeGasMetering();
}

function testFlowERC721ToERC1155(
Expand Down Expand Up @@ -79,4 +85,44 @@ contract FlowTest is FlowBasicTest {
flow.flow(evaluable, new uint256[](0), new SignedContextV1[](0));
vm.stopPrank();
}

function testFlowERC20ToERC721(address bob, uint256 erc20InAmount, uint256 erc721OutTokenId) external {
vm.assume(bob != address(0));
vm.assume(sentinel != uint256(uint160(bob)));
vm.assume(sentinel != erc20InAmount);
vm.assume(sentinel != erc721OutTokenId);
vm.label(bob, "Bob");

(IFlowV5 flow, EvaluableV2 memory evaluable) = deployFlow();

ERC20Transfer[] memory erc20Transfers = new ERC20Transfer[](1);
erc20Transfers[0] =
ERC20Transfer({token: address(iIERC20), from: bob, to: address(flow), amount: erc20InAmount});

ERC721Transfer[] memory erc721Transfers = new ERC721Transfer[](1);
erc721Transfers[0] = ERC721Transfer({token: iERC721, from: address(flow), to: bob, id: erc721OutTokenId});

vm.mockCall(iIERC20, abi.encodeWithSelector(IERC20.transferFrom.selector), abi.encode(true));
vm.expectCall(iIERC20, abi.encodeWithSelector(IERC20.transferFrom.selector, bob, flow, erc20InAmount));

vm.mockCall(
iERC721,
abi.encodeWithSelector(bytes4(keccak256("safeTransferFrom(address,address,uint256)"))),
abi.encode()
);
vm.expectCall(
iERC721,
abi.encodeWithSelector(
bytes4(keccak256("safeTransferFrom(address,address,uint256)")), flow, bob, erc721OutTokenId
)
);

uint256[] memory stack = generateTokenTransferStack(new ERC1155Transfer[](0), erc721Transfers, erc20Transfers);

interpreterEval2MockCall(stack, new uint256[](0));

vm.startPrank(bob);
flow.flow(evaluable, new uint256[](0), new SignedContextV1[](0));
vm.stopPrank();
}
}

0 comments on commit 43722b8

Please sign in to comment.