Skip to content

Commit

Permalink
Adding fuzz tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eloi010 committed Nov 22, 2023
1 parent b5f3c5e commit 73bab22
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
25 changes: 25 additions & 0 deletions test/foundry/core/managed/ManagedOpenfortAccountTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,31 @@ contract ManagedOpenfortAccountTest is OpenfortBaseTest {
assertEq(account2, managedOpenfortFactory.getAddressWithNonce(accountAdmin, "2"));
}

/*
* Create an account by directly calling the factory by fuzzing the admin and nonce parameters.
*/
function testFuzzCreateAccountWithNonceViaFactory(address _adminAddress, bytes32 _nonce) public {
// Get the counterfactual address
vm.prank(factoryAdmin);
address account2 = managedOpenfortFactory.getAddressWithNonce(_adminAddress, _nonce);

// Expect that we will see an event containing the account and admin
vm.expectEmit(true, true, false, true);
emit AccountCreated(account2, _adminAddress);

// Deploy a managed account to the counterfactual address
vm.prank(factoryAdmin);
managedOpenfortFactory.createAccountWithNonce(_adminAddress, _nonce);

// Calling it again should just return the address and not create another account
vm.prank(factoryAdmin);
managedOpenfortFactory.createAccountWithNonce(_adminAddress, _nonce);

// Make sure the counterfactual address has not been altered
vm.prank(factoryAdmin);
assertEq(account2, managedOpenfortFactory.getAddressWithNonce(_adminAddress, _nonce));
}

/*
* Create an account calling the factory via EntryPoint.
* Use initCode
Expand Down
25 changes: 25 additions & 0 deletions test/foundry/core/upgradeable/UpgradeableOpenfortAccountTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,31 @@ contract UpgradeableOpenfortAccountTest is OpenfortBaseTest {
assertEq(accountAddress2, upgradeableOpenfortFactory.getAddressWithNonce(accountAdmin, "2"));
}

/*
* Create an account by directly calling the factory by fuzzing the admin and nonce parameters.
*/
function testFuzzCreateAccountWithNonceViaFactory(address _adminAddress, bytes32 _nonce) public {
// Get the counterfactual address
vm.prank(factoryAdmin);
address accountAddress2 = upgradeableOpenfortFactory.getAddressWithNonce(_adminAddress, _nonce);

// Expect that we will see an event containing the account and admin
vm.expectEmit(true, true, false, true);
emit AccountCreated(accountAddress2, _adminAddress);

// Deploy a upgradeable account to the counterfactual address
vm.prank(factoryAdmin);
upgradeableOpenfortFactory.createAccountWithNonce(_adminAddress, _nonce);

// Calling it again should just return the address and not create another account
vm.prank(factoryAdmin);
upgradeableOpenfortFactory.createAccountWithNonce(_adminAddress, _nonce);

// Make sure the counterfactual address has not been altered
vm.prank(factoryAdmin);
assertEq(accountAddress2, upgradeableOpenfortFactory.getAddressWithNonce(_adminAddress, _nonce));
}

/*
* Create an account calling the factory via EntryPoint.
* Use initCode
Expand Down

0 comments on commit 73bab22

Please sign in to comment.