Skip to content

Commit

Permalink
feat!: basket name update (#776)
Browse files Browse the repository at this point in the history
* backport new proto

* remove prefix and add name to the basket state

* udpate tests

* basket denom tests

* adding more tests and update integration tests
  • Loading branch information
robert-zaremba authored Feb 16, 2022
1 parent 398824e commit 971a875
Show file tree
Hide file tree
Showing 19 changed files with 298 additions and 313 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ require (
github.com/prometheus/procfs v0.6.0 // indirect
github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0 // indirect
github.com/regen-network/cosmos-proto v0.3.1 // indirect
github.com/regen-network/regen-ledger/api v0.4.0 // indirect
github.com/regen-network/regen-ledger/api v0.5.0 // indirect
github.com/regen-network/regen-ledger/orm v1.0.0-beta1 // indirect
github.com/rs/cors v1.7.0 // indirect
github.com/sasha-s/go-deadlock v0.2.1-0.20190427202633-1595213edefa // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -916,8 +916,8 @@ github.com/regen-network/cosmos-sdk v0.44.2-regen-1/go.mod h1:fwQJdw+aECatpTvQTo
github.com/regen-network/protobuf v1.3.2-alpha.regen.4 h1:c9jEnU+xm6vqyrQe3M94UFWqiXxRIKKnqBOh2EACmBE=
github.com/regen-network/protobuf v1.3.2-alpha.regen.4/go.mod h1:/J8/bR1T/NXyIdQDLUaq15LjNE83nRzkyrLAMcPewig=
github.com/regen-network/regen-ledger/api v0.2.0/go.mod h1:kWly2pK0u3fDfyoYYilpEoTEg61pCjV/f5XSY0KzJQY=
github.com/regen-network/regen-ledger/api v0.4.0 h1:klcMljLCHU3MpkRyjrEXL6KKsDGeqFBt2aFUwFdpEH8=
github.com/regen-network/regen-ledger/api v0.4.0/go.mod h1:kWly2pK0u3fDfyoYYilpEoTEg61pCjV/f5XSY0KzJQY=
github.com/regen-network/regen-ledger/api v0.5.0 h1:Kp+16TzHxSeF0pJ1HPcUzhalCKJCkEnfiKj/NoJX6Lw=
github.com/regen-network/regen-ledger/api v0.5.0/go.mod h1:kWly2pK0u3fDfyoYYilpEoTEg61pCjV/f5XSY0KzJQY=
github.com/rjeczalik/notify v0.9.1/go.mod h1:rKwnCoCGeuQnwBtTSPL9Dad03Vh2n40ePRrjvIXnJho=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
Expand Down
49 changes: 29 additions & 20 deletions proto/regen/ecocredit/basket/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,16 @@ message MsgCreate {

// name will be used to together with prefix to create a bank denom for this
// basket token. It can be between 3-8 alphanumeric characters, with the
// first character being alphabetic. The bank denom will be
// `eco/<prefix><name>` and its display name will be `eco/<name>`.
// first character being alphabetic.
//
// The bank denom will be formed from name, credit type and exponent and be
// of the form `eco.<prefix><credit_type_abbrev>.<name>` where prefix
// is derived from exponent.
string name = 2;

// prefix is a single alphabetic character that denotes
// the denom prefix and indicates in some way what relationship is between
// the denom and display denom. Standard conventions are that m indicates
// milli (10^3), u indicates micro (10^6), n indicates nano (10^9).
// Typical usage of prefix should correspond with the `exponent` field,
// which is used to convert decimal ecocredit amounts to integral
// basket tokens.
string prefix = 3;

// description is a human-readable description of the basket denom that should
// be at most 256 characters.
string description = 4;

string description = 3;

// exponent is the exponent that will be used for converting credits to basket
// tokens and for bank denom metadata. It also limits the precision of
Expand All @@ -55,32 +48,48 @@ message MsgCreate {
// this should be displayed as one unit in user interfaces. It also means
// that the maximum precision of credit amounts is 6 decimal places so that
// the need to round is eliminated. The exponent must be >= the precision of
// the credit type at the time the basket is created.
uint32 exponent = 5;
// the credit type at the time the basket is created and be of one of the
// following values 0, 1, 2, 3, 6, 9, 12, 15, 18, 21, or 24 which correspond
// to the exponents which have an official SI prefix.
//
// The exponent will be used to form the prefix part of the the bank denom
// and will be mapped as follows:
// 0 - no prefix
// 1 - d (deci)
// 2 - c (centi)
// 3 - m (milli)
// 6 - u (micro)
// 9 - n (nano)
// 12 - p (pico)
// 15 - f (femto)
// 18 - a (atto)
// 21 - z (zepto)
// 24 - y (yocto)
uint32 exponent = 4;

// disable_auto_retire allows auto-retirement to be disabled.
// The credits will be auto-retired if disable_auto_retire is
// false unless the credits were previously put into the basket by the
// address picking them from the basket, in which case they will remain
// tradable.
bool disable_auto_retire = 6;
bool disable_auto_retire = 5;

// credit_type_abbrev is the abbreviation of the credit type this basket is
// able to hold.
string credit_type_abbrev = 7;
string credit_type_abbrev = 6;

// allowed_classes are the credit classes allowed to be put in the basket
repeated string allowed_classes = 8;
repeated string allowed_classes = 7;

// date_criteria is the date criteria for batches admitted to the basket.
DateCriteria date_criteria = 9;
DateCriteria date_criteria = 8;

// fee is the fee that the curator will pay to create the basket. It must be
// >= the required Params.basket_creation_fee. We include the fee explicitly
// here so that the curator explicitly acknowledges paying this fee and
// is not surprised to learn that the paid a big fee and didn't know
// beforehand.
repeated cosmos.base.v1beta1.Coin fee = 10 [
repeated cosmos.base.v1beta1.Coin fee = 9 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];
Expand Down
15 changes: 3 additions & 12 deletions x/ecocredit/basket/events.pb.go

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

8 changes: 4 additions & 4 deletions x/ecocredit/basket/msg_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,18 @@ func validateDateCriteria(d *DateCriteria) error {
return nil
}

// MsgCreateDenom formats denom and display denom:
// BasketDenom formats denom and display denom:
// * denom: eco.<m.Exponent><m.CreditTypeAbbrev>.<m.Name>
// * display denom: eco.<m.Exponent><m.CreditTypeAbbrev>.<m.Name>
// Returns error if MsgCrete.Exponent is not supported
func MsgCreateDenom(m *MsgCreate) (string, string, error) {
func BasketDenom(name, creditTypeAbbrev string, exponent uint32) (string, string, error) {
const basketDenomPrefix = "eco."
denomPrefix, err := ecocredit.ExponentToPrefix(m.Exponent)
denomPrefix, err := ecocredit.ExponentToPrefix(exponent)
if err != nil {
return "", "", err
}

denomTail := m.CreditTypeAbbrev + "." + m.Name
denomTail := creditTypeAbbrev + "." + name
displayDenomName := basketDenomPrefix + denomTail //
denom := basketDenomPrefix + denomPrefix + denomTail // eco.<credit-class>.<name>
return denom, displayDenomName, nil
Expand Down
41 changes: 37 additions & 4 deletions x/ecocredit/basket/msg_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@ func TestMsgCreateValidateBasic(t *testing.T) {
MsgCreate{Curator: a, Name: name, Exponent: 3, CreditTypeAbbrev: creditAbbr, DateCriteria: start, AllowedClasses: []string{"class1", ""}},
"allowed_classes[1] must be defined"},
{"fee-1",
MsgCreate{Curator: a, Prefix: "o", Name: name, Exponent: 3, CreditTypeAbbrev: creditAbbr, DateCriteria: start, AllowedClasses: classes, Fee: sdk.Coins{sdk.Coin{Denom: "1a"}}},
MsgCreate{Curator: a, Name: name, Exponent: 3, CreditTypeAbbrev: creditAbbr, DateCriteria: start, AllowedClasses: classes, Fee: sdk.Coins{sdk.Coin{Denom: "1a"}}},
"invalid denom"},
{"fee-2", MsgCreate{Curator: a, Prefix: "o", Name: name, Exponent: 3, CreditTypeAbbrev: creditAbbr, DateCriteria: start, AllowedClasses: classes, Fee: sdk.Coins{sdk.Coin{"aa", sdk.NewInt(-1)}}},
{"fee-2", MsgCreate{Curator: a, Name: name, Exponent: 3, CreditTypeAbbrev: creditAbbr, DateCriteria: start, AllowedClasses: classes, Fee: sdk.Coins{sdk.Coin{"aa", sdk.NewInt(-1)}}},
"invalid denom"},

{"good-1-fees-not-required",
MsgCreate{Curator: a, Prefix: "o", Name: name, Exponent: 0, CreditTypeAbbrev: creditAbbr, DateCriteria: start, AllowedClasses: classes, Description: descr}, ""},
MsgCreate{Curator: a, Name: name, Exponent: 0, CreditTypeAbbrev: creditAbbr, DateCriteria: start, AllowedClasses: classes, Description: descr}, ""},
{"good-date-criteria-not-required",
MsgCreate{Curator: a, Prefix: "o", Name: name, Exponent: 18, CreditTypeAbbrev: creditAbbr, DateCriteria: nil, AllowedClasses: classes, Fee: sdk.Coins{sdk.NewInt64Coin("regen", 1)}}, ""},
MsgCreate{Curator: a, Name: name, Exponent: 18, CreditTypeAbbrev: creditAbbr, DateCriteria: nil, AllowedClasses: classes, Fee: sdk.Coins{sdk.NewInt64Coin("regen", 1)}}, ""},
}

for _, tc := range tcs {
Expand Down Expand Up @@ -146,3 +146,36 @@ func TestMsgCreateSignBytes(t *testing.T) {
bz := m.GetSignBytes()
require.NotEmpty(t, bz)
}

func TestBasketDenom(t *testing.T) {
tcs := []struct {
tname string
abbrev string
exponent uint32
denom string
displayDenom string
err bool
}{
{"wrong exponent",
"X", 5, "", "", true},
{"exponent-0",
"X", 0, "eco.X.foo", "eco.X.foo", false},
{"exponent-1`",
"X", 1, "eco.dX.foo", "eco.X.foo", false},
{"exponent-2",
"X", 2, "eco.cX.foo", "eco.X.foo", false},
{"exponent-6",
"X", 6, "eco.uX.foo", "eco.X.foo", false},
}
require := require.New(t)
for _, tc := range tcs {
d, displayD, err := BasketDenom("foo", tc.abbrev, tc.exponent)
if tc.err {
require.Error(err, tc.tname)
} else {
require.NoError(err, tc.tname)
require.Equal(tc.denom, d, tc.tname)
require.Equal(tc.displayDenom, displayD, tc.tname)
}
}
}
40 changes: 8 additions & 32 deletions x/ecocredit/basket/query.pb.go

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

Loading

0 comments on commit 971a875

Please sign in to comment.