From 06b468e8ef63853ec3624002843a59fedf1c8cc8 Mon Sep 17 00:00:00 2001 From: forcodedancing Date: Tue, 20 Jun 2023 11:02:12 +0800 Subject: [PATCH] fix some unit tests --- x/storage/keeper/payment_test.go | 10 ++++++---- x/storage/types/message_complete_migrate_bucket.go | 2 +- .../types/message_complete_migrate_bucket_test.go | 6 ++++-- x/storage/types/message_migrate_bucket_test.go | 6 ++++-- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/x/storage/keeper/payment_test.go b/x/storage/keeper/payment_test.go index b7025490f..5e9c8b1bb 100644 --- a/x/storage/keeper/payment_test.go +++ b/x/storage/keeper/payment_test.go @@ -114,6 +114,8 @@ func (s *TestSuite) TestGetObjectLockFee() { params := paymenttypes.DefaultParams() s.paymentKeeper.EXPECT().GetParams(gomock.Any()). Return(params).AnyTimes() + s.paymentKeeper.EXPECT().GetVersionedParamsWithTs(gomock.Any(), gomock.Any()). + Return(params.VersionedParams, nil).AnyTimes() // verify lock fee calculation payloadSize := int64(10 * 1024 * 1024) @@ -148,8 +150,8 @@ func (s *TestSuite) TestGetBucketBill() { s.paymentKeeper.EXPECT().GetStoragePrice(gomock.Any(), gomock.Any()). Return(price, nil).AnyTimes() params := paymenttypes.DefaultParams() - s.paymentKeeper.EXPECT().GetParams(gomock.Any()). - Return(params).AnyTimes() + s.paymentKeeper.EXPECT().GetVersionedParamsWithTs(gomock.Any(), gomock.Any()). + Return(params.VersionedParams, nil).AnyTimes() // empty bucket, zero read quota bucketInfo := &types.BucketInfo{ @@ -186,7 +188,7 @@ func (s *TestSuite) TestGetBucketBill() { readRate := price.ReadPrice.MulInt64(int64(bucketInfo.ChargedReadQuota)).TruncateInt() s.Require().Equal(flows.Flows[0].ToAddress, gvgFamily.VirtualPaymentAddress) s.Require().Equal(flows.Flows[0].Rate, readRate) - taxPoolRate := s.paymentKeeper.GetParams(s.ctx).VersionedParams.ValidatorTaxRate.MulInt(readRate).TruncateInt() + taxPoolRate := params.VersionedParams.ValidatorTaxRate.MulInt(readRate).TruncateInt() s.Require().Equal(flows.Flows[1].ToAddress, paymenttypes.ValidatorTaxPoolAddress.String()) s.Require().Equal(flows.Flows[1].Rate, taxPoolRate) @@ -263,7 +265,7 @@ func (s *TestSuite) TestGetBucketBill() { s.Require().Equal(flows.Flows[2].Rate, readRate.Add(primaryStoreRate)) totalRate := readRate.Add(primaryStoreRate).Add(gvg1StoreRate).Add(gvg2StoreRate) - taxPoolRate = s.paymentKeeper.GetParams(s.ctx).VersionedParams.ValidatorTaxRate.MulInt(totalRate).TruncateInt() + taxPoolRate = params.VersionedParams.ValidatorTaxRate.MulInt(totalRate).TruncateInt() s.Require().Equal(flows.Flows[3].ToAddress, paymenttypes.ValidatorTaxPoolAddress.String()) s.Require().Equal(flows.Flows[3].Rate, taxPoolRate) } diff --git a/x/storage/types/message_complete_migrate_bucket.go b/x/storage/types/message_complete_migrate_bucket.go index 0938af1ec..9acc5b667 100644 --- a/x/storage/types/message_complete_migrate_bucket.go +++ b/x/storage/types/message_complete_migrate_bucket.go @@ -40,7 +40,7 @@ func (msg *MsgCompleteMigrateBucket) GetSignBytes() []byte { } func (msg *MsgCompleteMigrateBucket) ValidateBasic() error { - _, err := sdk.AccAddressFromBech32(msg.Operator) + _, err := sdk.AccAddressFromHexUnsafe(msg.Operator) if err != nil { return errors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) } diff --git a/x/storage/types/message_complete_migrate_bucket_test.go b/x/storage/types/message_complete_migrate_bucket_test.go index bbe0f142c..2a668a752 100644 --- a/x/storage/types/message_complete_migrate_bucket_test.go +++ b/x/storage/types/message_complete_migrate_bucket_test.go @@ -18,13 +18,15 @@ func TestMsgCompleteMigrateBucket_ValidateBasic(t *testing.T) { { name: "invalid address", msg: MsgCompleteMigrateBucket{ - Operator: "invalid_address", + Operator: "invalid_address", + BucketName: "bucketname", }, err: sdkerrors.ErrInvalidAddress, }, { name: "valid address", msg: MsgCompleteMigrateBucket{ - Operator: sample.AccAddress(), + Operator: sample.AccAddress(), + BucketName: "bucketname", }, }, } diff --git a/x/storage/types/message_migrate_bucket_test.go b/x/storage/types/message_migrate_bucket_test.go index 63ed4909d..2a2dd0e7b 100644 --- a/x/storage/types/message_migrate_bucket_test.go +++ b/x/storage/types/message_migrate_bucket_test.go @@ -18,13 +18,15 @@ func TestMsgMigrateBucket_ValidateBasic(t *testing.T) { { name: "invalid address", msg: MsgMigrateBucket{ - Operator: "invalid_address", + Operator: "invalid_address", + BucketName: "bucketname", }, err: sdkerrors.ErrInvalidAddress, }, { name: "valid address", msg: MsgMigrateBucket{ - Operator: sample.AccAddress(), + Operator: sample.AccAddress(), + BucketName: "bucketname", }, }, }