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

refactor: Rename credit class designer to admin (#496) #500

Merged
merged 10 commits into from
Sep 1, 2021
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.12
github.com/tendermint/tm-db v0.6.4
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect
google.golang.org/genproto v0.0.0-20210818220304-27ea9cc85d9f // indirect
google.golang.org/genproto v0.0.0-20210831024726-fe130286e0e2 // indirect
)

replace google.golang.org/grpc => google.golang.org/grpc v1.33.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1207,8 +1207,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-20210818220304-27ea9cc85d9f h1:enWPderunHptc5pzJkSYGx0olpF8goXzG0rY3kL0eSg=
google.golang.org/genproto v0.0.0-20210818220304-27ea9cc85d9f/go.mod h1:eFjDcFEctNawg4eG61bRv87N7iHBWyVhJu7u1kqDUXY=
google.golang.org/genproto v0.0.0-20210831024726-fe130286e0e2 h1:NHN4wOCScVzKhPenJ2dt+BTs3X/XkBVI/Rh4iDt55T8=
google.golang.org/genproto v0.0.0-20210831024726-fe130286e0e2/go.mod h1:eFjDcFEctNawg4eG61bRv87N7iHBWyVhJu7u1kqDUXY=
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 Down
4 changes: 2 additions & 2 deletions proto/regen/ecocredit/v1alpha1/events.proto
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ message EventCreateClass {
// class_id is the unique ID of credit class.
string class_id = 1 [ (gogoproto.moretags) = "yaml:\"class_id\"" ];

// designer is the designer of the credit class.
string designer = 2;
// admin is the admin of the credit class.
string admin = 2;
}

// EventCreateBatch is an event emitted when a credit batch is created.
Expand Down
8 changes: 4 additions & 4 deletions proto/regen/ecocredit/v1alpha1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ service Msg {
// MsgCreateClass is the Msg/CreateClass request type.
message MsgCreateClass {

// designer is the address of the account which designed the credit class. The
// designer has special permissions to change the list of issuers and perform
// other administrative operations.
string designer = 1;
// admin is the address of the account which can manage the credit class. The
// admin has permissions to change the list of issuers and perform other
// administrative operations.
string admin = 1;

// issuers are the account addresses of the approved issuers.
repeated string issuers = 2;
Expand Down
8 changes: 4 additions & 4 deletions proto/regen/ecocredit/v1alpha1/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ message ClassInfo {
// class_id is the unique ID of credit class.
string class_id = 1 [ (gogoproto.moretags) = "yaml:\"class_id\"" ];

// designer is the designer of the credit class.
string designer = 2;
// admin is the admin of the credit class.
string admin = 2;

// issuers are the approved issuers of the credit class.
repeated string issuers = 3;
Expand Down Expand Up @@ -82,9 +82,9 @@ message Params {
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];

// allowed_class_designers is an allowlist defining the addresses with
// allowed_class_creators is an allowlist defining the addresses with
// the required permissions to create credit classes
repeated string allowed_class_designers = 2;
repeated string allowed_class_creators = 2;

// allowlist_enabled is a param that enables/disables the allowlist for credit
// creation
Expand Down
2 changes: 1 addition & 1 deletion x/ecocredit/client/testsuite/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (s *IntegrationTestSuite) TestQueryClassInfo() {
expectErr: false,
expectedClassInfo: &ecocredit.ClassInfo{
ClassId: s.classInfo.ClassId,
Designer: s.classInfo.Designer,
Admin: s.classInfo.Admin,
Issuers: s.classInfo.Issuers,
Metadata: s.classInfo.Metadata,
CreditType: s.classInfo.CreditType,
Expand Down
73 changes: 31 additions & 42 deletions x/ecocredit/client/testsuite/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ func (s *IntegrationTestSuite) SetupSuite() {
out, err := cli.ExecTestCLICmd(val.ClientCtx, client.TxCreateClassCmd(),
append(
[]string{
val.Address.String(),
val.Address.String(),
validCreditType,
validMetadata,
Expand All @@ -105,7 +104,7 @@ func (s *IntegrationTestSuite) SetupSuite() {
// Store the first one in the test suite
s.classInfo = &ecocredit.ClassInfo{
ClassId: classId,
Designer: val.Address.String(),
Admin: val.Address.String(),
Issuers: []string{val.Address.String()},
CreditType: ecocredit.DefaultParams().CreditTypes[0],
Metadata: validMetadataBytes,
Expand Down Expand Up @@ -199,56 +198,34 @@ func (s *IntegrationTestSuite) TestTxCreateClass() {
respCode uint32
expectedClassInfo *ecocredit.ClassInfo
}{
{
name: "missing designer",
args: []string{},
expectErr: true,
expectedErrMsg: "accepts 4 arg(s), received 0",
},
{
name: "missing issuer",
args: []string{val0.Address.String()},
args: []string{},
expectErr: true,
expectedErrMsg: "accepts 4 arg(s), received 1",
expectedErrMsg: "accepts 3 arg(s), received 0",
},
{
name: "missing credit type",
args: []string{validCreditType},
args: []string{val0.Address.String()},
expectErr: true,
expectedErrMsg: "accepts 4 arg(s), received 1",
expectedErrMsg: "accepts 3 arg(s), received 1",
},
{
name: "missing metadata",
args: []string{val0.Address.String(), val0.Address.String()},
args: []string{val0.Address.String(), validCreditType},
expectErr: true,
expectedErrMsg: "accepts 4 arg(s), received 2",
expectedErrMsg: "accepts 3 arg(s), received 2",
},
{
name: "too many args",
args: []string{"abcde", "abcde", "abcde", "abcde", "dlskjf"},
args: []string{"abcde", "abcde", "abcde", "abcde"},
expectErr: true,
expectedErrMsg: "accepts 4 arg(s), received 5",
},
{
name: "invalid designer",
args: append(
[]string{
"abcde",
val0.Address.String(),
validCreditType,
validMetadata,
makeFlagFrom(val0.Address.String()),
},
s.commonTxFlags()...,
),
expectErr: true,
expectedErrMsg: "decoding bech32 failed: invalid bech32 string length 5",
expectedErrMsg: "accepts 3 arg(s), received 4",
},
{
name: "invalid issuer",
args: append(
[]string{
val0.Address.String(),
"abcde",
validCreditType,
validMetadata,
Expand All @@ -263,7 +240,6 @@ func (s *IntegrationTestSuite) TestTxCreateClass() {
name: "invalid metadata",
args: append(
[]string{
val0.Address.String(),
val0.Address.String(),
validCreditType,
"=",
Expand All @@ -278,7 +254,6 @@ func (s *IntegrationTestSuite) TestTxCreateClass() {
name: "missing from flag",
args: append(
[]string{
val0.Address.String(),
val0.Address.String(),
validCreditType,
validMetadata,
Expand All @@ -292,7 +267,6 @@ func (s *IntegrationTestSuite) TestTxCreateClass() {
name: "invalid credit type",
args: append(
[]string{
val0.Address.String(),
val0.Address.String(),
"caarbon",
validMetadata,
Expand All @@ -308,7 +282,6 @@ func (s *IntegrationTestSuite) TestTxCreateClass() {
name: "single issuer",
args: append(
[]string{
val0.Address.String(),
val0.Address.String(),
validCreditType,
validMetadata,
Expand All @@ -318,16 +291,33 @@ func (s *IntegrationTestSuite) TestTxCreateClass() {
),
expectErr: false,
expectedClassInfo: &ecocredit.ClassInfo{
Designer: val0.Address.String(),
Admin: val0.Address.String(),
Issuers: []string{val0.Address.String()},
Metadata: []byte{0x1},
},
},
{
name: "multiple issuers",
name: "single issuer with from key-name",
args: append(
[]string{
val0.Address.String(),
validCreditType,
validMetadata,
makeFlagFrom("node0"),
},
s.commonTxFlags()...,
),
expectErr: false,
expectedClassInfo: &ecocredit.ClassInfo{
Admin: val0.Address.String(),
Issuers: []string{val0.Address.String()},
Metadata: []byte{0x1},
},
},
{
name: "multiple issuers",
args: append(
[]string{
strings.Join(
[]string{
val0.Address.String(),
Expand All @@ -343,7 +333,7 @@ func (s *IntegrationTestSuite) TestTxCreateClass() {
),
expectErr: false,
expectedClassInfo: &ecocredit.ClassInfo{
Designer: val0.Address.String(),
Admin: val0.Address.String(),
Issuers: []string{val0.Address.String(), val1.Address.String()},
Metadata: []byte{0x1},
},
Expand All @@ -352,7 +342,6 @@ func (s *IntegrationTestSuite) TestTxCreateClass() {
name: "with amino-json",
args: append(
[]string{
val0.Address.String(),
val0.Address.String(),
validCreditType,
validMetadata,
Expand All @@ -363,7 +352,7 @@ func (s *IntegrationTestSuite) TestTxCreateClass() {
),
expectErr: false,
expectedClassInfo: &ecocredit.ClassInfo{
Designer: val0.Address.String(),
Admin: val0.Address.String(),
Issuers: []string{val0.Address.String()},
Metadata: []byte{0x1},
},
Expand Down Expand Up @@ -407,7 +396,7 @@ func (s *IntegrationTestSuite) TestTxCreateClass() {
var queryRes ecocredit.QueryClassInfoResponse
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(queryOut.Bytes(), &queryRes))

s.Require().Equal(tc.expectedClassInfo.Designer, queryRes.Info.Designer)
s.Require().Equal(tc.expectedClassInfo.Admin, queryRes.Info.Admin)
s.Require().Equal(tc.expectedClassInfo.Issuers, queryRes.Info.Issuers)
s.Require().Equal(tc.expectedClassInfo.Metadata, queryRes.Info.Metadata)
}
Expand Down
52 changes: 37 additions & 15 deletions x/ecocredit/client/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,39 +47,61 @@ func txflags(cmd *cobra.Command) *cobra.Command {

func TxCreateClassCmd() *cobra.Command {
return txflags(&cobra.Command{
Use: "create-class [designer] [issuer[,issuer]*] [credit type] [metadata]",
Short: "Creates a new credit class",
Long: `Creates a new credit class.
Use: "create-class [issuer[,issuer]*] [credit type] [metadata]",
Short: "Creates a new credit class with transaction author (--from) as admin",
Long: fmt.Sprintf(
`Creates a new credit class with transaction author (--from) as admin.

The transaction author must have permission to create a new credit class by
being a member of the %s allowlist. This is a governance parameter, so can be
queried via the command line.

They must also pay the fee associated with creating a new credit class, defined
by the %s parameter, so should make sure they have enough funds to cover that.

Parameters:
designer: address of the account which designed the credit class
issuer: comma separated (no spaces) list of issuer account addresses. Example: "addr1,addr2"
credit type: the credit class type (e.g. carbon, biodiversity, etc)
metadata: base64 encoded metadata - arbitrary data attached to the credit class info`,
Args: cobra.ExactArgs(4),
ecocredit.KeyAllowedClassCreators,
ecocredit.KeyCreditClassFee,
),
Args: cobra.ExactArgs(3),
RunE: func(cmd *cobra.Command, args []string) error {
issuers := strings.Split(args[1], ",")
clientCtx, err := sdkclient.GetClientTxContext(cmd)
if err != nil {
return err
}

// Get the class admin from the --from flag
admin := clientCtx.GetFromAddress()

// Parse the comma-separated list of issuers
issuers := strings.Split(args[0], ",")
for i := range issuers {
issuers[i] = strings.TrimSpace(issuers[i])
}
if args[2] == "" {

// Check credit type is provided
if args[1] == "" {
return sdkerrors.ErrInvalidRequest.Wrap("credit type is required")
}
creditType := args[2]
if args[3] == "" {
creditType := args[1]

// Check that metadata is provided and decode it
if args[2] == "" {
return errors.New("base64_metadata is required")
}
b, err := base64.StdEncoding.DecodeString(args[3])
b, err := base64.StdEncoding.DecodeString(args[2])
if err != nil {
return sdkerrors.ErrInvalidRequest.Wrap("metadata is malformed, proper base64 string is required")
}

clientCtx, err := sdkclient.GetClientTxContext(cmd)
if err != nil {
return err
}
msg := ecocredit.MsgCreateClass{
Designer: args[0], Issuers: issuers, Metadata: b, CreditType: creditType,
Admin: admin.String(),
Issuers: issuers,
Metadata: b,
CreditType: creditType,
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg)
},
Expand Down
Loading