mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-11-15 04:25:27 +00:00
87 lines
2.0 KiB
Go
87 lines
2.0 KiB
Go
|
package keeper_test
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"strconv"
|
||
|
"testing"
|
||
|
|
||
|
sdkmath "cosmossdk.io/math"
|
||
|
"github.com/cosmos/cosmos-sdk/baseapp"
|
||
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||
|
"github.com/stretchr/testify/suite"
|
||
|
|
||
|
"github.com/kava-labs/kava/x/precisebank/keeper"
|
||
|
"github.com/kava-labs/kava/x/precisebank/testutil"
|
||
|
"github.com/kava-labs/kava/x/precisebank/types"
|
||
|
)
|
||
|
|
||
|
type grpcQueryTestSuite struct {
|
||
|
testutil.Suite
|
||
|
|
||
|
queryClient types.QueryClient
|
||
|
}
|
||
|
|
||
|
func (suite *grpcQueryTestSuite) SetupTest() {
|
||
|
suite.Suite.SetupTest()
|
||
|
|
||
|
queryHelper := baseapp.NewQueryServerTestHelper(suite.Ctx, suite.App.InterfaceRegistry())
|
||
|
types.RegisterQueryServer(queryHelper, keeper.NewQueryServerImpl(suite.Keeper))
|
||
|
|
||
|
suite.queryClient = types.NewQueryClient(queryHelper)
|
||
|
}
|
||
|
|
||
|
func TestGrpcQueryTestSuite(t *testing.T) {
|
||
|
suite.Run(t, new(grpcQueryTestSuite))
|
||
|
}
|
||
|
|
||
|
func (suite *grpcQueryTestSuite) TestQueryTotalFractionalBalance() {
|
||
|
testCases := []struct {
|
||
|
name string
|
||
|
giveBalances []sdkmath.Int
|
||
|
}{
|
||
|
{
|
||
|
"empty",
|
||
|
[]sdkmath.Int{},
|
||
|
},
|
||
|
{
|
||
|
"min amount",
|
||
|
[]sdkmath.Int{
|
||
|
types.ConversionFactor().QuoRaw(2),
|
||
|
types.ConversionFactor().QuoRaw(2),
|
||
|
},
|
||
|
},
|
||
|
{
|
||
|
"exceeds conversion factor",
|
||
|
[]sdkmath.Int{
|
||
|
// 4 accounts * 0.5 == 2
|
||
|
types.ConversionFactor().QuoRaw(2),
|
||
|
types.ConversionFactor().QuoRaw(2),
|
||
|
types.ConversionFactor().QuoRaw(2),
|
||
|
types.ConversionFactor().QuoRaw(2),
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
|
||
|
for _, tc := range testCases {
|
||
|
suite.Run(tc.name, func() {
|
||
|
suite.SetupTest()
|
||
|
|
||
|
total := sdk.NewCoin(types.ExtendedCoinDenom, sdkmath.ZeroInt())
|
||
|
for i, balance := range tc.giveBalances {
|
||
|
addr := sdk.AccAddress([]byte(strconv.Itoa(i)))
|
||
|
suite.Keeper.SetFractionalBalance(suite.Ctx, addr, balance)
|
||
|
|
||
|
total.Amount = total.Amount.Add(balance)
|
||
|
}
|
||
|
|
||
|
res, err := suite.queryClient.TotalFractionalBalances(
|
||
|
context.Background(),
|
||
|
&types.QueryTotalFractionalBalancesRequest{},
|
||
|
)
|
||
|
suite.Require().NoError(err)
|
||
|
|
||
|
suite.Require().Equal(total, res.Total)
|
||
|
})
|
||
|
}
|
||
|
}
|