Skip to content

Commit

Permalink
[BP: v7 <- #772] Add more testing, remove redundant (#828)
Browse files Browse the repository at this point in the history
* Add more testing, remove redundant (#772)

* Add a "misc" test example for cosmos_node

* backup: wip (adding node, wallet keys, sending, FindTxs, and PollForBal)

* enable more and cleanup

* feat: SetSDKConfig(bech32prefix) for configuration

* testBroadcaster with bank multimsg send

* qol: NewGenesisKV(key, value)

* more wallet checks

* queryCmd, HashCommand

* rm duplicate test, add outside references

* rm SDK 45 test, same logic applies to 47

* Add light client verification to the IBC example

* Add more IBC examples

* fix: wasm icq StartupFlags

* Add more buffer to the conformance test

(cherry picked from commit 8caf914)

# Conflicts:
#	examples/cosmos/chain_miscellaneous_test.go
#	examples/cosmos/light_client_test.go
#	examples/cosmos/state_sync_test.go
#	examples/ibc/interchain_accounts_test.go
#	examples/ibc/interchain_queries_test.go
#	examples/ibc/learn_ibc_test.go
#	examples/ibc/packet_forward_test.go

* fix merge -> `v7`

---------

Co-authored-by: Reece Williams <[email protected]>
Co-authored-by: Reece Williams <[email protected]>
  • Loading branch information
3 people authored Oct 17, 2023
1 parent 99b000e commit dd072db
Show file tree
Hide file tree
Showing 10 changed files with 317 additions and 20 deletions.
23 changes: 23 additions & 0 deletions chain/cosmos/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package cosmos

import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

func SetSDKConfig(bech32Prefix string) *sdk.Config {
var (
bech32MainPrefix = bech32Prefix
bech32PrefixAccAddr = bech32MainPrefix
bech32PrefixAccPub = bech32MainPrefix + sdk.PrefixPublic
bech32PrefixValAddr = bech32MainPrefix + sdk.PrefixValidator + sdk.PrefixOperator
bech32PrefixValPub = bech32MainPrefix + sdk.PrefixValidator + sdk.PrefixOperator + sdk.PrefixPublic
bech32PrefixConsAddr = bech32MainPrefix + sdk.PrefixValidator + sdk.PrefixConsensus
bech32PrefixConsPub = bech32MainPrefix + sdk.PrefixValidator + sdk.PrefixConsensus + sdk.PrefixPublic
)

cfg := sdk.GetConfig()
cfg.SetBech32PrefixForAccount(bech32PrefixAccAddr, bech32PrefixAccPub)
cfg.SetBech32PrefixForValidator(bech32PrefixValAddr, bech32PrefixValPub)
cfg.SetBech32PrefixForConsensusNode(bech32PrefixConsAddr, bech32PrefixConsPub)
return cfg
}
4 changes: 2 additions & 2 deletions chain/cosmos/cosmos_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -1057,7 +1057,7 @@ func (c *CosmosChain) Height(ctx context.Context) (uint64, error) {
// Acknowledgements implements ibc.Chain, returning all acknowledgments in block at height
func (c *CosmosChain) Acknowledgements(ctx context.Context, height uint64) ([]ibc.PacketAcknowledgement, error) {
var acks []*chanTypes.MsgAcknowledgement
err := rangeBlockMessages(ctx, c.cfg.EncodingConfig.InterfaceRegistry, c.getFullNode().Client, height, func(msg types.Msg) bool {
err := RangeBlockMessages(ctx, c.cfg.EncodingConfig.InterfaceRegistry, c.getFullNode().Client, height, func(msg types.Msg) bool {
found, ok := msg.(*chanTypes.MsgAcknowledgement)
if ok {
acks = append(acks, found)
Expand Down Expand Up @@ -1090,7 +1090,7 @@ func (c *CosmosChain) Acknowledgements(ctx context.Context, height uint64) ([]ib
// Timeouts implements ibc.Chain, returning all timeouts in block at height
func (c *CosmosChain) Timeouts(ctx context.Context, height uint64) ([]ibc.PacketTimeout, error) {
var timeouts []*chanTypes.MsgTimeout
err := rangeBlockMessages(ctx, c.cfg.EncodingConfig.InterfaceRegistry, c.getFullNode().Client, height, func(msg types.Msg) bool {
err := RangeBlockMessages(ctx, c.cfg.EncodingConfig.InterfaceRegistry, c.getFullNode().Client, height, func(msg types.Msg) bool {
found, ok := msg.(*chanTypes.MsgTimeout)
if ok {
timeouts = append(timeouts, found)
Expand Down
4 changes: 4 additions & 0 deletions chain/cosmos/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ type GenesisKV struct {
Value interface{} `json:"value"`
}

func NewGenesisKV(key string, value interface{}) GenesisKV {
return GenesisKV{Key: key, Value: value}
}

func ModifyGenesis(genesisKV []GenesisKV) func(ibc.ChainConfig, []byte) ([]byte, error) {
return func(chainConfig ibc.ChainConfig, genbz []byte) ([]byte, error) {
g := make(map[string]interface{})
Expand Down
4 changes: 2 additions & 2 deletions chain/cosmos/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ type blockClient interface {
Block(ctx context.Context, height *int64) (*tmtypes.ResultBlock, error)
}

// rangeBlockMessages iterates through all a block's transactions and each transaction's messages yielding to f.
// RangeBlockMessages iterates through all a block's transactions and each transaction's messages yielding to f.
// Return true from f to stop iteration.
func rangeBlockMessages(ctx context.Context, interfaceRegistry codectypes.InterfaceRegistry, client blockClient, height uint64, done func(sdk.Msg) bool) error {
func RangeBlockMessages(ctx context.Context, interfaceRegistry codectypes.InterfaceRegistry, client blockClient, height uint64, done func(sdk.Msg) bool) error {
h := int64(height)
block, err := client.Block(ctx, &h)
if err != nil {
Expand Down
10 changes: 9 additions & 1 deletion conformance/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,10 @@ func testPacketRelaySuccess(
req.NoError(err, "failed to get acknowledgement on destination chain")
req.NoError(dstAck.Validate(), "invalid acknowledgement on destination chain")

// Even though we poll for the ack, there may be timing issues where balances are not fully reconciled yet.
// So we have a small buffer here.
require.NoError(t, testutil.WaitForBlocks(ctx, 5, srcChain, dstChain))

// get ibc denom for dst denom on src chain
dstDenomTrace := transfertypes.ParseDenomTrace(transfertypes.GetPrefixedDenom(channels[i].PortID, channels[i].ChannelID, dstDenom))
srcIbcDenom := dstDenomTrace.IBCDenom()
Expand Down Expand Up @@ -496,7 +500,7 @@ func testPacketRelayFail(

// Even though we poll for the timeout, there may be timing issues where balances are not fully reconciled yet.
// So we have a small buffer here.
require.NoError(t, testutil.WaitForBlocks(ctx, 2, srcChain, dstChain))
require.NoError(t, testutil.WaitForBlocks(ctx, 5, srcChain, dstChain))

// get ibc denom for src denom on dst chain
srcDenomTrace := transfertypes.ParseDenomTrace(transfertypes.GetPrefixedDenom(channels[i].Counterparty.PortID, channels[i].Counterparty.ChannelID, srcDenom))
Expand Down Expand Up @@ -525,6 +529,10 @@ func testPacketRelayFail(
req.NoError(err, "failed to get timeout packet on destination chain")
req.NoError(timeout.Validate(), "invalid timeout packet on destination chain")

// Even though we poll for the timeout, there may be timing issues where balances are not fully reconciled yet.
// So we have a small buffer here.
require.NoError(t, testutil.WaitForBlocks(ctx, 5, srcChain, dstChain))

// get ibc denom for dst denom on src chain
dstDenomTrace := transfertypes.ParseDenomTrace(transfertypes.GetPrefixedDenom(channels[i].PortID, channels[i].ChannelID, dstDenom))
srcIbcDenom := dstDenomTrace.IBCDenom()
Expand Down
3 changes: 3 additions & 0 deletions examples/cosmos/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# More Examples

[State Sync](https://github.com/CosmosContracts/juno/blob/reece/add-state-sync-test/interchaintest/state_sync_test.go)
4 changes: 1 addition & 3 deletions examples/cosmos/chain_export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ import (
)

func TestJunoStateExport(t *testing.T) {
// SDK v45
CosmosChainStateExportTest(t, "juno", "v15.0.0")
// SDK v47
CosmosChainStateExportTest(t, "juno", "v16.0.0")
CosmosChainStateExportTest(t, "juno", "v17.0.0")
}

func CosmosChainStateExportTest(t *testing.T, name, version string) {
Expand Down
Loading

0 comments on commit dd072db

Please sign in to comment.