generated from spengrah/solidity-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
139 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Compiling 3 files with 0.8.18 | ||
Solc 0.8.18 finished in 705.01ms | ||
Compiler run successful | ||
|
||
Running 5 tests for test/HatsHighCouncilVotingVault.t.sol:IsVotingRepHat | ||
[32m[PASS][0m testFuzz_matchesPattern_true(uint16) (runs: 5000, μ: 33584, ~: 33584) | ||
[32m[PASS][0m testFuzz_tooChildy_false(uint160) (runs: 5000, μ: 33626, ~: 33626) | ||
[32m[PASS][0m testFuzz_wrongLevel1Hat_false(uint16) (runs: 5000, μ: 33649, ~: 33649) | ||
[32m[PASS][0m testFuzz_wrongLevel3Hat_false(uint16) (runs: 5000, μ: 33671, ~: 33671) | ||
[32m[PASS][0m testFuzz_wrongTopHat_false(uint32) (runs: 5000, μ: 33604, ~: 33604) | ||
Test result: [32mok[0m. 5 passed; 0 failed; finished in 212.68ms | ||
| src/HatsHighCouncilVotingVault.sol:HatsHighCouncilVotingVault contract | | | | | | | ||
|------------------------------------------------------------------------|-----------------|-----|--------|-----|---------| | ||
| Deployment Cost | Deployment Size | | | | | | ||
| 168051 | 1015 | | | | | | ||
| Function Name | min | avg | median | max | # calls | | ||
| isVotingRepHat | 254 | 254 | 254 | 254 | 5 | | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.18; | ||
|
||
import { console2 } from "forge-std/Test.sol"; // remove before deploy | ||
import { IHats } from "hats-protocol/Interfaces/IHats.sol"; | ||
import { IVotingVault } from "council/interfaces/IVotingVault.sol"; | ||
|
||
contract HatsHighCouncilVotingVault is IVotingVault { | ||
/// @dev The pattern of a member DAO voting rep hat | ||
uint256 internal constant PATTERN = 0x00000001_0001_0000_0001_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000; | ||
/// @dev The mask for a member DAO voting rep hat | ||
uint256 internal constant MASK = 0xFFFFFFFF_FFFF_0000_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF; | ||
/// @notice The Hats Protocol contract | ||
IHats public immutable HATS; | ||
|
||
constructor(IHats hats) { | ||
HATS = hats; | ||
} | ||
|
||
/// @inheritdoc IVotingVault | ||
function queryVotePower(address user, uint256 /* blockNumber */, bytes calldata extraData)// forgefmt: disable-line | ||
external | ||
view | ||
override | ||
returns (uint256) | ||
{ | ||
/// @dev `extraData` is the abi-encoded id of `user`'s Member DAO Voting Rep hat | ||
uint256 votingHat = abi.decode(extraData, (uint256)); | ||
|
||
if (isVotingRepHat(votingHat)) { | ||
// hat balances are either 0 or 1 | ||
return HATS.balanceOf(user, votingHat); | ||
} else { | ||
return 0; | ||
} | ||
} | ||
|
||
/// @notice Checks if `hatId` is a member DAO voting rep hat | ||
/// @param hatId The id of the hat to check | ||
/// @return True if `hatId` is a member DAO voting rep hat | ||
function isVotingRepHat(uint256 hatId) public pure returns (bool) { | ||
return (hatId & MASK) == PATTERN; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.18; | ||
|
||
import { Test, console2 } from "forge-std/Test.sol"; | ||
import { HatsHighCouncilVotingVault } from "../src/HatsHighCouncilVotingVault.sol"; | ||
import { Deploy } from "../script/HatsHighCouncilVotingVault.s.sol"; | ||
|
||
contract HHCVVTest is Deploy, Test { | ||
// variables inhereted from Deploy script | ||
// HatsHighCouncilVotingVault public hhcvv; | ||
// IHats public hats; | ||
// uint256 public membershipDomain; | ||
|
||
uint256 public fork; | ||
uint256 public BLOCK_NUMBER; | ||
|
||
function setUp() public virtual { | ||
// create and activate a fork, at BLOCK_NUMBER | ||
// fork = vm.createSelectFork(vm.rpcUrl("mainnet"), BLOCK_NUMBER); | ||
|
||
// deploy via the script | ||
Deploy.prepare(false); | ||
Deploy.run(); | ||
} | ||
} | ||
|
||
contract IsVotingRepHat is HHCVVTest { | ||
uint256 testValue; | ||
|
||
function testFuzz_matchesPattern_true(uint16 id) public { | ||
vm.assume(id > 0); | ||
testValue = 0x00000001_0001_0000_0001_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000 + (uint256(id) << 192); | ||
console2.log(testValue); | ||
assertTrue(hhcvv.isVotingRepHat(testValue)); | ||
} | ||
|
||
function testFuzz_tooChildy_false(uint160 id) public { | ||
vm.assume(id > 0); | ||
testValue = 0x00000001_0001_0001_0001_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000 + uint256(id); | ||
console2.log(testValue); | ||
assertFalse(hhcvv.isVotingRepHat(testValue)); | ||
} | ||
|
||
function testFuzz_wrongTopHat_false(uint32 id) public { | ||
vm.assume(id > 1); | ||
testValue = 0x00000000_0001_0001_0001_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000 + (uint256(id) << 224); | ||
console2.log(testValue); | ||
assertFalse(hhcvv.isVotingRepHat(testValue)); | ||
} | ||
|
||
function testFuzz_wrongLevel1Hat_false(uint16 id) public { | ||
vm.assume(id > 1); | ||
testValue = 0x00000001_0000_0001_0001_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000 + (uint256(id) << 208); | ||
console2.log(testValue); | ||
assertFalse(hhcvv.isVotingRepHat(testValue)); | ||
} | ||
|
||
function testFuzz_wrongLevel3Hat_false(uint16 id) public { | ||
vm.assume(id > 1); | ||
testValue = 0x00000001_0001_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000 + (uint256(id) << 176); | ||
console2.log(testValue); | ||
assertFalse(hhcvv.isVotingRepHat(testValue)); | ||
} | ||
} |