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

Feat/test improvements #46

Merged
merged 4 commits into from
Oct 21, 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
3 changes: 2 additions & 1 deletion .solhint.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"not-rely-on-time": "off",
"one-contract-per-file": "off",
"var-name-mixedcase": "off",
"immutable-vars-naming": "off"
"immutable-vars-naming": "off",
"no-console": "warn"
Copy link
Contributor

@wshino wshino Oct 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, I sometimes forget to remove the console.log

}
}
4 changes: 1 addition & 3 deletions .solhintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
node_modules/
test/
script/
node_modules/
46 changes: 31 additions & 15 deletions README.md

Large diffs are not rendered by default.

14 changes: 3 additions & 11 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,12 @@ emv_version = "paris"
src = "src"
out = "out"
script = "script"
libs = [
"node_modules",
"lib",
]
libs = ["node_modules", "lib"]
fs_permissions = [
{ access = "read", path = "out-optimized" },
{ access = "read-write", path = "gas_calculations" },
]
allow_paths = [
"*",
"/",
]
allow_paths = ["*", "/"]
ignored_warnings_from = [
"node_modules",
"node_modules/@rhinestone/modulekit/src/**/*.sol",
Expand All @@ -36,6 +30,4 @@ number_underscore = "thousands"
quote_style = "double"
tab_width = 4
wrap_comments = true
ignore = [
"./src/libraries/L2ContractHelper.sol",
]
ignore = ["./src/libraries/L2ContractHelper.sol"]
14 changes: 5 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,12 @@
"scripts": {
"build": "forge build",
"build:optimized": "FOUNDRY_PROFILE=optimized forge build",
"build:smt": "FOUNDRY_PROFILE=smt forge build",
"clean": "rm -rf artifacts broadcast cache docs out out-optimized out-svg",
"gas:report": "forge test --gas-report --mp \"./test/integration/**/*.sol\" --nmt \"test(Fuzz)?_RevertWhen_\\w{1,}?\"",
"gas:snapshot": "forge snapshot --mp \"./test/integration/**/*.sol\" --nmt \"test(Fuzz)?_RevertWhen_\\w{1,}?\"",
"gas:snapshot:optimized": "pnpm run build:optimized && FOUNDRY_PROFILE=test-optimized forge snapshot --mp \"./test/integration/**/*.sol\" --nmt \"test(Fork)?(Fuzz)?_RevertWhen_\\w{1,}?\"",
"lint": "pnpm run lint:sol && bun run prettier:check",
"lint:sol": "forge fmt --check && pnpm solhint \"{script,src,test}/**/*.sol\"",
"gas:report": "forge test --gas-report --mp \"./test/integration/**/*.sol\"",
"gas:snapshot": "forge snapshot --mp \"./test/integration/**/*.sol\"",
"gas:snapshot:optimized": "pnpm run build:optimized && FOUNDRY_PROFILE=test-optimized forge snapshot --mp \"./test/integration/**/*.sol\"",
"lint": "forge fmt --check && pnpm solhint \"{script,src,test}/**/*.sol\"",
"prepack": "pnpm install",
"prettier:check": "prettier --check \"**/*.{json,md,svg,yml}\"",
"prettier:write": "prettier --write \"**/*.{json,md,svg,yml}\"",
"test": "forge test",
"test:lite": "FOUNDRY_PROFILE=lite forge test",
"test:optimized": "pnpm run build:optimized && FOUNDRY_PROFILE=test-optimized forge test"
Expand Down Expand Up @@ -58,4 +54,4 @@
"publishConfig": {
"access": "public"
}
}
}
4 changes: 3 additions & 1 deletion script/Compute7579RecoveryDataHash.s.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;

/* solhint-disable no-console */

import { Script } from "forge-std/Script.sol";
import { console } from "forge-std/console.sol";

contract Compute7579RecoveryDataHash is Script {
function run() public {
function run() public view {
bytes4 functionSelector = bytes4(keccak256(bytes("changeOwner(address)")));
address newOwner = vm.envAddress("NEW_OWNER");
address validator = vm.envAddress("VALIDATOR");
Expand Down
4 changes: 3 additions & 1 deletion script/ComputeSafeRecoveryCalldata.s.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;

/* solhint-disable no-console */

import { Script } from "forge-std/Script.sol";
import { console } from "forge-std/console.sol";

contract ComputeSafeRecoveryCalldataScript is Script {
function run() public {
function run() public view {
address oldOwner = vm.envAddress("OLD_OWNER");
address newOwner = vm.envAddress("NEW_OWNER");
address previousOwnerInLinkedList = address(1);
Expand Down
50 changes: 29 additions & 21 deletions script/Deploy7579TestAccount.s.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;

/* solhint-disable no-console, gas-custom-errors, max-states-count */

import { Script } from "forge-std/Script.sol";
import { console } from "forge-std/console.sol";
import { EmailAccountRecovery } from
Expand All @@ -27,27 +29,27 @@ contract Deploy7579TestAccountScript is RhinestoneModuleKit, Script {
using Strings for uint256;
using Strings for address;

uint256 privKey;
address deployer;
MSABasic msaBasicImpl;
MSAFactory msaFactory;
Bootstrap bootstrap;
MockHook hook;
MockTarget mockTarget;
uint256 public privKey;
address public deployer;
MSABasic public msaBasicImpl;
MSAFactory public msaFactory;
Bootstrap public bootstrap;
MockHook public hook;
MockTarget public mockTarget;

bytes32 accountSalt;
address validatorAddr;
address recoveryModuleAddr;
address[] guardians = new address[](0);
uint256[] guardianWeights = new uint256[](0);
bytes32 public accountSalt;
address public validatorAddr;
address public recoveryModuleAddr;
address[] public guardians = new address[](0);
uint256[] public guardianWeights = new uint256[](0);

address account;
bytes initCode;
bytes userOpCalldata;
PackedUserOperation userOp;
bytes32 userOpHash;
address public account;
bytes public initCode;
bytes public userOpCalldata;
PackedUserOperation public userOp;
bytes32 public userOpHash;

bytes4 functionSelector = bytes4(keccak256(bytes("changeOwner(address)")));
bytes4 public functionSelector = bytes4(keccak256(bytes("changeOwner(address)")));

function run() public {
privKey = vm.envUint("PRIVATE_KEY");
Expand Down Expand Up @@ -97,7 +99,6 @@ contract Deploy7579TestAccountScript is RhinestoneModuleKit, Script {
validatorAddr = address(new OwnableValidator());
console.log("Deployed Ownable Validator at", validatorAddr);
}
OwnableValidator validator = OwnableValidator(validatorAddr);

// Create initcode to be sent to Factory
BootstrapConfig[] memory validators = new BootstrapConfig[](1);
Expand Down Expand Up @@ -223,8 +224,15 @@ contract Deploy7579TestAccountScript is RhinestoneModuleKit, Script {
vm.stopBroadcast();
}

function getNonce(address account, address validator) internal returns (uint256 nonce) {
function getNonce(
address smartAccount,
address validator
)
internal
view
returns (uint256 nonce)
{
uint192 key = uint192(bytes24(bytes20(address(validator))));
nonce = IEntryPoint(ENTRYPOINT_ADDR).getNonce(address(account), key);
nonce = IEntryPoint(ENTRYPOINT_ADDR).getNonce(address(smartAccount), key);
}
}
4 changes: 2 additions & 2 deletions script/DeployEmailRecoveryModule.s.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;

/* solhint-disable no-console, gas-custom-errors */

import { Script } from "forge-std/Script.sol";
import { console } from "forge-std/console.sol";
import { EmailRecoveryCommandHandler } from "src/handlers/EmailRecoveryCommandHandler.sol";
Expand Down Expand Up @@ -61,8 +63,6 @@ contract DeployEmailRecoveryModuleScript is Script {
console.log("Deployed Ownable Validator at", validatorAddr);
}

EmailRecoveryCommandHandler emailRecoveryHandler = new EmailRecoveryCommandHandler();

address _factory = vm.envOr("RECOVERY_FACTORY", address(0));
if (_factory == address(0)) {
_factory = address(new EmailRecoveryFactory(verifier, emailAuthImpl));
Expand Down
2 changes: 2 additions & 0 deletions script/DeploySafeNativeRecovery.s.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;

/* solhint-disable no-console, gas-custom-errors */

import { Script } from "forge-std/Script.sol";
import { console } from "forge-std/console.sol";
import { Verifier } from "@zk-email/ether-email-auth-contracts/src/utils/Verifier.sol";
Expand Down
3 changes: 2 additions & 1 deletion script/DeploySafeRecovery.s.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;

/* solhint-disable no-console, gas-custom-errors */

import { Script } from "forge-std/Script.sol";
import { console } from "forge-std/console.sol";
import { SafeRecoveryCommandHandler } from "src/handlers/SafeRecoveryCommandHandler.sol";
import { EmailRecoveryFactory } from "src/factories/EmailRecoveryFactory.sol";
import { EmailRecoveryUniversalFactory } from "src/factories/EmailRecoveryUniversalFactory.sol";
import { Verifier } from "@zk-email/ether-email-auth-contracts/src/utils/Verifier.sol";
import { Groth16Verifier } from "@zk-email/ether-email-auth-contracts/src/utils/Groth16Verifier.sol";
Expand Down
4 changes: 2 additions & 2 deletions script/DeployUniversalEmailRecoveryModule.s.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;

/* solhint-disable no-console, gas-custom-errors */

import { Script } from "forge-std/Script.sol";
import { console } from "forge-std/console.sol";
import { EmailRecoveryCommandHandler } from "src/handlers/EmailRecoveryCommandHandler.sol";
Expand Down Expand Up @@ -54,8 +56,6 @@ contract DeployUniversalEmailRecoveryModuleScript is Script {
console.log("Deployed Email Auth at", emailAuthImpl);
}

EmailRecoveryCommandHandler emailRecoveryHandler = new EmailRecoveryCommandHandler();

address _factory = vm.envOr("RECOVERY_FACTORY", address(0));
if (_factory == address(0)) {
_factory = address(new EmailRecoveryUniversalFactory(verifier, emailAuthImpl));
Expand Down
6 changes: 1 addition & 5 deletions src/interfaces/IGuardianManager.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;

import {
EnumerableGuardianMap,
GuardianStorage,
GuardianStatus
} from "../libraries/EnumerableGuardianMap.sol";
import { GuardianStorage, GuardianStatus } from "../libraries/EnumerableGuardianMap.sol";

interface IGuardianManager {
/**
Expand Down
2 changes: 2 additions & 0 deletions src/libraries/StringUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ pragma solidity ^0.8.13;

import { strings } from "solidity-stringutils/src/strings.sol";

/* solhint-disable gas-custom-errors */

// Extracted from https://github.com/zkemail/email-wallet-sdk/blob/main/src/helpers/StringUtils.sol
library StringUtils {
using strings for *;
Expand Down
Loading