From 1030c3ff3a202ba11dd21d8736a02cfec81d1603 Mon Sep 17 00:00:00 2001 From: Hans Wang Date: Thu, 19 Oct 2023 15:20:27 -0700 Subject: [PATCH 1/4] forge fmt --- src/CodeJar.sol | 11 +--- src/QuarkScript.sol | 5 +- src/QuarkWallet.sol | 66 ++++++++++++------- src/QuarkWalletFactory.sol | 37 ++++++----- src/Relayer.sol | 52 +++++++++++---- src/RelayerAtomic.sol | 30 +++++---- test/Callbacks.t.sol | 107 +++++++++++++------------------ test/CodeJar.t.sol | 9 ++- test/EIP712.t.sol | 25 +++++--- test/Nonce.t.sol | 6 +- test/QuarkWallet.t.sol | 56 ++++------------ test/QuarkWalletFactory.t.sol | 78 ++++++++-------------- test/lib/CallbackFromCounter.sol | 6 +- test/lib/Counter.sol | 1 - test/lib/CounterScript.sol | 11 ++-- test/lib/GetOwner.sol | 6 +- test/lib/Incrementer.sol | 20 +++--- test/lib/Logger.sol | 8 +-- test/lib/MaxCounterScript.sol | 23 ++++--- test/lib/Reverts.sol | 8 +-- test/lib/YulHelper.sol | 5 +- 21 files changed, 274 insertions(+), 296 deletions(-) diff --git a/src/CodeJar.sol b/src/CodeJar.sol index 94edc6b0..07a79d41 100644 --- a/src/CodeJar.sol +++ b/src/CodeJar.sol @@ -76,15 +76,8 @@ contract CodeJar { * @return The create2 address based on running the initCode constructor */ function getCodeAddress(bytes memory initCode) internal view returns (address) { - return address(uint160(uint( - keccak256( - abi.encodePacked( - bytes1(0xff), - address(this), - uint256(0), - keccak256(initCode) - ) - ))) + return address( + uint160(uint256(keccak256(abi.encodePacked(bytes1(0xff), address(this), uint256(0), keccak256(initCode))))) ); } diff --git a/src/QuarkScript.sol b/src/QuarkScript.sol index 83947562..c2052f40 100644 --- a/src/QuarkScript.sol +++ b/src/QuarkScript.sol @@ -7,7 +7,7 @@ contract QuarkScript { function owner() internal view returns (address payable) { address payable owner_; assembly { - owner_ := sload(0x3bb5ebf00f3b539fbe3d28370e5631dd2bb9520dffcea6daf564f94582db8111) // keccak("org.quark.owner") + owner_ := sload(0x3bb5ebf00f3b539fbe3d28370e5631dd2bb9520dffcea6daf564f94582db8111) // keccak("org.quark.owner") } return owner_; } @@ -15,7 +15,7 @@ contract QuarkScript { function relayer() internal view returns (Relayer) { Relayer relayer_; assembly { - relayer_ := sload(0x46ce4d9fc828e2af4f167362c7c43e310c76adc313cd8fe11e785726f972b4f6) // keccak("org.quark.relayer") + relayer_ := sload(0x46ce4d9fc828e2af4f167362c7c43e310c76adc313cd8fe11e785726f972b4f6) // keccak("org.quark.relayer") } return relayer_; } @@ -49,4 +49,3 @@ contract QuarkScript { _; } } - diff --git a/src/QuarkWallet.sol b/src/QuarkWallet.sol index 3d38f75d..56c97a3e 100644 --- a/src/QuarkWallet.sol +++ b/src/QuarkWallet.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.19; -import { CodeJar } from "./CodeJar.sol"; -import { ECDSA } from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol"; +import {CodeJar} from "./CodeJar.sol"; +import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol"; contract QuarkWallet { error BadSignatory(); @@ -27,10 +27,13 @@ contract QuarkWallet { bytes32 internal constant ACTIVE_CALLBACK_SLOT = bytes32(keccak256("org.quark.active-callback")); /// @dev The EIP-712 typehash for authorizing an operation - bytes32 internal constant QUARK_OPERATION_TYPEHASH = keccak256("QuarkOperation(bytes scriptSource,bytes scriptCalldata,uint256 nonce,uint256 expiry,bool allowCallback)"); + bytes32 internal constant QUARK_OPERATION_TYPEHASH = keccak256( + "QuarkOperation(bytes scriptSource,bytes scriptCalldata,uint256 nonce,uint256 expiry,bool allowCallback)" + ); /// @dev The EIP-712 typehash for the contract's domain - bytes32 internal constant DOMAIN_TYPEHASH = keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"); + bytes32 internal constant DOMAIN_TYPEHASH = + keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"); /// @notice Name of contract, for use in DOMAIN_SEPARATOR string public constant name = "Quark Wallet"; @@ -54,9 +57,9 @@ contract QuarkWallet { uint256 nonce; uint256 expiry; bool allowCallback; - // requirements - // isReplayable } + // requirements + // isReplayable constructor(address owner_, CodeJar codeJar_) { owner = owner_; @@ -68,7 +71,9 @@ contract QuarkWallet { * variable that we are allowed to access with impunity. */ bytes32 slot = OWNER_SLOT; - assembly { sstore(slot, owner_) } + assembly { + sstore(slot, owner_) + } } /** @@ -112,9 +117,7 @@ contract QuarkWallet { */ function DOMAIN_SEPARATOR() public view returns (bytes32) { return keccak256( - abi.encode( - DOMAIN_TYPEHASH, keccak256(bytes(name)), keccak256(bytes(VERSION)), block.chainid, address(this) - ) + abi.encode(DOMAIN_TYPEHASH, keccak256(bytes(name)), keccak256(bytes(VERSION)), block.chainid, address(this)) ); } @@ -124,7 +127,9 @@ contract QuarkWallet { function getActiveCallback() internal returns (address) { bytes32 slot = ACTIVE_CALLBACK_SLOT; address callback; - assembly { callback := sload(slot) } + assembly { + callback := sload(slot) + } return callback; } @@ -136,7 +141,9 @@ contract QuarkWallet { */ function setActiveCallback(address callback) internal { bytes32 slot = ACTIVE_CALLBACK_SLOT; - assembly { sstore(slot, callback) } + assembly { + sstore(slot, callback) + } } /** @@ -148,16 +155,19 @@ contract QuarkWallet { * @param s EIP-712 signature s value * @return return value from the executed operation */ - function executeQuarkOperation( - QuarkOperation calldata op, - uint8 v, - bytes32 r, - bytes32 s - ) public payable returns (bytes memory) { + function executeQuarkOperation(QuarkOperation calldata op, uint8 v, bytes32 r, bytes32 s) + public + payable + returns (bytes memory) + { if (block.timestamp >= op.expiry) revert SignatureExpired(); if (isSet(op.nonce)) revert InvalidNonce(); - bytes32 structHash = keccak256(abi.encode(QUARK_OPERATION_TYPEHASH, op.scriptSource, op.scriptCalldata, op.nonce, op.expiry, op.allowCallback)); + bytes32 structHash = keccak256( + abi.encode( + QUARK_OPERATION_TYPEHASH, op.scriptSource, op.scriptCalldata, op.nonce, op.expiry, op.allowCallback + ) + ); bytes32 digest = keccak256(abi.encodePacked("\x19\x01", DOMAIN_SEPARATOR(), structHash)); if (isValidSignature(owner, digest, v, r, s)) { @@ -195,7 +205,11 @@ contract QuarkWallet { * @param scriptCalldata The encoded function selector and arguments to call on the transaction script * @return return value from the executed operation */ - function executeQuarkOperation(bytes calldata scriptSource, bytes calldata scriptCalldata) public payable returns (bytes memory) { + function executeQuarkOperation(bytes calldata scriptSource, bytes calldata scriptCalldata) + public + payable + returns (bytes memory) + { // XXX authenticate caller address scriptAddress = codeJar.saveCode(scriptSource); // XXX add support for allowCallback to the direct path @@ -205,7 +219,10 @@ contract QuarkWallet { /** * @dev Execute QuarkOperation */ - function executeQuarkOperationInternal(address scriptAddress, bytes memory scriptCalldata, bool allowCallback) internal returns (bytes memory) { + function executeQuarkOperationInternal(address scriptAddress, bytes memory scriptCalldata, bool allowCallback) + internal + returns (bytes memory) + { uint256 codeLen; assembly { codeLen := extcodesize(scriptAddress) @@ -224,10 +241,11 @@ contract QuarkWallet { } bool success; - uint returnSize; - uint scriptCalldataLen = scriptCalldata.length; + uint256 returnSize; + uint256 scriptCalldataLen = scriptCalldata.length; assembly { - success := callcode(gas(), scriptAddress, 0/* value */, add(scriptCalldata, 0x20), scriptCalldataLen, 0x0, 0) + success := + callcode(gas(), scriptAddress, 0, /* value */ add(scriptCalldata, 0x20), scriptCalldataLen, 0x0, 0) returnSize := returndatasize() } diff --git a/src/QuarkWalletFactory.sol b/src/QuarkWalletFactory.sol index 467eee22..071799b8 100644 --- a/src/QuarkWalletFactory.sol +++ b/src/QuarkWalletFactory.sol @@ -7,8 +7,8 @@ import "./QuarkWallet.sol"; contract QuarkWalletFactory { event WalletDeploy(address indexed account, address indexed walletAddress, bytes32 salt); - /// @notice Major version of the contract - uint public constant VERSION = 1; + /// @notice Major version of the contract + uint256 public constant VERSION = 1; /// @notice Address of CodeJar contract CodeJar public immutable codeJar; @@ -58,21 +58,23 @@ contract QuarkWalletFactory { * @return address Address of the QuarkWallet for account, salt pair */ function walletAddressForAccount(address account, bytes32 salt) public view returns (address) { - return address(uint160(uint( - keccak256( - abi.encodePacked( - bytes1(0xff), - address(this), - salt, + return address( + uint160( + uint256( keccak256( abi.encodePacked( - type(QuarkWallet).creationCode, - abi.encode(account), - abi.encode(address(codeJar)) + bytes1(0xff), + address(this), + salt, + keccak256( + abi.encodePacked( + type(QuarkWallet).creationCode, abi.encode(account), abi.encode(address(codeJar)) + ) + ) ) ) ) - ))) + ) ); } @@ -85,13 +87,10 @@ contract QuarkWalletFactory { * @param s EIP-712 Signature `s` value * @return bytes Return value of executing the operation */ - function createAndExecute( - address account, - QuarkWallet.QuarkOperation memory op, - uint8 v, - bytes32 r, - bytes32 s - ) external returns (bytes memory) { + function createAndExecute(address account, QuarkWallet.QuarkOperation memory op, uint8 v, bytes32 r, bytes32 s) + external + returns (bytes memory) + { return createAndExecute(account, 0, op, v, r, s); } diff --git a/src/Relayer.sol b/src/Relayer.sol index 9a7604a2..f2b39b06 100644 --- a/src/Relayer.sol +++ b/src/Relayer.sol @@ -32,21 +32,26 @@ abstract contract Relayer { /// @notice The major version of this contract string public constant version = "0"; - /** Internal constants **/ + /** + * Internal constants * + */ /// @dev The EIP-712 typehash for the contract's domain - bytes32 internal constant DOMAIN_TYPEHASH = keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"); + bytes32 internal constant DOMAIN_TYPEHASH = + keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"); /// @dev The EIP-712 typehash for runTrxScript - bytes32 internal constant TRX_SCRIPT_TYPEHASH = keccak256("TrxScript(address account,uint32 nonce,uint32[] reqs,bytes trxScript,bytes trxCalldata,uint256 expiry)"); + bytes32 internal constant TRX_SCRIPT_TYPEHASH = keccak256( + "TrxScript(address account,uint32 nonce,uint32[] reqs,bytes trxScript,bytes trxCalldata,uint256 expiry)" + ); /// @dev See https://ethereum.github.io/yellowpaper/paper.pdf #307) - uint internal constant MAX_VALID_ECDSA_S = 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0; + uint256 internal constant MAX_VALID_ECDSA_S = 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0; // Sets a nonce if it's unset, otherwise reverts with `NonceReplay`. function trySetNonce(address account, uint32 nonce, bool replayable) internal { uint32 nonceIndex = nonce / 256; - uint32 nonceOffset = nonce - ( nonceIndex * 256 ); + uint32 nonceOffset = nonce - (nonceIndex * 256); uint256 nonceBit = (2 << nonceOffset); uint256 nonceChunk = nonces[account][uint256(nonceIndex)]; @@ -62,7 +67,7 @@ abstract contract Relayer { // TODO: We could make this a lot more efficient if we bulk nonces together function getNonce(address account, uint32 nonce) internal view returns (bool) { uint32 nonceIndex = nonce / 256; - uint32 nonceOffset = nonce - ( nonceIndex * 256 ); + uint32 nonceOffset = nonce - (nonceIndex * 256); uint256 nonceBit = (2 << nonceOffset); uint256 nonceChunk = nonces[account][uint256(nonceIndex)]; @@ -93,7 +98,17 @@ abstract contract Relayer { if (uint256(s) > MAX_VALID_ECDSA_S) revert InvalidValueS(); // v ∈ {27, 28} (source: https://ethereum.github.io/yellowpaper/paper.pdf #308) if (v != 27 && v != 28) revert InvalidValueV(); - bytes32 structHash = keccak256(abi.encode(TRX_SCRIPT_TYPEHASH, account, nonce, keccak256(abi.encodePacked(reqs)), keccak256(trxScript), keccak256(trxCalldata), expiry)); + bytes32 structHash = keccak256( + abi.encode( + TRX_SCRIPT_TYPEHASH, + account, + nonce, + keccak256(abi.encodePacked(reqs)), + keccak256(trxScript), + keccak256(trxCalldata), + expiry + ) + ); bytes32 digest = keccak256(abi.encodePacked("\x19\x01", DOMAIN_SEPARATOR(), structHash)); address signatory = ecrecover(digest, v, r, s); if (signatory == address(0)) revert BadSignatory(); @@ -132,13 +147,15 @@ abstract contract Relayer { } function DOMAIN_SEPARATOR() public view returns (bytes32) { - return keccak256(abi.encode(DOMAIN_TYPEHASH, keccak256("Quark"), keccak256(bytes(version)), block.chainid, address(this))); + return keccak256( + abi.encode(DOMAIN_TYPEHASH, keccak256("Quark"), keccak256(bytes(version)), block.chainid, address(this)) + ); } /** * @notice Helper function to return a quark address for a given account. */ - function getQuarkAddress(address account) public virtual view returns (address); + function getQuarkAddress(address account) public view virtual returns (address); /** * Run a quark script from a given account. Note: can also use fallback, which is @@ -157,7 +174,8 @@ abstract contract Relayer { return _doRunQuark(msg.sender, quarkCode, quarkCalldata); } - /*** + /** + * * @notice Runs a given quark script, if valid, from the current sender. */ fallback(bytes calldata quarkCode) external payable returns (bytes memory) { @@ -166,7 +184,10 @@ abstract contract Relayer { // Internal function for running a quark. This handles the `create2`, invoking the script, // and then calling `destruct` to clean it up. We attempt to revert on any failed step. - function _doRunQuark(address account, bytes memory quarkCode, bytes memory quarkCalldata) internal returns (bytes memory) { + function _doRunQuark(address account, bytes memory quarkCode, bytes memory quarkCalldata) + internal + returns (bytes memory) + { bytes memory resData = _runQuark(account, quarkCode, quarkCalldata); assembly { log1(0, 0, 0xDEADBEEF) @@ -176,13 +197,16 @@ abstract contract Relayer { // Internal function for running a quark. This handles the `create2`, invoking the script, // and then calling `destruct` to clean it up. We attempt to revert on any failed step. - function _runQuark(address account, bytes memory quarkCode, bytes memory quarkCalldata) internal virtual returns (bytes memory); + function _runQuark(address account, bytes memory quarkCode, bytes memory quarkCalldata) + internal + virtual + returns (bytes memory); - /*** + /** + * * @notice Revert given empty call. */ receive() external payable { revert(); } } - diff --git a/src/RelayerAtomic.sol b/src/RelayerAtomic.sol index b2c99653..85a24a4a 100644 --- a/src/RelayerAtomic.sol +++ b/src/RelayerAtomic.sol @@ -20,22 +20,24 @@ contract RelayerAtomic is Relayer { /** * @notice Helper function to return a quark address for a given account. */ - function getQuarkAddress(address account) public override view returns (address) { - return address(uint160(uint( - keccak256( - abi.encodePacked( - bytes1(0xff), - address(this), - uint256(0), + function getQuarkAddress(address account) public view override returns (address) { + return address( + uint160( + uint256( keccak256( abi.encodePacked( - type(QuarkWallet).creationCode, - abi.encode(account), - abi.encode(address(codeJar)) + bytes1(0xff), + address(this), + uint256(0), + keccak256( + abi.encodePacked( + type(QuarkWallet).creationCode, abi.encode(account), abi.encode(address(codeJar)) + ) + ) ) ) ) - ))) + ) ); } @@ -68,7 +70,11 @@ contract RelayerAtomic is Relayer { // Internal function for running a quark. This handles the `create2`, invoking the script, // and then calling `destruct` to clean it up. We attempt to revert on any failed step. - function _runQuark(address account, bytes memory quarkCode, bytes memory quarkCalldata) internal override returns (bytes memory) { + function _runQuark(address account, bytes memory quarkCode, bytes memory quarkCalldata) + internal + override + returns (bytes memory) + { address quarkAddress = getQuarkAddress(account); // Ensure a quark isn't already running diff --git a/test/Callbacks.t.sol b/test/Callbacks.t.sol index aa3e5dce..4efc1998 100644 --- a/test/Callbacks.t.sol +++ b/test/Callbacks.t.sol @@ -4,14 +4,13 @@ import "forge-std/Test.sol"; import "forge-std/StdUtils.sol"; import "forge-std/console.sol"; -import { Test } from "forge-std/Test.sol"; -import { QuarkWallet } from "../src/QuarkWallet.sol"; -import { CodeJar} from "../src/CodeJar.sol"; -import { Counter } from "./lib/Counter.sol"; -import { YulHelper } from "./lib/YulHelper.sol"; +import {Test} from "forge-std/Test.sol"; +import {QuarkWallet} from "../src/QuarkWallet.sol"; +import {CodeJar} from "../src/CodeJar.sol"; +import {Counter} from "./lib/Counter.sol"; +import {YulHelper} from "./lib/YulHelper.sol"; contract CallbacksTest is Test { - CodeJar public codeJar; Counter public counter; @@ -19,7 +18,9 @@ contract CallbacksTest is Test { address aliceAccount; // see constructor() QuarkWallet public aliceWallet; - bytes32 internal constant QUARK_OPERATION_TYPEHASH = keccak256("QuarkOperation(bytes scriptSource,bytes scriptCalldata,uint256 nonce,uint256 expiry,bool allowCallback)"); + bytes32 internal constant QUARK_OPERATION_TYPEHASH = keccak256( + "QuarkOperation(bytes scriptSource,bytes scriptCalldata,uint256 nonce,uint256 expiry,bool allowCallback)" + ); constructor() { codeJar = new CodeJar(); @@ -33,36 +34,31 @@ contract CallbacksTest is Test { aliceWallet = new QuarkWallet(aliceAccount, codeJar); } - function signOp(uint256 privateKey, QuarkWallet wallet, QuarkWallet.QuarkOperation memory op) internal view returns (uint8, bytes32, bytes32) { - bytes32 structHash = keccak256(abi.encode( - QUARK_OPERATION_TYPEHASH, - op.scriptSource, - op.scriptCalldata, - op.nonce, - op.expiry, - op.allowCallback - )); - bytes32 digest = keccak256(abi.encodePacked( - "\x19\x01", - wallet.DOMAIN_SEPARATOR(), - structHash - )); + function signOp(uint256 privateKey, QuarkWallet wallet, QuarkWallet.QuarkOperation memory op) + internal + view + returns (uint8, bytes32, bytes32) + { + bytes32 structHash = keccak256( + abi.encode( + QUARK_OPERATION_TYPEHASH, op.scriptSource, op.scriptCalldata, op.nonce, op.expiry, op.allowCallback + ) + ); + bytes32 digest = keccak256(abi.encodePacked("\x19\x01", wallet.DOMAIN_SEPARATOR(), structHash)); return vm.sign(privateKey, digest); } function testCallbackFromCounter() public { assertEq(counter.number(), 0); - bytes memory callbackFromCounter = new YulHelper().getDeployed("CallbackFromCounter.sol/CallbackFromCounter.json"); + bytes memory callbackFromCounter = + new YulHelper().getDeployed("CallbackFromCounter.sol/CallbackFromCounter.json"); uint256 nonce = aliceWallet.nextUnusedNonce(); QuarkWallet.QuarkOperation memory op = QuarkWallet.QuarkOperation({ scriptSource: callbackFromCounter, - scriptCalldata: abi.encodeWithSignature( - "doIncrementAndCallback(address)", - counter - ), + scriptCalldata: abi.encodeWithSignature("doIncrementAndCallback(address)", counter), nonce: nonce, expiry: block.timestamp + 1000, allowCallback: true @@ -74,16 +70,15 @@ contract CallbacksTest is Test { } function testRevertsNestedCallbackScriptIfCallbackAlreadyActive() public { - bytes memory callbackFromCounter = new YulHelper().getDeployed("CallbackFromCounter.sol/CallbackFromCounter.json"); - bytes memory executeOtherScript = new YulHelper().getDeployed("ExecuteOtherOperation.sol/ExecuteOtherOperation.json"); + bytes memory callbackFromCounter = + new YulHelper().getDeployed("CallbackFromCounter.sol/CallbackFromCounter.json"); + bytes memory executeOtherScript = + new YulHelper().getDeployed("ExecuteOtherOperation.sol/ExecuteOtherOperation.json"); uint256 nonce1 = aliceWallet.nextUnusedNonce(); QuarkWallet.QuarkOperation memory nestedOp = QuarkWallet.QuarkOperation({ scriptSource: callbackFromCounter, - scriptCalldata: abi.encodeWithSignature( - "doIncrementAndCallback(address)", - counter - ), + scriptCalldata: abi.encodeWithSignature("doIncrementAndCallback(address)", counter), nonce: nonce1, expiry: block.timestamp + 1000, allowCallback: true @@ -94,12 +89,8 @@ contract CallbacksTest is Test { QuarkWallet.QuarkOperation memory parentOp = QuarkWallet.QuarkOperation({ scriptSource: executeOtherScript, scriptCalldata: abi.encodeWithSignature( - "run((bytes,bytes,uint256,uint256,bool),uint8,bytes32,bytes32)", - nestedOp, - v_, - r_, - s_ - ), + "run((bytes,bytes,uint256,uint256,bool),uint8,bytes32,bytes32)", nestedOp, v_, r_, s_ + ), nonce: nonce2, expiry: block.timestamp + 1000, allowCallback: true @@ -107,8 +98,10 @@ contract CallbacksTest is Test { (uint8 v, bytes32 r, bytes32 s) = signOp(alicePrivateKey, aliceWallet, parentOp); vm.expectRevert( - abi.encodeWithSelector(QuarkWallet.QuarkCallError.selector, - abi.encodeWithSelector(QuarkWallet.QuarkCallbackAlreadyActive.selector)) + abi.encodeWithSelector( + QuarkWallet.QuarkCallError.selector, + abi.encodeWithSelector(QuarkWallet.QuarkCallbackAlreadyActive.selector) + ) ); aliceWallet.executeQuarkOperation(parentOp, v, r, s); } @@ -117,15 +110,13 @@ contract CallbacksTest is Test { assertEq(counter.number(), 0); bytes memory counterScript = new YulHelper().getDeployed("CounterScript.sol/CounterScript.json"); - bytes memory executeOtherScript = new YulHelper().getDeployed("ExecuteOtherOperation.sol/ExecuteOtherOperation.json"); + bytes memory executeOtherScript = + new YulHelper().getDeployed("ExecuteOtherOperation.sol/ExecuteOtherOperation.json"); uint256 nonce1 = aliceWallet.nextUnusedNonce(); QuarkWallet.QuarkOperation memory nestedOp = QuarkWallet.QuarkOperation({ scriptSource: counterScript, - scriptCalldata: abi.encodeWithSignature( - "run(address)", - counter - ), + scriptCalldata: abi.encodeWithSignature("run(address)", counter), nonce: nonce1, expiry: block.timestamp + 1000, allowCallback: false @@ -136,12 +127,8 @@ contract CallbacksTest is Test { QuarkWallet.QuarkOperation memory parentOp = QuarkWallet.QuarkOperation({ scriptSource: executeOtherScript, scriptCalldata: abi.encodeWithSignature( - "run((bytes,bytes,uint256,uint256,bool),uint8,bytes32,bytes32)", - nestedOp, - v_, - r_, - s_ - ), + "run((bytes,bytes,uint256,uint256,bool),uint8,bytes32,bytes32)", nestedOp, v_, r_, s_ + ), nonce: nonce2, expiry: block.timestamp + 1000, allowCallback: true @@ -158,10 +145,7 @@ contract CallbacksTest is Test { uint256 nonce = aliceWallet.nextUnusedNonce(); QuarkWallet.QuarkOperation memory op = QuarkWallet.QuarkOperation({ scriptSource: counterScript, - scriptCalldata: abi.encodeWithSignature( - "run(address)", - counter - ), + scriptCalldata: abi.encodeWithSignature("run(address)", counter), nonce: nonce, expiry: block.timestamp + 1000, allowCallback: true @@ -173,15 +157,13 @@ contract CallbacksTest is Test { } function testRevertsOnCallbackWhenNoActiveCallback() public { - bytes memory callbackFromCounter = new YulHelper().getDeployed("CallbackFromCounter.sol/CallbackFromCounter.json"); + bytes memory callbackFromCounter = + new YulHelper().getDeployed("CallbackFromCounter.sol/CallbackFromCounter.json"); uint256 nonce = aliceWallet.nextUnusedNonce(); QuarkWallet.QuarkOperation memory op = QuarkWallet.QuarkOperation({ scriptSource: callbackFromCounter, - scriptCalldata: abi.encodeWithSignature( - "doIncrementAndCallback(address)", - counter - ), + scriptCalldata: abi.encodeWithSignature("doIncrementAndCallback(address)", counter), nonce: nonce, expiry: block.timestamp + 1000, allowCallback: false @@ -189,8 +171,9 @@ contract CallbacksTest is Test { (uint8 v, bytes32 r, bytes32 s) = signOp(alicePrivateKey, aliceWallet, op); vm.expectRevert( - abi.encodeWithSelector(QuarkWallet.QuarkCallError.selector, - abi.encodeWithSelector(QuarkWallet.NoActiveCallback.selector)) + abi.encodeWithSelector( + QuarkWallet.QuarkCallError.selector, abi.encodeWithSelector(QuarkWallet.NoActiveCallback.selector) + ) ); aliceWallet.executeQuarkOperation(op, v, r, s); } diff --git a/test/CodeJar.t.sol b/test/CodeJar.t.sol index 228c1e34..05e2850b 100644 --- a/test/CodeJar.t.sol +++ b/test/CodeJar.t.sol @@ -10,6 +10,7 @@ import "../src/CodeJar.sol"; contract CodeJarTest is Test { event Ping(uint256 value); + error CodeInvalid(address codeAddress); CodeJar public codeJar; @@ -43,7 +44,7 @@ contract CodeJarTest is Test { address scriptAddress = codeJar.saveCode(hex"11223344"); uint256 gasLeft = gasleft(); - address scriptAddressNext = codeJar.saveCode(hex"11223344"); + address scriptAddressNext = codeJar.saveCode(hex"11223344"); uint256 gasUsed = gasLeft - gasleft(); assertEq(scriptAddress, scriptAddressNext); assertEq(scriptAddressNext.code, hex"11223344"); @@ -59,8 +60,10 @@ contract CodeJarTest is Test { scripts[3] = hex"112233"; scripts[4] = hex"00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff"; scripts[5] = hex"00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff11"; - scripts[6] = hex"00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff"; - scripts[7] = hex"00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff11"; + scripts[6] = + hex"00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff"; + scripts[7] = + hex"00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff11"; for (uint8 i = 0; i < scripts.length; i++) { assertEq(codeJar.codeExists(scripts[i]), false); diff --git a/test/EIP712.t.sol b/test/EIP712.t.sol index 3738e4f9..365832db 100644 --- a/test/EIP712.t.sol +++ b/test/EIP712.t.sol @@ -4,11 +4,11 @@ import "forge-std/Test.sol"; import "forge-std/StdUtils.sol"; import "forge-std/console.sol"; -import { Test } from "forge-std/Test.sol"; -import { QuarkWallet } from "../src/QuarkWallet.sol"; -import { CodeJar} from "../src/CodeJar.sol"; -import { Counter } from "./lib/Counter.sol"; -import { YulHelper } from "./lib/YulHelper.sol"; +import {Test} from "forge-std/Test.sol"; +import {QuarkWallet} from "../src/QuarkWallet.sol"; +import {CodeJar} from "../src/CodeJar.sol"; +import {Counter} from "./lib/Counter.sol"; +import {YulHelper} from "./lib/YulHelper.sol"; contract EIP712Test is Test { CodeJar public codeJar; @@ -20,7 +20,9 @@ contract EIP712Test is Test { address bob = address(11); // 0x00...b address charlie = address(12); // 0x00...c - bytes32 internal constant QUARK_OPERATION_TYPEHASH = keccak256("QuarkOperation(bytes scriptSource,bytes scriptCalldata,uint256 nonce,uint256 expiry,bool allowCallback)"); + bytes32 internal constant QUARK_OPERATION_TYPEHASH = keccak256( + "QuarkOperation(bytes scriptSource,bytes scriptCalldata,uint256 nonce,uint256 expiry,bool allowCallback)" + ); function setUp() public { codeJar = new CodeJar(); @@ -35,12 +37,19 @@ contract EIP712Test is Test { } function aliceSignature(QuarkWallet.QuarkOperation memory op) internal view returns (uint8, bytes32, bytes32) { - bytes32 structHash = keccak256(abi.encode(QUARK_OPERATION_TYPEHASH, op.scriptSource, op.scriptCalldata, op.nonce, op.expiry, op.allowCallback)); + bytes32 structHash = keccak256( + abi.encode( + QUARK_OPERATION_TYPEHASH, op.scriptSource, op.scriptCalldata, op.nonce, op.expiry, op.allowCallback + ) + ); bytes32 digest = keccak256(abi.encodePacked("\x19\x01", wallet.DOMAIN_SEPARATOR(), structHash)); return vm.sign(alicePrivateKey, digest); } - function incrementCounterOperation(uint256 nonce, uint256 expiry) public returns (QuarkWallet.QuarkOperation memory) { + function incrementCounterOperation(uint256 nonce, uint256 expiry) + public + returns (QuarkWallet.QuarkOperation memory) + { bytes memory incrementer = new YulHelper().getDeployed("Incrementer.sol/Incrementer.json"); QuarkWallet.QuarkOperation memory op = QuarkWallet.QuarkOperation({ diff --git a/test/Nonce.t.sol b/test/Nonce.t.sol index bb0cbe3d..2adad1ce 100644 --- a/test/Nonce.t.sol +++ b/test/Nonce.t.sol @@ -4,11 +4,11 @@ pragma solidity ^0.8.19; import "forge-std/Test.sol"; import "forge-std/console.sol"; -import { CodeJar } from "../src/CodeJar.sol"; -import { QuarkWallet } from "../src/QuarkWallet.sol"; +import {CodeJar} from "../src/CodeJar.sol"; +import {QuarkWallet} from "../src/QuarkWallet.sol"; contract QuarkWalletHarness is QuarkWallet { - constructor(address owner, CodeJar codeJar) QuarkWallet(owner, codeJar) { } + constructor(address owner, CodeJar codeJar) QuarkWallet(owner, codeJar) {} function setNonceExternal(uint256 index) external { setNonce(index); diff --git a/test/QuarkWallet.t.sol b/test/QuarkWallet.t.sol index 8c949c73..c72b8fe5 100644 --- a/test/QuarkWallet.t.sol +++ b/test/QuarkWallet.t.sol @@ -30,10 +30,8 @@ contract QuarkWalletTest is Test { function testExecuteQuarkOperation() public { address account = address(0xaa); QuarkWallet wallet = new QuarkWallet{salt: 0}(account, codeJar); - bytes memory result = wallet.executeQuarkOperation( - new YulHelper().getDeployed("GetOwner.sol/GetOwner.json"), - abi.encode() - ); + bytes memory result = + wallet.executeQuarkOperation(new YulHelper().getDeployed("GetOwner.sol/GetOwner.json"), abi.encode()); assertEq(result, abi.encode(0xaa)); } @@ -42,24 +40,17 @@ contract QuarkWalletTest is Test { QuarkWallet wallet = new QuarkWallet{salt: 0}(account, codeJar); vm.expectRevert(abi.encodeWithSelector(QuarkWallet.QuarkCodeNotFound.selector)); - wallet.executeQuarkOperation( - abi.encode(), - abi.encodeWithSignature("x()") - ); + wallet.executeQuarkOperation(abi.encode(), abi.encodeWithSignature("x()")); } function testQuarkOperationRevertsIfCallReverts() public { address account = address(0xb0b); bytes memory revertsCode = new YulHelper().getDeployed("Reverts.sol/Reverts.json"); QuarkWallet wallet = new QuarkWallet{salt: 0}(account, codeJar); - vm.expectRevert(abi.encodeWithSelector( - QuarkWallet.QuarkCallError.selector, - abi.encodeWithSelector(Reverts.Whoops.selector) - )); - wallet.executeQuarkOperation( - revertsCode, - abi.encode() + vm.expectRevert( + abi.encodeWithSelector(QuarkWallet.QuarkCallError.selector, abi.encodeWithSelector(Reverts.Whoops.selector)) ); + wallet.executeQuarkOperation(revertsCode, abi.encode()); } function testAtomicPing() public { @@ -69,10 +60,7 @@ contract QuarkWalletTest is Test { QuarkWallet wallet = new QuarkWallet{salt: 0}(account, codeJar); vm.expectEmit(false, false, false, true); emit Ping(55); - wallet.executeQuarkOperation( - ping, - abi.encode() - ); + wallet.executeQuarkOperation(ping, abi.encode()); } function testAtomicIncrementer() public { @@ -81,10 +69,7 @@ contract QuarkWalletTest is Test { assertEq(counter.number(), 0); address account = address(0xb0b); QuarkWallet wallet = new QuarkWallet{salt: 0}(account, codeJar); - wallet.executeQuarkOperation( - incrementer, - abi.encodeWithSignature("incrementCounter(address)", counter) - ); + wallet.executeQuarkOperation(incrementer, abi.encodeWithSignature("incrementCounter(address)", counter)); assertEq(counter.number(), 3); } @@ -98,35 +83,22 @@ contract QuarkWalletTest is Test { address account = address(0xb0b); QuarkWallet wallet = new QuarkWallet{salt: 0}(account, codeJar); // call once - wallet.executeQuarkOperation( - maxCounterScript, - abi.encodeCall(MaxCounterScript.run, (counter)) - ); + wallet.executeQuarkOperation(maxCounterScript, abi.encodeCall(MaxCounterScript.run, (counter))); assertEq(counter.number(), 1); // call twice - wallet.executeQuarkOperation( - maxCounterScript, - abi.encodeCall(MaxCounterScript.run, (counter)) - ); + wallet.executeQuarkOperation(maxCounterScript, abi.encodeCall(MaxCounterScript.run, (counter))); // call thrice assertEq(counter.number(), 2); - wallet.executeQuarkOperation( - maxCounterScript, - abi.encodeCall(MaxCounterScript.run, (counter)) - ); + wallet.executeQuarkOperation(maxCounterScript, abi.encodeCall(MaxCounterScript.run, (counter))); assertEq(counter.number(), 3); // revert because max has been hit vm.expectRevert( abi.encodeWithSelector( - QuarkWallet.QuarkCallError.selector, - abi.encodeWithSelector(MaxCounterScript.EnoughAlready.selector) - ) - ); - wallet.executeQuarkOperation( - maxCounterScript, - abi.encodeCall(MaxCounterScript.run, (counter)) + QuarkWallet.QuarkCallError.selector, abi.encodeWithSelector(MaxCounterScript.EnoughAlready.selector) + ) ); + wallet.executeQuarkOperation(maxCounterScript, abi.encodeCall(MaxCounterScript.run, (counter))); assertEq(counter.number(), 3); vm.stopPrank(); diff --git a/test/QuarkWalletFactory.t.sol b/test/QuarkWalletFactory.t.sol index ce418f47..19faa292 100644 --- a/test/QuarkWalletFactory.t.sol +++ b/test/QuarkWalletFactory.t.sol @@ -21,9 +21,12 @@ contract QuarkWalletFactoryTest is Test { address alice; // see setup() address bob = address(11); - bytes32 internal constant QUARK_OPERATION_TYPEHASH = keccak256("QuarkOperation(bytes scriptSource,bytes scriptCalldata,uint256 nonce,uint256 expiry,bool allowCallback)"); + bytes32 internal constant QUARK_OPERATION_TYPEHASH = keccak256( + "QuarkOperation(bytes scriptSource,bytes scriptCalldata,uint256 nonce,uint256 expiry,bool allowCallback)" + ); - bytes32 internal constant QUARK_WALLET_DOMAIN_TYPEHASH = keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"); + bytes32 internal constant QUARK_WALLET_DOMAIN_TYPEHASH = + keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"); constructor() { factory = new QuarkWalletFactory(); @@ -53,8 +56,16 @@ contract QuarkWalletFactoryTest is Test { return aliceSignature(op, 0); } - function aliceSignature(QuarkWallet.QuarkOperation memory op, bytes32 salt) internal view returns (uint8, bytes32, bytes32) { - bytes32 structHash = keccak256(abi.encode(QUARK_OPERATION_TYPEHASH, op.scriptSource, op.scriptCalldata, op.nonce, op.expiry, op.allowCallback)); + function aliceSignature(QuarkWallet.QuarkOperation memory op, bytes32 salt) + internal + view + returns (uint8, bytes32, bytes32) + { + bytes32 structHash = keccak256( + abi.encode( + QUARK_OPERATION_TYPEHASH, op.scriptSource, op.scriptCalldata, op.nonce, op.expiry, op.allowCallback + ) + ); bytes32 walletDomainSeparator = domainSeparatorForAccount(alice, salt); bytes32 digest = keccak256(abi.encodePacked("\x19\x01", walletDomainSeparator, structHash)); return vm.sign(alicePrivateKey, digest); @@ -70,22 +81,14 @@ contract QuarkWalletFactoryTest is Test { function testCreatesWalletAtDeterministicAddress() public { vm.expectEmit(true, true, true, true); - emit WalletDeploy( - alice, - factory.walletAddressForAccount(alice), - bytes32(0) - ); + emit WalletDeploy(alice, factory.walletAddressForAccount(alice), bytes32(0)); address aliceWallet = factory.create(alice); assertEq(aliceWallet, factory.walletAddressForAccount(alice)); } function testCreateRevertsOnRepeat() public { vm.expectEmit(true, true, true, true); - emit WalletDeploy( - alice, - factory.walletAddressForAccount(alice), - bytes32(0) - ); + emit WalletDeploy(alice, factory.walletAddressForAccount(alice), bytes32(0)); factory.create(alice); vm.expectRevert(); factory.create(alice); @@ -94,11 +97,7 @@ contract QuarkWalletFactoryTest is Test { function testCreateAdditionalWalletWithSalt() public { // inital wallet is created vm.expectEmit(true, true, true, true); - emit WalletDeploy( - alice, - factory.walletAddressForAccount(alice), - bytes32(0) - ); + emit WalletDeploy(alice, factory.walletAddressForAccount(alice), bytes32(0)); factory.create(alice); // it is created with 0 as salt (and therefore reverts on a repeated attempt) @@ -129,21 +128,14 @@ contract QuarkWalletFactoryTest is Test { // operation is executed vm.expectEmit(true, true, true, true); // it creates a wallet - emit WalletDeploy( - alice, - factory.walletAddressForAccount(alice), - bytes32(0) - ); + emit WalletDeploy(alice, factory.walletAddressForAccount(alice), bytes32(0)); factory.createAndExecute(alice, op, v, r, s); - // operation was executed + // operation was executed assertEq(counter.number(), 3); // uses up the operation's nonce - assertEq( - QuarkWallet(factory.walletAddressForAccount(alice)).isSet(0), - true - ); + assertEq(QuarkWallet(factory.walletAddressForAccount(alice)).isSet(0), true); } function testCreateAndExecuteWithSalt() public { @@ -159,7 +151,7 @@ contract QuarkWalletFactoryTest is Test { bytes32 salt = bytes32("salty salt salt"); - // alice signs the operation + // alice signs the operation (uint8 v, bytes32 r, bytes32 s) = aliceSignature(op, salt); assertEq(counter.number(), 0); @@ -167,21 +159,14 @@ contract QuarkWalletFactoryTest is Test { // operation is executed vm.expectEmit(true, true, true, true); // it creates a wallet (with salt) - emit WalletDeploy( - alice, - factory.walletAddressForAccount(alice, salt), - salt - ); + emit WalletDeploy(alice, factory.walletAddressForAccount(alice, salt), salt); factory.createAndExecute(alice, salt, op, v, r, s); - // operation was executed + // operation was executed assertEq(counter.number(), 3); // uses up the operation's nonce - assertEq( - QuarkWallet(factory.walletAddressForAccount(alice, salt)).isSet(0), - true - ); + assertEq(QuarkWallet(factory.walletAddressForAccount(alice, salt)).isSet(0), true); } function testExecuteOnExistingWallet() public { @@ -202,23 +187,16 @@ contract QuarkWalletFactoryTest is Test { // the wallet is deployed vm.expectEmit(true, true, true, true); - emit WalletDeploy( - alice, - factory.walletAddressForAccount(alice), - bytes32(0) - ); + emit WalletDeploy(alice, factory.walletAddressForAccount(alice), bytes32(0)); factory.create(alice); // operation is executed factory.createAndExecute(alice, op, v, r, s); - // operation was executed + // operation was executed assertEq(counter.number(), 3); // uses up the operation's nonce - assertEq( - QuarkWallet(factory.walletAddressForAccount(alice)).isSet(0), - true - ); + assertEq(QuarkWallet(factory.walletAddressForAccount(alice)).isSet(0), true); } } diff --git a/test/lib/CallbackFromCounter.sol b/test/lib/CallbackFromCounter.sol index 53c59a80..2184c8fc 100644 --- a/test/lib/CallbackFromCounter.sol +++ b/test/lib/CallbackFromCounter.sol @@ -7,11 +7,11 @@ import "./Counter.sol"; contract CallbackFromCounter { function doIncrementAndCallback(Counter counter) public { - counter.incrementAndCallback(); + counter.incrementAndCallback(); } function callback() external { - Counter counter = Counter(msg.sender); - counter.increment(counter.number() * 10); + Counter counter = Counter(msg.sender); + counter.increment(counter.number() * 10); } } diff --git a/test/lib/Counter.sol b/test/lib/Counter.sol index a650176a..b87335fa 100644 --- a/test/lib/Counter.sol +++ b/test/lib/Counter.sol @@ -25,4 +25,3 @@ contract Counter { return HasCallback(msg.sender).callback(); } } - diff --git a/test/lib/CounterScript.sol b/test/lib/CounterScript.sol index 5b88aed6..41c6ad7f 100644 --- a/test/lib/CounterScript.sol +++ b/test/lib/CounterScript.sol @@ -4,10 +4,9 @@ pragma solidity ^0.8.19; import "./Counter.sol"; contract CounterScript { - function run(Counter c) external returns (bytes memory) { - c.increment(); - c.increment(); - return hex""; - } + function run(Counter c) external returns (bytes memory) { + c.increment(); + c.increment(); + return hex""; + } } - diff --git a/test/lib/GetOwner.sol b/test/lib/GetOwner.sol index 2c236700..920b58e9 100644 --- a/test/lib/GetOwner.sol +++ b/test/lib/GetOwner.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.19; import "../../src/QuarkScript.sol"; contract GetOwner is QuarkScript { - fallback(bytes calldata data) external payable returns (bytes memory) { - return abi.encode(owner()); - } + fallback(bytes calldata data) external payable returns (bytes memory) { + return abi.encode(owner()); + } } diff --git a/test/lib/Incrementer.sol b/test/lib/Incrementer.sol index a39f5ce1..69c977ea 100644 --- a/test/lib/Incrementer.sol +++ b/test/lib/Incrementer.sol @@ -4,15 +4,15 @@ pragma solidity ^0.8.19; import "./Counter.sol"; contract Incrementer { - function incrementCounter(Counter counter) public { - Counter(counter).increment(); - Counter(counter).increment(); - Counter(counter).increment(); - } + function incrementCounter(Counter counter) public { + Counter(counter).increment(); + Counter(counter).increment(); + Counter(counter).increment(); + } - fallback() external { - // Counter - address counter = 0xF62849F9A0B5Bf2913b396098F7c7019b51A820a; - incrementCounter(Counter(counter)); - } + fallback() external { + // Counter + address counter = 0xF62849F9A0B5Bf2913b396098F7c7019b51A820a; + incrementCounter(Counter(counter)); + } } diff --git a/test/lib/Logger.sol b/test/lib/Logger.sol index dddea3fc..7f8ca090 100644 --- a/test/lib/Logger.sol +++ b/test/lib/Logger.sol @@ -2,9 +2,9 @@ pragma solidity ^0.8.19; contract Logger { - event Ping(uint256); + event Ping(uint256); - fallback() external { - emit Ping(55); - } + fallback() external { + emit Ping(55); + } } diff --git a/test/lib/MaxCounterScript.sol b/test/lib/MaxCounterScript.sol index 23b76211..dd103968 100644 --- a/test/lib/MaxCounterScript.sol +++ b/test/lib/MaxCounterScript.sol @@ -5,19 +5,18 @@ import "../../src/QuarkScript.sol"; import "./Counter.sol"; contract MaxCounterScript is QuarkScript { - error EnoughAlready(); + error EnoughAlready(); - string constant maxCountVar = "quark.org.MaxCounterScript.maxCount"; + string constant maxCountVar = "quark.org.MaxCounterScript.maxCount"; - function run(Counter c) external returns (bytes memory) { - c.increment(); - uint256 count = sloadU256(maxCountVar); - if (count >= 3) { - revert EnoughAlready(); - } + function run(Counter c) external returns (bytes memory) { + c.increment(); + uint256 count = sloadU256(maxCountVar); + if (count >= 3) { + revert EnoughAlready(); + } - sstoreU256(maxCountVar, count + 1); - return hex""; - } + sstoreU256(maxCountVar, count + 1); + return hex""; + } } - diff --git a/test/lib/Reverts.sol b/test/lib/Reverts.sol index a3111bd0..00624205 100644 --- a/test/lib/Reverts.sol +++ b/test/lib/Reverts.sol @@ -2,9 +2,9 @@ pragma solidity ^0.8.19; contract Reverts { - error Whoops(); + error Whoops(); - fallback() external { - revert Whoops(); - } + fallback() external { + revert Whoops(); + } } diff --git a/test/lib/YulHelper.sol b/test/lib/YulHelper.sol index b9903bce..dfec938d 100644 --- a/test/lib/YulHelper.sol +++ b/test/lib/YulHelper.sol @@ -17,10 +17,7 @@ contract YulHelper is Test { } ///@notice check that the deployment was successful - require( - deployedAddress != address(0), - "could not deploy contract" - ); + require(deployedAddress != address(0), "could not deploy contract"); ///@notice return the address that the contract was deployed to return deployedAddress; From 1af0cab94c2a15d5932b3f11267e51ef6bf69164 Mon Sep 17 00:00:00 2001 From: Scott Silver Date: Thu, 19 Oct 2023 16:28:35 -0700 Subject: [PATCH 2/4] add forge fmt to Github Action --- .github/workflows/test.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 82500522..9da168b6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -33,6 +33,11 @@ jobs: forge build --sizes id: build + - name: Run Forge format + run: | + forge fmt --check + id: format + - name: Run Forge tests run: | forge test -vvv From b7795fd0af699425f858ad6a59bbc2fc71ba3211 Mon Sep 17 00:00:00 2001 From: Hans Wang Date: Thu, 19 Oct 2023 17:05:35 -0700 Subject: [PATCH 3/4] lint --- .github/workflows/lint.yml | 39 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 .github/workflows/lint.yml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 00000000..50b9b916 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,39 @@ +name: lint + +on: + workflow_dispatch: + pull_request: + +env: + FOUNDRY_PROFILE: ci + +jobs: + check: + strategy: + fail-fast: true + + name: Foundry project + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + submodules: recursive + + - name: Install Foundry + uses: foundry-rs/foundry-toolchain@v1 + with: + version: nightly + + - name: Install dependencies + run: forge install + + - name: Run Forge build + run: | + forge --version + forge build --sizes + id: build + + - name: Run Forge Format + run: | + forge fmt --check + id: format From c812e8d969bfca6a88aa1c6f580be65fdf36d916 Mon Sep 17 00:00:00 2001 From: Hans Wang Date: Thu, 19 Oct 2023 17:06:22 -0700 Subject: [PATCH 4/4] move format to be seaprate check --- .github/workflows/test.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9da168b6..82500522 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -33,11 +33,6 @@ jobs: forge build --sizes id: build - - name: Run Forge format - run: | - forge fmt --check - id: format - - name: Run Forge tests run: | forge test -vvv