From b2105d7732cef71e804cb2f960cc42004f7c5146 Mon Sep 17 00:00:00 2001 From: Sai Kumar Date: Wed, 3 Jul 2024 10:35:42 +0530 Subject: [PATCH] fix: fix the tests for app --- app/app.go | 2 +- app/wasm/test/umee_cw_test.go | 58 +--------------------------- sdkclient/query/client.go | 2 +- tests/e2e/e2e_ibc_test.go | 61 +++++++++++------------------- util/checkers/number_test.go | 12 +++--- util/store/store_test.go | 2 +- x/auction/codec.go | 2 +- x/auction/expected_keepers.go | 6 ++- x/auction/msgs_test.go | 6 +-- x/metoken/keeper/mocks_test.go | 2 +- x/oracle/types/utils_test.go | 6 +++ x/uibc/gmp/gmp_middleware_test.go | 2 +- x/uibc/uics20/memo_handler_test.go | 10 ++++- 13 files changed, 58 insertions(+), 113 deletions(-) diff --git a/app/app.go b/app/app.go index 0b615d1f03..c54fc5ac1d 100644 --- a/app/app.go +++ b/app/app.go @@ -108,7 +108,7 @@ import ( ibctransferkeeper "github.com/cosmos/ibc-go/v8/modules/apps/transfer/keeper" ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" ibc "github.com/cosmos/ibc-go/v8/modules/core" - ibcclienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" + ibcclienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" //nolint ibcconnectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types" ibcporttypes "github.com/cosmos/ibc-go/v8/modules/core/05-port/types" ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported" diff --git a/app/wasm/test/umee_cw_test.go b/app/wasm/test/umee_cw_test.go index e5a2964c2f..e4bcfeb098 100644 --- a/app/wasm/test/umee_cw_test.go +++ b/app/wasm/test/umee_cw_test.go @@ -4,13 +4,14 @@ import ( "encoding/json" "testing" - sdkmath "cosmossdk.io/math" wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" wasmvmtypes "github.com/CosmWasm/wasmvm/types" sdk "github.com/cosmos/cosmos-sdk/types" "gotest.tools/v3/assert" appparams "github.com/umee-network/umee/v6/app/params" + wq "github.com/umee-network/umee/v6/app/wasm/query" + "github.com/umee-network/umee/v6/x/incentive" lvtypes "github.com/umee-network/umee/v6/x/leverage/types" "github.com/umee-network/umee/v6/x/metoken" ) @@ -98,61 +99,6 @@ func (s *IntegrationTestSuite) TestStargateQueries() { } } -func (s *IntegrationTestSuite) TestLeverageTxs() { - accAddr := sdk.MustAccAddressFromBech32(s.contractAddr) - err := s.app.BankKeeper.SendCoinsFromModuleToAccount(s.ctx, minttypes.ModuleName, accAddr, sdk.NewCoins(sdk.NewCoin(appparams.BondDenom, sdkmath.NewInt(100000)))) - assert.NilError(s.T, err) - txTests := []struct { - Name string - Msg []byte - }{ - { - Name: "supply", - Msg: s.genCustomTx(wm.UmeeMsg{ - Supply: &lvtypes.MsgSupply{ - Supplier: s.contractAddr, - Asset: sdk.NewCoin(appparams.BondDenom, sdkmath.NewInt(700)), - }, - }), - }, - { - Name: "add collateral", - Msg: s.genCustomTx(wm.UmeeMsg{ - Collateralize: &lvtypes.MsgCollateralize{ - Borrower: s.contractAddr, - Asset: sdk.NewCoin("u/uumee", sdkmath.NewInt(700)), - }, - }), - }, - // { - // Name: "borrow", - // Msg: s.genCustomTx(wm.UmeeMsg{ - // Borrow: &lvtypes.MsgBorrow{ - // Borrower: addr2.String(), - // Asset: sdk.NewCoin(appparams.BondDenom, sdkmath.NewInt(150)), - // }, - // }), - // }, - } - - for _, tc := range txTests { - s.T.Run(tc.Name, func(t *testing.T) { - s.execContract(addr2, tc.Msg) - }) - } - - query := s.genCustomQuery(wq.UmeeQuery{ - AccountSummary: &lvtypes.QueryAccountSummary{ - Address: addr2.String(), - }, - }) - - resp := s.queryContract(query) - var rr lvtypes.QueryAccountSummaryResponse - err = json.Unmarshal(resp.Data, &rr) - assert.NilError(s.T, err) -} - func (s *IntegrationTestSuite) TestIncentiveQueries() { tests := []struct { Name string diff --git a/sdkclient/query/client.go b/sdkclient/query/client.go index 5f522b1294..e3317300b8 100644 --- a/sdkclient/query/client.go +++ b/sdkclient/query/client.go @@ -25,7 +25,7 @@ func NewClient(logger *log.Logger, grpcEndpoint string, queryTimeout time.Durati } func (c *Client) dialGrpcConn() (err error) { - c.GrpcConn, err = grpc.Dial( //nolint + c.GrpcConn, err = grpc.Dial( c.grpcEndpoint, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithContextDialer(dialerFunc), diff --git a/tests/e2e/e2e_ibc_test.go b/tests/e2e/e2e_ibc_test.go index 0e7a29afd0..3c14834200 100644 --- a/tests/e2e/e2e_ibc_test.go +++ b/tests/e2e/e2e_ibc_test.go @@ -85,8 +85,8 @@ func (s *E2ETest) checkSupply(endpoint, ibcDenom string, amount sdkmath.Int) { ) } -func (s *E2ETest) checkLeverageAccountBalance(endpoint, addr, ibcDenom string, amount math.Int) { - collateral := math.ZeroInt() +func (s *E2ETest) checkLeverageAccountBalance(endpoint, addr, ibcDenom string, amount sdkmath.Int) { + collateral := sdkmath.ZeroInt() var err error s.Require().Eventually( func() bool { @@ -105,17 +105,15 @@ func (s *E2ETest) checkLeverageAccountBalance(endpoint, addr, ibcDenom string, a } func (s *E2ETest) TestIBCTokenTransfer() { - // IBC inbound transfer of non x/leverage registered tokens must fail, because - // because we won't have price for it. + // IBC Inflow is enabled s.Run("send_stake_to_umee", func() { // require the recipient account receives the IBC tokens (IBC packets ACKd) umeeAPIEndpoint := s.UmeeREST() recipient := s.AccountAddr(0).String() token := sdk.NewInt64Coin("stake", 3300000000) // 3300stake - s.SendIBC(setup.GaiaChainID, s.Chain.ID, recipient, token, false, "") - // Zero, since not a registered token - s.checkSupply(umeeAPIEndpoint, stakeIBCHash, sdkmath.ZeroInt()) + s.SendIBC(setup.GaiaChainID, s.Chain.ID, recipient, token, "", "", "") + s.checkSupply(umeeAPIEndpoint, stakeIBCHash, token.Amount) }) s.Run("ibc_transfer_quota", func() { @@ -125,37 +123,24 @@ func (s *E2ETest) TestIBCTokenTransfer() { // totalQuota := sdkmath.NewInt(120) tokenQuota := sdkmath.NewInt(100) - var atomPrice sdkmath.LegacyDec - // compute the amount of ATOM sent from umee to gaia which would meet atom's token quota - s.Require().Eventually(func() bool { - var err error - atomPrice, err = s.QueryHistAvgPrice(umeeAPIEndpoint, atomSymbol) - if err != nil { - return false - } - return atomPrice.GT(sdkmath.LegacyOneDec()) - }, - 2*time.Minute, - 1*time.Second, - "price of atom should be greater than 1", - ) - - atomQuota := sdk.NewCoin(uatomIBCHash, - sdkmath.LegacyNewDecFromInt(tokenQuota).Quo(atomPrice).Mul(powerReduction).RoundInt(), - ) - - // IBC Inflow is enabled - s.Run("send_stake_to_umee", func() { - // require the recipient account receives the IBC tokens (IBC packets ACKd) - umeeAPIEndpoint := s.UmeeREST() - recipient := s.AccountAddr(0).String() - - token := sdk.NewInt64Coin("stake", 3300000000) // 3300stake - s.SendIBC(setup.GaiaChainID, s.Chain.ID, recipient, token, "", "", "") - s.checkSupply(umeeAPIEndpoint, stakeIBCHash, token.Amount) - }) + var atomPrice sdkmath.LegacyDec + // compute the amount of ATOM sent from umee to gaia which would meet atom's token quota + s.Require().Eventually(func() bool { + var err error + atomPrice, err = s.QueryHistAvgPrice(umeeAPIEndpoint, atomSymbol) + if err != nil { + return false + } + return atomPrice.GT(sdkmath.LegacyOneDec()) + }, + 2*time.Minute, + 1*time.Second, + "price of atom should be greater than 1", + ) - s.Run("ibc_transfer_quota", func() { + atomQuota := sdk.NewCoin(uatomIBCHash, + sdkmath.LegacyNewDecFromInt(tokenQuota).Quo(atomPrice).Mul(powerReduction).RoundInt(), + ) //<<<< INFLOW : gaia -> umee >> // send $500 ATOM from gaia to umee. (ibc_quota will not check token limit) atomFromGaia := mulCoin(atomQuota, "5.0") @@ -187,7 +172,7 @@ func (s *E2ETest) TestIBCTokenTransfer() { s.SendIBC(s.Chain.ID, setup.GaiaChainID, recvAddr, exceedUmee, "", "", "recipient address must not exceed 2048 bytes") // supply should not change - s.checkSupply(gaiaAPIEndpoint, umeeIBCHash, math.ZeroInt()) + s.checkSupply(gaiaAPIEndpoint, umeeIBCHash, sdkmath.ZeroInt()) // send $110 ATOM from umee to gaia exceedAtom := mulCoin(atomQuota, "1.1") diff --git a/util/checkers/number_test.go b/util/checkers/number_test.go index 9c0c2dec4f..b733363785 100644 --- a/util/checkers/number_test.go +++ b/util/checkers/number_test.go @@ -116,13 +116,13 @@ func TestNumPositive(t *testing.T) { assert.Error(BigNumPositive(tsdk.DecF(0), "")) assert.Error(BigNumPositive(tsdk.DecF(-0.01), "")) - assert.Error(BigNumPositive(sdk.NewDec(0), "")) - assert.Error(BigNumPositive(sdk.NewDec(-99999999999999999), "")) + assert.Error(BigNumPositive(sdkmath.LegacyNewDec(0), "")) + assert.Error(BigNumPositive(sdkmath.LegacyNewDec(-99999999999999999), "")) - assert.NoError(BigNumPositive(sdk.NewInt(1), "")) - assert.NoError(BigNumPositive(sdk.NewInt(2), "")) - assert.NoError(BigNumPositive(sdk.NewInt(9), "")) - n, ok := sdk.NewIntFromString("111111119999999999999999999") + assert.NoError(BigNumPositive(sdkmath.NewInt(1), "")) + assert.NoError(BigNumPositive(sdkmath.NewInt(2), "")) + assert.NoError(BigNumPositive(sdkmath.NewInt(9), "")) + n, ok := sdkmath.NewIntFromString("111111119999999999999999999") assert.True(ok) assert.NoError(BigNumPositive(n, "")) } diff --git a/util/store/store_test.go b/util/store/store_test.go index bb6707425c..d1ee361639 100644 --- a/util/store/store_test.go +++ b/util/store/store_test.go @@ -148,5 +148,5 @@ func uint32Key(id uint32) []byte { } func newCoin(denom string, amount int64) sdk.Coin { - return sdk.NewCoin(denom, sdk.NewInt(amount)) + return sdk.NewCoin(denom, sdkmath.NewInt(amount)) } diff --git a/x/auction/codec.go b/x/auction/codec.go index 82c8d4ad47..97d452feb6 100644 --- a/x/auction/codec.go +++ b/x/auction/codec.go @@ -13,7 +13,7 @@ import ( // encoding as Amino is still used for that purpose. var ( amino = codec.NewLegacyAmino() - ModuleCdc = codec.NewAminoCodec(amino) + ModuleCdc = amino ) func init() { diff --git a/x/auction/expected_keepers.go b/x/auction/expected_keepers.go index 0f456b1198..3e91bfae6b 100644 --- a/x/auction/expected_keepers.go +++ b/x/auction/expected_keepers.go @@ -11,6 +11,8 @@ type BankKeeper interface { BurnCoins(ctx context.Context, moduleName string, amounts sdk.Coins) error GetAllBalances(ctx context.Context, addr sdk.AccAddress) sdk.Coins SendCoins(ctx context.Context, fromAddr, toAddr sdk.AccAddress, amt sdk.Coins) error - SendCoinsFromAccountToModule(ctx context.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error - SendCoinsFromModuleToAccount(ctx context.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error + SendCoinsFromAccountToModule(ctx context.Context, senderAddr sdk.AccAddress, recipientModule string, + amt sdk.Coins) error + SendCoinsFromModuleToAccount(ctx context.Context, senderModule string, recipientAddr sdk.AccAddress, + amt sdk.Coins) error } diff --git a/x/auction/msgs_test.go b/x/auction/msgs_test.go index 88c4d9d8a3..b3ecc8b9e4 100644 --- a/x/auction/msgs_test.go +++ b/x/auction/msgs_test.go @@ -55,10 +55,10 @@ func TestMsgRewardsBid(t *testing.T) { invalid := validMsg invalid.Sender = "not a valid acc" invalid.Id = 0 - invalid.Amount.Amount = sdk.ZeroInt() + invalid.Amount.Amount = math.ZeroInt() invalidAmount1 := validMsg - invalidAmount1.Amount.Amount = sdk.NewInt(-100) + invalidAmount1.Amount.Amount = math.NewInt(-100) invalidDenom := validMsg invalidDenom.Amount.Denom = "other" @@ -84,7 +84,7 @@ func TestMsgRewardsBid(t *testing.T) { func TestValidateMin(t *testing.T) { t.Parallel() - min := sdk.NewInt(123) + min := math.NewInt(123) expectedErr := "bid amount must be at least 123uumee" umeeNegative := coin.Umee(0) umeeNegative.Amount = math.NewInt(-1) diff --git a/x/metoken/keeper/mocks_test.go b/x/metoken/keeper/mocks_test.go index 5db7d67292..e2ff1ba62e 100644 --- a/x/metoken/keeper/mocks_test.go +++ b/x/metoken/keeper/mocks_test.go @@ -106,7 +106,7 @@ func (b Bank) SendCoinsFromAccountToModule(_ context.Context, _ sdk.AccAddress, return nil } -func (b Bank) SendCoinsFromModuleToModule(ctx sdk.Context, senderModule, recipientModule string, amt sdk.Coins, +func (b Bank) SendCoinsFromModuleToModule(ctx context.Context, senderModule, recipientModule string, amt sdk.Coins, ) error { return nil } diff --git a/x/oracle/types/utils_test.go b/x/oracle/types/utils_test.go index 1cc199f296..ddd9233656 100644 --- a/x/oracle/types/utils_test.go +++ b/x/oracle/types/utils_test.go @@ -5,6 +5,7 @@ import ( "crypto/rand" "math/big" + addresscodec "cosmossdk.io/core/address" sdkmath "cosmossdk.io/math" storetypes "cosmossdk.io/store/types" "github.com/cometbft/cometbft/crypto/secp256k1" @@ -99,6 +100,7 @@ func GenerateRandomTestCase() (valValAddrs []sdk.ValAddress, stakingKeeper MockS // MockStakingKeeper implements the StakingKeeper interface. type MockStakingKeeper struct { validators []MockValidator + addrcdc addresscodec.Codec } func NewMockStakingKeeper(validators []MockValidator) MockStakingKeeper { @@ -107,6 +109,10 @@ func NewMockStakingKeeper(validators []MockValidator) MockStakingKeeper { } } +func (sk MockStakingKeeper) ValidatorAddressCodec() addresscodec.Codec { + return sk.addrcdc +} + func (sk MockStakingKeeper) Validators() []MockValidator { return sk.validators } diff --git a/x/uibc/gmp/gmp_middleware_test.go b/x/uibc/gmp/gmp_middleware_test.go index 8101c750ad..a60a1fa500 100644 --- a/x/uibc/gmp/gmp_middleware_test.go +++ b/x/uibc/gmp/gmp_middleware_test.go @@ -4,7 +4,7 @@ import ( "encoding/json" "testing" - "github.com/cometbft/cometbft/libs/log" + "cosmossdk.io/log" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" sdk "github.com/cosmos/cosmos-sdk/types" "gotest.tools/v3/assert" diff --git a/x/uibc/uics20/memo_handler_test.go b/x/uibc/uics20/memo_handler_test.go index 23f14aab9f..49eee58fe6 100644 --- a/x/uibc/uics20/memo_handler_test.go +++ b/x/uibc/uics20/memo_handler_test.go @@ -100,7 +100,10 @@ func TestValidateMemoMsg(t *testing.T) { for i, tc := range tcs { mh.receiver = receiver mh.received = sent - mh.msgs = tc.msgs + // todo: needs to find way to get msg.signer info + for _, msg := range tc.msgs { + mh.msgs = append(mh.msgs, msg.(sdk.LegacyMsg)) + } err := mh.validateMemoMsg() if tc.errstr != "" { assert.ErrorContains(err, tc.errstr, "test: %d", i) @@ -191,7 +194,10 @@ func TestMemoExecute(t *testing.T) { for i, tc := range tcs { mh.executeEnabled = tc.enabled mh.isGMP = tc.gmp - mh.msgs = tc.msgs + // mh.msgs = tc.msgs + for _, msg := range tc.msgs { + mh.msgs = append(mh.msgs, msg.(sdk.LegacyMsg)) + } err := mh.execute(&ctx) assert.ErrorIs(t, err, tc.err, i) }