Skip to content

v0.2.4-beta

Pre-release
Pre-release
Compare
Choose a tag to compare
@andrejrakic andrejrakic released this 10 Dec 20:10
6620d59

chainlink local logo

v0.2.4-beta Release - 10 December 2024

This release adds full support for Chainlink Data Streams including a helper GenerateMockReports off-chain component to mock the generation of unverified reports by Data Streams DON, used in local no-fork mode only. For forked mode you will need reports actually came from Data Streams DON, using data-streams-sdk for example.

Changelog

Dependencies

Package Version
@chainlink/contracts-ccip 1.5.1-beta.0
@chainlink/contracts 1.1.1
  • Chainlink CCIP
  • Chainlink CCIP v1.5
  • Chainlink Data Feeds
  • Chainlink Data Streams
  • Chainlink Automation
  • Chainlink VRF 2
  • Chainlink VRF 2.5

Added

  • Added full support for Data Streams by adding DataStreamsLocalSimulator.sol
    (Foundry/Hardhat/Remix IDE local mode), DataStreamsLocalSimulatorFork.sol
    (Foundry forked mode), DataStreamsLocalSimulatorFork.js (Hardhat forked
    mode) and MockReportGenerator.sol & MockReportGenerator.js to mock
    generating unverified reports by Data Streams DON for local modes in Foundry
    and Hardhat respectively.

Basic usage

Here's how you can test and simulate locally the basic Data Streams example from the Chainlink Official Documentation.

Foundry

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import {Test, console2} from "forge-std/Test.sol";
import {
    DataStreamsLocalSimulator,
    MockVerifierProxy
} from "@chainlink/local/src/data-streams/DataStreamsLocalSimulator.sol";
import {MockReportGenerator} from "@chainlink/local/src/data-streams/MockReportGenerator.sol";

import {ClientReportsVerifier} from "../../../src/test/data-streams/ClientReportsVerifier.sol";

contract ClientReportsVerifierTest is Test {
    DataStreamsLocalSimulator public dataStreamsLocalSimulator;
    MockReportGenerator public mockReportGenerator;

    ClientReportsVerifier public consumer;
    int192 initialPrice;

    function setUp() public {
        dataStreamsLocalSimulator = new DataStreamsLocalSimulator();
        (,,, MockVerifierProxy mockVerifierProxy_,,) = dataStreamsLocalSimulator.configuration();

        initialPrice = 1 ether;
        mockReportGenerator = new MockReportGenerator(initialPrice);

        consumer = new ClientReportsVerifier(address(mockVerifierProxy_));
    }

    function test_smoke() public {
        mockReportGenerator.updateFees(1 ether, 0.5 ether);
        bytes memory signedReportV3 = mockReportGenerator.generateReportV3();

        dataStreamsLocalSimulator.requestLinkFromFaucet(address(consumer), 1 ether);

        consumer.verifyReport(signedReportV3);

        int192 lastDecodedPrice = consumer.lastDecodedPrice();
        assertEq(lastDecodedPrice, initialPrice);
    }
}

Hardhat

import { loadFixture } from "@nomicfoundation/hardhat-toolbox/network-helpers";
import { ethers } from "hardhat";
import { assert } from "chai";
import { MockReportGenerator } from "@chainlink/local/scripts/data-streams/MockReportGenerator";

describe("ClientReportsVerifier", function () {

    async function deploy() {
        const localSimulatorFactory = await ethers.getContractFactory("DataStreamsLocalSimulator");
        const localSimulator = await localSimulatorFactory.deploy();

        const config: {
            wrappedNative_: string;
            linkToken_: string;
            mockVerifier_: string;
            mockVerifierProxy_: string;
            mockFeeManager_: string;
            mockRewardManager_: string;
        } = await localSimulator.configuration();

        const initialPrice = ethers.parseEther("1");
        const mockReportGenerator = new MockReportGenerator(initialPrice);

        const consumerFactory = await ethers.getContractFactory("ClientReportsVerifier");
        const consumer = await consumerFactory.deploy(config.mockVerifierProxy_);

        await mockReportGenerator.updateFees(ethers.parseEther("1"), ethers.parseEther("0.5"));

        await localSimulator.requestLinkFromFaucet(consumer.target, ethers.parseEther("1"));

        // const mockFeeManager = await ethers.getContractAt("MockFeeManager", config.mockFeeManager_);
        // await mockFeeManager.setMockDiscount(consumer.target, ethers.parseEther("1")); // 1e18 => 100% discount on fees

        return { consumer, initialPrice, mockReportGenerator };
    }

    it("should verify Data Streams report", async function () {
        const { consumer, initialPrice, mockReportGenerator } = await loadFixture(deploy);

        const unverifiedReport = await mockReportGenerator.generateReportV3();

        await consumer.verifyReport(unverifiedReport);

        const lastDecodedPrice = await consumer.lastDecodedPrice();
        assert(lastDecodedPrice === initialPrice);
    });
});

Testing the release

To test this release install @chainlink-local using the following commands:

Foundry (git)

forge install smartcontractkit/[email protected]

and then set remappings to: @chainlink/local/=lib/chainlink-local/ in either remappings.txt or foundry.toml file

Hardhat (npm)

npm install @chainlink/[email protected]

and then create the following contract and compile it:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import {DataStreamsLocalSimulator} from "@chainlink/local/src/data-streams/DataStreamsLocalSimulator.sol";

Remix IDE

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import {DataStreamsLocalSimulator} from "https://github.com/smartcontractkit/chainlink-local/blob/v0.2.4-beta/src/data-streams/DataStreamsLocalSimulator.sol";

PRs included

Full Changelog: v0.2.3...v0.2.4-beta