Skip to content

Commit

Permalink
fix: testing trust manager loop and threshold decrement
Browse files Browse the repository at this point in the history
  • Loading branch information
zeroknots committed Feb 21, 2024
1 parent 7ca7186 commit 12ce8f1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/core/TrustManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { ModuleTypeLib } from "../lib/ModuleTypeLib.sol";
import { TrustLib } from "../lib/TrustLib.sol";
import { LibSort } from "solady/utils/LibSort.sol";

import "forge-std/console2.sol";

Check failure on line 12 in src/core/TrustManager.sol

View workflow job for this annotation

GitHub Actions / lint / forge-lint

Unexpected import of console file

Check warning on line 12 in src/core/TrustManager.sol

View workflow job for this annotation

GitHub Actions / lint / forge-lint

global import of path forge-std/console2.sol is not allowed. Specify names to import individually or bind all exports of the module into a name (import "path" as Name)

Check failure on line 12 in src/core/TrustManager.sol

View workflow job for this annotation

GitHub Actions / lint / forge-lint

Unexpected import of console file

Check warning on line 12 in src/core/TrustManager.sol

View workflow job for this annotation

GitHub Actions / lint / forge-lint

global import of path forge-std/console2.sol is not allowed. Specify names to import individually or bind all exports of the module into a name (import "path" as Name)

/**
* @title TrustManager
* Allows smart accounts to query the registry for the security status of modules.
Expand Down Expand Up @@ -106,7 +108,7 @@ abstract contract TrustManager is IRegistry {
address attester = $trustedAttesters.attester;

// smart account has no trusted attesters set
if (attester == ZERO_ADDRESS || threshold != 0) {
if (attester == ZERO_ADDRESS || threshold == 0) {
revert NoTrustedAttestersFound();
}
// smart account only has ONE trusted attester
Expand All @@ -125,9 +127,11 @@ abstract contract TrustManager is IRegistry {
attester = $trustedAttesters.linkedAttesters[attester];
$attestation = $getAttestation({ module: module, attester: attester });
if ($attestation.checkValid(moduleType)) threshold--;
console2.log("threshold: ", threshold);

Check failure on line 130 in src/core/TrustManager.sol

View workflow job for this annotation

GitHub Actions / lint / forge-lint

Unexpected console statement

Check failure on line 130 in src/core/TrustManager.sol

View workflow job for this annotation

GitHub Actions / lint / forge-lint

Unexpected console statement
// if threshold reached, exit loop
if (threshold == 0) return;
}
if (threshold > 0) revert InsufficientAttestations();
}
}

Expand Down
21 changes: 21 additions & 0 deletions test/TrustDelegation.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,27 @@ contract TrustTest is AttestationTest {
}
}

function test_ManyAttesters() public {
_make_WhenUsingValidECDSA(attester1);
_make_WhenUsingValidECDSA(attester2);
Account memory attester3 = makeAccount("attester3");
Account memory attester4 = makeAccount("attester4");
address[] memory trustedAttesters = new address[](4);
trustedAttesters[0] = address(attester1.addr);
trustedAttesters[1] = address(attester3.addr);
trustedAttesters[2] = address(attester4.addr);
trustedAttesters[3] = address(attester2.addr);

vm.startPrank(smartAccount1.addr);
registry.trustAttesters(2, trustedAttesters);

registry.check(address(module1), ModuleType.wrap(1));
registry.check(address(module1), ModuleType.wrap(2));
registry.trustAttesters(3, trustedAttesters);
vm.expectRevert();
registry.check(address(module1), ModuleType.wrap(1));
}

function test_WhenSupplyingSameAttesterMultipleTimes() external whenSettingAttester {
address[] memory attesters = new address[](2);
attesters[0] = address(attester1.addr);
Expand Down
1 change: 0 additions & 1 deletion test/TrustDelegationExternal.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import "./Attestation.t.sol";
import "src/DataTypes.sol";
import { LibSort } from "solady/utils/LibSort.sol";


contract TrustTestExternal is AttestationTest {
using LibSort for address[];

Expand Down

0 comments on commit 12ce8f1

Please sign in to comment.