Skip to content

Commit

Permalink
✅ test: increase code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
cruzdanilo committed Jun 29, 2024
1 parent 654785c commit 8f6ac61
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 20 deletions.
39 changes: 21 additions & 18 deletions .gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,31 @@ MultiOwnerPluginIntegration:test_runtimeValidation_alwaysAllow_isValidSignature(
MultiOwnerPluginIntegration:test_runtimeValidation_ownerOrSelf_standardExecute() (gas: 145057)
MultiOwnerPluginIntegration:test_userOpValidation_owner_standardExecute() (gas: 347849)
MultiOwnerPluginTest:testFuzz_isValidSignature_ContractOwner(bytes32) (runs: 256, μ: 110118, ~: 110118)
MultiOwnerPluginTest:testFuzz_isValidSignature_ContractOwnerWithEOAOwner(bytes32) (runs: 256, μ: 120437, ~: 120437)
MultiOwnerPluginTest:testFuzz_isValidSignature_EOAOwner(string,bytes32) (runs: 256, μ: 130754, ~: 130747)
MultiOwnerPluginTest:testFuzz_isValidSignature_PasskeyOwner(bytes32) (runs: 256, μ: 365635, ~: 365718)
MultiOwnerPluginTest:testFuzz_userOpValidationFunction_ContractOwner((address,uint256,bytes,bytes,uint256,uint256,uint256,uint256,uint256,bytes,bytes)) (runs: 256, μ: 130892, ~: 130881)
MultiOwnerPluginTest:testFuzz_userOpValidationFunction_ContractOwnerWithEOAOwner((address,uint256,bytes,bytes,uint256,uint256,uint256,uint256,uint256,bytes,bytes)) (runs: 256, μ: 144491, ~: 144480)
MultiOwnerPluginTest:testFuzz_isValidSignature_ContractOwnerWithEOAOwner(bytes32) (runs: 256, μ: 120459, ~: 120459)
MultiOwnerPluginTest:testFuzz_isValidSignature_EOAOwner(string,bytes32) (runs: 256, μ: 130798, ~: 130791)
MultiOwnerPluginTest:testFuzz_isValidSignature_PasskeyOwner(bytes32) (runs: 256, μ: 365316, ~: 365517)
MultiOwnerPluginTest:testFuzz_userOpValidationFunction_ContractOwner((address,uint256,bytes,bytes,uint256,uint256,uint256,uint256,uint256,bytes,bytes)) (runs: 256, μ: 130914, ~: 130903)
MultiOwnerPluginTest:testFuzz_userOpValidationFunction_ContractOwnerWithEOAOwner((address,uint256,bytes,bytes,uint256,uint256,uint256,uint256,uint256,bytes,bytes)) (runs: 256, μ: 144513, ~: 144502)
MultiOwnerPluginTest:testFuzz_userOpValidationFunction_EOAOwner(string,(address,uint256,bytes,bytes,uint256,uint256,uint256,uint256,uint256,bytes,bytes)) (runs: 256, μ: 138767, ~: 138770)
MultiOwnerPluginTest:testFuzz_userOpValidationFunction_PasskeyOwner((address,uint256,bytes,bytes,uint256,uint256,uint256,uint256,uint256,bytes,bytes)) (runs: 256, μ: 373522, ~: 373350)
MultiOwnerPluginTest:test_eip712Domain() (gas: 35394)
MultiOwnerPluginTest:test_multiOwnerPlugin_sentinelIsNotOwner() (gas: 19794)
MultiOwnerPluginTest:test_onInstall_failWithInvalidAddress() (gas: 38434)
MultiOwnerPluginTest:test_onInstall_failWithLimitExceeded() (gas: 1714334)
MultiOwnerPluginTest:test_onInstall_success() (gas: 94764)
MultiOwnerPluginTest:testFuzz_userOpValidationFunction_PasskeyOwner((address,uint256,bytes,bytes,uint256,uint256,uint256,uint256,uint256,bytes,bytes)) (runs: 256, μ: 373450, ~: 373570)
MultiOwnerPluginTest:test_eip712Domain() (gas: 35438)
MultiOwnerPluginTest:test_isValidSignature_failWithOutOfBounds() (gas: 12285)
MultiOwnerPluginTest:test_multiOwnerPlugin_sentinelIsNotOwner() (gas: 19771)
MultiOwnerPluginTest:test_onInstall_failWithEmptyOwners() (gas: 36277)
MultiOwnerPluginTest:test_onInstall_failWithInvalidAddress() (gas: 38478)
MultiOwnerPluginTest:test_onInstall_failWithLimitExceeded() (gas: 1714289)
MultiOwnerPluginTest:test_onInstall_success() (gas: 94741)
MultiOwnerPluginTest:test_onUninstall_success() (gas: 84935)
MultiOwnerPluginTest:test_pluginInitializeGuards() (gas: 163889)
MultiOwnerPluginTest:test_pluginManifest() (gas: 38747)
MultiOwnerPluginTest:test_runtimeValidationFunction_OwnerOrSelf() (gas: 26747)
MultiOwnerPluginTest:test_updateOwnersPublicKeys_failWithInvalidAddress() (gas: 55749)
MultiOwnerPluginTest:test_updateOwners_failWithDuplicatedAddresses() (gas: 85472)
MultiOwnerPluginTest:test_updateOwners_failWithEmptyOwners() (gas: 70734)
MultiOwnerPluginTest:test_pluginInitializeGuards() (gas: 163911)
MultiOwnerPluginTest:test_pluginManifest() (gas: 38791)
MultiOwnerPluginTest:test_pluginMetadata_success() (gas: 16932)
MultiOwnerPluginTest:test_runtimeValidationFunction_OwnerOrSelf() (gas: 26703)
MultiOwnerPluginTest:test_updateOwnersPublicKeys_failWithInvalidAddress() (gas: 55707)
MultiOwnerPluginTest:test_updateOwners_failWithDuplicatedAddresses() (gas: 85494)
MultiOwnerPluginTest:test_updateOwners_failWithEmptyOwners() (gas: 70711)
MultiOwnerPluginTest:test_updateOwners_failWithLimitExceeded() (gas: 1924832)
MultiOwnerPluginTest:test_updateOwners_failWithNotExist() (gas: 58568)
MultiOwnerPluginTest:test_updateOwners_failWithZeroAddressOwner() (gas: 56362)
MultiOwnerPluginTest:test_updateOwners_failWithZeroAddressOwner() (gas: 56406)
MultiOwnerPluginTest:test_updateOwners_success() (gas: 119826)
WebauthnModularAccountFactoryTest:test_2StepOwnershipTransfer() (gas: 87560)
WebauthnModularAccountFactoryTest:test_addStake() (gas: 106151)
Expand Down
26 changes: 24 additions & 2 deletions test/WebauthnOwnerPlugin.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { BasePlugin } from "modular-account/src/plugins/BasePlugin.sol";
import { IMultiOwnerPlugin } from "modular-account/src/plugins/owner/IMultiOwnerPlugin.sol";
import { ContractOwner } from "modular-account/test/mocks/ContractOwner.sol";

import { PluginManifest } from "modular-account-libs/interfaces/IPlugin.sol";
import { PluginManifest, PluginMetadata } from "modular-account-libs/interfaces/IPlugin.sol";
import { UserOperation } from "modular-account-libs/interfaces/UserOperation.sol";

import { ECDSA } from "solady/utils/ECDSA.sol";
Expand All @@ -20,7 +20,7 @@ import { Utils, WebAuthnInfo } from "webauthn-sol/../test/Utils.sol";
import { WebAuthn } from "webauthn-sol/WebAuthn.sol";

import { DeployScript } from "../script/Deploy.s.sol";
import { OwnersLib } from "../src/OwnersLib.sol";
import { IndexOutOfBounds, OwnersLib } from "../src/OwnersLib.sol";
import { IWebauthnOwnerPlugin, MAX_OWNERS, PublicKey, WebauthnOwnerPlugin } from "../src/WebauthnOwnerPlugin.sol";

import { TestLib } from "./utils/TestLib.sol";
Expand Down Expand Up @@ -129,6 +129,13 @@ contract MultiOwnerPluginTest is Test {
vm.stopPrank();
}

function test_onInstall_failWithEmptyOwners() external {
vm.expectRevert(IMultiOwnerPlugin.EmptyOwnersNotAllowed.selector);
vm.startPrank(address(contractOwner));
plugin.onInstall(abi.encode(new PublicKey[](0)));
vm.stopPrank();
}

function test_onInstall_failWithLimitExceeded() external {
address[] memory owners = new address[](MAX_OWNERS + 1);
for (uint160 i = 0; i < owners.length; ++i) {
Expand Down Expand Up @@ -308,6 +315,11 @@ contract MultiOwnerPluginTest is Test {
assertEq(_1271_MAGIC_VALUE, plugin.isValidSignature(digest, signature));
}

function test_isValidSignature_failWithOutOfBounds() external {
vm.expectRevert(IndexOutOfBounds.selector);
plugin.isValidSignature("", abi.encodePacked(uint8(4), ""));
}

function test_runtimeValidationFunction_OwnerOrSelf() external {
// should pass with owner as sender
plugin.runtimeValidationFunction(
Expand Down Expand Up @@ -447,4 +459,14 @@ contract MultiOwnerPluginTest is Test {
vm.expectRevert(abi.encodeWithSelector(BasePlugin.AlreadyInitialized.selector));
plugin.onInstall(abi.encode(addrArr, new address[](0)));
}

function test_pluginMetadata_success() external view {
PluginMetadata memory metadata = plugin.pluginMetadata();

assertEq(metadata.permissionDescriptors.length, 2);
assertEq(metadata.permissionDescriptors[0].permissionDescription, "Modify Ownership");
assertEq(metadata.permissionDescriptors[1].permissionDescription, "Modify Ownership");
assertEq(metadata.permissionDescriptors[0].functionSelector, IMultiOwnerPlugin.updateOwners.selector);
assertEq(metadata.permissionDescriptors[1].functionSelector, IWebauthnOwnerPlugin.updateOwnersPublicKeys.selector);
}
}

0 comments on commit 8f6ac61

Please sign in to comment.