Skip to content

Commit

Permalink
fix: fix the tests for app
Browse files Browse the repository at this point in the history
  • Loading branch information
gsk967 committed Jul 3, 2024
1 parent 49e863e commit b2105d7
Show file tree
Hide file tree
Showing 13 changed files with 58 additions and 113 deletions.
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
58 changes: 2 additions & 56 deletions app/wasm/test/umee_cw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion sdkclient/query/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
61 changes: 23 additions & 38 deletions tests/e2e/e2e_ibc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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() {
Expand All @@ -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")
Expand Down Expand Up @@ -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")
Expand Down
12 changes: 6 additions & 6 deletions util/checkers/number_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, ""))
}
Expand Down
2 changes: 1 addition & 1 deletion util/store/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
2 changes: 1 addition & 1 deletion x/auction/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
6 changes: 4 additions & 2 deletions x/auction/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
6 changes: 3 additions & 3 deletions x/auction/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion x/metoken/keeper/mocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
6 changes: 6 additions & 0 deletions x/oracle/types/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion x/uibc/gmp/gmp_middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 8 additions & 2 deletions x/uibc/uics20/memo_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit b2105d7

Please sign in to comment.