clitest

package
v0.0.0-...-84b6a7f Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2021 License: Apache-2.0 Imports: 58 Imported by: 0

README

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

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

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 binary (lfb is 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 lfb binary is available in your $PATH. You can check which binary will be run by the suite by running which lfb. If you have your $GOPATH properly setup they should be in $GOPATH/bin/lfb. This will ensure that your test uses the latest binary you have built

Tests generally follow this structure:

func TestMyNewCommand(t *testing.T) {
    t.Parallel()
    f := InitFixtures(t)
    defer f.Cleanup()
    
    // start lfb server 
    proc := f.GDStart()
    defer func() { require.NoError(t, proc.Stop(false)) }()

    // Your test code goes here...
}

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 .lfb folder in a new temp folder.
  • Uses lfb to create 2 accounts for use in testing: foo and bar
  • 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 lfb 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 lfb 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. lfb query staking validator would be QueryStakingValidator). 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.
  • Sometimes if you exit a test early there can be still running lfb processes that will interrupt subsequent runs. Still running lfb processes will block access to the keybase while still running lfb processes will block ports and prevent new tests from spinning up. You can ensure new tests spin up clean by running pkill -9 lfb 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. See the TxSend function and its use for a good example.
  • Tx* functions follow a general pattern and return (success bool, stdout string, stderr string). This allows for easy testing of multiple different flag configurations. See TestLinkCLICreateValidator or TestLinkCLISubmitProposal for a good example of the pattern.
Notes multi-nodes tests
  • To enable multi-nodes integration test, Docker is required.

  • Test state for a network is stored on the FixtureGroup object. And the FixtureGroup consists of multiple Fixtures which is explained above

  • One test function has one docker network with predefined ip range subnet(ex: 192.168.0.0/24). If you want to add a test function then, please make sure the subnet does not overlap others subnet

  • Sometimes if you exit a test early there can be still running docker container. But don't worry it will be stoped and replaced by new container which is generated for the test case when the test function executed.

Documentation

Index

Constants

View Source
const (
	DenomStake = "stake2"
	DenomLink  = "link"
	UserTina   = "tina"
	UserKevin  = "kevin"
	UserRinah  = "rinah"
	UserBrian  = "brian"
	UserEvelyn = "evelyn"
	UserSam    = "sam"
)

Variables

Functions

func MarshalTx

func MarshalTx(t *testing.T, stdTx tx.Tx) []byte

func UnmarshalTx

func UnmarshalTx(t *testing.T, s []byte) (stdTx tx.Tx)

func UnmarshalTxResponse

func UnmarshalTxResponse(t *testing.T, s []byte) (txResp sdk.TxResponse)

func WaitForStart

func WaitForStart(url string)

WaitForStart waits for the node to start by pinging the url every 100ms for 10s until it returns 200. If it takes longer than 5s, it panics.

func WaitForTMStart

func WaitForTMStart(port string)

wait for tendermint to start by querying tendermint

func WriteToNewTempFile

func WriteToNewTempFile(t *testing.T, s string) *os.File

Write the given string to a new temporary file

Types

type FixtureGroup

type FixtureGroup struct {
	T *testing.T

	Network *testnet.Network

	BaseDir string
	// contains filtered or unexported fields
}

func InitFixturesGroup

func InitFixturesGroup(t *testing.T, numOfNodes ...int) *FixtureGroup

func NewFixtureGroup

func NewFixtureGroup(t *testing.T) *FixtureGroup

func (*FixtureGroup) AddFullNode

func (fg *FixtureGroup) AddFullNode(flags ...string) *Fixtures

func (*FixtureGroup) Cleanup

func (fg *FixtureGroup) Cleanup()

func (*FixtureGroup) Fixture

func (fg *FixtureGroup) Fixture(index int) *Fixtures

func (*FixtureGroup) LFBStartCluster

func (fg *FixtureGroup) LFBStartCluster(flags ...string)

type Fixtures

type Fixtures struct {
	ChainID  string
	RPCAddr  string
	Port     string
	Home     string
	P2PAddr  string
	P2PPort  string
	GRPCAddr string
	GRPCPort string
	TMAddr   string
	TMPort   string
	Moniker  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, homeDir string) *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 lfb add-genesis-account

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) Clone

func (f Fixtures) Clone() *Fixtures

func (*Fixtures) CollectGenTxs

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

CollectGenTxs is lfb collect-gentxs

func (*Fixtures) GenTx

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

GenTx is lfb gentx

func (Fixtures) GenesisFile

func (f Fixtures) GenesisFile() string

GenesisFile returns the path of the genesis file

func (Fixtures) GenesisState

func (f Fixtures) GenesisState() app.GenesisState

GenesisFile returns the application's genesis state

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 lfb keys add

func (*Fixtures) KeysAddRecover

func (f *Fixtures) KeysAddRecover(name, mnemonic string, flags ...string) (testutil.BufferWriter, error)

KeysAddRecover prepares lfb keys add --recover

func (*Fixtures) KeysAddRecoverHDPath

func (f *Fixtures) KeysAddRecoverHDPath(name, mnemonic string, account uint32, index uint32, flags ...string)

KeysAddRecoverHDPath prepares lfb keys add --recover --account --index

func (*Fixtures) KeysDelete

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

KeysDelete is lfb keys delete

func (*Fixtures) KeysShow

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

KeysShow is lfb keys show

func (*Fixtures) LFBInit

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

LFBInit is lfb init NOTE: LFBInit sets the ChainID for the Fixtures instance

func (*Fixtures) LFBOstracon

func (f *Fixtures) LFBOstracon(query string) string

LFBOstracon returns the results of lfb ostracon [query]

func (*Fixtures) LFBStart

func (f *Fixtures) LFBStart(minGasPrices string) *testnet.Network

func (*Fixtures) LogResult

func (f *Fixtures) LogResult(isSuccess bool, stdOut, stdErr string)

func (*Fixtures) MempoolNumUnconfirmedTxs

func (f *Fixtures) MempoolNumUnconfirmedTxs(flags ...string) *ostctypes.ResultUnconfirmedTxs

MempoolNumUnconfirmedTxs is linkcli mempool num-unconfirmed-txs

func (*Fixtures) NetInfo

func (f *Fixtures) NetInfo(flags ...string) *ostctypes.ResultNetInfo

___________________________________________________________________________________ tendermint rpc

func (Fixtures) PrivValidatorKeyFile

func (f Fixtures) PrivValidatorKeyFile() string

func (*Fixtures) QueryAccount

func (f *Fixtures) QueryAccount(address sdk.AccAddress, flags ...string) authtypes.BaseAccount

QueryAccount is lfb query account

func (*Fixtures) QueryBalances

func (f *Fixtures) QueryBalances(address sdk.AccAddress, flags ...string) banktypes.QueryAllBalancesResponse

QueryBalances is lfb query bank balances

func (*Fixtures) QueryBlockWithHeight

func (f *Fixtures) QueryBlockWithHeight(height int, flags ...string) *ostctypes.ResultBlock

func (*Fixtures) QueryCodeWasm

func (f *Fixtures) QueryCodeWasm(codeID uint64, outputPath string, flags ...string)

func (*Fixtures) QueryContractStateSmartWasm

func (f *Fixtures) QueryContractStateSmartWasm(contractAddress string, reqJSON string, flags ...string) string

func (*Fixtures) QueryGovDeposit

func (f *Fixtures) QueryGovDeposit(proposalID int, depositor sdk.AccAddress, flags ...string) gov.Deposit

QueryGovDeposit is lfb query gov deposit

func (*Fixtures) QueryGovDeposits

func (f *Fixtures) QueryGovDeposits(propsalID int, flags ...string) gov.QueryDepositsResponse

QueryGovDeposits is lfb query gov deposits

func (*Fixtures) QueryGovParamDeposit

func (f *Fixtures) QueryGovParamDeposit(flags ...string) gov.DepositParams

QueryGovParamDeposit is lfb query gov param deposit

func (*Fixtures) QueryGovParamTallying

func (f *Fixtures) QueryGovParamTallying(flags ...string) gov.TallyParams

QueryGovParamTallying is lfb query gov param tallying

func (*Fixtures) QueryGovParamVoting

func (f *Fixtures) QueryGovParamVoting(flags ...string) gov.VotingParams

QueryGovParamVoting is lfb query gov param voting

func (*Fixtures) QueryGovProposal

func (f *Fixtures) QueryGovProposal(proposalID int, flags ...string) gov.Proposal

QueryGovProposal is lfb query gov proposal

func (*Fixtures) QueryGovProposals

func (f *Fixtures) QueryGovProposals(flags ...string) gov.QueryProposalsResponse

QueryGovProposals is lfb query gov proposals

func (*Fixtures) QueryGovVote

func (f *Fixtures) QueryGovVote(proposalID int, voter sdk.AccAddress, flags ...string) gov.Vote

QueryGovVote is lfb query gov vote

func (*Fixtures) QueryGovVotes

func (f *Fixtures) QueryGovVotes(proposalID int, flags ...string) gov.QueryVotesResponse

QueryGovVotes is lfb query gov votes

func (*Fixtures) QueryLatestBlock

func (f *Fixtures) QueryLatestBlock(flags ...string) *ostctypes.ResultBlock

func (*Fixtures) QueryListCodeWasm

func (f *Fixtures) QueryListCodeWasm(flags ...string) wasmtypes.QueryCodesResponse

func (*Fixtures) QueryListContractByCodeWasm

func (f *Fixtures) QueryListContractByCodeWasm(codeID uint64, flags ...string) wasmtypes.QueryContractsByCodeResponse

func (*Fixtures) QueryRewards

func (f *Fixtures) QueryRewards(delAddr sdk.AccAddress, flags ...string) disttypes.QueryDelegatorTotalRewardsResponse

QueryRewards returns the rewards of a delegator

func (*Fixtures) QuerySigningInfo

func (f *Fixtures) QuerySigningInfo(val string, flags ...string) slashing.ValidatorSigningInfo

QuerySigningInfo returns the signing info for a validator

func (*Fixtures) QuerySlashingParams

func (f *Fixtures) QuerySlashingParams(flags ...string) slashing.Params

QuerySlashingParams is lfb query slashing params

func (*Fixtures) QueryStakingDelegationsTo

func (f *Fixtures) QueryStakingDelegationsTo(valAddr sdk.ValAddress, flags ...string) staking.QueryValidatorDelegationsResponse

QueryStakingDelegationsTo is lfb query staking delegations-to

func (*Fixtures) QueryStakingParameters

func (f *Fixtures) QueryStakingParameters(flags ...string) staking.Params

QueryStakingParameters is lfb query staking parameters

func (*Fixtures) QueryStakingPool

func (f *Fixtures) QueryStakingPool(flags ...string) staking.Pool

QueryStakingPool is lfb query staking pool

func (*Fixtures) QueryStakingUnbondingDelegationsFrom

func (f *Fixtures) QueryStakingUnbondingDelegationsFrom(valAddr sdk.ValAddress, flags ...string) staking.QueryValidatorUnbondingDelegationsResponse

QueryStakingUnbondingDelegationsFrom is lfb query staking unbonding-delegations-from

func (*Fixtures) QueryStakingValidator

func (f *Fixtures) QueryStakingValidator(valAddr sdk.ValAddress, flags ...string) staking.Validator

QueryStakingValidator is lfb query staking validator

func (*Fixtures) QueryTotalSupply

func (f *Fixtures) QueryTotalSupply(flags ...string) (totalSupply banktypes.QueryTotalSupplyResponse)

QueryTotalSupply returns the total supply of coins

func (*Fixtures) QueryTotalSupplyOf

func (f *Fixtures) QueryTotalSupplyOf(denom string, flags ...string) sdk.Coin

QueryTotalSupplyOf returns the total supply of a given coin denom

func (*Fixtures) QueryTx

func (f *Fixtures) QueryTx(hash string, flags ...string) *sdk.TxResponse

QueryTx is lfb query tx

func (*Fixtures) QueryTxInvalid

func (f *Fixtures) QueryTxInvalid(expectedErr error, hash string, flags ...string)

QueryTxInvalid query tx with wrong hash and compare expected error

func (*Fixtures) QueryTxs

func (f *Fixtures) QueryTxs(page, limit int, flags ...string) *sdk.SearchTxsResult

QueryTxs is lfb query txs

func (*Fixtures) QueryTxsInvalid

func (f *Fixtures) QueryTxsInvalid(expectedErr error, page, limit int, flags ...string)

QueryTxsInvalid query txs with wrong parameters and compare expected error

func (*Fixtures) Status

func (f *Fixtures) Status() *ostctypes.ResultStatus

func (*Fixtures) TxBroadcast

func (f *Fixtures) TxBroadcast(fileName string, flags ...string) (testutil.BufferWriter, error)

TxBroadcast is lfb tx broadcast

func (*Fixtures) TxEncode

func (f *Fixtures) TxEncode(fileName string, flags ...string) (testutil.BufferWriter, error)

TxEncode is lfb tx encode

func (*Fixtures) TxExecuteWasm

func (f *Fixtures) TxExecuteWasm(contractAddress string, msgJSON string, flags ...string) (testutil.BufferWriter, error)

func (*Fixtures) TxGovDeposit

func (f *Fixtures) TxGovDeposit(proposalID int, from string, amount sdk.Coin, flags ...string) (testutil.BufferWriter, error)

TxGovDeposit is lfb tx gov deposit

func (*Fixtures) TxGovSubmitCommunityPoolSpendProposal

func (f *Fixtures) TxGovSubmitCommunityPoolSpendProposal(
	from, proposalPath string, deposit sdk.Coin, flags ...string,
) (testutil.BufferWriter, error)

TxGovSubmitCommunityPoolSpendProposal executes a CLI community pool spend proposal submission.

func (*Fixtures) TxGovSubmitParamChangeProposal

func (f *Fixtures) TxGovSubmitParamChangeProposal(
	from, proposalPath string, flags ...string,
) (testutil.BufferWriter, error)

TxGovSubmitParamChangeProposal executes a CLI parameter change proposal submission.

func (*Fixtures) TxGovSubmitProposal

func (f *Fixtures) TxGovSubmitProposal(from, typ, title, description string, deposit sdk.Coin, flags ...string) (testutil.BufferWriter, error)

TxGovSubmitProposal is lfb tx gov submit-proposal

func (*Fixtures) TxGovVote

func (f *Fixtures) TxGovVote(proposalID int, option gov.VoteOption, from string, flags ...string) (testutil.BufferWriter, error)

TxGovVote is lfb tx gov vote

func (*Fixtures) TxInstantiateWasm

func (f *Fixtures) TxInstantiateWasm(codeID uint64, msgJSON string, flags ...string) (testutil.BufferWriter, error)

func (*Fixtures) TxMultisign

func (f *Fixtures) TxMultisign(fileName, name string, signaturesFiles []string,
	flags ...string) (testutil.BufferWriter, error)

TxMultisign is lfb tx multisign

func (*Fixtures) TxSend

func (f *Fixtures) TxSend(from string, to sdk.AccAddress, amount sdk.Coin, flags ...string) (testutil.BufferWriter, error)

TxSend is lfb tx send

func (*Fixtures) TxSign

func (f *Fixtures) TxSign(signer, fileName string, flags ...string) (testutil.BufferWriter, error)

TxSign is lfb tx sign

func (*Fixtures) TxStakingCreateValidator

func (f *Fixtures) TxStakingCreateValidator(from, consPubKey string, amount sdk.Coin, flags ...string) (testutil.BufferWriter, error)

TxStakingCreateValidator is lfb tx staking create-validator

func (*Fixtures) TxStakingUnbond

func (f *Fixtures) TxStakingUnbond(from, shares string, validator sdk.ValAddress, flags ...string) (testutil.BufferWriter, error)

TxStakingUnbond is lfb tx staking unbond

func (*Fixtures) TxStoreWasm

func (f *Fixtures) TxStoreWasm(wasmFilePath string, flags ...string) (testutil.BufferWriter, error)

func (*Fixtures) UnsafeResetAll

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

UnsafeResetAll is lfb unsafe-reset-all

func (*Fixtures) ValidateGenesis

func (f *Fixtures) ValidateGenesis(genFile string, flags ...string)

ValidateGenesis runs lfb validate-genesis

Jump to

Keyboard shortcuts

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