Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

threefoldtecharchive/substrate-client

Repository files navigation

test-substrate-client

TFchain go client

DEPRECATED: moved to: https://github.com/threefoldtech/tfchain/tree/development/clients/tfchain_client_go

Usage

To make substrate calls:

  • First, start a substrate connection against the desired url for the chain:

    manager := NewManager("wss://tfchain.grid.tf/ws")
    substrateConnection, err := manager.Substrate()
  • These are the urls for different chain networks:

    • devnet: wss://tfchain.dev.grid.tf/ws
    • testnet: wss://tfchain.test.grid.tf/ws
    • qanet: wss://tfchain.qa.grid.tf/ws
    • mainnet: wss://tfchain.grid.tf/ws
  • It is the user's responsibility to close the connection.

    defer substrateConnection.Close()
  • Then, a user could use the provided api calls to communicate with the chain. like:

    contractID, err := substrateConnection.CreateNodeContract(identity, nodeID, body, hash, publicIPsCount, solutionProviderID)
  • Also, if a connection is closed for some reason like timing out, internally, it is reopened if nothing blocks.

  • All provided api calls are found under the Substrate struct.

Run tests

To run the tests, you could either run it against a local docker image of the TFChain, or against devnet

  • Run against local docker image

    To run tests against a local docker image of tfchain, you need to set CI environment variable to anything actually.

    docker run -d -p 9944:9944 threefolddev/tfchain:2.2.0-rc8 --dev --ws-external
    sleep 3
    export CI="true"
    go test . -v
  • Run against devnet

    unset CI
    go test . -v

Test Coverage

  • 30.6% of statements

Workflows

  • Test

    • This workflow runs all tests found in the root directory against a local docker image of the TFChain found here.
  • Lint

    • This workflow ensures linting, so make sure to run these commands without any errors before pushing code:

      golangci-lint run
      gofmt -d -l .