clitest

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2020 License: Apache-2.0 Imports: 27 Imported by: 0

README

Desmos CLI Integration tests

The desmos 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 desmosd and desmoscli 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 desmosd or desmoscli binaries are available in your $PATH. You can check which binary will be run by the suite by running which desmosd or which desmoscli. If you have your $GOPATH properly setup they should be in $GOPATH/bin/desmos*. 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 desmosd 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 .desmosd and .desmoscli folders in a new temp folder.
  • Uses desmoscli 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 desmosd 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 desmoscli and desmosd 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. desmoscli 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 desmosd and desmoscli processes that will interrupt subsequent runs. Still running desmoscli processes will block access to the keybase while still running desmosd processes will block ports and prevent new tests from spinning up. You can ensure new tests spin up clean by running pkill -9 desmosd && pkill -9 desmoscli 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 TestGaiaCLICreateValidator or TestGaiaCLISubmitProposal for a good example of the pattern.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WriteToNewTempFile

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

Write the given string to a new temporary file

Types

type Fixtures

type Fixtures struct {
	BuildDir        string
	RootDir         string
	DesmosBinary    string
	DesmoscliBinary string
	ChainID         string
	RPCAddr         string
	Port            string
	DesmosdHome     string
	DesmoscliHome   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 desmosd add-genesis-account

func (*Fixtures) CLIConfig

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

CLIConfig is desmoscli 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 desmosd collect-gentxs

func (*Fixtures) DDInit

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

DDInit is desmosd init NOTE: DDInit sets the ChainID for the Fixtures instance

func (*Fixtures) Flags

func (f *Fixtures) Flags() string

Flags returns the flags necessary for making most CLI calls

func (*Fixtures) GDStart

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

GDStart runs desmosd start with the appropriate flags and returns a process

func (*Fixtures) GDTendermint

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

GDTendermint returns the results of desmosd tendermint [query]

func (*Fixtures) GenTx

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

GenTx is desmosd gentx

func (Fixtures) GenesisFile

func (f Fixtures) GenesisFile() string

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

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

KeysAdd is desmoscli keys add

func (*Fixtures) KeysAddRecover

func (f *Fixtures) KeysAddRecover(name, mnemonic string, flags ...string) (exitSuccess bool, stdout, stderr string)

KeysAddRecover prepares desmoscli keys add --recover

func (*Fixtures) KeysAddRecoverHDPath

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

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

func (*Fixtures) KeysDelete

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

KeysDelete is desmoscli keys delete

func (*Fixtures) KeysShow

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

KeysShow is desmoscli keys show

func (*Fixtures) QueryAccount

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

QueryAccount is desmoscli query account

func (*Fixtures) QueryGovDeposit

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

QueryGovDeposit is desmoscli query gov deposit

func (*Fixtures) QueryGovDeposits

func (f *Fixtures) QueryGovDeposits(propsalID int, flags ...string) []gov.Deposit

QueryGovDeposits is desmoscli query gov deposits

func (*Fixtures) QueryGovParamDeposit

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

QueryGovParamDeposit is desmoscli query gov param deposit

func (*Fixtures) QueryGovParamTallying

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

QueryGovParamTallying is desmoscli query gov param tallying

func (*Fixtures) QueryGovParamVoting

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

QueryGovParamVoting is desmoscli query gov param voting

func (*Fixtures) QueryGovProposal

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

QueryGovProposal is desmoscli query gov proposal

func (*Fixtures) QueryGovProposals

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

QueryGovProposals is desmoscli query gov proposals

func (*Fixtures) QueryGovVote

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

QueryGovVote is desmoscli query gov vote

func (*Fixtures) QueryGovVotes

func (f *Fixtures) QueryGovVotes(proposalID int, flags ...string) []gov.Vote

QueryGovVotes is desmoscli query gov votes

func (*Fixtures) QueryPost

func (f *Fixtures) QueryPost(id string, flags ...string) postsTypes.PostQueryResponse

QueryPost returns a specific stored post

func (*Fixtures) QueryPosts

func (f *Fixtures) QueryPosts(flags ...string) postsTypes.Posts

QueryPosts returns stored posts

func (*Fixtures) QueryProfile added in v0.13.0

func (f *Fixtures) QueryProfile(address sdk.AccAddress, flags ...string) profilesTypes.Profile

QueryProfile returns stored profile

func (*Fixtures) QueryProfiles added in v0.4.0

func (f *Fixtures) QueryProfiles(flags ...string) profilesTypes.Profiles

QueryProfile returns stored profiles

func (*Fixtures) QueryReactions added in v0.4.0

func (f *Fixtures) QueryReactions(flags ...string) postsTypes.Reactions

QueryReactions returns registered reactions

func (*Fixtures) QueryRelationships added in v0.11.0

func (f *Fixtures) QueryRelationships(flags ...string) map[string]relationshipsTypes.Relationships

QueryRelationships queries all the relationships that are stored

func (*Fixtures) QueryReports added in v0.7.0

func (f *Fixtures) QueryReports(id string, flags ...string) reportsTypes.ReportsQueryResponse

QueryReports returns stored reports associated to the id given

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

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

QuerySlashingParams is desmoscli query slashing params

func (*Fixtures) QueryStakingDelegationsTo

func (f *Fixtures) QueryStakingDelegationsTo(valAddr sdk.ValAddress, flags ...string) []staking.Delegation

QueryStakingDelegationsTo is desmoscli query staking delegations-to

func (*Fixtures) QueryStakingParameters

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

QueryStakingParameters is desmoscli query staking parameters

func (*Fixtures) QueryStakingPool

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

QueryStakingPool is desmoscli query staking pool

func (*Fixtures) QueryStakingUnbondingDelegationsFrom

func (f *Fixtures) QueryStakingUnbondingDelegationsFrom(valAddr sdk.ValAddress, flags ...string) []staking.UnbondingDelegation

QueryStakingUnbondingDelegationsFrom is desmoscli query staking unbonding-delegations-from

func (*Fixtures) QueryStakingValidator

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

QueryStakingValidator is desmoscli query staking validator

func (*Fixtures) QueryTotalSupply

func (f *Fixtures) QueryTotalSupply(flags ...string) (totalSupply sdk.Coins)

QueryTotalSupply returns the total supply of coins

func (*Fixtures) QueryTotalSupplyOf

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

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 desmoscli query txs

func (*Fixtures) QueryTxsInvalid

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

QueryTxsInvalid query txs with wrong parameters and compare expected error

func (*Fixtures) QueryUserBlocks added in v0.12.0

func (f *Fixtures) QueryUserBlocks(user sdk.AccAddress, flags ...string) []relationshipsTypes.UserBlock

QueryUserBlocks returns store user blocks

func (*Fixtures) QueryUserDTagRequests added in v0.12.0

func (f *Fixtures) QueryUserDTagRequests(user sdk.AccAddress, flags ...string) []profilesTypes.DTagTransferRequest

QueryUserDTagRequests returns the user's stored requests

func (*Fixtures) QueryUserRelationships added in v0.13.0

func (f *Fixtures) QueryUserRelationships(user sdk.AccAddress, flags ...string) relationshipsTypes.Relationships

QueryUserRelationships returns stored relationships

func (*Fixtures) TxBlockUser added in v0.12.0

func (f *Fixtures) TxBlockUser(blockedUser sdk.AccAddress, subspace, reason string, from sdk.AccAddress, flags ...string) (bool, string, string)

func (*Fixtures) TxBroadcast

func (f *Fixtures) TxBroadcast(fileName string, flags ...string) (bool, string, string)

TxBroadcast is desmoscli tx broadcast

func (*Fixtures) TxCreateRelationship added in v0.11.0

func (f *Fixtures) TxCreateRelationship(receiver sdk.AccAddress, subspace string, from sdk.AccAddress, flags ...string) (bool, string, string)

___________________________________________________________________________________ desmoscli tx relationships

func (*Fixtures) TxDeleteUserRelationship added in v0.11.0

func (f *Fixtures) TxDeleteUserRelationship(receiver sdk.AccAddress, subspace string, from sdk.AccAddress, flags ...string) (bool, string, string)

func (*Fixtures) TxEncode

func (f *Fixtures) TxEncode(fileName string, flags ...string) (bool, string, string)

TxEncode is desmoscli tx encode

func (*Fixtures) TxGovDeposit

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

TxGovDeposit is desmoscli tx gov deposit

func (*Fixtures) TxGovSubmitProposal

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

TxGovSubmitProposal is desmoscli 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 desmoscli tx gov vote

func (*Fixtures) TxMultisign

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

TxMultisign is desmoscli tx multisign

func (*Fixtures) TxPostsAddReaction

func (f *Fixtures) TxPostsAddReaction(id string, reaction string, from sdk.AccAddress, flags ...string) (bool, string, string)

TxPostsAddReaction is desmoscli tx posts add-reaction

func (*Fixtures) TxPostsAnswerPoll

func (f *Fixtures) TxPostsAnswerPoll(pollID postsTypes.PostID, answers []postsTypes.AnswerID, from sdk.AccAddress, flags ...string) (bool, string, string)

TxPostsAnswerPoll is desmoscli tx posts answer-poll

func (*Fixtures) TxPostsCreate

func (f *Fixtures) TxPostsCreate(subspace, message string, from sdk.AccAddress, flags ...string) (bool, string, string)

TxPostsCreate is desmoscli tx posts create

func (*Fixtures) TxPostsEdit

func (f *Fixtures) TxPostsEdit(id string, message string, from sdk.AccAddress, flags ...string) (bool, string, string)

TxPostsEdit is desmoscli tx posts edit

func (*Fixtures) TxPostsRegisterReaction added in v0.4.0

func (f *Fixtures) TxPostsRegisterReaction(shortCode, value, subspace string, from sdk.AccAddress, flags ...string) (bool, string, string)

TxPostsRegisterReaction is desmoscli tx posts register-reaction

func (*Fixtures) TxPostsRemoveReaction

func (f *Fixtures) TxPostsRemoveReaction(id string, reaction string, from sdk.AccAddress, flags ...string) (bool, string, string)

TxPostsRemoveReaction is desmoscli tx posts remove-reaction

func (*Fixtures) TxProfileAcceptDTagTransfer added in v0.12.0

func (f *Fixtures) TxProfileAcceptDTagTransfer(newDtag string, receiver, from sdk.AccAddress, flags ...string) (bool, string, string)

func (*Fixtures) TxProfileCancelDTagTransfer added in v0.13.0

func (f *Fixtures) TxProfileCancelDTagTransfer(owner, from sdk.AccAddress, flags ...string) (bool, string, string)

func (*Fixtures) TxProfileDelete added in v0.4.0

func (f *Fixtures) TxProfileDelete(from sdk.AccAddress, flags ...string) (bool, string, string)

func (*Fixtures) TxProfileRefuseDTagTransfer added in v0.13.0

func (f *Fixtures) TxProfileRefuseDTagTransfer(sender, from sdk.AccAddress, flags ...string) (bool, string, string)

func (*Fixtures) TxProfileRequestDTagTransfer added in v0.12.0

func (f *Fixtures) TxProfileRequestDTagTransfer(owner, from sdk.AccAddress, flags ...string) (bool, string, string)

func (*Fixtures) TxProfileSave added in v0.6.1

func (f *Fixtures) TxProfileSave(dTag string, from sdk.AccAddress, flags ...string) (bool, string, string)

___________________________________________________________________________________ desmoscli tx profiles

func (*Fixtures) TxReportPost added in v0.7.0

func (f *Fixtures) TxReportPost(id, repType, repMess string, from sdk.AccAddress, flags ...string) (bool, string, string)

func (*Fixtures) TxSend

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

TxSend is desmoscli tx send

func (*Fixtures) TxSign

func (f *Fixtures) TxSign(signer, fileName string, flags ...string) (bool, string, string)

TxSign is desmoscli tx sign

func (*Fixtures) TxStakingCreateValidator

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

TxStakingCreateValidator is desmoscli tx staking create-validator

func (*Fixtures) TxStakingUnbond

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

TxStakingUnbond is desmoscli tx staking unbond

func (*Fixtures) TxUnblockUser added in v0.12.0

func (f *Fixtures) TxUnblockUser(blockedUser sdk.AccAddress, subspace string, from sdk.AccAddress, flags ...string) (bool, string, string)

func (*Fixtures) UnsafeResetAll

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

UnsafeResetAll is desmosd unsafe-reset-all

func (*Fixtures) ValidateGenesis

func (f *Fixtures) ValidateGenesis()

ValidateGenesis runs desmosd validate-genesis

Jump to

Keyboard shortcuts

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