Skip to content

Commit

Permalink
fix: fix x/collection ModifyContract (#798)
Browse files Browse the repository at this point in the history
* Add field checks after x/token Modify

* Fix substitution logic in ModifyContract()

* Update CHANGELOG.md
  • Loading branch information
0Tech authored Nov 16, 2022
1 parent bb6d8fa commit 3330562
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (x/foundation) [\#772](https://github.com/line/lbm-sdk/pull/772) export x/foundation pool
* (baseapp) [\#781](https://github.com/line/lbm-sdk/pull/781) implement method `SetOption()` in baseapp
* (global) [\#782](https://github.com/line/lbm-sdk/pull/782) add unhandled return error handling
* (x/collection,x/token) [\#798](https://github.com/line/lbm-sdk/pull/798) Fix x/collection ModifyContract

### Breaking Changes
* (cli) [\#773](https://github.com/line/lbm-sdk/pull/773) guide users to use generate-only in messages for x/foundation authority
Expand Down
2 changes: 1 addition & 1 deletion x/collection/keeper/supply.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ func (k Keeper) ModifyContract(ctx sdk.Context, contractID string, operator sdk.
contract.Name = name
},
collection.AttributeKeyBaseImgURI.String(): func(uri string) {
contract.Name = uri
contract.BaseImgUri = uri
},
collection.AttributeKeyMeta.String(): func(meta string) {
contract.Meta = meta
Expand Down
40 changes: 31 additions & 9 deletions x/collection/keeper/supply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,18 @@ func (s *KeeperTestSuite) TestModifyContract() {
ctx, _ := s.ctx.CacheContext()

err := s.keeper.ModifyContract(ctx, contractID, s.vendor, changes)
if contractID == s.contractID {
s.Require().NoError(err)
} else {
if contractID != s.contractID {
s.Require().Error(err)
return
}
s.Require().NoError(err)

contract, err := s.keeper.GetContract(ctx, contractID)
s.Require().NoError(err)

s.Require().Equal(changes[0].Value, contract.Name)
s.Require().Equal(changes[1].Value, contract.BaseImgUri)
s.Require().Equal(changes[2].Value, contract.Meta)
})
}
}
Expand All @@ -229,11 +236,20 @@ func (s *KeeperTestSuite) TestModifyTokenClass() {
ctx, _ := s.ctx.CacheContext()

err := s.keeper.ModifyTokenClass(ctx, contractID, classID, s.vendor, changes)
if contractID == s.contractID && classID == s.nftClassID {
s.Require().NoError(err)
} else {
if contractID != s.contractID || classID != s.nftClassID {
s.Require().Error(err)
return
}
s.Require().NoError(err)

class, err := s.keeper.GetTokenClass(ctx, contractID, classID)
s.Require().NoError(err)

nftClass, ok := class.(*collection.NFTClass)
s.Require().True(ok)

s.Require().Equal(changes[0].Value, nftClass.Name)
s.Require().Equal(changes[1].Value, nftClass.Meta)
})
}
}
Expand Down Expand Up @@ -261,11 +277,17 @@ func (s *KeeperTestSuite) TestModifyNFT() {
ctx, _ := s.ctx.CacheContext()

err := s.keeper.ModifyNFT(ctx, contractID, tokenID, s.vendor, changes)
if contractID == s.contractID && tokenID == validTokenID {
s.Require().NoError(err)
} else {
if contractID != s.contractID || tokenID != validTokenID {
s.Require().Error(err)
return
}
s.Require().NoError(err)

nft, err := s.keeper.GetNFT(ctx, contractID, tokenID)
s.Require().NoError(err)

s.Require().Equal(changes[0].Value, nft.Name)
s.Require().Equal(changes[1].Value, nft.Meta)
})
}
}
Expand Down
13 changes: 10 additions & 3 deletions x/token/keeper/supply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,18 @@ func (s *KeeperTestSuite) TestModify() {
ctx, _ := s.ctx.CacheContext()

err := s.keeper.Modify(ctx, contractID, grantee, changes)
if contractID == s.contractID {
s.Require().NoError(err)
} else {
if contractID != s.contractID {
s.Require().Error(err)
return
}
s.Require().NoError(err)

class, err := s.keeper.GetClass(ctx, contractID)
s.Require().NoError(err)

s.Require().Equal(changes[0].Value, class.Name)
s.Require().Equal(changes[1].Value, class.ImageUri)
s.Require().Equal(changes[2].Value, class.Meta)
})
}
}
Expand Down

0 comments on commit 3330562

Please sign in to comment.