Skip to content

Commit

Permalink
Update docs for postal code format and rename tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ruhatch committed Jun 30, 2021
1 parent 8a03ae6 commit 21e4ac3
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 40 deletions.
8 changes: 4 additions & 4 deletions docs/modules/ecocredit/protobuf.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ batches have been retired at once for easy indexing.
| retirer | [string](#string) | | retirer is the account which has done the "retiring". This will be the account receiving credits in the case that credits were retired upon issuance using Msg/CreateBatch or retired upon transfer using Msg/Send. |
| batch_denom | [string](#string) | | batch_denom is the unique ID of credit batch. |
| units | [string](#string) | | units is the decimal number of credits that have been retired. |
| location | [string](#string) | | location is the location of the beneficiary or buyer of the retired credits. It is a string of the form <country-code>[-<sub-national-code>[-<postal-code>]], with the first two fields conforming to ISO 3166-2. |
| location | [string](#string) | | location is the location of the beneficiary or buyer of the retired credits. It is a string of the form <country-code>[-<sub-national-code>[ <postal-code>]], with the first two fields conforming to ISO 3166-2, and postal-code being up to 64 alphanumeric characters. |



Expand Down Expand Up @@ -445,7 +445,7 @@ single recipient.
| recipient | [string](#string) | | recipient is the account of the recipient. |
| tradable_units | [string](#string) | | tradable_units are the units of credits in this issuance that can be traded by this recipient. Decimal values are acceptable. |
| retired_units | [string](#string) | | retired_units are the units of credits in this issuance that are effectively retired by the issuer on receipt. Decimal values are acceptable. |
| retirement_location | [string](#string) | | retirement_location is the location of the beneficiary or buyer of the retired credits. This must be provided if retired_units is positive. It is a string of the form <country-code>[-<sub-national-code>[-<postal-code>]], with the first two fields conforming to ISO 3166-2. |
| retirement_location | [string](#string) | | retirement_location is the location of the beneficiary or buyer of the retired credits. This must be provided if retired_units is positive. It is a string of the form <country-code>[-<sub-national-code>[ <postal-code>]], with the first two fields conforming to ISO 3166-2, and postal-code being up to 64 alphanumeric characters. |



Expand Down Expand Up @@ -509,7 +509,7 @@ MsgRetireRequest is the Msg/Retire request type.
| ----- | ---- | ----- | ----------- |
| holder | [string](#string) | | holder is the credit holder address. |
| credits | [MsgRetireRequest.RetireUnits](#regen.ecocredit.v1alpha1.MsgRetireRequest.RetireUnits) | repeated | credits are the credits being retired. |
| location | [string](#string) | | location is the location of the beneficiary or buyer of the retired credits. It is a string of the form <country-code>[-<sub-national-code>[-<postal-code>]], with the first two fields conforming to ISO 3166-2. |
| location | [string](#string) | | location is the location of the beneficiary or buyer of the retired credits. It is a string of the form <country-code>[-<sub-national-code>[ <postal-code>]], with the first two fields conforming to ISO 3166-2, and postal-code being up to 64 alphanumeric characters. |



Expand Down Expand Up @@ -570,7 +570,7 @@ SendUnits are the tradable and retired units of a credit batch to send.
| batch_denom | [string](#string) | | batch_denom is the unique ID of the credit batch. |
| tradable_units | [string](#string) | | tradable_units are the units of credits in this issuance that can be traded by this recipient. Decimal values are acceptable within the precision returned by Query/Precision. |
| retired_units | [string](#string) | | retired_units are the units of credits in this transfer that are effectively retired by the recipient on receipt. Decimal values are acceptable within the precision returned by Query/Precision. |
| retirement_location | [string](#string) | | retirement_location is the location of the beneficiary or buyer of the retired credits. This must be provided if retired_units is positive. It is a string of the form <country-code>[-<sub-national-code>[-<postal-code>]], with the first two fields conforming to ISO 3166-2. |
| retirement_location | [string](#string) | | retirement_location is the location of the beneficiary or buyer of the retired credits. This must be provided if retired_units is positive. It is a string of the form <country-code>[-<sub-national-code>[ <postal-code>]], with the first two fields conforming to ISO 3166-2, and postal-code being up to 64 alphanumeric characters. |



Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ require (
github.com/tendermint/tendermint v0.34.11
github.com/tendermint/tm-db v0.6.4
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e // indirect
google.golang.org/genproto v0.0.0-20210614182748-5b3b54cad159 // indirect
google.golang.org/genproto v0.0.0-20210629200056-84d6f6074151 // indirect
)

replace google.golang.org/grpc => google.golang.org/grpc v1.33.2
Expand Down
10 changes: 5 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,6 @@ github.com/otiai10/mint v1.3.0/go.mod h1:F5AjcsTsWUqX+Na9fpHb52P8pcRX2CI6A3ctIT9
github.com/otiai10/mint v1.3.2 h1:VYWnrP5fXmz1MXvjuUvcBrXSjGE6xjON+axB/UrpO3E=
github.com/otiai10/mint v1.3.2/go.mod h1:/yxELlJQ0ufhjUwhshSj+wFjZ78CnZ48/1wtmBH1OTc=
github.com/pact-foundation/pact-go v1.0.4/go.mod h1:uExwJY4kCzNPcHRj+hCR/HBbOOIwwtUjcrb0b5/5kLM=
github.com/pariz/gountries v0.0.0-20200430155801-1c6a393df9c7 h1:GneNkGCnFPoBkaOd03qsvXSV+ZRkZedaN0DNJCruuI0=
github.com/pariz/gountries v0.0.0-20200430155801-1c6a393df9c7/go.mod h1:U0ETmPPEsfd7CpUKNMYi68xIOL8Ww4jPZlaqNngcwqs=
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
github.com/pascaldekloe/goe v0.1.0 h1:cBOtyMzM9HTpWjXfbbunk26uA6nG3a8n06Wieeh0MwY=
Expand Down Expand Up @@ -1151,7 +1150,7 @@ golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4f
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down Expand Up @@ -1235,8 +1234,8 @@ google.golang.org/genproto v0.0.0-20210310155132-4ce2db91004e/go.mod h1:FWY/as6D
google.golang.org/genproto v0.0.0-20210319143718-93e7006c17a6/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
google.golang.org/genproto v0.0.0-20210402141018-6c239bbf2bb1/go.mod h1:9lPAdzaEmUacj36I+k7YKbEc5CXzPIeORRgDAUOu28A=
google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0=
google.golang.org/genproto v0.0.0-20210614182748-5b3b54cad159 h1:7TIh9IZzwv/Gxqf+uYm45KzZTG1BlkZzb3yOa9GqgVE=
google.golang.org/genproto v0.0.0-20210614182748-5b3b54cad159/go.mod h1:SzzZ/N+nwJDaO1kznhnlzqS8ocJICar6hYhVyhi++24=
google.golang.org/genproto v0.0.0-20210629200056-84d6f6074151 h1:H/uPzsolsGjhl3CVT6Wb7bK+mf+hmkEvUVu+FBKyNlc=
google.golang.org/genproto v0.0.0-20210629200056-84d6f6074151/go.mod h1:yiaVoXHpRzHGyxV3o4DktVWY4mSUErTKaeEOq6C3t3U=
google.golang.org/grpc v1.33.2 h1:EQyQC3sa8M+p6Ulc8yy9SWSS2GVwyRc83gAbG8lrl4o=
google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
Expand All @@ -1251,8 +1250,9 @@ google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGj
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
google.golang.org/protobuf v1.25.1-0.20200805231151-a709e31e5d12/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ=
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
5 changes: 3 additions & 2 deletions proto/regen/ecocredit/v1alpha1/events.proto
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ message EventRetire {

// location is the location of the beneficiary or buyer of the retired
// credits. It is a string of the form
// <country-code>[-<sub-national-code>[-<postal-code>]], with the first two fields
// conforming to ISO 3166-2.
// <country-code>[-<sub-national-code>[ <postal-code>]], with the first two
// fields conforming to ISO 3166-2, and postal-code being up to 64
// alphanumeric characters.
string location = 4;
}
15 changes: 9 additions & 6 deletions proto/regen/ecocredit/v1alpha1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,9 @@ message MsgCreateBatchRequest {
// retirement_location is the location of the beneficiary or buyer of the
// retired credits. This must be provided if retired_units is positive. It
// is a string of the form
// <country-code>[-<sub-national-code>[-<postal-code>]], with the first two
// fields conforming to ISO 3166-2.
// <country-code>[-<sub-national-code>[ <postal-code>]], with the first two
// fields conforming to ISO 3166-2, and postal-code being up to 64
// alphanumeric characters.
string retirement_location = 4
[ (gogoproto.moretags) = "yaml:\"retirement_location\"" ];
}
Expand Down Expand Up @@ -153,8 +154,9 @@ message MsgSendRequest {
// retirement_location is the location of the beneficiary or buyer of the
// retired credits. This must be provided if retired_units is positive. It
// is a string of the form
// <country-code>[-<sub-national-code>[-<postal-code>]], with the first two
// fields conforming to ISO 3166-2.
// <country-code>[-<sub-national-code>[ <postal-code>]], with the first two
// fields conforming to ISO 3166-2, and postal-code being up to 64
// alphanumeric characters.
string retirement_location = 4
[ (gogoproto.moretags) = "yaml:\"retirement_location\"" ];
}
Expand Down Expand Up @@ -186,8 +188,9 @@ message MsgRetireRequest {

// location is the location of the beneficiary or buyer of the retired
// credits. It is a string of the form
// <country-code>[-<sub-national-code>[-<postal-code>]], with the first two fields
// conforming to ISO 3166-2.
// <country-code>[-<sub-national-code>[ <postal-code>]], with the first two
// fields conforming to ISO 3166-2, and postal-code being up to 64
// alphanumeric characters.
string location = 3;
}

Expand Down
3 changes: 2 additions & 1 deletion x/ecocredit/client/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ Parameters:
retirement_location: A string representing the location of the buyer or
beneficiary of retired credits. It has the form
<country-code>[-<region-code>[ <postal-code>]], where
country-code and region-code are taken from ISO 3166.
country-code and region-code are taken from ISO 3166, and
postal-code being up to 64 alphanumeric characters.
eg: 'AA-BB 12345'`,
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
Expand Down
5 changes: 3 additions & 2 deletions x/ecocredit/events.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion x/ecocredit/location.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var reLocation = regexp.MustCompile(`^([A-Z]{2})(?:-([A-Z0-9]{1,3})(?: ([a-zA-Z0
func validateLocation(location string) error {
matches := reLocation.FindStringSubmatch(location)
if matches == nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "Invalid retirement location: %s.\nLocation should have format <country-code>[-<region-code>[-<postal-code>]].\n", location)
return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "Invalid retirement location: %s.\nLocation should have format <country-code>[-<region-code>[ <postal-code>]].\n", location)
}

return nil
Expand Down
29 changes: 17 additions & 12 deletions x/ecocredit/location_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,52 +13,57 @@ func TestValidateLocation(t *testing.T) {
expectErr bool
}{
{
name: "can validate valid country code",
name: "valid country code",
location: "AF",
expectErr: false,
},
{
name: "can validate valid country code 2",
name: "valid country code 2",
location: "BF",
expectErr: false,
},
{
name: "can't validate invalid country code",
name: "invalid country code",
location: "ZZZ",
expectErr: true,
},
{
name: "can't validate invalid country code 2",
name: "invalid country code 2",
location: "Z!adflksdfZ",
expectErr: true,
},
{
name: "can validate valid region code",
name: "valid region code",
location: "AF-BDS",
expectErr: false,
},
{
name: "can validate valid region code 2",
location: "BF-BAL",
name: "valid region code 2",
location: "BF-B12",
expectErr: false,
},
{
name: "can't validate invalid region code",
name: "invalid region code",
location: "BF-ZZZZ",
expectErr: true,
},
{
name: "can validate valid postal code",
name: "invalid region code 2",
location: "BF-AB!",
expectErr: true,
},
{
name: "valid postal code",
location: "BF-BAL 1",
expectErr: false,
},
{
name: "can validate valid postal code 2",
location: "BF-BAL 0123456789",
name: "valid postal code 2",
location: "BF-B12 0123456789",
expectErr: false,
},
{
name: "can't validate invalid postal code",
name: "invalid postal code",
location: "BF-BAL 0123456789012345678901234567890123456789012345678901234567890123456789",
expectErr: true,
},
Expand Down
15 changes: 9 additions & 6 deletions x/ecocredit/tx.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 21e4ac3

Please sign in to comment.