Skip to content

Commit

Permalink
fix: asset format (#426)
Browse files Browse the repository at this point in the history
fix: asset format (not allowing single char)
  • Loading branch information
gfyrag authored and flemzord committed Jan 31, 2023
1 parent 5a72e81 commit ef8f67b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
34 changes: 34 additions & 0 deletions pkg/api/controllers/transaction_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,40 @@ func TestPostTransactions(t *testing.T) {
}},
},
},
{
name: "short asset",
payload: []controllers.PostTransaction{
{
Postings: core.Postings{
{
Source: "world",
Destination: "bank",
Amount: core.NewMonetaryInt(1000),
Asset: "F/9",
},
},
Timestamp: timestamp3,
},
},
expectedStatusCode: http.StatusOK,
expectedRes: sharedapi.BaseResponse[[]core.ExpandedTransaction]{
Data: &[]core.ExpandedTransaction{{
Transaction: core.Transaction{
TransactionData: core.TransactionData{
Postings: core.Postings{
{
Source: "world",
Destination: "bank",
Amount: core.NewMonetaryInt(1000),
Asset: "F/9",
},
},
Timestamp: timestamp3,
},
},
}},
},
},
}

internal.RunTest(t, fx.Invoke(func(lc fx.Lifecycle, api *api.API) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/core/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"regexp"
)

var assetRegexp = regexp.MustCompile(`^[A-Z][A-Z0-9]{1,16}(\/\d{1,6})?$`)
var assetRegexp = regexp.MustCompile(`^[A-Z][A-Z0-9]{0,16}(\/\d{1,6})?$`)

func AssetIsValid(v string) bool {
return assetRegexp.Match([]byte(v))
Expand Down

0 comments on commit ef8f67b

Please sign in to comment.