From 45b6f52202f3b3e39f4d5a185856349e766f9ba9 Mon Sep 17 00:00:00 2001 From: Alfonso Acosta Date: Wed, 6 Apr 2022 20:32:04 +0200 Subject: [PATCH] horizon: Test new protocol 19 account fields (#4322) --- .../transaction_preconditions_test.go | 40 ++++++++++++++++--- .../internal/test/integration/integration.go | 9 +++-- 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/services/horizon/internal/integration/transaction_preconditions_test.go b/services/horizon/internal/integration/transaction_preconditions_test.go index 8efdf1240d..51a1264a05 100644 --- a/services/horizon/internal/integration/transaction_preconditions_test.go +++ b/services/horizon/internal/integration/transaction_preconditions_test.go @@ -1,9 +1,11 @@ package integration import ( + "strconv" "testing" "time" + sdk "github.com/stellar/go/clients/horizonclient" "github.com/stellar/go/keypair" "github.com/stellar/go/services/horizon/internal/test/integration" "github.com/stellar/go/txnbuild" @@ -11,11 +13,11 @@ import ( ) func TestTransactionPreconditionsMinSeq(t *testing.T) { - if integration.GetCoreMaxSupportedProtocol() < 19 { - t.Skip("Can't run with protocol < 19") - } tt := assert.New(t) itest := integration.NewTest(t, integration.Config{}) + if itest.GetEffectiveProtocolVersion() < 19 { + t.Skip("Can't run with protocol < 19") + } master := itest.Master() masterAccount := itest.MasterAccount() currentAccountSeq, err := masterAccount.GetSequenceNumber() @@ -35,11 +37,11 @@ func TestTransactionPreconditionsMinSeq(t *testing.T) { } func TestTransactionPreconditionsTimeBounds(t *testing.T) { - if integration.GetCoreMaxSupportedProtocol() < 19 { - t.Skip("Can't run with protocol < 19") - } tt := assert.New(t) itest := integration.NewTest(t, integration.Config{}) + if itest.GetEffectiveProtocolVersion() < 19 { + t.Skip("Can't run with protocol < 19") + } master := itest.Master() masterAccount := itest.MasterAccount() currentAccountSeq, err := masterAccount.GetSequenceNumber() @@ -86,3 +88,29 @@ func buildTXParams(master *keypair.Full, masterAccount txnbuild.Account, sourceA }, } } + +func TestTransactionPreconditionsAccountFields(t *testing.T) { + tt := assert.New(t) + itest := integration.NewTest(t, integration.Config{}) + if itest.GetEffectiveProtocolVersion() < 19 { + t.Skip("Can't run with protocol < 19") + } + master := itest.Master() + masterAccount := itest.MasterAccount() + currentAccountSeq, err := masterAccount.GetSequenceNumber() + tt.NoError(err) + + tx := itest.MustSubmitOperations(masterAccount, master, + &txnbuild.BumpSequence{ + BumpTo: currentAccountSeq + 10, + }, + ) + + // refresh master account + account, err := itest.Client().AccountDetail(sdk.AccountRequest{AccountID: master.Address()}) + assert.NoError(t, err) + + // Check the new fields + tt.Equal(uint32(tx.Ledger), account.SequenceLedger) + tt.Equal(strconv.FormatInt(tx.LedgerCloseTime.Unix(), 10), account.SequenceTime) +} diff --git a/services/horizon/internal/test/integration/integration.go b/services/horizon/internal/test/integration/integration.go index fd032e0112..3594c36401 100644 --- a/services/horizon/internal/test/integration/integration.go +++ b/services/horizon/internal/test/integration/integration.go @@ -115,13 +115,12 @@ func NewTest(t *testing.T, config Config) *Test { t.Skip("skipping integration test: HORIZON_INTEGRATION_TESTS_ENABLED not set") } - // If not specific explicitly, set the protocol to the maximum supported version if config.ProtocolVersion == 0 { // Default to the maximum supported protocol version config.ProtocolVersion = ingest.MaxSupportedProtocolVersion // If the environment tells us that Core only supports up to certain version, // use that. - maxSupportedCoreProtocolFromEnv := GetCoreMaxSupportedProtocol() + maxSupportedCoreProtocolFromEnv := getCoreMaxSupportedProtocol() if maxSupportedCoreProtocolFromEnv != 0 && maxSupportedCoreProtocolFromEnv < ingest.MaxSupportedProtocolVersion { config.ProtocolVersion = maxSupportedCoreProtocolFromEnv } @@ -875,7 +874,7 @@ func mapToFlags(params map[string]string) []string { return args } -func GetCoreMaxSupportedProtocol() uint32 { +func getCoreMaxSupportedProtocol() uint32 { str := os.Getenv("HORIZON_INTEGRATION_TESTS_CORE_MAX_SUPPORTED_PROTOCOL") if str == "" { return 0 @@ -886,3 +885,7 @@ func GetCoreMaxSupportedProtocol() uint32 { } return uint32(version) } + +func (i *Test) GetEffectiveProtocolVersion() uint32 { + return i.config.ProtocolVersion +}