Skip to content

Commit

Permalink
Merge pull request #5 from Hats-Protocol/chaining-compatibility
Browse files Browse the repository at this point in the history
Chaining compatibility
  • Loading branch information
spengrah authored Sep 10, 2024
2 parents 93ea1c2 + da27c8a commit a7553f2
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 19 deletions.
4 changes: 3 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std

[submodule "lib/hats-module"]
path = lib/hats-module
url = https://github.com/hats-protocol/hats-module
[submodule "lib/hats-protocol"]
path = lib/hats-protocol
url = https://github.com/hats-protocol/hats-protocol
1 change: 1 addition & 0 deletions lib/hats-protocol
Submodule hats-protocol added at cccb71
10 changes: 6 additions & 4 deletions src/AllowlistEligibility.sol
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,9 @@ contract AllowlistEligibility is HatsEligibilityModule {

emit AccountRemoved(_account);

// burn the hat by setting their eligibility to with the account's current standing
HATS().setHatWearerStatus(hatId(), _account, false, !eligibility.badStanding);
// Check their eligibility and burn the hat if they are not eligible. We use this pull pattern instead of the push
// pattern — i.e. setHatWearerStatus — for compatibility with chained modules.
HATS().checkHatWearerStatus(hatId(), _account);

/**
* @dev Hats.sol will emit the following events:
Expand Down Expand Up @@ -287,8 +288,9 @@ contract AllowlistEligibility is HatsEligibilityModule {

emit AccountStandingChanged(_account, false);

// burn the account's hat by setting their eligibility and standing to false
HATS().setHatWearerStatus(hatId(), _account, false, false);
// have Hats.sol check the account's hat wearer status to burn their hat. We use this pull pattern instead of the
// push pattern — i.e. setHatWearerStatus — for compatibility with chained modules.
HATS().checkHatWearerStatus(hatId(), _account);

/**
* @dev Hats.sol will emit the following events:
Expand Down
22 changes: 10 additions & 12 deletions test/AllowlistEligibility.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ contract AllowlistEligibilityTest is Deploy, Test {
// bytes32 public SALT;

uint256 public fork;
uint256 public BLOCK_NUMBER = 17_671_864; // deployment block for Hats.sol
uint256 public BLOCK_NUMBER = 19_467_227; // deployment block for HatsModuleFactory
IHats public HATS = IHats(0x3bc1A0Ad72417f2d411118085256fC53CBdDd137); // v1.hatsprotocol.eth
HatsModuleFactory public factory;
HatsModuleFactory public factory = HatsModuleFactory(0x0a3f85fa597B6a967271286aA0724811acDF5CD9);
uint256 public SALT_NONCE = 1;
AllowlistEligibility public instance;
bytes public otherImmutableArgs;
bytes public initArgs;
Expand Down Expand Up @@ -73,9 +74,6 @@ contract AllowlistEligibilityTest is Deploy, Test {
// deploy implementation via the script
prepare(false, MODULE_VERSION);
run();

// deploy the hats module factory
factory = deployModuleFactory(HATS, SALT, "test factory");
}
}

Expand All @@ -101,7 +99,7 @@ contract WithInstanceTest is AllowlistEligibilityTest {

// deploy an instance of the module
instance = AllowlistEligibility(
deployModuleInstance(factory, address(implementation), hatToClaim, otherImmutableArgs, initArgs)
deployModuleInstance(factory, address(implementation), hatToClaim, otherImmutableArgs, initArgs, SALT_NONCE)
);

// set the instance as the hatToClaim's eligibility
Expand Down Expand Up @@ -139,27 +137,27 @@ contract Deployment is WithInstanceTest {
instance.setUp(abi.encode(ownerHat, arbitratorHat, alloweds));
}

function test_version() public {
function test_version() public view {
assertEq(instance.version(), MODULE_VERSION);
}

function test_implementation() public {
function test_implementation() public view {
assertEq(address(instance.IMPLEMENTATION()), address(implementation));
}

function test_hats() public {
function test_hats() public view {
assertEq(address(instance.HATS()), address(HATS));
}

function test_hatId() public {
function test_hatId() public view {
assertEq(instance.hatId(), hatToClaim);
}

function test_ownerHat() public {
function test_ownerHat() public view {
assertEq(instance.ownerHat(), ownerHat);
}

function test_arbitratorHat() public {
function test_arbitratorHat() public view {
assertEq(instance.arbitratorHat(), arbitratorHat);
}
}
Expand Down

0 comments on commit a7553f2

Please sign in to comment.