Skip to content

Commit

Permalink
Update blockchain id regexp and add tests (#194)
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanfrey authored and alpe committed Nov 19, 2018
1 parent 2b224c4 commit 63aa1b2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
24 changes: 20 additions & 4 deletions x/nft/blockchain/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,17 @@ func TestHandleIssueTokenMsg(t *testing.T) {
{ // happy path
owner: alice.Address(),
id: []byte("other_network"),
details: blockchain.TokenDetails{Chain: blockchain.Chain{MainTickerID: []byte("IOV")}, Iov: blockchain.IOV{Codec: "test"}},
details: blockchain.TokenDetails{Chain: blockchain.Chain{MainTickerID: []byte("IOV")}, Iov: blockchain.IOV{Codec: "bns"}},
},
{ // happy path for tendermint chain (validate autogen chainId, codec valid)
owner: alice.Address(),
id: []byte("test-chain-CnckvA"),
details: blockchain.TokenDetails{Chain: blockchain.Chain{MainTickerID: []byte("IOV")}, Iov: blockchain.IOV{Codec: "cosmos"}},
},
{ // happy path for lisk chain (validate nethash, codec valid)
owner: alice.Address(),
id: []byte("9a9813156bf1d2355da31a171e37f97dfa7568187c3fd7f9c728de8f180c19c7"),
details: blockchain.TokenDetails{Chain: blockchain.Chain{MainTickerID: []byte("IOV")}, Iov: blockchain.IOV{Codec: "lisk"}},
},
{ // valid approvals
owner: alice.Address(),
Expand All @@ -61,9 +71,15 @@ func TestHandleIssueTokenMsg(t *testing.T) {
}},
expDeliverError: true,
},
{ // unegistered ticker
owner: alice.Address(),
id: []byte("other_network3"),
details: blockchain.TokenDetails{Chain: blockchain.Chain{MainTickerID: []byte("LSK")}, Iov: blockchain.IOV{Codec: "test", CodecConfig: `{"da": 1}`}},
expDeliverError: true,
},
{ // invalid codec
owner: alice.Address(),
id: []byte("other_network3"),
id: []byte("other_network4"),
details: blockchain.TokenDetails{Chain: blockchain.Chain{MainTickerID: []byte("IOV")}, Iov: blockchain.IOV{Codec: "1"}},
approvals: []nft.ActionApprovals{{
Action: nft.Action_ActionUpdateDetails.String(),
Expand All @@ -73,7 +89,7 @@ func TestHandleIssueTokenMsg(t *testing.T) {
},
{ // invalid codec json
owner: alice.Address(),
id: []byte("other_network4"),
id: []byte("other_network5"),
details: blockchain.TokenDetails{Chain: blockchain.Chain{MainTickerID: []byte("IOV")}, Iov: blockchain.IOV{Codec: "bbb", CodecConfig: "{ssdas"}},
approvals: []nft.ActionApprovals{{
Action: nft.Action_ActionUpdateDetails.String(),
Expand All @@ -83,7 +99,7 @@ func TestHandleIssueTokenMsg(t *testing.T) {
},
{ // invalid approvals
owner: alice.Address(),
id: []byte("other_network5"),
id: []byte("other_network6"),
details: blockchain.TokenDetails{Chain: blockchain.Chain{MainTickerID: []byte("IOV")}, Iov: blockchain.IOV{Codec: "test"}},
expCheckError: true,
expDeliverError: true,
Expand Down
2 changes: 1 addition & 1 deletion x/nft/blockchain/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const (

var (
//todo: revisit pattern
IsValidID = regexp.MustCompile(`^[a-zA-Z0-9_.]{4,256}$`).MatchString
IsValidID = regexp.MustCompile(`^[a-zA-Z0-9_.-]{4,128}$`).MatchString
)

// Path returns the routing path for this message
Expand Down

0 comments on commit 63aa1b2

Please sign in to comment.