forked from Uniswap/v4-core
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCurrencyReserves.t.sol
58 lines (47 loc) · 2.21 KB
/
CurrencyReserves.t.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;
import {CurrencyReserves} from "../src/libraries/CurrencyReserves.sol";
import {Test} from "forge-std/Test.sol";
import {Currency} from "../src/types/Currency.sol";
contract CurrencyReservesTest is Test {
using CurrencyReserves for Currency;
Currency currency0;
function setUp() public {
currency0 = Currency.wrap(address(0xbeef));
}
function test_getReserves_returns_set() public {
currency0.syncCurrencyAndReserves(100);
uint256 value = CurrencyReserves.getSyncedReserves();
assertEq(value, 100);
assertEq(Currency.unwrap(CurrencyReserves.getSyncedCurrency()), Currency.unwrap(currency0));
}
function test_set_twice_returns_correct_value() public {
currency0.syncCurrencyAndReserves(100);
currency0.syncCurrencyAndReserves(200);
uint256 value = CurrencyReserves.getSyncedReserves();
assertEq(value, 200);
assertEq(Currency.unwrap(CurrencyReserves.getSyncedCurrency()), Currency.unwrap(currency0));
}
function test_reset_currency() public {
currency0.syncCurrencyAndReserves(100);
uint256 value = CurrencyReserves.getSyncedReserves();
assertEq(value, 100);
assertEq(Currency.unwrap(CurrencyReserves.getSyncedCurrency()), Currency.unwrap(currency0));
CurrencyReserves.resetCurrency();
uint256 valueAfterReset = CurrencyReserves.getSyncedReserves();
assertEq(valueAfterReset, 100);
assertEq(Currency.unwrap(CurrencyReserves.getSyncedCurrency()), address(0));
}
function test_reservesOfSlot() public pure {
assertEq(bytes32(uint256(keccak256("ReservesOf")) - 1), CurrencyReserves.RESERVES_OF_SLOT);
}
function test_syncSlot() public pure {
assertEq(bytes32(uint256(keccak256("Currency")) - 1), CurrencyReserves.CURRENCY_SLOT);
}
function test_fuzz_get_set(Currency currency, uint256 value) public {
vm.assume(value != type(uint256).max);
currency.syncCurrencyAndReserves(value);
assertEq(Currency.unwrap(CurrencyReserves.getSyncedCurrency()), Currency.unwrap(currency));
assertEq(CurrencyReserves.getSyncedReserves(), value);
}
}