Skip to content

Commit

Permalink
feat: Add SimplePlusAccountFactory test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
jpgonzalezra committed May 21, 2024
1 parent 05c05d1 commit 21a95bd
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions test/SimplePlusAccountFactory.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.23;

import { Test } from "forge-std/src/Test.sol";

import { EntryPoint } from "@account-abstraction/contracts/core/EntryPoint.sol";

import { SimplePlusAccount } from "../src/SimplePlusAccount.sol";
import { SimplePlusAccountFactory } from "../src/SimplePlusAccountFactory.sol";

contract SimplePlusAccountFactoryTest is Test {
address public constant OWNER_ADDRESS = address(0x100);
SimplePlusAccountFactory public factory;
EntryPoint public entryPoint;

function setUp() public {
entryPoint = new EntryPoint();
factory = new SimplePlusAccountFactory(entryPoint);
}

function testReturnsAddressWhenAccountAlreadyExists() public {
SimplePlusAccount account = factory.createAccount(OWNER_ADDRESS, 1);
SimplePlusAccount otherAccount = factory.createAccount(OWNER_ADDRESS, 1);
assertEq(address(account), address(otherAccount));
}

function testGetAddress() public {
address counterfactual = factory.getAddress(OWNER_ADDRESS, 1);
assertEq(counterfactual.codehash, bytes32(0));
SimplePlusAccount factual = factory.createAccount(OWNER_ADDRESS, 1);
assertTrue(address(factual).codehash != bytes32(0));
assertEq(counterfactual, address(factual));
}

/// @dev Receive funds from withdraw.
receive() external payable { }
}

0 comments on commit 21a95bd

Please sign in to comment.