clitest

package
v0.0.0-...-30704ab Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 16, 2021 License: Apache-2.0 Imports: 15 Imported by: 0

README

Relay CLI Integration tests

The relay cli integration tests live in this folder. You can run the full suite by running:

go test -mod=readonly -p 4 `go list ./cli_test/...`

To run a single test run:

go test -mod=readonly -p 4 `go list ./cli_test/...` -testify.m TestName

NOTE: While the full suite runs in parallel, some of the tests can take up to a minute to complete

Test Structure

This integration suite uses a thin wrapper over the os/exec package. This allows the integration test to run against built binaries (both relayd and relaycli are used) while being written in golang. This allows tests to take advantage of the various golang code we have for operations like marshal/unmarshal, crypto, etc...

NOTE: The tests will use whatever relayd or relaycli binaries are available in your $GOPATH/bin. You can check which binary will be run by the suite by running which relayd or which relaycli. If you have your $GOPATH properly setup they should be in $GOPATH/bin/relay*. This will ensure that your test uses the latest binary you have built

Tests generally follow this structure:

func (suite *UtilsSuite)  TestMyNewCommand() {
    suite.T().Parallel()
    f := InitFixtures(suite.T())

    // start relayd server
    proc := f.GDStart()
    defer proc.Stop(false)

    // Your test code goes here...

    f.Cleanup()
}

This boilerplate above:

  • Ensures the tests run in parallel. Because the tests are calling out to os/exec for many operations these tests can take a long time to run.
  • Creates .relayd and .relaycli folders in a new temp folder.
  • Uses relaycli to create test account for use in testing: foo
  • Creates a genesis file with coins (1000footoken,1000feetoken,150stake) controlled by the foo key
  • Generates an initial bonding transaction (gentx) to make the foo key a validator at genesis
  • Starts relayd and stops it once the test exits
  • Cleans up test state on a successful run
Notes when adding/running tests
  • Because the tests run against a built binary, you should make sure you build every time the code changes and you want to test again, otherwise you will be testing against an older version. If you are adding new tests this can easily lead to confusing test results.
  • The test_helpers.go file is organized according to the format of relaycli and relayd commands. There are comments with section headers describing the different areas. Helper functions to call CLI functionality are generally named after the command (e.g. relaycli query bestknowndigest would be QueryBestKnownDigest). Try to keep functions grouped by their position in the command tree.
  • Test state that is needed by tx and query commands (home, chain_id, etc...) is stored on the Fixtures object. This makes constructing your new tests almost trivial. Each test needs unique Fixture to run in parallel
  • Sometimes if you exit a test early there can be still running relayd and relaycli processes that will interrupt subsequent runs. Still running relayd processes will block ports and prevent new tests from spinning up. You can ensure new tests spin up clean by running pkill -9 relayd && pkill -9 relaycli before each test run.
  • Most query and tx commands take a variadic flags argument. This pattern allows for the creation of a general function which is easily modified by adding flags.
  • Tx* functions follow a general pattern and return (success bool, stdout string, stderr string). This allows for easy testing of multiple different flag configurations.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Fixtures

type Fixtures struct {
	BinDir         string
	RootDir        string
	RelaydBinary   string
	RelaycliBinary string
	ChainID        string
	RPCAddr        string
	Port           string
	RelaydHome     string
	RelaycliHome   string
	P2PAddr        string
	T              *testing.T
}

Fixtures is used to setup the testing environment

func InitFixtures

func InitFixtures(t *testing.T) (f *Fixtures)

InitFixtures is called at the beginning of a test and initializes a chain with 1 validator.

func NewFixtures

func NewFixtures(t *testing.T) *Fixtures

NewFixtures creates a new instance of Fixtures with many vars set

func (*Fixtures) AddGenesisAccount

func (f *Fixtures) AddGenesisAccount(address sdk.AccAddress, coins sdk.Coins, flags ...string)

AddGenesisAccount is relayd add-genesis-account

func (*Fixtures) CLIConfig

func (f *Fixtures) CLIConfig(key, value string, flags ...string)

CLIConfig is relaycli config

func (*Fixtures) Cleanup

func (f *Fixtures) Cleanup(dirs ...string)

Cleanup is meant to be run at the end of a test to clean up an remaining test state

func (*Fixtures) CollectGenTxs

func (f *Fixtures) CollectGenTxs(flags ...string)

CollectGenTxs is relayd collect-gentxs

func (*Fixtures) Flags

func (f *Fixtures) Flags() string

Flags returns the flags necessary for making most CLI calls

func (*Fixtures) GenTx

func (f *Fixtures) GenTx(name string, flags ...string)

GenTx is relayd gentx

func (Fixtures) GenesisFile

func (f Fixtures) GenesisFile() string

GenesisFile returns the path of the generated genesis file

func (*Fixtures) KeyAddress

func (f *Fixtures) KeyAddress(name string) sdk.AccAddress

KeyAddress returns the SDK account address from the key

func (*Fixtures) KeysAdd

func (f *Fixtures) KeysAdd(name string, flags ...string)

KeysAdd is relaycli keys add

func (*Fixtures) KeysShow

func (f *Fixtures) KeysShow(name string, flags ...string) keys.KeyOutput

KeysShow is relaycli keys show

func (*Fixtures) QueryCheckProof

func (f *Fixtures) QueryCheckProof(proof string, flags ...string) rtypes.QueryResCheckProof

QueryCheckProof returns the Boolean

func (*Fixtures) QueryCheckRequests

func (f *Fixtures) QueryCheckRequests(proof, requests string, flags ...string) rtypes.QueryResCheckRequests

QueryCheckRequests returns the Boolean

func (*Fixtures) QueryFindAncestor

func (f *Fixtures) QueryFindAncestor(digest, offset string) rtypes.QueryResFindAncestor

QueryFindAncestor returns the Boolean

func (*Fixtures) QueryFindAncestorInvalid

func (f *Fixtures) QueryFindAncestorInvalid(errStr, digest, offset string)

QueryFindAncestorInvalid require proper response for invalid query

func (*Fixtures) QueryGetBestDigest

func (f *Fixtures) QueryGetBestDigest(delAddr sdk.AccAddress) rtypes.QueryResGetBestDigest

QueryGetBestDigest returns the Best Known Digest

func (*Fixtures) QueryGetLastReorgLCA

func (f *Fixtures) QueryGetLastReorgLCA(delAddr sdk.AccAddress) rtypes.QueryResGetLastReorgLCA

QueryGetLastReorgLCA returns Last Common Anscestor

func (*Fixtures) QueryGetRelayGenesis

func (f *Fixtures) QueryGetRelayGenesis(delAddr sdk.AccAddress) rtypes.QueryResGetRelayGenesis

QueryGetRelayGenesis returns the relay genesis block Hash

func (*Fixtures) QueryHeaviestFromAncestor

func (f *Fixtures) QueryHeaviestFromAncestor(ancestor, currentBest, newBest, limit string) rtypes.QueryResHeaviestFromAncestor

QueryHeaviestFromAncestor returns a Boolean

func (*Fixtures) QueryHeaviestFromAncestorInvalid

func (f *Fixtures) QueryHeaviestFromAncestorInvalid(errStr, ancestor, currentBest, newBest, limit string)

QueryHeaviestFromAncestorInvalid require proper response for invalid query

func (*Fixtures) QueryIsAncestor

func (f *Fixtures) QueryIsAncestor(digest, ancestor, limit string) rtypes.QueryResIsAncestor

QueryIsAncestor returns the Boolean

func (*Fixtures) QueryIsMostRecentCommonAncestor

func (f *Fixtures) QueryIsMostRecentCommonAncestor(ancestor, left, right, limit string) rtypes.QueryResIsMostRecentCommonAncestor

QueryIsMostRecentCommonAncestor returns a Boolean

func (*Fixtures) RelayDInit

func (f *Fixtures) RelayDInit(moniker string, flags ...string)

RelayDInit is relayd init NOTE: RelayDInit sets the ChainID for the Fixtures instance

func (*Fixtures) RelayDStart

func (f *Fixtures) RelayDStart(flags ...string) *tests.Process

RelaydStart runs relayd start with the appropriate flags and returns a process

func (*Fixtures) TxIngestDiffChange

func (f *Fixtures) TxIngestDiffChange(delAddr sdk.AccAddress, prevEpochStart, jsonHeaders string, flags ...string) (bool, string, string)

TxIngestDiffChange is relaycli tx that ingests headers with new difficulty

func (*Fixtures) TxIngestHeaders

func (f *Fixtures) TxIngestHeaders(delAddr sdk.AccAddress, headers string, flags ...string) (bool, string, string)

TxIngestHeaders is a relaycli tx that ingests headers with same difficulty as previous headers

func (*Fixtures) TxMarkNewHeaviest

func (f *Fixtures) TxMarkNewHeaviest(delAddr sdk.AccAddress, ancestor, currentBest, newBest, limit string, flags ...string) (bool, string, string)

TxMarkNewHeaviest returns Last Common Anscestor

func (*Fixtures) TxNewRequest

func (f *Fixtures) TxNewRequest(delAddr sdk.AccAddress, spends, pays, value, numConfs string, flags ...string) (bool, string, string)

TxNewRequest is a relaycli tx that submits a new Proof Request

func (*Fixtures) TxProvideProof

func (f *Fixtures) TxProvideProof(delAddr sdk.AccAddress, proof, listofrequests string, flags ...string) (bool, string, string)

TxProvideProof is a relaycli tx that submits a new Proof Request

func (*Fixtures) UnsafeResetAll

func (f *Fixtures) UnsafeResetAll(flags ...string)

UnsafeResetAll is relayd unsafe-reset-all

type TestData

type TestData struct {
	GenesisHeaders []rtypes.BitcoinHeader
	NewDiffHeaders []rtypes.BitcoinHeader
	NewHeaders     []rtypes.BitcoinHeader
}

func GrabTestData

func GrabTestData(t *testing.T) TestData

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL