Skip to content

Commit

Permalink
horizon: Test new protocol 19 account fields (#4322)
Browse files Browse the repository at this point in the history
  • Loading branch information
2opremio authored Apr 6, 2022
1 parent b5ca7f4 commit 45b6f52
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
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"
"github.com/stretchr/testify/assert"
)

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()
Expand All @@ -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()
Expand Down Expand Up @@ -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)
}
9 changes: 6 additions & 3 deletions services/horizon/internal/test/integration/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand All @@ -886,3 +885,7 @@ func GetCoreMaxSupportedProtocol() uint32 {
}
return uint32(version)
}

func (i *Test) GetEffectiveProtocolVersion() uint32 {
return i.config.ProtocolVersion
}

0 comments on commit 45b6f52

Please sign in to comment.