Skip to content

Commit

Permalink
fix the test cases and rebase code
Browse files Browse the repository at this point in the history
  • Loading branch information
yutianwu committed Mar 11, 2024
1 parent e544b3d commit 8e30d35
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 28 deletions.
74 changes: 46 additions & 28 deletions e2e/tests/storage_rate_limit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ func (s *StorageTestSuite) TestSetBucketRateLimitToZero() {
msgSetBucketRateLimit := storagetypes.NewMsgSetBucketFlowRateLimit(s.User.GetAddr(), s.User.GetAddr(), s.User.GetAddr(), bucketName, sdkmath.NewInt(0))
s.SendTxBlock(s.User, msgSetBucketRateLimit)

queryHeadBucketRequest = storagetypes.QueryHeadBucketRequest{
BucketName: bucketName,
}
queryHeadBucketResponse, err = s.Client.HeadBucket(ctx, &queryHeadBucketRequest)
s.Require().NoError(err)

s.Require().Equal(queryHeadBucketResponse.ExtraInfo.IsRateLimited, true)
s.Require().Equal(queryHeadBucketResponse.ExtraInfo.FlowRateLimit.String(), "0")

// CreateObject
objectName := storageutils.GenRandomObjectName()
// create test buffer
Expand Down Expand Up @@ -122,10 +131,6 @@ func (s *StorageTestSuite) TestNotOwnerSetBucketRateLimit_Object() {
s.Require().NoError(err)
s.Require().Equal(queryHeadBucketResponse.BucketInfo.CreateAt, queryQuotaUpdateTimeResponse.UpdateAt)

fmt.Printf("User: %s\n", s.User.GetAddr().String())
fmt.Printf("queryHeadBucketResponse.BucketInfo.Owner: %s\n", queryHeadBucketResponse.BucketInfo.Owner)
fmt.Printf("queryHeadBucketResponse.BucketInfo.PaymentAccount: %s\n", queryHeadBucketResponse.BucketInfo.PaymentAddress)

// SetBucketRateLimit
msgSetBucketRateLimit := storagetypes.NewMsgSetBucketFlowRateLimit(paymentAcc.GetAddr(), s.User.GetAddr(), paymentAcc.GetAddr(), bucketName, sdkmath.NewInt(100000000000000))
s.SendTxBlock(paymentAcc, msgSetBucketRateLimit)
Expand Down Expand Up @@ -155,17 +160,16 @@ func (s *StorageTestSuite) TestNotOwnerSetBucketRateLimit_Object() {
objectName = storageutils.GenRandomObjectName()
msgCreateObject = storagetypes.NewMsgCreateObject(user.GetAddr(), bucketName, objectName, uint64(payloadSize), storagetypes.VISIBILITY_TYPE_PRIVATE, expectChecksum, contextType, storagetypes.REDUNDANCY_EC_TYPE, math.MaxUint, nil)
msgCreateObject.PrimarySpApproval.Sig, err = sp.ApprovalKey.Sign(msgCreateObject.GetApprovalBytes())

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

View workflow job for this annotation

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

ineffectual assignment to err (ineffassign)
s.Require().NoError(err)
s.SendTxBlockWithExpectErrorString(msgCreateObject, user, "greater than the flow rate limit")

// SetBucketRateLimit
msgSetBucketRateLimit = storagetypes.NewMsgSetBucketFlowRateLimit(paymentAcc.GetAddr(), s.User.GetAddr(), paymentAcc.GetAddr(), bucketName, sdkmath.NewInt(100000000000000))
s.SendTxBlock(paymentAcc, msgSetBucketRateLimit)

// create object
objectName = storageutils.GenRandomObjectName()
msgCreateObject = storagetypes.NewMsgCreateObject(user.GetAddr(), bucketName, objectName, uint64(payloadSize), storagetypes.VISIBILITY_TYPE_PRIVATE, expectChecksum, contextType, storagetypes.REDUNDANCY_EC_TYPE, math.MaxUint, nil)
msgCreateObject.PrimarySpApproval.Sig, err = sp.ApprovalKey.Sign(msgCreateObject.GetApprovalBytes())

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

View workflow job for this annotation

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

ineffectual assignment to err (ineffassign)
s.Require().NoError(err)
s.SendTxBlock(user, msgCreateObject)
}

Expand Down Expand Up @@ -216,10 +220,6 @@ func (s *StorageTestSuite) TestNotOwnerSetBucketRateLimit_Bucket() {
s.Require().NoError(err)
s.Require().Equal(queryHeadBucketResponse.BucketInfo.CreateAt, queryQuotaUpdateTimeResponse.UpdateAt)

fmt.Printf("User: %s\n", s.User.GetAddr().String())
fmt.Printf("queryHeadBucketResponse.BucketInfo.Owner: %s\n", queryHeadBucketResponse.BucketInfo.Owner)
fmt.Printf("queryHeadBucketResponse.BucketInfo.PaymentAccount: %s\n", queryHeadBucketResponse.BucketInfo.PaymentAddress)

// SetBucketRateLimit
msgSetBucketRateLimit := storagetypes.NewMsgSetBucketFlowRateLimit(paymentAcc.GetAddr(), s.User.GetAddr(), paymentAcc.GetAddr(), bucketName, sdkmath.NewInt(100000000000))
s.SendTxBlock(paymentAcc, msgSetBucketRateLimit)
Expand All @@ -228,32 +228,43 @@ func (s *StorageTestSuite) TestNotOwnerSetBucketRateLimit_Bucket() {
var readQuota uint64 = 100
msgUpdateBucketInfo := storagetypes.NewMsgUpdateBucketInfo(
user.GetAddr(), bucketName, &readQuota, nil, storagetypes.VISIBILITY_TYPE_PUBLIC_READ)
s.Require().NoError(err)
s.SendTxBlock(user, msgUpdateBucketInfo)
s.Require().NoError(err)

// SetBucketRateLimit
msgSetBucketRateLimit = storagetypes.NewMsgSetBucketFlowRateLimit(paymentAcc.GetAddr(), s.User.GetAddr(), paymentAcc.GetAddr(), bucketName, sdkmath.NewInt(0))
s.SendTxBlock(paymentAcc, msgSetBucketRateLimit)

// CreateObject
queryHeadBucketRequest = storagetypes.QueryHeadBucketRequest{
BucketName: bucketName,
}
queryHeadBucketResponse, err = s.Client.HeadBucket(ctx, &queryHeadBucketRequest)
s.Require().NoError(err)

s.Require().Equal(queryHeadBucketResponse.ExtraInfo.IsRateLimited, true)

// update bucket
readQuota = 101
msgUpdateBucketInfo = storagetypes.NewMsgUpdateBucketInfo(
user.GetAddr(), bucketName, &readQuota, nil, storagetypes.VISIBILITY_TYPE_PUBLIC_READ)
s.Require().NoError(err)
s.SendTxBlockWithExpectErrorString(msgUpdateBucketInfo, user, "greater than the flow rate limit")
s.Require().NoError(err)
s.SendTxBlockWithExpectErrorString(msgUpdateBucketInfo, user, "payment account is not changed but the bucket is limited")

// SetBucketRateLimit
msgSetBucketRateLimit = storagetypes.NewMsgSetBucketFlowRateLimit(paymentAcc.GetAddr(), s.User.GetAddr(), paymentAcc.GetAddr(), bucketName, sdkmath.NewInt(100000000000))
s.SendTxBlock(paymentAcc, msgSetBucketRateLimit)

queryHeadBucketRequest = storagetypes.QueryHeadBucketRequest{
BucketName: bucketName,
}
queryHeadBucketResponse, err = s.Client.HeadBucket(ctx, &queryHeadBucketRequest)
s.Require().NoError(err)

s.Require().Equal(queryHeadBucketResponse.ExtraInfo.IsRateLimited, false)

// update bucket
readQuota = 102
msgUpdateBucketInfo = storagetypes.NewMsgUpdateBucketInfo(
user.GetAddr(), bucketName, &readQuota, nil, storagetypes.VISIBILITY_TYPE_PUBLIC_READ)
s.Require().NoError(err)
s.SendTxBlock(user, msgUpdateBucketInfo)
s.Require().NoError(err)
}

// TestNotOwnerSetBucketRateLimit_BucketPaymentAccount
Expand Down Expand Up @@ -303,42 +314,48 @@ func (s *StorageTestSuite) TestNotOwnerSetBucketRateLimit_BucketPaymentAccount()
s.Require().NoError(err)
s.Require().Equal(queryHeadBucketResponse.BucketInfo.CreateAt, queryQuotaUpdateTimeResponse.UpdateAt)

fmt.Printf("User: %s\n", s.User.GetAddr().String())
fmt.Printf("queryHeadBucketResponse.BucketInfo.Owner: %s\n", queryHeadBucketResponse.BucketInfo.Owner)
fmt.Printf("queryHeadBucketResponse.BucketInfo.PaymentAccount: %s\n", queryHeadBucketResponse.BucketInfo.PaymentAddress)

// SetBucketRateLimit
msgSetBucketRateLimit := storagetypes.NewMsgSetBucketFlowRateLimit(s.User.GetAddr(), s.User.GetAddr(), s.User.GetAddr(), bucketName, sdkmath.NewInt(0))
s.SendTxBlock(s.User, msgSetBucketRateLimit)

// SetBucketRateLimit
msgUpdateBucketInfo := storagetypes.NewMsgUpdateBucketInfo(
user.GetAddr(), bucketName, nil, paymentAcc.GetAddr(), storagetypes.VISIBILITY_TYPE_PUBLIC_READ)
s.Require().NoError(err)
s.SendTxBlockWithExpectErrorString(msgUpdateBucketInfo, user, "the flow rate limit is not set")
s.Require().NoError(err)

// SetBucketRateLimit
msgSetBucketRateLimit = storagetypes.NewMsgSetBucketFlowRateLimit(paymentAcc.GetAddr(), s.User.GetAddr(), paymentAcc.GetAddr(), bucketName, sdkmath.NewInt(0))
s.SendTxBlock(paymentAcc, msgSetBucketRateLimit)

queryHeadBucketRequest = storagetypes.QueryHeadBucketRequest{
BucketName: bucketName,
}
queryHeadBucketResponse, err = s.Client.HeadBucket(ctx, &queryHeadBucketRequest)
s.Require().NoError(err)

s.Require().Equal(queryHeadBucketResponse.ExtraInfo.IsRateLimited, true)

// UpdateBucketInfo
msgUpdateBucketInfo = storagetypes.NewMsgUpdateBucketInfo(
user.GetAddr(), bucketName, nil, paymentAcc.GetAddr(), storagetypes.VISIBILITY_TYPE_PUBLIC_READ)
s.Require().NoError(err)
s.SendTxBlockWithExpectErrorString(msgUpdateBucketInfo, user, "greater than the flow rate limit")
s.Require().NoError(err)

// SetBucketRateLimit
msgSetBucketRateLimit = storagetypes.NewMsgSetBucketFlowRateLimit(paymentAcc.GetAddr(), s.User.GetAddr(), paymentAcc.GetAddr(), bucketName, sdkmath.NewInt(100000000000))
s.SendTxBlock(paymentAcc, msgSetBucketRateLimit)

queryHeadBucketRequest = storagetypes.QueryHeadBucketRequest{
BucketName: bucketName,
}
queryHeadBucketResponse, err = s.Client.HeadBucket(ctx, &queryHeadBucketRequest)
s.Require().NoError(err)

s.Require().Equal(queryHeadBucketResponse.ExtraInfo.IsRateLimited, false)

// UpdateBucketInfo
msgUpdateBucketInfo = storagetypes.NewMsgUpdateBucketInfo(
user.GetAddr(), bucketName, nil, paymentAcc.GetAddr(), storagetypes.VISIBILITY_TYPE_PUBLIC_READ)
s.Require().NoError(err)
s.SendTxBlock(user, msgUpdateBucketInfo)
s.Require().NoError(err)
}

func (s *StorageTestSuite) TestQueryBucketRateLimit() {
Expand Down Expand Up @@ -377,6 +394,7 @@ func (s *StorageTestSuite) TestQueryBucketRateLimit() {
queryBucketRateLimitRequest := storagetypes.QueryPaymentAccountBucketFlowRateLimitRequest{
PaymentAccount: paymentAcc.GetAddr().String(),
BucketName: bucketName,
BucketOwner: user.GetAddr().String(),
}
queryBucketRateLimitResponse, err := s.Client.QueryPaymentAccountBucketFlowRateLimit(ctx, &queryBucketRateLimitRequest)
s.Require().NoError(err)
Expand Down
3 changes: 3 additions & 0 deletions x/storage/keeper/bucket_rate_limit.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,9 @@ func (k Keeper) GetBucketExtraInfo(ctx sdk.Context, bucketInfo *types.BucketInfo
extraInfo.FlowRateLimit = rateLimit.FlowRateLimit
}

isRateLimited := k.IsBucketRateLimited(ctx, bucketInfo.BucketName)
extraInfo.IsRateLimited = isRateLimited

internalBucketInfo := k.MustGetInternalBucketInfo(ctx, bucketInfo.Id)

bill, err := k.GetBucketReadStoreBill(ctx, bucketInfo, internalBucketInfo)
Expand Down

0 comments on commit 8e30d35

Please sign in to comment.