From f77b40a95e6b3d124f90813487c409f2b0141f70 Mon Sep 17 00:00:00 2001 From: Wilson Cusack Date: Sun, 10 Mar 2024 19:55:38 -0400 Subject: [PATCH] add UpgradeToAndCall test --- .gas-snapshot | 86 ++++++++++--------- .../UpgradeToAndCall.t.sol | 31 +++++++ 2 files changed, 75 insertions(+), 42 deletions(-) create mode 100644 test/CoinbaseSmartWallet/UpgradeToAndCall.t.sol diff --git a/.gas-snapshot b/.gas-snapshot index 224c255..9ae8948 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -1,50 +1,52 @@ -AddOwnerAddressTest:testEmitsAddOwner() (gas: 92330) -AddOwnerAddressTest:testIncreasesOwnerIndex() (gas: 90548) -AddOwnerAddressTest:testRevertsIfAlreadyOwner() (gas: 93093) -AddOwnerAddressTest:testRevertsIfCalledByNonOwner() (gas: 11732) -AddOwnerAddressTest:testSetsIsOwner() (gas: 90432) -AddOwnerAddressTest:testSetsOwnerAtIndex() (gas: 98831) -AddOwnerPublicKeyTest:testEmitsAddOwner() (gas: 115377) -AddOwnerPublicKeyTest:testRevertsIfAlreadyOwner() (gas: 116169) -AddOwnerPublicKeyTest:testRevertsIfCalledByNonOwner() (gas: 11656) -AddOwnerPublicKeyTest:testSetsIsOwner() (gas: 113698) -AddOwnerPublicKeyTest:testSetsOwnerAtIndex() (gas: 128444) -CoinbaseSmartWallet1271InputGeneratorTest:testGetReplaySafeHashForDeployedAccount() (gas: 308642) -CoinbaseSmartWallet1271InputGeneratorTest:testGetReplaySafeHashForUndeployedAccount() (gas: 291413) -CoinbaseSmartWalletFactoryTest:testDeployDeterministicPassValues() (gas: 267720) -CoinbaseSmartWalletFactoryTest:test_CreateAccount_ReturnsPredeterminedAddress_WhenAccountAlreadyExists() (gas: 287384) -CoinbaseSmartWalletFactoryTest:test_createAccountDeploysToPredeterminedAddress() (gas: 269071) -CoinbaseSmartWalletFactoryTest:test_createAccountSetsOwnersCorrectly() (gas: 277937) +AddOwnerAddressTest:testEmitsAddOwner() (gas: 92374) +AddOwnerAddressTest:testIncreasesOwnerIndex() (gas: 90614) +AddOwnerAddressTest:testRevertsIfAlreadyOwner() (gas: 93137) +AddOwnerAddressTest:testRevertsIfCalledByNonOwner() (gas: 11754) +AddOwnerAddressTest:testSetsIsOwner() (gas: 90476) +AddOwnerAddressTest:testSetsOwnerAtIndex() (gas: 98897) +AddOwnerPublicKeyTest:testEmitsAddOwner() (gas: 115509) +AddOwnerPublicKeyTest:testFuzzIsOwnerPublicKey(bytes32,bytes32) (runs: 256, μ: 115333, ~: 115333) +AddOwnerPublicKeyTest:testRevertsIfAlreadyOwner() (gas: 116301) +AddOwnerPublicKeyTest:testRevertsIfCalledByNonOwner() (gas: 11744) +AddOwnerPublicKeyTest:testSetsIsOwner() (gas: 113775) +AddOwnerPublicKeyTest:testSetsOwnerAtIndex() (gas: 128543) +CoinbaseSmartWallet1271InputGeneratorTest:testGetReplaySafeHashForDeployedAccount() (gas: 308664) +CoinbaseSmartWallet1271InputGeneratorTest:testGetReplaySafeHashForUndeployedAccount() (gas: 291435) +CoinbaseSmartWalletFactoryTest:testDeployDeterministicPassValues() (gas: 267742) +CoinbaseSmartWalletFactoryTest:test_CreateAccount_ReturnsPredeterminedAddress_WhenAccountAlreadyExists() (gas: 287406) +CoinbaseSmartWalletFactoryTest:test_createAccountDeploysToPredeterminedAddress() (gas: 269093) +CoinbaseSmartWalletFactoryTest:test_createAccountSetsOwnersCorrectly() (gas: 277981) CoinbaseSmartWalletFactoryTest:test_revertsIfNoOwners() (gas: 29214) -ERC1271Test:test_returnsExpectedDomainHashWhenProxy() (gas: 15384) -MultiOwnableInitializeTest:testRevertsIfLength32ButLargerThanAddress() (gas: 78994) -MultiOwnableInitializeTest:testRevertsIfLength32NotAddress() (gas: 78975) -MultiOwnableInitializeTest:testRevertsIfLengthNot32Or64() (gas: 101278) -RemoveOwnerAtIndexTest:testEmitsRemoveOwner() (gas: 33281) -RemoveOwnerAtIndexTest:testRemovesOwner() (gas: 32647) -RemoveOwnerAtIndexTest:testRemovesOwnerAtIndex() (gas: 27532) -RemoveOwnerAtIndexTest:testRevertsIfCalledByNonOwner() (gas: 11310) -RemoveOwnerAtIndexTest:testRevertsIfNoOwnerAtIndex() (gas: 16626) -TestCanSkipChainIdValidation:test_approvedSelectorsReturnTrue() (gas: 15889) -TestCanSkipChainIdValidation:test_otherSelectorsReturnFalse() (gas: 12491) -TestExecuteWithoutChainIdValidation:testExecute() (gas: 424683) -TestExecuteWithoutChainIdValidation:testExecuteBatch() (gas: 729020) -TestExecuteWithoutChainIdValidation:testExecuteBatch(uint256) (runs: 256, μ: 3376320, ~: 3249240) -TestExecuteWithoutChainIdValidation:test__codesize() (gas: 48858) -TestExecuteWithoutChainIdValidation:test__codesize() (gas: 49093) +ERC1271Test:test_returnsExpectedDomainHashWhenProxy() (gas: 15406) +MultiOwnableInitializeTest:testRevertsIfLength32ButLargerThanAddress() (gas: 78927) +MultiOwnableInitializeTest:testRevertsIfLength32NotAddress() (gas: 78908) +MultiOwnableInitializeTest:testRevertsIfLengthNot32Or64() (gas: 101211) +RemoveOwnerAtIndexTest:testEmitsRemoveOwner() (gas: 33299) +RemoveOwnerAtIndexTest:testRemovesOwner() (gas: 32682) +RemoveOwnerAtIndexTest:testRemovesOwnerAtIndex() (gas: 27567) +RemoveOwnerAtIndexTest:testRevertsIfCalledByNonOwner() (gas: 11332) +RemoveOwnerAtIndexTest:testRevertsIfNoOwnerAtIndex() (gas: 16648) +TestCanSkipChainIdValidation:test_approvedSelectorsReturnTrue() (gas: 15845) +TestCanSkipChainIdValidation:test_otherSelectorsReturnFalse() (gas: 12469) +TestExecuteWithoutChainIdValidation:testExecute() (gas: 424705) +TestExecuteWithoutChainIdValidation:testExecuteBatch() (gas: 729086) +TestExecuteWithoutChainIdValidation:testExecuteBatch(uint256) (runs: 256, μ: 3409748, ~: 3278930) +TestExecuteWithoutChainIdValidation:test__codesize() (gas: 49006) +TestExecuteWithoutChainIdValidation:test__codesize() (gas: 49241) TestExecuteWithoutChainIdValidation:test_canChangeOwnerWithoutChainId() (gas: 287917) TestExecuteWithoutChainIdValidation:test_cannotCallExec() (gas: 220047) TestExecuteWithoutChainIdValidation:test_revertsIfCallerNotEntryPoint() (gas: 8620) TestExecuteWithoutChainIdValidation:test_revertsIfWrongNonceKey() (gas: 62275) TestExecuteWithoutChainIdValidation:test_revertsWithReservedNonce() (gas: 82302) TestInitialize:testInitialize() (gas: 21122) -TestInitialize:test_cannotInitImplementation() (gas: 2678562) -TestIsValidSignature:testReturnsInvalidIfPasskeySigButWrongOwnerLength() (gas: 39464) -TestIsValidSignature:testRevertsIfEthereumSignatureButWrongOwnerLength() (gas: 24046) -TestIsValidSignature:testSmartWalletSigner() (gas: 2951388) -TestIsValidSignature:testValidateSignatureWithEOASigner() (gas: 24917) -TestIsValidSignature:testValidateSignatureWithEOASignerFailsWithWrongSigner() (gas: 23847) -TestIsValidSignature:testValidateSignatureWithPasskeySigner() (gas: 421251) -TestIsValidSignature:testValidateSignatureWithPasskeySignerFailsBadOwnerIndex() (gas: 34964) -TestIsValidSignature:testValidateSignatureWithPasskeySignerFailsWithWrongBadSignature() (gas: 428717) +TestInitialize:test_cannotInitImplementation() (gas: 2708253) +TestIsValidSignature:testReturnsInvalidIfPasskeySigButWrongOwnerLength() (gas: 39497) +TestIsValidSignature:testRevertsIfEthereumSignatureButWrongOwnerLength() (gas: 24068) +TestIsValidSignature:testSmartWalletSigner() (gas: 2981137) +TestIsValidSignature:testValidateSignatureWithEOASigner() (gas: 24950) +TestIsValidSignature:testValidateSignatureWithEOASignerFailsWithWrongSigner() (gas: 23880) +TestIsValidSignature:testValidateSignatureWithPasskeySigner() (gas: 421284) +TestIsValidSignature:testValidateSignatureWithPasskeySignerFailsBadOwnerIndex() (gas: 34986) +TestIsValidSignature:testValidateSignatureWithPasskeySignerFailsWithWrongBadSignature() (gas: 428750) +TestUpgradeToAndCall:testUpgradeToAndCall() (gas: 23839) TestValidateUserOp:testValidateUserOp() (gas: 447113) \ No newline at end of file diff --git a/test/CoinbaseSmartWallet/UpgradeToAndCall.t.sol b/test/CoinbaseSmartWallet/UpgradeToAndCall.t.sol new file mode 100644 index 0000000..47b9ea7 --- /dev/null +++ b/test/CoinbaseSmartWallet/UpgradeToAndCall.t.sol @@ -0,0 +1,31 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +import {CoinbaseSmartWalletFactory} from "../../src/CoinbaseSmartWalletFactory.sol"; + +import "./SmartWalletTestBase.sol"; + +contract TestUpgradeToAndCall is SmartWalletTestBase { + address newImplementation = address(new Dummy()); + + function setUp() public override { + super.setUp(); + CoinbaseSmartWalletFactory factory = new CoinbaseSmartWalletFactory(address(new CoinbaseSmartWallet())); + account = factory.createAccount(owners, 1); + vm.startPrank(signer); + } + + function testUpgradeToAndCall() public { + account.upgradeToAndCall(newImplementation, abi.encodeWithSignature("dummy()")); + } +} + +contract Dummy is UUPSUpgradeable { + event Done(); + + function dummy() public { + emit Done(); + } + + function _authorizeUpgrade(address newImplementation) internal override {} +}