infrastructure

package
v0.0.0-...-e95794f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 7, 2026 License: Apache-2.0 Imports: 49 Imported by: 0

Documentation

Overview

backfill_helpers.go provides helper functions for backfill integration testing.

Package infrastructure provides helper utilities for integration testing

Package infrastructure provides Soroban transaction helpers for integration tests

Package infrastructure provides test constants for integration testing.

Index

Constants

View Source
const (
	// Transaction amounts (in XLM or token units as strings)
	DefaultPaymentAmount          = "10"
	DefaultFundingAmount          = "10000"
	DefaultTrustlineLimit         = "1000000"
	TestAccountCreationAmount     = "5"
	TestCustomAssetAmount         = "3000"
	TestAuthRequiredPaymentAmount = "1000"
	TestClaimableBalanceAmount    = "1"
	TestLiquidityPoolAmount       = "100"
	TestEURCPaymentAmount         = "75"
	TestUSDCPaymentAmount         = "100"

	// Soroban contract amounts (in stroops with 7 decimals)
	TestEURCTransferStroops  = 500000000  // 50 EURC
	TestSEP41TransferStroops = 5000000000 // 500 SEP41
	TestUSDCTransferStroops  = 2000000000 // 200 USDC
	TestSEP41MintStroops     = 5000000000 // 500 SEP41
	TestXLMTransferStroops   = 100000000  // 10 XLM (with 7 decimals)

	// Timeouts and intervals
	DefaultHTTPTimeout        = 30 * time.Second
	TransactionConfirmTimeout = 10 * time.Second
	CheckpointWaitDuration    = 10 * time.Second
	TransactionPollInterval   = 500 * time.Millisecond
	RPCHealthTimeout          = 120 * time.Second

	// Retry configuration
	DefaultConfirmationRetries  = 20
	ExtendedConfirmationRetries = 60

	// Ledger configuration
	LedgerValidityBuffer = 100 // Buffer for auth entry validity (ledgers)

	// Protocol configuration
	DefaultProtocolVersion = 24

	// Transaction timeouts (in seconds)
	DefaultTransactionTimeout  = 300
	InfiniteTransactionTimeout = 0 // Used for infinite timeout transactions
)

Variables

This section is empty.

Functions

func ConvertOperationsToBase64XDR

func ConvertOperationsToBase64XDR(operations []txnbuild.Operation) ([]string, error)

ConvertOperationsToBase64XDR converts a slice of operations to their base64 XDR representations.

func ExtractClaimableBalanceIDsFromMeta

func ExtractClaimableBalanceIDsFromMeta(resultMetaXDR string) ([]string, error)

ExtractClaimableBalanceIDsFromMeta extracts claimable balance IDs from transaction result metadata. Returns the balance IDs in the order they were created in the transaction.

func RenderResult

func RenderResult(useCase *UseCase) string

RenderResult renders a result string for a use case.

func SCAccountID

func SCAccountID(address string) (xdr.ScAddress, error)

func WaitForRPCHealthAndRun

func WaitForRPCHealthAndRun(ctx context.Context, rpcService services.RPCService, timeout time.Duration, onReady func() error) error

WaitForRPCHealthAndRun waits for the RPC service to become healthy and then runs the given function.

func WaitForTransactionConfirmation

func WaitForTransactionConfirmation(ctx context.Context, rpcService services.RPCService, hash string, retryOptions ...retry.Option) (txResult entities.RPCGetTransactionResult, err error)

Types

type Fixtures

type Fixtures struct {
	NetworkPassphrase     string
	PrimaryAccountKP      *keypair.Full
	SecondaryAccountKP    *keypair.Full
	SponsoredNewAccountKP *keypair.Full
	BalanceTestAccount1KP *keypair.Full
	BalanceTestAccount2KP *keypair.Full
	LiquidityPoolID       string
	RPCService            services.RPCService
	HolderContractAddress string
	EURCContractAddress   string
	SEP41ContractAddress  string
	USDCContractAddress   string
	MasterAccountKP       *keypair.Full
}

func NewFixtures

func NewFixtures(
	ctx context.Context,
	networkPassphrase string,
	primaryAccountKP *keypair.Full,
	secondaryAccountKP *keypair.Full,
	sponsoredNewAccountKP *keypair.Full,
	balanceTestAccount1KP *keypair.Full,
	balanceTestAccount2KP *keypair.Full,
	masterAccountKP *keypair.Full,
	rpcService services.RPCService,
	holderContractAddress string,
	eurcContractAddress string,
	sep41ContractAddress string,
	usdcContractAddress string,
) (*Fixtures, error)

func (*Fixtures) PrepareClaimAndClawbackUseCases

func (f *Fixtures) PrepareClaimAndClawbackUseCases(balanceIDToBeClaimed, balanceIDToBeClawbacked string) ([]*UseCase, error)

PrepareClaimAndClawbackUseCases creates use cases for claiming and clawing back claimable balances using the actual balance IDs from the confirmed createClaimableBalance transaction.

func (*Fixtures) PrepareUseCases

func (f *Fixtures) PrepareUseCases(ctx context.Context) ([]*UseCase, error)

type Set

type Set[T comparable] struct {
	// contains filtered or unexported fields
}

func NewSet

func NewSet[T comparable](values ...T) *Set[T]

func (*Set[T]) Add

func (s *Set[T]) Add(value T)

func (*Set[T]) Slice

func (s *Set[T]) Slice() []T

type SharedContainers

type SharedContainers struct {

	// Docker infrastructure
	TestNetwork            *testcontainers.DockerNetwork
	PostgresContainer      *TestContainer
	StellarCoreContainer   *TestContainer
	RPCContainer           *TestContainer
	WalletDBContainer      *TestContainer
	RedisContainer         *TestContainer
	WalletBackendContainer *WalletBackendContainer
	BackfillContainer      *TestContainer // Separate container for backfill testing
	// contains filtered or unexported fields
}

SharedContainers provides shared container management for integration tests

func NewSharedContainers

func NewSharedContainers(t *testing.T) *SharedContainers

NewSharedContainers creates and starts all containers needed for integration tests

func (*SharedContainers) Cleanup

func (s *SharedContainers) Cleanup(ctx context.Context)

Cleanup cleans up shared containers after all tests complete

func (*SharedContainers) CreateAndFundAccounts

func (s *SharedContainers) CreateAndFundAccounts(ctx context.Context, t *testing.T, accounts []*keypair.Full)

CreateAndFundAccounts creates and funds multiple accounts in a single transaction using the master account

func (*SharedContainers) GetBalanceTestAccount1KeyPair

func (s *SharedContainers) GetBalanceTestAccount1KeyPair(ctx context.Context) *keypair.Full

GetBalanceTestAccount1KeyPair returns the first balance test account keypair

func (*SharedContainers) GetBalanceTestAccount2KeyPair

func (s *SharedContainers) GetBalanceTestAccount2KeyPair(ctx context.Context) *keypair.Full

GetBalanceTestAccount2KeyPair returns the second balance test account keypair

func (*SharedContainers) GetClientAuthKeyPair

func (s *SharedContainers) GetClientAuthKeyPair(ctx context.Context) *keypair.Full

GetClientAuthKeyPair returns the client authentication keypair

func (*SharedContainers) GetDistributionAccountKeyPair

func (s *SharedContainers) GetDistributionAccountKeyPair(ctx context.Context) *keypair.Full

GetDistributionAccountKeyPair returns the distribution account keypair

func (*SharedContainers) GetIngestContainerLogs

func (s *SharedContainers) GetIngestContainerLogs(ctx context.Context) (string, error)

GetIngestContainerLogs returns the logs from the ingest container.

func (*SharedContainers) GetIngestCursor

func (s *SharedContainers) GetIngestCursor(ctx context.Context, cursorName string) (uint32, error)

GetIngestCursor retrieves a cursor value from the ingest_store table.

func (*SharedContainers) GetLedgerGapCount

func (s *SharedContainers) GetLedgerGapCount(ctx context.Context, startLedger, endLedger uint32) (int, error)

GetLedgerGapCount counts the number of missing ledgers (gaps) in the transactions table within the specified ledger range. Returns 0 if there are no gaps.

func (*SharedContainers) GetMasterKeyPair

func (s *SharedContainers) GetMasterKeyPair(ctx context.Context) *keypair.Full

GetMasterKeyPair returns the master account keypair

func (*SharedContainers) GetPrimarySourceAccountKeyPair

func (s *SharedContainers) GetPrimarySourceAccountKeyPair(ctx context.Context) *keypair.Full

GetPrimarySourceAccountKeyPair returns the primary source account keypair

func (*SharedContainers) GetSecondarySourceAccountKeyPair

func (s *SharedContainers) GetSecondarySourceAccountKeyPair(ctx context.Context) *keypair.Full

GetSecondarySourceAccountKeyPair returns the secondary source account keypair

func (*SharedContainers) GetSponsoredNewAccountKeyPair

func (s *SharedContainers) GetSponsoredNewAccountKeyPair(ctx context.Context) *keypair.Full

GetSponsoredNewAccountKeyPair returns the sponsored new account keypair

func (*SharedContainers) GetStateChangeCountForLedgerRange

func (s *SharedContainers) GetStateChangeCountForLedgerRange(ctx context.Context, startLedger, endLedger uint32) (int, error)

GetStateChangeCountForLedgerRange counts state changes in a ledger range.

func (*SharedContainers) GetTransactionAccountLinkCount

func (s *SharedContainers) GetTransactionAccountLinkCount(ctx context.Context, accountAddr string, startLedger, endLedger uint32) (int, error)

GetTransactionAccountLinkCount counts transaction-account links for an account in a ledger range.

func (*SharedContainers) GetTransactionCountForAccount

func (s *SharedContainers) GetTransactionCountForAccount(ctx context.Context, accountAddr string, startLedger, endLedger uint32) (int, error)

GetTransactionCountForAccount counts transactions involving a specific account in a ledger range.

func (*SharedContainers) GetWalletDBConnectionString

func (s *SharedContainers) GetWalletDBConnectionString(ctx context.Context) (string, error)

GetWalletDBConnectionString returns the connection string for the wallet backend database

func (*SharedContainers) HasOperationForAccount

func (s *SharedContainers) HasOperationForAccount(ctx context.Context, accountAddr, opType string, startLedger, endLedger uint32) (bool, error)

HasOperationForAccount checks if an operation of a specific type exists for an account in a ledger range.

func (*SharedContainers) RestartIngestContainer

func (s *SharedContainers) RestartIngestContainer(ctx context.Context, extraEnv map[string]string) error

RestartIngestContainer stops the current ingest container and starts a new one with extra environment variables

func (*SharedContainers) StartBackfillContainer

func (s *SharedContainers) StartBackfillContainer(ctx context.Context, startLedger, endLedger uint32) (*TestContainer, error)

StartBackfillContainer creates and starts a new backfill container alongside the live ingest container. It processes historical ledgers in the specified range.

func (*SharedContainers) StopIngestContainer

func (s *SharedContainers) StopIngestContainer(ctx context.Context) error

StopIngestContainer stops the ingest container without terminating it. This allows the network to advance while the container is stopped.

func (*SharedContainers) SubmitPaymentOp

func (s *SharedContainers) SubmitPaymentOp(ctx context.Context, t *testing.T, to string, amount string)

SubmitPaymentOp executes a native XLM payment from the master account to a destination

func (*SharedContainers) WaitForBackfillCompletion

func (s *SharedContainers) WaitForBackfillCompletion(ctx context.Context, expectedOldestLedger uint32, timeout time.Duration) error

WaitForBackfillCompletion polls until the oldest_ingest_ledger cursor reaches the expected value.

func (*SharedContainers) WaitForLatestLedgerToReach

func (s *SharedContainers) WaitForLatestLedgerToReach(ctx context.Context, targetLedger uint32, timeout time.Duration) error

WaitForLatestLedgerToReach polls the database until the latest_ingest_ledger cursor reaches the target.

func (*SharedContainers) WaitForNetworkAdvance

func (s *SharedContainers) WaitForNetworkAdvance(ctx context.Context, rpcService services.RPCService, targetLedger uint32, timeout time.Duration) error

WaitForNetworkAdvance polls the RPC service until the network reaches the target ledger.

type TestContainer

type TestContainer struct {
	testcontainers.Container
	MappedPortStr    string
	ConnectionString string
}

TestContainer wraps a testcontainer with connection string helper

func (*TestContainer) GetConnectionString

func (c *TestContainer) GetConnectionString(ctx context.Context) (string, error)

GetConnectionString returns the HTTP connection string for the container

func (*TestContainer) GetHost

func (c *TestContainer) GetHost(ctx context.Context) (string, error)

GetHost returns the host for the container

func (*TestContainer) GetPort

func (c *TestContainer) GetPort(ctx context.Context) (string, error)

GetPort returns the port for the container

type TestEnvironment

type TestEnvironment struct {
	Containers            *SharedContainers
	WBClient              *wbclient.Client
	RPCService            services.RPCService
	PrimaryAccountKP      *keypair.Full
	SecondaryAccountKP    *keypair.Full
	SponsoredNewAccountKP *keypair.Full
	BalanceTestAccount1KP *keypair.Full
	BalanceTestAccount2KP *keypair.Full
	USDCContractAddress   string
	EURCContractAddress   string
	// SEP41ContractAddress is the address of the deployed custom SEP-41 token contract.
	// Used for asserting token IDs in balance queries for non-SAC tokens.
	SEP41ContractAddress string
	// HolderContractAddress is the address of the test contract that holds token balances.
	// Used for querying C-address balances in integration tests.
	HolderContractAddress string
	// MasterAccountAddress is the address of the master/root account that issues classic assets.
	// Used for asserting issuer addresses in trustline and SAC balance tests.
	MasterAccountAddress     string
	ClaimBalanceID           string
	ClawbackBalanceID        string
	LiquidityPoolID          string
	NetworkPassphrase        string
	UseCases                 []*UseCase
	ClaimAndClawbackUseCases []*UseCase
}

TestEnvironment holds all initialized services and clients for integration tests

func NewTestEnvironment

func NewTestEnvironment(ctx context.Context, containers *SharedContainers) (*TestEnvironment, error)

NewTestEnvironment creates and initializes a test environment with all required services

func (*TestEnvironment) RestartIngestContainer

func (e *TestEnvironment) RestartIngestContainer(ctx context.Context, extraEnv map[string]string) error

RestartIngestContainer restarts the ingest container with extra environment variables

func (*TestEnvironment) WaitForLedgers

func (e *TestEnvironment) WaitForLedgers(ctx context.Context, ledgers int)

WaitForLedgers waits for a number of ledgers to close (approximated by sleep)

type UseCase

type UseCase struct {
	DelayTime               time.Duration
	TxSigners               *Set[*keypair.Full]
	RequestedTransaction    types.Transaction
	BuiltTransactionXDR     string
	SignedTransactionXDR    string
	FeeBumpedTransactionXDR string
	SendTransactionResult   entities.RPCSendTransactionResult
	GetTransactionResult    entities.RPCGetTransactionResult
	// contains filtered or unexported fields
}

func FindUseCase

func FindUseCase(useCases []*UseCase, useCaseName string) *UseCase

FindUseCase returns the use case with the given name from a slice of use cases.

func (*UseCase) Name

func (u *UseCase) Name() string

type WalletBackendContainer

type WalletBackendContainer struct {
	API    *TestContainer
	Ingest *TestContainer
}

WalletBackendContainer holds API and Ingest container references

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL