From a80589a927554c8b9168365143a76fca1f06805d Mon Sep 17 00:00:00 2001 From: Alexgao001 Date: Sat, 7 Oct 2023 18:31:19 +0800 Subject: [PATCH] add test --- e2e/core/basesuite.go | 6 +- e2e/tests/storage_test.go | 64 +++++++++++++++++++ .../types/message_reject_migrate_bucket.go | 6 +- 3 files changed, 70 insertions(+), 6 deletions(-) diff --git a/e2e/core/basesuite.go b/e2e/core/basesuite.go index 50fa8d1f4..7ff455a90 100644 --- a/e2e/core/basesuite.go +++ b/e2e/core/basesuite.go @@ -126,9 +126,9 @@ func (s *BaseSuite) InitChain() { func (s *BaseSuite) SetupSuite() { s.Config = InitConfig() - initValidatorOnce.Do(func() { - s.InitChain() - }) + //initValidatorOnce.Do(func() { + // s.InitChain() + //}) s.Client, _ = client.NewGreenfieldClient(s.Config.TendermintAddr, s.Config.ChainId) tmClient := client.NewTendermintClient(s.Config.TendermintAddr) diff --git a/e2e/tests/storage_test.go b/e2e/tests/storage_test.go index 547fa149f..5ba1b62d9 100644 --- a/e2e/tests/storage_test.go +++ b/e2e/tests/storage_test.go @@ -2010,3 +2010,67 @@ func (s *StorageTestSuite) TestMaintenanceSPCreateBucketAndObject() { s.Require().NoError(err) s.Require().Equal(sptypes.STATUS_IN_SERVICE, spResp.StorageProvider.Status) } + +func (s *StorageTestSuite) TestRejectMigrateBucket() { + // construct bucket and object + primarySP := s.BaseSuite.PickStorageProvider() + gvg, found := primarySP.GetFirstGlobalVirtualGroup() + s.Require().True(found) + user := s.GenAndChargeAccounts(1, 1000000)[0] + bucketName := storageutils.GenRandomBucketName() + objectName := storageutils.GenRandomObjectName() + s.BaseSuite.CreateObject(user, primarySP, gvg.Id, bucketName, objectName) + + var err error + dstPrimarySP := s.CreateNewStorageProvider() + + // migrate bucket + msgMigrationBucket := storagetypes.NewMsgMigrateBucket(user.GetAddr(), bucketName, dstPrimarySP.Info.Id) + msgMigrationBucket.DstPrimarySpApproval.ExpiredHeight = math.MaxInt + msgMigrationBucket.DstPrimarySpApproval.Sig, err = dstPrimarySP.ApprovalKey.Sign(msgMigrationBucket.GetApprovalBytes()) + s.SendTxBlock(user, msgMigrationBucket) + s.Require().NoError(err) + + ctx := context.Background() + queryHeadBucketRequest := storagetypes.QueryHeadBucketRequest{ + BucketName: bucketName, + } + queryHeadBucketResponse, err := s.Client.HeadBucket(ctx, &queryHeadBucketRequest) + s.Require().NoError(err) + s.Require().Equal(queryHeadBucketResponse.BucketInfo.BucketName, bucketName) + s.Require().Equal(queryHeadBucketResponse.BucketInfo.BucketStatus, storagetypes.BUCKET_STATUS_MIGRATING) + + // Dest SP reject the migration + rejectMigration := storagetypes.NewMsgRejectMigrateBucket(dstPrimarySP.OperatorKey.GetAddr(), bucketName) + s.SendTxBlock(dstPrimarySP.OperatorKey, rejectMigration) + s.Require().NoError(err) + + queryHeadBucketRequest = storagetypes.QueryHeadBucketRequest{ + BucketName: bucketName, + } + queryHeadBucketResponse, err = s.Client.HeadBucket(ctx, &queryHeadBucketRequest) + s.Require().NoError(err) + s.Require().Equal(queryHeadBucketResponse.BucketInfo.BucketStatus, storagetypes.BUCKET_STATUS_CREATED) + + // migrate bucket again + msgMigrationBucket = storagetypes.NewMsgMigrateBucket(user.GetAddr(), bucketName, dstPrimarySP.Info.Id) + msgMigrationBucket.DstPrimarySpApproval.ExpiredHeight = math.MaxInt + msgMigrationBucket.DstPrimarySpApproval.Sig, err = dstPrimarySP.ApprovalKey.Sign(msgMigrationBucket.GetApprovalBytes()) + s.SendTxBlock(user, msgMigrationBucket) + s.Require().NoError(err) + + // cancel migration by user + msgCancelMigrationBucket := storagetypes.NewMsgCancelMigrateBucket(user.GetAddr(), bucketName) + s.SendTxBlock(user, msgCancelMigrationBucket) + s.Require().NoError(err) + + queryHeadBucketResponse, err = s.Client.HeadBucket(ctx, &queryHeadBucketRequest) + s.Require().NoError(err) + s.Require().Equal(queryHeadBucketResponse.BucketInfo.BucketStatus, storagetypes.BUCKET_STATUS_CREATED) + + // dest SP should fail to reject + s.Client.SetKeyManager(dstPrimarySP.OperatorKey) + _, err = s.Client.BroadcastTx(context.Background(), []sdk.Msg{rejectMigration}, nil) + s.Require().Error(err) + s.Require().Equal(queryHeadBucketResponse.BucketInfo.BucketStatus, storagetypes.BUCKET_STATUS_CREATED) +} diff --git a/x/storage/types/message_reject_migrate_bucket.go b/x/storage/types/message_reject_migrate_bucket.go index b55ceb4e4..ae8af2fa5 100644 --- a/x/storage/types/message_reject_migrate_bucket.go +++ b/x/storage/types/message_reject_migrate_bucket.go @@ -27,11 +27,11 @@ func (msg *MsgRejectMigrateBucket) Type() string { } func (msg *MsgRejectMigrateBucket) GetSigners() []sdk.AccAddress { - creator, err := sdk.AccAddressFromHexUnsafe(msg.Operator) + operator, err := sdk.AccAddressFromHexUnsafe(msg.Operator) if err != nil { panic(err) } - return []sdk.AccAddress{creator} + return []sdk.AccAddress{operator} } func (msg *MsgRejectMigrateBucket) GetSignBytes() []byte { @@ -42,7 +42,7 @@ func (msg *MsgRejectMigrateBucket) GetSignBytes() []byte { func (msg *MsgRejectMigrateBucket) ValidateBasic() error { _, err := sdk.AccAddressFromHexUnsafe(msg.Operator) if err != nil { - return sdkerrors.ErrInvalidAddress.Wrapf("invalid creator address (%s)", err) + return sdkerrors.ErrInvalidAddress.Wrapf("invalid operator address (%s)", err) } err = s3util.CheckValidBucketName(msg.BucketName)