From 552c830dfeb59288d3cfb02e79fa0d1e1de7ed45 Mon Sep 17 00:00:00 2001 From: technicallyty <48813565+tytech3@users.noreply.github.com> Date: Thu, 17 Feb 2022 11:18:12 -0800 Subject: [PATCH 1/4] feat: remove --- .../client/testsuite/enable_allowed_list.go | 57 ------------------- x/ecocredit/client/testsuite/tx.go | 9 --- 2 files changed, 66 deletions(-) delete mode 100644 x/ecocredit/client/testsuite/enable_allowed_list.go diff --git a/x/ecocredit/client/testsuite/enable_allowed_list.go b/x/ecocredit/client/testsuite/enable_allowed_list.go deleted file mode 100644 index c113cb4e38..0000000000 --- a/x/ecocredit/client/testsuite/enable_allowed_list.go +++ /dev/null @@ -1,57 +0,0 @@ -package testsuite - -import ( - "fmt" - - "github.com/cosmos/cosmos-sdk/client/flags" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/regen-network/regen-ledger/types/testutil/cli" - "github.com/regen-network/regen-ledger/types/testutil/network" - "github.com/regen-network/regen-ledger/x/ecocredit/client" - "github.com/stretchr/testify/suite" -) - -type AllowListEnabledTestSuite struct { - suite.Suite - - cfg network.Config - network *network.Network -} - -func NewAllowListEnabledTestSuite(cfg network.Config) *AllowListEnabledTestSuite { - return &AllowListEnabledTestSuite{cfg: cfg} -} - -func (s *AllowListEnabledTestSuite) SetupSuite() { - s.network = network.New(s.T(), s.cfg) - _, err := s.network.WaitForHeight(1) - s.Require().NoError(err) -} - -func (s *AllowListEnabledTestSuite) TearDownSuite() { - s.T().Log("tearing down integration test suite") - s.network.Cleanup() -} - -func (s *AllowListEnabledTestSuite) TestCreateClass() { - val := s.network.Validators[0] - - out, err := cli.ExecTestCLICmd(val.ClientCtx, client.TxCreateClassCmd(), - []string{ - val.Address.String(), - "carbon", - "AQ==", - fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()), - fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), - fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), - fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), - }, - ) - - s.Require().NoError(err, out.String()) - - // tx should fail with error unauthorized since we enabled `AllowlistEnabled` param & set `AllowedClassCreators` as `[]`. - var res sdk.TxResponse - s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &res)) - s.Require().Contains(res.RawLog, fmt.Sprintf("%s is not allowed to create credit classes", val.Address.String())) -} diff --git a/x/ecocredit/client/testsuite/tx.go b/x/ecocredit/client/testsuite/tx.go index 552288b467..7cc5aebe50 100644 --- a/x/ecocredit/client/testsuite/tx.go +++ b/x/ecocredit/client/testsuite/tx.go @@ -18,7 +18,6 @@ import ( "github.com/regen-network/regen-ledger/types/testutil/network" "github.com/regen-network/regen-ledger/x/ecocredit" "github.com/regen-network/regen-ledger/x/ecocredit/client" - "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" tmcli "github.com/tendermint/tendermint/libs/cli" ) @@ -45,14 +44,6 @@ var validMetadataBytes = []byte{0x1} func RunCLITests(t *testing.T, cfg network.Config) { suite.Run(t, NewIntegrationTestSuite(cfg)) - - // setup another cfg for testing ecocredit enabled class creators list. - genesisState := ecocredit.DefaultGenesisState() - genesisState.Params.AllowlistEnabled = true - bz, err := cfg.Codec.MarshalJSON(genesisState) - require.NoError(t, err) - cfg.GenesisState[ecocredit.ModuleName] = bz - suite.Run(t, NewAllowListEnabledTestSuite(cfg)) } func NewIntegrationTestSuite(cfg network.Config) *IntegrationTestSuite { From cdd7fe81d0ba09c63af96e659cd64186386a22a7 Mon Sep 17 00:00:00 2001 From: technicallyty <48813565+tytech3@users.noreply.github.com> Date: Thu, 17 Feb 2022 11:24:34 -0800 Subject: [PATCH 2/4] chore: add errMsg --- x/ecocredit/server/testsuite/suite.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/x/ecocredit/server/testsuite/suite.go b/x/ecocredit/server/testsuite/suite.go index c3b8c90e08..9b7271ebf8 100644 --- a/x/ecocredit/server/testsuite/suite.go +++ b/x/ecocredit/server/testsuite/suite.go @@ -1038,6 +1038,7 @@ func (s *IntegrationTestSuite) TestScenario() { allowlist []string allowlistEnabled bool wantErr bool + errMsg string }{ { name: "valid allowlist and enabled", @@ -1059,6 +1060,7 @@ func (s *IntegrationTestSuite) TestScenario() { creatorAcc: s.signers[1], allowlistEnabled: true, wantErr: true, + errMsg: "not allowed", }, { name: "valid allowlist but disabled - anyone can create credits", @@ -1073,6 +1075,7 @@ func (s *IntegrationTestSuite) TestScenario() { creatorAcc: s.signers[0], allowlistEnabled: true, wantErr: true, + errMsg: "not allowed", }, } From 0dbb7f020f12e498bc4a0dcd00800f35dcb695cc Mon Sep 17 00:00:00 2001 From: technicallyty <48813565+tytech3@users.noreply.github.com> Date: Thu, 17 Feb 2022 13:09:26 -0800 Subject: [PATCH 3/4] go mod tidy --- types/go.mod | 1 + 1 file changed, 1 insertion(+) diff --git a/types/go.mod b/types/go.mod index 13a976d8bc..f09f9a3740 100644 --- a/types/go.mod +++ b/types/go.mod @@ -6,6 +6,7 @@ require ( github.com/cockroachdb/apd/v2 v2.0.2 github.com/cosmos/cosmos-sdk v0.44.2 github.com/gogo/protobuf v1.3.3 + github.com/golang/mock v1.6.0 github.com/grpc-ecosystem/grpc-gateway v1.16.0 github.com/spf13/cobra v1.2.1 github.com/stretchr/testify v1.7.0 From 3eff08b9e1da042df071167474af5559a488ad04 Mon Sep 17 00:00:00 2001 From: technicallyty <48813565+tytech3@users.noreply.github.com> Date: Thu, 17 Feb 2022 15:27:34 -0800 Subject: [PATCH 4/4] feat: date criteria amino compat --- x/ecocredit/basket/date_criteria.go | 19 +++++++++++++++ x/ecocredit/basket/date_criteria_test.go | 30 ++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/x/ecocredit/basket/date_criteria.go b/x/ecocredit/basket/date_criteria.go index 393bf97fc1..5cc06220bd 100644 --- a/x/ecocredit/basket/date_criteria.go +++ b/x/ecocredit/basket/date_criteria.go @@ -1,6 +1,7 @@ package basket import ( + "github.com/cosmos/cosmos-sdk/codec" "google.golang.org/protobuf/types/known/durationpb" "google.golang.org/protobuf/types/known/timestamppb" @@ -21,3 +22,21 @@ func (d *DateCriteria) ToApi() *basketv1.DateCriteria { } return nil } + +var _ codec.AminoMarshaler = &DateCriteria{} + +func (d DateCriteria) MarshalAminoJSON() ([]byte, error) { + return d.Marshal() +} + +func (d *DateCriteria) UnmarshalAminoJSON(bytes []byte) error { + return d.Unmarshal(bytes) +} + +func (d DateCriteria) MarshalAmino() ([]byte, error) { + return d.Marshal() +} + +func (d *DateCriteria) UnmarshalAmino(bytes []byte) error { + return d.Unmarshal(bytes) +} diff --git a/x/ecocredit/basket/date_criteria_test.go b/x/ecocredit/basket/date_criteria_test.go index 0d8a443502..171a7493b3 100644 --- a/x/ecocredit/basket/date_criteria_test.go +++ b/x/ecocredit/basket/date_criteria_test.go @@ -1,6 +1,8 @@ package basket import ( + "github.com/cosmos/cosmos-sdk/codec" + "gotest.tools/v3/assert" "testing" "github.com/gogo/protobuf/types" @@ -27,3 +29,31 @@ func TestDateCriteriaToApi(t *testing.T) { require.NotNil(dw) require.Equal(durStd, dw.AsDuration(), "handles window date") } + +func TestAminoDate(t *testing.T) { + cdc := codec.NewLegacyAmino() + dur := types.Duration{Seconds: 50} + bsk := MsgCreate{ + Name: "foo", + DateCriteria: &DateCriteria{Sum: &DateCriteria_StartDateWindow{StartDateWindow: &dur}}, + Exponent: 32, + } + + // test Un/MarshalJSON + bz, err := cdc.MarshalJSON(bsk) + assert.NilError(t, err) + var bsk2 MsgCreate + err = cdc.UnmarshalJSON(bz, &bsk2) + assert.NilError(t, err) + + // test regular Un/Marshal + bz, err = cdc.Marshal(bsk) + assert.NilError(t, err) + var bsk3 MsgCreate + err = cdc.Unmarshal(bz, &bsk3) + assert.NilError(t, err) + + + assert.DeepEqual(t, bsk, bsk2) + assert.DeepEqual(t, bsk2, bsk3) +}