Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
alexgao001 committed Oct 8, 2023
1 parent 8496bab commit a80589a
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 6 deletions.
6 changes: 3 additions & 3 deletions e2e/core/basesuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
64 changes: 64 additions & 0 deletions e2e/tests/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
6 changes: 3 additions & 3 deletions x/storage/types/message_reject_migrate_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down

0 comments on commit a80589a

Please sign in to comment.