Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get CoinbaseSmartContractFactory and ERC1271 to 100% coverage #37

Merged
merged 5 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion test/CoinbaseSmartWalletFactory.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
pragma solidity ^0.8.0;

import {Test, console2} from "forge-std/Test.sol";
import {CoinbaseSmartWallet} from "../src/CoinbaseSmartWallet.sol";
import {CoinbaseSmartWallet, MultiOwnable} from "../src/CoinbaseSmartWallet.sol";
import {CoinbaseSmartWalletFactory} from "../src/CoinbaseSmartWalletFactory.sol";
import {LibClone} from "solady/utils/LibClone.sol";

contract CoinbaseSmartWalletFactoryTest is Test {
CoinbaseSmartWalletFactory factory;
Expand Down Expand Up @@ -32,6 +33,20 @@ contract CoinbaseSmartWalletFactoryTest is Test {
factory.createAccount{value: 1e18}(owners, 0);
}

function test_exitIfAccountIsAlreadyInitialized() public {
stevieraykatz marked this conversation as resolved.
Show resolved Hide resolved
CoinbaseSmartWallet a = factory.createAccount(owners, 0);
vm.expectCall(address(a), abi.encodeCall(CoinbaseSmartWallet.initialize, (owners)), 0);
CoinbaseSmartWallet a2 = factory.createAccount(owners, 0);
assertEq(address(a), address(a2));
}

function test_RevertsIfLength32ButLargerThanAddress() public {
bytes memory badOwner = abi.encode(uint256(type(uint160).max) + 1);
owners.push(badOwner);
vm.expectRevert(abi.encodeWithSelector(MultiOwnable.InvalidEthereumAddressOwner.selector, badOwner));
factory.createAccount{value: 1e18}(owners, 0);
}

function test_createAccountDeploysToPredeterminedAddress() public {
address p = factory.getAddress(owners, 0);
CoinbaseSmartWallet a = factory.createAccount{value: 1e18}(owners, 0);
Expand All @@ -55,4 +70,10 @@ contract CoinbaseSmartWalletFactoryTest is Test {
function test_implementation_returnsExpectedAddress() public {
assertEq(factory.implementation(), address(account));
}

function test_initCodeHash() public {
bytes32 execptedHash = LibClone.initCodeHashERC1967(address(account));
bytes32 factoryHash = factory.initCodeHash();
assertEq(factoryHash, execptedHash);
}
}
13 changes: 11 additions & 2 deletions test/ERC1271.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,18 @@ contract ERC1271Test is Test {
}

function test_returnsExpectedDomainHashWhenProxy() public {
(, string memory name, string memory version, uint256 chainId, address verifyingContract,,) =
account.eip712Domain();
(
,
string memory name,
string memory version,
uint256 chainId,
address verifyingContract,
bytes32 salt,
uint256[] memory extensions
) = account.eip712Domain();
assertEq(verifyingContract, address(account));
assertEq(abi.encode(extensions), abi.encode(new uint256[](0)));
assertEq(salt, bytes32(0));
bytes32 expected = keccak256(
abi.encode(
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"),
Expand Down