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: Set up protocol 19 integration tests infrastructure #4312

Merged
merged 17 commits into from
Apr 4, 2022
Merged
Show file tree
Hide file tree
Changes from 16 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
24 changes: 16 additions & 8 deletions .github/workflows/horizon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
go: [1.17, 1.18]
pg: [9.6.5]
ingestion-backend: [db, captive-core, captive-core-remote-storage]
captive-core: [18.5.0-873.rc1.d387c6a71.focal]
protocol-version: [18, 19]
runs-on: ${{ matrix.os }}
services:
postgres:
Expand All @@ -32,7 +32,12 @@ jobs:
ports:
- 5432:5432
env:
HORIZON_INTEGRATION_TESTS: "true"
HORIZON_INTEGRATION_TESTS_ENABLED: true
HORIZON_INTEGRATION_TESTS_CORE_MAX_SUPPORTED_PROTOCOL: ${{ matrix.protocol-version }}
PROTOCOL_19_CORE_DEBIAN_PKG_VERSION: 18.4.1-875.95d896a49.focal~v19unsafe
sreuland marked this conversation as resolved.
Show resolved Hide resolved
PROTOCOL_19_CORE_DOCKER_IMG: stellar/stellar-core:18.4.1-875.95d896a49.focal-v19unsafe
PROTOCOL_18_CORE_DEBIAN_PKG_VERSION: 18.5.0-873.rc1.d387c6a71.focal
PROTOCOL_18_CORE_DOCKER_IMG: stellar/stellar-core:18.5.0-873.rc1.d387c6a71.focal
PGHOST: localhost
PGPORT: 5432
PGUSER: postgres
Expand Down Expand Up @@ -61,8 +66,11 @@ jobs:
with:
go-version: ${{ matrix.go }}

- name: Pull latest Stellar Core image
run: docker pull stellar/stellar-core
- name: Pull and set Stellar Core image
shell: bash
run: |
docker pull "$PROTOCOL_${{ matrix.protocol-version }}_CORE_DOCKER_IMG"
echo HORIZON_INTEGRATION_TESTS_DOCKER_IMG="$PROTOCOL_${{ matrix.protocol-version }}_CORE_DOCKER_IMG" >> $GITHUB_ENV

- if: ${{ startsWith(matrix.ingestion-backend, 'captive-core') }}
name: Install and enable Captive Core
Expand All @@ -74,14 +82,14 @@ jobs:

sudo wget -qO - https://apt.stellar.org/SDF.asc | APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=true sudo apt-key add -
sudo bash -c 'echo "deb https://apt.stellar.org focal unstable" > /etc/apt/sources.list.d/SDF-unstable.list'
sudo apt-get update && sudo apt-get install -y stellar-core=${{ matrix.captive-core }}
sudo apt-get update && sudo apt-get install -y stellar-core="$PROTOCOL_${{ matrix.protocol-version }}_CORE_DEBIAN_PKG_VERSION"
echo "Using stellar core version $(stellar-core version)"
echo 'HORIZON_INTEGRATION_ENABLE_CAPTIVE_CORE=true' >> $GITHUB_ENV
echo 'CAPTIVE_CORE_BIN=/usr/bin/stellar-core' >> $GITHUB_ENV
echo 'HORIZON_INTEGRATION_TESTS_ENABLE_CAPTIVE_CORE=true' >> $GITHUB_ENV
echo 'HORIZON_INTEGRATION_TESTS_CAPTIVE_CORE_BIN=/usr/bin/stellar-core' >> $GITHUB_ENV

- if: ${{ matrix.ingestion-backend == 'captive-core-remote-storage' }}
name: Setup Captive Core Remote Storage
run: echo 'HORIZON_INTEGRATION_ENABLE_CAPTIVE_CORE_USE_DB=true' >> $GITHUB_ENV
run: echo 'HORIZON_INTEGRATION_TESTS_CAPTIVE_CORE_USE_DB=true' >> $GITHUB_ENV

- run: go test -race -timeout 25m -v ./services/horizon/internal/integration/...

Expand Down
9 changes: 4 additions & 5 deletions integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ set -e

cd "$(dirname "${BASH_SOURCE[0]}")"

export HORIZON_INTEGRATION_TESTS=true
export HORIZON_INTEGRATION_ENABLE_CAP_35=${HORIZON_INTEGRATION_ENABLE_CAP_35:-}
export HORIZON_INTEGRATION_ENABLE_CAPTIVE_CORE=${HORIZON_INTEGRATION_ENABLE_CAPTIVE_CORE:-}
export HORIZON_INTEGRATION_ENABLE_CAPTIVE_CORE_USE_DB=${HORIZON_INTEGRATION_ENABLE_CAPTIVE_CORE_USE_DB:-}
export CAPTIVE_CORE_BIN=${CAPTIVE_CORE_BIN:-/usr/bin/stellar-core}
export HORIZON_INTEGRATION_TESTS_ENABLED=true
export HORIZON_INTEGRATION_TESTS_ENABLE_CAPTIVE_CORE=${HORIZON_INTEGRATION_TESTS_ENABLE_CAPTIVE_CORE:-}
export HORIZON_INTEGRATION_TESTS_CAPTIVE_CORE_USE_DB=${HORIZON_INTEGRATION_TESTS_CAPTIVE_CORE_USE_DB:-}
export HORIZON_INTEGRATION_TESTS_CAPTIVE_CORE_BIN=${HORIZON_INTEGRATION_TESTS_CAPTIVE_CORE_BIN:-/usr/bin/stellar-core}
export TRACY_NO_INVARIANT_CHECK=1 # This fails on my dev vm. - Paul

# launch postgres if it's not already.
Expand Down
2 changes: 1 addition & 1 deletion services/horizon/internal/ingest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
const (
// MaxSupportedProtocolVersion defines the maximum supported version of
// the Stellar protocol.
MaxSupportedProtocolVersion uint32 = 18
MaxSupportedProtocolVersion uint32 = 19

// CurrentVersion reflects the latest version of the ingestion
// algorithm. This value is stored in KV store and is used to decide
Expand Down
15 changes: 13 additions & 2 deletions services/horizon/internal/ingest/processor_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ingest

import (
"context"
"fmt"
"io"
"reflect"
"testing"
Expand Down Expand Up @@ -157,7 +158,12 @@ func TestProcessorRunnerRunHistoryArchiveIngestionProtocolVersionNotSupported(t
}

_, err := runner.RunHistoryArchiveIngestion(100, 200, xdr.Hash{})
assert.EqualError(t, err, "Error while checking for supported protocol version: This Horizon version does not support protocol version 200. The latest supported protocol version is 18. Please upgrade to the latest Horizon version.")
assert.EqualError(t, err,
fmt.Sprintf(
"Error while checking for supported protocol version: This Horizon version does not support protocol version 200. The latest supported protocol version is %d. Please upgrade to the latest Horizon version.",
MaxSupportedProtocolVersion,
),
)
}

func TestProcessorRunnerBuildChangeProcessor(t *testing.T) {
Expand Down Expand Up @@ -342,5 +348,10 @@ func TestProcessorRunnerRunAllProcessorsOnLedgerProtocolVersionNotSupported(t *t
}

_, err := runner.RunAllProcessorsOnLedger(ledger)
assert.EqualError(t, err, "Error while checking for supported protocol version: This Horizon version does not support protocol version 200. The latest supported protocol version is 18. Please upgrade to the latest Horizon version.")
assert.EqualError(t, err,
fmt.Sprintf(
"Error while checking for supported protocol version: This Horizon version does not support protocol version 200. The latest supported protocol version is %d. Please upgrade to the latest Horizon version.",
MaxSupportedProtocolVersion,
),
)
}
7 changes: 7 additions & 0 deletions services/horizon/internal/ingest/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,13 @@ func addAccountsToStateVerifier(ctx context.Context, verifier *verify.StateVerif
NumSponsored: xdr.Uint32(row.NumSponsored),
NumSponsoring: xdr.Uint32(row.NumSponsoring),
SignerSponsoringIDs: signerSponsoringIDs,
Ext: xdr.AccountEntryExtensionV2Ext{
V: 3,
V3: &xdr.AccountEntryExtensionV3{
SeqLedger: xdr.Uint32(row.SequenceLedger),
SeqTime: xdr.TimePoint(row.SequenceTime.Unix()),
},
},
},
},
},
Expand Down
6 changes: 6 additions & 0 deletions services/horizon/internal/ingest/verify_range_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,12 @@ func (s *VerifyRangeStateTestSuite) TestSuccessWithVerify() {
xdr.MustAddressPtr(mockAccountID),
xdr.MustAddressPtr(sponsor),
},
Ext: xdr.AccountEntryExtensionV2Ext{
V: 3,
V3: &xdr.AccountEntryExtensionV3{
SeqTime: xdr.TimePoint(18446744011573954816),
},
},
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestClaimableBalanceBasics(t *testing.T) {

// Ensure predicting claimable balances works.
t.Run("BalanceIDs", func(t *testing.T) {
tx, err := itest.CreateSignedTransaction(
tx, err := itest.CreateSignedTransactionFromOps(
itest.MasterAccount(),
[]*keypair.Full{master},
&txnbuild.CreateClaimableBalance{
Expand Down
4 changes: 2 additions & 2 deletions services/horizon/internal/integration/liquidity_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ func TestLiquidityPoolFailedDepositAndWithdraw(t *testing.T) {
nonExistentPoolID := [32]byte{0xca, 0xfe}

// Failing deposit
tx, err := itest.CreateSignedTransaction(shareAccount, []*keypair.Full{shareKeys},
tx, err := itest.CreateSignedTransactionFromOps(shareAccount, []*keypair.Full{shareKeys},
&txnbuild.LiquidityPoolDeposit{
LiquidityPoolID: nonExistentPoolID,
MaxAmountA: "400",
Expand Down Expand Up @@ -696,7 +696,7 @@ func TestLiquidityPoolFailedDepositAndWithdraw(t *testing.T) {
tt.Equal("0.0000000", deposit.SharesReceived)

// Failing withdrawal
tx, err = itest.CreateSignedTransaction(shareAccount, []*keypair.Full{shareKeys},
tx, err = itest.CreateSignedTransactionFromOps(shareAccount, []*keypair.Full{shareKeys},
&txnbuild.LiquidityPoolWithdraw{
LiquidityPoolID: nonExistentPoolID,
Amount: amount.StringFromInt64(int64(10)),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package integration

import (
"testing"
"time"

"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{})
master := itest.Master()
masterAccount := itest.MasterAccount()
currentAccountSeq, err := masterAccount.GetSequenceNumber()
tt.NoError(err)

// Ensure that the minSequence of the transaction is enough
// but the sequence isn't
txParams := buildTXParams(master, masterAccount, currentAccountSeq, currentAccountSeq+100)

// this errors because the tx.seqNum is more than +1 from sourceAccoubnt.seqNum
_, err = itest.SubmitTransaction(master, txParams)
tt.Error(err)

// Now the transaction should be submitted without problems
txParams.Preconditions.MinSequenceNumber = &currentAccountSeq
itest.MustSubmitTransaction(master, txParams)
}

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{})
master := itest.Master()
masterAccount := itest.MasterAccount()
currentAccountSeq, err := masterAccount.GetSequenceNumber()
tt.NoError(err)
txParams := buildTXParams(master, masterAccount, currentAccountSeq, currentAccountSeq+1)

// this errors because the min time is > current tx submit time
txParams.Preconditions.TimeBounds.MinTime = time.Now().Unix() + 3600
txParams.Preconditions.TimeBounds.MaxTime = time.Now().Unix() + 7200
_, err = itest.SubmitTransaction(master, txParams)
tt.Error(err)

// this errors because the max time is < current tx submit time
txParams.Preconditions.TimeBounds.MinTime = 0
txParams.Preconditions.TimeBounds.MaxTime = time.Now().Unix() - 3600
_, err = itest.SubmitTransaction(master, txParams)
tt.Error(err)

// Now the transaction should be submitted without problems, min < current tx submit time < max
txParams.Preconditions.TimeBounds.MinTime = time.Now().Unix() - 3600
txParams.Preconditions.TimeBounds.MaxTime = time.Now().Unix() + 3600
itest.MustSubmitTransaction(master, txParams)
}

func buildTXParams(master *keypair.Full, masterAccount txnbuild.Account, sourceAccountSeq int64, txSequence int64) txnbuild.TransactionParams {

ops := []txnbuild.Operation{
&txnbuild.BumpSequence{
BumpTo: sourceAccountSeq + 10,
},
}

return txnbuild.TransactionParams{
SourceAccount: &txnbuild.SimpleAccount{
AccountID: masterAccount.GetAccountID(),
Sequence: txSequence,
},
// Phony operation to run
Operations: ops,
BaseFee: txnbuild.MinBaseFee,
Memo: nil,
Preconditions: txnbuild.Preconditions{
TimeBounds: txnbuild.NewInfiniteTimeout(),
},
}
}
Loading