From b7da2eaa3374c3603a713793ba3f7b82bd81cad9 Mon Sep 17 00:00:00 2001 From: Sunny Aggarwal Date: Mon, 26 Nov 2018 06:29:21 -0500 Subject: [PATCH] Merge PR #2799: Account numbers and sequences to uint64 --- PENDING.md | 1 + client/context/query.go | 4 +- client/flags.go | 4 +- client/utils/rest.go | 4 +- cmd/gaia/app/genesis.go | 4 +- docs/_attic/sdk/core/app3.md | 16 ++--- docs/examples/democoin/x/cool/app_test.go | 16 ++--- docs/examples/democoin/x/pow/app_test.go | 6 +- x/auth/account.go | 20 +++--- x/auth/account_test.go | 4 +- x/auth/ante_test.go | 84 +++++++++++------------ x/auth/client/rest/sign.go | 4 +- x/auth/client/txbuilder/stdsignmsg.go | 4 +- x/auth/client/txbuilder/txbuilder.go | 12 ++-- x/auth/client/txbuilder/txbuilder_test.go | 4 +- x/auth/keeper.go | 8 +-- x/auth/keeper_test.go | 6 +- x/auth/stdtx.go | 10 +-- x/auth/stdtx_test.go | 14 ++-- x/bank/app_test.go | 32 ++++----- x/bank/bench_test.go | 2 +- x/bank/simulation/msgs.go | 4 +- x/ibc/app_test.go | 8 +-- x/ibc/client/cli/relay.go | 10 +-- x/ibc/ibc_test.go | 14 ++-- x/ibc/mapper.go | 12 ++-- x/ibc/types.go | 4 +- x/mock/app.go | 6 +- x/mock/app_test.go | 10 +-- x/mock/test_utils.go | 8 +-- x/slashing/app_test.go | 4 +- x/stake/app_test.go | 10 +-- 32 files changed, 175 insertions(+), 174 deletions(-) diff --git a/PENDING.md b/PENDING.md index c4c2c73f4d72..85f740b96457 100644 --- a/PENDING.md +++ b/PENDING.md @@ -16,6 +16,7 @@ BREAKING CHANGES * SDK * [\#2752](https://github.com/cosmos/cosmos-sdk/pull/2752) Don't hardcode bondable denom. + * [\#2701](https://github.com/cosmos/cosmos-sdk/issues/2701) Account numbers and sequence numbers in `auth` are now `uint64` instead of `int64` * [\#2019](https://github.com/cosmos/cosmos-sdk/issues/2019) Cap total number of signatures. Current per-transaction limit is 7, and if that is exceeded transaction is rejected. * [\#2801](https://github.com/cosmos/cosmos-sdk/pull/2801) Remove AppInit structure. * [\#2798](https://github.com/cosmos/cosmos-sdk/issues/2798) Governance API has miss-spelled English word in JSON response ('depositer' -> 'depositor') diff --git a/client/context/query.go b/client/context/query.go index 572a1377874b..486bd5186e48 100644 --- a/client/context/query.go +++ b/client/context/query.go @@ -92,7 +92,7 @@ func (ctx CLIContext) GetFromName() (string, error) { // GetAccountNumber returns the next account number for the given account // address. -func (ctx CLIContext) GetAccountNumber(address []byte) (int64, error) { +func (ctx CLIContext) GetAccountNumber(address []byte) (uint64, error) { account, err := ctx.GetAccount(address) if err != nil { return 0, err @@ -103,7 +103,7 @@ func (ctx CLIContext) GetAccountNumber(address []byte) (int64, error) { // GetAccountSequence returns the sequence number for the given account // address. -func (ctx CLIContext) GetAccountSequence(address []byte) (int64, error) { +func (ctx CLIContext) GetAccountSequence(address []byte) (uint64, error) { account, err := ctx.GetAccount(address) if err != nil { return 0, err diff --git a/client/flags.go b/client/flags.go index ffb2a0c2f04f..6a3ccff060e6 100644 --- a/client/flags.go +++ b/client/flags.go @@ -74,8 +74,8 @@ func PostCommands(cmds ...*cobra.Command) []*cobra.Command { for _, c := range cmds { c.Flags().Bool(FlagIndentResponse, false, "Add indent to JSON response") c.Flags().String(FlagFrom, "", "Name or address of private key with which to sign") - c.Flags().Int64(FlagAccountNumber, 0, "AccountNumber number to sign the tx") - c.Flags().Int64(FlagSequence, 0, "Sequence number to sign the tx") + c.Flags().Uint64(FlagAccountNumber, 0, "AccountNumber number to sign the tx") + c.Flags().Uint64(FlagSequence, 0, "Sequence number to sign the tx") c.Flags().String(FlagMemo, "", "Memo to send along with transaction") c.Flags().String(FlagFee, "", "Fee to pay along with transaction") c.Flags().String(FlagChainID, "", "Chain ID of tendermint node") diff --git a/client/utils/rest.go b/client/utils/rest.go index 13347098b39e..c0a8c3c77e45 100644 --- a/client/utils/rest.go +++ b/client/utils/rest.go @@ -124,8 +124,8 @@ type BaseReq struct { Name string `json:"name"` Password string `json:"password"` ChainID string `json:"chain_id"` - AccountNumber int64 `json:"account_number"` - Sequence int64 `json:"sequence"` + AccountNumber uint64 `json:"account_number"` + Sequence uint64 `json:"sequence"` Gas string `json:"gas"` GasAdjustment string `json:"gas_adjustment"` } diff --git a/cmd/gaia/app/genesis.go b/cmd/gaia/app/genesis.go index 15010af98f80..60e96307bc89 100644 --- a/cmd/gaia/app/genesis.go +++ b/cmd/gaia/app/genesis.go @@ -61,8 +61,8 @@ func NewGenesisState(accounts []GenesisAccount, authData auth.GenesisState, type GenesisAccount struct { Address sdk.AccAddress `json:"address"` Coins sdk.Coins `json:"coins"` - Sequence int64 `json:"sequence_number"` - AccountNumber int64 `json:"account_number"` + Sequence uint64 `json:"sequence_number"` + AccountNumber uint64 `json:"account_number"` } func NewGenesisAccount(acc *auth.BaseAccount) GenesisAccount { diff --git a/docs/_attic/sdk/core/app3.md b/docs/_attic/sdk/core/app3.md index 2462e3e66a09..a84bb6873da9 100644 --- a/docs/_attic/sdk/core/app3.md +++ b/docs/_attic/sdk/core/app3.md @@ -52,11 +52,11 @@ type Account interface { GetPubKey() crypto.PubKey // can return nil. SetPubKey(crypto.PubKey) error - GetAccountNumber() int64 - SetAccountNumber(int64) error + GetAccountNumber() uint64 + SetAccountNumber(uint64) error - GetSequence() int64 - SetSequence(int64) error + GetSequence() uint64 + SetSequence(uint64) error GetCoins() sdk.Coins SetCoins(sdk.Coins) error @@ -79,8 +79,8 @@ type BaseAccount struct { Address sdk.AccAddress `json:"address"` Coins sdk.Coins `json:"coins"` PubKey crypto.PubKey `json:"public_key"` - AccountNumber int64 `json:"account_number"` - Sequence int64 `json:"sequence"` + AccountNumber uint64 `json:"account_number"` + Sequence uint64 `json:"sequence"` } ``` @@ -161,8 +161,8 @@ The standard form for signatures is `StdSignature`: type StdSignature struct { crypto.PubKey `json:"pub_key"` // optional []byte `json:"signature"` - AccountNumber int64 `json:"account_number"` - Sequence int64 `json:"sequence"` + AccountNumber uint64 `json:"account_number"` + Sequence uint64 `json:"sequence"` } ``` diff --git a/docs/examples/democoin/x/cool/app_test.go b/docs/examples/democoin/x/cool/app_test.go index 7bfc8b9cc0b5..3725f7b9be7a 100644 --- a/docs/examples/democoin/x/cool/app_test.go +++ b/docs/examples/democoin/x/cool/app_test.go @@ -88,17 +88,17 @@ func TestMsgQuiz(t *testing.T) { require.Equal(t, acc1, res1) // Set the trend, submit a really cool quiz and check for reward - mock.SignCheckDeliver(t, mapp.BaseApp, []sdk.Msg{setTrendMsg1}, []int64{0}, []int64{0}, true, true, priv1) - mock.SignCheckDeliver(t, mapp.BaseApp, []sdk.Msg{quizMsg1}, []int64{0}, []int64{1}, true, true, priv1) + mock.SignCheckDeliver(t, mapp.BaseApp, []sdk.Msg{setTrendMsg1}, []uint64{0}, []uint64{0}, true, true, priv1) + mock.SignCheckDeliver(t, mapp.BaseApp, []sdk.Msg{quizMsg1}, []uint64{0}, []uint64{1}, true, true, priv1) mock.CheckBalance(t, mapp, addr1, sdk.Coins{sdk.NewCoin("icecold", sdk.NewInt(69))}) - mock.SignCheckDeliver(t, mapp.BaseApp, []sdk.Msg{quizMsg2}, []int64{0}, []int64{2}, false, false, priv1) // result without reward + mock.SignCheckDeliver(t, mapp.BaseApp, []sdk.Msg{quizMsg2}, []uint64{0}, []uint64{2}, false, false, priv1) // result without reward mock.CheckBalance(t, mapp, addr1, sdk.Coins{sdk.NewCoin("icecold", sdk.NewInt(69))}) - mock.SignCheckDeliver(t, mapp.BaseApp, []sdk.Msg{quizMsg1}, []int64{0}, []int64{3}, true, true, priv1) + mock.SignCheckDeliver(t, mapp.BaseApp, []sdk.Msg{quizMsg1}, []uint64{0}, []uint64{3}, true, true, priv1) mock.CheckBalance(t, mapp, addr1, sdk.Coins{sdk.NewCoin("icecold", sdk.NewInt(138))}) - mock.SignCheckDeliver(t, mapp.BaseApp, []sdk.Msg{setTrendMsg2}, []int64{0}, []int64{4}, true, true, priv1) // reset the trend - mock.SignCheckDeliver(t, mapp.BaseApp, []sdk.Msg{quizMsg1}, []int64{0}, []int64{5}, false, false, priv1) // the same answer will nolonger do! + mock.SignCheckDeliver(t, mapp.BaseApp, []sdk.Msg{setTrendMsg2}, []uint64{0}, []uint64{4}, true, true, priv1) // reset the trend + mock.SignCheckDeliver(t, mapp.BaseApp, []sdk.Msg{quizMsg1}, []uint64{0}, []uint64{5}, false, false, priv1) // the same answer will nolonger do! mock.CheckBalance(t, mapp, addr1, sdk.Coins{sdk.NewCoin("icecold", sdk.NewInt(138))}) - mock.SignCheckDeliver(t, mapp.BaseApp, []sdk.Msg{quizMsg2}, []int64{0}, []int64{6}, true, true, priv1) // earlier answer now relevant again + mock.SignCheckDeliver(t, mapp.BaseApp, []sdk.Msg{quizMsg2}, []uint64{0}, []uint64{6}, true, true, priv1) // earlier answer now relevant again mock.CheckBalance(t, mapp, addr1, sdk.Coins{sdk.NewCoin("badvibesonly", sdk.NewInt(69)), sdk.NewCoin("icecold", sdk.NewInt(138))}) - mock.SignCheckDeliver(t, mapp.BaseApp, []sdk.Msg{setTrendMsg3}, []int64{0}, []int64{7}, false, false, priv1) // expect to fail to set the trend to something which is not cool + mock.SignCheckDeliver(t, mapp.BaseApp, []sdk.Msg{setTrendMsg3}, []uint64{0}, []uint64{7}, false, false, priv1) // expect to fail to set the trend to something which is not cool } diff --git a/docs/examples/democoin/x/pow/app_test.go b/docs/examples/democoin/x/pow/app_test.go index 58a7d3538600..1556996b37c0 100644 --- a/docs/examples/democoin/x/pow/app_test.go +++ b/docs/examples/democoin/x/pow/app_test.go @@ -74,13 +74,13 @@ func TestMsgMine(t *testing.T) { // Mine and check for reward mineMsg1 := GenerateMsgMine(addr1, 1, 2) - mock.SignCheckDeliver(t, mapp.BaseApp, []sdk.Msg{mineMsg1}, []int64{0}, []int64{0}, true, true, priv1) + mock.SignCheckDeliver(t, mapp.BaseApp, []sdk.Msg{mineMsg1}, []uint64{0}, []uint64{0}, true, true, priv1) mock.CheckBalance(t, mapp, addr1, sdk.Coins{sdk.NewCoin("pow", sdk.NewInt(1))}) // Mine again and check for reward mineMsg2 := GenerateMsgMine(addr1, 2, 3) - mock.SignCheckDeliver(t, mapp.BaseApp, []sdk.Msg{mineMsg2}, []int64{0}, []int64{1}, true, true, priv1) + mock.SignCheckDeliver(t, mapp.BaseApp, []sdk.Msg{mineMsg2}, []uint64{0}, []uint64{1}, true, true, priv1) mock.CheckBalance(t, mapp, addr1, sdk.Coins{sdk.NewCoin("pow", sdk.NewInt(2))}) // Mine again - should be invalid - mock.SignCheckDeliver(t, mapp.BaseApp, []sdk.Msg{mineMsg2}, []int64{0}, []int64{1}, false, false, priv1) + mock.SignCheckDeliver(t, mapp.BaseApp, []sdk.Msg{mineMsg2}, []uint64{0}, []uint64{1}, false, false, priv1) mock.CheckBalance(t, mapp, addr1, sdk.Coins{sdk.NewCoin("pow", sdk.NewInt(2))}) } diff --git a/x/auth/account.go b/x/auth/account.go index 4a55a48ea3df..0fa601acc3ec 100644 --- a/x/auth/account.go +++ b/x/auth/account.go @@ -21,11 +21,11 @@ type Account interface { GetPubKey() crypto.PubKey // can return nil. SetPubKey(crypto.PubKey) error - GetAccountNumber() int64 - SetAccountNumber(int64) error + GetAccountNumber() uint64 + SetAccountNumber(uint64) error - GetSequence() int64 - SetSequence(int64) error + GetSequence() uint64 + SetSequence(uint64) error GetCoins() sdk.Coins SetCoins(sdk.Coins) error @@ -48,8 +48,8 @@ type BaseAccount struct { Address sdk.AccAddress `json:"address"` Coins sdk.Coins `json:"coins"` PubKey crypto.PubKey `json:"public_key"` - AccountNumber int64 `json:"account_number"` - Sequence int64 `json:"sequence"` + AccountNumber uint64 `json:"account_number"` + Sequence uint64 `json:"sequence"` } // Prototype function for BaseAccount @@ -100,23 +100,23 @@ func (acc *BaseAccount) SetCoins(coins sdk.Coins) error { } // Implements Account -func (acc *BaseAccount) GetAccountNumber() int64 { +func (acc *BaseAccount) GetAccountNumber() uint64 { return acc.AccountNumber } // Implements Account -func (acc *BaseAccount) SetAccountNumber(accNumber int64) error { +func (acc *BaseAccount) SetAccountNumber(accNumber uint64) error { acc.AccountNumber = accNumber return nil } // Implements sdk.Account. -func (acc *BaseAccount) GetSequence() int64 { +func (acc *BaseAccount) GetSequence() uint64 { return acc.Sequence } // Implements sdk.Account. -func (acc *BaseAccount) SetSequence(seq int64) error { +func (acc *BaseAccount) SetSequence(seq uint64) error { acc.Sequence = seq return nil } diff --git a/x/auth/account_test.go b/x/auth/account_test.go index e48060fbefc9..8b75e8ce5c9e 100644 --- a/x/auth/account_test.go +++ b/x/auth/account_test.go @@ -67,7 +67,7 @@ func TestBaseAccountSequence(t *testing.T) { _, _, addr := keyPubAddr() acc := NewBaseAccountWithAddress(addr) - seq := int64(7) + seq := uint64(7) err := acc.SetSequence(seq) require.Nil(t, err) @@ -79,7 +79,7 @@ func TestBaseAccountMarshal(t *testing.T) { acc := NewBaseAccountWithAddress(addr) someCoins := sdk.Coins{sdk.NewInt64Coin("atom", 123), sdk.NewInt64Coin("eth", 246)} - seq := int64(7) + seq := uint64(7) // set everything on the account err := acc.SetPubKey(pub) diff --git a/x/auth/ante_test.go b/x/auth/ante_test.go index 566892e07eae..8d7118e74652 100644 --- a/x/auth/ante_test.go +++ b/x/auth/ante_test.go @@ -66,7 +66,7 @@ func checkInvalidTx(t *testing.T, anteHandler sdk.AnteHandler, ctx sdk.Context, } } -func newTestTx(ctx sdk.Context, msgs []sdk.Msg, privs []crypto.PrivKey, accNums []int64, seqs []int64, fee StdFee) sdk.Tx { +func newTestTx(ctx sdk.Context, msgs []sdk.Msg, privs []crypto.PrivKey, accNums []uint64, seqs []uint64, fee StdFee) sdk.Tx { sigs := make([]StdSignature, len(privs)) for i, priv := range privs { signBytes := StdSignBytes(ctx.ChainID(), accNums[i], seqs[i], fee, msgs, "") @@ -80,7 +80,7 @@ func newTestTx(ctx sdk.Context, msgs []sdk.Msg, privs []crypto.PrivKey, accNums return tx } -func newTestTxWithMemo(ctx sdk.Context, msgs []sdk.Msg, privs []crypto.PrivKey, accNums []int64, seqs []int64, fee StdFee, memo string) sdk.Tx { +func newTestTxWithMemo(ctx sdk.Context, msgs []sdk.Msg, privs []crypto.PrivKey, accNums []uint64, seqs []uint64, fee StdFee, memo string) sdk.Tx { sigs := make([]StdSignature, len(privs)) for i, priv := range privs { signBytes := StdSignBytes(ctx.ChainID(), accNums[i], seqs[i], fee, msgs, memo) @@ -95,7 +95,7 @@ func newTestTxWithMemo(ctx sdk.Context, msgs []sdk.Msg, privs []crypto.PrivKey, } // All signers sign over the same StdSignDoc. Should always create invalid signatures -func newTestTxWithSignBytes(msgs []sdk.Msg, privs []crypto.PrivKey, accNums []int64, seqs []int64, fee StdFee, signBytes []byte, memo string) sdk.Tx { +func newTestTxWithSignBytes(msgs []sdk.Msg, privs []crypto.PrivKey, accNums []uint64, seqs []uint64, fee StdFee, signBytes []byte, memo string) sdk.Tx { sigs := make([]StdSignature, len(privs)) for i, priv := range privs { sig, err := priv.Sign(signBytes) @@ -133,7 +133,7 @@ func TestAnteHandlerSigErrors(t *testing.T) { msgs := []sdk.Msg{msg1, msg2} // test no signatures - privs, accNums, seqs := []crypto.PrivKey{}, []int64{}, []int64{} + privs, accNums, seqs := []crypto.PrivKey{}, []uint64{}, []uint64{} tx = newTestTx(ctx, msgs, privs, accNums, seqs, fee) // tx.GetSigners returns addresses in correct order: addr1, addr2, addr3 @@ -145,12 +145,12 @@ func TestAnteHandlerSigErrors(t *testing.T) { checkInvalidTx(t, anteHandler, ctx, tx, false, sdk.CodeUnauthorized) // test num sigs dont match GetSigners - privs, accNums, seqs = []crypto.PrivKey{priv1}, []int64{0}, []int64{0} + privs, accNums, seqs = []crypto.PrivKey{priv1}, []uint64{0}, []uint64{0} tx = newTestTx(ctx, msgs, privs, accNums, seqs, fee) checkInvalidTx(t, anteHandler, ctx, tx, false, sdk.CodeUnauthorized) // test an unrecognized account - privs, accNums, seqs = []crypto.PrivKey{priv1, priv2, priv3}, []int64{0, 1, 2}, []int64{0, 0, 0} + privs, accNums, seqs = []crypto.PrivKey{priv1, priv2, priv3}, []uint64{0, 1, 2}, []uint64{0, 0, 0} tx = newTestTx(ctx, msgs, privs, accNums, seqs, fee) checkInvalidTx(t, anteHandler, ctx, tx, false, sdk.CodeUnknownAddress) @@ -193,30 +193,30 @@ func TestAnteHandlerAccountNumbers(t *testing.T) { msgs := []sdk.Msg{msg} // test good tx from one signer - privs, accnums, seqs := []crypto.PrivKey{priv1}, []int64{0}, []int64{0} + privs, accnums, seqs := []crypto.PrivKey{priv1}, []uint64{0}, []uint64{0} tx = newTestTx(ctx, msgs, privs, accnums, seqs, fee) checkValidTx(t, anteHandler, ctx, tx, false) // new tx from wrong account number - seqs = []int64{1} - tx = newTestTx(ctx, msgs, privs, []int64{1}, seqs, fee) + seqs = []uint64{1} + tx = newTestTx(ctx, msgs, privs, []uint64{1}, seqs, fee) checkInvalidTx(t, anteHandler, ctx, tx, false, sdk.CodeInvalidSequence) // from correct account number - seqs = []int64{1} - tx = newTestTx(ctx, msgs, privs, []int64{0}, seqs, fee) + seqs = []uint64{1} + tx = newTestTx(ctx, msgs, privs, []uint64{0}, seqs, fee) checkValidTx(t, anteHandler, ctx, tx, false) // new tx with another signer and incorrect account numbers msg1 := newTestMsg(addr1, addr2) msg2 := newTestMsg(addr2, addr1) msgs = []sdk.Msg{msg1, msg2} - privs, accnums, seqs = []crypto.PrivKey{priv1, priv2}, []int64{1, 0}, []int64{2, 0} + privs, accnums, seqs = []crypto.PrivKey{priv1, priv2}, []uint64{1, 0}, []uint64{2, 0} tx = newTestTx(ctx, msgs, privs, accnums, seqs, fee) checkInvalidTx(t, anteHandler, ctx, tx, false, sdk.CodeInvalidSequence) // correct account numbers - privs, accnums, seqs = []crypto.PrivKey{priv1, priv2}, []int64{0, 1}, []int64{2, 0} + privs, accnums, seqs = []crypto.PrivKey{priv1, priv2}, []uint64{0, 1}, []uint64{2, 0} tx = newTestTx(ctx, msgs, privs, accnums, seqs, fee) checkValidTx(t, anteHandler, ctx, tx, false) } @@ -253,30 +253,30 @@ func TestAnteHandlerAccountNumbersAtBlockHeightZero(t *testing.T) { msgs := []sdk.Msg{msg} // test good tx from one signer - privs, accnums, seqs := []crypto.PrivKey{priv1}, []int64{0}, []int64{0} + privs, accnums, seqs := []crypto.PrivKey{priv1}, []uint64{0}, []uint64{0} tx = newTestTx(ctx, msgs, privs, accnums, seqs, fee) checkValidTx(t, anteHandler, ctx, tx, false) // new tx from wrong account number - seqs = []int64{1} - tx = newTestTx(ctx, msgs, privs, []int64{1}, seqs, fee) + seqs = []uint64{1} + tx = newTestTx(ctx, msgs, privs, []uint64{1}, seqs, fee) checkInvalidTx(t, anteHandler, ctx, tx, false, sdk.CodeInvalidSequence) // from correct account number - seqs = []int64{1} - tx = newTestTx(ctx, msgs, privs, []int64{0}, seqs, fee) + seqs = []uint64{1} + tx = newTestTx(ctx, msgs, privs, []uint64{0}, seqs, fee) checkValidTx(t, anteHandler, ctx, tx, false) // new tx with another signer and incorrect account numbers msg1 := newTestMsg(addr1, addr2) msg2 := newTestMsg(addr2, addr1) msgs = []sdk.Msg{msg1, msg2} - privs, accnums, seqs = []crypto.PrivKey{priv1, priv2}, []int64{1, 0}, []int64{2, 0} + privs, accnums, seqs = []crypto.PrivKey{priv1, priv2}, []uint64{1, 0}, []uint64{2, 0} tx = newTestTx(ctx, msgs, privs, accnums, seqs, fee) checkInvalidTx(t, anteHandler, ctx, tx, false, sdk.CodeInvalidSequence) // correct account numbers - privs, accnums, seqs = []crypto.PrivKey{priv1, priv2}, []int64{0, 0}, []int64{2, 0} + privs, accnums, seqs = []crypto.PrivKey{priv1, priv2}, []uint64{0, 0}, []uint64{2, 0} tx = newTestTx(ctx, msgs, privs, accnums, seqs, fee) checkValidTx(t, anteHandler, ctx, tx, false) } @@ -317,7 +317,7 @@ func TestAnteHandlerSequences(t *testing.T) { msgs := []sdk.Msg{msg} // test good tx from one signer - privs, accnums, seqs := []crypto.PrivKey{priv1}, []int64{0}, []int64{0} + privs, accnums, seqs := []crypto.PrivKey{priv1}, []uint64{0}, []uint64{0} tx = newTestTx(ctx, msgs, privs, accnums, seqs, fee) checkValidTx(t, anteHandler, ctx, tx, false) @@ -325,7 +325,7 @@ func TestAnteHandlerSequences(t *testing.T) { checkInvalidTx(t, anteHandler, ctx, tx, false, sdk.CodeInvalidSequence) // fix sequence, should pass - seqs = []int64{1} + seqs = []uint64{1} tx = newTestTx(ctx, msgs, privs, accnums, seqs, fee) checkValidTx(t, anteHandler, ctx, tx, false) @@ -334,7 +334,7 @@ func TestAnteHandlerSequences(t *testing.T) { msg2 := newTestMsg(addr3, addr1) msgs = []sdk.Msg{msg1, msg2} - privs, accnums, seqs = []crypto.PrivKey{priv1, priv2, priv3}, []int64{0, 1, 2}, []int64{2, 0, 0} + privs, accnums, seqs = []crypto.PrivKey{priv1, priv2, priv3}, []uint64{0, 1, 2}, []uint64{2, 0, 0} tx = newTestTx(ctx, msgs, privs, accnums, seqs, fee) checkValidTx(t, anteHandler, ctx, tx, false) @@ -344,18 +344,18 @@ func TestAnteHandlerSequences(t *testing.T) { // tx from just second signer with incorrect sequence fails msg = newTestMsg(addr2) msgs = []sdk.Msg{msg} - privs, accnums, seqs = []crypto.PrivKey{priv2}, []int64{1}, []int64{0} + privs, accnums, seqs = []crypto.PrivKey{priv2}, []uint64{1}, []uint64{0} tx = newTestTx(ctx, msgs, privs, accnums, seqs, fee) checkInvalidTx(t, anteHandler, ctx, tx, false, sdk.CodeInvalidSequence) // fix the sequence and it passes - tx = newTestTx(ctx, msgs, []crypto.PrivKey{priv2}, []int64{1}, []int64{1}, fee) + tx = newTestTx(ctx, msgs, []crypto.PrivKey{priv2}, []uint64{1}, []uint64{1}, fee) checkValidTx(t, anteHandler, ctx, tx, false) // another tx from both of them that passes msg = newTestMsg(addr1, addr2) msgs = []sdk.Msg{msg} - privs, accnums, seqs = []crypto.PrivKey{priv1, priv2}, []int64{0, 1}, []int64{3, 2} + privs, accnums, seqs = []crypto.PrivKey{priv1, priv2}, []uint64{0, 1}, []uint64{3, 2} tx = newTestTx(ctx, msgs, privs, accnums, seqs, fee) checkValidTx(t, anteHandler, ctx, tx, false) } @@ -381,7 +381,7 @@ func TestAnteHandlerFees(t *testing.T) { // msg and signatures var tx sdk.Tx msg := newTestMsg(addr1) - privs, accnums, seqs := []crypto.PrivKey{priv1}, []int64{0}, []int64{0} + privs, accnums, seqs := []crypto.PrivKey{priv1}, []uint64{0}, []uint64{0} fee := newStdFee() msgs := []sdk.Msg{msg} @@ -424,7 +424,7 @@ func TestAnteHandlerMemoGas(t *testing.T) { // msg and signatures var tx sdk.Tx msg := newTestMsg(addr1) - privs, accnums, seqs := []crypto.PrivKey{priv1}, []int64{0}, []int64{0} + privs, accnums, seqs := []crypto.PrivKey{priv1}, []uint64{0}, []uint64{0} fee := NewStdFee(0, sdk.NewInt64Coin("atom", 0)) // tx does not have enough gas @@ -483,19 +483,19 @@ func TestAnteHandlerMultiSigner(t *testing.T) { fee := newStdFee() // signers in order - privs, accnums, seqs := []crypto.PrivKey{priv1, priv2, priv3}, []int64{0, 1, 2}, []int64{0, 0, 0} + privs, accnums, seqs := []crypto.PrivKey{priv1, priv2, priv3}, []uint64{0, 1, 2}, []uint64{0, 0, 0} tx = newTestTxWithMemo(ctx, msgs, privs, accnums, seqs, fee, "Check signers are in expected order and different account numbers works") checkValidTx(t, anteHandler, ctx, tx, false) // change sequence numbers - tx = newTestTx(ctx, []sdk.Msg{msg1}, []crypto.PrivKey{priv1, priv2}, []int64{0, 1}, []int64{1, 1}, fee) + tx = newTestTx(ctx, []sdk.Msg{msg1}, []crypto.PrivKey{priv1, priv2}, []uint64{0, 1}, []uint64{1, 1}, fee) checkValidTx(t, anteHandler, ctx, tx, false) - tx = newTestTx(ctx, []sdk.Msg{msg2}, []crypto.PrivKey{priv3, priv1}, []int64{2, 0}, []int64{1, 2}, fee) + tx = newTestTx(ctx, []sdk.Msg{msg2}, []crypto.PrivKey{priv3, priv1}, []uint64{2, 0}, []uint64{1, 2}, fee) checkValidTx(t, anteHandler, ctx, tx, false) // expected seqs = [3, 2, 2] - tx = newTestTxWithMemo(ctx, msgs, privs, accnums, []int64{3, 2, 2}, fee, "Check signers are in expected order and different account numbers and sequence numbers works") + tx = newTestTxWithMemo(ctx, msgs, privs, accnums, []uint64{3, 2, 2}, fee, "Check signers are in expected order and different account numbers and sequence numbers works") checkValidTx(t, anteHandler, ctx, tx, false) } @@ -532,7 +532,7 @@ func TestAnteHandlerBadSignBytes(t *testing.T) { fee3.Amount[0].Amount = fee3.Amount[0].Amount.AddRaw(100) // test good tx and signBytes - privs, accnums, seqs := []crypto.PrivKey{priv1}, []int64{0}, []int64{0} + privs, accnums, seqs := []crypto.PrivKey{priv1}, []uint64{0}, []uint64{0} tx = newTestTx(ctx, msgs, privs, accnums, seqs, fee) checkValidTx(t, anteHandler, ctx, tx, false) @@ -542,8 +542,8 @@ func TestAnteHandlerBadSignBytes(t *testing.T) { cases := []struct { chainID string - accnum int64 - seq int64 + accnum uint64 + seq uint64 fee StdFee msgs []sdk.Msg code sdk.CodeType @@ -556,7 +556,7 @@ func TestAnteHandlerBadSignBytes(t *testing.T) { {chainID, 0, 1, fee3, msgs, codeUnauth}, // test wrong fee } - privs, seqs = []crypto.PrivKey{priv1}, []int64{1} + privs, seqs = []crypto.PrivKey{priv1}, []uint64{1} for _, cs := range cases { tx := newTestTxWithSignBytes( @@ -568,14 +568,14 @@ func TestAnteHandlerBadSignBytes(t *testing.T) { } // test wrong signer if public key exist - privs, accnums, seqs = []crypto.PrivKey{priv2}, []int64{0}, []int64{1} + privs, accnums, seqs = []crypto.PrivKey{priv2}, []uint64{0}, []uint64{1} tx = newTestTx(ctx, msgs, privs, accnums, seqs, fee) checkInvalidTx(t, anteHandler, ctx, tx, false, sdk.CodeUnauthorized) // test wrong signer if public doesn't exist msg = newTestMsg(addr2) msgs = []sdk.Msg{msg} - privs, accnums, seqs = []crypto.PrivKey{priv1}, []int64{1}, []int64{0} + privs, accnums, seqs = []crypto.PrivKey{priv1}, []uint64{1}, []uint64{0} tx = newTestTx(ctx, msgs, privs, accnums, seqs, fee) checkInvalidTx(t, anteHandler, ctx, tx, false, sdk.CodeInvalidPubKey) @@ -609,7 +609,7 @@ func TestAnteHandlerSetPubKey(t *testing.T) { // test good tx and set public key msg := newTestMsg(addr1) msgs := []sdk.Msg{msg} - privs, accnums, seqs := []crypto.PrivKey{priv1}, []int64{0}, []int64{0} + privs, accnums, seqs := []crypto.PrivKey{priv1}, []uint64{0}, []uint64{0} fee := newStdFee() tx = newTestTx(ctx, msgs, privs, accnums, seqs, fee) checkValidTx(t, anteHandler, ctx, tx, false) @@ -620,7 +620,7 @@ func TestAnteHandlerSetPubKey(t *testing.T) { // test public key not found msg = newTestMsg(addr2) msgs = []sdk.Msg{msg} - tx = newTestTx(ctx, msgs, privs, []int64{1}, seqs, fee) + tx = newTestTx(ctx, msgs, privs, []uint64{1}, seqs, fee) sigs := tx.(StdTx).GetSignatures() sigs[0].PubKey = nil checkInvalidTx(t, anteHandler, ctx, tx, false, sdk.CodeInvalidPubKey) @@ -629,7 +629,7 @@ func TestAnteHandlerSetPubKey(t *testing.T) { require.Nil(t, acc2.GetPubKey()) // test invalid signature and public key - tx = newTestTx(ctx, msgs, privs, []int64{1}, seqs, fee) + tx = newTestTx(ctx, msgs, privs, []uint64{1}, seqs, fee) checkInvalidTx(t, anteHandler, ctx, tx, false, sdk.CodeInvalidPubKey) acc2 = mapper.GetAccount(ctx, addr2) @@ -785,7 +785,7 @@ func TestAnteHandlerSigLimitExceeded(t *testing.T) { // test rejection logic privs, accnums, seqs := []crypto.PrivKey{priv1, priv2, priv3, priv4, priv5, priv6, priv7, priv8}, - []int64{0, 0, 0, 0, 0, 0, 0, 0}, []int64{0, 0, 0, 0, 0, 0, 0, 0} + []uint64{0, 0, 0, 0, 0, 0, 0, 0}, []uint64{0, 0, 0, 0, 0, 0, 0, 0} tx = newTestTx(ctx, msgs, privs, accnums, seqs, fee) checkInvalidTx(t, anteHandler, ctx, tx, false, sdk.CodeTooManySignatures) } diff --git a/x/auth/client/rest/sign.go b/x/auth/client/rest/sign.go index 13dd8d20c306..0307db6c1afa 100644 --- a/x/auth/client/rest/sign.go +++ b/x/auth/client/rest/sign.go @@ -18,8 +18,8 @@ type SignBody struct { LocalAccountName string `json:"name"` Password string `json:"password"` ChainID string `json:"chain_id"` - AccountNumber int64 `json:"account_number"` - Sequence int64 `json:"sequence"` + AccountNumber uint64 `json:"account_number"` + Sequence uint64 `json:"sequence"` AppendSig bool `json:"append_sig"` } diff --git a/x/auth/client/txbuilder/stdsignmsg.go b/x/auth/client/txbuilder/stdsignmsg.go index 050a370fffd7..f5c78cc3f929 100644 --- a/x/auth/client/txbuilder/stdsignmsg.go +++ b/x/auth/client/txbuilder/stdsignmsg.go @@ -10,8 +10,8 @@ import ( // it is signed. For use in the CLI. type StdSignMsg struct { ChainID string `json:"chain_id"` - AccountNumber int64 `json:"account_number"` - Sequence int64 `json:"sequence"` + AccountNumber uint64 `json:"account_number"` + Sequence uint64 `json:"sequence"` Fee auth.StdFee `json:"fee"` Msgs []sdk.Msg `json:"msgs"` Memo string `json:"memo"` diff --git a/x/auth/client/txbuilder/txbuilder.go b/x/auth/client/txbuilder/txbuilder.go index 593d745abfeb..8c0ce232be1e 100644 --- a/x/auth/client/txbuilder/txbuilder.go +++ b/x/auth/client/txbuilder/txbuilder.go @@ -14,8 +14,8 @@ import ( // TxBuilder implements a transaction context created in SDK modules. type TxBuilder struct { Codec *codec.Codec - AccountNumber int64 - Sequence int64 + AccountNumber uint64 + Sequence uint64 Gas uint64 GasAdjustment float64 SimulateGas bool @@ -38,10 +38,10 @@ func NewTxBuilderFromCLI() TxBuilder { return TxBuilder{ ChainID: chainID, - AccountNumber: viper.GetInt64(client.FlagAccountNumber), + AccountNumber: uint64(viper.GetInt64(client.FlagAccountNumber)), Gas: client.GasFlagVar.Gas, GasAdjustment: viper.GetFloat64(client.FlagGasAdjustment), - Sequence: viper.GetInt64(client.FlagSequence), + Sequence: uint64(viper.GetInt64(client.FlagSequence)), SimulateGas: client.GasFlagVar.Simulate, Fee: viper.GetString(client.FlagFee), Memo: viper.GetString(client.FlagMemo), @@ -73,7 +73,7 @@ func (bldr TxBuilder) WithFee(fee string) TxBuilder { } // WithSequence returns a copy of the context with an updated sequence number. -func (bldr TxBuilder) WithSequence(sequence int64) TxBuilder { +func (bldr TxBuilder) WithSequence(sequence uint64) TxBuilder { bldr.Sequence = sequence return bldr } @@ -85,7 +85,7 @@ func (bldr TxBuilder) WithMemo(memo string) TxBuilder { } // WithAccountNumber returns a copy of the context with an account number. -func (bldr TxBuilder) WithAccountNumber(accnum int64) TxBuilder { +func (bldr TxBuilder) WithAccountNumber(accnum uint64) TxBuilder { bldr.AccountNumber = accnum return bldr } diff --git a/x/auth/client/txbuilder/txbuilder_test.go b/x/auth/client/txbuilder/txbuilder_test.go index f4f9163a0303..4ff472fef4ff 100644 --- a/x/auth/client/txbuilder/txbuilder_test.go +++ b/x/auth/client/txbuilder/txbuilder_test.go @@ -21,8 +21,8 @@ var ( func TestTxBuilderBuild(t *testing.T) { type fields struct { Codec *codec.Codec - AccountNumber int64 - Sequence int64 + AccountNumber uint64 + Sequence uint64 Gas uint64 GasAdjustment float64 SimulateGas bool diff --git a/x/auth/keeper.go b/x/auth/keeper.go index da5481749fa7..deecaf2b2482 100644 --- a/x/auth/keeper.go +++ b/x/auth/keeper.go @@ -118,7 +118,7 @@ func (am AccountKeeper) GetPubKey(ctx sdk.Context, addr sdk.AccAddress) (crypto. } // Returns the Sequence of the account at address -func (am AccountKeeper) GetSequence(ctx sdk.Context, addr sdk.AccAddress) (int64, sdk.Error) { +func (am AccountKeeper) GetSequence(ctx sdk.Context, addr sdk.AccAddress) (uint64, sdk.Error) { acc := am.GetAccount(ctx, addr) if acc == nil { return 0, sdk.ErrUnknownAddress(addr.String()) @@ -126,7 +126,7 @@ func (am AccountKeeper) GetSequence(ctx sdk.Context, addr sdk.AccAddress) (int64 return acc.GetSequence(), nil } -func (am AccountKeeper) setSequence(ctx sdk.Context, addr sdk.AccAddress, newSequence int64) sdk.Error { +func (am AccountKeeper) setSequence(ctx sdk.Context, addr sdk.AccAddress, newSequence uint64) sdk.Error { acc := am.GetAccount(ctx, addr) if acc == nil { return sdk.ErrUnknownAddress(addr.String()) @@ -141,8 +141,8 @@ func (am AccountKeeper) setSequence(ctx sdk.Context, addr sdk.AccAddress, newSeq } // Returns and increments the global account number counter -func (am AccountKeeper) GetNextAccountNumber(ctx sdk.Context) int64 { - var accNumber int64 +func (am AccountKeeper) GetNextAccountNumber(ctx sdk.Context) uint64 { + var accNumber uint64 store := ctx.KVStore(am.key) bz := store.Get(globalAccountNumberKey) if bz == nil { diff --git a/x/auth/keeper_test.go b/x/auth/keeper_test.go index f1f4c7eaf9d9..8409a7d59367 100644 --- a/x/auth/keeper_test.go +++ b/x/auth/keeper_test.go @@ -49,7 +49,7 @@ func TestAccountMapperGetSet(t *testing.T) { require.Nil(t, mapper.GetAccount(ctx, addr)) // set some values on the account and save it - newSequence := int64(20) + newSequence := uint64(20) acc.SetSequence(newSequence) mapper.SetAccount(ctx, acc) @@ -75,8 +75,8 @@ func TestAccountMapperRemoveAccount(t *testing.T) { acc1 := mapper.NewAccountWithAddress(ctx, addr1) acc2 := mapper.NewAccountWithAddress(ctx, addr2) - accSeq1 := int64(20) - accSeq2 := int64(40) + accSeq1 := uint64(20) + accSeq2 := uint64(40) acc1.SetSequence(accSeq1) acc2.SetSequence(accSeq2) diff --git a/x/auth/stdtx.go b/x/auth/stdtx.go index e8b9461fd982..2f8ae4158349 100644 --- a/x/auth/stdtx.go +++ b/x/auth/stdtx.go @@ -156,16 +156,16 @@ func (fee StdFee) Bytes() []byte { // and the Sequence numbers for each signature (prevent // inchain replay and enforce tx ordering per account). type StdSignDoc struct { - AccountNumber int64 `json:"account_number"` + AccountNumber uint64 `json:"account_number"` ChainID string `json:"chain_id"` Fee json.RawMessage `json:"fee"` Memo string `json:"memo"` Msgs []json.RawMessage `json:"msgs"` - Sequence int64 `json:"sequence"` + Sequence uint64 `json:"sequence"` } // StdSignBytes returns the bytes to sign for a transaction. -func StdSignBytes(chainID string, accnum int64, sequence int64, fee StdFee, msgs []sdk.Msg, memo string) []byte { +func StdSignBytes(chainID string, accnum uint64, sequence uint64, fee StdFee, msgs []sdk.Msg, memo string) []byte { var msgsBytes []json.RawMessage for _, msg := range msgs { msgsBytes = append(msgsBytes, json.RawMessage(msg.GetSignBytes())) @@ -188,8 +188,8 @@ func StdSignBytes(chainID string, accnum int64, sequence int64, fee StdFee, msgs type StdSignature struct { crypto.PubKey `json:"pub_key"` // optional Signature []byte `json:"signature"` - AccountNumber int64 `json:"account_number"` - Sequence int64 `json:"sequence"` + AccountNumber uint64 `json:"account_number"` + Sequence uint64 `json:"sequence"` } // logic for standard transaction decoding diff --git a/x/auth/stdtx_test.go b/x/auth/stdtx_test.go index a3267ac192a8..ee6556101244 100644 --- a/x/auth/stdtx_test.go +++ b/x/auth/stdtx_test.go @@ -34,8 +34,8 @@ func TestStdTx(t *testing.T) { func TestStdSignBytes(t *testing.T) { type args struct { chainID string - accnum int64 - sequence int64 + accnum uint64 + sequence uint64 fee StdFee msgs []sdk.Msg memo string @@ -85,7 +85,7 @@ func TestTxValidateBasic(t *testing.T) { require.Equal(t, sdk.CodeInsufficientFee, err.Result().Code) // require to fail validation when no signatures exist - privs, accNums, seqs := []crypto.PrivKey{}, []int64{}, []int64{} + privs, accNums, seqs := []crypto.PrivKey{}, []uint64{}, []uint64{} tx = newTestTx(ctx, msgs, privs, accNums, seqs, fee) err = tx.ValidateBasic() @@ -93,7 +93,7 @@ func TestTxValidateBasic(t *testing.T) { require.Equal(t, sdk.CodeUnauthorized, err.Result().Code) // require to fail validation when signatures do not match expected signers - privs, accNums, seqs = []crypto.PrivKey{priv1}, []int64{0, 1}, []int64{0, 0} + privs, accNums, seqs = []crypto.PrivKey{priv1}, []uint64{0, 1}, []uint64{0, 0} tx = newTestTx(ctx, msgs, privs, accNums, seqs, fee) err = tx.ValidateBasic() @@ -102,7 +102,7 @@ func TestTxValidateBasic(t *testing.T) { // require to fail validation when memo is too large badMemo := strings.Repeat("bad memo", 50) - privs, accNums, seqs = []crypto.PrivKey{priv1, priv2}, []int64{0, 1}, []int64{0, 0} + privs, accNums, seqs = []crypto.PrivKey{priv1, priv2}, []uint64{0, 1}, []uint64{0, 0} tx = newTestTxWithMemo(ctx, msgs, privs, accNums, seqs, fee, badMemo) err = tx.ValidateBasic() @@ -111,7 +111,7 @@ func TestTxValidateBasic(t *testing.T) { // require to fail validation when there are too many signatures privs = []crypto.PrivKey{priv1, priv2, priv3, priv4, priv5, priv6, priv7, priv8} - accNums, seqs = []int64{0, 0, 0, 0, 0, 0, 0, 0}, []int64{0, 0, 0, 0, 0, 0, 0, 0} + accNums, seqs = []uint64{0, 0, 0, 0, 0, 0, 0, 0}, []uint64{0, 0, 0, 0, 0, 0, 0, 0} badMsg := newTestMsg(addr1, addr2, addr3, addr4, addr5, addr6, addr7, addr8) badMsgs := []sdk.Msg{badMsg} tx = newTestTx(ctx, badMsgs, privs, accNums, seqs, fee) @@ -121,7 +121,7 @@ func TestTxValidateBasic(t *testing.T) { require.Equal(t, sdk.CodeTooManySignatures, err.Result().Code) // require to pass when above criteria are matched - privs, accNums, seqs = []crypto.PrivKey{priv1, priv2}, []int64{0, 1}, []int64{0, 0} + privs, accNums, seqs = []crypto.PrivKey{priv1, priv2}, []uint64{0, 1}, []uint64{0, 0} tx = newTestTx(ctx, msgs, privs, accNums, seqs, fee) err = tx.ValidateBasic() diff --git a/x/bank/app_test.go b/x/bank/app_test.go index c71a9b392b5a..128705b58300 100644 --- a/x/bank/app_test.go +++ b/x/bank/app_test.go @@ -24,8 +24,8 @@ type ( expSimPass bool expPass bool msgs []sdk.Msg - accNums []int64 - accSeqs []int64 + accNums []uint64 + accSeqs []uint64 privKeys []crypto.PrivKey expectedBalances []expectedBalance } @@ -109,8 +109,8 @@ func TestMsgSendWithAccounts(t *testing.T) { testCases := []appTestCase{ { msgs: []sdk.Msg{sendMsg1}, - accNums: []int64{0}, - accSeqs: []int64{0}, + accNums: []uint64{0}, + accSeqs: []uint64{0}, expSimPass: true, expPass: true, privKeys: []crypto.PrivKey{priv1}, @@ -121,8 +121,8 @@ func TestMsgSendWithAccounts(t *testing.T) { }, { msgs: []sdk.Msg{sendMsg1, sendMsg2}, - accNums: []int64{0}, - accSeqs: []int64{0}, + accNums: []uint64{0}, + accSeqs: []uint64{0}, expSimPass: false, expPass: false, privKeys: []crypto.PrivKey{priv1}, @@ -140,7 +140,7 @@ func TestMsgSendWithAccounts(t *testing.T) { // bumping the tx nonce number without resigning should be an auth error mapp.BeginBlock(abci.RequestBeginBlock{}) - tx := mock.GenTx([]sdk.Msg{sendMsg1}, []int64{0}, []int64{0}, priv1) + tx := mock.GenTx([]sdk.Msg{sendMsg1}, []uint64{0}, []uint64{0}, priv1) tx.Signatures[0].Sequence = 1 res := mapp.Deliver(tx) @@ -148,7 +148,7 @@ func TestMsgSendWithAccounts(t *testing.T) { require.EqualValues(t, sdk.CodespaceRoot, res.Codespace) // resigning the tx with the bumped sequence should work - mock.SignCheckDeliver(t, mapp.BaseApp, []sdk.Msg{sendMsg1, sendMsg2}, []int64{0}, []int64{1}, true, true, priv1) + mock.SignCheckDeliver(t, mapp.BaseApp, []sdk.Msg{sendMsg1, sendMsg2}, []uint64{0}, []uint64{1}, true, true, priv1) } func TestMsgSendMultipleOut(t *testing.T) { @@ -168,8 +168,8 @@ func TestMsgSendMultipleOut(t *testing.T) { testCases := []appTestCase{ { msgs: []sdk.Msg{sendMsg2}, - accNums: []int64{0}, - accSeqs: []int64{0}, + accNums: []uint64{0}, + accSeqs: []uint64{0}, expSimPass: true, expPass: true, privKeys: []crypto.PrivKey{priv1}, @@ -211,8 +211,8 @@ func TestSengMsgMultipleInOut(t *testing.T) { testCases := []appTestCase{ { msgs: []sdk.Msg{sendMsg3}, - accNums: []int64{0, 0}, - accSeqs: []int64{0, 0}, + accNums: []uint64{0, 0}, + accSeqs: []uint64{0, 0}, expSimPass: true, expPass: true, privKeys: []crypto.PrivKey{priv1, priv4}, @@ -247,8 +247,8 @@ func TestMsgSendDependent(t *testing.T) { testCases := []appTestCase{ { msgs: []sdk.Msg{sendMsg1}, - accNums: []int64{0}, - accSeqs: []int64{0}, + accNums: []uint64{0}, + accSeqs: []uint64{0}, expSimPass: true, expPass: true, privKeys: []crypto.PrivKey{priv1}, @@ -259,8 +259,8 @@ func TestMsgSendDependent(t *testing.T) { }, { msgs: []sdk.Msg{sendMsg4}, - accNums: []int64{0}, - accSeqs: []int64{0}, + accNums: []uint64{0}, + accSeqs: []uint64{0}, expSimPass: true, expPass: true, privKeys: []crypto.PrivKey{priv2}, diff --git a/x/bank/bench_test.go b/x/bank/bench_test.go index bff99da996c8..a3f69dcdd4d8 100644 --- a/x/bank/bench_test.go +++ b/x/bank/bench_test.go @@ -37,7 +37,7 @@ func BenchmarkOneBankSendTxPerBlock(b *testing.B) { // Construct genesis state mock.SetGenesis(benchmarkApp, accs) // Precompute all txs - txs := mock.GenSequenceOfTxs([]sdk.Msg{sendMsg1}, []int64{0}, []int64{int64(0)}, b.N, priv1) + txs := mock.GenSequenceOfTxs([]sdk.Msg{sendMsg1}, []uint64{0}, []uint64{uint64(0)}, b.N, priv1) b.ResetTimer() // Run this with a profiler, so its easy to distinguish what time comes from // Committing, and what time comes from Check/Deliver Tx. diff --git a/x/bank/simulation/msgs.go b/x/bank/simulation/msgs.go index f1fd866c1fe4..78b1f1945290 100644 --- a/x/bank/simulation/msgs.go +++ b/x/bank/simulation/msgs.go @@ -95,8 +95,8 @@ func createSingleInputSendMsg(r *rand.Rand, ctx sdk.Context, accs []simulation.A func sendAndVerifyMsgSend(app *baseapp.BaseApp, mapper auth.AccountKeeper, msg bank.MsgSend, ctx sdk.Context, privkeys []crypto.PrivKey, handler sdk.Handler) error { initialInputAddrCoins := make([]sdk.Coins, len(msg.Inputs)) initialOutputAddrCoins := make([]sdk.Coins, len(msg.Outputs)) - AccountNumbers := make([]int64, len(msg.Inputs)) - SequenceNumbers := make([]int64, len(msg.Inputs)) + AccountNumbers := make([]uint64, len(msg.Inputs)) + SequenceNumbers := make([]uint64, len(msg.Inputs)) for i := 0; i < len(msg.Inputs); i++ { acc := mapper.GetAccount(ctx, msg.Inputs[i].Address) diff --git a/x/ibc/app_test.go b/x/ibc/app_test.go index e59588a5aca3..f59b37921b93 100644 --- a/x/ibc/app_test.go +++ b/x/ibc/app_test.go @@ -70,10 +70,10 @@ func TestIBCMsgs(t *testing.T) { Sequence: 0, } - mock.SignCheckDeliver(t, mapp.BaseApp, []sdk.Msg{transferMsg}, []int64{0}, []int64{0}, true, true, priv1) + mock.SignCheckDeliver(t, mapp.BaseApp, []sdk.Msg{transferMsg}, []uint64{0}, []uint64{0}, true, true, priv1) mock.CheckBalance(t, mapp, addr1, emptyCoins) - mock.SignCheckDeliver(t, mapp.BaseApp, []sdk.Msg{transferMsg}, []int64{0}, []int64{1}, false, false, priv1) - mock.SignCheckDeliver(t, mapp.BaseApp, []sdk.Msg{receiveMsg}, []int64{0}, []int64{2}, true, true, priv1) + mock.SignCheckDeliver(t, mapp.BaseApp, []sdk.Msg{transferMsg}, []uint64{0}, []uint64{1}, false, false, priv1) + mock.SignCheckDeliver(t, mapp.BaseApp, []sdk.Msg{receiveMsg}, []uint64{0}, []uint64{2}, true, true, priv1) mock.CheckBalance(t, mapp, addr1, coins) - mock.SignCheckDeliver(t, mapp.BaseApp, []sdk.Msg{receiveMsg}, []int64{0}, []int64{2}, false, false, priv1) + mock.SignCheckDeliver(t, mapp.BaseApp, []sdk.Msg{receiveMsg}, []uint64{0}, []uint64{2}, false, false, priv1) } diff --git a/x/ibc/client/cli/relay.go b/x/ibc/client/cli/relay.go index 217d7cdee8e9..4ada207b8462 100644 --- a/x/ibc/client/cli/relay.go +++ b/x/ibc/client/cli/relay.go @@ -113,7 +113,7 @@ OUTER: panic(err) } - var processed int64 + var processed uint64 if processedbz == nil { processed = 0 } else if err = c.cdc.UnmarshalBinaryLengthPrefixed(processedbz, &processed); err != nil { @@ -127,7 +127,7 @@ OUTER: continue OUTER //TODO replace with continue (I think it should just to the correct place where OUTER is now) } - var egressLength int64 + var egressLength uint64 if egressLengthbz == nil { egressLength = 0 } else if err = c.cdc.UnmarshalBinaryLengthPrefixed(egressLengthbz, &egressLength); err != nil { @@ -166,12 +166,12 @@ func query(node string, key []byte, storeName string) (res []byte, err error) { } // nolint: unparam -func (c relayCommander) broadcastTx(seq int64, node string, tx []byte) error { +func (c relayCommander) broadcastTx(seq uint64, node string, tx []byte) error { _, err := context.NewCLIContext().WithNodeURI(node).BroadcastTx(tx) return err } -func (c relayCommander) getSequence(node string) int64 { +func (c relayCommander) getSequence(node string) uint64 { res, err := query(node, c.address, c.accStore) if err != nil { panic(err) @@ -189,7 +189,7 @@ func (c relayCommander) getSequence(node string) int64 { return 0 } -func (c relayCommander) refine(bz []byte, sequence int64, passphrase string) []byte { +func (c relayCommander) refine(bz []byte, sequence uint64, passphrase string) []byte { var packet ibc.IBCPacket if err := c.cdc.UnmarshalBinaryLengthPrefixed(bz, &packet); err != nil { panic(err) diff --git a/x/ibc/ibc_test.go b/x/ibc/ibc_test.go index 94c3c7a2ecb2..2fa24a6c7c3c 100644 --- a/x/ibc/ibc_test.go +++ b/x/ibc/ibc_test.go @@ -90,11 +90,11 @@ func TestIBC(t *testing.T) { var msg sdk.Msg var res sdk.Result - var egl int64 - var igs int64 + var egl uint64 + var igs uint64 egl = ibcm.getEgressLength(store, chainid) - require.Equal(t, egl, int64(0)) + require.Equal(t, egl, uint64(0)) msg = IBCTransferMsg{ IBCPacket: packet, @@ -107,10 +107,10 @@ func TestIBC(t *testing.T) { require.Equal(t, zero, coins) egl = ibcm.getEgressLength(store, chainid) - require.Equal(t, egl, int64(1)) + require.Equal(t, egl, uint64(1)) igs = ibcm.GetIngressSequence(ctx, chainid) - require.Equal(t, igs, int64(0)) + require.Equal(t, igs, uint64(0)) msg = IBCReceiveMsg{ IBCPacket: packet, @@ -125,11 +125,11 @@ func TestIBC(t *testing.T) { require.Equal(t, mycoins, coins) igs = ibcm.GetIngressSequence(ctx, chainid) - require.Equal(t, igs, int64(1)) + require.Equal(t, igs, uint64(1)) res = h(ctx, msg) require.False(t, res.IsOK()) igs = ibcm.GetIngressSequence(ctx, chainid) - require.Equal(t, igs, int64(1)) + require.Equal(t, igs, uint64(1)) } diff --git a/x/ibc/mapper.go b/x/ibc/mapper.go index 957ab191a8a3..101fac03393e 100644 --- a/x/ibc/mapper.go +++ b/x/ibc/mapper.go @@ -76,7 +76,7 @@ func unmarshalBinaryPanic(cdc *codec.Codec, bz []byte, ptr interface{}) { } // TODO add description -func (ibcm Mapper) GetIngressSequence(ctx sdk.Context, srcChain string) int64 { +func (ibcm Mapper) GetIngressSequence(ctx sdk.Context, srcChain string) uint64 { store := ctx.KVStore(ibcm.key) key := IngressSequenceKey(srcChain) @@ -87,13 +87,13 @@ func (ibcm Mapper) GetIngressSequence(ctx sdk.Context, srcChain string) int64 { return 0 } - var res int64 + var res uint64 unmarshalBinaryPanic(ibcm.cdc, bz, &res) return res } // TODO add description -func (ibcm Mapper) SetIngressSequence(ctx sdk.Context, srcChain string, sequence int64) { +func (ibcm Mapper) SetIngressSequence(ctx sdk.Context, srcChain string, sequence uint64) { store := ctx.KVStore(ibcm.key) key := IngressSequenceKey(srcChain) @@ -102,20 +102,20 @@ func (ibcm Mapper) SetIngressSequence(ctx sdk.Context, srcChain string, sequence } // Retrieves the index of the currently stored outgoing IBC packets. -func (ibcm Mapper) getEgressLength(store sdk.KVStore, destChain string) int64 { +func (ibcm Mapper) getEgressLength(store sdk.KVStore, destChain string) uint64 { bz := store.Get(EgressLengthKey(destChain)) if bz == nil { zero := marshalBinaryPanic(ibcm.cdc, int64(0)) store.Set(EgressLengthKey(destChain), zero) return 0 } - var res int64 + var res uint64 unmarshalBinaryPanic(ibcm.cdc, bz, &res) return res } // Stores an outgoing IBC packet under "egress/chain_id/index". -func EgressKey(destChain string, index int64) []byte { +func EgressKey(destChain string, index uint64) []byte { return []byte(fmt.Sprintf("egress/%s/%d", destChain, index)) } diff --git a/x/ibc/types.go b/x/ibc/types.go index 72dae0d389d0..0f596bb03554 100644 --- a/x/ibc/types.go +++ b/x/ibc/types.go @@ -96,7 +96,7 @@ func (msg IBCTransferMsg) ValidateBasic() sdk.Error { type IBCReceiveMsg struct { IBCPacket Relayer sdk.AccAddress - Sequence int64 + Sequence uint64 } // nolint @@ -112,7 +112,7 @@ func (msg IBCReceiveMsg) GetSignBytes() []byte { b, err := msgCdc.MarshalJSON(struct { IBCPacket json.RawMessage Relayer sdk.AccAddress - Sequence int64 + Sequence uint64 }{ IBCPacket: json.RawMessage(msg.IBCPacket.GetSignBytes()), Relayer: msg.Relayer, diff --git a/x/mock/app.go b/x/mock/app.go index 0b7b0ae16bf0..6382ba05bf09 100644 --- a/x/mock/app.go +++ b/x/mock/app.go @@ -185,7 +185,7 @@ func SetGenesis(app *App, accs []auth.Account) { } // GenTx generates a signed mock transaction. -func GenTx(msgs []sdk.Msg, accnums []int64, seq []int64, priv ...crypto.PrivKey) auth.StdTx { +func GenTx(msgs []sdk.Msg, accnums []uint64, seq []uint64, priv ...crypto.PrivKey) auth.StdTx { // Make the transaction free fee := auth.StdFee{ Amount: sdk.Coins{sdk.NewInt64Coin("foocoin", 0)}, @@ -304,7 +304,7 @@ func GetAllAccounts(mapper auth.AccountKeeper, ctx sdk.Context) []auth.Account { // GenSequenceOfTxs generates a set of signed transactions of messages, such // that they differ only by having the sequence numbers incremented between // every transaction. -func GenSequenceOfTxs(msgs []sdk.Msg, accnums []int64, initSeqNums []int64, numToGenerate int, priv ...crypto.PrivKey) []auth.StdTx { +func GenSequenceOfTxs(msgs []sdk.Msg, accnums []uint64, initSeqNums []uint64, numToGenerate int, priv ...crypto.PrivKey) []auth.StdTx { txs := make([]auth.StdTx, numToGenerate, numToGenerate) for i := 0; i < numToGenerate; i++ { txs[i] = GenTx(msgs, accnums, initSeqNums, priv...) @@ -314,7 +314,7 @@ func GenSequenceOfTxs(msgs []sdk.Msg, accnums []int64, initSeqNums []int64, numT return txs } -func incrementAllSequenceNumbers(initSeqNums []int64) { +func incrementAllSequenceNumbers(initSeqNums []uint64) { for i := 0; i < len(initSeqNums); i++ { initSeqNums[i]++ } diff --git a/x/mock/app_test.go b/x/mock/app_test.go index c47ddb7179fc..1af0e4a033b6 100644 --- a/x/mock/app_test.go +++ b/x/mock/app_test.go @@ -61,14 +61,14 @@ func TestCheckAndDeliverGenTx(t *testing.T) { SignCheckDeliver( t, mApp.BaseApp, []sdk.Msg{msg}, - []int64{accs[0].GetAccountNumber()}, []int64{accs[0].GetSequence()}, + []uint64{accs[0].GetAccountNumber()}, []uint64{accs[0].GetSequence()}, true, true, privKeys[0], ) // Signing a tx with the wrong privKey should result in an auth error res := SignCheckDeliver( t, mApp.BaseApp, []sdk.Msg{msg}, - []int64{accs[1].GetAccountNumber()}, []int64{accs[1].GetSequence() + 1}, + []uint64{accs[1].GetAccountNumber()}, []uint64{accs[1].GetSequence() + 1}, true, false, privKeys[1], ) @@ -78,7 +78,7 @@ func TestCheckAndDeliverGenTx(t *testing.T) { // Resigning the tx with the correct privKey should result in an OK result SignCheckDeliver( t, mApp.BaseApp, []sdk.Msg{msg}, - []int64{accs[0].GetAccountNumber()}, []int64{accs[0].GetSequence() + 1}, + []uint64{accs[0].GetAccountNumber()}, []uint64{accs[0].GetSequence() + 1}, true, true, privKeys[0], ) } @@ -92,14 +92,14 @@ func TestCheckGenTx(t *testing.T) { msg1 := testMsg{signers: []sdk.AccAddress{addrs[0]}, positiveNum: 1} CheckGenTx( t, mApp.BaseApp, []sdk.Msg{msg1}, - []int64{accs[0].GetAccountNumber()}, []int64{accs[0].GetSequence()}, + []uint64{accs[0].GetAccountNumber()}, []uint64{accs[0].GetSequence()}, true, privKeys[0], ) msg2 := testMsg{signers: []sdk.AccAddress{addrs[0]}, positiveNum: -1} CheckGenTx( t, mApp.BaseApp, []sdk.Msg{msg2}, - []int64{accs[0].GetAccountNumber()}, []int64{accs[0].GetSequence()}, + []uint64{accs[0].GetAccountNumber()}, []uint64{accs[0].GetSequence()}, false, privKeys[0], ) } diff --git a/x/mock/test_utils.go b/x/mock/test_utils.go index 130339d0e77f..4d5fe05f33c2 100644 --- a/x/mock/test_utils.go +++ b/x/mock/test_utils.go @@ -50,8 +50,8 @@ func CheckBalance(t *testing.T, app *App, addr sdk.AccAddress, exp sdk.Coins) { // compared against the parameter 'expPass'. A test assertion is made using the // parameter 'expPass' against the result. A corresponding result is returned. func CheckGenTx( - t *testing.T, app *baseapp.BaseApp, msgs []sdk.Msg, accNums []int64, - seq []int64, expPass bool, priv ...crypto.PrivKey, + t *testing.T, app *baseapp.BaseApp, msgs []sdk.Msg, accNums []uint64, + seq []uint64, expPass bool, priv ...crypto.PrivKey, ) sdk.Result { tx := GenTx(msgs, accNums, seq, priv...) res := app.Check(tx) @@ -70,8 +70,8 @@ func CheckGenTx( // the parameter 'expPass' against the result. A corresponding result is // returned. func SignCheckDeliver( - t *testing.T, app *baseapp.BaseApp, msgs []sdk.Msg, accNums []int64, - seq []int64, expSimPass, expPass bool, priv ...crypto.PrivKey, + t *testing.T, app *baseapp.BaseApp, msgs []sdk.Msg, accNums []uint64, + seq []uint64, expSimPass, expPass bool, priv ...crypto.PrivKey, ) sdk.Result { tx := GenTx(msgs, accNums, seq, priv...) // Must simulate now as CheckTx doesn't run Msgs anymore diff --git a/x/slashing/app_test.go b/x/slashing/app_test.go index bfcbcba0b2bf..279844a4ce7b 100644 --- a/x/slashing/app_test.go +++ b/x/slashing/app_test.go @@ -111,7 +111,7 @@ func TestSlashingMsgs(t *testing.T) { createValidatorMsg := stake.NewMsgCreateValidator( sdk.ValAddress(addr1), priv1.PubKey(), bondCoin, description, commission, ) - mock.SignCheckDeliver(t, mapp.BaseApp, []sdk.Msg{createValidatorMsg}, []int64{0}, []int64{0}, true, true, priv1) + mock.SignCheckDeliver(t, mapp.BaseApp, []sdk.Msg{createValidatorMsg}, []uint64{0}, []uint64{0}, true, true, priv1) mock.CheckBalance(t, mapp, addr1, sdk.Coins{genCoin.Minus(bondCoin)}) mapp.BeginBlock(abci.RequestBeginBlock{}) @@ -125,7 +125,7 @@ func TestSlashingMsgs(t *testing.T) { checkValidatorSigningInfo(t, mapp, keeper, sdk.ConsAddress(addr1), false) // unjail should fail with unknown validator - res := mock.SignCheckDeliver(t, mapp.BaseApp, []sdk.Msg{unjailMsg}, []int64{0}, []int64{1}, false, false, priv1) + res := mock.SignCheckDeliver(t, mapp.BaseApp, []sdk.Msg{unjailMsg}, []uint64{0}, []uint64{1}, false, false, priv1) require.EqualValues(t, CodeValidatorNotJailed, res.Code) require.EqualValues(t, DefaultCodespace, res.Codespace) } diff --git a/x/stake/app_test.go b/x/stake/app_test.go index 2866acf1d15a..f6c887c29133 100644 --- a/x/stake/app_test.go +++ b/x/stake/app_test.go @@ -125,7 +125,7 @@ func TestStakeMsgs(t *testing.T) { sdk.ValAddress(addr1), priv1.PubKey(), bondCoin, description, commissionMsg, ) - mock.SignCheckDeliver(t, mApp.BaseApp, []sdk.Msg{createValidatorMsg}, []int64{0}, []int64{0}, true, true, priv1) + mock.SignCheckDeliver(t, mApp.BaseApp, []sdk.Msg{createValidatorMsg}, []uint64{0}, []uint64{0}, true, true, priv1) mock.CheckBalance(t, mApp, addr1, sdk.Coins{genCoin.Minus(bondCoin)}) mApp.BeginBlock(abci.RequestBeginBlock{}) @@ -139,7 +139,7 @@ func TestStakeMsgs(t *testing.T) { addr1, sdk.ValAddress(addr2), priv2.PubKey(), bondCoin, description, commissionMsg, ) - mock.SignCheckDeliver(t, mApp.BaseApp, []sdk.Msg{createValidatorMsgOnBehalfOf}, []int64{0, 0}, []int64{1, 0}, true, true, priv1, priv2) + mock.SignCheckDeliver(t, mApp.BaseApp, []sdk.Msg{createValidatorMsgOnBehalfOf}, []uint64{0, 0}, []uint64{1, 0}, true, true, priv1, priv2) mock.CheckBalance(t, mApp, addr1, sdk.Coins{genCoin.Minus(bondCoin).Minus(bondCoin)}) mApp.BeginBlock(abci.RequestBeginBlock{}) @@ -155,7 +155,7 @@ func TestStakeMsgs(t *testing.T) { description = NewDescription("bar_moniker", "", "", "") editValidatorMsg := NewMsgEditValidator(sdk.ValAddress(addr1), description, nil) - mock.SignCheckDeliver(t, mApp.BaseApp, []sdk.Msg{editValidatorMsg}, []int64{0}, []int64{2}, true, true, priv1) + mock.SignCheckDeliver(t, mApp.BaseApp, []sdk.Msg{editValidatorMsg}, []uint64{0}, []uint64{2}, true, true, priv1) validator = checkValidator(t, mApp, keeper, sdk.ValAddress(addr1), true) require.Equal(t, description, validator.Description) @@ -163,13 +163,13 @@ func TestStakeMsgs(t *testing.T) { mock.CheckBalance(t, mApp, addr2, sdk.Coins{genCoin}) delegateMsg := NewMsgDelegate(addr2, sdk.ValAddress(addr1), bondCoin) - mock.SignCheckDeliver(t, mApp.BaseApp, []sdk.Msg{delegateMsg}, []int64{0}, []int64{1}, true, true, priv2) + mock.SignCheckDeliver(t, mApp.BaseApp, []sdk.Msg{delegateMsg}, []uint64{0}, []uint64{1}, true, true, priv2) mock.CheckBalance(t, mApp, addr2, sdk.Coins{genCoin.Minus(bondCoin)}) checkDelegation(t, mApp, keeper, addr2, sdk.ValAddress(addr1), true, sdk.NewDec(10)) // begin unbonding beginUnbondingMsg := NewMsgBeginUnbonding(addr2, sdk.ValAddress(addr1), sdk.NewDec(10)) - mock.SignCheckDeliver(t, mApp.BaseApp, []sdk.Msg{beginUnbondingMsg}, []int64{0}, []int64{2}, true, true, priv2) + mock.SignCheckDeliver(t, mApp.BaseApp, []sdk.Msg{beginUnbondingMsg}, []uint64{0}, []uint64{2}, true, true, priv2) // delegation should exist anymore checkDelegation(t, mApp, keeper, addr2, sdk.ValAddress(addr1), false, sdk.Dec{})