Skip to content

Commit

Permalink
update ibctesting
Browse files Browse the repository at this point in the history
  • Loading branch information
hoank101 committed May 3, 2024
1 parent 9c1a5f3 commit 034cb02
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 48 deletions.
54 changes: 23 additions & 31 deletions app/ibctesting/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ibctesting

import (
"context"
errorsmod "cosmossdk.io/errors"
sdkmath "cosmossdk.io/math"
storetypes "cosmossdk.io/store/types"
"fmt"
Expand All @@ -17,7 +18,6 @@ import (

ratelimitmodulekeeper "github.com/notional-labs/composable/v6/x/ratelimit/keeper"

"cosmossdk.io/errors"
abci "github.com/cometbft/cometbft/abci/types"
"github.com/cometbft/cometbft/crypto/tmhash"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
Expand Down Expand Up @@ -177,19 +177,20 @@ func NewTestChain(t *testing.T, coord *Coordinator, appFactory ChainAppFactory,
txConfig := app.TxConfig()
// create an account to send transactions from
chain := &TestChain{
t: t,
Coordinator: coord,
ChainID: chainID,
App: app,
CurrentHeader: header,
QueryServer: app.GetIBCKeeper(),
TxConfig: txConfig,
Codec: app.AppCodec(),
Vals: valSet,
NextVals: valSet,
Signers: signers,
SenderPrivKey: senderPrivKey,
SenderAccount: acc,
t: t,
Coordinator: coord,
ChainID: chainID,
App: app,
CurrentHeader: header,
QueryServer: app.GetIBCKeeper(),
TxConfig: txConfig,
Codec: app.AppCodec(),
Vals: valSet,
NextVals: valSet,
Signers: signers,
SenderPrivKey: senderPrivKey,
SenderAccount: acc,
DefaultMsgFees: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.ZeroInt())),
}

baseapp.SetChainID(chain.ChainID)(chain.App.GetBaseApp())
Expand Down Expand Up @@ -590,13 +591,13 @@ func (chain *TestChain) GetPrefix() commitmenttypes.MerklePrefix {

// ConstructUpdateTMClientHeader will construct a valid 07-tendermint Header to update the
// light client on the source chain.
func (chain *TestChain) ConstructUpdateTMClientHeader(counterparty *TestChain, clientID string) (*ibctmtypes.Header, error) {
func (chain *TestChain) ConstructUpdateTMClientHeader(counterparty *TestChain, clientID string) (*ibctm.Header, error) {
return chain.ConstructUpdateTMClientHeaderWithTrustedHeight(counterparty, clientID, clienttypes.ZeroHeight())
}

// ConstructUpdateTMClientHeader will construct a valid 07-tendermint Header to update the
// ConstructUpdateTMClientHeaderWithTrustedHeight will construct a valid 07-tendermint Header to update the
// light client on the source chain.
func (chain *TestChain) ConstructUpdateTMClientHeaderWithTrustedHeight(counterparty *TestChain, clientID string, trustedHeight clienttypes.Height) (*ibctmtypes.Header, error) {
func (chain *TestChain) ConstructUpdateTMClientHeaderWithTrustedHeight(counterparty *TestChain, clientID string, trustedHeight clienttypes.Height) (*ibctm.Header, error) {
header := counterparty.LastHeader
// Relayer must query for LatestHeight on client to get TrustedHeight if the trusted height is not set
if trustedHeight.IsZero() {
Expand All @@ -606,21 +607,12 @@ func (chain *TestChain) ConstructUpdateTMClientHeaderWithTrustedHeight(counterpa
tmTrustedVals *cmttypes.ValidatorSet
ok bool
)
// Once we get TrustedHeight from client, we must query the validators from the counterparty chain
// If the LatestHeight == LastHeader.Height, then TrustedValidators are current validators
// If LatestHeight < LastHeader.Height, we can query the historical validator set from HistoricalInfo
if trustedHeight == counterparty.LastHeader.GetHeight() {
tmTrustedVals = counterparty.Vals
} else {
// NOTE: We need to get validators from counterparty at height: trustedHeight+1
// since the last trusted validators for a header at height h
// is the NextValidators at h+1 committed to in header h by
// NextValidatorsHash
tmTrustedVals, ok = counterparty.GetValsAtHeight(int64(trustedHeight.RevisionHeight + 1))
if !ok {
return nil, errors.Wrapf(ibctmtypes.ErrInvalidHeaderHeight, "could not retrieve trusted validators at trustedHeight: %d", trustedHeight)
}

tmTrustedVals, ok = counterparty.GetValsAtHeight(int64(trustedHeight.RevisionHeight))
if !ok {
return nil, errorsmod.Wrapf(ibctm.ErrInvalidHeaderHeight, "could not retrieve trusted validators at trustedHeight: %d", trustedHeight)
}

// inject trusted fields into last header
// for now assume revision number is 0
header.TrustedHeight = trustedHeight
Expand Down
2 changes: 0 additions & 2 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package keepers

import (
"fmt"
alliancemodulekeeper "github.com/terra-money/alliance/x/alliance/keeper"
"math"
"path/filepath"
"strings"
Expand Down Expand Up @@ -154,7 +153,6 @@ type AppKeepers struct {
GroupKeeper groupkeeper.Keeper
Wasm08Keeper wasm08Keeper.Keeper // TODO: use this name ?
WasmKeeper wasmkeeper.Keeper
AllianceKeeper alliancemodulekeeper.Keeper
IBCHooksKeeper *ibchookskeeper.Keeper
Ics20WasmHooks *ibc_hooks.WasmHooks
HooksICS4Wrapper ibc_hooks.ICS4Middleware
Expand Down
7 changes: 3 additions & 4 deletions app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import (
const (
SimAppChainID = ""
)
const DefaultGas = 1200000

func setup(withGenesis bool, chainID string, opts ...wasmkeeper.Option) (*ComposableApp, GenesisState) {
db := dbm.NewMemDB()
Expand Down Expand Up @@ -334,8 +335,6 @@ func CheckBalance(t *testing.T, app *ComposableApp, addr sdk.AccAddress, balance
require.True(t, balances.Equal(app.BankKeeper.GetAllBalances(ctxCheck, addr)))
}

const DefaultGas = 1200000

// SignCheckDeliver checks a generated signed transaction and simulates a
// block commitment with the given transaction. A test assertion is made using
// the parameter 'expPass' against the result. A corresponding result is
Expand Down Expand Up @@ -531,8 +530,8 @@ func SignAndDeliverWithoutCommit(t *testing.T, txCfg client.TxConfig, app *basea
rand.New(rand.NewSource(time.Now().UnixNano())),
txCfg,
msgs,
fees,
simtestutil.DefaultGenTxGas,
sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 0)},
2*DefaultGas,
chainID,
accNums,
accSeqs,
Expand Down
2 changes: 1 addition & 1 deletion custom/bank/bank_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func (suite *CustomBankTestSuite) TestTotalSupply() {
totalSupply, err := suite.chainB.GetBankKeeper().TotalSupply(suite.chainB.GetContext(), &banktypes.QueryTotalSupplyRequest{})
suite.Require().NoError(err)
suite.Require().Equal(totalSupply.Supply, originalChainBTotalSupply.Supply.Add(tc.expTotalSupplyDiff...))
suite.Require().Equal(totalSupply.Supply, tc.expChainBTotalSuppy)
suite.Require().Equal(totalSupply.Supply.String(), tc.expChainBTotalSuppy.String())
})
}
}
Expand Down
7 changes: 3 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/cosmos/ibc-apps/modules/async-icq/v8 v8.0.0
github.com/cosmos/ibc-go/modules/capability v1.0.0
github.com/cosmos/ibc-go/modules/light-clients/08-wasm v0.1.1-0.20231213092650-57fcdb9a9a9d
github.com/cosmos/ibc-go/v8 v8.1.1
github.com/cosmos/ibc-go/v8 v8.2.1
github.com/gogo/protobuf v1.3.3
github.com/golang/protobuf v1.5.4
github.com/golangci/golangci-lint v1.52.0
Expand All @@ -24,7 +24,6 @@ require (
github.com/spf13/cast v1.6.0
github.com/spf13/cobra v1.8.0
github.com/stretchr/testify v1.9.0
github.com/terra-money/alliance v0.4.3
golang.org/x/tools v0.18.0
google.golang.org/genproto/googleapis/api v0.0.0-20240221002015-b0ce06bbee7c
google.golang.org/grpc v1.62.1
Expand Down Expand Up @@ -360,10 +359,10 @@ replace (
// lock wasmvm so we do not break the grandpa contract
// TODO: check wasm vm compatibility with grandpa contract
github.com/CosmWasm/wasmvm => github.com/CosmWasm/wasmvm v1.5.2

github.com/cosmos/cosmos-sdk => github.com/notional-labs/cosmos-sdk v0.50.5-patch-validators-trim-tag

github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8 => github.com/notional-labs/ibc-apps/middleware/packet-forward-middleware/v8 v8.0.0-20240501060940-654293260efb
github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8 => github.com/notional-labs/ibc-apps/middleware/packet-forward-middleware/v8 v8.0.0-20240501114651-5399289a5ef2

// use cosmos-compatible protobufs
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1

Expand Down
10 changes: 4 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -828,8 +828,8 @@ github.com/cosmos/ibc-go/modules/capability v1.0.0 h1:r/l++byFtn7jHYa09zlAdSeevo
github.com/cosmos/ibc-go/modules/capability v1.0.0/go.mod h1:D81ZxzjZAe0ZO5ambnvn1qedsFQ8lOwtqicG6liLBco=
github.com/cosmos/ibc-go/modules/light-clients/08-wasm v0.1.1-0.20231213092650-57fcdb9a9a9d h1:F4mhR61RZU4KJ38n5CeZrnNINU/KxMfP1sKfk5fTlHA=
github.com/cosmos/ibc-go/modules/light-clients/08-wasm v0.1.1-0.20231213092650-57fcdb9a9a9d/go.mod h1:u2FXNcSxzzn5IwjWBA51HKMwiYMRK6/G35VmSJULhP0=
github.com/cosmos/ibc-go/v8 v8.1.1 h1:N2+GA86yACcXnKWCKtqdbCwP0/Eo8pH79+6e7TicULU=
github.com/cosmos/ibc-go/v8 v8.1.1/go.mod h1:o1ipS95xpdjqNcB8Drq0eI3Sn4FRLigjll42ec1ECuU=
github.com/cosmos/ibc-go/v8 v8.2.1 h1:MTsnZZjxvGD4Fv5pYyx5UkELafSX0rlPt6IfsE2BpTQ=
github.com/cosmos/ibc-go/v8 v8.2.1/go.mod h1:wj3qx75iC/XNnsMqbPDCIGs0G6Y3E/lo3bdqCyoCy+8=
github.com/cosmos/ics23/go v0.10.0 h1:iXqLLgp2Lp+EdpIuwXTYIQU+AiHj9mOC2X9ab++bZDM=
github.com/cosmos/ics23/go v0.10.0/go.mod h1:ZfJSmng/TBNTBkFemHHHj5YY7VAU/MBU980F4VU1NG0=
github.com/cosmos/keyring v1.1.7-0.20210622111912-ef00f8ac3d76 h1:DdzS1m6o/pCqeZ8VOAit/gyATedRgjvkVI+UCrLpyuU=
Expand Down Expand Up @@ -1387,8 +1387,8 @@ github.com/nishanths/predeclared v0.2.2 h1:V2EPdZPliZymNAn79T8RkNApBjMmVKh5XRpLm
github.com/nishanths/predeclared v0.2.2/go.mod h1:RROzoN6TnGQupbC+lqggsOlcgysk3LMK/HI84Mp280c=
github.com/notional-labs/cosmos-sdk v0.50.5-patch-validators-trim-tag h1:lnMn2O2zjUvLbWJuKY3yXtrkVzCXQ7r1/oS/tgCsyjU=
github.com/notional-labs/cosmos-sdk v0.50.5-patch-validators-trim-tag/go.mod h1:oV/k6GJgXV9QPoM2fsYDPPsyPBgQbdotv532O6Mz1OQ=
github.com/notional-labs/ibc-apps/middleware/packet-forward-middleware/v8 v8.0.0-20240501060940-654293260efb h1:v0XaNoHEI/yY0tONGtVR+DN7yxDanKL0LI24YpN3Fb8=
github.com/notional-labs/ibc-apps/middleware/packet-forward-middleware/v8 v8.0.0-20240501060940-654293260efb/go.mod h1:caFEYyFRCMVQdN9UsCC17apFxd/LSntCxEFpWIaDmr4=
github.com/notional-labs/ibc-apps/middleware/packet-forward-middleware/v8 v8.0.0-20240501114651-5399289a5ef2 h1:3O/frX6x3SMOmVtJnn1BK9IFxL4U2WTlnk2vjVTYUwM=
github.com/notional-labs/ibc-apps/middleware/packet-forward-middleware/v8 v8.0.0-20240501114651-5399289a5ef2/go.mod h1:caFEYyFRCMVQdN9UsCC17apFxd/LSntCxEFpWIaDmr4=
github.com/nunnatsa/ginkgolinter v0.9.0 h1:Sm0zX5QfjJzkeCjEp+t6d3Ha0jwvoDjleP9XCsrEzOA=
github.com/nunnatsa/ginkgolinter v0.9.0/go.mod h1:FHaMLURXP7qImeH6bvxWJUpyH+2tuqe5j4rW1gxJRmI=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
Expand Down Expand Up @@ -1598,8 +1598,6 @@ github.com/tenntenn/modver v1.0.1 h1:2klLppGhDgzJrScMpkj9Ujy3rXPUspSjAcev9tSEBgA
github.com/tenntenn/modver v1.0.1/go.mod h1:bePIyQPb7UeioSRkw3Q0XeMhYZSMx9B8ePqg6SAMGH0=
github.com/tenntenn/text/transform v0.0.0-20200319021203-7eef512accb3 h1:f+jULpRQGxTSkNYKJ51yaw6ChIqO+Je8UqsTKN/cDag=
github.com/tenntenn/text/transform v0.0.0-20200319021203-7eef512accb3/go.mod h1:ON8b8w4BN/kE1EOhwT0o+d62W65a6aPw1nouo9LMgyY=
github.com/terra-money/alliance v0.4.3 h1:vlTsGkXOO78T8SJHjSQshbiTw7WSdieybWMOYsWyTmY=
github.com/terra-money/alliance v0.4.3/go.mod h1:ljXUIs49+2gHHbNljOoLrIaYV+1QHthS3vdtA7hODe0=
github.com/tetafro/godot v1.4.11 h1:BVoBIqAf/2QdbFmSwAWnaIqDivZdOV0ZRwEm6jivLKw=
github.com/tetafro/godot v1.4.11/go.mod h1:LR3CJpxDVGlYOWn3ZZg1PgNZdTUvzsZWu8xaEohUpn8=
github.com/tidwall/btree v1.7.0 h1:L1fkJH/AuEh5zBnnBbmTwQ5Lt+bRJ5A8EWecslvo9iI=
Expand Down

0 comments on commit 034cb02

Please sign in to comment.