Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(x/ecocredit): add basket years in the past #874

Merged
merged 26 commits into from
Mar 16, 2022
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
901ae89
feat(x/ecocredit): add basket fixed start date
ryanchristo Mar 10, 2022
8637df3
feat(x/ecocredit): add basket fixed start date
ryanchristo Mar 10, 2022
d8b57a6
feat(x/ecocredit): add basket fixed start date
ryanchristo Mar 10, 2022
32025e6
feat(x/ecocredit): add basket fixed start date
ryanchristo Mar 10, 2022
ff0e44d
feat(x/ecocredit): add basket fixed start date
ryanchristo Mar 10, 2022
0e50842
feat(x/ecocredit): add basket fixed start date
ryanchristo Mar 10, 2022
e679f23
feat(x/ecocredit): add basket fixed start date
ryanchristo Mar 10, 2022
f616366
feat(x/ecocredit): add basket fixed start date
ryanchristo Mar 11, 2022
4d87960
address review comments
ryanchristo Mar 11, 2022
0119fb1
Merge branch 'master' into ryan/820-basket-start-date
ryanchristo Mar 11, 2022
a58c3dc
fix generated proto
ryanchristo Mar 11, 2022
8edb3f4
fix generated proto
ryanchristo Mar 11, 2022
a5b31c3
add revision and since
ryanchristo Mar 11, 2022
1dd8af0
add revision and since
ryanchristo Mar 11, 2022
cbb80c2
Merge branch 'master' into ryan/820-basket-start-date
ryanchristo Mar 11, 2022
98e5396
fix proto gen
ryanchristo Mar 11, 2022
a54542a
Merge branch 'master' into ryan/820-basket-start-date
ryanchristo Mar 11, 2022
c9708ca
Merge branch 'master' into ryan/820-basket-start-date
ryanchristo Mar 11, 2022
1571cd2
merge updates
ryanchristo Mar 12, 2022
9a6eaff
Merge branch 'master' into ryan/820-basket-start-date
ryanchristo Mar 12, 2022
3a5e6c1
Merge branch 'master' into ryan/820-basket-start-date
ryanchristo Mar 14, 2022
9f5c29f
Merge branch 'master' into ryan/820-basket-start-date
ryanchristo Mar 15, 2022
de90601
Merge branch 'master' into ryan/820-basket-start-date
ryanchristo Mar 15, 2022
44b2657
fix tests
ryanchristo Mar 15, 2022
44b246b
Merge branch 'master' into ryan/820-basket-start-date
ryanchristo Mar 15, 2022
1e394b1
rename package
ryanchristo Mar 16, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 92 additions & 22 deletions api/regen/ecocredit/basket/v1/types.pulsar.go

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

19 changes: 16 additions & 3 deletions proto/regen/ecocredit/basket/v1/types.proto
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
syntax = "proto3";

// Revision 1
package regen.ecocredit.basket.v1;

option go_package = "github.com/regen-network/regen-ledger/x/ecocredit/basket";
@@ -27,13 +28,25 @@ message BasketCredit {
message DateCriteria {
// min_start_date (optional) is the earliest start date for batches of credits allowed
// into the basket.
// At most only one of `start_date_window` and `min_start_date` can be set.
// At most only one of `start_date_window`, `min_start_date`, and `years_in_the_past`
// can be set for a basket.
google.protobuf.Timestamp min_start_date = 1;

// start_date_window (optional) is a duration of time measured into the past which sets
// a cutoff for batch start dates when adding new credits to the basket.
// Based on the current block timestamp, credits whose start date is before
// `block_timestamp - batch_date_window` will not be allowed into the basket.
// At most only one of `start_date_window` and `min_start_date` can be set.
// `block_timestamp - start_date_window` will not be allowed into the basket.
// At most only one of `start_date_window`, `min_start_date`, and `years_in_the_past`
// can be set for a basket.
google.protobuf.Duration start_date_window = 2;

// years_in_the_past (optional) is the number of years into the past which sets a
// cutoff for the batch start dates when adding new credits to the basket.
// Based on the current block timestamp, credits whose start date year is less than
// `block_timestamp_year - years_in_the_past` will not be allowed into the basket.
// At most only one of `start_date_window`, `min_start_date`, and `years_in_the_past`
// can be set for a basket.
//
// Since Revision 1
uint32 years_in_the_past = 3;
}
7 changes: 3 additions & 4 deletions x/ecocredit/basket/msg_create.go
Original file line number Diff line number Diff line change
@@ -90,8 +90,9 @@ func validateDateCriteria(d *DateCriteria) error {
}
minStartDate := d.GetMinStartDate()
startDateWindow := d.GetStartDateWindow()
if minStartDate != nil && startDateWindow != nil {
return errBadReq.Wrap("only one of date_criteria.min_start_date or date_criteria.start_date_window must be set")
yearsInThePast := d.GetYearsInThePast()
if (minStartDate != nil && startDateWindow != nil) || (startDateWindow != nil && yearsInThePast != 0) || (minStartDate != nil && yearsInThePast != 0) {
return errBadReq.Wrap("only one of date_criteria.min_start_date, date_criteria.start_date_window, or date_criteria.years_in_the_past must be set")
}
if minStartDate != nil {
if minStartDate.Seconds < -2208992400 { // batch older than 1900-01-01 is an obvious error
@@ -101,8 +102,6 @@ func validateDateCriteria(d *DateCriteria) error {
if startDateWindow.Seconds < 24*3600 {
return errBadReq.Wrap("date_criteria.start_date_window must be at least 1 day")
}
} else {
return errBadReq.Wrapf("unsupported date_criteria value %v", d)
}
return nil
}
75 changes: 51 additions & 24 deletions x/ecocredit/basket/msg_create_test.go
Original file line number Diff line number Diff line change
@@ -47,7 +47,7 @@ func TestMsgCreateValidateBasic(t *testing.T) {
{"name-short",
MsgCreate{Curator: a, Name: randstr.String(nameMinLen - 1)},
"name must start with an alphabetic character"},
{"name-no-alpahnum",
{"name-no-alphanum",
MsgCreate{Curator: a, Name: randstr.String(nameMinLen) + "*"},
"name must start with an alphabetic character"},
{"name-no-alpah-prefix",
@@ -59,15 +59,12 @@ func TestMsgCreateValidateBasic(t *testing.T) {
{"exponent-2",
MsgCreate{Curator: a, Name: name, Exponent: 17},
"exponent must be one of [0 1 2 3 6 9 12 15 18 21 24]"},
{"credity_type-1",
{"credit_type-1",
MsgCreate{Curator: a, Name: name, Exponent: 3},
"credit type abbreviation must be 1-3"},
{"credity_type-2",
{"credit_type-2",
MsgCreate{Curator: a, Name: name, Exponent: 3, CreditTypeAbbrev: randstr.String(creditTypeAbbrMaxLen + 1)},
"credit type abbreviation must be 1-3"},
{"date_criteria-1",
MsgCreate{Curator: a, Name: name, Exponent: 3, CreditTypeAbbrev: creditAbbr, DateCriteria: &DateCriteria{}},
"unsupported date_criteria value"},
{"description",
MsgCreate{Curator: a, Name: name, Exponent: 3, CreditTypeAbbrev: creditAbbr, DateCriteria: start, Description: randstr.String(descrMaxLen + 1)},
"description can't be longer"},
@@ -102,27 +99,57 @@ func TestMsgCreateValidateDateCriteria(t *testing.T) {
d DateCriteria
err string
}{
{"nil-min_start_date",
DateCriteria{MinStartDate: nil},
"unsupported date_criteria value"},
{"bad-min_start_date",
DateCriteria{MinStartDate: &gogotypes.Timestamp{Seconds: time.Date(1400, 1, 1, 0, 0, 0, 0, time.UTC).Unix()}},
"date_criteria.min_start_date must be after"},
{"nil-start_date_window",
DateCriteria{StartDateWindow: nil},
"unsupported date_criteria value"},
{"bad-start_date_window",
{
"bad-min_start_date",
DateCriteria{MinStartDate: &gogotypes.Timestamp{
Seconds: time.Date(1400, 1, 1, 0, 0, 0, 0, time.UTC).Unix()},
},
"date_criteria.min_start_date must be after",
},
{
"bad-start_date_window",
DateCriteria{StartDateWindow: &gogotypes.Duration{Seconds: 3600}},
"date_criteria.start_date_window must be at least 1 day"},
{"both-min_start_date-start_date_window-set",
DateCriteria{MinStartDate: gogotypes.TimestampNow(), StartDateWindow: &gogotypes.Duration{Seconds: 3600 * 24 * 2}},
"only one of date_criteria.min_start_date or date_criteria.start_date_window must be set"},
{"good-min_start_date",
"date_criteria.start_date_window must be at least 1 day",
},
{
"both-min_start_date-start_date_window-set",
DateCriteria{
MinStartDate: gogotypes.TimestampNow(),
StartDateWindow: &gogotypes.Duration{Seconds: 3600 * 24 * 2},
},
"only one of date_criteria.min_start_date, date_criteria.start_date_window, or date_criteria.years_in_the_past must be set",
},
{
"both-min_start_date-years_in_the_past-set",
DateCriteria{
MinStartDate: gogotypes.TimestampNow(),
YearsInThePast: 10,
},
"only one of date_criteria.min_start_date, date_criteria.start_date_window, or date_criteria.years_in_the_past must be set",
},
{
"both-start_date_window-years_in_the_past-set",
DateCriteria{
StartDateWindow: &gogotypes.Duration{Seconds: 3600 * 24 * 2},
YearsInThePast: 10,
},
"only one of date_criteria.min_start_date, date_criteria.start_date_window, or date_criteria.years_in_the_past must be set",
},
{
"good-min_start_date",
DateCriteria{MinStartDate: gogotypes.TimestampNow()},
""},
{"good-start_date_window",
"",
},
{
"good-start_date_window",
DateCriteria{StartDateWindow: &gogotypes.Duration{Seconds: 3600 * 24 * 2}},
""},
"",
},
{
"good-years_in_the_past",
DateCriteria{YearsInThePast: 10},
"",
},
}
for _, tc := range tcs {
t.Run(tc.id, func(t *testing.T) {
Rate limit · GitHub

Access has been restricted

You have triggered a rate limit.

Please wait a few minutes before you try again;
in some cases this may take up to an hour.