Skip to content
This repository has been archived by the owner on Oct 24, 2024. It is now read-only.

Commit

Permalink
fix error format
Browse files Browse the repository at this point in the history
  • Loading branch information
taryune committed Oct 18, 2023
1 parent bb0edcc commit b4e9c68
Show file tree
Hide file tree
Showing 22 changed files with 84 additions and 114 deletions.
6 changes: 2 additions & 4 deletions x/epochs/types/epoch_info.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package types

import (
"errors"
"fmt"
"strings"

errorsmod "cosmossdk.io/errors"
Expand Down Expand Up @@ -30,10 +28,10 @@ func (e EpochInfo) Validate() error {
return ErrEpochDurationCannotBeZero
}
if e.CurrentEpoch < 0 {
return errorsmod.Wrapf(errors.New(fmt.Sprintf("%d", e.CurrentEpoch)), ErrCurrentEpochCannotBeNegative.Error())
return errorsmod.Wrapf(ErrCurrentEpochCannotBeNegative, "%d", e.CurrentEpoch)
}
if e.CurrentEpochStartHeight < 0 {
return errorsmod.Wrapf(errors.New(fmt.Sprintf("%d", e.CurrentEpoch)), ErrCurrentEpochStartHeightCannotBeNegative.Error())
return errorsmod.Wrapf(ErrCurrentEpochStartHeightCannotBeNegative, "%d", e.CurrentEpoch)
}
return nil
}
3 changes: 1 addition & 2 deletions x/epochs/types/genesis.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package types

import (
"errors"
"time"

errorsmod "cosmossdk.io/errors"
Expand Down Expand Up @@ -48,7 +47,7 @@ func (gs GenesisState) Validate() error {

for _, epoch := range gs.Epochs {
if epochIdentifiers[epoch.Identifier] {
return errorsmod.Wrapf(errors.New(epoch.Identifier), ErrDuplicatedEpochEntry.Error())
return errorsmod.Wrapf(ErrDuplicatedEpochEntry, "%s", epoch.Identifier)
}
if err := epoch.Validate(); err != nil {
return err
Expand Down
5 changes: 2 additions & 3 deletions x/registry/keeper/msg_server_register_second_level_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package keeper

import (
"context"
"errors"
"fmt"

"github.com/mycel-domain/mycel/x/registry/types"

Expand All @@ -14,8 +12,9 @@ import (
func (k msgServer) RegisterSecondLevelDomain(goCtx context.Context, msg *types.MsgRegisterSecondLevelDomain) (*types.MsgRegisterSecondLevelDomainResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

// TODO: Check parent's registration period
if msg.RegistrationPeriodInYear < 1 || msg.RegistrationPeriodInYear > 4 {
return nil, errorsmod.Wrapf(errors.New(fmt.Sprintf("%d year(s)", msg.RegistrationPeriodInYear)), types.ErrInvalidRegistrationPeriod.Error())
return nil, errorsmod.Wrapf(types.ErrInvalidRegistrationPeriod, "%d year(s)", msg.RegistrationPeriodInYear)
}

creatorAddress, err := sdk.AccAddressFromBech32(msg.Creator)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package keeper_test

import (
"errors"
"fmt"

authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
Expand Down Expand Up @@ -50,7 +49,7 @@ func (suite *KeeperTestSuite) TestRegisterSecondLevelDomain() {
name: "foo",
parent: "cel",
registrationPeriodInYear: 1,
expErr: errorsmod.Wrapf(errors.New(fmt.Sprintf("foo.cel")), types.ErrDomainIsAlreadyTaken.Error()),
expErr: errorsmod.Wrapf(types.ErrDomainIsAlreadyTaken, "foo.cel"),
fn: func() {
// Register domain once
domain := &types.MsgRegisterSecondLevelDomain{
Expand All @@ -68,7 +67,7 @@ func (suite *KeeperTestSuite) TestRegisterSecondLevelDomain() {
name: "foo",
parent: "xxx",
registrationPeriodInYear: 1,
expErr: errorsmod.Wrapf(errors.New(fmt.Sprintf("xxx")), types.ErrParentDomainDoesNotExist.Error()),
expErr: errorsmod.Wrapf(types.ErrParentDomainDoesNotExist, "xxx"),
fn: func() {
},
},
Expand Down
14 changes: 6 additions & 8 deletions x/registry/keeper/msg_server_register_top_level_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package keeper

import (
"context"
"errors"
"fmt"

"github.com/mycel-domain/mycel/x/registry/types"

Expand All @@ -15,7 +13,7 @@ func (k msgServer) RegisterTopLevelDomain(goCtx context.Context, msg *types.MsgR
ctx := sdk.UnwrapSDKContext(goCtx)

if msg.RegistrationPeriodInYear < 1 || msg.RegistrationPeriodInYear > 4 {
return nil, errorsmod.Wrapf(errors.New(fmt.Sprintf("%d year(s)", msg.RegistrationPeriodInYear)), types.ErrInvalidRegistrationPeriod.Error())
return nil, errorsmod.Wrapf(types.ErrInvalidRegistrationPeriod, "%d year(s)", msg.RegistrationPeriodInYear)
}

creatorAddress, err := sdk.AccAddressFromBech32(msg.Creator)
Expand All @@ -31,11 +29,11 @@ func (k msgServer) RegisterTopLevelDomain(goCtx context.Context, msg *types.MsgR

defaultRegistrationConfig := types.GetDefaultSubdomainConfig(3030)
domain := types.TopLevelDomain{
Name: msg.Name,
ExpirationDate: expirationDate.UnixNano(),
Metadata: nil,
SubdomainConfig: &defaultRegistrationConfig,
AccessControl: accessControl,
Name: msg.Name,
ExpirationDate: expirationDate.UnixNano(),
Metadata: nil,
SubdomainConfig: &defaultRegistrationConfig,
AccessControl: accessControl,
RegistrationFee: sdk.NewCoins(),
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package keeper_test

import (
"errors"
"fmt"

"github.com/mycel-domain/mycel/testutil"
Expand Down Expand Up @@ -37,7 +36,7 @@ func (suite *KeeperTestSuite) TestRegisterTopLevelDomain() {
creator: testutil.Alice,
name: "cel2",
registrationPeriodInYear: 1,
expErr: errorsmod.Wrapf(errors.New(fmt.Sprintf("cel2")), types.ErrDomainIsAlreadyTaken.Error()),
expErr: errorsmod.Wrapf(types.ErrDomainIsAlreadyTaken, "cel2"),
fn: func() {
// Register domain once
domain := &types.MsgRegisterTopLevelDomain{
Expand Down
4 changes: 1 addition & 3 deletions x/registry/keeper/msg_server_update_dns_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package keeper

import (
"context"
"errors"
"fmt"

"github.com/mycel-domain/mycel/x/registry/types"

Expand All @@ -16,7 +14,7 @@ func (k msgServer) UpdateDnsRecord(goCtx context.Context, msg *types.MsgUpdateDn

domain, isFound := k.Keeper.GetSecondLevelDomain(ctx, msg.Name, msg.Parent)
if !isFound {
return nil, errorsmod.Wrapf(errors.New(fmt.Sprintf("%s.%s", msg.Name, msg.Parent)), types.ErrDomainNotFound.Error())
return nil, errorsmod.Wrapf(types.ErrDomainNotFound, "%s.%s", msg.Name, msg.Parent)
}

// Check if the domain is owned by the creator
Expand Down
5 changes: 2 additions & 3 deletions x/registry/keeper/msg_server_update_dns_record_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package keeper_test

import (
"errors"
"fmt"

"github.com/mycel-domain/mycel/testutil"
Expand Down Expand Up @@ -54,7 +53,7 @@ func (suite *KeeperTestSuite) TestUpdateDnsRecord() {
parent: "fuga",
dnsRecordType: "A",
value: "192.168.0.1",
expErr: errorsmod.Wrapf(errors.New(fmt.Sprintf("hoge.fuga")), types.ErrDomainNotFound.Error()),
expErr: errorsmod.Wrapf(types.ErrDomainNotFound, "hoge.fuga"),
fn: func() {},
},
{
Expand All @@ -63,7 +62,7 @@ func (suite *KeeperTestSuite) TestUpdateDnsRecord() {
parent: "cel",
dnsRecordType: "A",
value: "192.168.0.1",
expErr: errorsmod.Wrapf(errors.New(fmt.Sprintf(testutil.Bob)), types.ErrDomainNotEditable.Error()),
expErr: errorsmod.Wrapf(types.ErrDomainNotEditable, "%s", testutil.Bob),
fn: func() {},
},
}
Expand Down
4 changes: 1 addition & 3 deletions x/registry/keeper/msg_server_update_wallet_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package keeper

import (
"context"
"errors"
"fmt"

"github.com/mycel-domain/mycel/x/registry/types"

Expand All @@ -16,7 +14,7 @@ func (k msgServer) UpdateWalletRecord(goCtx context.Context, msg *types.MsgUpdat

domain, isFound := k.Keeper.GetSecondLevelDomain(ctx, msg.Name, msg.Parent)
if !isFound {
return nil, errorsmod.Wrapf(errors.New(fmt.Sprintf("%s.%s", msg.Name, msg.Parent)), types.ErrDomainNotFound.Error())
return nil, errorsmod.Wrapf(types.ErrDomainNotFound, "%s.%s", msg.Name, msg.Parent)
}

// Check if the domain is owned by the creator
Expand Down
5 changes: 2 additions & 3 deletions x/registry/keeper/msg_server_update_wallet_record_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package keeper_test

import (
"errors"
"fmt"

"github.com/mycel-domain/mycel/x/registry/types"
Expand Down Expand Up @@ -73,7 +72,7 @@ func (suite *KeeperTestSuite) TestUpdateWalletRecord() {
parent: "fuga",
walletRecordType: "ETHEREUM_MAINNET_MAINNET",
value: "0x1234567890123456789012345678901234567890",
expErr: errorsmod.Wrapf(errors.New(fmt.Sprintf("hoge.fuga")), types.ErrDomainNotFound.Error()),
expErr: errorsmod.Wrapf(types.ErrDomainNotFound, "hoge.fuga"),
fn: func() {},
},
{
Expand All @@ -82,7 +81,7 @@ func (suite *KeeperTestSuite) TestUpdateWalletRecord() {
parent: "cel",
walletRecordType: "ETHEREUM_MAINNET_MAINNET",
value: "0x1234567890123456789012345678901234567890",
expErr: errorsmod.Wrapf(errors.New(fmt.Sprintf(testutil.Bob)), types.ErrDomainNotEditable.Error()),
expErr: errorsmod.Wrapf(types.ErrDomainNotEditable, "%s", testutil.Bob),
fn: func() {},
},
}
Expand Down
4 changes: 1 addition & 3 deletions x/registry/keeper/register_second_level_domain.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package keeper

import (
"errors"
"fmt"
"strconv"

"github.com/mycel-domain/mycel/x/registry/types"
Expand Down Expand Up @@ -87,7 +85,7 @@ func (k Keeper) RegisterSecondLevelDomain(ctx sdk.Context, domain types.SecondLe

// Check if parent domain has subdomain registration config
if parentDomain.SubdomainConfig.MaxSubdomainRegistrations <= parentDomain.SubdomainCount {
err = errorsmod.Wrapf(errors.New(fmt.Sprintf("%d", parentDomain.SubdomainCount)), types.ErrMaxSubdomainCountReached.Error())
err = errorsmod.Wrapf(types.ErrMaxSubdomainCountReached, "%d", parentDomain.SubdomainCount)
return err
}

Expand Down
6 changes: 2 additions & 4 deletions x/registry/keeper/second_level_domain.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package keeper

import (
"errors"
"fmt"
"github.com/mycel-domain/mycel/x/registry/types"
"time"

Expand Down Expand Up @@ -86,13 +84,13 @@ func (k Keeper) GetValidSecondLevelDomain(ctx sdk.Context, name string, parent s
// Get second level domain
secondLevelDomain, isFound := k.GetSecondLevelDomain(ctx, name, parent)
if !isFound {
return secondLevelDomain, errosmod.Wrapf(errors.New(fmt.Sprintf("%s.%s", name, parent)), types.ErrDomainNotFound.Error())
return secondLevelDomain, errosmod.Wrapf(types.ErrDomainNotFound, "%s.%s", name, parent)
}

// Check if domain is not expired
expirationDate := time.Unix(0, secondLevelDomain.ExpirationDate)
if ctx.BlockTime().After(expirationDate) && secondLevelDomain.ExpirationDate != 0 {
return secondLevelDomain, errosmod.Wrapf(errors.New(fmt.Sprintf("%s", name)), types.ErrDomainExpired.Error())
return secondLevelDomain, errosmod.Wrapf(types.ErrDomainExpired, "%s", name)
}

return secondLevelDomain, nil
Expand Down
5 changes: 2 additions & 3 deletions x/registry/keeper/second_level_domain_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package keeper_test

import (
"errors"
"fmt"
"strconv"
"testing"
Expand All @@ -11,8 +10,8 @@ import (
"github.com/mycel-domain/mycel/x/registry/keeper"
"github.com/mycel-domain/mycel/x/registry/types"

errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -108,7 +107,7 @@ func (suite *KeeperTestSuite) TestGetValidSecondLevelDomain() {
Parent: "test",
ExpirationDate: suite.ctx.BlockTime().AddDate(0, 0, -20).UnixNano(),
},
expErr: sdkerrors.Wrapf(errors.New(fmt.Sprintf("test")), types.ErrDomainExpired.Error()),
expErr: errorsmod.Wrapf(types.ErrDomainExpired, "test"),
},
}
for i, tc := range testCases {
Expand Down
8 changes: 3 additions & 5 deletions x/registry/keeper/top_level_domain.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package keeper

import (
"errors"
"fmt"
"time"

errorsmod "cosmossdk.io/errors"
"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/mycel-domain/mycel/x/registry/types"
)

Expand Down Expand Up @@ -79,13 +77,13 @@ func (k Keeper) GetValidTopLevelDomain(ctx sdk.Context, name string) (topLevelDo
// Get top level domain
topLevelDomain, isFound := k.GetTopLevelDomain(ctx, name)
if !isFound {
return topLevelDomain, sdkerrors.Wrapf(errors.New(fmt.Sprintf("%s", name)), types.ErrDomainNotFound.Error())
return topLevelDomain, errorsmod.Wrapf(types.ErrDomainNotFound, "%s", name)
}

// Check if domain is not expired
expirationDate := time.Unix(0, topLevelDomain.ExpirationDate)
if ctx.BlockTime().After(expirationDate) && topLevelDomain.ExpirationDate != 0 {
return topLevelDomain, sdkerrors.Wrapf(errors.New(fmt.Sprintf("%s", name)), types.ErrDomainExpired.Error())
return topLevelDomain, errorsmod.Wrapf(types.ErrDomainExpired, "%s", name)
}

return topLevelDomain, nil
Expand Down
5 changes: 2 additions & 3 deletions x/registry/keeper/top_level_domain_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package keeper_test

import (
"errors"
"fmt"

"strconv"
"testing"

errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
keepertest "github.com/mycel-domain/mycel/testutil/keeper"
"github.com/mycel-domain/mycel/testutil/nullify"
"github.com/mycel-domain/mycel/x/registry/keeper"
Expand Down Expand Up @@ -90,7 +89,7 @@ func (suite *KeeperTestSuite) TestGetValidTopLevelDomain() {
Name: "test",
ExpirationDate: suite.ctx.BlockTime().AddDate(0, 0, -20).UnixNano(),
},
expErr: sdkerrors.Wrapf(errors.New(fmt.Sprintf("test")), types.ErrDomainExpired.Error()),
expErr: errorsmod.Wrapf(types.ErrDomainExpired, "test"),
},
}
for i, tc := range testCases {
Expand Down
Loading

0 comments on commit b4e9c68

Please sign in to comment.