diff --git a/.gas-snapshot b/.gas-snapshot index a3546a744..cbdc2aaac 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -1,118 +1,119 @@ -DeveloperDeployTest:testUp() (gas: 24279) -ETHPriceIsRightTest:testAnyoneCanChangeGuessBeforeEnd() (gas: 131807) -ETHPriceIsRightTest:testAnyoneCanEnterGuessBeforeEnd() (gas: 127341) -ETHPriceIsRightTest:testFailCannotEnterGuessAfterTime() (gas: 11629) +DeveloperDeployTest:testUp() (gas: 24235) +ETHPriceIsRightTest:testAnyoneCanChangeGuessBeforeEnd() (gas: 131829) +ETHPriceIsRightTest:testAnyoneCanEnterGuessBeforeEnd() (gas: 127363) ETHPriceIsRightTest:testGuessCalculations() (gas: 156151) ETHPriceIsRightTest:testUp() (gas: 16852) +ETHPriceIsRightTest:test_RevertWhen_CannotEnterGuessAfterTime() (gas: 9491) EngenCreditsTest:testCanBurnAfterSettingFlag() (gas: 70853) EngenCreditsTest:testCanTransferAfterSettingFlag() (gas: 100027) -EngenCreditsTest:testFailOthersCannotUpgrade() (gas: 2102028) -EngenCreditsTest:testNobodyCanBurn() (gas: 70679) +EngenCreditsTest:testNobodyCanBurn() (gas: 70724) EngenCreditsTest:testNobodyCanTransfer() (gas: 71888) -EngenCreditsTest:testOthersCannotMint() (gas: 25978) -EngenCreditsTest:testOwnerCanMint() (gas: 68218) -EngenCreditsTest:testOwnerCanUpgradeEngen() (gas: 2133223) -EngenCreditsTest:testUp() (gas: 22908) -EngenCreditsTest:testWalletCanGetPoints() (gas: 631586) -EngenCreditsTest:testWalletCanGetPointsWithOverride() (gas: 657489) -EngenCreditsTest:testWalletCannotGetPointsTwice() (gas: 718288) -FaucetTest:testClaim() (gas: 81023) -FaucetTest:testClaimOnBehalf() (gas: 115966) -FaucetTest:testFailIfClaimedTwice() (gas: 77198) -FaucetTest:testFailOwnerCannotStartWithoutAmount() (gas: 19407) -FaucetTest:testFailStartFaucetByOthers() (gas: 16870) -FaucetTest:testOwnerCanStartFaucet() (gas: 42651) +EngenCreditsTest:testOthersCannotMint() (gas: 26022) +EngenCreditsTest:testOwnerCanMint() (gas: 68239) +EngenCreditsTest:testOwnerCanUpgradeEngen() (gas: 2133256) +EngenCreditsTest:testUp() (gas: 22842) +EngenCreditsTest:testWalletCanGetPoints() (gas: 631644) +EngenCreditsTest:testWalletCanGetPointsWithOverride() (gas: 657503) +EngenCreditsTest:testWalletCannotGetPointsTwice() (gas: 718420) +EngenCreditsTest:test_RevertWhen_OthersCannotUpgrade() (gas: 2099976) +FaucetTest:testClaim() (gas: 81001) +FaucetTest:testClaimOnBehalf() (gas: 115944) +FaucetTest:testClaim_RevertWhen_ClaimedTwice() (gas: 77600) +FaucetTest:testOwnerCanStartFaucet() (gas: 42718) +FaucetTest:testStart_RevertWhen_CallerIsNotOwner(address) (runs: 256, μ: 19494, ~: 19494) +FaucetTest:testStart_RevertWhen_OwnerCannotStartWithoutAmount(uint256) (runs: 256, μ: 20425, ~: 21054) FaucetTest:testUp() (gas: 6294) -KYCViewerTest:testFailOthersCannotUpgradeFactory() (gas: 1029248) -KYCViewerTest:testIsKYCBothOwnerAndWallet() (gas: 82707) -KYCViewerTest:testOwnerCanUpgradeViewer() (gas: 1065414) -KYCViewerTest:testUp() (gas: 40633) -KintoEntryPointTest:testCannotResetWalletFactoryAddress() (gas: 13610) -KintoEntryPointTest:testUp() (gas: 9940) -KintoIDTest:testAuthorizedCanUpgrade() (gas: 3932582) -KintoIDTest:testBurnFailsWithoutMinting() (gas: 26911) -KintoIDTest:testBurnKYC() (gas: 250194) -KintoIDTest:testBurningTwiceFails() (gas: 254209) -KintoIDTest:testDappSignature() (gas: 166) -KintoIDTest:testFailOnlyProviderCanMonitor() (gas: 48382) -KintoIDTest:testFailOthersCannotUpgrade() (gas: 3885070) -KintoIDTest:testFailProviderCanAddTraitUnknownUser() (gas: 22719) -KintoIDTest:testFailTransfersAreDisabled() (gas: 297354) -KintoIDTest:testFailUserCannotAddSanction() (gas: 47795) -KintoIDTest:testFailUserCannotAddTrait() (gas: 47797) -KintoIDTest:testFailUserCannotRemoveSanction() (gas: 22608) -KintoIDTest:testFailUserCannotRemoveTrait() (gas: 326993) -KintoIDTest:testIsSanctionsMonitored() (gas: 28227) -KintoIDTest:testMintCompanyKYC() (gas: 284477) -KintoIDTest:testMintIndividualKYC() (gas: 282508) -KintoIDTest:testMintIndividualKYCWithExpiredSignature() (gas: 47491) -KintoIDTest:testMintIndividualKYCWithInvalidNonce() (gas: 291771) -KintoIDTest:testMintIndividualKYCWithInvalidSender() (gas: 48206) -KintoIDTest:testMintIndividualKYCWithInvalidSigner() (gas: 60535) +KYCViewerTest:testIsKYCBothOwnerAndWallet() (gas: 82686) +KYCViewerTest:testOwnerCanUpgradeViewer() (gas: 1065415) +KYCViewerTest:testUp() (gas: 40612) +KYCViewerTest:test_RevertWhen_OthersCannotUpgradeFactory() (gas: 1032200) +KintoEntryPointTest:testCannotResetWalletFactoryAddress() (gas: 13544) +KintoEntryPointTest:testUp() (gas: 9919) +KintoIDTest:testAddSanction_RevertWhen_CallerIsNotKYCProvider() (gas: 357740) +KintoIDTest:testAddTrait_RevertWhen_CallerIsNotProvider() (gas: 333008) +KintoIDTest:testAddTrait_RevertWhen_UserIsNotKYCd() (gas: 24904) +KintoIDTest:testAddTrait_WhenCallerIsProvider() (gas: 298557) +KintoIDTest:testAuthorizedCanUpgrade() (gas: 3932078) +KintoIDTest:testBurnFailsWithoutMinting() (gas: 26917) +KintoIDTest:testBurnKYC() (gas: 250288) +KintoIDTest:testBurningTwiceFails() (gas: 254300) +KintoIDTest:testDappSignature() (gas: 254) +KintoIDTest:testIsSanctionsMonitored() (gas: 28294) +KintoIDTest:testMintCompanyKYC() (gas: 284554) +KintoIDTest:testMintIndividualKYC() (gas: 282533) +KintoIDTest:testMintIndividualKYCWithExpiredSignature() (gas: 47547) +KintoIDTest:testMintIndividualKYCWithInvalidNonce() (gas: 291762) +KintoIDTest:testMintIndividualKYCWithInvalidSender() (gas: 48212) +KintoIDTest:testMintIndividualKYCWithInvalidSigner() (gas: 60569) KintoIDTest:testMonitorNoChanges() (gas: 24089) -KintoIDTest:testOnlyProviderCanBurnKYC() (gas: 303449) -KintoIDTest:testOwnerCanUpgrade() (gas: 3893769) -KintoIDTest:testProviderCanAddSanction() (gas: 323296) -KintoIDTest:testProviderCanAddTrait() (gas: 291380) -KintoIDTest:testProviderCanRemoveSancion() (gas: 311233) -KintoIDTest:testProviderCanRemoveTrait() (gas: 282942) -KintoIDTest:testSettingTraitsAndSanctions() (gas: 317512) -KintoIDTest:testUp() (gas: 17956) -KintoWalletFactoryTest:testAllWalletsUpgrade() (gas: 3517833) +KintoIDTest:testOnlyProviderCanBurnKYC() (gas: 303490) +KintoIDTest:testOwnerCanUpgrade() (gas: 3893836) +KintoIDTest:testProviderCanAddSanction() (gas: 323413) +KintoIDTest:testProviderCanRemoveSancion() (gas: 311283) +KintoIDTest:testRemoveSanction_RevertWhen_CallerIsNotKYCProvider() (gas: 367323) +KintoIDTest:testRemoveTrait_RevertWhen_CallerIsNotProvider() (gas: 357743) +KintoIDTest:testRemoveTrait_WhenCallerIsProvider() (gas: 282949) +KintoIDTest:testSettingTraitsAndSanctions() (gas: 317349) +KintoIDTest:testUp() (gas: 18217) +KintoIDTest:test_RevertWhen_OnlyProviderCanMonitor(address) (runs: 256, μ: 79525, ~: 79525) +KintoIDTest:test_RevertWhen_OthersCannotUpgrade() (gas: 3918129) +KintoIDTest:test_RevertWhen_TransfersAreDisabled() (gas: 275471) +KintoWalletFactoryTest:testAllWalletsUpgrade() (gas: 3519255) KintoWalletFactoryTest:testDeployCustomContract() (gas: 136473) -KintoWalletFactoryTest:testFailCreateWalletThroughDeploy() (gas: 51285) -KintoWalletFactoryTest:testFailOthersCannotUpgradeFactory() (gas: 2636897) -KintoWalletFactoryTest:testFailOthersCannotUpgradeWallets() (gas: 3498853) -KintoWalletFactoryTest:testOwnerCanUpgradeFactory() (gas: 2673030) -KintoWalletFactoryTest:testRandomSignerCannotFundWallet() (gas: 77154) -KintoWalletFactoryTest:testSignerCanFundWallet() (gas: 71109) +KintoWalletFactoryTest:testDeploy_RevertWhen_CreateWalletThroughDeploy() (gas: 53069) +KintoWalletFactoryTest:testOwnerCanUpgradeFactory() (gas: 2714743) +KintoWalletFactoryTest:testRandomSignerCannotFundWallet() (gas: 77132) +KintoWalletFactoryTest:testSignerCanFundWallet() (gas: 71132) KintoWalletFactoryTest:testSignerCannotFundInvalidWallet() (gas: 25030) -KintoWalletFactoryTest:testSignerCannotFundWalletWithoutEth() (gas: 18216) -KintoWalletFactoryTest:testUp() (gas: 20247) -KintoWalletFactoryTest:testWhitelistedSignerCanFundWallet() (gas: 463743) -KintoWalletTest:testAddingOneFunder() (gas: 393298) -KintoWalletTest:testAddingOneSigner() (gas: 404205) -KintoWalletTest:testApproveAndRevokeTokens() (gas: 580610) -KintoWalletTest:testApproveTokens() (gas: 530958) -KintoWalletTest:testChangingPolicyWithThreeSigners() (gas: 442028) -KintoWalletTest:testChangingPolicyWithTwoSigners() (gas: 413114) -KintoWalletTest:testFailApproveTokensWithoutWhitelist() (gas: 157159) -KintoWalletTest:testFailCallingApproveDirectly() (gas: 625818) -KintoWalletTest:testFailChangingPolicyWithoutRightSigners() (gas: 174419) -KintoWalletTest:testFailDirectCall() (gas: 65568) -KintoWalletTest:testFailMultipleTransactionsExecuteBatchPaymasterRefuses() (gas: 363188) -KintoWalletTest:testFailMultisigTransaction() (gas: 605529) -KintoWalletTest:testFailMultisigTransactionWhen2OutOf3Signers() (gas: 620528) -KintoWalletTest:testFailOthersCannotUpgrade() (gas: 3151175) -KintoWalletTest:testFailOwnerCannotUpgrade() (gas: 3467167) -KintoWalletTest:testFailRecoverNotEnoughTime() (gas: 430100) -KintoWalletTest:testFailRecoverNotRecoverer() (gas: 79216) -KintoWalletTest:testFailRecoverWithoutBurningOldOwner() (gas: 368060) -KintoWalletTest:testFailRecoverWithoutMintingNewOwner() (gas: 218345) -KintoWalletTest:testFailSendingTransactionDirectly() (gas: 184911) -KintoWalletTest:testFailSettingAppKeyNoWhitelist() (gas: 389794) -KintoWalletTest:testFailTransactionViaPaymasterNoapproval() (gas: 457146) -KintoWalletTest:testFailWithDuplicateSigner() (gas: 379042) -KintoWalletTest:testFailWithEmptyArray() (gas: 383567) -KintoWalletTest:testFailWithManyOwners() (gas: 379274) -KintoWalletTest:testFailWithoutKYCSigner() (gas: 377318) -KintoWalletTest:testMultipleTransactionsExecuteBatchPaymaster() (gas: 534232) -KintoWalletTest:testMultipleTransactionsViaPaymaster() (gas: 756771) -KintoWalletTest:testMultisigTransaction() (gas: 859779) -KintoWalletTest:testMultisigTransactionWith1SignerButSeveralOwners() (gas: 864858) -KintoWalletTest:testMultisigTransactionWith2SignersWithAppkey() (gas: 969063) -KintoWalletTest:testMultisigTransactionWith3Signers() (gas: 901623) -KintoWalletTest:testRecoverAccountSuccessfully() (gas: 402899) -KintoWalletTest:testSettingAppKey() (gas: 491395) -KintoWalletTest:testTransactionViaPaymaster() (gas: 694244) -KintoWalletTest:testUp() (gas: 32038) -KintoWalletTest:testWalletOwnersAreWhitelisted() (gas: 39988) -SponsorPaymasterExploitTest:testExploit() (gas: 283756) -SponsorPaymasterTest:testFailOthersCannotUpgrade() (gas: 2205926) -SponsorPaymasterTest:testFailUserCanDepositStakeAndWithdrawWithoutRoll() (gas: 129377) -SponsorPaymasterTest:testFailUserCanWithdrawAllInEmergency() (gas: 137198) +KintoWalletFactoryTest:testSignerCannotFundWalletWithoutEth() (gas: 18193) +KintoWalletFactoryTest:testUp() (gas: 20270) +KintoWalletFactoryTest:testUpgrade_RevertWhen_CallerIsNotOwner() (gas: 3503200) +KintoWalletFactoryTest:testWhitelistedSignerCanFundWallet() (gas: 463772) +KintoWalletFactoryTest:test_RevertWhen_OthersCannotUpgradeFactory() (gas: 2681448) +KintoWalletTest:testAddingOneFunder() (gas: 379158) +KintoWalletTest:testAddingOneSigner() (gas: 389998) +KintoWalletTest:testApproveAndRevokeTokens() (gas: 567019) +KintoWalletTest:testApproveTokens() (gas: 515732) +KintoWalletTest:testChangingPolicyWithThreeSigners() (gas: 427872) +KintoWalletTest:testChangingPolicyWithTwoSigners() (gas: 398939) +KintoWalletTest:testMultipleTransactionsExecuteBatchPaymaster() (gas: 538256) +KintoWalletTest:testMultipleTransactionsViaPaymaster() (gas: 761453) +KintoWalletTest:testMultisigTransaction() (gas: 883220) +KintoWalletTest:testMultisigTransactionWith1SignerButSeveralOwners() (gas: 699859) +KintoWalletTest:testMultisigTransactionWith2SignersWithAppkey() (gas: 985964) +KintoWalletTest:testMultisigTransactionWith3Signers() (gas: 950118) +KintoWalletTest:testRecoverAccountSuccessfully() (gas: 370091) +KintoWalletTest:testSettingAppKey() (gas: 476255) +KintoWalletTest:testTransactionViaPaymaster() (gas: 698678) +KintoWalletTest:testUp() (gas: 32015) +KintoWalletTest:testWalletOwnersAreWhitelisted() (gas: 39998) +KintoWalletTest:test_RevertWhen_ApproveTokensWithoutWhitelist() (gas: 377192) +KintoWalletTest:test_RevertWhen_CallingApproveDirectly() (gas: 626413) +KintoWalletTest:test_RevertWhen_ChangingPolicyWithoutRightSigners() (gas: 458635) +KintoWalletTest:test_RevertWhen_DirectCall() (gas: 26597) +KintoWalletTest:test_RevertWhen_DuplicateSigner() (gas: 370191) +KintoWalletTest:test_RevertWhen_MultipleTransactionsExecuteBatchPaymasterRefuses() (gas: 366748) +KintoWalletTest:test_RevertWhen_MultisigTransaction() (gas: 597041) +KintoWalletTest:test_RevertWhen_MultisigTransactionHas2OutOf3Signers() (gas: 657497) +KintoWalletTest:test_RevertWhen_OthersCannotUpgrade() (gas: 4036525) +KintoWalletTest:test_RevertWhen_OwnerCannotUpgrade() (gas: 3437273) +KintoWalletTest:test_RevertWhen_RecoverNotEnoughTime() (gas: 378590) +KintoWalletTest:test_RevertWhen_RecoverNotRecoverer(address) (runs: 256, μ: 36128, ~: 36128) +KintoWalletTest:test_RevertWhen_RecoverWithoutBurningOldOwner() (gas: 384498) +KintoWalletTest:test_RevertWhen_RecoverWithoutNewOwnerKYCd() (gas: 149996) +KintoWalletTest:test_RevertWhen_SendingTransactionDirectlyAndPrefund() (gas: 572032) +KintoWalletTest:test_RevertWhen_SendingTransactionDirectlyAndPrefundNotPaid() (gas: 189516) +KintoWalletTest:test_RevertWhen_SettingAppKeyNoWhitelist() (gas: 374960) +KintoWalletTest:test_RevertWhen_TransactionViaPaymasterAndNoApproval() (gas: 467286) +KintoWalletTest:test_RevertWhen_WithEmptyArray() (gas: 364203) +KintoWalletTest:test_RevertWhen_WithManyOwners() (gas: 370562) +KintoWalletTest:test_RevertWhen_WithoutKYCSigner() (gas: 360417) +SponsorPaymasterExploitTest:testExploit() (gas: 283737) SponsorPaymasterTest:testOwnerCanDepositStakeAndWithdraw() (gas: 95286) -SponsorPaymasterTest:testOwnerCanUpgrade() (gas: 2242110) -SponsorPaymasterTest:testOwnerCanWithdrawAllInEmergency() (gas: 123988) +SponsorPaymasterTest:testOwnerCanUpgrade() (gas: 2242121) +SponsorPaymasterTest:testOwnerCanWithdrawAllInEmergency() (gas: 123921) SponsorPaymasterTest:testUp() (gas: 10454) -SponsorPaymasterTest:testUserCanDepositStakeAndWithdraw() (gas: 108566) \ No newline at end of file +SponsorPaymasterTest:testUpgrade_RevertWhen_CallerIsNotOwner() (gas: 2208832) +SponsorPaymasterTest:testUserCanDepositStakeAndWithdraw() (gas: 108566) +SponsorPaymasterTest:test_RevertWhen_UserCanDepositStakeAndWithdrawWithoutRoll() (gas: 124420) +SponsorPaymasterTest:test_RevertWhen_UserCanWithdrawAllInEmergency() (gas: 130566) \ No newline at end of file diff --git a/src/wallet/KintoWallet.sol b/src/wallet/KintoWallet.sol index c2c8991ee..ced6dd4d5 100644 --- a/src/wallet/KintoWallet.sol +++ b/src/wallet/KintoWallet.sol @@ -121,7 +121,7 @@ contract KintoWallet is Initializable, BaseAccount, TokenCallbackHandler, IKinto /* ============ Signer Management ============ */ /** - * @dev Change the signer policy + * @dev Change signer policy * @param policy new policy */ function setSignerPolicy(uint8 policy) public override onlySelf { @@ -132,11 +132,11 @@ contract KintoWallet is Initializable, BaseAccount, TokenCallbackHandler, IKinto } /** - * @dev Changed the signers + * @dev Change signers and policy (if new) * @param newSigners new signers array */ function resetSigners(address[] calldata newSigners, uint8 policy) external override onlySelf { - require(newSigners[0] == owners[0], "KW-rs: first signer must same unless recovery"); + require(newSigners[0] == owners[0], "KW-rs: first signer must be the same unless recovery"); _resetSigners(newSigners, policy); } @@ -220,7 +220,7 @@ contract KintoWallet is Initializable, BaseAccount, TokenCallbackHandler, IKinto } /** - * @dev Allos the wallet to transact with a specific app + * @dev Allows the wallet to transact with a specific app * @param apps apps array * @param flags whether to allow or disallow the app */ diff --git a/test/ETHPriceIsRight.t.sol b/test/ETHPriceIsRight.t.sol index 4f1d3e9cc..5722b2a2d 100644 --- a/test/ETHPriceIsRight.t.sol +++ b/test/ETHPriceIsRight.t.sol @@ -63,10 +63,10 @@ contract ETHPriceIsRightTest is Test { assertEq(_priceIsRight.avgGuess(), 3000 ether); } - function testFailCannotEnterGuessAfterTime() public { - vm.startPrank(_user); + function test_RevertWhen_CannotEnterGuessAfterTime() public { vm.warp(_priceIsRight.END_ENTER_TIMESTAMP() + 1); + + vm.expectRevert("You cannot enter guesses anymore"); _priceIsRight.enterGuess(2000 ether); - vm.stopPrank(); } } diff --git a/test/KYCViewer.t.sol b/test/KYCViewer.t.sol index 331da575f..f9e48a861 100644 --- a/test/KYCViewer.t.sol +++ b/test/KYCViewer.t.sol @@ -84,10 +84,8 @@ contract KYCViewerTest is Create2Helper, UserOp, AATestScaffolding { function test_RevertWhen_OthersCannotUpgradeFactory() public { KYCViewerV2 _implementationV2 = new KYCViewerV2(address(_walletFactory)); + vm.expectRevert("only owner"); _kycViewer.upgradeTo(address(_implementationV2)); - // re-wrap the _proxy - _kycViewer2 = KYCViewerV2(address(_kycViewer)); - assertEq(_kycViewer2.newFunction(), 1); } /* ============ Viewer Tests ============ */ diff --git a/test/KintoWalletFactory.t.sol b/test/KintoWalletFactory.t.sol index 260a08c3a..29b767206 100644 --- a/test/KintoWalletFactory.t.sol +++ b/test/KintoWalletFactory.t.sol @@ -87,10 +87,8 @@ contract KintoWalletFactoryTest is Create2Helper, UserOp, AATestScaffolding { function test_RevertWhen_OthersCannotUpgradeFactory() public { KintoWalletFactoryV2 _implementationV2 = new KintoWalletFactoryV2(_kintoWalletImpl); + vm.expectRevert("Ownable: caller is not the owner"); _walletFactory.upgradeTo(address(_implementationV2)); - // re-wrap the _proxy - _walletFactoryv2 = KintoWalletFactoryV2(address(_proxy)); - assertEq(_walletFactoryv2.newFunction(), 1); } function testAllWalletsUpgrade() public { @@ -110,12 +108,15 @@ contract KintoWalletFactoryTest is Create2Helper, UserOp, AATestScaffolding { vm.stopPrank(); } - function test_RevertWhen_OthersCannotUpgradeWallets() public { - // Deploy wallet implementation + function testUpgrade_RevertWhen_CallerIsNotOwner() public { + // deploy wallet implementation _kintoWalletImpl = new KintoWalletV999(_entryPoint, _kintoIDv1); + // deploy walletv1 through wallet factory and initializes it _kintoWalletv1 = _walletFactory.createAccount(_owner, _owner, 0); - // Upgrade all implementations + + // upgrade all implementations + vm.expectRevert("Ownable: caller is not the owner"); _walletFactory.upgradeAllWalletImplementations(_kintoWalletImpl); } @@ -132,14 +133,14 @@ contract KintoWalletFactoryTest is Create2Helper, UserOp, AATestScaffolding { vm.stopPrank(); } - function test_RevertWhen_CreateWalletThroughDeploy() public { + function testDeploy_RevertWhen_CreateWalletThroughDeploy() public { vm.startPrank(_owner); - bytes memory a = abi.encodeWithSelector(KintoWallet.initialize.selector, _owner, _owner); - _walletFactory.deployContract( - 0, - abi.encodePacked(type(SafeBeaconProxy).creationCode, abi.encode(address(_walletFactory.beacon()), a)), - bytes32(0) + bytes memory initialize = abi.encodeWithSelector(KintoWallet.initialize.selector, _owner, _owner); + bytes memory bytecode = abi.encodePacked( + type(SafeBeaconProxy).creationCode, abi.encode(address(_walletFactory.beacon()), initialize) ); + vm.expectRevert("Direct KintoWallet deployment not allowed"); + _walletFactory.deployContract(0, bytecode, bytes32(0)); vm.stopPrank(); } diff --git a/test/SponsorPaymaster.t.sol b/test/SponsorPaymaster.t.sol index 67b1e4462..8b52a6cdc 100644 --- a/test/SponsorPaymaster.t.sol +++ b/test/SponsorPaymaster.t.sol @@ -74,12 +74,10 @@ contract SponsorPaymasterTest is KYCSignature { vm.stopPrank(); } - function testFailOthersCannotUpgrade() public { + function testUpgrade_RevertWhen_CallerIsNotOwner() public { SponsorPaymasterV2 _implementationV2 = new SponsorPaymasterV2(_entryPoint, _owner); + vm.expectRevert("SP: not owner"); _paymaster.upgradeTo(address(_implementationV2)); - // re-wrap the _proxy - _paymasterv2 = SponsorPaymasterV2(address(_proxy)); - assertEq(_paymasterv2.newFunction(), 1); } // Deposit & Stake @@ -108,37 +106,47 @@ contract SponsorPaymasterTest is KYCSignature { vm.stopPrank(); } - function testFailUserCanDepositStakeAndWithdrawWithoutRoll() public { - vm.startPrank(_user); - uint256 balance = address(_user).balance; - _paymaster.addDepositFor{value: 5e18}(address(_user)); - assertEq(address(_user).balance, balance - 5e18); + function test_RevertWhen_UserCanDepositStakeAndWithdrawWithoutRoll() public { + // user deposits 5 eth + uint256 balance = address(this).balance; + _paymaster.addDepositFor{value: 5e18}(address(this)); + assertEq(address(this).balance, balance - 5e18); + + // user unlocks token deposit _paymaster.unlockTokenDeposit(); - _paymaster.withdrawTokensTo(address(_user), 5e18); - assertEq(address(_user).balance, balance); - vm.stopPrank(); + + // user withdraws 5 eth + vm.expectRevert("SP: must unlockTokenDeposit"); + _paymaster.withdrawTokensTo(address(this), 5e18); + + assertEq(address(this).balance, balance - 5e18); } function testOwnerCanWithdrawAllInEmergency() public { - vm.startPrank(_user); + vm.prank(_user); _paymaster.addDepositFor{value: 5e18}(address(_user)); + vm.startPrank(_owner); + uint256 balance = address(_owner).balance; _paymaster.addDepositFor{value: 5e18}(address(_owner)); + _paymaster.withdrawTo(payable(_owner), address(_entryPoint).balance); assertEq(address(_paymaster).balance, 0); assertEq(address(_owner).balance, balance + 5e18); + vm.stopPrank(); } - function testFailUserCanWithdrawAllInEmergency() public { - vm.startPrank(_owner); + function test_RevertWhen_UserCanWithdrawAllInEmergency() public { + vm.prank(_owner); _paymaster.addDepositFor{value: 5e18}(address(_owner)); + + // user deposits 5 eth and then tries to withdraw all vm.startPrank(_user); - uint256 balance = address(_user).balance; _paymaster.addDepositFor{value: 5e18}(address(_user)); + vm.expectRevert("Ownable: caller is not the owner"); _paymaster.withdrawTo(payable(_user), address(_entryPoint).balance); - assertEq(address(_user).balance, balance + 5e18); vm.stopPrank(); } }