From 4911db850dd8232e7b8f701f81535d37c24a9b8d Mon Sep 17 00:00:00 2001 From: Christopher Goes Date: Thu, 3 May 2018 18:35:12 +0200 Subject: [PATCH 1/4] Fix auto-sequencing (closes #950) --- client/context/viper.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/client/context/viper.go b/client/context/viper.go index 7e82f7ad9d..4b3007f12a 100644 --- a/client/context/viper.go +++ b/client/context/viper.go @@ -36,7 +36,7 @@ func NewCoreContextFromViper() CoreContext { Sequence: viper.GetInt64(client.FlagSequence), Client: rpc, Decoder: nil, - AccountStore: "main", + AccountStore: "acc", } } @@ -55,7 +55,8 @@ func defaultChainID() (string, error) { // EnsureSequence - automatically set sequence number if none provided func EnsureSequence(ctx CoreContext) (CoreContext, error) { - if viper.IsSet(client.FlagSequence) { + // Should be viper.IsSet, but this does not work - https://github.com/spf13/viper/pull/331 + if viper.GetInt64(client.FlagSequence) != 0 { return ctx, nil } from, err := ctx.GetFromAddress() From 05988623af728301aec667b8ee3f955d8c2e1a6d Mon Sep 17 00:00:00 2001 From: Christopher Goes Date: Thu, 3 May 2018 18:36:37 +0200 Subject: [PATCH 2/4] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e6fd489592..0b1e67bee6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ FEATURES: BUG FIXES * Gaia now uses stake, ported from github.com/cosmos/gaia +* Auto-sequencing now works correctly ## 0.15.1 (April 29, 2018) From 10540e38db9ee7e155d370284c98c61b13875edd Mon Sep 17 00:00:00 2001 From: Christopher Goes Date: Thu, 3 May 2018 23:19:56 +0200 Subject: [PATCH 3/4] Handle case of empty (new) account --- client/context/helpers.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/client/context/helpers.go b/client/context/helpers.go index ded70cb5c6..233dbcc2b8 100644 --- a/client/context/helpers.go +++ b/client/context/helpers.go @@ -158,6 +158,11 @@ func (ctx CoreContext) NextSequence(address []byte) (int64, error) { return 0, err } + if len(res) == 0 { + fmt.Printf("No account found, defaulting to sequence 0\n") + return 0, err + } + account, err := ctx.Decoder(res) if err != nil { panic(err) From 23c9e2fb6f04a26f1b7bb4a46b946fa18e25acdd Mon Sep 17 00:00:00 2001 From: Christopher Goes Date: Fri, 4 May 2018 05:43:29 +0200 Subject: [PATCH 4/4] Update CLI tests to test auto-sequencing --- cmd/gaia/cli_test/cli_test.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cmd/gaia/cli_test/cli_test.go b/cmd/gaia/cli_test/cli_test.go index 102c4ada98..b4529efd89 100644 --- a/cmd/gaia/cli_test/cli_test.go +++ b/cmd/gaia/cli_test/cli_test.go @@ -48,6 +48,15 @@ func TestGaiaCLISend(t *testing.T) { assert.Equal(t, int64(10), barAcc.GetCoins().AmountOf("steak")) fooAcc = executeGetAccount(t, fmt.Sprintf("gaiacli account %v %v", fooAddr, flags)) assert.Equal(t, int64(40), fooAcc.GetCoins().AmountOf("steak")) + + // test autosequencing + executeWrite(t, fmt.Sprintf("gaiacli send %v --amount=10steak --to=%v --name=foo", flags, barAddr), pass) + time.Sleep(time.Second * 3) // waiting for some blocks to pass + + barAcc = executeGetAccount(t, fmt.Sprintf("gaiacli account %v %v", barAddr, flags)) + assert.Equal(t, int64(20), barAcc.GetCoins().AmountOf("steak")) + fooAcc = executeGetAccount(t, fmt.Sprintf("gaiacli account %v %v", fooAddr, flags)) + assert.Equal(t, int64(30), fooAcc.GetCoins().AmountOf("steak")) } func TestGaiaCLIDeclareCandidacy(t *testing.T) {