A MockIPFS node provides default behaviours and allows defining custom behaviour rules to simulate interactions with the IPFS network without requiring a full node or access to the real IPFS network.

This should not be created directly: instead, call then getLocal() or getRemote() methods exported from this module.

Once you have a MockIPFS node, you can start defining rules using any of the forX() methods. Each method returns a rule builder, allowing you to add extra matching constraints, followed by a thenX() final method which enables the rule, returning a promise that resolves once the rule is constructed and active.

Hierarchy

  • MockIPFSNode

Constructors

Accessors

  • get ipfsOptions(): {
        host: string;
        port: number;
        protocol: string;
    }
  • The IPFS options required to connect to this MockIPFS node. These can be passed directly to IPFS.create from ipfs-http-client to create a real IPFS client that connects to this mock node.

    Returns {
        host: string;
        port: number;
        protocol: string;
    }

    • host: string
    • port: number
    • protocol: string

Methods

  • Mock IPFS add requests containing certain types of content, mocking the behaviour of the add command while ensuring that the added content is never actually sent to a real IPFS node.

    Parameters

    • Rest ...content: (string | Uint8Array | {
          content?: string | Uint8Array;
          path: string;
      })[]

    Returns AddRuleBuilder

  • Mock the behaviour of IPNS name publishing.

    This takes an optional name argument to match. If not provided, the defined behaviour will apply for all IPFS resolutions for any name.

    Parameters

    • Optional nameKey: string

    Returns NamePublishRuleBuilder

  • Mock the behaviour of IPNS name resolutions.

    This takes an optional name argument to match. If not provided, the defined behaviour will apply for all IPFS resolutions for any name.

    Parameters

    • Optional name: string

    Returns NameResolveRuleBuilder

  • Mock the behaviour of IPFS pin removal.

    This takes an optional CID argument. If not provided, the mock will match unpinning of any CID.

    Parameters

    • Optional cid: string

    Returns PinRmRuleBuilder

  • Get the list of all IPFS CIDs & content that have been added to this IPFS mock node since it started.

    Returns Promise<{
        content?: Uint8Array;
        path?: string;
    }[]>

  • Get the list of all IPFS pins that have been added to this IPFS mock node since it started.

    Returns Promise<{
        cid: string;
    }[]>

  • Get the list of all IPNS publications that have been received by this IPFS mock node since it started.

    Returns Promise<{
        name: null | string;
        value: string;
    }[]>

  • Get the list of all IPNS resolution queries that have been received by this IPFS mock node since it started.

    Returns Promise<{
        name: null | string;
    }[]>

  • Get the list of all IPFS CIDs that have been requested from this IPFS mock node since it started.

    Returns Promise<{
        path: string;
    }[]>

  • Get the list of all IPFS pins that have been removed from this IPFS mock node since it started.

    Returns Promise<{
        cid: string;
    }[]>

  • The node must be started before use. Starting the node resets it, removing any rules that may have been added previously and configuring default behaviours for unmatched requests.

    Returns Promise<void>

Generated using TypeDoc