Skip to content

Commit

Permalink
Merge branch 'master' into aaronc/tx-tips
Browse files Browse the repository at this point in the history
  • Loading branch information
amaury1093 authored Aug 11, 2021
2 parents 674cbca + c14b101 commit f4c2770
Show file tree
Hide file tree
Showing 81 changed files with 2,620 additions and 361 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/atlas.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: technote-space/get-diff-action@v4
- uses: technote-space/get-diff-action@v5
id: git_diff
with:
PATTERNS: |
Expand All @@ -30,7 +30,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: technote-space/get-diff-action@v4
- uses: technote-space/get-diff-action@v5
id: git_diff
with:
PATTERNS: |
Expand All @@ -45,7 +45,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: technote-space/get-diff-action@v4
- uses: technote-space/get-diff-action@v5
id: git_diff
with:
PATTERNS: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
timeout-minutes: 6
steps:
- uses: actions/checkout@v2
- uses: technote-space/get-diff-action@v4
- uses: technote-space/get-diff-action@v5
with:
PATTERNS: |
**/**.go
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/proto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
timeout-minutes: 5
steps:
- uses: actions/checkout@master
- uses: technote-space/get-diff-action@v4
- uses: technote-space/get-diff-action@v5
with:
PATTERNS: |
**/**.proto
Expand All @@ -21,7 +21,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: technote-space/get-diff-action@v4
- uses: technote-space/get-diff-action@v5
with:
PATTERNS: |
**/**.proto
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/sims.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
go-version: 1.16
- name: Display go version
run: go version
- uses: technote-space/get-diff-action@v4
- uses: technote-space/get-diff-action@v5
with:
PATTERNS: |
**/**.go
Expand All @@ -72,7 +72,7 @@ jobs:
go-version: 1.16
- name: Display go version
run: go version
- uses: technote-space/get-diff-action@v4
- uses: technote-space/get-diff-action@v5
with:
SUFFIX_FILTER: |
**/**.go
Expand Down Expand Up @@ -100,7 +100,7 @@ jobs:
go-version: 1.16
- name: Display go version
run: go version
- uses: technote-space/get-diff-action@v4
- uses: technote-space/get-diff-action@v5
with:
SUFFIX_FILTER: |
**/**.go
Expand Down Expand Up @@ -128,7 +128,7 @@ jobs:
go-version: 1.16
- name: Display go version
run: go version
- uses: technote-space/get-diff-action@v4
- uses: technote-space/get-diff-action@v5
with:
SUFFIX_FILTER: |
**/**.go
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- uses: actions/[email protected]
with:
go-version: 1.16
- uses: technote-space/get-diff-action@v4
- uses: technote-space/get-diff-action@v5
id: git_diff
with:
PATTERNS: |
Expand All @@ -52,7 +52,7 @@ jobs:
go-version: 1.16
- name: Display go version
run: go version
- uses: technote-space/get-diff-action@v4
- uses: technote-space/get-diff-action@v5
id: git_diff
with:
PREFIX_FILTER: |
Expand Down Expand Up @@ -103,7 +103,7 @@ jobs:
- uses: actions/[email protected]
with:
go-version: 1.16
- uses: technote-space/get-diff-action@v4
- uses: technote-space/get-diff-action@v5
with:
PATTERNS: |
**/**.go
Expand All @@ -127,7 +127,7 @@ jobs:
needs: tests
steps:
- uses: actions/checkout@v2
- uses: technote-space/get-diff-action@v4
- uses: technote-space/get-diff-action@v5
with:
PATTERNS: |
**/**.go
Expand Down Expand Up @@ -181,7 +181,7 @@ jobs:
- uses: actions/[email protected]
with:
go-version: 1.16
- uses: technote-space/get-diff-action@v4
- uses: technote-space/get-diff-action@v5
with:
PATTERNS: |
**/**.go
Expand All @@ -205,7 +205,7 @@ jobs:
timeout-minutes: 10
steps:
- uses: actions/checkout@v2
- uses: technote-space/get-diff-action@v4
- uses: technote-space/get-diff-action@v5
id: git_diff
with:
PATTERNS: |
Expand All @@ -225,7 +225,7 @@ jobs:
- uses: actions/[email protected]
with:
go-version: 1.16
- uses: technote-space/get-diff-action@v4
- uses: technote-space/get-diff-action@v5
id: git_diff
with:
PATTERNS: |
Expand Down
70 changes: 53 additions & 17 deletions CHANGELOG.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# TODO: demo connecting rest-server (or is this in server now?)
FROM golang:alpine AS build-env

# Install minimum necessary dependencies,
# Install minimum necessary dependencies
ENV PACKAGES curl make git libc-dev bash gcc linux-headers eudev-dev python3
RUN apk add --no-cache $PACKAGES

Expand Down
25 changes: 14 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ MOCKS_DIR = $(CURDIR)/tests/mocks
HTTPS_GIT := https://github.com/cosmos/cosmos-sdk.git
DOCKER := $(shell which docker)
DOCKER_BUF := $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace bufbuild/buf
PROJECT_NAME = $(shell git remote get-url origin | xargs basename -s .git)

export GO111MODULE = on

Expand Down Expand Up @@ -327,17 +328,17 @@ benchmark:
### Linting ###
###############################################################################

containerMarkdownLintImage=tmknom/markdownlint
containerMarkdownLint=cosmos-sdk-markdownlint
containerMarkdownLintFix=cosmos-sdk-markdownlint-fix
markdownLintImage=tmknom/markdownlint
containerMarkdownLint=$(PROJECT_NAME)-markdownlint
containerMarkdownLintFix=$(PROJECT_NAME)-markdownlint-fix

lint:
golangci-lint run --out-format=tab
@if docker ps -a --format '{{.Names}}' | grep -Eq "^${containerMarkdownLint}$$"; then docker start -a $(containerMarkdownLint); else docker run --name $(containerMarkdownLint) -i -v "$(CURDIR):/work" $(containerMarkdownLintImage); fi
@if docker ps -a --format '{{.Names}}' | grep -Eq "^${containerMarkdownLint}$$"; then docker start -a $(containerMarkdownLint); else docker run --name $(containerMarkdownLint) -i -v "$(CURDIR):/work" $(markdownLintImage); fi

lint-fix:
golangci-lint run --fix --out-format=tab --issues-exit-code=0
@if docker ps -a --format '{{.Names}}' | grep -Eq "^${containerMarkdownLintFix}$$"; then docker start -a $(containerMarkdownLintFix); else docker run --name $(containerMarkdownLintFix) -i -v "$(CURDIR):/work" $(containerMarkdownLintImage) . --fix; fi
@if docker ps -a --format '{{.Names}}' | grep -Eq "^${containerMarkdownLintFix}$$"; then docker start -a $(containerMarkdownLintFix); else docker run --name $(containerMarkdownLintFix) -i -v "$(CURDIR):/work" $(markdownLintImage) . --fix; fi

.PHONY: lint lint-fix

Expand Down Expand Up @@ -377,11 +378,12 @@ devdoc-update:
### Protobuf ###
###############################################################################

containerProtoVer=v0.2
containerProtoImage=tendermintdev/sdk-proto-gen:$(containerProtoVer)
containerProtoGen=cosmos-sdk-proto-gen-$(containerProtoVer)
containerProtoGenSwagger=cosmos-sdk-proto-gen-swagger-$(containerProtoVer)
containerProtoFmt=cosmos-sdk-proto-fmt-$(containerProtoVer)
protoVer=v0.2
protoImageName=tendermintdev/sdk-proto-gen:$(protoVer)
containerProtoGen=$(PROJECT_NAME)-proto-gen-$(protoVer)
containerProtoGenAny=$(PROJECT_NAME)-proto-gen-any-$(protoVer)
containerProtoGenSwagger=$(PROJECT_NAME)-proto-gen-swagger-$(protoVer)
containerProtoFmt=$(PROJECT_NAME)-proto-fmt-$(protoVer)

proto-all: proto-format proto-lint proto-gen

Expand All @@ -393,7 +395,8 @@ proto-gen:
# This generates the SDK's custom wrapper for google.protobuf.Any. It should only be run manually when needed
proto-gen-any:
@echo "Generating Protobuf Any"
$(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace $(containerProtoImage) sh ./scripts/protocgen-any.sh
@if docker ps -a --format '{{.Names}}' | grep -Eq "^${containerProtoGenAny}$$"; then docker start -a $(containerProtoGenAny); else docker run --name $(containerProtoGenAny) -v $(CURDIR):/workspace --workdir /workspace $(containerProtoImage) \
sh ./scripts/protocgen-any.sh; fi

proto-swagger-gen:
@echo "Generating Protobuf Swagger"
Expand Down
16 changes: 5 additions & 11 deletions client/context.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package client

import (
"bufio"
"encoding/json"
"io"
"os"
Expand All @@ -10,7 +11,6 @@ import (
"gopkg.in/yaml.v2"

"github.com/gogo/protobuf/proto"
"github.com/pkg/errors"
rpcclient "github.com/tendermint/tendermint/rpc/client"

"github.com/cosmos/cosmos-sdk/codec"
Expand Down Expand Up @@ -68,7 +68,10 @@ func (ctx Context) WithKeyringOptions(opts ...keyring.Option) Context {

// WithInput returns a copy of the context with an updated input.
func (ctx Context) WithInput(r io.Reader) Context {
ctx.Input = r
// convert to a bufio.Reader to have a shared buffer between the keyring and the
// the Commands, ensuring a read from one advance the read pointer for the other.
// see https://github.com/cosmos/cosmos-sdk/issues/9566.
ctx.Input = bufio.NewReader(r)
return ctx
}

Expand Down Expand Up @@ -320,15 +323,6 @@ func GetFromFields(kr keyring.Keyring, from string, genOnly bool) (sdk.AccAddres
return nil, "", 0, nil
}

if genOnly {
addr, err := sdk.AccAddressFromBech32(from)
if err != nil {
return nil, "", 0, errors.Wrap(err, "must provide a valid Bech32 address in generate-only mode")
}

return addr, "", 0, nil
}

var info keyring.Info
if addr, err := sdk.AccAddressFromBech32(from); err == nil {
info, err = kr.KeyByAddress(addr)
Expand Down
2 changes: 1 addition & 1 deletion client/keys/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ Example:
}

func runAddCmdPrepare(cmd *cobra.Command, args []string) error {
buf := bufio.NewReader(cmd.InOrStdin())
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

buf := bufio.NewReader(clientCtx.Input)
return runAddCmd(clientCtx, cmd, args, buf)
}

Expand Down
47 changes: 46 additions & 1 deletion client/keys/add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/testutil"
sdk "github.com/cosmos/cosmos-sdk/types"
bip39 "github.com/cosmos/go-bip39"
)

func Test_runAddCmdBasic(t *testing.T) {
Expand All @@ -30,7 +31,7 @@ func Test_runAddCmdBasic(t *testing.T) {
kb, err := keyring.New(sdk.KeyringServiceName(), keyring.BackendTest, kbHome, mockIn)
require.NoError(t, err)

clientCtx := client.Context{}.WithKeyringDir(kbHome)
clientCtx := client.Context{}.WithKeyringDir(kbHome).WithInput(mockIn)
ctx := context.WithValue(context.Background(), client.ClientContextKey, &clientCtx)

t.Cleanup(func() {
Expand Down Expand Up @@ -227,3 +228,47 @@ func Test_runAddCmdDryRun(t *testing.T) {
})
}
}

func TestAddRecoverFileBackend(t *testing.T) {
cmd := AddKeyCommand()
cmd.Flags().AddFlagSet(Commands("home").PersistentFlags())

mockIn := testutil.ApplyMockIODiscardOutErr(cmd)
kbHome := t.TempDir()

clientCtx := client.Context{}.WithKeyringDir(kbHome).WithInput(mockIn)
ctx := context.WithValue(context.Background(), client.ClientContextKey, &clientCtx)

cmd.SetArgs([]string{
"keyname1",
fmt.Sprintf("--%s=%s", flags.FlagHome, kbHome),
fmt.Sprintf("--%s=%s", cli.OutputFlag, OutputFormatText),
fmt.Sprintf("--%s=%s", flags.FlagKeyAlgorithm, string(hd.Secp256k1Type)),
fmt.Sprintf("--%s=%s", flags.FlagKeyringBackend, keyring.BackendFile),
fmt.Sprintf("--%s", flagRecover),
})

keyringPassword := "12345678"

entropySeed, err := bip39.NewEntropy(mnemonicEntropySize)
require.NoError(t, err)

mnemonic, err := bip39.NewMnemonic(entropySeed)
require.NoError(t, err)

mockIn.Reset(fmt.Sprintf("%s\n%s\n%s\n", mnemonic, keyringPassword, keyringPassword))
require.NoError(t, cmd.ExecuteContext(ctx))

kb, err := keyring.New(sdk.KeyringServiceName(), keyring.BackendFile, kbHome, mockIn)
require.NoError(t, err)

t.Cleanup(func() {
mockIn.Reset(fmt.Sprintf("%s\n%s\n", keyringPassword, keyringPassword))
_ = kb.Delete("keyname1")
})

mockIn.Reset(fmt.Sprintf("%s\n%s\n", keyringPassword, keyringPassword))
info, err := kb.Key("keyname1")
require.NoError(t, err)
require.Equal(t, "keyname1", info.GetName())
}
2 changes: 1 addition & 1 deletion client/keys/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ FULLY AWARE OF THE RISKS. If you are unsure, you may want to do some research
and export your keys in ASCII-armored encrypted format.`,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
buf := bufio.NewReader(cmd.InOrStdin())
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
buf := bufio.NewReader(clientCtx.Input)
unarmored, _ := cmd.Flags().GetBool(flagUnarmoredHex)
unsafe, _ := cmd.Flags().GetBool(flagUnsafe)

Expand Down
Loading

0 comments on commit f4c2770

Please sign in to comment.