Skip to content

Commit

Permalink
protocols/horizon: Change Transaction.AccountSequence to int64 (#4409)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bartekn authored May 27, 2022
1 parent 8212530 commit 6af10a1
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 37 deletions.
3 changes: 3 additions & 0 deletions clients/horizonclient/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion protocols/horizon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
14 changes: 7 additions & 7 deletions services/horizon/internal/actions_transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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")
}
4 changes: 2 additions & 2 deletions services/horizon/internal/db2/history/fee_bump_scenario.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/base64"
"encoding/hex"
"fmt"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -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"`
Expand Down Expand Up @@ -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())),
Expand Down
26 changes: 13 additions & 13 deletions services/horizon/internal/db2/history/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion services/horizon/internal/db2/history/txsub_result_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions services/horizon/internal/integration/txsub_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package integration

import (
"strconv"
"sync"
"testing"

Expand Down Expand Up @@ -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)
}
Expand Down
20 changes: 12 additions & 8 deletions services/horizon/internal/resourceadapter/operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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{})

Expand Down Expand Up @@ -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,
},
}

Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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"},
Expand Down
2 changes: 2 additions & 0 deletions services/horizon/internal/resourceadapter/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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"),
Expand Down

0 comments on commit 6af10a1

Please sign in to comment.