Skip to content

Commit

Permalink
refactor(contracts): adapt trait to check and pass internal-external …
Browse files Browse the repository at this point in the history
…behaviour
  • Loading branch information
0xjei committed Oct 3, 2024
1 parent 23e2578 commit 0c5b7eb
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
9 changes: 8 additions & 1 deletion packages/contracts/contracts/src/core/Excubia.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ abstract contract Excubia is IExcubia, Ownable(msg.sender) {
}

/// @inheritdoc IExcubia
function trait() external pure virtual returns (string memory) {}
function trait() external pure virtual returns (string memory) {
return _trait();
}

/// @inheritdoc IExcubia
function setGate(address _gate) public virtual onlyOwner {
Expand All @@ -44,6 +46,11 @@ abstract contract Excubia is IExcubia, Ownable(msg.sender) {
_check(passerby, data);
}

/// @notice Internal function to define the trait of the Excubia contract.
/// @dev maintain consistency across _pass & _check definitions.
/// @return The specific trait of the Excubia contract (e.g., SemaphoreExcubia has trait `Semaphore`).
function _trait() internal pure virtual returns (string memory) {}

/// @notice Internal function to enforce the custom gate passing logic.
/// @dev Calls the `_check` internal logic and emits the relative event if successful.
/// @param passerby The address of the entity attempting to pass the gate.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ contract FreeForAllExcubia is Excubia {
mapping(address => bool) public passedPassersby;

/// @notice The trait of the Excubia contract.
function trait() external pure override returns (string memory) {
function _trait() internal pure override returns (string memory) {
super._trait();

return "FreeForAll";
}

Expand Down
6 changes: 5 additions & 1 deletion packages/contracts/contracts/test/FreeForAllExcubia.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ contract FreeForAllExcubiaTest is Test {
vm.stopPrank();
}

function testInternalTrait() public view {
freeForAllExcubiaTW.exposed_trait();
}

function testInternalCheck() public view {
freeForAllExcubiaTW.exposed_check(passerby, "");
}
Expand Down Expand Up @@ -222,7 +226,7 @@ contract FreeForAllExcubiaTest is Test {

uint256 gasAfter = gasleft();
uint256 gasUsed = gasBefore - gasAfter;
assert(gasUsed < 30000);
assert(gasUsed < 70000);
}

function test_GatePassesSelf() public {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ pragma solidity ^0.8.27;
import {FreeForAllExcubia} from "../../src/extensions/FreeForAllExcubia.sol";

contract FreeForAllExcubiaTestWrapper is FreeForAllExcubia {
function exposed_trait() public pure {
_trait();
}

function exposed_check(address passerby, bytes calldata data) public view {
_check(passerby, data);
}
Expand Down

0 comments on commit 0c5b7eb

Please sign in to comment.