Skip to content

Commit

Permalink
(test/Circles): test flow to invite v1 user to v2
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminbollen committed Mar 28, 2024
1 parent fb5f449 commit 4de6630
Showing 1 changed file with 32 additions and 43 deletions.
75 changes: 32 additions & 43 deletions test/hub/V1MintStatusUpdate.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -57,60 +57,57 @@ contract V1MintStatusUpdateTest is Test, TimeCirclesSetup, HumanRegistration {
// move time
skipTime(5 days + 1 hours + 31 minutes);

uint256 mintedAlice = mintV1Tokens(tokenAlice);
uint256 mintedBob = mintV1Tokens(tokenBob);
// mints 42799999999999536000 CRC
// which is 8.5599999999999072 CRC per day
console.log("mintedAlice", mintedAlice);
console.log("mintedBob", mintedBob);
// Alice and Bob mint in V1
mintV1Tokens(tokenAlice);
mintV1Tokens(tokenBob);

// Alice stops her V1 token and registers in V2
vm.startPrank(addresses[0]);
tokenAlice.stop();
require(tokenAlice.stopped(), "Token not stopped");
assertTrue(tokenAlice.stopped(), "Token not stopped");
mockHub.registerHuman(bytes32(0));
vm.stopPrank();
require(mockHub.isHuman(addresses[0]), "Alice not registered");
assertTrue(mockHub.isHuman(addresses[0]), "Alice not registered");

// Alice invites Bob, while he is still active in V1
vm.prank(addresses[0]);
mockHub.inviteHuman(addresses[1]);
require(mockHub.isHuman(addresses[1]), "Bob not registered");
assertTrue(mockHub.isHuman(addresses[1]), "Bob not registered");

uint256 previousEndPeriod = 0;

for (uint256 i = 0; i < 5; i++) {
// Calculate issuance to get the current start and end periods
(, uint256 startPeriod, uint256 endPeriod) = mockHub.calculateIssuance(addresses[0]);

// For iterations after the first, check if the previous endPeriod matches the current startPeriod
if (i > 0) {
require(previousEndPeriod == startPeriod, "EndPeriod does not match next StartPeriod");
}
// move time
skipTime(5 days - 31 minutes);

// Update previousEndPeriod with the current endPeriod for the next iteration
previousEndPeriod = endPeriod;
// Alice can mint in V2
vm.prank(addresses[0]);
mockHub.personalMint();

// Generate a pseudo-random number between 1 and 4
uint256 hoursSkip = uint256(keccak256(abi.encodePacked(block.timestamp, i, uint256(0)))) % 4 + 1;
uint256 secondsSkip = uint256(keccak256(abi.encodePacked(block.timestamp, i, uint256(1)))) % 3600;
// Bob cannot mint in V2, but can in V1
vm.expectRevert();
vm.prank(addresses[1]);
mockHub.personalMint();
mintV1Tokens(tokenBob);

// Simulate passing of time variable windows of time (1-5 hours)
skipTime(hoursSkip * 1 hours + secondsSkip);
// Bob stops his V1 token
vm.prank(addresses[1]);
tokenBob.stop();

// Perform the mint operation as Alice
vm.prank(addresses[0]);
mockHub.personalMint();
}
// Bob can mint in V2, but calculateIssuance will still revert because V1 status not updated
vm.expectRevert();
mockHub.calculateIssuance(addresses[1]);
// however, sending a transaction to update the V1 status does calculate the issuance
(uint256 issuance, uint256 startPeriod, uint256 endPeriod) = mockHub.calculateIssuanceWithCheck(addresses[1]);
console.log("Bob can mint in V2:", issuance);
console.log("from", startPeriod, "to", endPeriod);

// move time
skipTime(5 days - 31 minutes);
skipTime(5 days + 31 minutes);
(issuance, startPeriod, endPeriod) = mockHub.calculateIssuance(addresses[1]);
console.log("Bob can mint in V2:", issuance);
console.log("from", startPeriod, "to", endPeriod);

// Alice can mint in V2
vm.startPrank(addresses[0]);
// Bob can mint in V2
vm.prank(addresses[1]);
mockHub.personalMint();

//
}

// Private functions
Expand All @@ -131,12 +128,4 @@ contract V1MintStatusUpdateTest is Test, TimeCirclesSetup, HumanRegistration {
uint256 balanceAfter = _token.balanceOf(owner);
return balanceAfter - balanceBefore;
}

// function mintV2Circles(address _avatar) private returns (uint256) {
// // we can't check on the data (which contains id and amount),
// // because we don't know the amount upfront.
// vm.expectEmit(false, true, true, false);
// emit IERC1155.TransferSingle(_avatar, address(0), _avatar, uint256(uint160(_avatar)), 1);

// }
}

0 comments on commit 4de6630

Please sign in to comment.