Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

imp(testing): use testing.TB instead of testing.T #3138

Merged
merged 4 commits into from
Feb 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Improvements

* (tests) [\#3138](https://github.com/cosmos/ibc-go/pull/3138) Support benchmarks and fuzz tests through `testing.TB`.
* (core) [\#3082](https://github.com/cosmos/ibc-go/pull/3082) Add `HasConnection` and `HasChannel` methods.
* (tests) [\#2926](https://github.com/cosmos/ibc-go/pull/2926) Lint tests
* (apps/transfer) [\#2643](https://github.com/cosmos/ibc-go/pull/2643) Add amount, denom, and memo to transfer event emission.
Expand Down
2 changes: 1 addition & 1 deletion modules/core/ante/ante_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func (suite *AnteTestSuite) createUpdateClientMessage() sdk.Msg {
endpoint.ClientID, header,
endpoint.Chain.SenderAccount.GetAddress().String(),
)
require.NoError(endpoint.Chain.T, err)
require.NoError(endpoint.Chain.TB, err)

return msg
}
Expand Down
2 changes: 1 addition & 1 deletion testing/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func SetupTestingApp() (TestingApp, map[string]json.RawMessage) {
// that also act as delegators. For simplicity, each validator is bonded with a delegation
// of one consensus engine unit (10^6) in the default token of the simapp from first genesis
// account. A Nop logger is set in SimApp.
func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs []authtypes.GenesisAccount, chainID string, powerReduction math.Int, balances ...banktypes.Balance) TestingApp {
func SetupWithGenesisValSet(t testing.TB, valSet *tmtypes.ValidatorSet, genAccs []authtypes.GenesisAccount, chainID string, powerReduction math.Int, balances ...banktypes.Balance) TestingApp {
app, genesisState := DefaultTestingAppInit()

// set genesis accounts
Expand Down
51 changes: 25 additions & 26 deletions testing/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type SenderAccount struct {
// is used for delivering transactions through the application state.
// NOTE: the actual application uses an empty chain-id for ease of testing.
type TestChain struct {
*testing.T
testing.TB

Coordinator *Coordinator
App TestingApp
Expand Down Expand Up @@ -91,7 +91,7 @@ type TestChain struct {
//
// CONTRACT: Validator array must be provided in the order expected by Tendermint.
// i.e. sorted first by power and then lexicographically by address.
func NewTestChainWithValSet(t *testing.T, coord *Coordinator, chainID string, valSet *tmtypes.ValidatorSet, signers map[string]tmtypes.PrivValidator) *TestChain {
func NewTestChainWithValSet(tb testing.TB, coord *Coordinator, chainID string, valSet *tmtypes.ValidatorSet, signers map[string]tmtypes.PrivValidator) *TestChain {
genAccs := []authtypes.GenesisAccount{}
genBals := []banktypes.Balance{}
senderAccs := []SenderAccount{}
Expand All @@ -101,7 +101,7 @@ func NewTestChainWithValSet(t *testing.T, coord *Coordinator, chainID string, va
senderPrivKey := secp256k1.GenPrivKey()
acc := authtypes.NewBaseAccount(senderPrivKey.PubKey().Address().Bytes(), senderPrivKey.PubKey(), uint64(i), 0)
amount, ok := sdk.NewIntFromString("10000000000000000000")
require.True(t, ok)
require.True(tb, ok)

// add sender account
balance := banktypes.Balance{
Expand All @@ -120,7 +120,7 @@ func NewTestChainWithValSet(t *testing.T, coord *Coordinator, chainID string, va
senderAccs = append(senderAccs, senderAcc)
}

app := SetupWithGenesisValSet(t, valSet, genAccs, chainID, sdk.DefaultPowerReduction, genBals...)
app := SetupWithGenesisValSet(tb, valSet, genAccs, chainID, sdk.DefaultPowerReduction, genBals...)

// create current header and call begin block
header := tmproto.Header{
Expand All @@ -133,7 +133,7 @@ func NewTestChainWithValSet(t *testing.T, coord *Coordinator, chainID string, va

// create an account to send transactions from
chain := &TestChain{
T: t,
TB: tb,
Coordinator: coord,
ChainID: chainID,
App: app,
Expand Down Expand Up @@ -190,7 +190,7 @@ func (chain *TestChain) GetContext() sdk.Context {
// their own SimApp.
func (chain *TestChain) GetSimApp() *simapp.SimApp {
app, ok := chain.App.(*simapp.SimApp)
require.True(chain.T, ok)
require.True(chain.TB, ok)

return app
}
Expand Down Expand Up @@ -219,10 +219,10 @@ func (chain *TestChain) QueryProofForStore(storeKey string, key []byte, height i
})

merkleProof, err := commitmenttypes.ConvertProofs(res.ProofOps)
require.NoError(chain.T, err)
require.NoError(chain.TB, err)

proof, err := chain.App.AppCodec().Marshal(&merkleProof)
require.NoError(chain.T, err)
require.NoError(chain.TB, err)

revision := clienttypes.ParseChainID(chain.ChainID)

Expand All @@ -243,10 +243,10 @@ func (chain *TestChain) QueryUpgradeProof(key []byte, height uint64) ([]byte, cl
})

merkleProof, err := commitmenttypes.ConvertProofs(res.ProofOps)
require.NoError(chain.T, err)
require.NoError(chain.TB, err)

proof, err := chain.App.AppCodec().Marshal(&merkleProof)
require.NoError(chain.T, err)
require.NoError(chain.TB, err)

revision := clienttypes.ParseChainID(chain.ChainID)

Expand Down Expand Up @@ -286,7 +286,7 @@ func (chain *TestChain) NextBlock() {
// val set changes returned from previous block get applied to the next validators
// of this block. See tendermint spec for details.
chain.Vals = chain.NextVals
chain.NextVals = ApplyValSetChanges(chain.T, chain.Vals, res.ValidatorUpdates)
chain.NextVals = ApplyValSetChanges(chain.TB, chain.Vals, res.ValidatorUpdates)

// increment the current header
chain.CurrentHeader = tmproto.Header{
Expand Down Expand Up @@ -318,15 +318,14 @@ func (chain *TestChain) SendMsgs(msgs ...sdk.Msg) (*sdk.Result, error) {
chain.Coordinator.UpdateTimeForChain(chain)

_, r, err := simapp.SignAndDeliver(
chain.T,
chain.TB,
chain.TxConfig,
chain.App.GetBaseApp(),
chain.GetContext().BlockHeader(),
msgs,
chain.ChainID,
[]uint64{chain.SenderAccount.GetAccountNumber()},
[]uint64{chain.SenderAccount.GetSequence()},
true, true, chain.SenderPrivKey,
true, chain.SenderPrivKey,
)
if err != nil {
return nil, err
Expand All @@ -350,7 +349,7 @@ func (chain *TestChain) SendMsgs(msgs ...sdk.Msg) (*sdk.Result, error) {
// expected to exist otherwise testing will fail.
func (chain *TestChain) GetClientState(clientID string) exported.ClientState {
clientState, found := chain.App.GetIBCKeeper().ClientKeeper.GetClientState(chain.GetContext(), clientID)
require.True(chain.T, found)
require.True(chain.TB, found)

return clientState
}
Expand Down Expand Up @@ -382,7 +381,7 @@ func (chain *TestChain) GetValsAtHeight(height int64) (*tmtypes.ValidatorSet, bo
// acknowledgement does not exist then testing will fail.
func (chain *TestChain) GetAcknowledgement(packet exported.PacketI) []byte {
ack, found := chain.App.GetIBCKeeper().ChannelKeeper.GetPacketAcknowledgement(chain.GetContext(), packet.GetDestPort(), packet.GetDestChannel(), packet.GetSequence())
require.True(chain.T, found)
require.True(chain.TB, found)

return ack
}
Expand Down Expand Up @@ -457,7 +456,7 @@ func (chain *TestChain) CreateTMClientHeader(chainID string, blockHeight int64,
valSet *tmproto.ValidatorSet
trustedVals *tmproto.ValidatorSet
)
require.NotNil(chain.T, tmValSet)
require.NotNil(chain.TB, tmValSet)

vsetHash := tmValSet.Hash()
nextValHash := nextVals.Hash()
Expand Down Expand Up @@ -492,7 +491,7 @@ func (chain *TestChain) CreateTMClientHeader(chainID string, blockHeight int64,
}

commit, err := tmtypes.MakeCommit(blockID, blockHeight, 1, voteSet, signerArr, timestamp)
require.NoError(chain.T, err)
require.NoError(chain.TB, err)

signedHeader := &tmproto.SignedHeader{
Header: tmHeader.ToProto(),
Expand All @@ -501,12 +500,12 @@ func (chain *TestChain) CreateTMClientHeader(chainID string, blockHeight int64,

if tmValSet != nil { //nolint:staticcheck
valSet, err = tmValSet.ToProto()
require.NoError(chain.T, err)
require.NoError(chain.TB, err)
}

if tmTrustedVals != nil {
trustedVals, err = tmTrustedVals.ToProto()
require.NoError(chain.T, err)
require.NoError(chain.TB, err)
}

// The trusted fields may be nil. They may be filled before relaying messages to a client.
Expand Down Expand Up @@ -540,11 +539,11 @@ func (chain *TestChain) CreatePortCapability(scopedKeeper capabilitykeeper.Scope
if !ok {
// create capability using the IBC capability keeper
cap, err := chain.App.GetScopedIBCKeeper().NewCapability(chain.GetContext(), host.PortPath(portID))
require.NoError(chain.T, err)
require.NoError(chain.TB, err)

// claim capability using the scopedKeeper
err = scopedKeeper.ClaimCapability(chain.GetContext(), cap, host.PortPath(portID))
require.NoError(chain.T, err)
require.NoError(chain.TB, err)
}

chain.NextBlock()
Expand All @@ -554,7 +553,7 @@ func (chain *TestChain) CreatePortCapability(scopedKeeper capabilitykeeper.Scope
// exist, otherwise testing will fail.
func (chain *TestChain) GetPortCapability(portID string) *capabilitytypes.Capability {
cap, ok := chain.App.GetScopedIBCKeeper().GetCapability(chain.GetContext(), host.PortPath(portID))
require.True(chain.T, ok)
require.True(chain.TB, ok)

return cap
}
Expand All @@ -568,9 +567,9 @@ func (chain *TestChain) CreateChannelCapability(scopedKeeper capabilitykeeper.Sc
_, ok := chain.App.GetScopedIBCKeeper().GetCapability(chain.GetContext(), capName)
if !ok {
cap, err := chain.App.GetScopedIBCKeeper().NewCapability(chain.GetContext(), capName)
require.NoError(chain.T, err)
require.NoError(chain.TB, err)
err = scopedKeeper.ClaimCapability(chain.GetContext(), cap, capName)
require.NoError(chain.T, err)
require.NoError(chain.TB, err)
}

chain.NextBlock()
Expand All @@ -580,7 +579,7 @@ func (chain *TestChain) CreateChannelCapability(scopedKeeper capabilitykeeper.Sc
// The capability must exist, otherwise testing will fail.
func (chain *TestChain) GetChannelCapability(portID, channelID string) *capabilitytypes.Capability {
cap, ok := chain.App.GetScopedIBCKeeper().GetCapability(chain.GetContext(), host.ChannelCapabilityPath(portID, channelID))
require.True(chain.T, ok)
require.True(chain.TB, ok)

return cap
}
Expand Down
Loading