Skip to content

Commit

Permalink
udpate mock files and fix test issues
Browse files Browse the repository at this point in the history
  • Loading branch information
forcodedancing committed Mar 8, 2024
1 parent 68e761d commit 8d672ac
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 164 deletions.
66 changes: 2 additions & 64 deletions e2e/tests/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -829,56 +829,11 @@ func (s *StorageTestSuite) TestDiscontinueObject_UserDeleted() {

// DiscontinueObject
msgDiscontinueObject := storagetypes.NewMsgDiscontinueObject(sp.GcKey.GetAddr(), bucketName, []sdkmath.Uint{objectId}, "test")
txRes := s.SendTxBlock(sp.GcKey, msgDiscontinueObject)
deleteAt := filterDiscontinueObjectEventFromTx(txRes).DeleteAt
_ = s.SendTxBlock(sp.GcKey, msgDiscontinueObject)

// DeleteObject before discontinue confirm window
msgDeleteObject := storagetypes.NewMsgDeleteObject(user.GetAddr(), bucketName, objectName)
txRes = s.SendTxBlock(user, msgDeleteObject)
event := filterDeleteObjectEventFromTx(txRes)
s.Require().Equal(event.ObjectId, objectId)

// Wait after the delete timestamp
heightBefore := txRes.Height
heightAfter := int64(0)
for {
time.Sleep(200 * time.Millisecond)
statusRes, err := s.TmClient.TmClient.Status(context.Background())
s.Require().NoError(err)
blockTime := statusRes.SyncInfo.LatestBlockTime.Unix()

s.T().Logf("current blockTime: %d, delete blockTime: %d", blockTime, deleteAt)

if blockTime >= deleteAt {
heightAfter = statusRes.SyncInfo.LatestBlockHeight
break
} else {
heightBefore = statusRes.SyncInfo.LatestBlockHeight
}
}

time.Sleep(200 * time.Millisecond)
events := make([]storagetypes.EventDeleteObject, 0)
for heightBefore <= heightAfter {
blockRes, err := s.TmClient.TmClient.BlockResults(context.Background(), &heightBefore)
s.Require().NoError(err)
events = append(events, filterDeleteObjectEventFromBlock(blockRes)...)
heightBefore++
}

// Already deleted by user
found := false
for _, event := range events {
if event.ObjectId.Equal(objectId) {
found = true
}
}
s.Require().True(!found)

time.Sleep(500 * time.Millisecond)
statusRes, err := s.TmClient.TmClient.Status(context.Background())
s.Require().NoError(err)
s.Require().True(statusRes.SyncInfo.LatestBlockHeight > heightAfter)
s.SendTxBlockWithExpectErrorString(msgDeleteObject, user, "is discontined")
}

func (s *StorageTestSuite) TestDiscontinueBucket_Normal() {
Expand Down Expand Up @@ -1191,23 +1146,6 @@ func filterDeleteObjectEventFromBlock(blockRes *ctypes.ResultBlockResults) []sto
return events
}

func filterDeleteObjectEventFromTx(txRes *sdk.TxResponse) storagetypes.EventDeleteObject {
objectIdStr := ""
for _, event := range txRes.Events {
if event.Type == "greenfield.storage.EventDeleteObject" {
for _, attr := range event.Attributes {
if string(attr.Key) == "object_id" {
objectIdStr = strings.Trim(string(attr.Value), `"`)
}
}
}
}
objectId := sdkmath.NewUintFromString(objectIdStr)
return storagetypes.EventDeleteObject{
ObjectId: objectId,
}
}

func filterDiscontinueBucketEventFromTx(txRes *sdk.TxResponse) storagetypes.EventDiscontinueBucket {
deleteAtStr := ""
for _, event := range txRes.Logs[0].Events {
Expand Down
2 changes: 1 addition & 1 deletion x/payment/keeper/grpc_query_params_by_timestamp.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func (k Keeper) ParamsByTimestamp(c context.Context, req *types.QueryParamsByTim

ts := req.GetTimestamp()
if ts == 0 {
ts = ctx.BlockTime().Unix()
ts = ctx.BlockTime().Unix() + 1
}

params := k.GetParams(ctx)
Expand Down
14 changes: 0 additions & 14 deletions x/payment/types/expected_keepers_mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion x/storage/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (k Keeper) QueryParamsByTimestamp(c context.Context, req *types.QueryParams

ts := req.GetTimestamp()
if ts == 0 {
ts = ctx.BlockTime().Unix()
ts = ctx.BlockTime().Unix() + 1
}

params := k.GetParams(ctx)
Expand Down
4 changes: 2 additions & 2 deletions x/storage/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ func (s *TestSuite) TestQueryVersionedParams() {
err = s.storageKeeper.SetParams(s.ctx, params)
s.Require().NoError(err)

responseT1, err := s.storageKeeper.QueryParamsByTimestamp(s.ctx, &types.QueryParamsByTimestampRequest{Timestamp: blockTimeT1})
responseT1, err := s.storageKeeper.QueryParamsByTimestamp(s.ctx, &types.QueryParamsByTimestampRequest{Timestamp: blockTimeT1 + 1})
s.Require().NoError(err)
s.Require().Equal(&types.QueryParamsByTimestampResponse{Params: paramsT1}, responseT1)
getParams := responseT1.GetParams()
s.Require().Equal(getParams.GetMaxSegmentSize(), uint64(1))

responseT2, err := s.storageKeeper.QueryParamsByTimestamp(s.ctx, &types.QueryParamsByTimestampRequest{Timestamp: blockTimeT2})
responseT2, err := s.storageKeeper.QueryParamsByTimestamp(s.ctx, &types.QueryParamsByTimestampRequest{Timestamp: blockTimeT2 + 1})
s.Require().NoError(err)
s.Require().Equal(&types.QueryParamsByTimestampResponse{Params: paramsT2}, responseT2)
p := responseT2.GetParams()
Expand Down
3 changes: 3 additions & 0 deletions x/storage/keeper/keeper_object_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package keeper_test

import (
"time"

"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/golang/mock/gomock"
Expand Down Expand Up @@ -202,6 +204,7 @@ func (s *TestSuite) TestCreateObject() {
OutFlowCount: 0,
FrozenNetflowRate: math.Int{},
}, nil).AnyTimes()
s.ctx = s.ctx.WithBlockTime(s.ctx.BlockTime().Add(1 * time.Second))
_, err = s.storageKeeper.CreateObject(s.ctx, operatorAddress, bucketInfo.BucketName,
objectName, 100, types.CreateObjectOptions{
Visibility: 0,
Expand Down
5 changes: 3 additions & 2 deletions x/storage/keeper/payment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,11 @@ func (s *TestSuite) TestGetObjectLockFee() {
Return(params.VersionedParams, nil).AnyTimes()

// verify lock fee calculation
timeNow := time.Now().Unix() + 1
payloadSize := int64(10 * 1024 * 1024)
amount, err := s.storageKeeper.GetObjectLockFee(s.ctx, time.Now().Unix(), uint64(payloadSize))
amount, err := s.storageKeeper.GetObjectLockFee(s.ctx, timeNow, uint64(payloadSize))
s.Require().NoError(err)
secondarySPNum := int64(s.storageKeeper.GetExpectSecondarySPNumForECObject(s.ctx, time.Now().Unix()))
secondarySPNum := int64(s.storageKeeper.GetExpectSecondarySPNumForECObject(s.ctx, timeNow))
spRate := price.PrimaryStorePrice.Add(price.SecondaryStorePrice.MulInt64(secondarySPNum)).MulInt64(payloadSize)
validatorTaxRate := params.VersionedParams.ValidatorTaxRate.MulInt(spRate.TruncateInt())
expectedAmount := spRate.Add(validatorTaxRate).MulInt64(int64(params.VersionedParams.ReserveTime)).TruncateInt()
Expand Down
97 changes: 53 additions & 44 deletions x/storage/types/expected_keepers_mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8d672ac

Please sign in to comment.