Skip to content

Commit

Permalink
Add pfm upgrade test
Browse files Browse the repository at this point in the history
  • Loading branch information
drklee3 committed Feb 13, 2025
1 parent 5fd3a13 commit 3c2c3ce
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 5 deletions.
3 changes: 3 additions & 0 deletions client/grpc/query/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
ibcclienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
ibcchanneltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
evmtypes "github.com/evmos/ethermint/x/evm/types"
feemarkettypes "github.com/evmos/ethermint/x/feemarket/types"

Expand Down Expand Up @@ -66,6 +67,7 @@ type QueryClient struct {
Evm evmtypes.QueryClient
Feemarket feemarkettypes.QueryClient
IbcClient ibcclienttypes.QueryClient
IbcChannel ibcchanneltypes.QueryClient
IbcTransfer ibctransfertypes.QueryClient

// kava module query clients
Expand Down Expand Up @@ -113,6 +115,7 @@ func NewQueryClient(grpcEndpoint string) (*QueryClient, error) {
Evm: evmtypes.NewQueryClient(conn),
Feemarket: feemarkettypes.NewQueryClient(conn),
IbcClient: ibcclienttypes.NewQueryClient(conn),
IbcChannel: ibcchanneltypes.NewQueryClient(conn),
IbcTransfer: ibctransfertypes.NewQueryClient(conn),

Auction: auctiontypes.NewQueryClient(conn),
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/.env
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ E2E_RUN_KVTOOL_NETWORKS=true
E2E_KVTOOL_KAVA_CONFIG_TEMPLATE="v0.27"

# E2E_INCLUDE_IBC_TESTS when true will start a 2nd chain & open an IBC channel. It will enable all IBC tests.
E2E_INCLUDE_IBC_TESTS=true
E2E_INCLUDE_IBC_TESTS=false

# E2E_SKIP_SHUTDOWN when true will keep the networks running after tests complete (pass or fail)
# This is useful for debugging chain state when writing tests.
Expand Down
5 changes: 5 additions & 0 deletions tests/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,17 @@ func (suite *IntegrationTestSuite) TestIbcTransfer() {
// the balance should be deducted from kava account
suite.Eventually(func() bool {
balance := suite.Kava.QuerySdkForBalances(kavaAcc.SdkAddress)
suite.T().Logf("kava balances: %s, expected equal: %s", balance.AmountOf("kava"), expectedSrcBalance)

return balance.AmountOf("ukava").Equal(expectedSrcBalance.Amount)
}, 10*time.Second, 1*time.Second)

// expect the balance to be transferred to the ibc chain!
suite.Eventually(func() bool {
balance := suite.Ibc.QuerySdkForBalances(ibcAcc.SdkAddress)

suite.T().Logf("ibc balances: %s, expected to include: %s", balance, fundsToSend)

found := false
for _, c := range balance {
// find the ibc denom coin
Expand Down
22 changes: 19 additions & 3 deletions tests/e2e/e2e_upgrade_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/query"
ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
ibcchanneltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"

Expand All @@ -19,10 +20,16 @@ func (suite *IntegrationTestSuite) getEscrowAccountBalances(

channelsRes, err := grpcClient.Query.IbcChannel.Channels(
ctx,
&ibcchanneltypes.QueryChannelsRequest{},
&ibcchanneltypes.QueryChannelsRequest{
Pagination: &query.PageRequest{
Limit: 1000,
},
},
)
suite.Require().NoError(err)

suite.T().Logf("found %d IBC channels", len(channelsRes.Channels))

escrowBals := make(map[string]sdk.Coins)
totalEscrowBal := sdk.Coins{}

Expand All @@ -36,6 +43,12 @@ func (suite *IntegrationTestSuite) getEscrowAccountBalances(
)
suite.Require().NoError(err)

// Check if escrow addr already exists in map
if _, ok := escrowBals[escrowAddress.String()]; ok {
suite.T().Logf("escrow address %s already exists in map", escrowAddress.String())
continue
}

escrowBalances, err := grpcClient.Query.Bank.AllBalances(ctx, &banktypes.QueryAllBalancesRequest{
Address: escrowAddress.EscrowAddress,
})
Expand Down Expand Up @@ -100,9 +113,12 @@ func (suite *IntegrationTestSuite) TestPfmUpgrade() {
suite.T().Logf("escrowBankBalsAfter: %s", escrowBankBalsAfter)

// Balances in escrow STATE, not bank
escrowStateAfter := suite.getEscrowStateBalances(afterUpgradeCtx, totalBankEscrowBefore)
escrowStateAfter := suite.getEscrowStateBalances(afterUpgradeCtx, totalBankEscrowAfter)
suite.T().Logf("escrowStateAfter: %s", escrowStateAfter)

// Bank balances should stay unchanged before/after upgrade
suite.Require().Equal(totalBankEscrowBefore, totalBankEscrowAfter, "bank balances should stay the same after upgrade")

// Post-upgrade, escrow bank balances should match escrow state
suite.Require().Equal(escrowStateAfter, totalBankEscrowAfter, "escrow mismatch after upgrade")
suite.Require().Equal(escrowStateAfter, totalBankEscrowAfter, "escrow state/balance mismatch after upgrade")
}

0 comments on commit 3c2c3ce

Please sign in to comment.