Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: change the default params of x/collection #894

Merged
merged 3 commits into from
Feb 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (cosmovisor) [\#792](https://github.com/line/lbm-sdk/pull/792) Use upstream's cosmovisor
* (server) [\#821](https://github.com/line/lbm-sdk/pull/821) Get validator pubkey considering KMS
* (client) [\#890](https://github.com/line/lbm-sdk/pull/890) Map Ostracon:ErrTxInMap to lbm-sdk:ErrTxInMempoolCache
* (x/collection) [\#894](https://github.com/line/lbm-sdk/pull/894) Change the default params of x/collection

### Bug Fixes
* (client) [\#817](https://github.com/line/lbm-sdk/pull/817) remove support for composite (BLS) type
Expand Down
15 changes: 14 additions & 1 deletion x/collection/client/testutil/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,21 @@ func NewIntegrationTestSuite(cfg network.Config) *IntegrationTestSuite {
func (s *IntegrationTestSuite) SetupSuite() {
s.T().Log("setting up integration test suite")

var gs collection.GenesisState
s.Require().NoError(s.cfg.Codec.UnmarshalJSON(s.cfg.GenesisState[collection.ModuleName], &gs))

params := collection.Params{
DepthLimit: 4,
WidthLimit: 4,
}
gs.Params = params

gsBz, err := s.cfg.Codec.MarshalJSON(&gs)
s.Require().NoError(err)
s.cfg.GenesisState[collection.ModuleName] = gsBz

s.network = network.New(s.T(), s.cfg)
_, err := s.network.WaitForHeight(1)
_, err = s.network.WaitForHeight(1)
s.Require().NoError(err)

s.vendor = s.createAccount("vendor")
Expand Down
4 changes: 2 additions & 2 deletions x/collection/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
)

const (
DefaultDepthLimit = 3
DefaultWidthLimit = 8
DefaultDepthLimit = 1
DefaultWidthLimit = 4
)

// ValidateGenesis check the given genesis state has no integrity issues
Expand Down
2 changes: 1 addition & 1 deletion x/collection/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

// InitGenesis new collection genesis
func (k Keeper) InitGenesis(ctx sdk.Context, data *collection.GenesisState) {
k.setParams(ctx, data.Params)
k.SetParams(ctx, data.Params)

for _, contract := range data.Contracts {
k.setContract(ctx, contract)
Expand Down
12 changes: 10 additions & 2 deletions x/collection/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ type KeeperTestSuite struct {

balance sdk.Int

depthLimit int

numNFTs int
numRoots int
}
Expand Down Expand Up @@ -65,6 +67,12 @@ func (s *KeeperTestSuite) SetupTest() {
s.queryServer = keeper.NewQueryServer(s.keeper)
s.msgServer = keeper.NewMsgServer(s.keeper)

s.depthLimit = 4
s.keeper.SetParams(s.ctx, collection.Params{
DepthLimit: uint32(s.depthLimit),
WidthLimit: 4,
})

addresses := []*sdk.AccAddress{
&s.vendor,
&s.operator,
Expand Down Expand Up @@ -130,11 +138,11 @@ func (s *KeeperTestSuite) SetupTest() {
}
// 1 for the successful attach, 2 for the failure
remainders := 1 + 2
s.numNFTs = collection.DefaultDepthLimit + remainders
s.numNFTs = s.depthLimit + remainders
// 3 chains, and each chain has depth_limit, 1 and 2 of its length.
s.numRoots = 3
for _, to := range []sdk.AccAddress{s.customer, s.operator, s.vendor} {
tokens, err := s.keeper.MintNFT(s.ctx, s.contractID, to, newParams(s.nftClassID, collection.DefaultDepthLimit))
tokens, err := s.keeper.MintNFT(s.ctx, s.contractID, to, newParams(s.nftClassID, s.depthLimit))
s.Require().NoError(err)

// create a chain of its length depth_limit
Expand Down
6 changes: 3 additions & 3 deletions x/collection/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,7 @@ func (s *KeeperTestSuite) TestMsgAttach() {
}{
"valid request": {
contractID: s.contractID,
subjectID: collection.NewNFTID(s.nftClassID, collection.DefaultDepthLimit+1),
subjectID: collection.NewNFTID(s.nftClassID, s.depthLimit+1),
targetID: collection.NewNFTID(s.nftClassID, 1),
},
"contract not found": {
Expand Down Expand Up @@ -1131,7 +1131,7 @@ func (s *KeeperTestSuite) TestMsgOperatorAttach() {
"valid request": {
contractID: s.contractID,
operator: s.operator,
subjectID: collection.NewNFTID(s.nftClassID, collection.DefaultDepthLimit+1),
subjectID: collection.NewNFTID(s.nftClassID, s.depthLimit+1),
targetID: collection.NewNFTID(s.nftClassID, 1),
},
"contract not found": {
Expand All @@ -1144,7 +1144,7 @@ func (s *KeeperTestSuite) TestMsgOperatorAttach() {
"not authorized": {
contractID: s.contractID,
operator: s.vendor,
subjectID: collection.NewNFTID(s.nftClassID, collection.DefaultDepthLimit+1),
subjectID: collection.NewNFTID(s.nftClassID, s.depthLimit+1),
targetID: collection.NewNFTID(s.nftClassID, 1),
err: collection.ErrCollectionNotApproved,
},
Expand Down
12 changes: 6 additions & 6 deletions x/collection/keeper/nft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ func (s *KeeperTestSuite) TestAttach() {
}{
"valid request": {
contractID: s.contractID,
subject: collection.NewNFTID(s.nftClassID, collection.DefaultDepthLimit+1),
target: collection.NewNFTID(s.nftClassID, collection.DefaultDepthLimit),
subject: collection.NewNFTID(s.nftClassID, s.depthLimit+1),
target: collection.NewNFTID(s.nftClassID, s.depthLimit),
},
"not owner of subject": {
contractID: s.contractID,
Expand All @@ -24,19 +24,19 @@ func (s *KeeperTestSuite) TestAttach() {
},
"target not found": {
contractID: s.contractID,
subject: collection.NewNFTID(s.nftClassID, collection.DefaultDepthLimit+1),
subject: collection.NewNFTID(s.nftClassID, s.depthLimit+1),
target: collection.NewNFTID(s.nftClassID, s.numNFTs*3+1),
err: collection.ErrTokenNotExist,
},
"result exceeds the limit": {
contractID: s.contractID,
subject: collection.NewNFTID(s.nftClassID, collection.DefaultDepthLimit+2),
target: collection.NewNFTID(s.nftClassID, collection.DefaultDepthLimit),
subject: collection.NewNFTID(s.nftClassID, s.depthLimit+2),
target: collection.NewNFTID(s.nftClassID, s.depthLimit),
err: collection.ErrCompositionTooDeep,
},
"not owner of target": {
contractID: s.contractID,
subject: collection.NewNFTID(s.nftClassID, collection.DefaultDepthLimit+1),
subject: collection.NewNFTID(s.nftClassID, s.depthLimit+1),
target: collection.NewNFTID(s.nftClassID, s.numNFTs+1),
err: collection.ErrTokenNotOwnedBy,
},
Expand Down
2 changes: 1 addition & 1 deletion x/collection/keeper/param.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func (k Keeper) GetParams(ctx sdk.Context) collection.Params {
return params
}

func (k Keeper) setParams(ctx sdk.Context, params collection.Params) {
func (k Keeper) SetParams(ctx sdk.Context, params collection.Params) {
store := ctx.KVStore(k.storeKey)
key := paramsKey

Expand Down