Files
tokenbound/test/AccountETH.t.sol
Jayden Windle 03a730c2c0 Macro Audit Fixes (#19)
* [H-3]: Added max lock time (#8)

* Added max lock time of 1 year

* Fixed tests + covered max unlock exceeded scenario

* Removed payable castings (#9)

* [L-2]: Added event coverage (#10)

* [Q-1]: Added onlyUnlocked modifier (#11)

* [Q-2] Removed unused imports (#12)

* [Q-3]: Added ERC165 support (#14)

* [G-3] Made vaultImplementation immutable (#15)

* Added chainid to vault salt + context (#16)

* Added chainid to vault salt + context to mitigate cross-chain attacks

* Added support for deploying cross-chain vaults to VaultRegistry

* Updated natspec docs

* Added cross-chain executor (#17)

* Added support for cross-chain executors and increased test coverage

* added natspec coverage

* Apply EIP naming conventions (#18)

* migrated vault to account in accordance with eip naming

* renamed VaultRegistry to AccountRegistry, updated naming in tests

* split registry and cross chain executor list, renamed methods

* finished migrating to eip naming conventions, split out tests, removed proxy size test

* removed chainid from interface

* remove console

* removed unused imports

* fix spelling

* fixed registry interface to match eip

* fix event

* fixed event test

* added event indexing
2023-04-11 14:23:26 -04:00

100 lines
2.9 KiB
Solidity

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
import "forge-std/Test.sol";
import "openzeppelin-contracts/token/ERC20/ERC20.sol";
import "openzeppelin-contracts/proxy/Clones.sol";
import "../src/CrossChainExecutorList.sol";
import "../src/Account.sol";
import "../src/AccountRegistry.sol";
import "./mocks/MockERC721.sol";
contract AccountTest is Test {
CrossChainExecutorList ccExecutorList;
Account implementation;
AccountRegistry public accountRegistry;
MockERC721 public tokenCollection;
function setUp() public {
ccExecutorList = new CrossChainExecutorList();
implementation = new Account(address(ccExecutorList));
accountRegistry = new AccountRegistry(address(implementation));
tokenCollection = new MockERC721();
}
function testTransferETHPreDeploy() public {
uint256 tokenId = 1;
address user1 = vm.addr(1);
vm.deal(user1, 0.2 ether);
// get address that account will be deployed to (before token is minted)
address accountAddress = accountRegistry.account(
address(tokenCollection),
tokenId
);
// mint token for account to user1
tokenCollection.mint(user1, tokenId);
assertEq(tokenCollection.ownerOf(tokenId), user1);
// send ETH from user1 to account (prior to account deployment)
vm.prank(user1);
(bool sent, ) = accountAddress.call{value: 0.2 ether}("");
assertTrue(sent);
assertEq(accountAddress.balance, 0.2 ether);
// deploy account contract (from a different wallet)
address createdAccountInstance = accountRegistry.createAccount(
address(tokenCollection),
tokenId
);
assertEq(accountAddress, createdAccountInstance);
Account account = Account(payable(accountAddress));
// user1 executes transaction to send ETH from account
vm.prank(user1);
account.executeCall(payable(user1), 0.1 ether, "");
// success!
assertEq(accountAddress.balance, 0.1 ether);
assertEq(user1.balance, 0.1 ether);
}
function testTransferETHPostDeploy(uint256 tokenId) public {
address user1 = vm.addr(1);
vm.deal(user1, 0.2 ether);
address accountAddress = accountRegistry.createAccount(
address(tokenCollection),
tokenId
);
tokenCollection.mint(user1, tokenId);
assertEq(tokenCollection.ownerOf(tokenId), user1);
vm.prank(user1);
(bool sent, ) = accountAddress.call{value: 0.2 ether}("");
assertTrue(sent);
assertEq(accountAddress.balance, 0.2 ether);
Account account = Account(payable(accountAddress));
vm.prank(user1);
account.executeCall(payable(user1), 0.1 ether, "");
assertEq(accountAddress.balance, 0.1 ether);
assertEq(user1.balance, 0.1 ether);
}
}