-
Notifications
You must be signed in to change notification settings - Fork 228
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: test code for distribution & mstaking msg server (#192)
* [Test] Test code distribution - msg server - custom msg server - grpc query server mstaking - msg server * fix: custom_msg_server_test
- Loading branch information
Showing
6 changed files
with
691 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package keeper_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"cosmossdk.io/math" | ||
"github.com/cosmos/cosmos-sdk/types" | ||
"github.com/initia-labs/initia/x/distribution/keeper" | ||
customTypes "github.com/initia-labs/initia/x/distribution/types" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestDepositValidatorRewardsPool(t *testing.T) { | ||
ctx, keepers := createDefaultTestInput(t) | ||
customMsgServer := keeper.NewCustomMsgServerImpl(keepers.DistKeeper) | ||
_, _, depositor := keyPubAddr() | ||
keepers.Faucet.Mint(ctx, depositor, types.NewCoin("uinit", math.NewInt(20))) | ||
val := createValidatorWithBalance(ctx, keepers, 100, 100, 1) | ||
|
||
cases := []struct { | ||
name string | ||
msg *customTypes.MsgDepositValidatorRewardsPool | ||
resp *customTypes.MsgDepositValidatorRewardsPoolResponse | ||
errMsg string | ||
}{ | ||
{ | ||
name: "success", | ||
msg: &customTypes.MsgDepositValidatorRewardsPool{ | ||
Depositor: depositor.String(), | ||
ValidatorAddress: val.String(), | ||
Denom: "uinit", | ||
Amount: types.NewCoins(types.NewCoin("uinit", math.NewInt(10))), | ||
}, | ||
|
||
resp: &customTypes.MsgDepositValidatorRewardsPoolResponse{}, | ||
errMsg: "", | ||
}, | ||
{ | ||
name: "invalid depositor address", | ||
msg: &customTypes.MsgDepositValidatorRewardsPool{ | ||
Depositor: "invalid", | ||
ValidatorAddress: val.String(), | ||
Denom: "uinit", | ||
Amount: types.NewCoins(types.NewCoin("uinit", math.NewInt(10))), | ||
}, | ||
resp: &customTypes.MsgDepositValidatorRewardsPoolResponse{}, | ||
errMsg: "decoding bech32 failed: invalid bech32 string length 7", | ||
}, | ||
{ | ||
name: "invalid validaor address", | ||
msg: &customTypes.MsgDepositValidatorRewardsPool{ | ||
Depositor: depositor.String(), | ||
ValidatorAddress: "invalid", | ||
Denom: "uinit", | ||
Amount: types.NewCoins(types.NewCoin("uinit", math.NewInt(10))), | ||
}, | ||
resp: &customTypes.MsgDepositValidatorRewardsPoolResponse{}, | ||
errMsg: "decoding bech32 failed: invalid bech32 string length 7", | ||
}, | ||
} | ||
|
||
for _, tc := range cases { | ||
tc := tc | ||
t.Run(tc.name, func(t *testing.T) { | ||
out, err := customMsgServer.DepositValidatorRewardsPool(ctx, tc.msg) | ||
if tc.errMsg == "" { | ||
require.NoError(t, err) | ||
require.Equal(t, tc.resp, out) | ||
} else { | ||
require.Error(t, err) | ||
require.Contains(t, err.Error(), tc.errMsg) | ||
} | ||
}) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package keeper_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/cosmos/cosmos-sdk/x/distribution/types" | ||
"github.com/initia-labs/initia/x/distribution/keeper" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestQueryParams(t *testing.T) { | ||
ctx, testKp := createDefaultTestInput(t) | ||
queryServer := keeper.NewQueryServer(testKp.DistKeeper) | ||
|
||
cases := []struct { | ||
name string | ||
req *types.QueryParamsRequest | ||
resp *types.QueryParamsResponse | ||
errMsg string | ||
}{ | ||
{ | ||
name: "success", | ||
req: &types.QueryParamsRequest{}, | ||
resp: &types.QueryParamsResponse{ | ||
Params: types.DefaultParams(), | ||
}, | ||
errMsg: "", | ||
}, | ||
} | ||
|
||
for _, tc := range cases { | ||
tc := tc | ||
t.Run(tc.name, func(t *testing.T) { | ||
out, err := queryServer.Params(ctx, (*types.QueryParamsRequest)(tc.req)) | ||
if tc.errMsg == "" { | ||
require.NoError(t, err) | ||
require.Equal(t, tc.resp, out) | ||
} else { | ||
require.Error(t, err) | ||
require.Contains(t, err.Error(), tc.errMsg) | ||
require.Nil(t, out) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestQueryValidatorDistributionInfo(t *testing.T) { | ||
ctx, testKp := createDefaultTestInput(t) | ||
queryServer := keeper.NewQueryServer(testKp.DistKeeper) | ||
// operator, err := codectestutil.CodecOptions{}.NewInterfaceRegistry().SigningContext().ValidatorAddressCodec().BytesToString(operatorAddr) | ||
|
||
vali, operator := createValidatorAndOperatorWithBalance(ctx, testKp, 100, 100, 1) | ||
cases := []struct { | ||
name string | ||
req *types.QueryValidatorDistributionInfoRequest | ||
resp *types.QueryValidatorDistributionInfoResponse | ||
errMsg string | ||
}{ | ||
{ | ||
name: "invalid validator address", | ||
req: &types.QueryValidatorDistributionInfoRequest{ | ||
ValidatorAddress: "invalid address", | ||
}, | ||
resp: &types.QueryValidatorDistributionInfoResponse{}, | ||
errMsg: "decoding bech32 failed", | ||
}, | ||
{ | ||
name: "validator", | ||
req: &types.QueryValidatorDistributionInfoRequest{ | ||
ValidatorAddress: vali.String(), | ||
}, | ||
resp: &types.QueryValidatorDistributionInfoResponse{ | ||
OperatorAddress: operator.String(), | ||
}, | ||
}, | ||
} | ||
|
||
for _, tc := range cases { | ||
tc := tc | ||
t.Run(tc.name, func(t *testing.T) { | ||
out, err := queryServer.ValidatorDistributionInfo(ctx, tc.req) | ||
if tc.errMsg == "" { | ||
require.NoError(t, err) | ||
require.Equal(t, tc.resp, out) | ||
} else { | ||
require.Error(t, err) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.