Skip to content

Commit

Permalink
Update TransactionWithoutLedger
Browse files Browse the repository at this point in the history
  • Loading branch information
bartekn committed May 25, 2022
1 parent d8207f0 commit 4e38e8d
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 59 deletions.
3 changes: 1 addition & 2 deletions services/horizon/internal/actions/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package actions

import (
"net/http/httptest"
"strconv"
"testing"

"github.com/stellar/go/protocols/horizon"
Expand Down Expand Up @@ -119,7 +118,7 @@ func checkOuterHashResponse(
transactionResponse horizon.Transaction,
) {
tt.Assert.Equal(fixture.Transaction.Account, transactionResponse.Account)
tt.Assert.Equal(fixture.Transaction.AccountSequence, strconv.FormatInt(transactionResponse.AccountSequence, 10))
tt.Assert.Equal(fixture.Transaction.AccountSequence, transactionResponse.AccountSequence)
tt.Assert.Equal(fixture.Transaction.FeeAccount.String, transactionResponse.FeeAccount)
tt.Assert.Equal(fixture.Transaction.FeeCharged, transactionResponse.FeeCharged)
tt.Assert.Equal(fixture.Transaction.TransactionHash, transactionResponse.ID)
Expand Down
1 change: 0 additions & 1 deletion services/horizon/internal/actions_transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,6 @@ func TestTransactionActions_PostSuccessful(t *testing.T) {
w := ht.Post("/transactions", form)
ht.Assert.Equal(200, w.Code)
ht.Assert.Contains(w.Body.String(), `"result_xdr": "AAAAAAAAAGQAAAAAAAAAAQAAAAAAAAABAAAAAAAAAAA="`)
ht.Assert.Contains(w.Body.String(), `"source_account_sequence": "8589934593"`)
}

func TestTransactionActions_PostFailed(t *testing.T) {
Expand Down
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
8 changes: 4 additions & 4 deletions services/horizon/internal/resourceadapter/operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

func TestNewOperationAllTypesCovered(t *testing.T) {
tx := &history.Transaction{TransactionWithoutLedger: history.TransactionWithoutLedger{AccountSequence: "1"}}
tx := &history.Transaction{}
for typ, s := range xdr.OperationTypeToStringMap {
row := history.Operation{
Type: xdr.OperationType(typ),
Expand Down Expand Up @@ -86,7 +86,7 @@ func TestPopulateOperation_WithTransaction(t *testing.T) {
Successful: true,
MaxFee: 10000,
FeeCharged: 100,
AccountSequence: "1",
AccountSequence: 1,
},
}

Expand Down Expand Up @@ -300,7 +300,7 @@ func getJSONResponse(typ xdr.OperationType, details string) (rsp map[string]inte
Successful: true,
MaxFee: 10000,
FeeCharged: 100,
AccountSequence: "1",
AccountSequence: 1,
},
}
operationsRow := history.Operation{
Expand Down Expand Up @@ -333,7 +333,7 @@ func TestFeeBumpOperation(t *testing.T) {
TransactionHash: "cebb875a00ff6e1383aef0fd251a76f22c1f9ab2a2dffcb077855736ade2659a",
FeeAccount: null.StringFrom("GCXKG6RN4ONIEPCMNFB732A436Z5PNDSRLGWK7GBLCMQLIFO4S7EYWVU"),
Account: "GBRPYHIL2CI3FNQ4BXLFMNDLFJUNPU2HY3ZMFSHONUCEOASW7QC7OX2H",
AccountSequence: "1",
AccountSequence: 1,
NewMaxFee: null.IntFrom(10000),
InnerTransactionHash: null.StringFrom("2374e99349b9ef7dba9a5db3339b78fda8f34777b1af33ba468ad5c0df946d4d"),
Signatures: []string{"a", "b", "c"},
Expand Down
7 changes: 1 addition & 6 deletions services/horizon/internal/resourceadapter/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (

protocol "github.com/stellar/go/protocols/horizon"
"github.com/stellar/go/services/horizon/internal/db2/history"
"github.com/stellar/go/support/errors"
"github.com/stellar/go/support/render/hal"
)

Expand All @@ -37,11 +36,7 @@ func PopulateTransaction(
muxedAccount := xdr.MustMuxedAddress(dest.AccountMuxed)
dest.AccountMuxedID = uint64(muxedAccount.Med25519.Id)
}
accountSequence, err := strconv.ParseInt(row.AccountSequence, 10, 64)
if err != nil {
return errors.Wrap(err, "error parsing row.AccountSequence")
}
dest.AccountSequence = accountSequence
dest.AccountSequence = row.AccountSequence

dest.FeeCharged = row.FeeCharged

Expand Down
30 changes: 11 additions & 19 deletions services/horizon/internal/resourceadapter/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ func TestPopulateTransaction_Successful(t *testing.T) {
dest = Transaction{}
row = history.Transaction{
TransactionWithoutLedger: history.TransactionWithoutLedger{
Successful: true,
AccountSequence: "1",
Successful: true,
},
}

Expand All @@ -41,8 +40,7 @@ func TestPopulateTransaction_Successful(t *testing.T) {
dest = Transaction{}
row = history.Transaction{
TransactionWithoutLedger: history.TransactionWithoutLedger{
Successful: false,
AccountSequence: "1",
Successful: false,
},
}

Expand All @@ -55,9 +53,8 @@ func TestPopulateTransaction_HashMemo(t *testing.T) {
dest := Transaction{}
row := history.Transaction{
TransactionWithoutLedger: history.TransactionWithoutLedger{
MemoType: "hash",
Memo: null.StringFrom("abcdef"),
AccountSequence: "1",
MemoType: "hash",
Memo: null.StringFrom("abcdef"),
},
}
assert.NoError(t, PopulateTransaction(ctx, row.TransactionHash, &dest, row))
Expand Down Expand Up @@ -122,10 +119,9 @@ func TestPopulateTransaction_TextMemo(t *testing.T) {
assert.NoError(t, err)
row := history.Transaction{
TransactionWithoutLedger: history.TransactionWithoutLedger{
MemoType: "text",
TxEnvelope: envelopeXDR,
Memo: null.StringFrom("sample"),
AccountSequence: "1",
MemoType: "text",
TxEnvelope: envelopeXDR,
Memo: null.StringFrom("sample"),
},
}

Expand All @@ -150,9 +146,8 @@ func TestPopulateTransaction_Fee(t *testing.T) {
dest = Transaction{}
row = history.Transaction{
TransactionWithoutLedger: history.TransactionWithoutLedger{
MaxFee: 10000,
FeeCharged: 100,
AccountSequence: "1",
MaxFee: 10000,
FeeCharged: 100,
},
}

Expand Down Expand Up @@ -181,7 +176,6 @@ func TestPopulateTransaction_Preconditions(t *testing.T) {
dest = Transaction{}
row = history.Transaction{
TransactionWithoutLedger: history.TransactionWithoutLedger{
AccountSequence: "1",
TimeBounds: history.TimeBounds{
Lower: null.IntFrom(stellarTime.MillisFromTime(validAfter).ToInt64() / 1000),
Upper: null.IntFrom(stellarTime.MillisFromTime(validBefore).ToInt64() / 1000),
Expand Down Expand Up @@ -283,7 +277,6 @@ func TestPopulateTransaction_PreconditionsV2(t *testing.T) {
envelopeTimebounds := envelope.TimeBounds()
row := history.Transaction{
TransactionWithoutLedger: history.TransactionWithoutLedger{
AccountSequence: "1",
TimeBounds: history.TimeBounds{
Lower: null.IntFrom(int64(envelopeTimebounds.MinTime)),
Upper: null.IntFrom(int64(envelopeTimebounds.MaxTime)),
Expand Down Expand Up @@ -325,7 +318,6 @@ func TestPopulateTransaction_PreconditionsV2_Omissions(t *testing.T) {

for _, tx := range []history.TransactionWithoutLedger{
{
AccountSequence: "1",
// minimum precondition so that the field exists in general
MinAccountSequenceLedgerGap: null.IntFrom(0),
TimeBounds: history.TimeBounds{Null: true},
Expand All @@ -334,7 +326,7 @@ func TestPopulateTransaction_PreconditionsV2_Omissions(t *testing.T) {
MinAccountSequenceAge: null.StringFrom("0"),
ExtraSigners: pq.StringArray{},
}, {
AccountSequence: "1",
AccountSequence: 1,
MinAccountSequenceLedgerGap: null.IntFrom(0),
TimeBounds: history.TimeBounds{Null: true},
LedgerBounds: history.LedgerBounds{Null: true},
Expand Down Expand Up @@ -377,7 +369,7 @@ func TestFeeBumpTransaction(t *testing.T) {
FeeAccount: null.StringFrom("GA7QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJVSGZ"),
FeeAccountMuxed: null.StringFrom("MA7QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJUAAAAAAAAAAAACJUQ"),
Account: "GAQAA5L65LSYH7CQ3VTJ7F3HHLGCL3DSLAR2Y47263D56MNNGHSQSTVY",
AccountSequence: "1",
AccountSequence: 1,
AccountMuxed: null.StringFrom("MAQAA5L65LSYH7CQ3VTJ7F3HHLGCL3DSLAR2Y47263D56MNNGHSQSAAAAAAAAAAE2LP26"),
NewMaxFee: null.IntFrom(10000),
InnerTransactionHash: null.StringFrom("2374e99349b9ef7dba9a5db3339b78fda8f34777b1af33ba468ad5c0df946d4d"),
Expand Down
2 changes: 1 addition & 1 deletion services/horizon/internal/test/scenarios/base-horizon.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1574,7 +1574,7 @@ INSERT INTO txsub_results
VALUES (
'2374e99349b9ef7dba9a5db3339b78fda8f34777b1af33ba468ad5c0df946d4d',
NULL,
'{ "TxResult": "AAAAAAAAAGQAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAA=", "AccountSequence": "1" }',
'{ "TxResult": "AAAAAAAAAGQAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAA="}',
'2019-06-03 18:28:47.032496+02');

--
Expand Down
12 changes: 6 additions & 6 deletions services/horizon/internal/test/scenarios/bindata.go

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -1124,7 +1124,7 @@ INSERT INTO txsub_results
VALUES (
'56e3216045d579bea40f2d35a09406de3a894ecb5be70dbda5ec9c0427a0d5a1',
NULL,
'{ "TxResult": "AAAAAAAAAGQAAAAAAAAAAQAAAAAAAAABAAAAAAAAAAA=", "AccountSequence": "8589934593" }',
'{ "TxResult": "AAAAAAAAAGQAAAAAAAAAAQAAAAAAAAABAAAAAAAAAAA="}',
'2019-06-03 18:28:47.032496+02');

--
Expand Down

0 comments on commit 4e38e8d

Please sign in to comment.