Skip to content

Testing with the mock ​

VerityCoordinatorMock behaves like the real coordinator for subscriptions and consumer checks, but needs no keys, proofs or node. You trigger fulfilment yourself.

solidity
import {VerityCoordinatorMock} from "@verity/mocks/VerityCoordinatorMock.sol";

function setUp() public {
    mock = new VerityCoordinatorMock();
    subId = mock.createSubscription();
    game = new MyGame(address(mock), keccak256("any lane"), subId);
    mock.addConsumer(subId, address(game));
}

function test_playerWins() public {
    uint256 id = game.play();
    uint256[] memory words = new uint256[](1);
    words[0] = 5;                                   // choose the outcome
    mock.fulfillRandomWordsWithOverride(id, words);
    // assert...
}

function testFuzz_anyOutcomeIsSafe(uint256 word) public {
    uint256 id = game.play();
    uint256[] memory words = new uint256[](1);
    words[0] = word;                                // every possible outcome
    mock.fulfillRandomWordsWithOverride(id, words);
    // invariants...
}
  • fulfillRandomWords(requestId) delivers pseudo-random words derived from the id.
  • fulfillRandomWordsWithOverride(requestId, words) delivers exactly your words.
  • Both forward exactly the request's callbackGasLimit, like the real coordinator, so out-of-gas bugs show up in tests.

Test the ugly paths: never fulfilling (your timeout/refund logic), late fulfilment after a refund, a reverting callback, and the maximum size of whatever your callback processes.

The example contracts in verity-examples/contracts have full test suites using the mock.

Testnet: PulseChain testnet v4. Unaudited software; do not use on mainnet yet.