From 6af10a1f8a3f6d6d5775d8d2718779361f3c1b6d Mon Sep 17 00:00:00 2001 From: Bartek Nowotarski Date: Fri, 27 May 2022 14:35:53 +0200 Subject: [PATCH] protocols/horizon: Change Transaction.AccountSequence to int64 (#4409) Change `protocols/horizon.Transaction.AccountSequence` to `int64` from `string`. There shouldn't be any extra parsing required in Go since `AccountSequence` returned by Horizon will be always a valid int64 value. We can make sure the value is rendered as a string to support JS using `string` tag. --- clients/horizonclient/CHANGELOG.md | 3 +++ protocols/horizon/main.go | 2 +- .../internal/actions_transaction_test.go | 14 +++++----- .../internal/db2/history/fee_bump_scenario.go | 4 +-- .../transaction_batch_insert_builder.go | 5 ++-- .../internal/db2/history/transaction_test.go | 26 +++++++++---------- .../internal/db2/history/txsub_result_test.go | 2 +- .../internal/integration/txsub_test.go | 3 +-- .../resourceadapter/operations_test.go | 20 ++++++++------ .../resourceadapter/transaction_test.go | 2 ++ 10 files changed, 44 insertions(+), 37 deletions(-) diff --git a/clients/horizonclient/CHANGELOG.md b/clients/horizonclient/CHANGELOG.md index d1c5514ac7..ee5cacce2a 100644 --- a/clients/horizonclient/CHANGELOG.md +++ b/clients/horizonclient/CHANGELOG.md @@ -3,6 +3,9 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## Unreleased + +* Type of `AccountSequence` field in `protocols/horizon.Account` was changed to `int64`. ## [v10.0.0](https://github.com/stellar/go/releases/tag/horizonclient-v10.0.0) - 2022-04-18 diff --git a/protocols/horizon/main.go b/protocols/horizon/main.go index 8c5635860a..e5862805d8 100644 --- a/protocols/horizon/main.go +++ b/protocols/horizon/main.go @@ -511,7 +511,7 @@ type Transaction struct { Account string `json:"source_account"` AccountMuxed string `json:"account_muxed,omitempty"` AccountMuxedID uint64 `json:"account_muxed_id,omitempty,string"` - AccountSequence string `json:"source_account_sequence"` + AccountSequence int64 `json:"source_account_sequence,string"` FeeAccount string `json:"fee_account"` FeeAccountMuxed string `json:"fee_account_muxed,omitempty"` FeeAccountMuxedID uint64 `json:"fee_account_muxed_id,omitempty,string"` diff --git a/services/horizon/internal/actions_transaction_test.go b/services/horizon/internal/actions_transaction_test.go index 605a0a8f69..940426b947 100644 --- a/services/horizon/internal/actions_transaction_test.go +++ b/services/horizon/internal/actions_transaction_test.go @@ -340,7 +340,7 @@ func TestTransactionActions_PostSuccessful(t *testing.T) { w := ht.Post("/transactions", form) ht.Assert.Equal(200, w.Code) - ht.Assert.Contains(string(w.Body.Bytes()), `"result_xdr": "AAAAAAAAAGQAAAAAAAAAAQAAAAAAAAABAAAAAAAAAAA="`) + ht.Assert.Contains(w.Body.String(), `"result_xdr": "AAAAAAAAAGQAAAAAAAAAAQAAAAAAAAABAAAAAAAAAAA="`) } func TestTransactionActions_PostFailed(t *testing.T) { @@ -355,8 +355,8 @@ func TestTransactionActions_PostFailed(t *testing.T) { w := ht.Post("/transactions", form) ht.Assert.Equal(400, w.Code) - ht.Assert.Contains(string(w.Body.Bytes()), "op_underfunded") - ht.Assert.Contains(string(w.Body.Bytes()), `"result_xdr": "AAAAAAAAAGT/////AAAAAQAAAAAAAAAB/////gAAAAA="`) + ht.Assert.Contains(w.Body.String(), "op_underfunded") + ht.Assert.Contains(w.Body.String(), `"result_xdr": "AAAAAAAAAGT/////AAAAAQAAAAAAAAAB/////gAAAAA="`) } func TestPostFeeBumpTransaction(t *testing.T) { @@ -412,14 +412,14 @@ func TestPostFailedFeeBumpTransaction(t *testing.T) { form := url.Values{"tx": []string{fixture.Transaction.TxEnvelope}} w := ht.Post("/transactions", form) ht.Assert.Equal(400, w.Code) - ht.Assert.Contains(string(w.Body.Bytes()), "tx_fee_bump_inner_failed") - ht.Assert.Contains(string(w.Body.Bytes()), "tx_bad_auth") + ht.Assert.Contains(w.Body.String(), "tx_fee_bump_inner_failed") + ht.Assert.Contains(w.Body.String(), "tx_bad_auth") innerTxEnvelope, err := xdr.MarshalBase64(fixture.Envelope.FeeBump.Tx.InnerTx.V1) ht.Assert.NoError(err) form = url.Values{"tx": []string{innerTxEnvelope}} w = ht.Post("/transactions", form) ht.Assert.Equal(400, w.Code) - ht.Assert.Contains(string(w.Body.Bytes()), "tx_bad_auth") - ht.Assert.NotContains(string(w.Body.Bytes()), "tx_fee_bump_inner_failed") + ht.Assert.Contains(w.Body.String(), "tx_bad_auth") + ht.Assert.NotContains(w.Body.String(), "tx_fee_bump_inner_failed") } diff --git a/services/horizon/internal/db2/history/fee_bump_scenario.go b/services/horizon/internal/db2/history/fee_bump_scenario.go index 8f488b03d3..83093a2aa8 100644 --- a/services/horizon/internal/db2/history/fee_bump_scenario.go +++ b/services/horizon/internal/db2/history/fee_bump_scenario.go @@ -307,7 +307,7 @@ func FeeBumpScenario(tt *test.T, q *Q, successful bool) FeeBumpFixture { LedgerSequence: fixture.Ledger.Sequence, ApplicationOrder: 1, Account: account.Address(), - AccountSequence: "97", + AccountSequence: 97, MaxFee: int64(fixture.Envelope.Fee()), FeeCharged: int64(resultPair.Result.FeeCharged), OperationCount: 1, @@ -336,7 +336,7 @@ func FeeBumpScenario(tt *test.T, q *Q, successful bool) FeeBumpFixture { LedgerSequence: fixture.Ledger.Sequence, ApplicationOrder: 1, Account: "GAUJETIZVEP2NRYLUESJ3LS66NVCEGMON4UDCBCSBEVPIID773P2W6AY", - AccountSequence: "78621794419880145", + AccountSequence: 78621794419880145, MaxFee: 200, FeeCharged: 300, OperationCount: 1, diff --git a/services/horizon/internal/db2/history/transaction_batch_insert_builder.go b/services/horizon/internal/db2/history/transaction_batch_insert_builder.go index 5af5476a7e..d9170f05a3 100644 --- a/services/horizon/internal/db2/history/transaction_batch_insert_builder.go +++ b/services/horizon/internal/db2/history/transaction_batch_insert_builder.go @@ -5,7 +5,6 @@ import ( "encoding/base64" "encoding/hex" "fmt" - "strconv" "strings" "time" @@ -121,7 +120,7 @@ type TransactionWithoutLedger struct { ApplicationOrder int32 `db:"application_order"` Account string `db:"account"` AccountMuxed null.String `db:"account_muxed"` - AccountSequence string `db:"account_sequence"` + AccountSequence int64 `db:"account_sequence"` MaxFee int64 `db:"max_fee"` FeeCharged int64 `db:"fee_charged"` OperationCount int32 `db:"operation_count"` @@ -179,7 +178,7 @@ func transactionToRow(transaction ingest.LedgerTransaction, sequence uint32, enc ApplicationOrder: int32(transaction.Index), Account: account.Address(), AccountMuxed: accountMuxed, - AccountSequence: strconv.FormatInt(transaction.Envelope.SeqNum(), 10), + AccountSequence: transaction.Envelope.SeqNum(), MaxFee: int64(transaction.Envelope.Fee()), FeeCharged: int64(transaction.Result.Result.FeeCharged), OperationCount: int32(len(transaction.Envelope.Operations())), diff --git a/services/horizon/internal/db2/history/transaction_test.go b/services/horizon/internal/db2/history/transaction_test.go index 5f65451155..1947f2ea6c 100644 --- a/services/horizon/internal/db2/history/transaction_test.go +++ b/services/horizon/internal/db2/history/transaction_test.go @@ -348,7 +348,7 @@ func TestInsertTransaction(t *testing.T) { LedgerSequence: ledger.Sequence, ApplicationOrder: 1, Account: "GAUJETIZVEP2NRYLUESJ3LS66NVCEGMON4UDCBCSBEVPIID773P2W6AY", - AccountSequence: "78621794419880145", + AccountSequence: 78621794419880145, MaxFee: 200, FeeCharged: 300, OperationCount: 1, @@ -385,7 +385,7 @@ func TestInsertTransaction(t *testing.T) { LedgerSequence: ledger.Sequence, ApplicationOrder: 1, Account: "GAUJETIZVEP2NRYLUESJ3LS66NVCEGMON4UDCBCSBEVPIID773P2W6AY", - AccountSequence: "78621794419880145", + AccountSequence: 78621794419880145, MaxFee: 200, FeeCharged: 300, OperationCount: 1, @@ -422,7 +422,7 @@ func TestInsertTransaction(t *testing.T) { LedgerSequence: ledger.Sequence, ApplicationOrder: 1, Account: "GAUJETIZVEP2NRYLUESJ3LS66NVCEGMON4UDCBCSBEVPIID773P2W6AY", - AccountSequence: "78621794419880145", + AccountSequence: 78621794419880145, MaxFee: 200, FeeCharged: 123, OperationCount: 1, @@ -459,7 +459,7 @@ func TestInsertTransaction(t *testing.T) { LedgerSequence: ledger.Sequence, ApplicationOrder: 1, Account: "GAUJETIZVEP2NRYLUESJ3LS66NVCEGMON4UDCBCSBEVPIID773P2W6AY", - AccountSequence: "78621794419880145", + AccountSequence: 78621794419880145, // set max fee to a value larger than MAX_INT32 but less than or equal to MAX_UINT32 MaxFee: 2500000000, FeeCharged: int64(1 << 33), @@ -497,7 +497,7 @@ func TestInsertTransaction(t *testing.T) { LedgerSequence: ledger.Sequence, ApplicationOrder: 1, Account: "GAUJETIZVEP2NRYLUESJ3LS66NVCEGMON4UDCBCSBEVPIID773P2W6AY", - AccountSequence: "78621794419880145", + AccountSequence: 78621794419880145, MaxFee: 200, FeeCharged: 300, OperationCount: 1, @@ -534,7 +534,7 @@ func TestInsertTransaction(t *testing.T) { LedgerSequence: ledger.Sequence, ApplicationOrder: 1, Account: "GAUJETIZVEP2NRYLUESJ3LS66NVCEGMON4UDCBCSBEVPIID773P2W6AY", - AccountSequence: "78621794419880145", + AccountSequence: 78621794419880145, MaxFee: 200, FeeCharged: 300, OperationCount: 1, @@ -571,7 +571,7 @@ func TestInsertTransaction(t *testing.T) { LedgerSequence: ledger.Sequence, ApplicationOrder: 1, Account: "GAUJETIZVEP2NRYLUESJ3LS66NVCEGMON4UDCBCSBEVPIID773P2W6AY", - AccountSequence: "78621794419880145", + AccountSequence: 78621794419880145, MaxFee: 200, FeeCharged: 300, OperationCount: 1, @@ -608,7 +608,7 @@ func TestInsertTransaction(t *testing.T) { LedgerSequence: ledger.Sequence, ApplicationOrder: 1, Account: "GAUJETIZVEP2NRYLUESJ3LS66NVCEGMON4UDCBCSBEVPIID773P2W6AY", - AccountSequence: "78621794419880145", + AccountSequence: 78621794419880145, MaxFee: 200, FeeCharged: 300, OperationCount: 1, @@ -646,7 +646,7 @@ func TestInsertTransaction(t *testing.T) { LedgerSequence: ledger.Sequence, ApplicationOrder: 1, Account: "GAUJETIZVEP2NRYLUESJ3LS66NVCEGMON4UDCBCSBEVPIID773P2W6AY", - AccountSequence: "123456", + AccountSequence: 123456, MaxFee: 100, FeeCharged: 300, OperationCount: 1, @@ -683,7 +683,7 @@ func TestInsertTransaction(t *testing.T) { LedgerSequence: ledger.Sequence, ApplicationOrder: 1, Account: "GAUJETIZVEP2NRYLUESJ3LS66NVCEGMON4UDCBCSBEVPIID773P2W6AY", - AccountSequence: "123456", + AccountSequence: 123456, MaxFee: 100, FeeCharged: 300, OperationCount: 1, @@ -720,7 +720,7 @@ func TestInsertTransaction(t *testing.T) { LedgerSequence: ledger.Sequence, ApplicationOrder: 1, Account: "GAUJETIZVEP2NRYLUESJ3LS66NVCEGMON4UDCBCSBEVPIID773P2W6AY", - AccountSequence: "123456", + AccountSequence: 123456, MaxFee: 100, FeeCharged: 300, OperationCount: 1, @@ -760,7 +760,7 @@ func TestInsertTransaction(t *testing.T) { LedgerSequence: ledger.Sequence, ApplicationOrder: 1, Account: "GDQNY3PBOJOKYZSRMK2S7LHHGWZIUISD4QORETLMXEWXBI7KFZZMKTL3", - AccountSequence: "1", + AccountSequence: 1, MaxFee: 100, FeeCharged: 300, OperationCount: 1, @@ -800,7 +800,7 @@ func TestInsertTransaction(t *testing.T) { LedgerSequence: ledger.Sequence, ApplicationOrder: 1, Account: "GAUJETIZVEP2NRYLUESJ3LS66NVCEGMON4UDCBCSBEVPIID773P2W6AY", - AccountSequence: "123456", + AccountSequence: 123456, MaxFee: 200, FeeCharged: 300, OperationCount: 2, diff --git a/services/horizon/internal/db2/history/txsub_result_test.go b/services/horizon/internal/db2/history/txsub_result_test.go index f137b5dc24..3cc513dde0 100644 --- a/services/horizon/internal/db2/history/txsub_result_test.go +++ b/services/horizon/internal/db2/history/txsub_result_test.go @@ -79,7 +79,7 @@ func TestTxSubResult(t *testing.T) { LedgerSequence: int32(sequence), ApplicationOrder: 1, Account: "GAUJETIZVEP2NRYLUESJ3LS66NVCEGMON4UDCBCSBEVPIID773P2W6AY", - AccountSequence: "78621794419880145", + AccountSequence: 78621794419880145, MaxFee: 200, FeeCharged: 300, OperationCount: 1, diff --git a/services/horizon/internal/integration/txsub_test.go b/services/horizon/internal/integration/txsub_test.go index eb3723db4d..60b8717b18 100644 --- a/services/horizon/internal/integration/txsub_test.go +++ b/services/horizon/internal/integration/txsub_test.go @@ -1,7 +1,6 @@ package integration import ( - "strconv" "sync" "testing" @@ -58,7 +57,7 @@ func TestTxsub(t *testing.T) { tt.Equal(accounts[i].GetAccountID(), txResp.Account) seq, err := account.GetSequenceNumber() assert.NoError(t, err) - tt.Equal(strconv.FormatInt(seq, 10), txResp.AccountSequence) + tt.Equal(seq, txResp.AccountSequence) t.Logf("%d/%d done", i, j) }(i, j, account) } diff --git a/services/horizon/internal/resourceadapter/operations_test.go b/services/horizon/internal/resourceadapter/operations_test.go index 90a2104244..39660a3678 100644 --- a/services/horizon/internal/resourceadapter/operations_test.go +++ b/services/horizon/internal/resourceadapter/operations_test.go @@ -14,11 +14,12 @@ import ( ) func TestNewOperationAllTypesCovered(t *testing.T) { + tx := &history.Transaction{} for typ, s := range xdr.OperationTypeToStringMap { row := history.Operation{ Type: xdr.OperationType(typ), } - op, err := NewOperation(context.Background(), row, "foo", &history.Transaction{}, history.Ledger{}) + op, err := NewOperation(context.Background(), row, "foo", tx, history.Ledger{}) assert.NoError(t, err, s) // if we got a base type, the operation is not covered if _, ok := op.(operations.Base); ok { @@ -30,7 +31,7 @@ func TestNewOperationAllTypesCovered(t *testing.T) { row := history.Operation{ Type: xdr.OperationType(200000), } - op, err := NewOperation(context.Background(), row, "foo", &history.Transaction{}, history.Ledger{}) + op, err := NewOperation(context.Background(), row, "foo", tx, history.Ledger{}) assert.NoError(t, err) assert.IsType(t, op, operations.Base{}) @@ -82,9 +83,10 @@ func TestPopulateOperation_WithTransaction(t *testing.T) { operationsRow = history.Operation{TransactionSuccessful: true} transactionRow = history.Transaction{ TransactionWithoutLedger: history.TransactionWithoutLedger{ - Successful: true, - MaxFee: 10000, - FeeCharged: 100, + Successful: true, + MaxFee: 10000, + FeeCharged: 100, + AccountSequence: 1, }, } @@ -295,9 +297,10 @@ func getJSONResponse(typ xdr.OperationType, details string) (rsp map[string]inte ctx, _ := test.ContextWithLogBuffer() transactionRow := history.Transaction{ TransactionWithoutLedger: history.TransactionWithoutLedger{ - Successful: true, - MaxFee: 10000, - FeeCharged: 100, + Successful: true, + MaxFee: 10000, + FeeCharged: 100, + AccountSequence: 1, }, } operationsRow := history.Operation{ @@ -330,6 +333,7 @@ func TestFeeBumpOperation(t *testing.T) { TransactionHash: "cebb875a00ff6e1383aef0fd251a76f22c1f9ab2a2dffcb077855736ade2659a", FeeAccount: null.StringFrom("GCXKG6RN4ONIEPCMNFB732A436Z5PNDSRLGWK7GBLCMQLIFO4S7EYWVU"), Account: "GBRPYHIL2CI3FNQ4BXLFMNDLFJUNPU2HY3ZMFSHONUCEOASW7QC7OX2H", + AccountSequence: 1, NewMaxFee: null.IntFrom(10000), InnerTransactionHash: null.StringFrom("2374e99349b9ef7dba9a5db3339b78fda8f34777b1af33ba468ad5c0df946d4d"), Signatures: []string{"a", "b", "c"}, diff --git a/services/horizon/internal/resourceadapter/transaction_test.go b/services/horizon/internal/resourceadapter/transaction_test.go index 77246ae681..29c8040ce6 100644 --- a/services/horizon/internal/resourceadapter/transaction_test.go +++ b/services/horizon/internal/resourceadapter/transaction_test.go @@ -326,6 +326,7 @@ func TestPopulateTransaction_PreconditionsV2_Omissions(t *testing.T) { MinAccountSequenceAge: null.StringFrom("0"), ExtraSigners: pq.StringArray{}, }, { + AccountSequence: 1, MinAccountSequenceLedgerGap: null.IntFrom(0), TimeBounds: history.TimeBounds{Null: true}, LedgerBounds: history.LedgerBounds{Null: true}, @@ -368,6 +369,7 @@ func TestFeeBumpTransaction(t *testing.T) { FeeAccount: null.StringFrom("GA7QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJVSGZ"), FeeAccountMuxed: null.StringFrom("MA7QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJUAAAAAAAAAAAACJUQ"), Account: "GAQAA5L65LSYH7CQ3VTJ7F3HHLGCL3DSLAR2Y47263D56MNNGHSQSTVY", + AccountSequence: 1, AccountMuxed: null.StringFrom("MAQAA5L65LSYH7CQ3VTJ7F3HHLGCL3DSLAR2Y47263D56MNNGHSQSAAAAAAAAAAE2LP26"), NewMaxFee: null.IntFrom(10000), InnerTransactionHash: null.StringFrom("2374e99349b9ef7dba9a5db3339b78fda8f34777b1af33ba468ad5c0df946d4d"),