|
| 1 | +// SPDX-License-Identifier: UNLICENSED |
| 2 | +pragma solidity >=0.8.4; |
| 3 | + |
| 4 | +import {Test} from "forge-std/Test.sol"; |
| 5 | + |
| 6 | +import {IERC721} from "@openzeppelin/contracts/token/ERC721/IERC721.sol"; |
| 7 | + |
| 8 | +import {DefiBridgeProxy} from "./../../aztec/DefiBridgeProxy.sol"; |
| 9 | +import {RollupProcessor} from "./../../aztec/RollupProcessor.sol"; |
| 10 | +import {AztecTypes} from "./../../aztec/AztecTypes.sol"; |
| 11 | + |
| 12 | +import {AceOfZkBridge} from "./../../bridges/aceofzk/AceOfZkBridge.sol"; |
| 13 | + |
| 14 | +contract AceOfZkTest is Test { |
| 15 | + error InvalidCaller(); |
| 16 | + error AsyncDisabled(); |
| 17 | + |
| 18 | + IERC721 public constant ACE_OF_ZK_NFT = IERC721(0xE56B526E532804054411A470C49715c531CFd485); |
| 19 | + address public constant NFT_HOLDER = 0xE298a76986336686CC3566469e3520d23D1a8aaD; |
| 20 | + uint256 public constant NFT_ID = 16; |
| 21 | + |
| 22 | + AceOfZkBridge internal bridge; |
| 23 | + DefiBridgeProxy internal defiBridgeProxy; |
| 24 | + RollupProcessor internal rollupProcessor; |
| 25 | + |
| 26 | + AztecTypes.AztecAsset private empty; |
| 27 | + AztecTypes.AztecAsset private ethAsset = |
| 28 | + AztecTypes.AztecAsset({id: 1, erc20Address: address(0), assetType: AztecTypes.AztecAssetType.ETH}); |
| 29 | + |
| 30 | + function setUp() public { |
| 31 | + defiBridgeProxy = new DefiBridgeProxy(); |
| 32 | + rollupProcessor = new RollupProcessor(address(defiBridgeProxy)); |
| 33 | + |
| 34 | + bridge = new AceOfZkBridge(address(rollupProcessor)); |
| 35 | + |
| 36 | + vm.prank(NFT_HOLDER); |
| 37 | + ACE_OF_ZK_NFT.approve(address(bridge), NFT_ID); |
| 38 | + } |
| 39 | + |
| 40 | + function testHappyPath() public { |
| 41 | + // Fund rollup processor |
| 42 | + vm.deal(address(rollupProcessor), 1); |
| 43 | + |
| 44 | + assertTrue(ACE_OF_ZK_NFT.ownerOf(NFT_ID) != address(rollupProcessor), "The rollup processor owns the nft"); |
| 45 | + |
| 46 | + (uint256 outputValueA, uint256 outputValueB, bool isAsync) = rollupProcessor.convert( |
| 47 | + address(bridge), |
| 48 | + ethAsset, |
| 49 | + empty, |
| 50 | + ethAsset, |
| 51 | + empty, |
| 52 | + 1, |
| 53 | + 0, |
| 54 | + 0 |
| 55 | + ); |
| 56 | + |
| 57 | + assertEq(outputValueA, 0, "Non zero return a"); |
| 58 | + assertEq(outputValueB, 0, "Non zero return b"); |
| 59 | + assertFalse(isAsync, "The convert was async"); |
| 60 | + assertEq(ACE_OF_ZK_NFT.ownerOf(NFT_ID), address(rollupProcessor), "The rollup processor does not own the nft"); |
| 61 | + } |
| 62 | + |
| 63 | + function testWrongCaller(address _caller) public { |
| 64 | + vm.assume(_caller != address(rollupProcessor)); |
| 65 | + |
| 66 | + vm.prank(_caller); |
| 67 | + |
| 68 | + vm.expectRevert(InvalidCaller.selector); |
| 69 | + bridge.convert(ethAsset, empty, ethAsset, empty, 0, 0, 0, _caller); |
| 70 | + } |
| 71 | + |
| 72 | + function testAsyncDisabled() public { |
| 73 | + vm.expectRevert(AsyncDisabled.selector); |
| 74 | + bridge.finalise(ethAsset, empty, ethAsset, empty, 0, 0); |
| 75 | + } |
| 76 | +} |
0 commit comments