Skip to content

Commit

Permalink
refactor: remove sdkerrortypes (tendermint#967)
Browse files Browse the repository at this point in the history
* reward

* profile

* profile

* launch

* campaign

* monitoringc

* monitoringp

* participation

* refactor funds errors

Co-authored-by: Lucas Bertrand <[email protected]>
  • Loading branch information
Alex Johnson and lumtis authored Oct 7, 2022
1 parent 2345454 commit 266305d
Show file tree
Hide file tree
Showing 73 changed files with 174 additions and 177 deletions.
2 changes: 1 addition & 1 deletion x/campaign/keeper/msg_create_campaign.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (k msgServer) CreateCampaign(goCtx context.Context, msg *types.MsgCreateCam
return nil, ignterrors.Criticalf("invalid coordinator bech32 address %s", err.Error())
}
if err = k.distrKeeper.FundCommunityPool(ctx, creationFee, coordAddr); err != nil {
return nil, err
return nil, sdkerrors.Wrap(types.ErrFundCommunityPool, err.Error())
}
}

Expand Down
3 changes: 1 addition & 2 deletions x/campaign/keeper/msg_create_campaign_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrortypes "github.com/cosmos/cosmos-sdk/types/errors"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -125,7 +124,7 @@ func TestMsgCreateCampaign(t *testing.T) {
TotalSupply: sample.TotalSupply(r),
Metadata: sample.Metadata(r, 20),
},
err: sdkerrortypes.ErrInsufficientFunds,
err: types.ErrFundCommunityPool,
},
} {
t.Run(tc.name, func(t *testing.T) {
Expand Down
4 changes: 4 additions & 0 deletions x/campaign/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@ var (
ErrInvalidMetadataLength = sdkerrors.Register(ModuleName, 15, "metadata field too long")
ErrMainnetLaunchTriggered = sdkerrors.Register(ModuleName, 16, "mainnet launch already triggered")
ErrInvalidSpecialAllocations = sdkerrors.Register(ModuleName, 17, "invalid special allocations")
ErrInvalidMainnetInfo = sdkerrors.Register(ModuleName, 18, "invalid mainnet info")
ErrCannotUpdateCampaign = sdkerrors.Register(ModuleName, 19, "cannot update campaign")
ErrInvalidVoucherAddress = sdkerrors.Register(ModuleName, 20, "invalid address for voucher operation")
ErrFundCommunityPool = sdkerrors.Register(ModuleName, 21, "unable to fund community pool")
)
3 changes: 1 addition & 2 deletions x/campaign/types/msg_burn_vouchers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package types
import (
sdkerrors "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrortypes "github.com/cosmos/cosmos-sdk/types/errors"
)

const TypeMsgBurnVouchers = "burn_vouchers"
Expand Down Expand Up @@ -42,7 +41,7 @@ func (msg *MsgBurnVouchers) GetSignBytes() []byte {
func (msg *MsgBurnVouchers) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(msg.Sender)
if err != nil {
return sdkerrors.Wrapf(sdkerrortypes.ErrInvalidAddress, "invalid sender address (%s)", err)
return sdkerrors.Wrapf(ErrInvalidVoucherAddress, "invalid sender address (%s)", err)
}

if !msg.Vouchers.IsValid() {
Expand Down
3 changes: 1 addition & 2 deletions x/campaign/types/msg_burn_vouchers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrortypes "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/stretchr/testify/require"

"github.com/tendermint/spn/testutil/sample"
Expand Down Expand Up @@ -35,7 +34,7 @@ func TestMsgBurnVouchers_ValidateBasic(t *testing.T) {
CampaignID: 0,
Vouchers: sample.Coins(r),
},
err: sdkerrortypes.ErrInvalidAddress,
err: types.ErrInvalidVoucherAddress,
},
{
name: "should prevent validation of msg with invalid vouchers",
Expand Down
4 changes: 2 additions & 2 deletions x/campaign/types/msg_create_campaign.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package types
import (
sdkerrors "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrortypes "github.com/cosmos/cosmos-sdk/types/errors"

spntypes "github.com/tendermint/spn/pkg/types"
profile "github.com/tendermint/spn/x/profile/types"
)

const TypeMsgCreateCampaign = "create_campaign"
Expand Down Expand Up @@ -50,7 +50,7 @@ func (msg *MsgCreateCampaign) GetSignBytes() []byte {
func (msg *MsgCreateCampaign) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(msg.Coordinator)
if err != nil {
return sdkerrors.Wrapf(sdkerrortypes.ErrInvalidAddress, "invalid coordinator address (%s)", err)
return sdkerrors.Wrap(profile.ErrInvalidCoordAddress, err.Error())
}

if err := CheckCampaignName(msg.CampaignName); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions x/campaign/types/msg_create_campaign_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import (

sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrortypes "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/stretchr/testify/require"

spntypes "github.com/tendermint/spn/pkg/types"
"github.com/tendermint/spn/testutil/sample"
"github.com/tendermint/spn/x/campaign/types"
profile "github.com/tendermint/spn/x/profile/types"
)

func TestMsgCreateCampaign_ValidateBasic(t *testing.T) {
Expand Down Expand Up @@ -38,7 +38,7 @@ func TestMsgCreateCampaign_ValidateBasic(t *testing.T) {
TotalSupply: sample.TotalSupply(r),
Metadata: sample.Metadata(r, 20),
},
err: sdkerrortypes.ErrInvalidAddress,
err: profile.ErrInvalidCoordAddress,
},
{
name: "should prevent validation of msg with invalid campaign name",
Expand Down
7 changes: 4 additions & 3 deletions x/campaign/types/msg_edit_campaign.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package types
import (
sdkerrors "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrortypes "github.com/cosmos/cosmos-sdk/types/errors"

profile "github.com/tendermint/spn/x/profile/types"

spntypes "github.com/tendermint/spn/pkg/types"
)
Expand Down Expand Up @@ -45,11 +46,11 @@ func (msg *MsgEditCampaign) GetSignBytes() []byte {
func (msg *MsgEditCampaign) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(msg.Coordinator)
if err != nil {
return sdkerrors.Wrapf(sdkerrortypes.ErrInvalidAddress, "invalid coordinator address (%s)", err)
return sdkerrors.Wrap(profile.ErrInvalidCoordAddress, err.Error())
}

if len(msg.Name) == 0 && len(msg.Metadata) == 0 {
return sdkerrors.Wrapf(sdkerrortypes.ErrInvalidRequest, "must modify at least one field (name or metadata)")
return sdkerrors.Wrap(ErrCannotUpdateCampaign, "must modify at least one field (name or metadata)")
}

if len(msg.Name) != 0 {
Expand Down
7 changes: 4 additions & 3 deletions x/campaign/types/msg_edit_campaign_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package types_test
import (
"testing"

sdkerrortypes "github.com/cosmos/cosmos-sdk/types/errors"
profile "github.com/tendermint/spn/x/profile/types"

"github.com/stretchr/testify/require"

spntypes "github.com/tendermint/spn/pkg/types"
Expand Down Expand Up @@ -63,7 +64,7 @@ func TestMsgEditCampaign_ValidateBasic(t *testing.T) {
Name: sample.CampaignName(r),
Metadata: sample.Metadata(r, 20),
},
err: sdkerrortypes.ErrInvalidAddress,
err: profile.ErrInvalidCoordAddress,
},
{
name: "should prevent validation of msg with invalid metadata length",
Expand All @@ -83,7 +84,7 @@ func TestMsgEditCampaign_ValidateBasic(t *testing.T) {
Name: "",
Metadata: []byte{},
},
err: sdkerrortypes.ErrInvalidRequest,
err: types.ErrCannotUpdateCampaign,
},
}
for _, tt := range tests {
Expand Down
10 changes: 5 additions & 5 deletions x/campaign/types/msg_initialize_mainnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package types
import (
sdkerrors "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrortypes "github.com/cosmos/cosmos-sdk/types/errors"

"github.com/tendermint/spn/pkg/chainid"
profile "github.com/tendermint/spn/x/profile/types"
)

const TypeMsgInitializeMainnet = "initialize_mainnet"
Expand Down Expand Up @@ -52,17 +52,17 @@ func (msg *MsgInitializeMainnet) GetSignBytes() []byte {
func (msg *MsgInitializeMainnet) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(msg.Coordinator)
if err != nil {
return sdkerrors.Wrapf(sdkerrortypes.ErrInvalidAddress, "invalid coordinator address (%s)", err)
return sdkerrors.Wrap(profile.ErrInvalidCoordAddress, err.Error())
}

if msg.SourceURL == "" {
return sdkerrors.Wrap(sdkerrortypes.ErrInvalidRequest, "empty source URL")
return sdkerrors.Wrap(ErrInvalidMainnetInfo, "empty source URL")
}
if msg.SourceHash == "" {
return sdkerrors.Wrap(sdkerrortypes.ErrInvalidRequest, "empty source hash")
return sdkerrors.Wrap(ErrInvalidMainnetInfo, "empty source hash")
}
if _, _, err := chainid.ParseGenesisChainID(msg.MainnetChainID); err != nil {
return sdkerrors.Wrapf(sdkerrortypes.ErrInvalidRequest, err.Error())
return sdkerrors.Wrapf(ErrInvalidMainnetInfo, err.Error())
}

return nil
Expand Down
10 changes: 5 additions & 5 deletions x/campaign/types/msg_initialize_mainnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package types_test
import (
"testing"

sdkerrortypes "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/stretchr/testify/require"

"github.com/tendermint/spn/testutil/sample"
"github.com/tendermint/spn/x/campaign/types"
profile "github.com/tendermint/spn/x/profile/types"
)

func TestMsgInitializeMainnet_ValidateBasic(t *testing.T) {
Expand Down Expand Up @@ -35,7 +35,7 @@ func TestMsgInitializeMainnet_ValidateBasic(t *testing.T) {
SourceHash: sample.String(r, 20),
MainnetChainID: sample.GenesisChainID(r),
},
err: sdkerrortypes.ErrInvalidAddress,
err: profile.ErrInvalidCoordAddress,
},
{
name: "should prevent validation of msg with empty source URL",
Expand All @@ -46,7 +46,7 @@ func TestMsgInitializeMainnet_ValidateBasic(t *testing.T) {
SourceHash: sample.String(r, 20),
MainnetChainID: sample.GenesisChainID(r),
},
err: sdkerrortypes.ErrInvalidRequest,
err: types.ErrInvalidMainnetInfo,
},
{
name: "should prevent validation of msg with empty source hash",
Expand All @@ -57,7 +57,7 @@ func TestMsgInitializeMainnet_ValidateBasic(t *testing.T) {
SourceHash: "",
MainnetChainID: sample.GenesisChainID(r),
},
err: sdkerrortypes.ErrInvalidRequest,
err: types.ErrInvalidMainnetInfo,
},
{
name: "should prevent validation of msg with invalid chain id",
Expand All @@ -68,7 +68,7 @@ func TestMsgInitializeMainnet_ValidateBasic(t *testing.T) {
SourceHash: sample.String(r, 20),
MainnetChainID: "invalid_chain_id",
},
err: sdkerrortypes.ErrInvalidRequest,
err: types.ErrInvalidMainnetInfo,
},
}
for _, tt := range tests {
Expand Down
5 changes: 3 additions & 2 deletions x/campaign/types/msg_mint_vouchers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package types
import (
sdkerrors "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrortypes "github.com/cosmos/cosmos-sdk/types/errors"

profile "github.com/tendermint/spn/x/profile/types"
)

const TypeMsgMintVouchers = "mint_vouchers"
Expand Down Expand Up @@ -42,7 +43,7 @@ func (msg *MsgMintVouchers) GetSignBytes() []byte {
func (msg *MsgMintVouchers) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(msg.Coordinator)
if err != nil {
return sdkerrors.Wrapf(sdkerrortypes.ErrInvalidAddress, "invalid coordinator address (%s)", err)
return sdkerrors.Wrap(profile.ErrInvalidCoordAddress, err.Error())
}

if !sdk.Coins(msg.Shares).IsValid() {
Expand Down
4 changes: 2 additions & 2 deletions x/campaign/types/msg_mint_vouchers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import (

sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrortypes "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/stretchr/testify/require"

"github.com/tendermint/spn/testutil/sample"
"github.com/tendermint/spn/x/campaign/types"
profile "github.com/tendermint/spn/x/profile/types"
)

func TestMsgMintVouchers_ValidateBasic(t *testing.T) {
Expand All @@ -35,7 +35,7 @@ func TestMsgMintVouchers_ValidateBasic(t *testing.T) {
CampaignID: 0,
Shares: sample.Shares(r),
},
err: sdkerrortypes.ErrInvalidAddress,
err: profile.ErrInvalidCoordAddress,
},
{
name: "should prevent validation of msg with invalid shares",
Expand Down
5 changes: 2 additions & 3 deletions x/campaign/types/msg_redeem_vouchers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package types
import (
sdkerrors "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrortypes "github.com/cosmos/cosmos-sdk/types/errors"
)

const TypeMsgRedeemVouchers = "redeem_vouchers"
Expand Down Expand Up @@ -43,12 +42,12 @@ func (msg *MsgRedeemVouchers) GetSignBytes() []byte {
func (msg *MsgRedeemVouchers) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(msg.Sender)
if err != nil {
return sdkerrors.Wrapf(sdkerrortypes.ErrInvalidAddress, "invalid sender address (%s)", err)
return sdkerrors.Wrapf(ErrInvalidVoucherAddress, "invalid sender address (%s)", err)
}

_, err = sdk.AccAddressFromBech32(msg.Account)
if err != nil {
return sdkerrors.Wrapf(sdkerrortypes.ErrInvalidAddress, "invalid account address (%s)", err)
return sdkerrors.Wrapf(ErrInvalidVoucherAddress, "invalid account address (%s)", err)
}

if !msg.Vouchers.IsValid() {
Expand Down
5 changes: 2 additions & 3 deletions x/campaign/types/msg_redeem_vouchers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrortypes "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/stretchr/testify/require"

"github.com/tendermint/spn/testutil/sample"
Expand Down Expand Up @@ -47,7 +46,7 @@ func TestMsgRedeemVouchers_ValidateBasic(t *testing.T) {
Vouchers: sample.Vouchers(r, 0),
CampaignID: 0,
},
err: sdkerrortypes.ErrInvalidAddress,
err: types.ErrInvalidVoucherAddress,
},
{
name: "should prevent validation of msg with invalid account address",
Expand All @@ -57,7 +56,7 @@ func TestMsgRedeemVouchers_ValidateBasic(t *testing.T) {
Vouchers: sample.Vouchers(r, 0),
CampaignID: 0,
},
err: sdkerrortypes.ErrInvalidAddress,
err: types.ErrInvalidVoucherAddress,
},
{
name: "should prevent validation of msg with invalid coin voucher",
Expand Down
3 changes: 1 addition & 2 deletions x/campaign/types/msg_unredeem_vouchers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package types
import (
sdkerrors "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrortypes "github.com/cosmos/cosmos-sdk/types/errors"
)

const TypeMsgUnredeemVouchers = "unredeem_vouchers"
Expand Down Expand Up @@ -42,7 +41,7 @@ func (msg *MsgUnredeemVouchers) GetSignBytes() []byte {
func (msg *MsgUnredeemVouchers) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(msg.Sender)
if err != nil {
return sdkerrors.Wrapf(sdkerrortypes.ErrInvalidAddress, "invalid sender address (%s)", err)
return sdkerrors.Wrapf(ErrInvalidVoucherAddress, "invalid sender address (%s)", err)
}

if !sdk.Coins(msg.Shares).IsValid() {
Expand Down
3 changes: 1 addition & 2 deletions x/campaign/types/msg_unredeem_vouchers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrortypes "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/stretchr/testify/require"

"github.com/tendermint/spn/testutil/sample"
Expand Down Expand Up @@ -35,7 +34,7 @@ func TestMsgUnredeemVouchers_ValidateBasic(t *testing.T) {
CampaignID: 0,
Shares: sample.Shares(r),
},
err: sdkerrortypes.ErrInvalidAddress,
err: types.ErrInvalidVoucherAddress,
},
{
name: "should prevent validation of msg with invalid shares",
Expand Down
5 changes: 3 additions & 2 deletions x/campaign/types/msg_update_special_allocations.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package types
import (
sdkerrors "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrortypes "github.com/cosmos/cosmos-sdk/types/errors"

profile "github.com/tendermint/spn/x/profile/types"
)

const TypeMsgUpdateSpecialAllocations = "update_special_allocations"
Expand Down Expand Up @@ -45,7 +46,7 @@ func (msg *MsgUpdateSpecialAllocations) GetSignBytes() []byte {

func (msg *MsgUpdateSpecialAllocations) ValidateBasic() error {
if _, err := sdk.AccAddressFromBech32(msg.Coordinator); err != nil {
return sdkerrors.Wrapf(sdkerrortypes.ErrInvalidAddress, "invalid coordinator address (%s)", err)
return sdkerrors.Wrap(profile.ErrInvalidCoordAddress, err.Error())
}
if err := msg.SpecialAllocations.Validate(); err != nil {
return sdkerrors.Wrapf(ErrInvalidSpecialAllocations, err.Error())
Expand Down
Loading

0 comments on commit 266305d

Please sign in to comment.