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
      • LibStruct.sol — Useful library to read Subscription structs
      • MockManager.sol — Useful mock manager to register and activate nodes
      • MockNode.sol — Useful mock Infernet node with test fixtures
  • Basic test structure

    The following Solidity snippet sets up a Foundry test, deploys the EIP712Coordinator, 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 {MockNode} from "infernet/test/mocks/MockNode.sol";
    import {EIP712Coordinator} from "infernet/core/EIP712Coordinator.sol";
     
    contract MyTest is Test {
        /// @notice EIP712Coordinator
        EIP712Coordinator internal COORDINATOR;
     
        /// @notice Mock node (Alice)
        MockNode internal ALICE;
     
        /// @notice Mock node (Bob)
        MockNode internal BOB;
     
        function setUp() public {
            // Initialize coordinator
            COORDINATOR = new EIP712Coordinator();
     
            // Initalize mock nodes
            ALICE = new MockNode(COORDINATOR);
            BOB = new MockNode(COORDINATOR);
     
            // For each node
            MockNode[2] memory nodes = [ALICE, BOB];
            for (uint256 i = 0; i < 2; i++) {
                // Select node
                MockNode node = nodes[i];
     
                // Activate nodes
                vm.warp(0);
                node.registerNode(address(node));
                vm.warp(COORDINATOR.cooldown());
                node.activateNode();
            }
        }
    }