Infernet
SDK
Testing

Testing

If using Foundry: forge (opens in a new tab) as your Solidity smart contract development platform, the SDK provides existing utilities and mocks to test your smart contract's Infernet-related functionality:

Setting up remappings.txt:

You can access the test utilities and mocks in the lib/infernet/contracts/test directory once the SDK has been installed. For easy access, you can modify your remappings.txt to map this directory to infernet/tests:

"infernet/tests=lib/infernet/contracts/test" >> remappings.txt

Available utilities and mocks

      • LigSign.sol — Useful library to create and validate EIP-712 subscriptions
      • LibDeploy.sol — Useful library to 1-click deploy all Infernet SDK contracts
        • Base.sol — Base consumer
        • Callback.sol — CallbackConsumer
        • Subscription.sol — SubscriptionConsumer
        • DelegatorCallback.sol — CallbackConsumer w/ EIP-712 delegation
        • DelegatorSubscription.sol — SubscriptionConsumer w/ EIP-712 delegation
        • AllowlistSubscription.sol — SubscriptionConsumer w/ node Allowlist
        • AllowlistDelegatorSubscription.sol — SubscriptionConsumer w/ EIP-712 delegation and node Allowlist
        • Base.sol — Base verifier
        • Atomic.sol — Atomic proof verifier
        • Optimistic.sol — Optimistic proof verifier
      • MockCoordinated.sol — Coordinator-permissioned contract
      • MockNode.sol — Infernet node
      • MockProtocol.sol — Fee contract
      • MockToken.sol — ERC20 token
  • Basic test structure

    The following Solidity snippet sets up a Foundry test, deploys the Infernet SDK contracts via LibDeploy, and sets up two mock Infernet nodes, ALICE and BOB that are ready to submit subscription responses:

    import {Test} from "forge-std/Test.sol";
    import {LibDeploy} from "./lib/LibDeploy.sol";
    import {Registry} from "infernet/core/Registry.sol";
    import {MockNode} from "infernet/test/mocks/MockNode.sol";
     
    contract MyTest is Test {
        /// @notice Registry
        Registry internal REGISTRY;
     
        /// @notice Mock node (Alice)
        MockNode internal ALICE;
     
        /// @notice Mock node (Bob)
        MockNode internal BOB;
     
        function setUp() public {
            // Initialize registry
            uint256 initialNonce = vm.getNonce(address(this));
            (Registry registry,,,,,) = LibDeploy.deployContracts(
              address(this),
              initialNonce,
              address(this),
              0
            );
            REGISTRY = registry;
     
            // Initalize mock nodes
            ALICE = new MockNode(REGISTRY);
            BOB = new MockNode(REGISTRY);
        }
    }