Some checks failed
Build SimApp / build (amd64) (push) Waiting to run
Build SimApp / build (arm64) (push) Waiting to run
CodeQL / Analyze (push) Waiting to run
Build & Push / build (push) Waiting to run
Run Gosec / Gosec (push) Waiting to run
Lint / golangci-lint (push) Waiting to run
Checks dependencies and mocks generation / Check go mod tidy (push) Waiting to run
Checks dependencies and mocks generation / Check up to date mocks (push) Waiting to run
System Tests / setup (push) Waiting to run
System Tests / test-system (push) Blocked by required conditions
System Tests / test-system-legacy (push) Blocked by required conditions
Tests / Code Coverage / split-test-files (push) Waiting to run
Tests / Code Coverage / tests (00) (push) Blocked by required conditions
Tests / Code Coverage / tests (01) (push) Blocked by required conditions
Tests / Code Coverage / tests (02) (push) Blocked by required conditions
Tests / Code Coverage / tests (03) (push) Blocked by required conditions
Tests / Code Coverage / test-integration (push) Waiting to run
Tests / Code Coverage / test-e2e (push) Waiting to run
Tests / Code Coverage / repo-analysis (push) Blocked by required conditions
Tests / Code Coverage / test-sim-nondeterminism (push) Waiting to run
Tests / Code Coverage / test-clientv2 (push) Waiting to run
Tests / Code Coverage / test-core (push) Waiting to run
Tests / Code Coverage / test-depinject (push) Waiting to run
Tests / Code Coverage / test-errors (push) Waiting to run
Tests / Code Coverage / test-math (push) Waiting to run
Tests / Code Coverage / test-schema (push) Waiting to run
Tests / Code Coverage / test-collections (push) Waiting to run
Tests / Code Coverage / test-cosmovisor (push) Waiting to run
Tests / Code Coverage / test-confix (push) Waiting to run
Tests / Code Coverage / test-store (push) Waiting to run
Tests / Code Coverage / test-log (push) Waiting to run
Tests / Code Coverage / test-x-tx (push) Waiting to run
Tests / Code Coverage / test-x-nft (push) Waiting to run
Tests / Code Coverage / test-x-circuit (push) Waiting to run
Tests / Code Coverage / test-x-feegrant (push) Waiting to run
Tests / Code Coverage / test-x-evidence (push) Waiting to run
Tests / Code Coverage / test-x-upgrade (push) Waiting to run
Tests / Code Coverage / test-tools-benchmark (push) Waiting to run
Build & Push SDK Proto Builder / build (push) Has been cancelled
88 lines
2.1 KiB
Go
88 lines
2.1 KiB
Go
//go:build !race
|
|
|
|
// Disabled -race because the package github.com/manifoldco/promptui@v0.9.0
|
|
// has a data race and this code exposes it, but fixing it would require
|
|
// holding up the associated change to this.
|
|
|
|
package cli_test
|
|
|
|
import (
|
|
"fmt"
|
|
"math"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/chzyer/readline"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/gov/client/cli"
|
|
)
|
|
|
|
type st struct {
|
|
I int
|
|
}
|
|
|
|
// Tests that we successfully report overflows in parsing ints
|
|
// See https://github.com/cosmos/cosmos-sdk/issues/13346
|
|
func TestPromptIntegerOverflow(t *testing.T) {
|
|
// Intentionally sending values out of the range of int.
|
|
intOverflowers := []string{
|
|
"-9223372036854775809",
|
|
"9223372036854775808",
|
|
"9923372036854775809",
|
|
"-9923372036854775809",
|
|
"18446744073709551616",
|
|
"-18446744073709551616",
|
|
}
|
|
|
|
for _, intOverflower := range intOverflowers {
|
|
overflowStr := intOverflower
|
|
t.Run(overflowStr, func(t *testing.T) {
|
|
origStdin := readline.Stdin
|
|
defer func() {
|
|
readline.Stdin = origStdin
|
|
}()
|
|
|
|
fin, fw := readline.NewFillableStdin(os.Stdin)
|
|
readline.Stdin = fin
|
|
_, err := fw.Write([]byte(overflowStr + "\n"))
|
|
require.NoError(t, err)
|
|
|
|
v, err := cli.Prompt(st{}, "")
|
|
assert.Equal(t, st{}, v, "expected a value of zero")
|
|
require.NotNil(t, err, "expected a report of an overflow")
|
|
require.Contains(t, err.Error(), "range")
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestPromptParseInteger(t *testing.T) {
|
|
// Intentionally sending a value out of the range of
|
|
values := []struct {
|
|
in string
|
|
want int
|
|
}{
|
|
{fmt.Sprintf("%d", math.MinInt), math.MinInt},
|
|
{"19991", 19991},
|
|
{"991000000199", 991000000199},
|
|
}
|
|
|
|
for _, tc := range values {
|
|
t.Run(tc.in, func(t *testing.T) {
|
|
origStdin := readline.Stdin
|
|
defer func() {
|
|
readline.Stdin = origStdin
|
|
}()
|
|
|
|
fin, fw := readline.NewFillableStdin(os.Stdin)
|
|
readline.Stdin = fin
|
|
_, err := fw.Write([]byte(tc.in + "\n"))
|
|
assert.NoError(t, err)
|
|
|
|
v, err := cli.Prompt(st{}, "")
|
|
assert.Nil(t, err, "expected a nil error")
|
|
assert.Equal(t, tc.want, v.I, "expected %d = %d", tc.want, v.I)
|
|
})
|
|
}
|
|
}
|