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

02-client refactor: creating ValidateClientMessage fn for Header and Misbehaviour on 07-tendermint #1115

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
8f62a47
refactor: allow the mock module to be used multiple times as base ibc…
colin-axner Feb 10, 2022
843b459
feat: adding Pack/Unpack acknowledgement helper fns (#895)
seantking Feb 10, 2022
fb2f041
imp: support custom keys for testing (#893)
fedekunze Feb 10, 2022
c27d5b5
chore: add ParsePacketFromEvents testing helper function (#904)
colin-axner Feb 14, 2022
afa2d90
fix: correctly claim capability for mock module, handle genesis expor…
colin-axner Feb 15, 2022
d31f92d
docs: update migration docs for upgrade proposal in relation to ICS27…
colin-axner Feb 15, 2022
f442721
chore(ica): add trail of bits audit report (#903)
crodriguezvega Feb 16, 2022
20dd5ca
testing: adding multiple sender accounts for testing purposes (#935)
seantking Feb 17, 2022
98f4d3a
Create test chain with multiple validators (#942)
AdityaSripal Feb 17, 2022
52e3ae5
add changelog entry for SDK bump
crodriguezvega Feb 18, 2022
d48f576
fix: classify client states without consensus states as expired (#941)
timlind Feb 22, 2022
01cd4ad
chore: fix broken link (#972)
colin-axner Feb 22, 2022
9fcf254
add backport actions for v1.3.x and v2.1.x (#958)
crodriguezvega Feb 22, 2022
08d38d4
Revert "feat: adding Pack/Unpack acknowledgement helper fns (#895)" (…
colin-axner Feb 23, 2022
ef34765
chore: update migration docs (#985)
colin-axner Feb 23, 2022
556cc01
chore: fix mispelled words (#991)
seantking Feb 24, 2022
04ab3cb
fix: remove go mod tidy from proto-gen script (#989)
seantking Feb 24, 2022
4545154
bug: support base denoms with slashes (#978)
crodriguezvega Feb 28, 2022
9d8be7c
upgrade ics23 to v0.7 (#948)
crodriguezvega Feb 28, 2022
6d6888b
ibctesting: make `testing.T` public (#1020)
fedekunze Feb 28, 2022
e1be19b
add changelog entry for #941
crodriguezvega Mar 1, 2022
f994d1e
fix package import (#1007)
crodriguezvega Mar 1, 2022
147e0f1
feat: Add a function to initialize the ICS27 module via an upgrade pr…
colin-axner Mar 1, 2022
f71a505
docs: add missing args to NewKeeper in integration docs (#1038)
daeMOn63 Mar 3, 2022
a55ca88
small fixes for v2 to v3 migration (#1016)
crodriguezvega Mar 4, 2022
029c6e9
add missing slash
crodriguezvega Mar 4, 2022
7ae90c2
build(deps): bump actions/checkout from 2.4.0 to 3 (#1045)
dependabot[bot] Mar 7, 2022
fc452ac
call packet.GetSequence() rather than passing the func as argument (#…
Mar 7, 2022
13df199
Add counterpartyChannelID param to IBCModule.OnChanOpenAck (#1086)
catShaark Mar 9, 2022
90a7e5f
fix mirgation docs (#1091)
colin-axner Mar 9, 2022
a7563c9
fix: handle testing update client errors (#1094)
fedekunze Mar 9, 2022
f0b94df
replace channel keeper with IBC keeper in AnteDecorator (#950)
crodriguezvega Mar 10, 2022
d40f1da
add backport rules for v1.4.x and v2.2.x (#1085)
crodriguezvega Mar 10, 2022
c32e4be
ibctesting: custom voting power reduction for testing (#939)
fedekunze Mar 11, 2022
7ca5875
merging Header & Misbehavior interfaces into ClientMessage & fixing a…
seantking Mar 11, 2022
d59c886
fix: update related functions
seantking Mar 11, 2022
44bf918
Merge branch '02-client-refactor' into sean/issue#875-merge-misbehvio…
seantking Mar 11, 2022
c345354
chore: comments
seantking Mar 11, 2022
f45fd50
refactor: creating validateClientMessage fn for Header and Misbehaviour
seantking Mar 13, 2022
b76e338
refactor: exposing ValidateClientMessage as pub fn on ClientState type
seantking Mar 13, 2022
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
Prev Previous commit
Next Next commit
ibctesting: make testing.T public (#1020)
  • Loading branch information
fedekunze authored Feb 28, 2022
commit 6d6888b9c5cffc6b9c0f09ec5f77a8932d0b7e86
41 changes: 19 additions & 22 deletions testing/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ import (
"github.com/cosmos/ibc-go/v3/testing/simapp"
)

var (
MaxAccounts = 10
)
var MaxAccounts = 10

type SenderAccount struct {
SenderPrivKey cryptotypes.PrivKey
Expand All @@ -51,7 +49,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 {
t *testing.T
*testing.T

Coordinator *Coordinator
App TestingApp
Expand Down Expand Up @@ -88,7 +86,6 @@ type TestChain struct {
// CONTRACT: Validator and signer 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 []tmtypes.PrivValidator) *TestChain {

genAccs := []authtypes.GenesisAccount{}
genBals := []banktypes.Balance{}
senderAccs := []SenderAccount{}
Expand Down Expand Up @@ -129,7 +126,7 @@ func NewTestChainWithValSet(t *testing.T, coord *Coordinator, chainID string, va

// create an account to send transactions from
chain := &TestChain{
t: t,
T: t,
Coordinator: coord,
ChainID: chainID,
App: app,
Expand Down Expand Up @@ -191,7 +188,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.T, ok)

return app
}
Expand All @@ -213,10 +210,10 @@ func (chain *TestChain) QueryProofAtHeight(key []byte, height int64) ([]byte, cl
})

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

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

revision := clienttypes.ParseChainID(chain.ChainID)

Expand All @@ -237,10 +234,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.T, err)

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

revision := clienttypes.ParseChainID(chain.ChainID)

Expand Down Expand Up @@ -300,7 +297,7 @@ func (chain *TestChain) SendMsgs(msgs ...sdk.Msg) (*sdk.Result, error) {
chain.Coordinator.UpdateTimeForChain(chain)

_, r, err := simapp.SignAndDeliver(
chain.t,
chain.T,
chain.TxConfig,
chain.App.GetBaseApp(),
chain.GetContext().BlockHeader(),
Expand Down Expand Up @@ -329,7 +326,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.T, found)

return clientState
}
Expand Down Expand Up @@ -361,7 +358,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.T, found)

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

vsetHash := tmValSet.Hash()

Expand All @@ -461,7 +458,7 @@ func (chain *TestChain) CreateTMClientHeader(chainID string, blockHeight int64,
voteSet := tmtypes.NewVoteSet(chainID, blockHeight, 1, tmproto.PrecommitType, tmValSet)

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

signedHeader := &tmproto.SignedHeader{
Header: tmHeader.ToProto(),
Expand Down Expand Up @@ -533,11 +530,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.T, err)

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

chain.App.Commit()
Expand All @@ -549,7 +546,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.T, ok)

return cap
}
Expand All @@ -563,9 +560,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.T, err)
err = scopedKeeper.ClaimCapability(chain.GetContext(), cap, capName)
require.NoError(chain.t, err)
require.NoError(chain.T, err)
}

chain.App.Commit()
Expand All @@ -577,7 +574,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.T, ok)

return cap
}
26 changes: 13 additions & 13 deletions testing/coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var (
// Coordinator is a testing struct which contains N TestChain's. It handles keeping all chains
// in sync with regards to time.
type Coordinator struct {
t *testing.T
*testing.T

CurrentTime time.Time
Chains map[string]*TestChain
Expand All @@ -29,7 +29,7 @@ type Coordinator struct {
func NewCoordinator(t *testing.T, n int) *Coordinator {
chains := make(map[string]*TestChain)
coord := &Coordinator{
t: t,
T: t,
CurrentTime: globalStartTime,
}

Expand Down Expand Up @@ -84,10 +84,10 @@ func (coord *Coordinator) Setup(path *Path) {
// caller does not anticipate any errors.
func (coord *Coordinator) SetupClients(path *Path) {
err := path.EndpointA.CreateClient()
require.NoError(coord.t, err)
require.NoError(coord.T, err)

err = path.EndpointB.CreateClient()
require.NoError(coord.t, err)
require.NoError(coord.T, err)
}

// SetupClientConnections is a helper function to create clients and the appropriate
Expand All @@ -105,16 +105,16 @@ func (coord *Coordinator) SetupConnections(path *Path) {
// successfully opened otherwise testing will fail.
func (coord *Coordinator) CreateConnections(path *Path) {
err := path.EndpointA.ConnOpenInit()
require.NoError(coord.t, err)
require.NoError(coord.T, err)

err = path.EndpointB.ConnOpenTry()
require.NoError(coord.t, err)
require.NoError(coord.T, err)

err = path.EndpointA.ConnOpenAck()
require.NoError(coord.t, err)
require.NoError(coord.T, err)

err = path.EndpointB.ConnOpenConfirm()
require.NoError(coord.t, err)
require.NoError(coord.T, err)

// ensure counterparty is up to date
path.EndpointA.UpdateClient()
Expand Down Expand Up @@ -146,16 +146,16 @@ func (coord *Coordinator) CreateTransferChannels(path *Path) {
// opened otherwise testing will fail.
func (coord *Coordinator) CreateChannels(path *Path) {
err := path.EndpointA.ChanOpenInit()
require.NoError(coord.t, err)
require.NoError(coord.T, err)

err = path.EndpointB.ChanOpenTry()
require.NoError(coord.t, err)
require.NoError(coord.T, err)

err = path.EndpointA.ChanOpenAck()
require.NoError(coord.t, err)
require.NoError(coord.T, err)

err = path.EndpointB.ChanOpenConfirm()
require.NoError(coord.t, err)
require.NoError(coord.T, err)

// ensure counterparty is up to date
path.EndpointA.UpdateClient()
Expand All @@ -165,7 +165,7 @@ func (coord *Coordinator) CreateChannels(path *Path) {
// not exist.
func (coord *Coordinator) GetChain(chainID string) *TestChain {
chain, found := coord.Chains[chainID]
require.True(coord.t, found, fmt.Sprintf("%s chain does not exist", chainID))
require.True(coord.T, found, fmt.Sprintf("%s chain does not exist", chainID))
return chain
}

Expand Down
31 changes: 14 additions & 17 deletions testing/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (endpoint *Endpoint) CreateClient() (err error) {
switch endpoint.ClientConfig.GetClientType() {
case exported.Tendermint:
tmConfig, ok := endpoint.ClientConfig.(*TendermintConfig)
require.True(endpoint.Chain.t, ok)
require.True(endpoint.Chain.T, ok)

height := endpoint.Counterparty.Chain.LastHeader.GetHeight().(clienttypes.Height)
clientState = ibctmtypes.NewClientState(
Expand All @@ -98,7 +98,7 @@ func (endpoint *Endpoint) CreateClient() (err error) {
consensusState = endpoint.Counterparty.Chain.LastHeader.ConsensusState()
case exported.Solomachine:
// TODO
// solo := NewSolomachine(chain.t, endpoint.Chain.Codec, clientID, "", 1)
// solo := NewSolomachine(Chain.T, endpoint.Chain.Codec, clientID, "", 1)
// clientState = solo.ClientState()
// consensusState = solo.ConsensusState()

Expand All @@ -113,15 +113,15 @@ func (endpoint *Endpoint) CreateClient() (err error) {
msg, err := clienttypes.NewMsgCreateClient(
clientState, consensusState, endpoint.Chain.SenderAccount.GetAddress().String(),
)
require.NoError(endpoint.Chain.t, err)
require.NoError(endpoint.Chain.T, err)

res, err := endpoint.Chain.SendMsgs(msg)
if err != nil {
return err
}

endpoint.ClientID, err = ParseClientIDFromEvents(res.GetEvents())
require.NoError(endpoint.Chain.t, err)
require.NoError(endpoint.Chain.T, err)

return nil
}
Expand All @@ -131,9 +131,7 @@ func (endpoint *Endpoint) UpdateClient() (err error) {
// ensure counterparty has committed state
endpoint.Chain.Coordinator.CommitBlock(endpoint.Counterparty.Chain)

var (
header exported.Header
)
var header exported.Header

switch endpoint.ClientConfig.GetClientType() {
case exported.Tendermint:
Expand All @@ -151,10 +149,9 @@ func (endpoint *Endpoint) UpdateClient() (err error) {
endpoint.ClientID, header,
endpoint.Chain.SenderAccount.GetAddress().String(),
)
require.NoError(endpoint.Chain.t, err)
require.NoError(endpoint.Chain.T, err)

return endpoint.Chain.sendMsgs(msg)

}

// ConnOpenInit will construct and execute a MsgConnectionOpenInit on the associated endpoint.
Expand All @@ -171,7 +168,7 @@ func (endpoint *Endpoint) ConnOpenInit() error {
}

endpoint.ConnectionID, err = ParseConnectionIDFromEvents(res.GetEvents())
require.NoError(endpoint.Chain.t, err)
require.NoError(endpoint.Chain.T, err)

return nil
}
Expand All @@ -197,7 +194,7 @@ func (endpoint *Endpoint) ConnOpenTry() error {

if endpoint.ConnectionID == "" {
endpoint.ConnectionID, err = ParseConnectionIDFromEvents(res.GetEvents())
require.NoError(endpoint.Chain.t, err)
require.NoError(endpoint.Chain.T, err)
}

return nil
Expand Down Expand Up @@ -277,7 +274,7 @@ func (endpoint *Endpoint) ChanOpenInit() error {
}

endpoint.ChannelID, err = ParseChannelIDFromEvents(res.GetEvents())
require.NoError(endpoint.Chain.t, err)
require.NoError(endpoint.Chain.T, err)

return nil
}
Expand All @@ -303,7 +300,7 @@ func (endpoint *Endpoint) ChanOpenTry() error {

if endpoint.ChannelID == "" {
endpoint.ChannelID, err = ParseChannelIDFromEvents(res.GetEvents())
require.NoError(endpoint.Chain.t, err)
require.NoError(endpoint.Chain.T, err)
}

// update version to selected app version
Expand Down Expand Up @@ -449,7 +446,7 @@ func (endpoint *Endpoint) TimeoutPacket(packet channeltypes.Packet) error {

proof, proofHeight := endpoint.Counterparty.QueryProof(packetKey)
nextSeqRecv, found := endpoint.Counterparty.Chain.App.GetIBCKeeper().ChannelKeeper.GetNextSequenceRecv(endpoint.Counterparty.Chain.GetContext(), endpoint.ChannelConfig.PortID, endpoint.ChannelID)
require.True(endpoint.Chain.t, found)
require.True(endpoint.Chain.T, found)

timeoutMsg := channeltypes.NewMsgTimeout(
packet, nextSeqRecv,
Expand Down Expand Up @@ -486,7 +483,7 @@ func (endpoint *Endpoint) SetClientState(clientState exported.ClientState) {
// The consensus state is expected to exist otherwise testing will fail.
func (endpoint *Endpoint) GetConsensusState(height exported.Height) exported.ConsensusState {
consensusState, found := endpoint.Chain.GetConsensusState(endpoint.ClientID, height)
require.True(endpoint.Chain.t, found)
require.True(endpoint.Chain.T, found)

return consensusState
}
Expand All @@ -500,7 +497,7 @@ func (endpoint *Endpoint) SetConsensusState(consensusState exported.ConsensusSta
// connection is expected to exist otherwise testing will fail.
func (endpoint *Endpoint) GetConnection() connectiontypes.ConnectionEnd {
connection, found := endpoint.Chain.App.GetIBCKeeper().ConnectionKeeper.GetConnection(endpoint.Chain.GetContext(), endpoint.ConnectionID)
require.True(endpoint.Chain.t, found)
require.True(endpoint.Chain.T, found)

return connection
}
Expand All @@ -514,7 +511,7 @@ func (endpoint *Endpoint) SetConnection(connection connectiontypes.ConnectionEnd
// is expected to exist otherwise testing will fail.
func (endpoint *Endpoint) GetChannel() channeltypes.Channel {
channel, found := endpoint.Chain.App.GetIBCKeeper().ChannelKeeper.GetChannel(endpoint.Chain.GetContext(), endpoint.ChannelConfig.PortID, endpoint.ChannelID)
require.True(endpoint.Chain.t, found)
require.True(endpoint.Chain.T, found)

return channel
}
Expand Down