-
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.
(migration): write crude first test for conversion between v1 and tim…
…e circles
- Loading branch information
1 parent
d7ed2fd
commit ee5d847
Showing
5 changed files
with
65 additions
and
12 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
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,53 @@ | ||
// 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 "../../src/migration/Migration.sol"; | ||
import "../setup/TimeSetup.sol"; | ||
import "./MockHub.sol"; | ||
|
||
contract GraphTest is Test { | ||
// Constants | ||
|
||
uint256 private ACCURACY_ONE = uint256(10 ** 8); | ||
uint256 private ACCURACY_ONE_HUNDREDTH = uint256(10 ** 6); | ||
uint256 private MOMENT_IN_TIME = uint256(1702317618); | ||
|
||
// State variables | ||
|
||
MockHubV1 public mockHubV1; | ||
|
||
CirclesMigration public migration; | ||
|
||
function setUp() public { | ||
mockHubV1 = new MockHubV1(); | ||
|
||
migration = new CirclesMigration(mockHubV1); | ||
|
||
vm.warp(MOMENT_IN_TIME); | ||
} | ||
|
||
function testConversionMigrationV1ToTimeCircles() public { | ||
// `MOMENT_IN_TIME` is in the third period | ||
assertEq(uint256(3), mockHubV1.periods()); | ||
|
||
uint256 originalAmountV1 = uint256(7471193061687490000000); | ||
// at the constant `MOMENT_IN_TIME` | ||
uint256 expectedAmountV2 = uint256(1809845 * 10 ** 16); | ||
|
||
// this is a crude first test. These tests should be redone more accurately | ||
// possibly even on-chain | ||
|
||
// for now require accuracy < 1% | ||
uint256 convertedAmount = migration.convertFromV1ToTimeCircles(originalAmountV1); | ||
uint256 difference = uint256(0); | ||
if (convertedAmount < expectedAmountV2) { | ||
difference = ACCURACY_ONE - (ACCURACY_ONE * convertedAmount) / expectedAmountV2; | ||
} else { | ||
difference = ACCURACY_ONE - (ACCURACY_ONE * expectedAmountV2) / convertedAmount; | ||
} | ||
uint256 relativeDifference = difference / ACCURACY_ONE_HUNDREDTH; | ||
assertEq(0, relativeDifference); | ||
} | ||
} |
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