From 99b0a63515ff654929d42ce0f297e6ad47f933ec Mon Sep 17 00:00:00 2001 From: "Arthur G." Date: Tue, 14 May 2024 18:30:53 +0200 Subject: [PATCH] WIP truflation feed tests --- config/truflationFeed.json | 7 +++ foundry.toml | 1 + tests/feeds/chainlink/TruflationFeed.t.sol | 58 ++++++++++++++++++++++ 3 files changed, 66 insertions(+) create mode 100644 config/truflationFeed.json create mode 100644 tests/feeds/chainlink/TruflationFeed.t.sol diff --git a/config/truflationFeed.json b/config/truflationFeed.json new file mode 100644 index 00000000..4ff176d0 --- /dev/null +++ b/config/truflationFeed.json @@ -0,0 +1,7 @@ +{ + "feedAddress": "0x1594F325afc4f8dc4E4ad0A3F758f48B1F72930a", + "heartbeat": 60, + "macroWindowThreshold": 1, + "microWindowThreshold": 1, + "targetValue": 5 +} \ No newline at end of file diff --git a/foundry.toml b/foundry.toml index f5ff2937..84aa884d 100644 --- a/foundry.toml +++ b/foundry.toml @@ -10,6 +10,7 @@ test = "tests" script = "scripts" out = "forge-out" libs = ["lib"] +fs_permissions = [{ access = "read", path = "./config"}] remappings = [ "@openzeppelin/=lib/openzeppelin-contracts/", diff --git a/tests/feeds/chainlink/TruflationFeed.t.sol b/tests/feeds/chainlink/TruflationFeed.t.sol new file mode 100644 index 00000000..c8911848 --- /dev/null +++ b/tests/feeds/chainlink/TruflationFeed.t.sol @@ -0,0 +1,58 @@ +pragma solidity 0.8.10; + +import "forge-std/StdJson.sol"; +import {Test, console2} from "forge-std/Test.sol"; +import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol"; + +contract TruflationFeedTest is Test { + using stdJson for string; + + function append(string memory a, string memory b) internal pure returns (string memory) { + return string(abi.encodePacked(a, b)); + } + + struct JsonConfig { + address feedAddress; + uint256 heartbeat; + uint256 macroWindowTreshold; + uint256 microWindowTreshold; + uint256 targetValue; + } + + string truflationRPC; + JsonConfig config; + AggregatorV3Interface feed; + + function setUp() public { + truflationRPC = vm.envString("TRUFLATION_RPC"); + vm.createSelectFork(truflationRPC, 43_948_853); + + string memory root = vm.projectRoot(); + string memory path = append(root, "/config/truflationFeed.json"); + string memory json = vm.readFile(path); + bytes memory jsonBytes = json.parseRaw(""); + + config = abi.decode(jsonBytes, (JsonConfig)); + feed = AggregatorV3Interface(config.feedAddress); + } + + function test() public { + console2.log("Feed address: ", config.feedAddress); + console2.log("Heartbeat: ", config.heartbeat); + console2.log("Macro window treshold: ", config.macroWindowTreshold); + console2.log("Micro window treshold: ", config.microWindowTreshold); + console2.log("Target value: ", config.targetValue); + } + + function testConsecutiveRoundId() public { + (uint80 roundId,,,,) = feed.latestRoundData(); + console2.log("Latest round id: ", roundId); + console2.log("Current block number: ", block.number); + + vm.createSelectFork(truflationRPC, block.number + (5 * 60 * 60)); + + (uint80 nextRoundId,,,,) = feed.latestRoundData(); + console2.log("Next round id: ", nextRoundId); + console2.log("Current block number: ", block.number); + } +}