From 629c25f58c707d2bbfb1783b9407e3d08b7c2eea Mon Sep 17 00:00:00 2001 From: zeroknots Date: Wed, 21 Feb 2024 14:05:16 +0700 Subject: [PATCH] found bug: external attester --- test/SchemaValidation.t.sol | 2 -- test/TrustDelegation.t.sol | 12 +++++++++-- test/TrustDelegationExternal.t.sol | 34 ++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 test/TrustDelegationExternal.t.sol diff --git a/test/SchemaValidation.t.sol b/test/SchemaValidation.t.sol index ce96eff6..85f3e3e0 100644 --- a/test/SchemaValidation.t.sol +++ b/test/SchemaValidation.t.sol @@ -16,7 +16,6 @@ contract SchemaValidationTest is BaseTest { uid1 = registry.registerSchema(schema, IExternalSchemaValidator(address(schemaValidatorFalse))); assertTrue(uid != uid1); - } function test_WhenSchemaNew() external whenRegisteringNewSchema { @@ -27,7 +26,6 @@ contract SchemaValidationTest is BaseTest { assertTrue(uid != SchemaUID.wrap(bytes32(0))); - SchemaRecord memory record = registry.findSchema(uid); assertEq(record.registeredAt, block.timestamp); assertEq(keccak256(abi.encodePacked(record.schema)), keccak256(abi.encodePacked(schema))); diff --git a/test/TrustDelegation.t.sol b/test/TrustDelegation.t.sol index 6db7c1ca..83a8d03e 100644 --- a/test/TrustDelegation.t.sol +++ b/test/TrustDelegation.t.sol @@ -27,15 +27,23 @@ contract TrustTest is AttestationTest { assertEq(result[0], address(attester1.addr)); } - function test_WhenSupplyingManyAttesters(address[] memory attesters) external whenSettingAttester prankWithAccount(smartAccount1) { + function test_WhenSupplyingManyAttesters( + uint8 threshold, + address[] memory attesters + ) + external + whenSettingAttester + prankWithAccount(smartAccount1) + { vm.assume(attesters.length < 100); vm.assume(attesters.length > 0); + vm.assume(threshold <= attesters.length + 4); for (uint256 i; i < attesters.length; i++) { vm.assume(attesters[i] != address(0)); } attesters.sort(); attesters.uniquifySorted(); - registry.trustAttesters(uint8(attesters.length), attesters); + registry.trustAttesters(threshold, attesters); // It should set. // It should emit event. address[] memory result = registry.findTrustedAttesters(smartAccount1.addr); diff --git a/test/TrustDelegationExternal.t.sol b/test/TrustDelegationExternal.t.sol new file mode 100644 index 00000000..e3cda8e6 --- /dev/null +++ b/test/TrustDelegationExternal.t.sol @@ -0,0 +1,34 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.0; + +import "./Attestation.t.sol"; +import "src/DataTypes.sol"; +import { LibSort } from "solady/utils/LibSort.sol"; + +contract TrustTestExternal is AttestationTest { + using LibSort for address[]; + + function setUp() public override { + super.setUp(); + // test_WhenAttestingWithNoAttestationData(address(module1)); + } + + modifier whenSettingAttester() { + _; + } + + function test_WhenSupplyingExternal() external whenSettingAttester { + // It should set. + test_WhenUsingValidECDSA(); + address[] memory trustedAttesters = new address[](2); + trustedAttesters[0] = address(attester1.addr); + trustedAttesters[1] = address(attester2.addr); + + registry.check(address(module1), ModuleType.wrap(1), attester1.addr); + registry.check(address(module1), ModuleType.wrap(2), attester1.addr); + vm.expectRevert(); + registry.check(address(module1), ModuleType.wrap(3), attester1.addr); + registry.checkN(address(module1), trustedAttesters, 1); + + } +}