Skip to content

Commit

Permalink
fix: change the default params of x/collection (#894)
Browse files Browse the repository at this point in the history
* Change the default params

* Update CHANGELOG.md

* Lint
  • Loading branch information
0Tech authored Feb 13, 2023
1 parent 5a8d776 commit cb6f186
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 16 deletions.
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

0 comments on commit cb6f186

Please sign in to comment.