Skip to content

Commit

Permalink
fix: reject NFT coins on FT APIs (#1294)
Browse files Browse the repository at this point in the history
* Reject using NFTs on FT APIs

* Update tests

* Update CHANGELOG.md

* Fix expected errors
  • Loading branch information
0Tech authored Mar 23, 2024
1 parent e86b980 commit ca39b18
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (x/foundation) [\#1277](https://github.com/Finschia/finschia-sdk/pull/1277) add init logic of foundation module accounts to InitGenesis in order to eliminate potential panic
* (x/collection, x/token) [\#1288](https://github.com/Finschia/finschia-sdk/pull/1288) use accAddress to compare in validatebasic function in collection & token modules
* (x/collection) [\#1268](https://github.com/Finschia/finschia-sdk/pull/1268) export x/collection params into genesis
* (x/collection) [\#1294](https://github.com/Finschia/finschia-sdk/pull/1294) reject NFT coins on FT APIs

### Removed

Expand Down
14 changes: 7 additions & 7 deletions x/collection/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ func validateAmount(amount sdk.Int) error {
}

// deprecated
func validateCoins(amount []Coin) error {
return validateCoinsWithIDValidator(amount, ValidateTokenID)
func validateFTCoins(amount []Coin) error {
return validateCoinsWithIDValidator(amount, ValidateFTID)
}

// deprecated
Expand Down Expand Up @@ -247,7 +247,7 @@ func (m MsgSendFT) ValidateBasic() error {
return sdkerrors.ErrInvalidAddress.Wrapf("invalid to address: %s", m.To)
}

if err := validateCoins(m.Amount); err != nil {
if err := validateFTCoins(m.Amount); err != nil {
return err
}

Expand Down Expand Up @@ -293,7 +293,7 @@ func (m MsgOperatorSendFT) ValidateBasic() error {
return sdkerrors.ErrInvalidAddress.Wrapf("invalid to address: %s", m.To)
}

if err := validateCoins(m.Amount); err != nil {
if err := validateFTCoins(m.Amount); err != nil {
return err
}

Expand Down Expand Up @@ -675,7 +675,7 @@ func (m MsgMintFT) ValidateBasic() error {
return sdkerrors.ErrInvalidAddress.Wrapf("invalid to address: %s", m.To)
}

if err := validateCoins(m.Amount); err != nil {
if err := validateFTCoins(m.Amount); err != nil {
return err
}

Expand Down Expand Up @@ -775,7 +775,7 @@ func (m MsgBurnFT) ValidateBasic() error {
return sdkerrors.ErrInvalidAddress.Wrapf("invalid from address: %s", m.From)
}

if err := validateCoins(m.Amount); err != nil {
if err := validateFTCoins(m.Amount); err != nil {
return err
}

Expand Down Expand Up @@ -818,7 +818,7 @@ func (m MsgOperatorBurnFT) ValidateBasic() error {
return sdkerrors.ErrInvalidAddress.Wrapf("invalid from address: %s", m.From)
}

if err := validateCoins(m.Amount); err != nil {
if err := validateFTCoins(m.Amount); err != nil {
return err
}

Expand Down
45 changes: 45 additions & 0 deletions x/collection/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ func TestMsgSendFT(t *testing.T) {
}},
err: collection.ErrInvalidTokenID,
},
"nft id": {
contractID: "deadbeef",
from: addrs[0],
to: addrs[1],
amount: []collection.Coin{
collection.NewNFTCoin("deadbeef", 42),
},
err: collection.ErrInvalidTokenID,
},
}

for name, tc := range testCases {
Expand Down Expand Up @@ -185,6 +194,16 @@ func TestMsgOperatorSendFT(t *testing.T) {
}},
err: collection.ErrInvalidTokenID,
},
"nft id": {
contractID: "deadbeef",
operator: addrs[0],
from: addrs[1],
to: addrs[2],
amount: []collection.Coin{
collection.NewNFTCoin("deadbeef", 42),
},
err: collection.ErrInvalidTokenID,
},
}

for name, tc := range testCases {
Expand Down Expand Up @@ -848,6 +867,15 @@ func TestMsgMintFT(t *testing.T) {
}},
err: collection.ErrInvalidTokenID,
},
"nft id": {
contractID: contractID,
operator: addrs[0],
to: addrs[1],
amount: []collection.Coin{
collection.NewNFTCoin("deadbeef", 42),
},
err: collection.ErrInvalidTokenID,
},
}

for name, tc := range testCases {
Expand Down Expand Up @@ -1030,6 +1058,14 @@ func TestMsgBurnFT(t *testing.T) {
}},
err: collection.ErrInvalidAmount,
},
"nft id": {
contractID: "deadbeef",
from: addrs[0],
amount: []collection.Coin{
collection.NewNFTCoin("deadbeef", 42),
},
err: collection.ErrInvalidTokenID,
},
}

for name, tc := range testCases {
Expand Down Expand Up @@ -1110,6 +1146,15 @@ func TestMsgOperatorBurnFT(t *testing.T) {
}},
err: collection.ErrInvalidAmount,
},
"nft id": {
contractID: "deadbeef",
grantee: addrs[0],
from: addrs[1],
amount: []collection.Coin{
collection.NewNFTCoin("deadbeef", 42),
},
err: collection.ErrInvalidTokenID,
},
}

for name, tc := range testCases {
Expand Down

0 comments on commit ca39b18

Please sign in to comment.