From a8df141953e146ecd12fd0a67912b678cbd09514 Mon Sep 17 00:00:00 2001 From: Kitipong Sirirueangsakul Date: Tue, 3 Oct 2023 13:14:44 +0700 Subject: [PATCH 1/8] add route, type for update params in globalfee --- x/globalfee/types/keys.go | 4 ++++ x/globalfee/types/msgs.go | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/x/globalfee/types/keys.go b/x/globalfee/types/keys.go index f79244713..012e31211 100644 --- a/x/globalfee/types/keys.go +++ b/x/globalfee/types/keys.go @@ -4,10 +4,14 @@ const ( // ModuleName is the name of the this module ModuleName = "globalfee" + // QuerierRoute is the querier route for the globalfee module QuerierRoute = ModuleName // StoreKey to be used when creating the KVStore. StoreKey = ModuleName + + // RouterKey is the msg router key for the globalfee module + RouterKey = ModuleName ) var ( diff --git a/x/globalfee/types/msgs.go b/x/globalfee/types/msgs.go index 27ecb6f9c..d9e5fa964 100644 --- a/x/globalfee/types/msgs.go +++ b/x/globalfee/types/msgs.go @@ -5,8 +5,18 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) +const ( + TypeMsgUpdateParams = "update_params" +) + var _ sdk.Msg = &MsgUpdateParams{} +// Route returns the route of MsgUpdateParams - "oracle" (sdk.Msg interface). +func (m MsgUpdateParams) Route() string { return RouterKey } + +// Type returns the message type of MsgUpdateParams (sdk.Msg interface). +func (m MsgUpdateParams) Type() string { return TypeMsgUpdateParams } + // GetSignBytes implements the LegacyMsg interface. func (m MsgUpdateParams) GetSignBytes() []byte { return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m)) From 0904069def5aa390b8de4f33e8057b9051a8b3bf Mon Sep 17 00:00:00 2001 From: colmazia Date: Wed, 4 Oct 2023 14:17:23 +0700 Subject: [PATCH 2/8] add consensus in upgrade --- app/upgrades/v2_6/constants.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/upgrades/v2_6/constants.go b/app/upgrades/v2_6/constants.go index fac25fab8..08421a651 100644 --- a/app/upgrades/v2_6/constants.go +++ b/app/upgrades/v2_6/constants.go @@ -6,6 +6,7 @@ import ( vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" "github.com/cosmos/cosmos-sdk/x/authz" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + consensusparamtypes "github.com/cosmos/cosmos-sdk/x/consensus/types" distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" "github.com/cosmos/cosmos-sdk/x/feegrant" govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" @@ -24,7 +25,7 @@ var Upgrade = upgrades.Upgrade{ UpgradeName: UpgradeName, CreateUpgradeHandler: CreateUpgradeHandler, StoreUpgrades: storetypes.StoreUpgrades{ - Added: []string{group.StoreKey, globalfeetypes.StoreKey}, + Added: []string{group.StoreKey, globalfeetypes.StoreKey, consensusparamtypes.StoreKey}, }, } From a45e6cb3c3168bacff49a5c0c8edda6a0692591c Mon Sep 17 00:00:00 2001 From: colmazia Date: Wed, 4 Oct 2023 14:30:37 +0700 Subject: [PATCH 3/8] add crisis store in upgrade --- app/upgrades/v2_6/constants.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/upgrades/v2_6/constants.go b/app/upgrades/v2_6/constants.go index 08421a651..9a5da3d81 100644 --- a/app/upgrades/v2_6/constants.go +++ b/app/upgrades/v2_6/constants.go @@ -7,6 +7,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/authz" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" consensusparamtypes "github.com/cosmos/cosmos-sdk/x/consensus/types" + crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types" distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" "github.com/cosmos/cosmos-sdk/x/feegrant" govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" @@ -25,7 +26,7 @@ var Upgrade = upgrades.Upgrade{ UpgradeName: UpgradeName, CreateUpgradeHandler: CreateUpgradeHandler, StoreUpgrades: storetypes.StoreUpgrades{ - Added: []string{group.StoreKey, globalfeetypes.StoreKey, consensusparamtypes.StoreKey}, + Added: []string{group.StoreKey, globalfeetypes.StoreKey, consensusparamtypes.StoreKey, crisistypes.StoreKey}, }, } From 8fc14e9b9e5bec4d0b4013b2bc1ef5527af6537e Mon Sep 17 00:00:00 2001 From: colmazia Date: Wed, 4 Oct 2023 14:51:16 +0700 Subject: [PATCH 4/8] add bank migration 3 to 4 --- x/bank/module.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/x/bank/module.go b/x/bank/module.go index acba565ce..3807326ef 100644 --- a/x/bank/module.go +++ b/x/bank/module.go @@ -63,4 +63,8 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { if err := cfg.RegisterMigration(types.ModuleName, 2, m.Migrate2to3); err != nil { panic(fmt.Sprintf("failed to migrate x/bank from version 2 to 3: %v", err)) } + + if err := cfg.RegisterMigration(types.ModuleName, 3, m.Migrate3to4); err != nil { + panic(fmt.Sprintf("failed to migrate x/bank from version 3 to 4: %v", err)) + } } From ceae46d20f2742d22d1a7f133bd3e68f10b8109e Mon Sep 17 00:00:00 2001 From: colmazia Date: Wed, 4 Oct 2023 16:25:31 +0700 Subject: [PATCH 5/8] add param subspace --- app/upgrades/v2_6/upgrades.go | 50 +++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/app/upgrades/v2_6/upgrades.go b/app/upgrades/v2_6/upgrades.go index ab4c90aaa..61cd319c8 100644 --- a/app/upgrades/v2_6/upgrades.go +++ b/app/upgrades/v2_6/upgrades.go @@ -1,10 +1,22 @@ package v2_6 import ( + oracletypes "github.com/bandprotocol/chain/v2/x/oracle/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types" + distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" + minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" + paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" + slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" icahosttypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" + ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" "github.com/bandprotocol/chain/v2/app/keepers" "github.com/bandprotocol/chain/v2/app/upgrades" @@ -18,6 +30,44 @@ func CreateUpgradeHandler( keepers *keepers.AppKeepers, ) upgradetypes.UpgradeHandler { return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { + // Set param key table for params module migration + for _, subspace := range keepers.ParamsKeeper.GetSubspaces() { + subspace := subspace + + var keyTable paramstypes.KeyTable + switch subspace.Name() { + case authtypes.ModuleName: + keyTable = authtypes.ParamKeyTable() //nolint:staticcheck + case banktypes.ModuleName: + keyTable = banktypes.ParamKeyTable() //nolint:staticcheck + case stakingtypes.ModuleName: + keyTable = stakingtypes.ParamKeyTable() //nolint:staticcheck + case minttypes.ModuleName: + keyTable = minttypes.ParamKeyTable() //nolint:staticcheck + case distrtypes.ModuleName: + keyTable = distrtypes.ParamKeyTable() //nolint:staticcheck + case slashingtypes.ModuleName: + keyTable = slashingtypes.ParamKeyTable() //nolint:staticcheck + case govtypes.ModuleName: + keyTable = govv1.ParamKeyTable() //nolint:staticcheck + case crisistypes.ModuleName: + keyTable = crisistypes.ParamKeyTable() //nolint:staticcheck + // ibc types + case ibctransfertypes.ModuleName: + keyTable = ibctransfertypes.ParamKeyTable() //nolint:staticcheck + case icahosttypes.SubModuleName: + keyTable = icahosttypes.ParamKeyTable() //nolint:staticcheck + case oracletypes.ModuleName: + keyTable = oracletypes.ParamKeyTable() //nolint:staticcheck + default: + continue + } + + if !subspace.HasKeyTable() { + subspace.WithKeyTable(keyTable) + } + } + hostParams := icahosttypes.Params{ HostEnabled: true, // specifying the whole list instead of adding and removing. Less fragile. From f503e9758c39ef4b2dfb38d07dc165d1ec90f77b Mon Sep 17 00:00:00 2001 From: colmazia Date: Wed, 4 Oct 2023 17:22:43 +0700 Subject: [PATCH 6/8] fix from comments --- x/oracle/keeper/owasm.go | 22 ++++++++++++---------- x/oracle/types/expected_keepers.go | 3 --- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/x/oracle/keeper/owasm.go b/x/oracle/keeper/owasm.go index 0cd595011..a853c1c2b 100644 --- a/x/oracle/keeper/owasm.go +++ b/x/oracle/keeper/owasm.go @@ -21,10 +21,11 @@ func ConvertToOwasmGas(cosmos uint64) uint64 { // GetSpanSize return maximum value between MaxReportDataSize and MaxCallDataSize func (k Keeper) GetSpanSize(ctx sdk.Context) uint64 { - if k.GetParams(ctx).MaxReportDataSize > k.GetParams(ctx).MaxCalldataSize { - return k.GetParams(ctx).MaxReportDataSize + params := k.GetParams(ctx) + if params.MaxReportDataSize > params.MaxCalldataSize { + return params.MaxReportDataSize } - return k.GetParams(ctx).MaxCalldataSize + return params.MaxCalldataSize } // GetRandomValidators returns a pseudorandom subset of active validators. Each validator has @@ -71,12 +72,13 @@ func (k Keeper) PrepareRequest( } askCount := r.GetAskCount() - if askCount > k.GetParams(ctx).MaxAskCount { - return 0, types.WrapMaxError(types.ErrInvalidAskCount, int(askCount), int(k.GetParams(ctx).MaxAskCount)) + params := k.GetParams(ctx) + if askCount > params.MaxAskCount { + return 0, types.WrapMaxError(types.ErrInvalidAskCount, int(askCount), int(params.MaxAskCount)) } // Consume gas for data requests. - ctx.GasMeter().ConsumeGas(askCount*k.GetParams(ctx).PerValidatorRequestGas, "PER_VALIDATOR_REQUEST_FEE") + ctx.GasMeter().ConsumeGas(askCount*params.PerValidatorRequestGas, "PER_VALIDATOR_REQUEST_FEE") // Get a random validator set to perform this request. validators, err := k.GetRandomValidators(ctx, int(askCount), k.GetRequestCount(ctx)+1) @@ -93,8 +95,8 @@ func (k Keeper) PrepareRequest( // Create an execution environment and call Owasm prepare function. env := types.NewPrepareEnv( req, - int64(k.GetParams(ctx).MaxCalldataSize), - int64(k.GetParams(ctx).MaxRawRequestCount), + int64(params.MaxCalldataSize), + int64(params.MaxRawRequestCount), int64(k.GetSpanSize(ctx)), ) script, err := k.GetOracleScript(ctx, req.OracleScriptID) @@ -103,7 +105,7 @@ func (k Keeper) PrepareRequest( } // Consume fee and execute owasm code - ctx.GasMeter().ConsumeGas(k.GetParams(ctx).BaseOwasmGas, "BASE_OWASM_FEE") + ctx.GasMeter().ConsumeGas(params.BaseOwasmGas, "BASE_OWASM_FEE") ctx.GasMeter().ConsumeGas(r.GetPrepareGas(), "OWASM_PREPARE_FEE") code := k.GetFile(script.Filename) output, err := k.owasmVM.Prepare(code, ConvertToOwasmGas(r.GetPrepareGas()), env) @@ -142,7 +144,7 @@ func (k Keeper) PrepareRequest( ctx.EventManager().EmitEvent(event) // Subtract execute fee - ctx.GasMeter().ConsumeGas(k.GetParams(ctx).BaseOwasmGas, "BASE_OWASM_FEE") + ctx.GasMeter().ConsumeGas(params.BaseOwasmGas, "BASE_OWASM_FEE") ctx.GasMeter().ConsumeGas(r.GetExecuteGas(), "OWASM_EXECUTE_FEE") // Emit an event for each of the raw data requests. diff --git a/x/oracle/types/expected_keepers.go b/x/oracle/types/expected_keepers.go index b3e5a10fc..a78335cf9 100644 --- a/x/oracle/types/expected_keepers.go +++ b/x/oracle/types/expected_keepers.go @@ -11,7 +11,6 @@ import ( distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ibcclienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" - ibcchanneltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" ) // AccountKeeper defines the expected account keeper. @@ -47,8 +46,6 @@ type DistrKeeper interface { // ChannelKeeper defines the expected IBC channel keeper type ChannelKeeper interface { - GetChannel(ctx sdk.Context, srcPort, srcChan string) (channel ibcchanneltypes.Channel, found bool) - GetNextSequenceSend(ctx sdk.Context, portID, channelID string) (uint64, bool) SendPacket( ctx sdk.Context, chanCap *capabilitytypes.Capability, From 1f248dfd326998c741687377203c3b760d0cee3c Mon Sep 17 00:00:00 2001 From: Kitipong Sirirueangsakul Date: Tue, 28 Nov 2023 13:53:21 +0700 Subject: [PATCH 7/8] update error string to be lower case --- client/grpc/oracle/proof/proof.go | 2 +- client/grpc/oracle/proof/service.go | 5 ++--- client/grpc/oracle/proof/signature.go | 4 ++-- pkg/gzip/gzip_test.go | 2 +- testing/chain.go | 10 ++++++---- x/bank/keeper/keeper.go | 2 +- x/oracle/keeper/grpc_query.go | 2 +- x/oracle/keeper/owasm_test.go | 3 +++ yoda/event.go | 4 ++-- yoda/executor/executor.go | 12 ++++++------ yoda/executor/multi_test.go | 2 ++ yoda/run.go | 4 ++-- 12 files changed, 29 insertions(+), 23 deletions(-) diff --git a/client/grpc/oracle/proof/proof.go b/client/grpc/oracle/proof/proof.go index 4d2d33f27..66de4e9f4 100644 --- a/client/grpc/oracle/proof/proof.go +++ b/client/grpc/oracle/proof/proof.go @@ -149,7 +149,7 @@ func getProofsByKey( } } default: - return nil, &ics23.ExistenceProof{}, &ics23.ExistenceProof{}, fmt.Errorf("Unknown proof ops found") + return nil, &ics23.ExistenceProof{}, &ics23.ExistenceProof{}, fmt.Errorf("unknown proof ops found") } } diff --git a/client/grpc/oracle/proof/service.go b/client/grpc/oracle/proof/service.go index 758ae8fa6..3dd5f95d4 100644 --- a/client/grpc/oracle/proof/service.go +++ b/client/grpc/oracle/proof/service.go @@ -13,7 +13,6 @@ import ( "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/bandprotocol/chain/v2/x/oracle/types" - oracletypes "github.com/bandprotocol/chain/v2/x/oracle/types" ) // RegisterProofService registers the node gRPC service on the provided gRPC router. @@ -89,7 +88,7 @@ func (s proofServer) Proof(ctx context.Context, req *QueryProofRequest) (*QueryP } // Unmarshal the value into a Result object - var rs oracletypes.Result + var rs types.Result types.ModuleCdc.MustUnmarshal(value, &rs) // Create an OracleDataProof object with the relevant information @@ -195,7 +194,7 @@ func (s proofServer) MultiProof(ctx context.Context, req *QueryMultiProofRequest } // Unmarshal the value into a Result object - var rs oracletypes.Result + var rs types.Result types.ModuleCdc.MustUnmarshal(value, &rs) // Create an OracleDataProof object with the relevant information diff --git a/client/grpc/oracle/proof/signature.go b/client/grpc/oracle/proof/signature.go index 32d925283..cb8b85ab3 100644 --- a/client/grpc/oracle/proof/signature.go +++ b/client/grpc/oracle/proof/signature.go @@ -44,7 +44,7 @@ func recoverETHAddress(msg, sig, signer []byte) ([]byte, uint8, error) { return crypto.PubkeyToAddress(*pubuc).Bytes(), 27 + i, nil } } - return nil, 0, fmt.Errorf("No match address found") + return nil, 0, fmt.Errorf("no match address found") } func GetPrefix(t tmproto.SignedMsgType, height int64, round int64) ([]byte, error) { @@ -126,7 +126,7 @@ func GetSignaturesAndPrefix(info *types.SignedHeader) ([]TMSignature, CommonEnco } } if len(addrs) == 0 { - return nil, CommonEncodedVotePart{}, fmt.Errorf("No valid precommit") + return nil, CommonEncodedVotePart{}, fmt.Errorf("no valid precommit") } signatures := make([]TMSignature, len(addrs)) diff --git a/pkg/gzip/gzip_test.go b/pkg/gzip/gzip_test.go index c3725a777..c7890a37d 100644 --- a/pkg/gzip/gzip_test.go +++ b/pkg/gzip/gzip_test.go @@ -22,7 +22,7 @@ func TestUncompress(t *testing.T) { require.NoError(t, err) require.Equal(t, file1, accFile) - accFile, err = gzip.Uncompress(gzipFile, 2) + _, err = gzip.Uncompress(gzipFile, 2) require.Error(t, err) _, err = gzip.Uncompress(file1, 999) diff --git a/testing/chain.go b/testing/chain.go index 78cdd9d00..3018238c5 100644 --- a/testing/chain.go +++ b/testing/chain.go @@ -28,7 +28,6 @@ import ( clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" commitmenttypes "github.com/cosmos/ibc-go/v7/modules/core/23-commitment/types" ibchost "github.com/cosmos/ibc-go/v7/modules/core/24-host" - "github.com/cosmos/ibc-go/v7/modules/core/exported" ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported" ibctmtypes "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint" "github.com/cosmos/ibc-go/v7/testing/mock" @@ -325,7 +324,7 @@ func (chain *TestChain) SendReport( // GetClientState retrieves the client state for the provided clientID. The client is // expected to exist otherwise testing will fail. -func (chain *TestChain) GetClientState(clientID string) exported.ClientState { +func (chain *TestChain) GetClientState(clientID string) ibcexported.ClientState { clientState, found := chain.App.GetIBCKeeper().ClientKeeper.GetClientState(chain.GetContext(), clientID) require.True(chain.t, found) @@ -334,7 +333,10 @@ func (chain *TestChain) GetClientState(clientID string) exported.ClientState { // GetConsensusState retrieves the consensus state for the provided clientID and height. // It will return a success boolean depending on if consensus state exists or not. -func (chain *TestChain) GetConsensusState(clientID string, height exported.Height) (exported.ConsensusState, bool) { +func (chain *TestChain) GetConsensusState( + clientID string, + height ibcexported.Height, +) (ibcexported.ConsensusState, bool) { return chain.App.GetIBCKeeper().ClientKeeper.GetClientConsensusState(chain.GetContext(), clientID, height) } @@ -357,7 +359,7 @@ func (chain *TestChain) GetValsAtHeight(height int64) (*tmtypes.ValidatorSet, bo // GetAcknowledgement retrieves an acknowledgement for the provided packet. If the // acknowledgement does not exist then testing will fail. -func (chain *TestChain) GetAcknowledgement(packet exported.PacketI) []byte { +func (chain *TestChain) GetAcknowledgement(packet ibcexported.PacketI) []byte { ack, found := chain.App.GetIBCKeeper().ChannelKeeper.GetPacketAcknowledgement( chain.GetContext(), packet.GetDestPort(), diff --git a/x/bank/keeper/keeper.go b/x/bank/keeper/keeper.go index 286923d9d..f4a841091 100644 --- a/x/bank/keeper/keeper.go +++ b/x/bank/keeper/keeper.go @@ -42,7 +42,7 @@ func (k *WrappedBankKeeper) SetDistrKeeper(dk types.DistributionKeeper) { // Logger returns a module-specific logger. func (k WrappedBankKeeper) Logger(ctx sdk.Context) log.Logger { - return ctx.Logger().With("module", fmt.Sprint("x/wrappedbank")) + return ctx.Logger().With("module", "x/wrappedbank") } // BurnCoins moves the specified amount of coins from the given module name to diff --git a/x/oracle/keeper/grpc_query.go b/x/oracle/keeper/grpc_query.go index 6eb8a6ef2..b8344c312 100644 --- a/x/oracle/keeper/grpc_query.go +++ b/x/oracle/keeper/grpc_query.go @@ -341,7 +341,7 @@ func (k Querier) RequestVerification( // Provided signature should be valid, which means this query request should be signed by the provided reporter pk, err := hex.DecodeString(req.Reporter) if err != nil || len(pk) != secp256k1.PubKeySize { - return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("unable to get reporter's public key")) + return nil, status.Error(codes.InvalidArgument, "unable to get reporter's public key") } reporterPubKey := secp256k1.PubKey(pk[:]) diff --git a/x/oracle/keeper/owasm_test.go b/x/oracle/keeper/owasm_test.go index 94c43d877..415dcf2b6 100644 --- a/x/oracle/keeper/owasm_test.go +++ b/x/oracle/keeper/owasm_test.go @@ -125,6 +125,7 @@ func TestPrepareRequestSuccessBasic(t *testing.T) { sdk.WrapSDKContext(ctx), authtypes.NewQueryAllBalancesRequest(testapp.FeePayer.Address, &query.PageRequest{}), ) + require.NoError(t, err) feePayerBalances := balancesRes.Balances // OracleScript#1: Prepare asks for DS#1,2,3 with ExtID#1,2,3 and calldata "beeb" @@ -974,6 +975,7 @@ func TestCollectFeeBasicSuccess(t *testing.T) { sdk.WrapSDKContext(ctx), authtypes.NewQueryAllBalancesRequest(testapp.FeePayer.Address, &query.PageRequest{}), ) + require.NoError(t, err) feePayerBalances := balancesRes.Balances feePayerBalances[0].Amount = feePayerBalances[0].Amount.Sub(sdk.NewInt(3000000)) @@ -1006,6 +1008,7 @@ func TestCollectFeeBasicSuccessWithOtherAskCount(t *testing.T) { sdk.WrapSDKContext(ctx), authtypes.NewQueryAllBalancesRequest(testapp.FeePayer.Address, &query.PageRequest{}), ) + require.NoError(t, err) feePayerBalances := balancesRes.Balances feePayerBalances[0].Amount = feePayerBalances[0].Amount.Sub(sdk.NewInt(12000000)) diff --git a/yoda/event.go b/yoda/event.go index 9c14b4bff..7e8ac35e8 100644 --- a/yoda/event.go +++ b/yoda/event.go @@ -35,10 +35,10 @@ func GetEventValues(log sdk.ABCIMessageLog, evType string, evKey string) (res [] func GetEventValue(log sdk.ABCIMessageLog, evType string, evKey string) (string, error) { values := GetEventValues(log, evType, evKey) if len(values) == 0 { - return "", fmt.Errorf("Cannot find event with type: %s, key: %s", evType, evKey) + return "", fmt.Errorf("cannot find event with type: %s, key: %s", evType, evKey) } if len(values) > 1 { - return "", fmt.Errorf("Found more than one event with type: %s, key: %s", evType, evKey) + return "", fmt.Errorf("found more than one event with type: %s, key: %s", evType, evKey) } return values[0], nil } diff --git a/yoda/executor/executor.go b/yoda/executor/executor.go index 86251e5c3..8e97e1dc9 100644 --- a/yoda/executor/executor.go +++ b/yoda/executor/executor.go @@ -41,9 +41,9 @@ func NewExecutor(executor string) (exec Executor, err error) { case "rest": exec = NewRestExec(base, timeout) case "docker": - return nil, fmt.Errorf("Docker executor is currently not supported") + return nil, fmt.Errorf("docker executor is currently not supported") default: - return nil, fmt.Errorf("Invalid executor name: %s, base: %s", name, base) + return nil, fmt.Errorf("invalid executor name: %s, base: %s", name, base) } // TODO: Remove hardcode in test execution @@ -72,17 +72,17 @@ func NewExecutor(executor string) (exec Executor, err error) { func parseExecutor(executorStr string) (name string, base string, timeout time.Duration, err error) { executor := strings.SplitN(executorStr, ":", 2) if len(executor) != 2 { - return "", "", 0, fmt.Errorf("Invalid executor, cannot parse executor: %s", executorStr) + return "", "", 0, fmt.Errorf("invalid executor, cannot parse executor: %s", executorStr) } u, err := url.Parse(executor[1]) if err != nil { - return "", "", 0, fmt.Errorf("Invalid url, cannot parse %s to url with error: %s", executor[1], err.Error()) + return "", "", 0, fmt.Errorf("invalid url, cannot parse %s to url with error: %s", executor[1], err.Error()) } query := u.Query() timeoutStr := query.Get(flagQueryTimeout) if timeoutStr == "" { - return "", "", 0, fmt.Errorf("Invalid timeout, executor requires query timeout") + return "", "", 0, fmt.Errorf("invalid timeout, executor requires query timeout") } // Remove timeout from query because we need to return `base` query.Del(flagQueryTimeout) @@ -90,7 +90,7 @@ func parseExecutor(executorStr string) (name string, base string, timeout time.D timeout, err = time.ParseDuration(timeoutStr) if err != nil { - return "", "", 0, fmt.Errorf("Invalid timeout, cannot parse duration with error: %s", err.Error()) + return "", "", 0, fmt.Errorf("invalid timeout, cannot parse duration with error: %s", err.Error()) } return executor[0], u.String(), timeout, nil } diff --git a/yoda/executor/multi_test.go b/yoda/executor/multi_test.go index ed77616f7..9a3138324 100644 --- a/yoda/executor/multi_test.go +++ b/yoda/executor/multi_test.go @@ -80,6 +80,7 @@ func TestMultiExecOneWorking(t *testing.T) { exec2 := newMockExec([]byte("output"), 0, nil) exec3 := newMockExec(nil, 0, errors.New("error3")) exec, err := NewMultiExec([]Executor{exec1, exec2, exec3}, "round-robin") + require.NoError(t, err) result, err := exec.Exec(nil, "", nil) require.NoError(t, err) require.Equal(t, ExecResult{Output: []byte("output"), Code: 0}, result) @@ -96,6 +97,7 @@ func TestMultiExecAllErrors(t *testing.T) { exec2 := newMockExec(nil, 0, errors.New("error2")) exec3 := newMockExec(nil, 0, errors.New("error3")) exec, err := NewMultiExec([]Executor{exec1, exec2, exec3}, "round-robin") + require.NoError(t, err) _, err = exec.Exec(nil, "", nil) require.EqualError(t, err, "MultiError: error1, error2, error3") _, err = exec.Exec(nil, "", nil) diff --git a/yoda/run.go b/yoda/run.go index cdf8f5133..e21d52f49 100644 --- a/yoda/run.go +++ b/yoda/run.go @@ -106,14 +106,14 @@ func runCmd(c *Context) *cobra.Command { Args: cobra.ExactArgs(0), RunE: func(cmd *cobra.Command, args []string) error { if cfg.ChainID == "" { - return errors.New("Chain ID must not be empty") + return errors.New("chain ID must not be empty") } keys, err := kb.List() if err != nil { return err } if len(keys) == 0 { - return errors.New("No key available") + return errors.New("no key available") } c.keys = keys c.validator, err = sdk.ValAddressFromBech32(cfg.Validator) From 61be9bf6b5244850634379d97b0b2e09c458c9ec Mon Sep 17 00:00:00 2001 From: Kitipong Sirirueangsakul Date: Tue, 28 Nov 2023 14:36:16 +0700 Subject: [PATCH 8/8] fix test --- yoda/executor/executor_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/yoda/executor/executor_test.go b/yoda/executor/executor_test.go index 44672f74e..7d37e832b 100644 --- a/yoda/executor/executor_test.go +++ b/yoda/executor/executor_test.go @@ -29,15 +29,15 @@ func TestParseExecutor(t *testing.T) { func TestParseExecutorWithoutRawQuery(t *testing.T) { _, _, _, err := parseExecutor("beeb:www.beebprotocol.com") - require.EqualError(t, err, "Invalid timeout, executor requires query timeout") + require.EqualError(t, err, "invalid timeout, executor requires query timeout") } func TestParseExecutorInvalidExecutorError(t *testing.T) { _, _, _, err := parseExecutor("beeb") - require.EqualError(t, err, "Invalid executor, cannot parse executor: beeb") + require.EqualError(t, err, "invalid executor, cannot parse executor: beeb") } func TestParseExecutorInvalidTimeoutError(t *testing.T) { _, _, _, err := parseExecutor("beeb:www.beebprotocol.com?timeout=beeb") - require.EqualError(t, err, "Invalid timeout, cannot parse duration with error: time: invalid duration \"beeb\"") + require.EqualError(t, err, "invalid timeout, cannot parse duration with error: time: invalid duration \"beeb\"") }