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: fix error msg #592

Merged
merged 8 commits into from
Oct 25, 2021
Merged
Show file tree
Hide file tree
Changes from 7 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
#### Fixed

* [#591](https://github.com/regen-network/regen-ledger/pull/591) Set credit class fee in upgrade handler
* [#592](https://github.com/regen-network/regen-ledger/pull/592) fixed `undefined` error msg for creating class

## [v2.0.0-beta1](https://github.com/regen-network/regen-ledger/releases/tag/v2.0.0-beta1) - 2021-08-19

Expand Down
3 changes: 1 addition & 2 deletions app/testsuite/modules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ import (
"testing"

ecocredit "github.com/regen-network/regen-ledger/x/ecocredit/client/testsuite"
"github.com/stretchr/testify/suite"
)

func TestEcocreditIntegration(t *testing.T) {
cfg := DefaultConfig()

suite.Run(t, ecocredit.NewIntegrationTestSuite(cfg))
ecocredit.RunCLITests(t, cfg)
}
52 changes: 52 additions & 0 deletions x/ecocredit/client/testsuite/enable_allowed_list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
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
}
Comment on lines +14 to +19
Copy link
Contributor Author

@atheeshp atheeshp Oct 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a new suite for not to disturb the existing integration tests flow which is using AllowlistEnabled as false (anyone can create classes in this case)


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) 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()))
}
45 changes: 26 additions & 19 deletions x/ecocredit/client/testsuite/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/base64"
"fmt"
"strings"
"testing"

"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/crypto/hd"
Expand All @@ -17,6 +18,7 @@ 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 @@ -41,6 +43,18 @@ const (

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 {
return &IntegrationTestSuite{cfg: cfg}
}
Expand Down Expand Up @@ -71,26 +85,19 @@ func (s *IntegrationTestSuite) SetupSuite() {
val.ClientCtx.Keyring.SavePubKey("throwaway", a1pub, hd.Secp256k1Type)

account := sdk.AccAddress(info.GetPubKey().Address())
_, err = banktestutil.MsgSendExec(
val.ClientCtx,
val.Address,
account,
sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(2000))), 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)
for _, acc := range []sdk.AccAddress{account, a1} {
_, err = banktestutil.MsgSendExec(
val.ClientCtx,
val.Address,
acc,
sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(2000))), 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)
}

_, err = banktestutil.MsgSendExec(
val.ClientCtx,
val.Address,
a1,
sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(2000))), 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)
s.testAccount = a1
s.testAccount = account

var commonFlags = []string{
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
Expand Down
3 changes: 1 addition & 2 deletions x/ecocredit/server/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package server

import (
"context"
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
Expand Down Expand Up @@ -34,7 +33,7 @@ func (s serverImpl) CreateClass(goCtx context.Context, req *ecocredit.MsgCreateC
var params ecocredit.Params
s.paramSpace.GetParamSet(ctx.Context, &params)
if params.AllowlistEnabled && !s.isCreatorAllowListed(ctx, params.AllowedClassCreators, adminAddress) {
return nil, fmt.Errorf("%s is not allowed to create credit classes", adminAddress.String())
return nil, sdkerrors.ErrUnauthorized.Wrapf("%s is not allowed to create credit classes", adminAddress.String())
}

err = s.chargeCreditClassFee(ctx.Context, adminAddress)
Expand Down