ci: improve error checking (errcheck linter) (#11195)
## Description Implements part of #7258 Check some of currently unchecked errors. - [x] baseapp - [x] client - [x] codec - [x] crypto - [x] server - [x] simapp - [ ] snapshots - [ ] store - [x] testutil - [ ] types - [ ] modules --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable)
This commit is contained in:
parent
fed09c593a
commit
1fe59eb22a
|
@ -64,7 +64,9 @@ func (ps *paramStore) Set(_ sdk.Context, key []byte, value interface{}) {
|
|||
panic(err)
|
||||
}
|
||||
|
||||
ps.db.Set(key, bz)
|
||||
if err := ps.db.Set(key, bz); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (ps *paramStore) Has(_ sdk.Context, key []byte) bool {
|
||||
|
@ -183,7 +185,7 @@ func setupBaseAppWithSnapshots(t *testing.T, blocks uint, blockTxs int, options
|
|||
snapshotStore, err := snapshots.NewStore(dbm.NewMemDB(), snapshotDir)
|
||||
require.NoError(t, err)
|
||||
teardown := func() {
|
||||
os.RemoveAll(snapshotDir)
|
||||
_ = os.RemoveAll(snapshotDir)
|
||||
}
|
||||
|
||||
app := setupBaseApp(t, append(options,
|
||||
|
@ -287,7 +289,8 @@ func TestConsensusParamsNotNil(t *testing.T) {
|
|||
app.EndBlock(abci.RequestEndBlock{Height: header.Height})
|
||||
app.CheckTx(abci.RequestCheckTx{})
|
||||
app.DeliverTx(abci.RequestDeliverTx{})
|
||||
app.Simulate([]byte{})
|
||||
_, _, err := app.Simulate([]byte{})
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
// Test that we can make commits and then reload old versions.
|
||||
|
|
|
@ -61,7 +61,9 @@ func (app *BaseApp) RegisterGRPCServer(server gogogrpc.Server) {
|
|||
grpcCtx = context.WithValue(grpcCtx, sdk.SdkContextKey, sdkCtx)
|
||||
|
||||
md = metadata.Pairs(grpctypes.GRPCBlockHeightHeader, strconv.FormatInt(height, 10))
|
||||
grpc.SetHeader(grpcCtx, md)
|
||||
if err = grpc.SetHeader(grpcCtx, md); err != nil {
|
||||
app.logger.Error("failed to set gRPC header", "err", err)
|
||||
}
|
||||
|
||||
return handler(grpcCtx, req)
|
||||
}
|
||||
|
|
|
@ -3,19 +3,18 @@ package config_test
|
|||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
"io"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/config"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking/client/cli"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -32,9 +31,9 @@ func initClientContext(t *testing.T, envVar string) (client.Context, func()) {
|
|||
WithViper("").
|
||||
WithCodec(codec.NewProtoCodec(codectypes.NewInterfaceRegistry()))
|
||||
|
||||
clientCtx.Viper.BindEnv(nodeEnv)
|
||||
require.NoError(t, clientCtx.Viper.BindEnv(nodeEnv))
|
||||
if envVar != "" {
|
||||
os.Setenv(nodeEnv, envVar)
|
||||
require.NoError(t, os.Setenv(nodeEnv, envVar))
|
||||
}
|
||||
|
||||
clientCtx, err := config.ReadFromClientConfig(clientCtx)
|
||||
|
@ -46,7 +45,7 @@ func initClientContext(t *testing.T, envVar string) (client.Context, func()) {
|
|||
func TestConfigCmd(t *testing.T) {
|
||||
clientCtx, cleanup := initClientContext(t, testNode1)
|
||||
defer func() {
|
||||
os.Unsetenv(nodeEnv)
|
||||
_ = os.Unsetenv(nodeEnv)
|
||||
cleanup()
|
||||
}()
|
||||
|
||||
|
@ -60,7 +59,7 @@ func TestConfigCmd(t *testing.T) {
|
|||
b := bytes.NewBufferString("")
|
||||
cmd.SetOut(b)
|
||||
cmd.SetArgs([]string{"node"})
|
||||
cmd.Execute()
|
||||
require.NoError(t, cmd.Execute())
|
||||
out, err := io.ReadAll(b)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, string(out), testNode1+"\n")
|
||||
|
@ -89,7 +88,7 @@ func TestConfigCmdEnvFlag(t *testing.T) {
|
|||
clientCtx, cleanup := initClientContext(t, tc.envVar)
|
||||
defer func() {
|
||||
if tc.envVar != "" {
|
||||
os.Unsetenv(nodeEnv)
|
||||
_ = os.Unsetenv(nodeEnv)
|
||||
}
|
||||
cleanup()
|
||||
}()
|
||||
|
|
|
@ -95,7 +95,9 @@ func AddQueryFlagsToCmd(cmd *cobra.Command) {
|
|||
cmd.Flags().Int64(FlagHeight, 0, "Use a specific height to query state at (this can error if the node is pruning state)")
|
||||
cmd.Flags().StringP(tmcli.OutputFlag, "o", "text", "Output format (text|json)")
|
||||
|
||||
cmd.MarkFlagRequired(FlagChainID)
|
||||
// some base commands does not require chainID e.g `simd testnet` while subcommands do
|
||||
// hence the flag should not be required for those commands
|
||||
_ = cmd.MarkFlagRequired(FlagChainID)
|
||||
}
|
||||
|
||||
// AddTxFlagsToCmd adds common flags to a module tx command.
|
||||
|
|
|
@ -207,5 +207,5 @@ func RegisterTendermintService(
|
|||
// RegisterGRPCGatewayRoutes mounts the tendermint service's GRPC-gateway routes on the
|
||||
// given Mux.
|
||||
func RegisterGRPCGatewayRoutes(clientConn gogogrpc.ClientConn, mux *runtime.ServeMux) {
|
||||
RegisterServiceHandlerClient(context.Background(), mux, NewServiceClient(clientConn))
|
||||
_ = RegisterServiceHandlerClient(context.Background(), mux, NewServiceClient(clientConn))
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ func GetPassword(prompt string, buf *bufio.Reader) (pass string, err error) {
|
|||
// If the input is not recognized, it returns false and a nil error.
|
||||
func GetConfirmation(prompt string, r *bufio.Reader, w io.Writer) (bool, error) {
|
||||
if inputIsTty() {
|
||||
fmt.Fprintf(w, "%s [y/N]: ", prompt)
|
||||
_, _ = fmt.Fprintf(w, "%s [y/N]: ", prompt)
|
||||
}
|
||||
|
||||
response, err := readLineFromBuf(r)
|
||||
|
|
|
@ -292,14 +292,23 @@ func printCreate(cmd *cobra.Command, k *keyring.Record, showMnemonic bool, mnemo
|
|||
switch outputFormat {
|
||||
case OutputFormatText:
|
||||
cmd.PrintErrln()
|
||||
printKeyringRecord(cmd.OutOrStdout(), k, keyring.MkAccKeyOutput, outputFormat)
|
||||
if err := printKeyringRecord(cmd.OutOrStdout(), k, keyring.MkAccKeyOutput, outputFormat); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// print mnemonic unless requested not to.
|
||||
if showMnemonic {
|
||||
fmt.Fprintln(cmd.ErrOrStderr(), "\n**Important** write this mnemonic phrase in a safe place.")
|
||||
fmt.Fprintln(cmd.ErrOrStderr(), "It is the only way to recover your account if you ever forget your password.")
|
||||
fmt.Fprintln(cmd.ErrOrStderr(), "")
|
||||
fmt.Fprintln(cmd.ErrOrStderr(), mnemonic)
|
||||
if _, err := fmt.Fprintf(
|
||||
cmd.ErrOrStderr(),
|
||||
`
|
||||
*Important** write this mnemonic phrase in a safe place.
|
||||
It is the only way to recover your account if you ever forget your password.
|
||||
|
||||
%s
|
||||
|
||||
`, mnemonic); err != nil {
|
||||
return fmt.Errorf("failed to print mnemonic: %v", err)
|
||||
}
|
||||
}
|
||||
case OutputFormatJSON:
|
||||
out, err := keyring.MkAccKeyOutput(k)
|
||||
|
|
|
@ -89,9 +89,7 @@ func Test_runExportCmd(t *testing.T) {
|
|||
// create a key
|
||||
kb, err := keyring.New(sdk.KeyringServiceName(), tc.keyringBackend, kbHome, bufio.NewReader(mockInBuf), cdc)
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
kb.Delete("keyname1") // nolint:errcheck
|
||||
})
|
||||
t.Cleanup(cleanupKeys(t, kb, "keyname1"))
|
||||
|
||||
path := sdk.GetConfig().GetFullBIP44Path()
|
||||
_, err = kb.NewAccount("keyname1", testdata.TestMnemonic, "", path, hd.Secp256k1)
|
||||
|
|
|
@ -91,12 +91,9 @@ HbP+c6JmeJy9JXe2rbbF1QtCX1gLqGcDQPBXiCtFvP7/8wTZtVOPj8vREzhZ9ElO
|
|||
WithCodec(cdc)
|
||||
ctx := context.WithValue(context.Background(), client.ClientContextKey, &clientCtx)
|
||||
|
||||
t.Cleanup(func() {
|
||||
kb.Delete("keyname1") // nolint:errcheck
|
||||
})
|
||||
t.Cleanup(cleanupKeys(t, kb, "keyname1"))
|
||||
|
||||
keyfile := filepath.Join(kbHome, "key.asc")
|
||||
|
||||
require.NoError(t, os.WriteFile(keyfile, []byte(armoredKey), 0644))
|
||||
|
||||
defer func() {
|
||||
|
|
|
@ -34,8 +34,7 @@ func runListCmd(cmd *cobra.Command, _ []string) error {
|
|||
}
|
||||
|
||||
if ok, _ := cmd.Flags().GetBool(flagListNames); !ok {
|
||||
printKeyringRecords(cmd.OutOrStdout(), records, clientCtx.OutputFormat)
|
||||
return nil
|
||||
return printKeyringRecords(cmd.OutOrStdout(), records, clientCtx.OutputFormat)
|
||||
}
|
||||
|
||||
for _, k := range records {
|
||||
|
|
|
@ -5,7 +5,6 @@ import (
|
|||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
|
@ -18,6 +17,16 @@ import (
|
|||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
func cleanupKeys(t *testing.T, kb keyring.Keyring, keys ...string) func() {
|
||||
return func() {
|
||||
for _, k := range keys {
|
||||
if err := kb.Delete(k); err != nil {
|
||||
t.Log("can't delete KB key ", k, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func Test_runListCmd(t *testing.T) {
|
||||
cmd := ListKeysCmd()
|
||||
cmd.Flags().AddFlagSet(Commands("home").PersistentFlags())
|
||||
|
@ -37,14 +46,7 @@ func Test_runListCmd(t *testing.T) {
|
|||
_, err = kb.NewAccount("something", testdata.TestMnemonic, "", path, hd.Secp256k1)
|
||||
require.NoError(t, err)
|
||||
|
||||
t.Cleanup(func() {
|
||||
kb.Delete("something") // nolint:errcheck
|
||||
})
|
||||
|
||||
type args struct {
|
||||
cmd *cobra.Command
|
||||
args []string
|
||||
}
|
||||
t.Cleanup(cleanupKeys(t, kb, "something"))
|
||||
|
||||
testData := []struct {
|
||||
name string
|
||||
|
|
|
@ -128,9 +128,14 @@ func runShowCmd(cmd *cobra.Command, args []string) (err error) {
|
|||
if isShowPubKey {
|
||||
out = ko.PubKey
|
||||
}
|
||||
fmt.Fprintln(cmd.OutOrStdout(), out)
|
||||
|
||||
if _, err := fmt.Fprintln(cmd.OutOrStdout(), out); err != nil {
|
||||
return err
|
||||
}
|
||||
default:
|
||||
printKeyringRecord(cmd.OutOrStdout(), k, bechKeyOut, outputFormat)
|
||||
if err := printKeyringRecord(cmd.OutOrStdout(), k, bechKeyOut, outputFormat); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if isShowDevice {
|
||||
|
|
|
@ -72,8 +72,8 @@ func Test_runShowCmd(t *testing.T) {
|
|||
fakeKeyName2 := "runShowCmd_Key2"
|
||||
|
||||
t.Cleanup(func() {
|
||||
kb.Delete("runShowCmd_Key1")
|
||||
kb.Delete("runShowCmd_Key2")
|
||||
cleanupKeys(t, kb, "runShowCmd_Key1")
|
||||
cleanupKeys(t, kb, "runShowCmd_Key2")
|
||||
})
|
||||
|
||||
path := hd.NewFundraiserParams(1, sdk.CoinType, 0).String()
|
||||
|
|
|
@ -17,53 +17,69 @@ const (
|
|||
|
||||
type bechKeyOutFn func(k *cryptokeyring.Record) (cryptokeyring.KeyOutput, error)
|
||||
|
||||
func printKeyringRecord(w io.Writer, k *cryptokeyring.Record, bechKeyOut bechKeyOutFn, output string) {
|
||||
func printKeyringRecord(w io.Writer, k *cryptokeyring.Record, bechKeyOut bechKeyOutFn, output string) error {
|
||||
ko, err := bechKeyOut(k)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
return err
|
||||
}
|
||||
|
||||
switch output {
|
||||
case OutputFormatText:
|
||||
printTextRecords(w, []cryptokeyring.KeyOutput{ko})
|
||||
if err := printTextRecords(w, []cryptokeyring.KeyOutput{ko}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
case OutputFormatJSON:
|
||||
out, err := KeysCdc.MarshalJSON(ko)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Fprintln(w, string(out))
|
||||
if _, err := fmt.Fprintln(w, string(out)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func printKeyringRecords(w io.Writer, records []*cryptokeyring.Record, output string) {
|
||||
func printKeyringRecords(w io.Writer, records []*cryptokeyring.Record, output string) error {
|
||||
kos, err := cryptokeyring.MkAccKeysOutput(records)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
return err
|
||||
}
|
||||
|
||||
switch output {
|
||||
case OutputFormatText:
|
||||
printTextRecords(w, kos)
|
||||
if err := printTextRecords(w, kos); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
case OutputFormatJSON:
|
||||
// TODO https://github.com/cosmos/cosmos-sdk/issues/8046
|
||||
// Replace AminoCdc with Proto JSON
|
||||
out, err := KeysCdc.MarshalJSON(kos)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Fprintf(w, "%s", out)
|
||||
if _, err := fmt.Fprintf(w, "%s", out); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func printTextRecords(w io.Writer, kos []cryptokeyring.KeyOutput) {
|
||||
func printTextRecords(w io.Writer, kos []cryptokeyring.KeyOutput) error {
|
||||
out, err := yaml.Marshal(&kos)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Fprintln(w, string(out))
|
||||
if _, err := fmt.Fprintln(w, string(out)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@ func TestAuxTxBuilder(t *testing.T) {
|
|||
{
|
||||
"GetSignBytes pubkey should not be nil",
|
||||
func() error {
|
||||
b.SetMsgs(msg1)
|
||||
require.NoError(t, b.SetMsgs(msg1))
|
||||
|
||||
_, err := b.GetSignBytes()
|
||||
return err
|
||||
|
@ -70,8 +70,8 @@ func TestAuxTxBuilder(t *testing.T) {
|
|||
{
|
||||
"GetSignBytes invalid sign mode",
|
||||
func() error {
|
||||
b.SetMsgs(msg1)
|
||||
b.SetPubKey(pub1)
|
||||
require.NoError(t, b.SetMsgs(msg1))
|
||||
require.NoError(t, b.SetPubKey(pub1))
|
||||
|
||||
_, err := b.GetSignBytes()
|
||||
return err
|
||||
|
@ -81,13 +81,12 @@ func TestAuxTxBuilder(t *testing.T) {
|
|||
{
|
||||
"GetSignBytes tipper should not be nil (if tip is set)",
|
||||
func() error {
|
||||
b.SetMsgs(msg1)
|
||||
b.SetPubKey(pub1)
|
||||
require.NoError(t, b.SetMsgs(msg1))
|
||||
require.NoError(t, b.SetPubKey(pub1))
|
||||
b.SetTip(&typestx.Tip{})
|
||||
err := b.SetSignMode(signing.SignMode_SIGN_MODE_DIRECT_AUX)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, b.SetSignMode(signing.SignMode_SIGN_MODE_DIRECT_AUX))
|
||||
|
||||
_, err = b.GetSignBytes()
|
||||
_, err := b.GetSignBytes()
|
||||
return err
|
||||
},
|
||||
true, "tipper cannot be empty",
|
||||
|
@ -95,13 +94,12 @@ func TestAuxTxBuilder(t *testing.T) {
|
|||
{
|
||||
"GetSignBytes works for DIRECT_AUX",
|
||||
func() error {
|
||||
b.SetMsgs(msg1)
|
||||
b.SetPubKey(pub1)
|
||||
require.NoError(t, b.SetMsgs(msg1))
|
||||
require.NoError(t, b.SetPubKey(pub1))
|
||||
b.SetTip(tip)
|
||||
err := b.SetSignMode(signing.SignMode_SIGN_MODE_DIRECT_AUX)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, b.SetSignMode(signing.SignMode_SIGN_MODE_DIRECT_AUX))
|
||||
|
||||
_, err = b.GetSignBytes()
|
||||
_, err := b.GetSignBytes()
|
||||
return err
|
||||
},
|
||||
false, "",
|
||||
|
@ -109,13 +107,12 @@ func TestAuxTxBuilder(t *testing.T) {
|
|||
{
|
||||
"GetAuxSignerData address should not be empty",
|
||||
func() error {
|
||||
b.SetMsgs(msg1)
|
||||
b.SetPubKey(pub1)
|
||||
require.NoError(t, b.SetMsgs(msg1))
|
||||
require.NoError(t, b.SetPubKey(pub1))
|
||||
b.SetTip(tip)
|
||||
err := b.SetSignMode(signing.SignMode_SIGN_MODE_DIRECT_AUX)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, b.SetSignMode(signing.SignMode_SIGN_MODE_DIRECT_AUX))
|
||||
|
||||
_, err = b.GetSignBytes()
|
||||
_, err := b.GetSignBytes()
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = b.GetAuxSignerData()
|
||||
|
@ -126,14 +123,13 @@ func TestAuxTxBuilder(t *testing.T) {
|
|||
{
|
||||
"GetAuxSignerData signature should not be empty",
|
||||
func() error {
|
||||
b.SetMsgs(msg1)
|
||||
b.SetPubKey(pub1)
|
||||
require.NoError(t, b.SetMsgs(msg1))
|
||||
require.NoError(t, b.SetPubKey(pub1))
|
||||
b.SetTip(tip)
|
||||
b.SetAddress(addr1.String())
|
||||
err := b.SetSignMode(signing.SignMode_SIGN_MODE_DIRECT_AUX)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, b.SetSignMode(signing.SignMode_SIGN_MODE_DIRECT_AUX))
|
||||
|
||||
_, err = b.GetSignBytes()
|
||||
_, err := b.GetSignBytes()
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = b.GetAuxSignerData()
|
||||
|
@ -149,8 +145,8 @@ func TestAuxTxBuilder(t *testing.T) {
|
|||
b.SetTimeoutHeight(timeoutHeight)
|
||||
b.SetMemo(memo)
|
||||
b.SetChainID(chainID)
|
||||
b.SetMsgs(msg1)
|
||||
b.SetPubKey(pub1)
|
||||
require.NoError(t, b.SetMsgs(msg1))
|
||||
require.NoError(t, b.SetPubKey(pub1))
|
||||
b.SetTip(tip)
|
||||
b.SetAddress(addr1.String())
|
||||
err := b.SetSignMode(signing.SignMode_SIGN_MODE_DIRECT_AUX)
|
||||
|
@ -172,8 +168,8 @@ func TestAuxTxBuilder(t *testing.T) {
|
|||
{
|
||||
"GetSignBytes works for LEGACY_AMINO_JSON",
|
||||
func() error {
|
||||
b.SetMsgs(msg1)
|
||||
b.SetPubKey(pub1)
|
||||
require.NoError(t, b.SetMsgs(msg1))
|
||||
require.NoError(t, b.SetPubKey(pub1))
|
||||
b.SetTip(tip)
|
||||
b.SetAddress(addr1.String())
|
||||
err := b.SetSignMode(signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON)
|
||||
|
@ -192,8 +188,8 @@ func TestAuxTxBuilder(t *testing.T) {
|
|||
b.SetTimeoutHeight(timeoutHeight)
|
||||
b.SetMemo(memo)
|
||||
b.SetChainID(chainID)
|
||||
b.SetMsgs(msg1)
|
||||
b.SetPubKey(pub1)
|
||||
require.NoError(t, b.SetMsgs(msg1))
|
||||
require.NoError(t, b.SetPubKey(pub1))
|
||||
b.SetTip(tip)
|
||||
b.SetAddress(addr1.String())
|
||||
err := b.SetSignMode(signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON)
|
||||
|
|
|
@ -28,7 +28,7 @@ func testInterfaceMarshaling(require *require.Assertions, cdc interfaceMarshaler
|
|||
var animal testdata.Animal
|
||||
if isAminoBin {
|
||||
require.PanicsWithValue("Unmarshal expects a pointer", func() {
|
||||
cdc.unmarshal(bz, animal)
|
||||
_ = cdc.unmarshal(bz, animal)
|
||||
})
|
||||
} else {
|
||||
err = cdc.unmarshal(bz, animal)
|
||||
|
|
|
@ -300,7 +300,7 @@ func TestDerivePrivateKeyForPathDoNotCrash(t *testing.T) {
|
|||
for _, path := range paths {
|
||||
path := path
|
||||
t.Run(path, func(t *testing.T) {
|
||||
hd.DerivePrivateKeyForPath([32]byte{}, [32]byte{}, path)
|
||||
_, _ = hd.DerivePrivateKeyForPath([32]byte{}, [32]byte{}, path)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1077,19 +1077,19 @@ func TestNonConsistentKeyring_SavePubKey(t *testing.T) {
|
|||
priv := ed25519.GenPrivKey()
|
||||
pub := priv.PubKey()
|
||||
|
||||
k, err := kr.SaveOfflineKey(key, pub)
|
||||
require.Nil(t, err)
|
||||
_, err = kr.SaveOfflineKey(key, pub)
|
||||
require.NoError(t, err)
|
||||
|
||||
// broken keyring state test
|
||||
unsafeKr, ok := kr.(keystore)
|
||||
require.True(t, ok)
|
||||
// we lost public key for some reason, but still have an address record
|
||||
unsafeKr.db.Remove(infoKey(key))
|
||||
require.NoError(t, unsafeKr.db.Remove(infoKey(key)))
|
||||
list, err = kr.List()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 0, len(list))
|
||||
|
||||
k, err = kr.SaveOfflineKey(key, pub)
|
||||
k, err := kr.SaveOfflineKey(key, pub)
|
||||
require.Nil(t, err)
|
||||
pubKey, err := k.GetPubKey()
|
||||
require.NoError(t, err)
|
||||
|
|
|
@ -4,11 +4,11 @@ import (
|
|||
"crypto/ecdsa"
|
||||
"crypto/elliptic"
|
||||
"crypto/sha256"
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
"math/big"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/suite"
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
)
|
||||
|
||||
func TestSKSuite(t *testing.T) {
|
||||
|
@ -39,10 +39,11 @@ func (suite *SKSuite) TestMarshal() {
|
|||
const size = 32
|
||||
|
||||
var buffer = make([]byte, size)
|
||||
suite.sk.MarshalTo(buffer)
|
||||
_, err := suite.sk.MarshalTo(buffer)
|
||||
require.NoError(err)
|
||||
|
||||
var sk = new(PrivKey)
|
||||
err := sk.Unmarshal(buffer, secp256r1, size)
|
||||
err = sk.Unmarshal(buffer, secp256r1, size)
|
||||
require.NoError(err)
|
||||
require.True(sk.Equal(&suite.sk.PrivateKey))
|
||||
}
|
||||
|
@ -80,7 +81,7 @@ func (suite *SKSuite) TestSign() {
|
|||
// leave r untouched!
|
||||
high_s := new(big.Int).Mod(new(big.Int).Neg(low_s), elliptic.P256().Params().N)
|
||||
|
||||
require.False(suite.pk.VerifySignature(msg, signatureRaw(r,high_s)))
|
||||
require.False(suite.pk.VerifySignature(msg, signatureRaw(r, high_s)))
|
||||
|
||||
// Valid signature using low_s, but too long
|
||||
sigCpy = make([]byte, len(sig)+2)
|
||||
|
|
|
@ -173,7 +173,7 @@ func TestVerifyMultisignature(t *testing.T) {
|
|||
sig = multisig.NewMultisig(5)
|
||||
|
||||
require.Error(pk.VerifyMultisignature(signBytesFn, sig))
|
||||
multisig.AddSignatureFromPubKey(sig, sigs[0], pubKeys[0], pubKeys)
|
||||
require.NoError(multisig.AddSignatureFromPubKey(sig, sigs[0], pubKeys[0], pubKeys))
|
||||
// Add second signature manually
|
||||
sig.Signatures = append(sig.Signatures, sigs[0])
|
||||
},
|
||||
|
@ -208,8 +208,8 @@ func TestVerifyMultisignature(t *testing.T) {
|
|||
_, sigs := generatePubKeysAndSignatures(2, msg)
|
||||
pk = kmultisig.NewLegacyAminoPubKey(2, pubKeys)
|
||||
sig = multisig.NewMultisig(2)
|
||||
multisig.AddSignatureFromPubKey(sig, sigs[0], pubKeys[0], pubKeys)
|
||||
multisig.AddSignatureFromPubKey(sig, sigs[1], pubKeys[1], pubKeys)
|
||||
require.NoError(multisig.AddSignatureFromPubKey(sig, sigs[0], pubKeys[0], pubKeys))
|
||||
require.NoError(multisig.AddSignatureFromPubKey(sig, sigs[1], pubKeys[1], pubKeys))
|
||||
},
|
||||
false,
|
||||
},
|
||||
|
|
|
@ -111,8 +111,7 @@ func (suite *PKSuite) TestMarshalProto() {
|
|||
require.NoError(cdc.UnmarshalInterface(bz, &pkI))
|
||||
require.True(pkI.Equals(suite.pk))
|
||||
|
||||
cdc.UnmarshalInterface(bz, nil)
|
||||
require.Error(err, "nil should fail")
|
||||
require.Error(cdc.UnmarshalInterface(bz, nil), "nil should fail")
|
||||
}
|
||||
|
||||
func (suite *PKSuite) TestSize() {
|
||||
|
|
|
@ -30,7 +30,7 @@ func checkAminoJSON(t *testing.T, src interface{}, dst interface{}, isNil bool)
|
|||
|
||||
// nolint: govet
|
||||
func ExamplePrintRegisteredTypes() {
|
||||
cdc.PrintTypes(os.Stdout)
|
||||
_ = cdc.PrintTypes(os.Stdout)
|
||||
// | Type | Name | Prefix | Length | Notes |
|
||||
// | ---- | ---- | ------ | ----- | ------ |
|
||||
// | PrivKeyLedgerSecp256k1 | tendermint/PrivKeyLedgerSecp256k1 | 0x10CAB393 | variable | |
|
||||
|
|
|
@ -195,7 +195,9 @@ func (s *GRPCWebTestSuite) makeGrpcRequest(
|
|||
if err != nil {
|
||||
return nil, Trailer{}, nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
defer func() {
|
||||
_ = resp.Body.Close()
|
||||
}()
|
||||
contents, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, Trailer{}, nil, err
|
||||
|
|
|
@ -115,7 +115,9 @@ is performed. Note, when enabled, gRPC will also be automatically enabled.
|
|||
|
||||
// Bind flags to the Context's Viper so the app construction can set
|
||||
// options accordingly.
|
||||
serverCtx.Viper.BindPFlags(cmd.Flags())
|
||||
if err := serverCtx.Viper.BindPFlags(cmd.Flags()); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err := GetPruningOptionsFromFlags(serverCtx.Viper)
|
||||
return err
|
||||
|
@ -246,7 +248,9 @@ func startInProcess(ctx *Context, clientCtx client.Context, appCreator types.App
|
|||
cpuProfileCleanup = func() {
|
||||
ctx.Logger.Info("stopping CPU profiler", "profile", cpuProfile)
|
||||
pprof.StopCPUProfile()
|
||||
f.Close()
|
||||
if err := f.Close(); err != nil {
|
||||
ctx.Logger.Info("failed to close cpu-profile file", "profile", cpuProfile, "err", err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -447,7 +451,9 @@ func startInProcess(ctx *Context, clientCtx client.Context, appCreator types.App
|
|||
if grpcSrv != nil {
|
||||
grpcSrv.Stop()
|
||||
if grpcWebSrv != nil {
|
||||
grpcWebSrv.Close()
|
||||
if err := grpcWebSrv.Close(); err != nil {
|
||||
ctx.Logger.Error("failed to close grpc-web http server: ", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -68,7 +68,9 @@ func NewContext(v *viper.Viper, config *tmcfg.Config, logger tmlog.Logger) *Cont
|
|||
|
||||
func bindFlags(basename string, cmd *cobra.Command, v *viper.Viper) (err error) {
|
||||
defer func() {
|
||||
recover()
|
||||
if r := recover(); r != nil {
|
||||
err = fmt.Errorf("bindFlags failed: %v", r)
|
||||
}
|
||||
}()
|
||||
|
||||
cmd.Flags().VisitAll(func(f *pflag.Flag) {
|
||||
|
@ -121,8 +123,12 @@ func InterceptConfigsPreRunHandler(cmd *cobra.Command, customAppConfigTemplate s
|
|||
basename := path.Base(executableName)
|
||||
|
||||
// Configure the viper instance
|
||||
serverCtx.Viper.BindPFlags(cmd.Flags())
|
||||
serverCtx.Viper.BindPFlags(cmd.PersistentFlags())
|
||||
if err := serverCtx.Viper.BindPFlags(cmd.Flags()); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := serverCtx.Viper.BindPFlags(cmd.PersistentFlags()); err != nil {
|
||||
return err
|
||||
}
|
||||
serverCtx.Viper.SetEnvPrefix(basename)
|
||||
serverCtx.Viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_", "-", "_"))
|
||||
serverCtx.Viper.AutomaticEnv()
|
||||
|
@ -198,14 +204,16 @@ func interceptConfigs(rootViper *viper.Viper, customAppTemplate string, customCo
|
|||
tmcfg.EnsureRoot(rootDir)
|
||||
|
||||
if err = conf.ValidateBasic(); err != nil {
|
||||
return nil, fmt.Errorf("error in config file: %v", err)
|
||||
return nil, fmt.Errorf("error in config file: %w", err)
|
||||
}
|
||||
|
||||
conf.RPC.PprofListenAddress = "localhost:6060"
|
||||
conf.P2P.RecvRate = 5120000
|
||||
conf.P2P.SendRate = 5120000
|
||||
conf.Consensus.TimeoutCommit = 5 * time.Second
|
||||
tmcfg.WriteConfigFile(rootDir, conf)
|
||||
if err := tmcfg.WriteConfigFile(rootDir, conf); err != nil {
|
||||
return nil, fmt.Errorf("error writing config file: %w", err)
|
||||
}
|
||||
|
||||
case err != nil:
|
||||
return nil, err
|
||||
|
|
|
@ -218,9 +218,9 @@ func TestInterceptConfigsPreRunHandlerReadsEnvVars(t *testing.T) {
|
|||
basename = strings.ReplaceAll(basename, ".", "_")
|
||||
// This is added by tendermint
|
||||
envVarName := fmt.Sprintf("%s_RPC_LADDR", strings.ToUpper(basename))
|
||||
os.Setenv(envVarName, testAddr)
|
||||
require.NoError(t, os.Setenv(envVarName, testAddr))
|
||||
t.Cleanup(func() {
|
||||
os.Unsetenv(envVarName)
|
||||
require.NoError(t, os.Unsetenv(envVarName))
|
||||
})
|
||||
|
||||
cmd.PreRunE = preRunETestImpl
|
||||
|
@ -305,7 +305,7 @@ func (v precedenceCommon) setAll(t *testing.T, setFlag *string, setEnvVar *strin
|
|||
}
|
||||
|
||||
if setEnvVar != nil {
|
||||
os.Setenv(v.envVarName, *setEnvVar)
|
||||
require.NoError(t, os.Setenv(v.envVarName, *setEnvVar))
|
||||
}
|
||||
|
||||
if setConfigFile != nil {
|
||||
|
|
|
@ -2,6 +2,7 @@ package simapp
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
||||
|
@ -125,8 +126,16 @@ func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []
|
|||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
app.DistrKeeper.Hooks().BeforeDelegationCreated(ctx, delAddr, valAddr)
|
||||
app.DistrKeeper.Hooks().AfterDelegationModified(ctx, delAddr, valAddr)
|
||||
|
||||
if err := app.DistrKeeper.Hooks().BeforeDelegationCreated(ctx, delAddr, valAddr); err != nil {
|
||||
// never called as BeforeDelegationCreated always returns nil
|
||||
panic(fmt.Errorf("error while incrementing period: %w", err))
|
||||
}
|
||||
|
||||
if err := app.DistrKeeper.Hooks().AfterDelegationModified(ctx, delAddr, valAddr); err != nil {
|
||||
// never called as AfterDelegationModified always returns nil
|
||||
panic(fmt.Errorf("error while creating a new delegation period record: %w", err))
|
||||
}
|
||||
}
|
||||
|
||||
// reset context height
|
||||
|
@ -174,7 +183,10 @@ func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []
|
|||
counter++
|
||||
}
|
||||
|
||||
iter.Close()
|
||||
if err := iter.Close(); err != nil {
|
||||
app.Logger().Error("error while closing the key-value store reverse prefix iterator: ", err)
|
||||
return
|
||||
}
|
||||
|
||||
_, err := app.StakingKeeper.ApplyAndReturnValidatorSetUpdates(ctx)
|
||||
if err != nil {
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
||||
|
||||
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
|
||||
|
@ -25,11 +26,8 @@ func BenchmarkFullAppSimulation(b *testing.B) {
|
|||
}
|
||||
|
||||
defer func() {
|
||||
db.Close()
|
||||
err = os.RemoveAll(dir)
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
require.NoError(b, db.Close())
|
||||
require.NoError(b, os.RemoveAll(dir))
|
||||
}()
|
||||
|
||||
app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, MakeTestEncodingConfig(), EmptyAppOptions{}, interBlockCacheOpt())
|
||||
|
@ -75,11 +73,8 @@ func BenchmarkInvariants(b *testing.B) {
|
|||
config.AllInvariants = false
|
||||
|
||||
defer func() {
|
||||
db.Close()
|
||||
err = os.RemoveAll(dir)
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
require.NoError(b, db.Close())
|
||||
require.NoError(b, os.RemoveAll(dir))
|
||||
}()
|
||||
|
||||
app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, MakeTestEncodingConfig(), EmptyAppOptions{}, interBlockCacheOpt())
|
||||
|
|
|
@ -66,7 +66,7 @@ func TestFullAppSimulation(t *testing.T) {
|
|||
require.NoError(t, err, "simulation setup failed")
|
||||
|
||||
defer func() {
|
||||
db.Close()
|
||||
require.NoError(t, db.Close())
|
||||
require.NoError(t, os.RemoveAll(dir))
|
||||
}()
|
||||
|
||||
|
@ -104,7 +104,7 @@ func TestAppImportExport(t *testing.T) {
|
|||
require.NoError(t, err, "simulation setup failed")
|
||||
|
||||
defer func() {
|
||||
db.Close()
|
||||
require.NoError(t, db.Close())
|
||||
require.NoError(t, os.RemoveAll(dir))
|
||||
}()
|
||||
|
||||
|
@ -144,7 +144,7 @@ func TestAppImportExport(t *testing.T) {
|
|||
require.NoError(t, err, "simulation setup failed")
|
||||
|
||||
defer func() {
|
||||
newDB.Close()
|
||||
require.NoError(t, newDB.Close())
|
||||
require.NoError(t, os.RemoveAll(newDir))
|
||||
}()
|
||||
|
||||
|
@ -211,7 +211,7 @@ func TestAppSimulationAfterImport(t *testing.T) {
|
|||
require.NoError(t, err, "simulation setup failed")
|
||||
|
||||
defer func() {
|
||||
db.Close()
|
||||
require.NoError(t, db.Close())
|
||||
require.NoError(t, os.RemoveAll(dir))
|
||||
}()
|
||||
|
||||
|
@ -256,7 +256,7 @@ func TestAppSimulationAfterImport(t *testing.T) {
|
|||
require.NoError(t, err, "simulation setup failed")
|
||||
|
||||
defer func() {
|
||||
newDB.Close()
|
||||
require.NoError(t, newDB.Close())
|
||||
require.NoError(t, os.RemoveAll(newDir))
|
||||
}()
|
||||
|
||||
|
|
|
@ -519,9 +519,13 @@ func startTestnet(cmd *cobra.Command, args startArgs) error {
|
|||
return err
|
||||
}
|
||||
|
||||
testnet.WaitForHeight(1)
|
||||
if _, err := testnet.WaitForHeight(1); err != nil {
|
||||
return err
|
||||
}
|
||||
cmd.Println("press the Enter Key to terminate")
|
||||
fmt.Scanln() // wait for Enter Key
|
||||
if _, err := fmt.Scanln(); err != nil { // wait for Enter Key
|
||||
return err
|
||||
}
|
||||
testnet.Cleanup()
|
||||
|
||||
return nil
|
||||
|
|
|
@ -61,7 +61,7 @@ func (w *ChunkWriter) CloseWithError(err error) {
|
|||
w.closed = true
|
||||
close(w.ch)
|
||||
if w.pipe != nil {
|
||||
w.pipe.CloseWithError(err)
|
||||
_ = w.pipe.CloseWithError(err) // CloseWithError always returns nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -132,7 +132,7 @@ func TestChunkReader(t *testing.T) {
|
|||
pr, pw := io.Pipe()
|
||||
pch := make(chan io.ReadCloser, 1)
|
||||
pch <- pr
|
||||
pw.CloseWithError(theErr)
|
||||
_ = pw.CloseWithError(theErr)
|
||||
|
||||
chunkReader = snapshots.NewChunkReader(pch)
|
||||
buf = make([]byte, 4)
|
||||
|
|
|
@ -17,7 +17,6 @@ import (
|
|||
|
||||
"github.com/cosmos/cosmos-sdk/snapshots"
|
||||
"github.com/cosmos/cosmos-sdk/snapshots/types"
|
||||
snapshottypes "github.com/cosmos/cosmos-sdk/snapshots/types"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
)
|
||||
|
||||
|
@ -74,12 +73,12 @@ func snapshotItems(items [][]byte) [][]byte {
|
|||
zWriter, _ := zlib.NewWriterLevel(bufWriter, 7)
|
||||
protoWriter := protoio.NewDelimitedWriter(zWriter)
|
||||
for _, item := range items {
|
||||
types.WriteExtensionItem(protoWriter, item)
|
||||
_ = types.WriteExtensionItem(protoWriter, item)
|
||||
}
|
||||
protoWriter.Close()
|
||||
zWriter.Close()
|
||||
bufWriter.Flush()
|
||||
chunkWriter.Close()
|
||||
_ = protoWriter.Close()
|
||||
_ = zWriter.Close()
|
||||
_ = bufWriter.Flush()
|
||||
_ = chunkWriter.Close()
|
||||
}()
|
||||
|
||||
var chunks [][]byte
|
||||
|
@ -90,6 +89,7 @@ func snapshotItems(items [][]byte) [][]byte {
|
|||
}
|
||||
chunks = append(chunks, chunk)
|
||||
}
|
||||
|
||||
return chunks
|
||||
}
|
||||
|
||||
|
@ -99,31 +99,31 @@ type mockSnapshotter struct {
|
|||
|
||||
func (m *mockSnapshotter) Restore(
|
||||
height uint64, format uint32, protoReader protoio.Reader,
|
||||
) (snapshottypes.SnapshotItem, error) {
|
||||
) (types.SnapshotItem, error) {
|
||||
if format == 0 {
|
||||
return snapshottypes.SnapshotItem{}, types.ErrUnknownFormat
|
||||
return types.SnapshotItem{}, types.ErrUnknownFormat
|
||||
}
|
||||
if m.items != nil {
|
||||
return snapshottypes.SnapshotItem{}, errors.New("already has contents")
|
||||
return types.SnapshotItem{}, errors.New("already has contents")
|
||||
}
|
||||
|
||||
m.items = [][]byte{}
|
||||
for {
|
||||
item := &snapshottypes.SnapshotItem{}
|
||||
item := &types.SnapshotItem{}
|
||||
err := protoReader.ReadMsg(item)
|
||||
if err == io.EOF {
|
||||
break
|
||||
} else if err != nil {
|
||||
return snapshottypes.SnapshotItem{}, sdkerrors.Wrap(err, "invalid protobuf message")
|
||||
return types.SnapshotItem{}, sdkerrors.Wrap(err, "invalid protobuf message")
|
||||
}
|
||||
payload := item.GetExtensionPayload()
|
||||
if payload == nil {
|
||||
return snapshottypes.SnapshotItem{}, sdkerrors.Wrap(err, "invalid protobuf message")
|
||||
return types.SnapshotItem{}, sdkerrors.Wrap(err, "invalid protobuf message")
|
||||
}
|
||||
m.items = append(m.items, payload.Payload)
|
||||
}
|
||||
|
||||
return snapshottypes.SnapshotItem{}, nil
|
||||
return types.SnapshotItem{}, nil
|
||||
}
|
||||
|
||||
func (m *mockSnapshotter) Snapshot(height uint64, protoWriter protoio.Writer) error {
|
||||
|
@ -136,10 +136,10 @@ func (m *mockSnapshotter) Snapshot(height uint64, protoWriter protoio.Writer) er
|
|||
}
|
||||
|
||||
func (m *mockSnapshotter) SnapshotFormat() uint32 {
|
||||
return snapshottypes.CurrentFormat
|
||||
return types.CurrentFormat
|
||||
}
|
||||
func (m *mockSnapshotter) SupportedFormats() []uint32 {
|
||||
return []uint32{snapshottypes.CurrentFormat}
|
||||
return []uint32{types.CurrentFormat}
|
||||
}
|
||||
|
||||
// setupBusyManager creates a manager with an empty store that is busy creating a snapshot at height 1.
|
||||
|
@ -189,6 +189,6 @@ func (m *hungSnapshotter) Snapshot(height uint64, protoWriter protoio.Writer) er
|
|||
|
||||
func (m *hungSnapshotter) Restore(
|
||||
height uint64, format uint32, protoReader protoio.Reader,
|
||||
) (snapshottypes.SnapshotItem, error) {
|
||||
) (types.SnapshotItem, error) {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
|
|
@ -166,7 +166,12 @@ func (m *Manager) createSnapshot(height uint64, ch chan<- io.ReadCloser) {
|
|||
if streamWriter == nil {
|
||||
return
|
||||
}
|
||||
defer streamWriter.Close()
|
||||
defer func() {
|
||||
if err := streamWriter.Close(); err != nil {
|
||||
streamWriter.CloseWithError(err)
|
||||
}
|
||||
}()
|
||||
|
||||
if err := m.multistore.Snapshot(height, streamWriter); err != nil {
|
||||
streamWriter.CloseWithError(err)
|
||||
return
|
||||
|
|
|
@ -145,13 +145,13 @@ func (s *Store) Load(height uint64, format uint32) (*types.Snapshot, <-chan io.R
|
|||
ch <- pr
|
||||
chunk, err := s.loadChunkFile(height, format, i)
|
||||
if err != nil {
|
||||
pw.CloseWithError(err)
|
||||
_ = pw.CloseWithError(err)
|
||||
return
|
||||
}
|
||||
defer chunk.Close()
|
||||
_, err = io.Copy(pw, chunk)
|
||||
if err != nil {
|
||||
pw.CloseWithError(err)
|
||||
_ = pw.CloseWithError(err)
|
||||
return
|
||||
}
|
||||
chunk.Close()
|
||||
|
|
|
@ -88,7 +88,10 @@ func TestStore_Delete(t *testing.T) {
|
|||
|
||||
// Deleting a snapshot being saved should error
|
||||
ch := make(chan io.ReadCloser)
|
||||
go store.Save(9, 1, ch)
|
||||
go func() {
|
||||
_, err := store.Save(9, 1, ch)
|
||||
require.NoError(t, err)
|
||||
}()
|
||||
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
err = store.Delete(9, 1)
|
||||
|
@ -324,7 +327,10 @@ func TestStore_Save(t *testing.T) {
|
|||
// Saving a snapshot should error if a snapshot is already in progress for the same height,
|
||||
// regardless of format. However, a different height should succeed.
|
||||
ch = make(chan io.ReadCloser)
|
||||
go store.Save(7, 1, ch)
|
||||
go func() {
|
||||
_, err := store.Save(7, 1, ch)
|
||||
require.NoError(t, err)
|
||||
}()
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
_, err = store.Save(7, 2, makeChunks(nil))
|
||||
require.Error(t, err)
|
||||
|
|
|
@ -103,7 +103,15 @@ func (sr *StreamReader) ReadMsg(msg proto.Message) error {
|
|||
|
||||
// Close implements io.Closer interface
|
||||
func (sr *StreamReader) Close() error {
|
||||
sr.protoReader.Close()
|
||||
sr.zReader.Close()
|
||||
return sr.chunkReader.Close()
|
||||
var err error
|
||||
if err1 := sr.protoReader.Close(); err1 != nil {
|
||||
err = err1
|
||||
}
|
||||
if err2 := sr.zReader.Close(); err2 != nil {
|
||||
err = err2
|
||||
}
|
||||
if err3 := sr.chunkReader.Close(); err3 != nil {
|
||||
err = err3
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ func TestApplyMockIO(t *testing.T) {
|
|||
|
||||
func TestWriteToNewTempFile(t *testing.T) {
|
||||
tempfile := testutil.WriteToNewTempFile(t, "test string")
|
||||
tempfile.Close()
|
||||
require.NoError(t, tempfile.Close())
|
||||
|
||||
bs, err := os.ReadFile(tempfile.Name())
|
||||
require.NoError(t, err)
|
||||
|
|
|
@ -16,7 +16,9 @@ func GetRequest(url string) ([]byte, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer res.Body.Close()
|
||||
defer func() {
|
||||
_ = res.Body.Close()
|
||||
}()
|
||||
|
||||
body, err := io.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
|
@ -33,7 +35,9 @@ func PostRequest(url string, contentType string, data []byte) ([]byte, error) {
|
|||
if err != nil {
|
||||
return nil, fmt.Errorf("error while sending post request: %w", err)
|
||||
}
|
||||
defer res.Body.Close()
|
||||
defer func() {
|
||||
_ = res.Body.Close()
|
||||
}()
|
||||
|
||||
bz, err := io.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue