-
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.
(test/hub): registering humans and other setup for path transfer tests
- Loading branch information
1 parent
41df2dc
commit 2860018
Showing
7 changed files
with
164 additions
and
16 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
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,32 @@ | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
pragma solidity >=0.8.13; | ||
|
||
import {Test} from "forge-std/Test.sol"; | ||
import {StdCheats} from "forge-std/StdCheats.sol"; | ||
|
||
import "../setup/TimeSetup.sol"; | ||
import "../setup/HumanRegistration.sol"; | ||
import "./MockPathTransferHub.sol"; | ||
|
||
contract HubPathTransferTest is Test, TimeSetup, HumanRegistration { | ||
// Constants | ||
|
||
uint256 public constant CRC = uint256(10 ** 18); | ||
|
||
// State variables | ||
|
||
MockPathTransferHub public mockHub; | ||
|
||
constructor() HumanRegistration(4) {} | ||
|
||
// Setup | ||
|
||
function setUp() public { | ||
startTime(); | ||
mockHub = new MockPathTransferHub(INFLATION_DAY_ZERO, 365 days); | ||
} | ||
|
||
// Tests | ||
|
||
function testOperateFlowMatrix() public {} | ||
} |
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,49 @@ | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
pragma solidity >=0.8.13; | ||
|
||
import "../../src/migration/IHub.sol"; | ||
import "../../src/hub/Hub.sol"; | ||
import "../../src/migration/IHub.sol"; | ||
|
||
contract MockPathTransferHub is Hub { | ||
// Constructor | ||
|
||
constructor(uint256 _inflationDayZero, uint256 _bootstrapTime) | ||
Hub(IHubV1(address(1)), address(0), _inflationDayZero, address(1), _bootstrapTime, "") | ||
{} | ||
|
||
// External functions | ||
|
||
function registerHumanUnrestricted() external { | ||
address human = msg.sender; | ||
|
||
// insert avatar into linked list; reverts if it already exists | ||
_insertAvatar(human); | ||
|
||
// set the last mint time to the current timestamp for invited human | ||
// and register the v1 Circles contract status as unregistered | ||
address v1CirclesStatus = address(0); | ||
MintTime storage mintTime = mintTimes[human]; | ||
mintTime.mintV1Status = v1CirclesStatus; | ||
mintTime.lastMintTime = uint96(block.timestamp); | ||
|
||
// trust self indefinitely, cannot be altered later | ||
_trust(human, human, INDEFINITE_FUTURE); | ||
} | ||
|
||
// Public functions | ||
|
||
function accessUnpackCoordinates(bytes calldata _packedData, uint256 _numberOfTriplets) | ||
public | ||
pure | ||
returns (uint16[] memory unpackedCoordinates_) | ||
{ | ||
return super._unpackCoordinates(_packedData, _numberOfTriplets); | ||
} | ||
|
||
// Private functions | ||
|
||
function notMocked() private pure { | ||
assert(false); | ||
} | ||
} |
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,62 @@ | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
pragma solidity >=0.8.13; | ||
|
||
import {Test} from "forge-std/Test.sol"; | ||
import {StdCheats} from "forge-std/StdCheats.sol"; | ||
|
||
contract HumanRegistration is Test { | ||
// Constants | ||
uint256 public immutable N; | ||
|
||
// State variables | ||
|
||
// forgefmt: disable-next-line | ||
string[50] public avatars = ["Alice", "Bob", "Charlie", "David", "Eve", "Frank", "Grace", "Hank", "Ivy", "Jack", "Kathy", "Liam", "Mia", "Noah", "Olivia", "Parker", "Quinn", "Ruby", "Steve", "Tina", "Umar", "Violet", "Wes", "Xena", "Yale", "Zara", "Asher", "Bella", "Cody", "Daisy", "Edward", "Fiona", "George", "Holly", "Ian", "Jenna", "Kevin", "Luna", "Mason", "Nina", "Oscar", "Piper", "Quincy", "Rosa", "Sam", "Troy", "Una", "Victor", "Wendy", "Xander"]; | ||
|
||
address[] public addresses; | ||
address[] public sortedAddresses; | ||
uint256[] public permutationMap; | ||
|
||
// Public functions | ||
|
||
constructor(uint16 _n) { | ||
require(_n <= 50, "N must be less than or equal to 50"); | ||
N = _n; | ||
addresses = new address[](N); | ||
sortedAddresses = new address[](N); | ||
permutationMap = new uint256[](N); | ||
for (uint256 i = 0; i < N; i++) { | ||
addresses[i] = makeAddr(avatars[i]); | ||
} | ||
sortAddressesWithPermutationMap(); | ||
} | ||
|
||
// Private functions | ||
|
||
/** | ||
* @dev Sorts an array of addresses in ascending order using Bubble Sort | ||
* and returns the permutation map. This is not meant to be an efficient sort, | ||
* rather the simplest implementation for transparancy of the test. | ||
*/ | ||
function sortAddressesWithPermutationMap() private { | ||
uint256 length = addresses.length; | ||
sortedAddresses = addresses; | ||
|
||
// Initialize the permutation map with original indices | ||
for (uint256 i = 0; i < length; i++) { | ||
permutationMap[i] = i; | ||
} | ||
|
||
// Bubble sort the array and the permutation map | ||
for (uint256 i = 0; i < length; i++) { | ||
for (uint256 j = 0; j < length - i - 1; j++) { | ||
if (sortedAddresses[j] > sortedAddresses[j + 1]) { | ||
// Swap elements in the address array | ||
(sortedAddresses[j], sortedAddresses[j + 1]) = (sortedAddresses[j + 1], sortedAddresses[j]); | ||
// Swap corresponding elements in the permutation map | ||
(permutationMap[j], permutationMap[j + 1]) = (permutationMap[j + 1], permutationMap[j]); | ||
} | ||
} | ||
} | ||
} | ||
} |
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