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

fix(x/ecocredit): impl AminoMarshaler for DateCriteria #786

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
19 changes: 19 additions & 0 deletions x/ecocredit/basket/date_criteria.go
Original file line number Diff line number Diff line change
@@ -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"

Expand All @@ -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)
}
30 changes: 30 additions & 0 deletions x/ecocredit/basket/date_criteria_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package basket

import (
"github.com/cosmos/cosmos-sdk/codec"
"gotest.tools/v3/assert"
"testing"

"github.com/gogo/protobuf/types"
Expand All @@ -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)
}
57 changes: 0 additions & 57 deletions x/ecocredit/client/testsuite/enable_allowed_list.go

This file was deleted.

9 changes: 0 additions & 9 deletions x/ecocredit/client/testsuite/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions x/ecocredit/server/testsuite/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,7 @@ func (s *IntegrationTestSuite) TestScenario() {
allowlist []string
allowlistEnabled bool
wantErr bool
errMsg string
}{
{
name: "valid allowlist and enabled",
Expand All @@ -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",
Expand All @@ -1073,6 +1075,7 @@ func (s *IntegrationTestSuite) TestScenario() {
creatorAcc: s.signers[0],
allowlistEnabled: true,
wantErr: true,
errMsg: "not allowed",
},
}

Expand Down