diff --git a/CHANGELOG.md b/CHANGELOG.md index e75380554f..92efb7b45c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/x/collection/client/testutil/suite.go b/x/collection/client/testutil/suite.go index 0eb814b219..ce646179f8 100644 --- a/x/collection/client/testutil/suite.go +++ b/x/collection/client/testutil/suite.go @@ -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") diff --git a/x/collection/genesis.go b/x/collection/genesis.go index 5b37dbfe66..a54d10f4b0 100644 --- a/x/collection/genesis.go +++ b/x/collection/genesis.go @@ -8,8 +8,8 @@ import ( ) const ( - DefaultDepthLimit = 3 - DefaultWidthLimit = 8 + DefaultDepthLimit = 1 + DefaultWidthLimit = 4 ) // ValidateGenesis check the given genesis state has no integrity issues diff --git a/x/collection/keeper/genesis.go b/x/collection/keeper/genesis.go index a48ef543f4..11069610f0 100644 --- a/x/collection/keeper/genesis.go +++ b/x/collection/keeper/genesis.go @@ -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) diff --git a/x/collection/keeper/keeper_test.go b/x/collection/keeper/keeper_test.go index 07cad00bbd..8fd829d868 100644 --- a/x/collection/keeper/keeper_test.go +++ b/x/collection/keeper/keeper_test.go @@ -33,6 +33,8 @@ type KeeperTestSuite struct { balance sdk.Int + depthLimit int + numNFTs int numRoots int } @@ -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, @@ -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 diff --git a/x/collection/keeper/msg_server_test.go b/x/collection/keeper/msg_server_test.go index 28a742026c..9d190ce0c1 100644 --- a/x/collection/keeper/msg_server_test.go +++ b/x/collection/keeper/msg_server_test.go @@ -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": { @@ -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": { @@ -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, }, diff --git a/x/collection/keeper/nft_test.go b/x/collection/keeper/nft_test.go index a3771304ff..2c71098a79 100644 --- a/x/collection/keeper/nft_test.go +++ b/x/collection/keeper/nft_test.go @@ -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, @@ -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, }, diff --git a/x/collection/keeper/param.go b/x/collection/keeper/param.go index fb81060df6..080420f906 100644 --- a/x/collection/keeper/param.go +++ b/x/collection/keeper/param.go @@ -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