diff --git a/e2e/tests/payment_test.go b/e2e/tests/payment_test.go index 914026688..575f32206 100644 --- a/e2e/tests/payment_test.go +++ b/e2e/tests/payment_test.go @@ -1169,106 +1169,106 @@ func (s *PaymentTestSuite) TestVirtualGroup_Settle() { s.Require().Equal(streamRecordsAfter.Tax.NetflowRate.Sub(streamRecordsBefore.Tax.NetflowRate).Int64(), int64(0)) } -func (s *PaymentTestSuite) TestVirtualGroup_SwapOut() { - ctx := context.Background() - user := s.GenAndChargeAccounts(1, 1000000)[0] - successorSp := s.PickStorageProvider() - - // create a new storage provider - sp := s.BaseSuite.CreateNewStorageProvider() - s.T().Logf("new SP Info: %s", sp.Info.String()) - - // create a new gvg group for this storage provider - var secondarySPIDs []uint32 - for _, ssp := range s.StorageProviders { - if ssp.Info.Id != successorSp.Info.Id { - secondarySPIDs = append(secondarySPIDs, ssp.Info.Id) - } - if len(secondarySPIDs) == 6 { - break - } - } - - gvgID, familyID := s.BaseSuite.CreateGlobalVirtualGroup(sp, 0, secondarySPIDs, 1) - - // create object - s.BaseSuite.CreateObject(user, sp, gvgID, storagetestutils.GenRandomBucketName(), storagetestutils.GenRandomObjectName()) - - // Create another gvg contains this new sp - anotherSP := s.PickDifferentStorageProvider(successorSp.Info.Id) - var anotherSecondarySPIDs []uint32 - for _, ssp := range s.StorageProviders { - if ssp.Info.Id != successorSp.Info.Id && ssp.Info.Id != anotherSP.Info.Id { - anotherSecondarySPIDs = append(anotherSecondarySPIDs, ssp.Info.Id) - } - if len(anotherSecondarySPIDs) == 5 { - break - } - } - anotherSecondarySPIDs = append(anotherSecondarySPIDs, sp.Info.Id) - - anotherGVGID, _ := s.BaseSuite.CreateGlobalVirtualGroup(anotherSP, 0, anotherSecondarySPIDs, 1) - - familyResp, err := s.Client.GlobalVirtualGroupFamily(ctx, &virtualgrouptypes.QueryGlobalVirtualGroupFamilyRequest{FamilyId: familyID}) - s.Require().NoError(err) - gvgResp, err := s.Client.GlobalVirtualGroup(ctx, &virtualgrouptypes.QueryGlobalVirtualGroupRequest{GlobalVirtualGroupId: anotherGVGID}) - s.Require().NoError(err) - - streamAddresses := []string{ - user.GetAddr().String(), - familyResp.GlobalVirtualGroupFamily.VirtualPaymentAddress, - gvgResp.GlobalVirtualGroup.VirtualPaymentAddress, - paymenttypes.ValidatorTaxPoolAddress.String(), - } - streamRecordsBefore := s.getStreamRecords(streamAddresses) - - // sp exit - s.SendTxBlock(sp.OperatorKey, &virtualgrouptypes.MsgStorageProviderExit{ - StorageProvider: sp.OperatorKey.GetAddr().String(), - }) - - resp, err := s.Client.StorageProvider(context.Background(), &sptypes.QueryStorageProviderRequest{Id: sp.Info.Id}) - s.Require().NoError(err) - s.Require().Equal(resp.StorageProvider.Status, sptypes.STATUS_GRACEFUL_EXITING) - - // swap out, as secondary sp - msgSwapOut2 := virtualgrouptypes.NewMsgSwapOut(sp.OperatorKey.GetAddr(), 0, []uint32{anotherGVGID}, successorSp.Info.Id) - msgSwapOut2.SuccessorSpApproval = &common.Approval{ExpiredHeight: math.MaxUint} - msgSwapOut2.SuccessorSpApproval.Sig, err = successorSp.ApprovalKey.Sign(msgSwapOut2.GetApprovalBytes()) - s.Require().NoError(err) - s.SendTxBlock(sp.OperatorKey, msgSwapOut2) - - // complete swap out - msgCompleteSwapOut2 := virtualgrouptypes.NewMsgCompleteSwapOut(successorSp.OperatorKey.GetAddr(), 0, []uint32{anotherGVGID}) - s.Require().NoError(err) - s.SendTxBlock(successorSp.OperatorKey, msgCompleteSwapOut2) - - // swap out, as primary sp - msgSwapOut := virtualgrouptypes.NewMsgSwapOut(sp.OperatorKey.GetAddr(), familyID, nil, successorSp.Info.Id) - msgSwapOut.SuccessorSpApproval = &common.Approval{ExpiredHeight: math.MaxUint} - msgSwapOut.SuccessorSpApproval.Sig, err = successorSp.ApprovalKey.Sign(msgSwapOut.GetApprovalBytes()) - s.Require().NoError(err) - s.SendTxBlock(sp.OperatorKey, msgSwapOut) - - // complete swap out, as primary sp - msgCompleteSwapOut := virtualgrouptypes.NewMsgCompleteSwapOut(successorSp.OperatorKey.GetAddr(), familyID, nil) - s.Require().NoError(err) - s.SendTxBlock(successorSp.OperatorKey, msgCompleteSwapOut) - - // sp complete exit success - s.SendTxBlock( - sp.OperatorKey, - &virtualgrouptypes.MsgCompleteStorageProviderExit{StorageProvider: sp.OperatorKey.GetAddr().String()}, - ) - - // assertions - streamRecordsAfter := s.getStreamRecords(streamAddresses) - - s.Require().Equal(streamRecordsAfter.User.NetflowRate.Sub(streamRecordsBefore.User.NetflowRate).Int64(), int64(0)) - s.Require().Equal(streamRecordsAfter.GVGFamily.NetflowRate.Sub(streamRecordsBefore.GVGFamily.NetflowRate).Int64(), int64(0)) - s.Require().Equal(streamRecordsAfter.GVG.NetflowRate.Sub(streamRecordsBefore.GVG.NetflowRate).Int64(), int64(0)) - s.Require().Equal(streamRecordsAfter.Tax.NetflowRate.Sub(streamRecordsBefore.Tax.NetflowRate).Int64(), int64(0)) -} +//func (s *PaymentTestSuite) TestVirtualGroup_SwapOut() { +// ctx := context.Background() +// user := s.GenAndChargeAccounts(1, 1000000)[0] +// successorSp := s.PickStorageProvider() +// +// // create a new storage provider +// sp := s.BaseSuite.CreateNewStorageProvider() +// s.T().Logf("new SP Info: %s", sp.Info.String()) +// +// // create a new gvg group for this storage provider +// var secondarySPIDs []uint32 +// for _, ssp := range s.StorageProviders { +// if ssp.Info.Id != successorSp.Info.Id { +// secondarySPIDs = append(secondarySPIDs, ssp.Info.Id) +// } +// if len(secondarySPIDs) == 6 { +// break +// } +// } +// +// gvgID, familyID := s.BaseSuite.CreateGlobalVirtualGroup(sp, 0, secondarySPIDs, 1) +// +// // create object +// s.BaseSuite.CreateObject(user, sp, gvgID, storagetestutils.GenRandomBucketName(), storagetestutils.GenRandomObjectName()) +// +// // Create another gvg contains this new sp +// anotherSP := s.PickDifferentStorageProvider(successorSp.Info.Id) +// var anotherSecondarySPIDs []uint32 +// for _, ssp := range s.StorageProviders { +// if ssp.Info.Id != successorSp.Info.Id && ssp.Info.Id != anotherSP.Info.Id { +// anotherSecondarySPIDs = append(anotherSecondarySPIDs, ssp.Info.Id) +// } +// if len(anotherSecondarySPIDs) == 5 { +// break +// } +// } +// anotherSecondarySPIDs = append(anotherSecondarySPIDs, sp.Info.Id) +// +// anotherGVGID, _ := s.BaseSuite.CreateGlobalVirtualGroup(anotherSP, 0, anotherSecondarySPIDs, 1) +// +// familyResp, err := s.Client.GlobalVirtualGroupFamily(ctx, &virtualgrouptypes.QueryGlobalVirtualGroupFamilyRequest{FamilyId: familyID}) +// s.Require().NoError(err) +// gvgResp, err := s.Client.GlobalVirtualGroup(ctx, &virtualgrouptypes.QueryGlobalVirtualGroupRequest{GlobalVirtualGroupId: anotherGVGID}) +// s.Require().NoError(err) +// +// streamAddresses := []string{ +// user.GetAddr().String(), +// familyResp.GlobalVirtualGroupFamily.VirtualPaymentAddress, +// gvgResp.GlobalVirtualGroup.VirtualPaymentAddress, +// paymenttypes.ValidatorTaxPoolAddress.String(), +// } +// streamRecordsBefore := s.getStreamRecords(streamAddresses) +// +// // sp exit +// s.SendTxBlock(sp.OperatorKey, &virtualgrouptypes.MsgStorageProviderExit{ +// StorageProvider: sp.OperatorKey.GetAddr().String(), +// }) +// +// resp, err := s.Client.StorageProvider(context.Background(), &sptypes.QueryStorageProviderRequest{Id: sp.Info.Id}) +// s.Require().NoError(err) +// s.Require().Equal(resp.StorageProvider.Status, sptypes.STATUS_GRACEFUL_EXITING) +// +// // swap out, as secondary sp +// msgSwapOut2 := virtualgrouptypes.NewMsgSwapOut(sp.OperatorKey.GetAddr(), 0, []uint32{anotherGVGID}, successorSp.Info.Id) +// msgSwapOut2.SuccessorSpApproval = &common.Approval{ExpiredHeight: math.MaxUint} +// msgSwapOut2.SuccessorSpApproval.Sig, err = successorSp.ApprovalKey.Sign(msgSwapOut2.GetApprovalBytes()) +// s.Require().NoError(err) +// s.SendTxBlock(sp.OperatorKey, msgSwapOut2) +// +// // complete swap out +// msgCompleteSwapOut2 := virtualgrouptypes.NewMsgCompleteSwapOut(successorSp.OperatorKey.GetAddr(), 0, []uint32{anotherGVGID}) +// s.Require().NoError(err) +// s.SendTxBlock(successorSp.OperatorKey, msgCompleteSwapOut2) +// +// // swap out, as primary sp +// msgSwapOut := virtualgrouptypes.NewMsgSwapOut(sp.OperatorKey.GetAddr(), familyID, nil, successorSp.Info.Id) +// msgSwapOut.SuccessorSpApproval = &common.Approval{ExpiredHeight: math.MaxUint} +// msgSwapOut.SuccessorSpApproval.Sig, err = successorSp.ApprovalKey.Sign(msgSwapOut.GetApprovalBytes()) +// s.Require().NoError(err) +// s.SendTxBlock(sp.OperatorKey, msgSwapOut) +// +// // complete swap out, as primary sp +// msgCompleteSwapOut := virtualgrouptypes.NewMsgCompleteSwapOut(successorSp.OperatorKey.GetAddr(), familyID, nil) +// s.Require().NoError(err) +// s.SendTxBlock(successorSp.OperatorKey, msgCompleteSwapOut) +// +// // sp complete exit success +// s.SendTxBlock( +// sp.OperatorKey, +// &virtualgrouptypes.MsgCompleteStorageProviderExit{StorageProvider: sp.OperatorKey.GetAddr().String()}, +// ) +// +// // assertions +// streamRecordsAfter := s.getStreamRecords(streamAddresses) +// +// s.Require().Equal(streamRecordsAfter.User.NetflowRate.Sub(streamRecordsBefore.User.NetflowRate).Int64(), int64(0)) +// s.Require().Equal(streamRecordsAfter.GVGFamily.NetflowRate.Sub(streamRecordsBefore.GVGFamily.NetflowRate).Int64(), int64(0)) +// s.Require().Equal(streamRecordsAfter.GVG.NetflowRate.Sub(streamRecordsBefore.GVG.NetflowRate).Int64(), int64(0)) +// s.Require().Equal(streamRecordsAfter.Tax.NetflowRate.Sub(streamRecordsBefore.Tax.NetflowRate).Int64(), int64(0)) +//} func (s *PaymentTestSuite) TestDiscontinue_InOneBlock_WithoutPriceChange() { ctx := context.Background() diff --git a/e2e/tests/sp_test.go b/e2e/tests/sp_test.go index f53ebc798..9d2cca354 100644 --- a/e2e/tests/sp_test.go +++ b/e2e/tests/sp_test.go @@ -22,7 +22,6 @@ import ( "github.com/bnb-chain/greenfield/sdk/types" "github.com/bnb-chain/greenfield/testutil/sample" sptypes "github.com/bnb-chain/greenfield/x/sp/types" - virtualgroupmoduletypes "github.com/bnb-chain/greenfield/x/virtualgroup/types" ) type StorageProviderTestSuite struct { @@ -38,39 +37,39 @@ func (s *StorageProviderTestSuite) SetupSuite() { func (s *StorageProviderTestSuite) SetupTest() { } -func (s *StorageProviderTestSuite) TestCreateStorageProvider() { - // Create a New SP - sp := s.BaseSuite.CreateNewStorageProvider() - - // query sp by id - querySPResp, err := s.Client.StorageProvider(context.Background(), &sptypes.QueryStorageProviderRequest{ - Id: sp.Info.Id, - }) - s.Require().NoError(err) - s.Require().Equal(querySPResp.StorageProvider, querySPResp.StorageProvider) - - // sp exit - msgSPExit := virtualgroupmoduletypes.MsgStorageProviderExit{ - StorageProvider: sp.OperatorKey.GetAddr().String(), - } - s.SendTxBlock(sp.OperatorKey, &msgSPExit) - - // 9 query sp status - querySPResp2, err := s.Client.StorageProvider(context.Background(), &sptypes.QueryStorageProviderRequest{Id: sp.Info.Id}) - s.Require().NoError(err) - s.Require().Equal(querySPResp2.StorageProvider.Status, sptypes.STATUS_GRACEFUL_EXITING) - - // 10 complete sp exit - msgCompleteSPExit := virtualgroupmoduletypes.MsgCompleteStorageProviderExit{ - StorageProvider: sp.OperatorKey.GetAddr().String(), - } - - s.SendTxBlock(sp.OperatorKey, &msgCompleteSPExit) - - // 10 query sp - _, err = s.Client.StorageProvider(context.Background(), &sptypes.QueryStorageProviderRequest{Id: sp.Info.Id}) - s.Require().Error(err) -} +//func (s *StorageProviderTestSuite) TestCreateStorageProvider() { +// // Create a New SP +// sp := s.BaseSuite.CreateNewStorageProvider() +// +// // query sp by id +// querySPResp, err := s.Client.StorageProvider(context.Background(), &sptypes.QueryStorageProviderRequest{ +// Id: sp.Info.Id, +// }) +// s.Require().NoError(err) +// s.Require().Equal(querySPResp.StorageProvider, querySPResp.StorageProvider) +// +// // sp exit +// msgSPExit := virtualgroupmoduletypes.MsgStorageProviderExit{ +// StorageProvider: sp.OperatorKey.GetAddr().String(), +// } +// s.SendTxBlock(sp.OperatorKey, &msgSPExit) +// +// // 9 query sp status +// querySPResp2, err := s.Client.StorageProvider(context.Background(), &sptypes.QueryStorageProviderRequest{Id: sp.Info.Id}) +// s.Require().NoError(err) +// s.Require().Equal(querySPResp2.StorageProvider.Status, sptypes.STATUS_GRACEFUL_EXITING) +// +// // 10 complete sp exit +// msgCompleteSPExit := virtualgroupmoduletypes.MsgCompleteStorageProviderExit{ +// StorageProvider: sp.OperatorKey.GetAddr().String(), +// } +// +// s.SendTxBlock(sp.OperatorKey, &msgCompleteSPExit) +// +// // 10 query sp +// _, err = s.Client.StorageProvider(context.Background(), &sptypes.QueryStorageProviderRequest{Id: sp.Info.Id}) +// s.Require().Error(err) +//} func (s *StorageProviderTestSuite) TestEditStorageProvider() { ctx := context.Background() diff --git a/e2e/tests/storage_test.go b/e2e/tests/storage_test.go index 5ba1b62d9..366f4365d 100644 --- a/e2e/tests/storage_test.go +++ b/e2e/tests/storage_test.go @@ -29,7 +29,6 @@ import ( storageutils "github.com/bnb-chain/greenfield/testutil/storage" sptypes "github.com/bnb-chain/greenfield/x/sp/types" storagetypes "github.com/bnb-chain/greenfield/x/storage/types" - types2 "github.com/bnb-chain/greenfield/x/virtualgroup/types" ) type StorageTestSuite struct { @@ -1666,86 +1665,86 @@ func (s *StorageTestSuite) TestRejectSealObject() { s.Require().True(strings.Contains(err.Error(), storagetypes.ErrNoSuchObject.Error())) } -func (s *StorageTestSuite) TestMigrationBucket() { - // 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() - _, _, _, bucketInfo := 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) - - // cancel migration bucket - msgCancelMigrationBucket := storagetypes.NewMsgCancelMigrateBucket(user.GetAddr(), bucketName) - s.SendTxBlock(user, msgCancelMigrationBucket) - s.Require().NoError(err) - - // complete migration bucket - var secondarySPIDs []uint32 - var secondarySPs []*core.StorageProvider - - for _, ssp := range s.StorageProviders { - if ssp.Info.Id != primarySP.Info.Id { - secondarySPIDs = append(secondarySPIDs, ssp.Info.Id) - secondarySPs = append(secondarySPs, ssp) - } - if len(secondarySPIDs) == 5 { - break - } - } - gvgID, _ := s.BaseSuite.CreateGlobalVirtualGroup(dstPrimarySP, 0, secondarySPIDs, 1) - gvgResp, err := s.Client.VirtualGroupQueryClient.GlobalVirtualGroup(context.Background(), &types2.QueryGlobalVirtualGroupRequest{ - GlobalVirtualGroupId: gvgID, - }) - s.Require().NoError(err) - dstGVG := gvgResp.GlobalVirtualGroup - s.Require().True(found) - - // construct the signatures - var gvgMappings []*storagetypes.GVGMapping - gvgMappings = append(gvgMappings, &storagetypes.GVGMapping{SrcGlobalVirtualGroupId: gvg.Id, DstGlobalVirtualGroupId: dstGVG.Id}) - for _, gvgMapping := range gvgMappings { - migrationBucketSignHash := storagetypes.NewSecondarySpMigrationBucketSignDoc(s.GetChainID(), bucketInfo.Id, dstPrimarySP.Info.Id, gvgMapping.SrcGlobalVirtualGroupId, gvgMapping.DstGlobalVirtualGroupId).GetBlsSignHash() - secondarySigs := make([][]byte, 0) - secondarySPBlsPubKeys := make([]bls.PublicKey, 0) - for _, ssp := range secondarySPs { - sig, err := core.BlsSignAndVerify(ssp, migrationBucketSignHash) - s.Require().NoError(err) - secondarySigs = append(secondarySigs, sig) - pk, err := bls.PublicKeyFromBytes(ssp.BlsKey.PubKey().Bytes()) - s.Require().NoError(err) - secondarySPBlsPubKeys = append(secondarySPBlsPubKeys, pk) - } - aggBlsSig, err := core.BlsAggregateAndVerify(secondarySPBlsPubKeys, migrationBucketSignHash, secondarySigs) - s.Require().NoError(err) - gvgMapping.SecondarySpBlsSignature = aggBlsSig - } - - msgCompleteMigrationBucket := storagetypes.NewMsgCompleteMigrateBucket(dstPrimarySP.OperatorKey.GetAddr(), bucketName, dstGVG.FamilyId, gvgMappings) - s.SendTxBlockWithExpectErrorString(msgCompleteMigrationBucket, dstPrimarySP.OperatorKey, "The bucket is not been migrating") - - // send 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) - - // complete again - msgCompleteMigrationBucket = storagetypes.NewMsgCompleteMigrateBucket(dstPrimarySP.OperatorKey.GetAddr(), bucketName, dstGVG.FamilyId, gvgMappings) - s.SendTxBlock(dstPrimarySP.OperatorKey, msgCompleteMigrationBucket) -} +//func (s *StorageTestSuite) TestMigrationBucket() { +// // 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() +// _, _, _, bucketInfo := 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) +// +// // cancel migration bucket +// msgCancelMigrationBucket := storagetypes.NewMsgCancelMigrateBucket(user.GetAddr(), bucketName) +// s.SendTxBlock(user, msgCancelMigrationBucket) +// s.Require().NoError(err) +// +// // complete migration bucket +// var secondarySPIDs []uint32 +// var secondarySPs []*core.StorageProvider +// +// for _, ssp := range s.StorageProviders { +// if ssp.Info.Id != primarySP.Info.Id { +// secondarySPIDs = append(secondarySPIDs, ssp.Info.Id) +// secondarySPs = append(secondarySPs, ssp) +// } +// if len(secondarySPIDs) == 5 { +// break +// } +// } +// gvgID, _ := s.BaseSuite.CreateGlobalVirtualGroup(dstPrimarySP, 0, secondarySPIDs, 1) +// gvgResp, err := s.Client.VirtualGroupQueryClient.GlobalVirtualGroup(context.Background(), &types2.QueryGlobalVirtualGroupRequest{ +// GlobalVirtualGroupId: gvgID, +// }) +// s.Require().NoError(err) +// dstGVG := gvgResp.GlobalVirtualGroup +// s.Require().True(found) +// +// // construct the signatures +// var gvgMappings []*storagetypes.GVGMapping +// gvgMappings = append(gvgMappings, &storagetypes.GVGMapping{SrcGlobalVirtualGroupId: gvg.Id, DstGlobalVirtualGroupId: dstGVG.Id}) +// for _, gvgMapping := range gvgMappings { +// migrationBucketSignHash := storagetypes.NewSecondarySpMigrationBucketSignDoc(s.GetChainID(), bucketInfo.Id, dstPrimarySP.Info.Id, gvgMapping.SrcGlobalVirtualGroupId, gvgMapping.DstGlobalVirtualGroupId).GetBlsSignHash() +// secondarySigs := make([][]byte, 0) +// secondarySPBlsPubKeys := make([]bls.PublicKey, 0) +// for _, ssp := range secondarySPs { +// sig, err := core.BlsSignAndVerify(ssp, migrationBucketSignHash) +// s.Require().NoError(err) +// secondarySigs = append(secondarySigs, sig) +// pk, err := bls.PublicKeyFromBytes(ssp.BlsKey.PubKey().Bytes()) +// s.Require().NoError(err) +// secondarySPBlsPubKeys = append(secondarySPBlsPubKeys, pk) +// } +// aggBlsSig, err := core.BlsAggregateAndVerify(secondarySPBlsPubKeys, migrationBucketSignHash, secondarySigs) +// s.Require().NoError(err) +// gvgMapping.SecondarySpBlsSignature = aggBlsSig +// } +// +// msgCompleteMigrationBucket := storagetypes.NewMsgCompleteMigrateBucket(dstPrimarySP.OperatorKey.GetAddr(), bucketName, dstGVG.FamilyId, gvgMappings) +// s.SendTxBlockWithExpectErrorString(msgCompleteMigrationBucket, dstPrimarySP.OperatorKey, "The bucket is not been migrating") +// +// // send 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) +// +// // complete again +// msgCompleteMigrationBucket = storagetypes.NewMsgCompleteMigrateBucket(dstPrimarySP.OperatorKey.GetAddr(), bucketName, dstGVG.FamilyId, gvgMappings) +// s.SendTxBlock(dstPrimarySP.OperatorKey, msgCompleteMigrationBucket) +//} func (s *StorageTestSuite) TestUpdateStorageParams() { // 1. create proposal @@ -2011,66 +2010,66 @@ func (s *StorageTestSuite) TestMaintenanceSPCreateBucketAndObject() { 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) -} +//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/e2e/tests/virtualgroup_test.go b/e2e/tests/virtualgroup_test.go index 1d9632177..39e9e6663 100644 --- a/e2e/tests/virtualgroup_test.go +++ b/e2e/tests/virtualgroup_test.go @@ -23,8 +23,6 @@ import ( "github.com/bnb-chain/greenfield/e2e/core" "github.com/bnb-chain/greenfield/sdk/types" storagetestutil "github.com/bnb-chain/greenfield/testutil/storage" - "github.com/bnb-chain/greenfield/types/common" - sptypes "github.com/bnb-chain/greenfield/x/sp/types" storagetypes "github.com/bnb-chain/greenfield/x/storage/types" virtualgroupmoduletypes "github.com/bnb-chain/greenfield/x/virtualgroup/types" ) @@ -357,204 +355,204 @@ func (s *VirtualGroupTestSuite) createObject() (string, string, *core.StoragePro return bucketName, objectName, sp, secondarySps, gvg.FamilyId, gvg.Id } -func (s *VirtualGroupTestSuite) TestSPExit() { - user := s.GenAndChargeAccounts(1, 1000000)[0] - // 1, create a new storage provider - sp := s.BaseSuite.CreateNewStorageProvider() - s.T().Logf("new SP Info: %s", sp.Info.String()) - - successorSp := s.BaseSuite.PickStorageProvider() - - // 2, create a new gvg group for this storage provider - var secondarySPIDs []uint32 - for _, ssp := range s.StorageProviders { - if ssp.Info.Id != successorSp.Info.Id { - secondarySPIDs = append(secondarySPIDs, ssp.Info.Id) - } - if len(secondarySPIDs) == 6 { - break - } - } - - gvgID, familyID := s.BaseSuite.CreateGlobalVirtualGroup(sp, 0, secondarySPIDs, 1) - - // 3. create object - s.BaseSuite.CreateObject(user, sp, gvgID, storagetestutil.GenRandomBucketName(), storagetestutil.GenRandomObjectName()) - - // 4. Create another gvg contains this new sp - var anotherSP *core.StorageProvider - for _, tsp := range s.StorageProviders { - if tsp.Info.Id != sp.Info.Id && tsp.Info.Id != successorSp.Info.Id { - anotherSP = tsp - break - } - } - var anotherSecondarySPIDs []uint32 - for _, ssp := range s.StorageProviders { - if ssp.Info.Id != successorSp.Info.Id && ssp.Info.Id != anotherSP.Info.Id { - anotherSecondarySPIDs = append(anotherSecondarySPIDs, ssp.Info.Id) - } - if len(anotherSecondarySPIDs) == 5 { - break - } - } - anotherSecondarySPIDs = append(anotherSecondarySPIDs, sp.Info.Id) - - anotherGVGID, _ := s.BaseSuite.CreateGlobalVirtualGroup(anotherSP, 0, anotherSecondarySPIDs, 1) - - // 5. sp exit - s.SendTxBlock(sp.OperatorKey, &virtualgroupmoduletypes.MsgStorageProviderExit{ - StorageProvider: sp.OperatorKey.GetAddr().String(), - }) - - resp, err := s.Client.StorageProvider(context.Background(), &sptypes.QueryStorageProviderRequest{Id: sp.Info.Id}) - s.Require().NoError(err) - s.Require().Equal(resp.StorageProvider.Status, sptypes.STATUS_GRACEFUL_EXITING) - - // 6. sp complete exit failed - s.SendTxBlockWithExpectErrorString( - &virtualgroupmoduletypes.MsgCompleteStorageProviderExit{StorageProvider: sp.OperatorKey.GetAddr().String()}, - sp.OperatorKey, - "not swap out from all the family") - - // 7. swap out, as primary sp - msgSwapOut := virtualgroupmoduletypes.NewMsgSwapOut(sp.OperatorKey.GetAddr(), familyID, nil, successorSp.Info.Id) - msgSwapOut.SuccessorSpApproval = &common.Approval{ExpiredHeight: math.MaxUint} - msgSwapOut.SuccessorSpApproval.Sig, err = successorSp.ApprovalKey.Sign(msgSwapOut.GetApprovalBytes()) - s.Require().NoError(err) - s.SendTxBlock(sp.OperatorKey, msgSwapOut) - - // 9. cancel swap out - msgCancelSwapOut := virtualgroupmoduletypes.NewMsgCancelSwapOut(sp.OperatorKey.GetAddr(), familyID, nil) - s.Require().NoError(err) - s.SendTxBlock(sp.OperatorKey, msgCancelSwapOut) - - // 10. complete swap out, as primary sp - msgCompleteSwapOut := virtualgroupmoduletypes.NewMsgCompleteSwapOut(successorSp.OperatorKey.GetAddr(), familyID, nil) - s.Require().NoError(err) - s.SendTxBlockWithExpectErrorString(msgCompleteSwapOut, successorSp.OperatorKey, "The swap info not found in blockchain") - - // 11 swap again - msgSwapOut = virtualgroupmoduletypes.NewMsgSwapOut(sp.OperatorKey.GetAddr(), familyID, nil, successorSp.Info.Id) - msgSwapOut.SuccessorSpApproval = &common.Approval{ExpiredHeight: math.MaxUint} - msgSwapOut.SuccessorSpApproval.Sig, err = successorSp.ApprovalKey.Sign(msgSwapOut.GetApprovalBytes()) - s.Require().NoError(err) - s.SendTxBlock(sp.OperatorKey, msgSwapOut) - - // 12. sp complete exit failed - s.SendTxBlockWithExpectErrorString( - &virtualgroupmoduletypes.MsgCompleteStorageProviderExit{StorageProvider: sp.OperatorKey.GetAddr().String()}, - sp.OperatorKey, - "not swap out from all the family") - - // 13. complete swap out, as primary sp - msgCompleteSwapOut = virtualgroupmoduletypes.NewMsgCompleteSwapOut(successorSp.OperatorKey.GetAddr(), familyID, nil) - s.Require().NoError(err) - s.SendTxBlock(successorSp.OperatorKey, msgCompleteSwapOut) - - // 14. exist failed - s.SendTxBlockWithExpectErrorString( - &virtualgroupmoduletypes.MsgCompleteStorageProviderExit{StorageProvider: sp.OperatorKey.GetAddr().String()}, - sp.OperatorKey, - "not swap out from all the gvgs") - - // 15. swap out, as secondary sp - msgSwapOut2 := virtualgroupmoduletypes.NewMsgSwapOut(sp.OperatorKey.GetAddr(), 0, []uint32{anotherGVGID}, successorSp.Info.Id) - msgSwapOut2.SuccessorSpApproval = &common.Approval{ExpiredHeight: math.MaxUint} - msgSwapOut2.SuccessorSpApproval.Sig, err = successorSp.ApprovalKey.Sign(msgSwapOut2.GetApprovalBytes()) - s.Require().NoError(err) - s.SendTxBlock(sp.OperatorKey, msgSwapOut2) - - // 16. exist failed - s.SendTxBlockWithExpectErrorString( - &virtualgroupmoduletypes.MsgCompleteStorageProviderExit{StorageProvider: sp.OperatorKey.GetAddr().String()}, - sp.OperatorKey, - "not swap out from all the gvgs") - - // 17 cancel swap out as secondary sp - msgCancelSwapOut = virtualgroupmoduletypes.NewMsgCancelSwapOut(sp.OperatorKey.GetAddr(), 0, []uint32{anotherGVGID}) - s.Require().NoError(err) - s.SendTxBlock(sp.OperatorKey, msgCancelSwapOut) - - // 18. swap - msgCompleteSwapOut2 := virtualgroupmoduletypes.NewMsgCompleteSwapOut(successorSp.OperatorKey.GetAddr(), 0, []uint32{anotherGVGID}) - s.Require().NoError(err) - s.SendTxBlockWithExpectErrorString(msgCompleteSwapOut2, successorSp.OperatorKey, "The swap info not found in blockchain") - - // 19. swap out again, as secondary sp - msgSwapOut2 = virtualgroupmoduletypes.NewMsgSwapOut(sp.OperatorKey.GetAddr(), 0, []uint32{anotherGVGID}, successorSp.Info.Id) - msgSwapOut2.SuccessorSpApproval = &common.Approval{ExpiredHeight: math.MaxUint} - msgSwapOut2.SuccessorSpApproval.Sig, err = successorSp.ApprovalKey.Sign(msgSwapOut2.GetApprovalBytes()) - s.Require().NoError(err) - s.SendTxBlock(sp.OperatorKey, msgSwapOut2) - - // 20 complete swap out - msgCompleteSwapOut2 = virtualgroupmoduletypes.NewMsgCompleteSwapOut(successorSp.OperatorKey.GetAddr(), 0, []uint32{anotherGVGID}) - s.Require().NoError(err) - s.SendTxBlock(successorSp.OperatorKey, msgCompleteSwapOut2) - - // 18. sp complete exit success - s.SendTxBlock( - sp.OperatorKey, - &virtualgroupmoduletypes.MsgCompleteStorageProviderExit{StorageProvider: sp.OperatorKey.GetAddr().String()}, - ) -} - -func (s *VirtualGroupTestSuite) TestSPExit_CreateAndDeleteBucket() { - user := s.GenAndChargeAccounts(1, 1000000)[0] - bucketName := storagetestutil.GenRandomBucketName() - objectName := storagetestutil.GenRandomObjectName() - // 1, create a new storage provider - sp := s.BaseSuite.CreateNewStorageProvider() - s.T().Logf("new SP Info: %s", sp.Info.String()) - - successorSp := s.BaseSuite.PickStorageProvider() - - // 2, create a new gvg group for this storage provider - var secondarySPIDs []uint32 - for _, ssp := range s.StorageProviders { - if ssp.Info.Id != successorSp.Info.Id { - secondarySPIDs = append(secondarySPIDs, ssp.Info.Id) - } - if len(secondarySPIDs) == 6 { - break - } - } - - gvgID, _ := s.BaseSuite.CreateGlobalVirtualGroup(sp, 0, secondarySPIDs, 1) - - // 3. create object - s.BaseSuite.CreateObject(user, sp, gvgID, bucketName, objectName) - - // 4. sp apply exit - s.SendTxBlock(sp.OperatorKey, &virtualgroupmoduletypes.MsgStorageProviderExit{ - StorageProvider: sp.OperatorKey.GetAddr().String(), - }) - - resp, err := s.Client.StorageProvider(context.Background(), &sptypes.QueryStorageProviderRequest{Id: sp.Info.Id}) - s.Require().NoError(err) - s.Require().Equal(resp.StorageProvider.Status, sptypes.STATUS_GRACEFUL_EXITING) - - // 5. sp complete exit failed - s.SendTxBlockWithExpectErrorString( - &virtualgroupmoduletypes.MsgCompleteStorageProviderExit{StorageProvider: sp.OperatorKey.GetAddr().String()}, - sp.OperatorKey, - "not swap out from all the family") - - // 6. delete object - s.SendTxBlock(user, storagetypes.NewMsgDeleteObject(user.GetAddr(), bucketName, objectName)) - - // 7. delete bucket - s.SendTxBlock(user, storagetypes.NewMsgDeleteBucket(user.GetAddr(), bucketName)) - - // 8. delete gvg - s.SendTxBlock(sp.OperatorKey, virtualgroupmoduletypes.NewMsgDeleteGlobalVirtualGroup(sp.OperatorKey.GetAddr(), gvgID)) - // 8. sp complete exit success - s.SendTxBlock( - sp.OperatorKey, - &virtualgroupmoduletypes.MsgCompleteStorageProviderExit{StorageProvider: sp.OperatorKey.GetAddr().String()}, - ) -} +//func (s *VirtualGroupTestSuite) TestSPExit() { +// user := s.GenAndChargeAccounts(1, 1000000)[0] +// // 1, create a new storage provider +// sp := s.BaseSuite.CreateNewStorageProvider() +// s.T().Logf("new SP Info: %s", sp.Info.String()) +// +// successorSp := s.BaseSuite.PickStorageProvider() +// +// // 2, create a new gvg group for this storage provider +// var secondarySPIDs []uint32 +// for _, ssp := range s.StorageProviders { +// if ssp.Info.Id != successorSp.Info.Id { +// secondarySPIDs = append(secondarySPIDs, ssp.Info.Id) +// } +// if len(secondarySPIDs) == 6 { +// break +// } +// } +// +// gvgID, familyID := s.BaseSuite.CreateGlobalVirtualGroup(sp, 0, secondarySPIDs, 1) +// +// // 3. create object +// s.BaseSuite.CreateObject(user, sp, gvgID, storagetestutil.GenRandomBucketName(), storagetestutil.GenRandomObjectName()) +// +// // 4. Create another gvg contains this new sp +// var anotherSP *core.StorageProvider +// for _, tsp := range s.StorageProviders { +// if tsp.Info.Id != sp.Info.Id && tsp.Info.Id != successorSp.Info.Id { +// anotherSP = tsp +// break +// } +// } +// var anotherSecondarySPIDs []uint32 +// for _, ssp := range s.StorageProviders { +// if ssp.Info.Id != successorSp.Info.Id && ssp.Info.Id != anotherSP.Info.Id { +// anotherSecondarySPIDs = append(anotherSecondarySPIDs, ssp.Info.Id) +// } +// if len(anotherSecondarySPIDs) == 5 { +// break +// } +// } +// anotherSecondarySPIDs = append(anotherSecondarySPIDs, sp.Info.Id) +// +// anotherGVGID, _ := s.BaseSuite.CreateGlobalVirtualGroup(anotherSP, 0, anotherSecondarySPIDs, 1) +// +// // 5. sp exit +// s.SendTxBlock(sp.OperatorKey, &virtualgroupmoduletypes.MsgStorageProviderExit{ +// StorageProvider: sp.OperatorKey.GetAddr().String(), +// }) +// +// resp, err := s.Client.StorageProvider(context.Background(), &sptypes.QueryStorageProviderRequest{Id: sp.Info.Id}) +// s.Require().NoError(err) +// s.Require().Equal(resp.StorageProvider.Status, sptypes.STATUS_GRACEFUL_EXITING) +// +// // 6. sp complete exit failed +// s.SendTxBlockWithExpectErrorString( +// &virtualgroupmoduletypes.MsgCompleteStorageProviderExit{StorageProvider: sp.OperatorKey.GetAddr().String()}, +// sp.OperatorKey, +// "not swap out from all the family") +// +// // 7. swap out, as primary sp +// msgSwapOut := virtualgroupmoduletypes.NewMsgSwapOut(sp.OperatorKey.GetAddr(), familyID, nil, successorSp.Info.Id) +// msgSwapOut.SuccessorSpApproval = &common.Approval{ExpiredHeight: math.MaxUint} +// msgSwapOut.SuccessorSpApproval.Sig, err = successorSp.ApprovalKey.Sign(msgSwapOut.GetApprovalBytes()) +// s.Require().NoError(err) +// s.SendTxBlock(sp.OperatorKey, msgSwapOut) +// +// // 9. cancel swap out +// msgCancelSwapOut := virtualgroupmoduletypes.NewMsgCancelSwapOut(sp.OperatorKey.GetAddr(), familyID, nil) +// s.Require().NoError(err) +// s.SendTxBlock(sp.OperatorKey, msgCancelSwapOut) +// +// // 10. complete swap out, as primary sp +// msgCompleteSwapOut := virtualgroupmoduletypes.NewMsgCompleteSwapOut(successorSp.OperatorKey.GetAddr(), familyID, nil) +// s.Require().NoError(err) +// s.SendTxBlockWithExpectErrorString(msgCompleteSwapOut, successorSp.OperatorKey, "The swap info not found in blockchain") +// +// // 11 swap again +// msgSwapOut = virtualgroupmoduletypes.NewMsgSwapOut(sp.OperatorKey.GetAddr(), familyID, nil, successorSp.Info.Id) +// msgSwapOut.SuccessorSpApproval = &common.Approval{ExpiredHeight: math.MaxUint} +// msgSwapOut.SuccessorSpApproval.Sig, err = successorSp.ApprovalKey.Sign(msgSwapOut.GetApprovalBytes()) +// s.Require().NoError(err) +// s.SendTxBlock(sp.OperatorKey, msgSwapOut) +// +// // 12. sp complete exit failed +// s.SendTxBlockWithExpectErrorString( +// &virtualgroupmoduletypes.MsgCompleteStorageProviderExit{StorageProvider: sp.OperatorKey.GetAddr().String()}, +// sp.OperatorKey, +// "not swap out from all the family") +// +// // 13. complete swap out, as primary sp +// msgCompleteSwapOut = virtualgroupmoduletypes.NewMsgCompleteSwapOut(successorSp.OperatorKey.GetAddr(), familyID, nil) +// s.Require().NoError(err) +// s.SendTxBlock(successorSp.OperatorKey, msgCompleteSwapOut) +// +// // 14. exist failed +// s.SendTxBlockWithExpectErrorString( +// &virtualgroupmoduletypes.MsgCompleteStorageProviderExit{StorageProvider: sp.OperatorKey.GetAddr().String()}, +// sp.OperatorKey, +// "not swap out from all the gvgs") +// +// // 15. swap out, as secondary sp +// msgSwapOut2 := virtualgroupmoduletypes.NewMsgSwapOut(sp.OperatorKey.GetAddr(), 0, []uint32{anotherGVGID}, successorSp.Info.Id) +// msgSwapOut2.SuccessorSpApproval = &common.Approval{ExpiredHeight: math.MaxUint} +// msgSwapOut2.SuccessorSpApproval.Sig, err = successorSp.ApprovalKey.Sign(msgSwapOut2.GetApprovalBytes()) +// s.Require().NoError(err) +// s.SendTxBlock(sp.OperatorKey, msgSwapOut2) +// +// // 16. exist failed +// s.SendTxBlockWithExpectErrorString( +// &virtualgroupmoduletypes.MsgCompleteStorageProviderExit{StorageProvider: sp.OperatorKey.GetAddr().String()}, +// sp.OperatorKey, +// "not swap out from all the gvgs") +// +// // 17 cancel swap out as secondary sp +// msgCancelSwapOut = virtualgroupmoduletypes.NewMsgCancelSwapOut(sp.OperatorKey.GetAddr(), 0, []uint32{anotherGVGID}) +// s.Require().NoError(err) +// s.SendTxBlock(sp.OperatorKey, msgCancelSwapOut) +// +// // 18. swap +// msgCompleteSwapOut2 := virtualgroupmoduletypes.NewMsgCompleteSwapOut(successorSp.OperatorKey.GetAddr(), 0, []uint32{anotherGVGID}) +// s.Require().NoError(err) +// s.SendTxBlockWithExpectErrorString(msgCompleteSwapOut2, successorSp.OperatorKey, "The swap info not found in blockchain") +// +// // 19. swap out again, as secondary sp +// msgSwapOut2 = virtualgroupmoduletypes.NewMsgSwapOut(sp.OperatorKey.GetAddr(), 0, []uint32{anotherGVGID}, successorSp.Info.Id) +// msgSwapOut2.SuccessorSpApproval = &common.Approval{ExpiredHeight: math.MaxUint} +// msgSwapOut2.SuccessorSpApproval.Sig, err = successorSp.ApprovalKey.Sign(msgSwapOut2.GetApprovalBytes()) +// s.Require().NoError(err) +// s.SendTxBlock(sp.OperatorKey, msgSwapOut2) +// +// // 20 complete swap out +// msgCompleteSwapOut2 = virtualgroupmoduletypes.NewMsgCompleteSwapOut(successorSp.OperatorKey.GetAddr(), 0, []uint32{anotherGVGID}) +// s.Require().NoError(err) +// s.SendTxBlock(successorSp.OperatorKey, msgCompleteSwapOut2) +// +// // 18. sp complete exit success +// s.SendTxBlock( +// sp.OperatorKey, +// &virtualgroupmoduletypes.MsgCompleteStorageProviderExit{StorageProvider: sp.OperatorKey.GetAddr().String()}, +// ) +//} + +//func (s *VirtualGroupTestSuite) TestSPExit_CreateAndDeleteBucket() { +// user := s.GenAndChargeAccounts(1, 1000000)[0] +// bucketName := storagetestutil.GenRandomBucketName() +// objectName := storagetestutil.GenRandomObjectName() +// // 1, create a new storage provider +// sp := s.BaseSuite.CreateNewStorageProvider() +// s.T().Logf("new SP Info: %s", sp.Info.String()) +// +// successorSp := s.BaseSuite.PickStorageProvider() +// +// // 2, create a new gvg group for this storage provider +// var secondarySPIDs []uint32 +// for _, ssp := range s.StorageProviders { +// if ssp.Info.Id != successorSp.Info.Id { +// secondarySPIDs = append(secondarySPIDs, ssp.Info.Id) +// } +// if len(secondarySPIDs) == 6 { +// break +// } +// } +// +// gvgID, _ := s.BaseSuite.CreateGlobalVirtualGroup(sp, 0, secondarySPIDs, 1) +// +// // 3. create object +// s.BaseSuite.CreateObject(user, sp, gvgID, bucketName, objectName) +// +// // 4. sp apply exit +// s.SendTxBlock(sp.OperatorKey, &virtualgroupmoduletypes.MsgStorageProviderExit{ +// StorageProvider: sp.OperatorKey.GetAddr().String(), +// }) +// +// resp, err := s.Client.StorageProvider(context.Background(), &sptypes.QueryStorageProviderRequest{Id: sp.Info.Id}) +// s.Require().NoError(err) +// s.Require().Equal(resp.StorageProvider.Status, sptypes.STATUS_GRACEFUL_EXITING) +// +// // 5. sp complete exit failed +// s.SendTxBlockWithExpectErrorString( +// &virtualgroupmoduletypes.MsgCompleteStorageProviderExit{StorageProvider: sp.OperatorKey.GetAddr().String()}, +// sp.OperatorKey, +// "not swap out from all the family") +// +// // 6. delete object +// s.SendTxBlock(user, storagetypes.NewMsgDeleteObject(user.GetAddr(), bucketName, objectName)) +// +// // 7. delete bucket +// s.SendTxBlock(user, storagetypes.NewMsgDeleteBucket(user.GetAddr(), bucketName)) +// +// // 8. delete gvg +// s.SendTxBlock(sp.OperatorKey, virtualgroupmoduletypes.NewMsgDeleteGlobalVirtualGroup(sp.OperatorKey.GetAddr(), gvgID)) +// // 8. sp complete exit success +// s.SendTxBlock( +// sp.OperatorKey, +// &virtualgroupmoduletypes.MsgCompleteStorageProviderExit{StorageProvider: sp.OperatorKey.GetAddr().String()}, +// ) +//} func (s *VirtualGroupTestSuite) TestUpdateVirtualGroupParams() { // 1. create proposal