Skip to content

Commit

Permalink
create object with new gvg
Browse files Browse the repository at this point in the history
  • Loading branch information
yutianwu committed Apr 2, 2024
1 parent 220ec82 commit df3ca6f
Show file tree
Hide file tree
Showing 2 changed files with 152 additions and 0 deletions.
129 changes: 129 additions & 0 deletions e2e/tests/storage_rate_limit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ import (
gashubtypes "github.com/cosmos/cosmos-sdk/x/gashub/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
govtypesv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
"github.com/prysmaticlabs/prysm/crypto/bls"

"github.com/bnb-chain/greenfield/e2e/core"
"github.com/bnb-chain/greenfield/sdk/keys"
virtualgrouptypes "github.com/bnb-chain/greenfield/x/virtualgroup/types"

types2 "github.com/bnb-chain/greenfield/sdk/types"

Expand Down Expand Up @@ -484,6 +489,8 @@ func (s *StorageTestSuite) TestQueryBucketRateLimit() {
}

func (s *StorageTestSuite) TestSetBucketFlowRateLimit_Discontinue() {
s.enableMessage()

sp, user, bucketName, _, _, _ := s.createObject()

// SetBucketRateLimit
Expand Down Expand Up @@ -515,3 +522,125 @@ func (s *StorageTestSuite) TestSetBucketFlowRateLimit_Discontinue() {
}
}
}

func (s *StorageTestSuite) createObjectWithNewGvg(v storagetypes.VisibilityType) (*core.StorageProvider, keys.KeyManager, string, storagetypes.Uint, string, storagetypes.Uint) {

Check failure on line 526 in e2e/tests/storage_rate_limit_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint (1.20.x, ubuntu-latest)

func `(*StorageTestSuite).createObjectWithNewGvg` is unused (unused)
var err error
// CreateBucket
sp := s.BaseSuite.PickStorageProvider()

_, secondarySps := s.GetSecondarySP(sp)
gvgID, _ := s.BaseSuite.CreateGlobalVirtualGroup(sp, 0, secondarySps, 1)
gvgResp, err := s.Client.VirtualGroupQueryClient.GlobalVirtualGroup(context.Background(), &virtualgrouptypes.QueryGlobalVirtualGroupRequest{
GlobalVirtualGroupId: gvgID,
})
s.Require().NoError(err)
gvg := gvgResp.GlobalVirtualGroup

user := s.GenAndChargeAccounts(1, 1000000)[0]
bucketName := storageutils.GenRandomBucketName()
msgCreateBucket := storagetypes.NewMsgCreateBucket(
user.GetAddr(), bucketName, v, sp.OperatorKey.GetAddr(),
nil, math.MaxUint, nil, 0)
msgCreateBucket.PrimarySpApproval.GlobalVirtualGroupFamilyId = gvg.FamilyId
msgCreateBucket.PrimarySpApproval.Sig, err = sp.ApprovalKey.Sign(msgCreateBucket.GetApprovalBytes())
s.Require().NoError(err)
s.SendTxBlock(user, msgCreateBucket)

// HeadBucket
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.Owner, user.GetAddr().String())
s.Require().Equal(queryHeadBucketResponse.BucketInfo.GlobalVirtualGroupFamilyId, gvg.FamilyId)
s.Require().Equal(queryHeadBucketResponse.BucketInfo.PaymentAddress, user.GetAddr().String())
s.Require().Equal(queryHeadBucketResponse.BucketInfo.Visibility, v)
s.Require().Equal(queryHeadBucketResponse.BucketInfo.SourceType, storagetypes.SOURCE_TYPE_ORIGIN)

// CreateObject
objectName := storageutils.GenRandomObjectName()
// create test buffer
var buffer bytes.Buffer
line := `1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,
1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,
1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,
1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,
1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,
1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,
1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,
1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,
1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,
1234567890,1234567890,1234567890,123`
// Create 1MiB content where each line contains 1024 characters.
for i := 0; i < 1024; i++ {
buffer.WriteString(fmt.Sprintf("[%05d] %s\n", i, line))
}
payloadSize := buffer.Len()
checksum := sdk.Keccak256(buffer.Bytes())
expectChecksum := [][]byte{checksum, checksum, checksum, checksum, checksum, checksum, checksum}
contextType := "text/event-stream"
msgCreateObject := storagetypes.NewMsgCreateObject(user.GetAddr(), bucketName, objectName, uint64(payloadSize), v, expectChecksum, contextType, storagetypes.REDUNDANCY_EC_TYPE, math.MaxUint, nil)
msgCreateObject.PrimarySpApproval.Sig, err = sp.ApprovalKey.Sign(msgCreateObject.GetApprovalBytes())
s.Require().NoError(err)
s.SendTxBlock(user, msgCreateObject)

// HeadObject
queryHeadObjectRequest := storagetypes.QueryHeadObjectRequest{
BucketName: bucketName,
ObjectName: objectName,
}
queryHeadObjectResponse, err := s.Client.HeadObject(ctx, &queryHeadObjectRequest)
s.Require().NoError(err)
s.Require().Equal(queryHeadObjectResponse.ObjectInfo.ObjectName, objectName)
s.Require().Equal(queryHeadObjectResponse.ObjectInfo.BucketName, bucketName)
s.Require().Equal(queryHeadObjectResponse.ObjectInfo.PayloadSize, uint64(payloadSize))
s.Require().Equal(queryHeadObjectResponse.ObjectInfo.Visibility, v)
s.Require().Equal(queryHeadObjectResponse.ObjectInfo.ObjectStatus, storagetypes.OBJECT_STATUS_CREATED)
s.Require().Equal(queryHeadObjectResponse.ObjectInfo.Owner, user.GetAddr().String())
s.Require().Equal(queryHeadObjectResponse.ObjectInfo.Checksums, expectChecksum)
s.Require().Equal(queryHeadObjectResponse.ObjectInfo.SourceType, storagetypes.SOURCE_TYPE_ORIGIN)
s.Require().Equal(queryHeadObjectResponse.ObjectInfo.RedundancyType, storagetypes.REDUNDANCY_EC_TYPE)
s.Require().Equal(queryHeadObjectResponse.ObjectInfo.ContentType, contextType)

// SealObject
gvgId := gvg.Id
msgSealObject := storagetypes.NewMsgSealObject(sp.SealKey.GetAddr(), bucketName, objectName, gvgId, nil)

secondarySigs := make([][]byte, 0)
secondarySPBlsPubKeys := make([]bls.PublicKey, 0)
blsSignHash := storagetypes.NewSecondarySpSealObjectSignDoc(s.GetChainID(), gvgId, queryHeadObjectResponse.ObjectInfo.Id, storagetypes.GenerateHash(queryHeadObjectResponse.ObjectInfo.Checksums[:])).GetBlsSignHash()
// every secondary sp signs the checksums
for _, spID := range gvg.SecondarySpIds {
sig, err := core.BlsSignAndVerify(s.StorageProviders[spID], blsSignHash)
s.Require().NoError(err)
secondarySigs = append(secondarySigs, sig)
pk, err := bls.PublicKeyFromBytes(s.StorageProviders[spID].BlsKey.PubKey().Bytes())
s.Require().NoError(err)
secondarySPBlsPubKeys = append(secondarySPBlsPubKeys, pk)
}
aggBlsSig, err := core.BlsAggregateAndVerify(secondarySPBlsPubKeys, blsSignHash, secondarySigs)
s.Require().NoError(err)
msgSealObject.SecondarySpBlsAggSignatures = aggBlsSig

s.T().Logf("msg %s", msgSealObject.String())
s.SendTxBlock(sp.SealKey, msgSealObject)

// ListBuckets
queryListBucketsRequest := storagetypes.QueryListBucketsRequest{}
queryListBucketResponse, err := s.Client.ListBuckets(ctx, &queryListBucketsRequest)
s.Require().NoError(err)
s.Require().Greater(len(queryListBucketResponse.BucketInfos), 0)

// ListObject
queryListObjectsRequest := storagetypes.QueryListObjectsRequest{
BucketName: bucketName,
}
queryListObjectsResponse, err := s.Client.ListObjects(ctx, &queryListObjectsRequest)
s.Require().NoError(err)
s.Require().Equal(len(queryListObjectsResponse.ObjectInfos), 1)
s.Require().Equal(queryListObjectsResponse.ObjectInfos[0].ObjectName, objectName)
return sp, user, bucketName, queryHeadBucketResponse.BucketInfo.Id, objectName, queryListObjectsResponse.ObjectInfos[0].Id
}
23 changes: 23 additions & 0 deletions e2e/tests/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,29 @@ func (s *StorageTestSuite) TestDiscontinueBucket_UserDeleted() {
s.Require().True(statusRes.SyncInfo.LatestBlockHeight > heightAfter)
}

func (s *StorageTestSuite) GetSecondarySP(sps ...*core.StorageProvider) ([]*core.StorageProvider, []uint32) {
var secondarySPs []*core.StorageProvider
var secondarySPIDs []uint32

for _, ssp := range s.StorageProviders {
isSecondSP := true
for _, sp := range sps {
if ssp.Info.Id == sp.Info.Id {
isSecondSP = false
break
}
}
if isSecondSP {
secondarySPIDs = append(secondarySPIDs, ssp.Info.Id)
secondarySPs = append(secondarySPs, ssp)
}
if len(secondarySPIDs) == 6 {
break
}
}
return secondarySPs, secondarySPIDs
}

// createObject with default VISIBILITY_TYPE_PRIVATE
func (s *StorageTestSuite) createObject() (*core.StorageProvider, keys.KeyManager, string, storagetypes.Uint, string, storagetypes.Uint) {
return s.createObjectWithVisibility(storagetypes.VISIBILITY_TYPE_PRIVATE)
Expand Down

0 comments on commit df3ca6f

Please sign in to comment.