README ¶
Gaia CLI Integration tests
The gaia 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/...` -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 binaries (both wasmd
and wasmcli
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
wasmd
orwasmcli
binaries are available in your$PATH
. You can check which binary will be run by the suite by runningwhich wasmd
orwhich wasmcli
. If you have your$GOPATH
properly setup they should be in$GOPATH/bin/gaia*
. 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)
// start wasmd 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
.wasmd
and.wasmcli
folders in a new temp folder. - Uses
wasmcli
to create 2 accounts for use in testing:foo
andbar
- Creates a genesis file with coins (
1000footoken,1000feetoken,150stake
) controlled by thefoo
key - Generates an initial bonding transaction (
gentx
) to make thefoo
key a validator at genesis - Starts
wasmd
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 ofwasmcli
andwasmd
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.wasmcli query staking validator
would beQueryStakingValidator
). Try to keep functions grouped by their position in the command tree. - Test state that is needed by
tx
andquery
commands (home
,chain_id
, etc...) is stored on theFixtures
object. This makes constructing your new tests almost trivial. - Sometimes if you exit a test early there can be still running
wasmd
andwasmcli
processes that will interrupt subsequent runs. Still runningwasmcli
processes will block access to the keybase while still runningwasmd
processes will block ports and prevent new tests from spinning up. You can ensure new tests spin up clean by runningpkill -9 wasmd && pkill -9 wasmcli
before each test run. - Most
query
andtx
commands take a variadicflags
argument. This pattern allows for the creation of a general function which is easily modified by adding flags. See theTxSend
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. SeeTestGaiaCLICreateValidator
orTestGaiaCLISubmitProposal
for a good example of the pattern.
Documentation ¶
Index ¶
- func WriteToNewTempFile(t *testing.T, s string) *os.File
- type Fixtures
- func (f *Fixtures) AddGenesisAccount(address sdk.AccAddress, coins sdk.Coins, flags ...string)
- func (f *Fixtures) CLIConfig(key, value string, flags ...string)
- func (f *Fixtures) Cleanup(dirs ...string)
- func (f *Fixtures) CollectGenTxs(flags ...string)
- func (f *Fixtures) Flags() string
- func (f *Fixtures) GDInit(moniker string, flags ...string)
- func (f *Fixtures) GDStart(flags ...string) *tests.Process
- func (f *Fixtures) GDTendermint(query string) string
- func (f *Fixtures) GenTx(name string, flags ...string)
- func (f Fixtures) GenesisFile() string
- func (f Fixtures) GenesisState() simapp.GenesisState
- func (f *Fixtures) KeyAddress(name string) sdk.AccAddress
- func (f *Fixtures) KeysAdd(name string, flags ...string)
- func (f *Fixtures) KeysAddRecover(name, mnemonic string, flags ...string) (exitSuccess bool, stdout, stderr string)
- func (f *Fixtures) KeysAddRecoverHDPath(name, mnemonic string, account uint32, index uint32, flags ...string)
- func (f *Fixtures) KeysDelete(name string, flags ...string)
- func (f *Fixtures) KeysShow(name string, flags ...string) keys.KeyOutput
- func (f *Fixtures) QueryAccount(address sdk.AccAddress, flags ...string) auth.BaseAccount
- func (f *Fixtures) QueryGovDeposit(proposalID int, depositor sdk.AccAddress, flags ...string) gov.Deposit
- func (f *Fixtures) QueryGovDeposits(propsalID int, flags ...string) []gov.Deposit
- func (f *Fixtures) QueryGovParamDeposit() gov.DepositParams
- func (f *Fixtures) QueryGovParamTallying() gov.TallyParams
- func (f *Fixtures) QueryGovParamVoting() gov.VotingParams
- func (f *Fixtures) QueryGovProposal(proposalID int, flags ...string) gov.Proposal
- func (f *Fixtures) QueryGovProposals(flags ...string) gov.Proposals
- func (f *Fixtures) QueryGovVote(proposalID int, voter sdk.AccAddress, flags ...string) gov.Vote
- func (f *Fixtures) QueryGovVotes(proposalID int, flags ...string) []gov.Vote
- func (f *Fixtures) QueryRewards(delAddr sdk.AccAddress, flags ...string) distribution.QueryDelegatorTotalRewardsResponse
- func (f *Fixtures) QuerySigningInfo(val string) slashing.ValidatorSigningInfo
- func (f *Fixtures) QuerySlashingParams() slashing.Params
- func (f *Fixtures) QueryStakingDelegationsTo(valAddr sdk.ValAddress, flags ...string) []staking.Delegation
- func (f *Fixtures) QueryStakingParameters(flags ...string) staking.Params
- func (f *Fixtures) QueryStakingPool(flags ...string) staking.Pool
- func (f *Fixtures) QueryStakingUnbondingDelegationsFrom(valAddr sdk.ValAddress, flags ...string) []staking.UnbondingDelegation
- func (f *Fixtures) QueryStakingValidator(valAddr sdk.ValAddress, flags ...string) staking.Validator
- func (f *Fixtures) QueryTotalSupply(flags ...string) (totalSupply sdk.Coins)
- func (f *Fixtures) QueryTotalSupplyOf(denom string, flags ...string) sdk.Int
- func (f *Fixtures) QueryTxs(page, limit int, events ...string) *sdk.SearchTxsResult
- func (f *Fixtures) QueryTxsInvalid(expectedErr error, page, limit int, events ...string)
- func (f *Fixtures) TxBroadcast(fileName string, flags ...string) (bool, string, string)
- func (f *Fixtures) TxEncode(fileName string, flags ...string) (bool, string, string)
- func (f *Fixtures) TxGovDeposit(proposalID int, from string, amount sdk.Coin, flags ...string) (bool, string, string)
- func (f *Fixtures) TxGovSubmitCommunityPoolSpendProposal(from, proposalPath string, deposit sdk.Coin, flags ...string) (bool, string, string)
- func (f *Fixtures) TxGovSubmitParamChangeProposal(from, proposalPath string, deposit sdk.Coin, flags ...string) (bool, string, string)
- func (f *Fixtures) TxGovSubmitProposal(from, typ, title, description string, deposit sdk.Coin, flags ...string) (bool, string, string)
- func (f *Fixtures) TxGovVote(proposalID int, option gov.VoteOption, from string, flags ...string) (bool, string, string)
- func (f *Fixtures) TxMultisign(fileName, name string, signaturesFiles []string, flags ...string) (bool, string, string)
- func (f *Fixtures) TxSend(from string, to sdk.AccAddress, amount sdk.Coin, flags ...string) (bool, string, string)
- func (f *Fixtures) TxSign(signer, fileName string, flags ...string) (bool, string, string)
- func (f *Fixtures) TxStakingCreateValidator(from, consPubKey string, amount sdk.Coin, flags ...string) (bool, string, string)
- func (f *Fixtures) TxStakingUnbond(from, shares string, validator sdk.ValAddress, flags ...string) bool
- func (f *Fixtures) UnsafeResetAll(flags ...string)
- func (f *Fixtures) ValidateGenesis()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Fixtures ¶
type Fixtures struct { BuildDir string RootDir string GaiadBinary string GaiacliBinary string ChainID string RPCAddr string Port string GaiadHome string GaiacliHome string P2PAddr string T *testing.T }
Fixtures is used to setup the testing environment
func InitFixtures ¶
InitFixtures is called at the beginning of a test and initializes a chain with 1 validator.
func NewFixtures ¶
NewFixtures creates a new instance of Fixtures with many vars set
func (*Fixtures) AddGenesisAccount ¶
AddGenesisAccount is wasmd add-genesis-account
func (*Fixtures) Cleanup ¶
Cleanup is meant to be run at the end of a test to clean up an remaining test state
func (*Fixtures) CollectGenTxs ¶
CollectGenTxs is wasmd collect-gentxs
func (*Fixtures) GDInit ¶
GDInit is wasmd init NOTE: GDInit sets the ChainID for the Fixtures instance
func (*Fixtures) GDStart ¶
GDStart runs wasmd start with the appropriate flags and returns a process
func (*Fixtures) GDTendermint ¶
GDTendermint returns the results of wasmd tendermint [query]
func (Fixtures) GenesisFile ¶
GenesisFile returns the path of the genesis file
func (Fixtures) GenesisState ¶
func (f Fixtures) GenesisState() simapp.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) KeysAddRecover ¶
func (f *Fixtures) KeysAddRecover(name, mnemonic string, flags ...string) (exitSuccess bool, stdout, stderr string)
KeysAddRecover prepares wasmcli keys add --recover
func (*Fixtures) KeysAddRecoverHDPath ¶
func (f *Fixtures) KeysAddRecoverHDPath(name, mnemonic string, account uint32, index uint32, flags ...string)
KeysAddRecoverHDPath prepares wasmcli keys add --recover --account --index
func (*Fixtures) KeysDelete ¶
KeysDelete is wasmcli keys delete
func (*Fixtures) QueryAccount ¶
func (f *Fixtures) QueryAccount(address sdk.AccAddress, flags ...string) auth.BaseAccount
QueryAccount is wasmcli query account
func (*Fixtures) QueryGovDeposit ¶
func (f *Fixtures) QueryGovDeposit(proposalID int, depositor sdk.AccAddress, flags ...string) gov.Deposit
QueryGovDeposit is wasmcli query gov deposit
func (*Fixtures) QueryGovDeposits ¶
QueryGovDeposits is wasmcli query gov deposits
func (*Fixtures) QueryGovParamDeposit ¶
func (f *Fixtures) QueryGovParamDeposit() gov.DepositParams
QueryGovParamDeposit is wasmcli query gov param deposit
func (*Fixtures) QueryGovParamTallying ¶
func (f *Fixtures) QueryGovParamTallying() gov.TallyParams
QueryGovParamTallying is wasmcli query gov param tallying
func (*Fixtures) QueryGovParamVoting ¶
func (f *Fixtures) QueryGovParamVoting() gov.VotingParams
QueryGovParamVoting is wasmcli query gov param voting
func (*Fixtures) QueryGovProposal ¶
QueryGovProposal is wasmcli query gov proposal
func (*Fixtures) QueryGovProposals ¶
QueryGovProposals is wasmcli query gov proposals
func (*Fixtures) QueryGovVote ¶
QueryGovVote is wasmcli query gov vote
func (*Fixtures) QueryGovVotes ¶
QueryGovVotes is wasmcli query gov votes
func (*Fixtures) QueryRewards ¶
func (f *Fixtures) QueryRewards(delAddr sdk.AccAddress, flags ...string) distribution.QueryDelegatorTotalRewardsResponse
QueryRewards returns the rewards of a delegator
func (*Fixtures) QuerySigningInfo ¶
func (f *Fixtures) QuerySigningInfo(val string) slashing.ValidatorSigningInfo
QuerySigningInfo returns the signing info for a validator
func (*Fixtures) QuerySlashingParams ¶
QuerySlashingParams is wasmcli query slashing params
func (*Fixtures) QueryStakingDelegationsTo ¶
func (f *Fixtures) QueryStakingDelegationsTo(valAddr sdk.ValAddress, flags ...string) []staking.Delegation
QueryStakingDelegationsTo is wasmcli query staking delegations-to
func (*Fixtures) QueryStakingParameters ¶
QueryStakingParameters is wasmcli query staking parameters
func (*Fixtures) QueryStakingPool ¶
QueryStakingPool is wasmcli query staking pool
func (*Fixtures) QueryStakingUnbondingDelegationsFrom ¶
func (f *Fixtures) QueryStakingUnbondingDelegationsFrom(valAddr sdk.ValAddress, flags ...string) []staking.UnbondingDelegation
QueryStakingUnbondingDelegationsFrom is wasmcli query staking unbonding-delegations-from
func (*Fixtures) QueryStakingValidator ¶
QueryStakingValidator is wasmcli query staking validator
func (*Fixtures) QueryTotalSupply ¶
QueryTotalSupply returns the total supply of coins
func (*Fixtures) QueryTotalSupplyOf ¶
QueryTotalSupplyOf returns the total supply of a given coin denom
func (*Fixtures) QueryTxs ¶
func (f *Fixtures) QueryTxs(page, limit int, events ...string) *sdk.SearchTxsResult
QueryTxs is wasmcli query txs
func (*Fixtures) QueryTxsInvalid ¶
QueryTxsInvalid query txs with wrong parameters and compare expected error
func (*Fixtures) TxBroadcast ¶
TxBroadcast is wasmcli tx broadcast
func (*Fixtures) TxGovDeposit ¶
func (f *Fixtures) TxGovDeposit(proposalID int, from string, amount sdk.Coin, flags ...string) (bool, string, string)
TxGovDeposit is wasmcli tx gov deposit
func (*Fixtures) TxGovSubmitCommunityPoolSpendProposal ¶
func (f *Fixtures) TxGovSubmitCommunityPoolSpendProposal( from, proposalPath string, deposit sdk.Coin, flags ...string, ) (bool, string, string)
TxGovSubmitCommunityPoolSpendProposal executes a CLI community pool spend proposal submission.
func (*Fixtures) TxGovSubmitParamChangeProposal ¶
func (f *Fixtures) TxGovSubmitParamChangeProposal( from, proposalPath string, deposit sdk.Coin, flags ...string, ) (bool, string, string)
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) (bool, string, string)
TxGovSubmitProposal is wasmcli tx gov submit-proposal
func (*Fixtures) TxGovVote ¶
func (f *Fixtures) TxGovVote(proposalID int, option gov.VoteOption, from string, flags ...string) (bool, string, string)
TxGovVote is wasmcli tx gov vote
func (*Fixtures) TxMultisign ¶
func (f *Fixtures) TxMultisign(fileName, name string, signaturesFiles []string, flags ...string) (bool, string, string)
TxMultisign is wasmcli tx multisign
func (*Fixtures) TxSend ¶
func (f *Fixtures) TxSend(from string, to sdk.AccAddress, amount sdk.Coin, flags ...string) (bool, string, string)
TxSend is wasmcli tx send
func (*Fixtures) TxStakingCreateValidator ¶
func (f *Fixtures) TxStakingCreateValidator(from, consPubKey string, amount sdk.Coin, flags ...string) (bool, string, string)
TxStakingCreateValidator is wasmcli tx staking create-validator
func (*Fixtures) TxStakingUnbond ¶
func (f *Fixtures) TxStakingUnbond(from, shares string, validator sdk.ValAddress, flags ...string) bool
TxStakingUnbond is wasmcli tx staking unbond
func (*Fixtures) UnsafeResetAll ¶
UnsafeResetAll is wasmd unsafe-reset-all
func (*Fixtures) ValidateGenesis ¶
func (f *Fixtures) ValidateGenesis()
ValidateGenesis runs wasmd validate-genesis