[ENG-687]: Testing for the UpdateParams handler (#49)

This commit is contained in:
David Terpay 2023-04-05 18:40:42 -04:00 committed by GitHub
parent a0dacf78a1
commit d3a198a710
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 99 additions and 2 deletions

View File

@ -124,5 +124,68 @@ func (suite *KeeperTestSuite) TestMsgAuctionBid() {
}
func (suite *KeeperTestSuite) TestMsgUpdateParams() {
suite.T().SkipNow()
rng := rand.New(rand.NewSource(time.Now().Unix()))
account := testutils.RandomAccounts(rng, 1)[0]
testCases := []struct {
name string
msg *types.MsgUpdateParams
pass bool
passBasic bool
}{
{
name: "invalid proposer fee",
msg: &types.MsgUpdateParams{
Authority: suite.authorityAccount.String(),
Params: types.Params{
ProposerFee: sdk.MustNewDecFromStr("1.1"),
},
},
passBasic: false,
pass: true,
},
{
name: "invalid auction fees",
msg: &types.MsgUpdateParams{
Authority: suite.authorityAccount.String(),
Params: types.Params{
ProposerFee: sdk.MustNewDecFromStr("0.1"),
},
},
passBasic: false,
pass: true,
},
{
name: "invalid authority address",
msg: &types.MsgUpdateParams{
Authority: account.Address.String(),
Params: types.Params{
ProposerFee: sdk.MustNewDecFromStr("0.1"),
MaxBundleSize: 2,
EscrowAccountAddress: suite.authorityAccount.String(),
MinBuyInFee: sdk.NewInt64Coin("foo", 100),
MinBidIncrement: sdk.NewInt64Coin("foo", 100),
ReserveFee: sdk.NewInt64Coin("foo", 100),
},
},
passBasic: true,
pass: false,
},
}
for _, tc := range testCases {
suite.Run(tc.name, func() {
if !tc.passBasic {
suite.Require().Error(tc.msg.ValidateBasic())
}
_, err := suite.msgServer.UpdateParams(suite.ctx, tc.msg)
if tc.pass {
suite.Require().NoError(err)
} else {
suite.Require().Error(err)
}
})
}
}

View File

@ -125,6 +125,31 @@ func TestMsgUpdateParams(t *testing.T) {
},
expectPass: true,
},
{
description: "invalid message with multiple fee denoms",
msg: types.MsgUpdateParams{
Authority: sdk.AccAddress([]byte("test")).String(),
Params: types.Params{
ProposerFee: sdk.NewDec(1),
EscrowAccountAddress: sdk.AccAddress([]byte("test")).String(),
ReserveFee: sdk.NewCoin("test", sdk.NewInt(100)),
MinBidIncrement: sdk.NewCoin("test2", sdk.NewInt(100)),
MinBuyInFee: sdk.NewCoin("test3", sdk.NewInt(100)),
},
},
expectPass: false,
},
{
description: "invalid message with unset fee denoms",
msg: types.MsgUpdateParams{
Authority: sdk.AccAddress([]byte("test")).String(),
Params: types.Params{
ProposerFee: sdk.NewDec(1),
EscrowAccountAddress: sdk.AccAddress([]byte("test")).String(),
},
},
expectPass: false,
},
}
for _, tc := range cases {

View File

@ -67,6 +67,16 @@ func (p Params) Validate() error {
return fmt.Errorf("invalid minimum bid increment (%s)", err)
}
denoms := map[string]struct{}{
p.ReserveFee.Denom: {},
p.MinBuyInFee.Denom: {},
p.MinBidIncrement.Denom: {},
}
if len(denoms) != 1 {
return fmt.Errorf("mismatched auction fee denoms: minimum bid increment (%s), minimum buy-in fee (%s), reserve fee (%s)", p.MinBidIncrement, p.MinBuyInFee, p.ReserveFee)
}
return validateProposerFee(p.ProposerFee)
}
@ -93,7 +103,6 @@ func validateProposerFee(v sdk.Dec) error {
}
func validateEscrowAccountAddress(account string) error {
// If the escrow account address is set, ensure it is a valid address.
if _, err := sdk.AccAddressFromBech32(account); err != nil {
return fmt.Errorf("invalid escrow account address (%s)", err)
}