Skip to content

Commit

Permalink
reject deleting discontinued objects
Browse files Browse the repository at this point in the history
  • Loading branch information
forcodedancing committed Mar 8, 2024
1 parent db91b66 commit dd74b40
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
3 changes: 1 addition & 2 deletions e2e/tests/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
"testing"
"time"

paymenttypes "github.com/bnb-chain/greenfield/x/payment/types"

sdkmath "cosmossdk.io/math"
ctypes "github.com/cometbft/cometbft/rpc/core/types"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -30,6 +28,7 @@ import (
"github.com/bnb-chain/greenfield/sdk/types"
storageutils "github.com/bnb-chain/greenfield/testutil/storage"
types2 "github.com/bnb-chain/greenfield/types"
paymenttypes "github.com/bnb-chain/greenfield/x/payment/types"
sptypes "github.com/bnb-chain/greenfield/x/sp/types"
storagetypes "github.com/bnb-chain/greenfield/x/storage/types"
)
Expand Down
4 changes: 2 additions & 2 deletions x/payment/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ func TestParamsByTimestampQuery(t *testing.T) {
require.NoError(t, err)

response, err := keeper.ParamsByTimestamp(ctx, &types.QueryParamsByTimestampRequest{
Timestamp: before.Unix(),
Timestamp: before.Unix() + 1,
})
require.NoError(t, err)
require.True(t, newReserveTime != response.Params.VersionedParams.ReserveTime)

response, err = keeper.ParamsByTimestamp(ctx, &types.QueryParamsByTimestampRequest{
Timestamp: after.Unix(),
Timestamp: after.Unix() + 1,
})
require.NoError(t, err)
require.True(t, newReserveTime == response.Params.VersionedParams.ReserveTime)
Expand Down
5 changes: 5 additions & 0 deletions x/storage/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,11 @@ func (k Keeper) DeleteObject(
return types.ErrNoSuchObject
}

if objectInfo.ObjectStatus == types.OBJECT_STATUS_DISCONTINUED {
return types.ErrInvalidObjectStatus.Wrapf("The object %s is discontined, will be deleted automatically",
objectInfo.ObjectName)
}

if objectInfo.SourceType != opts.SourceType {
return types.ErrSourceTypeMismatch
}
Expand Down

0 comments on commit dd74b40

Please sign in to comment.