Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

horizon: Add integration test for new protocol 19 account fields #4322

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this asserts the case of an existing account that would already be on the ledger(history) with no v3 ext, should we do another test case for creating a new account with some v3 values and retrieving that one also?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am confused. AFAIU this test checks the new v3 ext fields, but maybe I am missing something. Can you elaborate?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merging now, happy to change anything which was amiss

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
}