From 73bab22f207b355e112753a3a3d72ab954f8fea2 Mon Sep 17 00:00:00 2001 From: Eloi Manuel Date: Wed, 22 Nov 2023 10:08:53 +0100 Subject: [PATCH] Adding fuzz tests --- .../managed/ManagedOpenfortAccountTest.t.sol | 25 +++++++++++++++++++ .../UpgradeableOpenfortAccountTest.t.sol | 25 +++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/test/foundry/core/managed/ManagedOpenfortAccountTest.t.sol b/test/foundry/core/managed/ManagedOpenfortAccountTest.t.sol index bef9807..0fcf0f1 100644 --- a/test/foundry/core/managed/ManagedOpenfortAccountTest.t.sol +++ b/test/foundry/core/managed/ManagedOpenfortAccountTest.t.sol @@ -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 diff --git a/test/foundry/core/upgradeable/UpgradeableOpenfortAccountTest.t.sol b/test/foundry/core/upgradeable/UpgradeableOpenfortAccountTest.t.sol index 131aa81..3eb21ba 100644 --- a/test/foundry/core/upgradeable/UpgradeableOpenfortAccountTest.t.sol +++ b/test/foundry/core/upgradeable/UpgradeableOpenfortAccountTest.t.sol @@ -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