Documentation
¶
Overview ¶
Package testing provides test infrastructure for XRPL transaction testing.
Package testing provides test infrastructure for XRPL transaction testing.
This package is inspired by rippled's test::jtx framework and provides a similar API for creating deterministic test environments.
Overview ¶
The testing package provides:
- TestEnv: A test environment with ledger state management
- Account: Deterministic test accounts with keypairs
- Amount helpers: Functions for creating XRP and IOU amounts
- Transaction builders: Fluent builders for common transaction types
- Assertions: Test assertion helpers for common checks
Basic Usage ¶
func TestPayment(t *testing.T) {
env := testing.NewTestEnv(t)
alice := testing.NewAccount("alice")
bob := testing.NewAccount("bob")
env.Fund(alice, bob)
env.Close()
// Alice sends 100 XRP to Bob
payment := builders.Pay(
&builders.Account{Address: alice.Address},
&builders.Account{Address: bob.Address},
testing.XRP(100),
).Build()
result := env.Submit(payment)
testing.RequireTxSuccess(t, result)
}
TestEnv ¶
TestEnv manages a test ledger environment. It creates a genesis ledger with a master account and provides methods for funding accounts, submitting transactions, and closing ledgers.
env := testing.NewTestEnv(t) env.Fund(alice) // Fund account with 1000 XRP env.FundAmount(bob, testing.XRP(500)) // Fund with specific amount env.Close() // Close ledger, advance sequence env.Balance(alice) // Get XRP balance in drops env.Now() // Get current ledger time
Account ¶
Account represents a test account with deterministic keypair derivation. Using the same name will always produce the same account, making tests reproducible.
alice := testing.NewAccount("alice") // secp256k1 by default
bob := testing.NewAccountWithKeyType("bob", testing.KeyTypeEd25519)
master := testing.MasterAccount() // Genesis account
Amount Helpers ¶
Amount helpers convert between XRP and drops:
testing.XRP(100) // 100 XRP = 100,000,000 drops testing.Drops(1000) // 1000 drops
For issued currencies:
gateway := testing.NewAccount("gateway")
testing.USD(gateway, 100.50) // $100.50 USD from gateway
testing.EUR(gateway, 50.00) // 50 EUR from gateway
testing.IssuedCurrency(gateway, "JPY", 1000.0) // Custom currency
Transaction Builders ¶
The builders package provides fluent interfaces for constructing transactions:
// Payment
builders.Pay(from, to, amount).Fee(10).Build()
// Trust line
builders.TrustUSD(account, issuer, "1000000").Build()
// Offer
builders.OfferCreate(account, takerPays, takerGets).Passive().Build()
// Escrow
builders.EscrowCreate(from, to, amount).
FinishTime(time.Now().Add(24 * time.Hour)).
Condition(builders.TestCondition1).
Build()
Assertions ¶
Helper functions for common test assertions:
testing.RequireBalance(t, env, alice, testing.XRP(900)) testing.RequireBalanceXRP(t, env, alice, 900) testing.RequireTxSuccess(t, result) testing.RequireTxFail(t, result, testing.TecUNFUNDED_PAYMENT) testing.RequireAccountExists(t, env, alice)
Clock Control ¶
The test environment uses a ManualClock that can be controlled:
env.AdvanceTime(10 * time.Second) env.SetTime(time.Date(2025, 1, 1, 0, 0, 0, 0, time.UTC)) env.Now() // Current test time
Index ¶
- Constants
- func AssertBalanceChange(t *testing.T, env *TestEnv, acc *Account, expectedChange int64, fn func())
- func AssertNoBalanceChange(t *testing.T, env *TestEnv, acc *Account, fn func())
- func BTC(gw *Account, amount float64) tx.Amount
- func DecodeAddress(address string) ([20]byte, error)
- func Drops(n int64) int64
- func EUR(gw *Account, amount float64) tx.Amount
- func FormatBalance(drops uint64) string
- func IssuedCurrency(gw *Account, currency string, amount float64) tx.Amount
- func IssuedCurrencyFromMantissa(gw *Account, currency string, mantissa int64, exponent int) tx.Amount
- func NewDisableRegularKeyTx(acc *Account) tx.Transaction
- func NewRemoveSignerListTx(acc *Account) tx.Transaction
- func NewSetRegularKeyTx(acc *Account, regularKey *Account) tx.Transaction
- func NewSignerListSetTx(acc *Account, quorum uint32, signers []TestSigner) tx.Transaction
- func RequireAccountExists(t *testing.T, env *TestEnv, acc *Account)
- func RequireAccountNotExists(t *testing.T, env *TestEnv, acc *Account)
- func RequireBalance(t *testing.T, env *TestEnv, acc *Account, expected uint64)
- func RequireBalanceApprox(t *testing.T, env *TestEnv, acc *Account, expected uint64, tolerance uint64)
- func RequireBalanceXRP(t *testing.T, env *TestEnv, acc *Account, expectedXRP int64)
- func RequireBurnedCount(t *testing.T, env *TestEnv, acc *Account, expected uint32)
- func RequireFlagNotSet(t *testing.T, env *TestEnv, acc *Account, flag uint32)
- func RequireFlagSet(t *testing.T, env *TestEnv, acc *Account, flag uint32)
- func RequireFlags(t *testing.T, env *TestEnv, acc *Account, expectedFlags uint32)
- func RequireIOUBalance(t *testing.T, env *TestEnv, holder, issuer *Account, currency string, ...)
- func RequireIOUBalanceApprox(t *testing.T, env *TestEnv, holder, issuer *Account, currency string, ...)
- func RequireLedgerEntryExists(t *testing.T, env *TestEnv, key keylet.Keylet)
- func RequireLedgerEntryNotExists(t *testing.T, env *TestEnv, key keylet.Keylet)
- func RequireLines(t *testing.T, env *TestEnv, acc *Account, expected uint32)
- func RequireMintedCount(t *testing.T, env *TestEnv, acc *Account, expected uint32)
- func RequireOffers(t *testing.T, env *TestEnv, acc *Account, expected uint32)
- func RequireOwnerCount(t *testing.T, env *TestEnv, acc *Account, expected uint32)
- func RequireSequence(t *testing.T, env *TestEnv, acc *Account, expected uint32)
- func RequireSignerListCount(t *testing.T, env *TestEnv, acc *Account, expected uint32)
- func RequireTicketCount(t *testing.T, env *TestEnv, acc *Account, expected uint32)
- func RequireTrustLineExists(t *testing.T, env *TestEnv, acc1, acc2 *Account, currency string)
- func RequireTrustLineNotExists(t *testing.T, env *TestEnv, acc1, acc2 *Account, currency string)
- func RequireTxClaimed(t *testing.T, result TxResult, expectedCode string)
- func RequireTxFail(t *testing.T, result TxResult, expectedCode string)
- func RequireTxSuccess(t *testing.T, result TxResult)
- func ResultCodeCategory(code string) string
- func USD(gw *Account, amount float64) tx.Amount
- func WithSeq(transaction tx.Transaction, seq uint32) tx.Transaction
- func WithTicketSeq(transaction tx.Transaction, ticketSeq uint32) tx.Transaction
- func XRP(n int64) int64
- func XRPMinusFee(env *TestEnv, amountXRP int64) uint64
- func XRPMinusFees(env *TestEnv, amountXRP int64, numFees int) uint64
- func XRPTxAmount(drops int64) tx.Amount
- func XRPTxAmountFromXRP(xrp float64) tx.Amount
- type Account
- func MasterAccount() *Account
- func NewAccount(name string) *Account
- func NewAccountFromPassphrase(name, passphrase string) *Account
- func NewAccountFromPassphraseWithKeyType(name, passphrase, keyType string) *Account
- func NewAccountFromSeed(name, base58Seed string) *Account
- func NewAccountWithAddress(name string, address string) *Account
- func NewAccountWithKeyType(name string, keyType string) *Account
- func (a *Account) AccountID() [20]byte
- func (a *Account) AccountIDHex() string
- func (a *Account) Human() string
- func (a *Account) IOU(currency string, value float64) tx.Amount
- func (a *Account) IsEd25519() bool
- func (a *Account) IsSecp256k1() bool
- func (a *Account) PrivateKeyHex() string
- func (a *Account) PublicKeyHex() string
- func (a *Account) String() string
- type AccountInfo
- type ManualClock
- type TestEnv
- func NewTestEnv(t testing.TB) *TestEnv
- func NewTestEnvBacked(t testing.TB) *TestEnv
- func NewTestEnvWithConfig(t testing.TB, cfg genesis.Config) *TestEnv
- func NewTestEnvWithConfigBacked(t testing.TB, cfg genesis.Config) *TestEnv
- func NewTestEnvWithTxQ(t testing.TB, cfg txq.Config) *TestEnv
- func NewTestEnvWithTxQAndConfig(t testing.TB, txqCfg txq.Config, genesisCfg genesis.Config) *TestEnv
- func (e *TestEnv) AccountInfo(acc *Account) *AccountInfo
- func (e *TestEnv) AdvanceTime(d time.Duration)
- func (e *TestEnv) AuthorizeTrustLine(issuer, holder *Account, currency string)
- func (e *TestEnv) Balance(acc *Account) uint64
- func (e *TestEnv) BalanceIOU(holder *Account, currency string, issuer *Account) float64
- func (e *TestEnv) BaseFee() uint64
- func (e *TestEnv) BumpDirectoryLastPage(acc *Account, targetPage uint64, adjustField string) error
- func (e *TestEnv) BumpSequenceAndDeductAmount(acc *Account, fee uint64)
- func (e *TestEnv) BumpSequenceAndDeductFee(acc *Account)
- func (e *TestEnv) BurnedCount(acc *Account) uint32
- func (e *TestEnv) ClearTrustLineAuth(acc1, acc2 *Account, currency string)
- func (e *TestEnv) Close()
- func (e *TestEnv) CloseAt(targetSeq uint32)
- func (e *TestEnv) CloseWithTimeLeap()
- func (e *TestEnv) CreateOffer(acc *Account, takerGets, takerPays tx.Amount) TxResult
- func (e *TestEnv) CreatePassiveOffer(acc *Account, takerGets, takerPays tx.Amount) TxResult
- func (e *TestEnv) CreateTickets(acc *Account, count uint32) uint32
- func (e *TestEnv) DisableDepositAuth(acc *Account)
- func (e *TestEnv) DisableDisallowIncomingCheck(acc *Account)
- func (e *TestEnv) DisableDisallowIncomingNFTokenOffer(acc *Account)
- func (e *TestEnv) DisableDisallowIncomingPayChan(acc *Account)
- func (e *TestEnv) DisableDisallowIncomingTrustline(acc *Account)
- func (e *TestEnv) DisableFeature(name string)
- func (e *TestEnv) DisableGlobalFreeze(acc *Account)
- func (e *TestEnv) DisableMasterKey(acc *Account)
- func (e *TestEnv) DisableRegularKey(acc *Account)
- func (e *TestEnv) DisableRegularKeyExpect(acc *Account, expectedCode string)
- func (e *TestEnv) DisableRequireAuth(acc *Account)
- func (e *TestEnv) DisableRequireDest(acc *Account)
- func (e *TestEnv) EnableDepositAuth(acc *Account)
- func (e *TestEnv) EnableDisallowIncomingCheck(acc *Account)
- func (e *TestEnv) EnableDisallowIncomingNFTokenOffer(acc *Account)
- func (e *TestEnv) EnableDisallowIncomingPayChan(acc *Account)
- func (e *TestEnv) EnableDisallowIncomingTrustline(acc *Account)
- func (e *TestEnv) EnableFeature(name string)
- func (e *TestEnv) EnableGlobalFreeze(acc *Account)
- func (e *TestEnv) EnableNoFreeze(acc *Account)
- func (e *TestEnv) EnableOpenLedgerReplay()
- func (e *TestEnv) EnableRequireAuth(acc *Account)
- func (e *TestEnv) EnableRequireDest(acc *Account)
- func (e *TestEnv) EscalatedFee() uint64
- func (e *TestEnv) Exists(acc *Account) bool
- func (e *TestEnv) FeatureEnabled(name string) bool
- func (e *TestEnv) ForceOwnerDirEmptyAnchorWithNext(acc *Account, nextPage uint64) error
- func (e *TestEnv) FreezeTrustLine(issuer, holder *Account, currency string)
- func (e *TestEnv) Fund(accounts ...*Account)
- func (e *TestEnv) FundAmount(acc *Account, amount uint64)
- func (e *TestEnv) FundAmountNoRipple(acc *Account, amount uint64)
- func (e *TestEnv) FundNoRipple(accounts ...*Account)
- func (e *TestEnv) GetAccount(name string) *Account
- func (e *TestEnv) GetTxQ() *txq.TxQ
- func (e *TestEnv) HasNoRipple(account, counterparty *Account, currency string) bool
- func (e *TestEnv) IOUBalance(holder, issuer *Account, currency string) *state.Amount
- func (e *TestEnv) IncLedgerSeqForAccDel(acc *Account)
- func (e *TestEnv) IsReplayEnabled() bool
- func (e *TestEnv) LastClosedLedger() *ledger.Ledger
- func (e *TestEnv) Ledger() *ledger.Ledger
- func (e *TestEnv) LedgerEntry(key keylet.Keylet) ([]byte, error)
- func (e *TestEnv) LedgerEntryExists(key keylet.Keylet) bool
- func (e *TestEnv) LedgerSeq() uint32
- func (e *TestEnv) Limit(holder, issuer *Account, currency string) float64
- func (e *TestEnv) MasterAccount() *Account
- func (e *TestEnv) MintedCount(acc *Account) uint32
- func (e *TestEnv) Noop(acc *Account)
- func (e *TestEnv) NoopWithFee(acc *Account, fee uint64)
- func (e *TestEnv) Now() time.Time
- func (e *TestEnv) OpenLedgerFee(customBaseFee uint64) uint64
- func (e *TestEnv) OwnerCount(acc *Account) uint32
- func (e *TestEnv) Pay(acc *Account, drops uint64)
- func (e *TestEnv) PayIOU(sender, receiver *Account, issuer *Account, currency string, amount float64)
- func (e *TestEnv) PayIOUWithSendMax(sender, receiver *Account, issuer *Account, currency string, ...)
- func (e *TestEnv) Preauthorize(owner, authorized *Account)
- func (e *TestEnv) ReimburseWithPayment(acc *Account)
- func (e *TestEnv) RemoveSignerList(acc *Account)
- func (e *TestEnv) ReserveBase() uint64
- func (e *TestEnv) ReserveIncrement() uint64
- func (e *TestEnv) ResetTxQMaxSize()
- func (e *TestEnv) Seq(acc *Account) uint32
- func (e *TestEnv) SeqOrDefault(acc *Account) uint32
- func (e *TestEnv) SetAmendments(names []string)
- func (e *TestEnv) SetBaseFee(baseFee uint64)
- func (e *TestEnv) SetBypassTxQ(bypass bool)
- func (e *TestEnv) SetDelegate(owner, authorized *Account, permissions []string)
- func (e *TestEnv) SetFirstNFTokenSequenceDirect(acc *Account, seq uint32)
- func (e *TestEnv) SetInSetupMode(setup bool)
- func (e *TestEnv) SetMintedNFTokensDirect(acc *Account, count uint32)
- func (e *TestEnv) SetNetworkID(id uint32)
- func (e *TestEnv) SetNextCloseSalt(salt [32]byte)
- func (e *TestEnv) SetOpenLedger(open bool)
- func (e *TestEnv) SetRegularKey(acc, regularKey *Account)
- func (e *TestEnv) SetReserves(reserveBase, reserveIncrement uint64)
- func (e *TestEnv) SetSignerList(acc *Account, quorum uint32, signers []TestSigner)
- func (e *TestEnv) SetTime(t time.Time)
- func (e *TestEnv) SetTransferRate(acc *Account, rate uint32)
- func (e *TestEnv) SetTransferRateDirect(acc *Account, rate uint32)
- func (e *TestEnv) SetVerifySignatures(verify bool)
- func (e *TestEnv) SignWith(txn tx.Transaction, signer *Account) tx.Transaction
- func (e *TestEnv) Submit(transaction interface{}) TxResult
- func (e *TestEnv) SubmitMultiSigned(transaction interface{}, signers []*Account) TxResult
- func (e *TestEnv) SubmitPseudo(transaction interface{}) TxResult
- func (e *TestEnv) SubmitSigned(transaction interface{}) TxResult
- func (e *TestEnv) SubmitSignedWith(transaction interface{}, signer *Account) TxResult
- func (e *TestEnv) TicketCount(acc *Account) uint32
- func (e *TestEnv) Trust(acc *Account, amount tx.Amount)
- func (e *TestEnv) TrustLineExists(acc1, acc2 *Account, currency string) bool
- func (e *TestEnv) TrustLineFlags(account, counterparty *Account, currency string) uint32
- func (e *TestEnv) TxInLedger() uint32
- func (e *TestEnv) TxQMetrics() txq.Metrics
- func (e *TestEnv) Unauthorize(owner, authorized *Account)
- func (e *TestEnv) UnfreezeTrustLine(issuer, holder *Account, currency string)
- func (e *TestEnv) WithT(t testing.TB) *TestEnv
- type TestSigner
- type TxResult
- type TxResultCode
Constants ¶
const ( KeyTypeSecp256k1 = "secp256k1" KeyTypeEd25519 = "ed25519" )
KeyType constants for account key derivation.
const DropsPerXRP int64 = 1_000_000
DropsPerXRP is the number of drops in one XRP.
Variables ¶
This section is empty.
Functions ¶
func AssertBalanceChange ¶
AssertBalanceChange runs a function and asserts the expected balance change. The change can be positive (increase) or negative (decrease).
func AssertNoBalanceChange ¶
AssertNoBalanceChange runs a function and asserts the balance stays the same.
func DecodeAddress ¶
DecodeAddress decodes an XRPL address to a 20-byte account ID.
func Drops ¶
Drops returns the drop amount unchanged. This is a convenience function for clarity when specifying amounts in drops.
func FormatBalance ¶
FormatBalance formats a balance in drops as a human-readable string. For example, 1000000000 drops becomes "1000.000000 XRP".
func IssuedCurrency ¶
IssuedCurrency creates an issued currency amount with custom currency code. The currency code must be 3 characters (e.g., "JPY", "GBP", "CNY").
func IssuedCurrencyFromMantissa ¶
func IssuedCurrencyFromMantissa(gw *Account, currency string, mantissa int64, exponent int) tx.Amount
IssuedCurrencyFromMantissa creates an issued currency amount from mantissa/exponent. Use this when you need precise control over the amount representation.
func NewDisableRegularKeyTx ¶
func NewDisableRegularKeyTx(acc *Account) tx.Transaction
NewDisableRegularKeyTx creates a raw SetRegularKey transaction that clears the regular key.
func NewRemoveSignerListTx ¶
func NewRemoveSignerListTx(acc *Account) tx.Transaction
NewRemoveSignerListTx creates a raw SignerListSet transaction that removes the signer list.
func NewSetRegularKeyTx ¶
func NewSetRegularKeyTx(acc *Account, regularKey *Account) tx.Transaction
NewSetRegularKeyTx creates a raw SetRegularKey transaction that sets a regular key.
func NewSignerListSetTx ¶
func NewSignerListSetTx(acc *Account, quorum uint32, signers []TestSigner) tx.Transaction
NewSignerListSetTx creates a raw SignerListSet transaction without submitting. Use this when you need to submit via SubmitMultiSigned or SubmitSignedWith.
func RequireAccountExists ¶
RequireAccountExists asserts that an account exists in the ledger.
func RequireAccountNotExists ¶
RequireAccountNotExists asserts that an account does not exist in the ledger.
func RequireBalance ¶
RequireBalance asserts that an account has the expected XRP balance in drops. This is a convenience wrapper around require.Equal for balance checks.
func RequireBalanceApprox ¶
func RequireBalanceApprox(t *testing.T, env *TestEnv, acc *Account, expected uint64, tolerance uint64)
RequireBalanceApprox asserts that an account balance is within a tolerance of the expected value. This is useful when fees or other small adjustments affect the exact balance.
func RequireBalanceXRP ¶
RequireBalanceXRP asserts that an account has the expected XRP balance. The expected amount is in whole XRP units (e.g., 100 XRP, not drops).
func RequireBurnedCount ¶
RequireBurnedCount asserts that an account has the expected number of burned NFTokens. Reference: rippled's burnedCount() test helper.
func RequireFlagNotSet ¶
RequireFlagNotSet asserts that a specific flag is NOT set on an account.
func RequireFlagSet ¶
RequireFlagSet asserts that a specific flag is set on an account.
func RequireFlags ¶
RequireFlags asserts that an account has the expected flags set.
func RequireIOUBalance ¶
func RequireIOUBalance(t *testing.T, env *TestEnv, holder, issuer *Account, currency string, expected float64)
RequireIOUBalance asserts that an account has the expected IOU balance. The balance is from the holder's perspective. Reference: rippled's require(env.balance(alice, USD) == USD(100))
func RequireIOUBalanceApprox ¶
func RequireIOUBalanceApprox(t *testing.T, env *TestEnv, holder, issuer *Account, currency string, expected, tolerance float64)
RequireIOUBalanceApprox asserts that an account IOU balance is within a tolerance of the expected value.
func RequireLedgerEntryExists ¶
RequireLedgerEntryExists asserts that a ledger entry exists at the given keylet.
func RequireLedgerEntryNotExists ¶
RequireLedgerEntryNotExists asserts that a ledger entry does NOT exist at the given keylet.
func RequireLines ¶
RequireLines asserts that an account has the expected number of trust lines. This counts RippleState entries in the account's owner directory.
func RequireMintedCount ¶
RequireMintedCount asserts that an account has the expected number of minted NFTokens. Reference: rippled's mintedCount() test helper.
func RequireOffers ¶
RequireOffers asserts that an account has the expected number of offers. This counts Offer entries in the account's owner directory.
func RequireOwnerCount ¶
RequireOwnerCount asserts that an account has the expected owner count.
func RequireSequence ¶
RequireSequence asserts that an account has the expected sequence number.
func RequireSignerListCount ¶
RequireSignerListCount asserts that an account has the expected number of signer lists. On the XRPL, an account can have at most one signer list, so expected is 0 or 1.
func RequireTicketCount ¶
RequireTicketCount asserts that an account has the expected number of tickets. This iterates the owner directory and counts entries of type Ticket (0x0054), matching rippled's owner_count<ltTICKET> behavior.
func RequireTrustLineExists ¶
RequireTrustLineExists asserts that a trust line exists between two accounts for a currency.
func RequireTrustLineNotExists ¶
RequireTrustLineNotExists asserts that a trust line does NOT exist between two accounts for a currency.
func RequireTxClaimed ¶
RequireTxClaimed asserts that a transaction had its fee claimed but wasn't applied. This corresponds to "tec" result codes.
func RequireTxFail ¶
RequireTxFail asserts that a transaction result indicates failure with a specific code.
func RequireTxSuccess ¶
RequireTxSuccess asserts that a transaction result indicates success.
func ResultCodeCategory ¶
ResultCodeCategory returns the category of a result code.
func USD ¶
USD creates a USD issued currency amount with the specified gateway. The amount is specified as a float (e.g., 100.50 for $100.50).
func WithSeq ¶
func WithSeq(transaction tx.Transaction, seq uint32) tx.Transaction
WithSeq sets the sequence number on a transaction manually. This bypasses autofill and allows testing transactions from non-existent accounts. Reference: rippled's seq(1) funclet in test/jtx/seq.h
func WithTicketSeq ¶
func WithTicketSeq(transaction tx.Transaction, ticketSeq uint32) tx.Transaction
WithTicketSeq sets TicketSequence on a transaction (Sequence becomes 0). Reference: rippled's ticket::use(ticketSeq) in ticket.h
func XRPMinusFee ¶
XRPMinusFee calculates expected XRP balance after paying fees. amount is in drops, fee defaults to env's base fee.
func XRPMinusFees ¶
XRPMinusFees calculates expected XRP balance after paying multiple fees.
func XRPTxAmount ¶
XRPTxAmount creates an XRP tx.Amount from drops. This returns a tx.Amount suitable for use in transactions.
func XRPTxAmountFromXRP ¶
XRPTxAmountFromXRP creates an XRP tx.Amount from whole XRP units. For example, XRPTxAmountFromXRP(100) creates an amount of 100 XRP.
Types ¶
type Account ¶
type Account struct {
// Name is a human-readable identifier for the account (used for debugging).
Name string
// KeyType indicates the cryptographic algorithm used ("secp256k1" or "ed25519").
KeyType string
// Seed is the seed bytes used to derive the keypair.
Seed []byte
// Address is the classic XRPL address (e.g., "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh").
Address string
// PublicKey is the compressed public key bytes (33 bytes for secp256k1, 33 for ed25519 with prefix).
PublicKey []byte
// PrivateKey is the private key bytes (32 bytes).
PrivateKey []byte
// ID is the 20-byte account ID derived from the public key.
ID [20]byte
// Sequence tracks the account's sequence number (for test convenience).
Sequence uint32
}
Account represents a test account with keypair and address information.
func MasterAccount ¶
func MasterAccount() *Account
MasterAccount returns the well-known master account derived from "masterpassphrase". This is the genesis account that holds all XRP initially. Address: rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh
func NewAccount ¶
NewAccount creates a new test account with a deterministic keypair derived from the name. Using the same name will always produce the same account, making tests reproducible. By default, uses secp256k1 key derivation.
func NewAccountFromPassphrase ¶
NewAccountFromPassphrase creates a test account from a specific passphrase. This is useful for recreating well-known accounts. Uses secp256k1 by default.
func NewAccountFromPassphraseWithKeyType ¶
NewAccountFromPassphraseWithKeyType creates a test account from a specific passphrase with the specified key type.
func NewAccountFromSeed ¶
NewAccountFromSeed creates a test account from a base58-encoded seed string. This is useful for recreating accounts from known seeds (e.g., from rippled test vectors).
func NewAccountWithAddress ¶
NewAccountWithAddress creates a test account at a specific address. The account has no real keypair — it can only be used as a payment destination (to create/fund an account at that specific address) in test environments with signature verification disabled.
func NewAccountWithKeyType ¶
NewAccountWithKeyType creates a new test account with the specified key type. Supported key types: "secp256k1" and "ed25519".
func (*Account) AccountID ¶
AccountID returns the 20-byte account ID. This is an alias for accessing the ID field directly.
func (*Account) AccountIDHex ¶
AccountIDHex returns the account ID as a hex string.
func (*Account) Human ¶
Human returns the human-readable address of the account. This is equivalent to accessing the Address field directly.
func (*Account) IOU ¶
IOU returns a tx.Amount for this account as issuer of the given currency. Usage: gw.IOU("USD", 100) returns an issued amount of 100 USD from gw. Reference: rippled's Account::operator[]("USD")(100)
func (*Account) IsSecp256k1 ¶
IsSecp256k1 returns true if this account uses secp256k1 cryptography.
func (*Account) PrivateKeyHex ¶
PrivateKeyHex returns the private key as a hex string (uppercase).
func (*Account) PublicKeyHex ¶
PublicKeyHex returns the public key as a hex string (uppercase).
type AccountInfo ¶
type AccountInfo struct {
Address string
Balance uint64
Sequence uint32
OwnerCount uint32
Flags uint32
MintedNFTokens uint32
BurnedNFTokens uint32
FirstNFTokenSequence *uint32
NFTokenMinter string
Domain string
EmailHash string
MessageKey string
WalletLocator string
AccountTxnID [32]byte
TransferRate uint32
TicketCount uint32
}
AccountInfo contains account information from the ledger.
type ManualClock ¶
type ManualClock struct {
// contains filtered or unexported fields
}
ManualClock provides a controllable clock for testing time-dependent behavior.
func NewManualClock ¶
func NewManualClock() *ManualClock
NewManualClock creates a new ManualClock set to a default time. The default is January 1, 2020, 00:00:00 UTC, which is after the Ripple epoch.
func NewManualClockAt ¶
func NewManualClockAt(t time.Time) *ManualClock
NewManualClockAt creates a new ManualClock set to the specified time.
func (*ManualClock) Advance ¶
func (c *ManualClock) Advance(d time.Duration)
Advance moves the clock forward by the specified duration.
func (*ManualClock) Now ¶
func (c *ManualClock) Now() time.Time
Now returns the current time on the clock.
func (*ManualClock) Set ¶
func (c *ManualClock) Set(t time.Time)
Set sets the clock to a specific time.
type TestEnv ¶
type TestEnv struct {
// VerifySignatures enables cryptographic signature verification in the engine.
// Default is false (test mode). Set to true for conformance tests with real tx_blobs.
VerifySignatures bool
// contains filtered or unexported fields
}
TestEnv manages a test ledger environment for transaction testing. It provides a simplified interface for creating accounts, funding them, submitting transactions, and verifying results.
func NewTestEnv ¶
NewTestEnv creates a new test environment with a genesis ledger.
func NewTestEnvBacked ¶
NewTestEnvBacked creates a test environment with PebbleDB-backed SHAMaps. Use this for heavy tests (e.g., crossing_limits with 2000+ offers) that would OOM with unbacked mode. Data goes to disk; only the LRU cache lives in RAM.
func NewTestEnvWithConfig ¶
NewTestEnvWithConfig creates a new test environment with custom genesis configuration.
func NewTestEnvWithConfigBacked ¶
NewTestEnvWithConfigBacked creates a test environment with custom config and PebbleDB backing.
func NewTestEnvWithTxQ ¶
NewTestEnvWithTxQ creates a test environment with a transaction queue. Submit() will route transactions through the TxQ for fee escalation and sequence-gap queuing, matching rippled's behavior when using Env with TxQ. Reference: rippled's test Env routes through NetworkOPs -> TxQ.
func NewTestEnvWithTxQAndConfig ¶
func NewTestEnvWithTxQAndConfig(t testing.TB, txqCfg txq.Config, genesisCfg genesis.Config) *TestEnv
NewTestEnvWithTxQAndConfig creates a test environment with a transaction queue and custom genesis configuration.
func (*TestEnv) AccountInfo ¶
func (e *TestEnv) AccountInfo(acc *Account) *AccountInfo
AccountInfo returns detailed account information.
func (*TestEnv) AdvanceTime ¶
AdvanceTime advances the test clock by the specified duration.
func (*TestEnv) AuthorizeTrustLine ¶
AuthorizeTrustLine authorizes a trust line (when RequireAuth is set on the issuer). Reference: rippled's trust(account, amount, tfSetfAuth)
func (*TestEnv) BalanceIOU ¶
BalanceIOU returns the IOU balance of an account for a specific currency and issuer as float64. This is a convenience method for tests that need simple numeric comparisons.
func (*TestEnv) BumpDirectoryLastPage ¶
BumpDirectoryLastPage moves the last page of an account's owner directory to a target page number. This mirrors rippled's test::jtx::directory::bumpLastPage() which is used to test directory page limit checks by placing the last page near the maximum allowed page number.
The operation: 1. Finds the last page of the owner directory 2. Copies its entries to a new page at targetPage 3. Erases the old last page 4. Updates page chain pointers (root, previous page) 5. Updates each moved entry's adjustField to the new page number
Reference: rippled src/test/jtx/impl/directory.cpp bumpLastPage()
func (*TestEnv) BumpSequenceAndDeductAmount ¶
BumpSequenceAndDeductAmount increments an account's sequence and deducts the specified fee amount directly in the ledger. This is used when the fee to deduct differs from the base fee, e.g., for multi-signed transactions where the fee is baseFee * (1 + numSigners).
func (*TestEnv) BumpSequenceAndDeductFee ¶
BumpSequenceAndDeductFee increments an account's sequence and deducts the base fee directly in the ledger. Used by the conformance runner to match rippled's behavior where tem* results from type-specific preflight (inside doApply) still consume the sequence and fee because the engine's generic preclaim already passed.
func (*TestEnv) BurnedCount ¶
BurnedCount returns the number of NFTokens burned for this issuer. Reference: rippled's burnedCount() test helper.
func (*TestEnv) ClearTrustLineAuth ¶
ClearTrustLineAuth clears the authorization flags on a trust line between two accounts. This directly modifies ledger state, simulating rippled's rawInsert for tests that require unauthorized but funded trust lines.
func (*TestEnv) Close ¶
func (e *TestEnv) Close()
Close closes the current ledger and advances to a new one. This is equivalent to "ledger_accept" in rippled.
When replayOnClose is enabled, Close() simulates the consensus process: it discards the current open ledger state, creates a fresh open ledger from the last closed ledger (parent), and replays all tracked transactions in canonical order with retry passes. This matches rippled's standalone consensus simulation (BuildLedger.cpp).
func (*TestEnv) CloseAt ¶
CloseAt closes ledgers until the ledger reaches the target sequence. If already at or past target, does nothing.
func (*TestEnv) CloseWithTimeLeap ¶
func (e *TestEnv) CloseWithTimeLeap()
CloseWithTimeLeap closes the current ledger with a simulated time leap. A time leap indicates that consensus was slow, causing the TxQ to aggressively reduce txnsExpected back toward the minimum. This matches rippled's behavior when env.close(env.now() + 5s, 10000ms) is called in tests. Reference: rippled TxQ::FeeMetrics::update timeLeap handling
func (*TestEnv) CreateOffer ¶
CreateOffer creates an offer on the DEX. takerGets is what the offer creator will receive (what the taker pays). takerPays is what the offer creator will pay (what the taker gets).
func (*TestEnv) CreatePassiveOffer ¶
CreatePassiveOffer creates a passive offer on the DEX. Passive offers don't immediately consume offers at an equal or better rate.
func (*TestEnv) CreateTickets ¶
CreateTickets creates N tickets for an account. Returns the first ticket sequence number. Reference: rippled's ticket::create(account, count) in ticket.h
func (*TestEnv) DisableDepositAuth ¶
DisableDepositAuth disables the DepositAuth flag on an account.
func (*TestEnv) DisableDisallowIncomingCheck ¶
DisableDisallowIncomingCheck disables the DisallowIncomingCheck flag on an account.
func (*TestEnv) DisableDisallowIncomingNFTokenOffer ¶
DisableDisallowIncomingNFTokenOffer disables the DisallowIncomingNFTokenOffer flag on an account.
func (*TestEnv) DisableDisallowIncomingPayChan ¶
DisableDisallowIncomingPayChan disables the DisallowIncomingPayChan flag on an account.
func (*TestEnv) DisableDisallowIncomingTrustline ¶
DisableDisallowIncomingTrustline disables the DisallowIncomingTrustline flag on an account.
func (*TestEnv) DisableFeature ¶
DisableFeature disables an amendment by name for subsequent transactions. See EnableFeature for the Close()-required semantic. Reference: rippled's Env::disableFeature() in test/jtx/impl/Env.cpp.
func (*TestEnv) DisableGlobalFreeze ¶
DisableGlobalFreeze disables the GlobalFreeze flag on an account. Note: Cannot be cleared if NoFreeze is set.
func (*TestEnv) DisableMasterKey ¶
DisableMasterKey disables the master key on an account using AccountSet. The account must have a regular key or signer list set first.
func (*TestEnv) DisableRegularKey ¶
DisableRegularKey removes the regular key from an account. Reference: rippled's regkey(account, disabled) in regkey.h
func (*TestEnv) DisableRegularKeyExpect ¶
DisableRegularKeyExpect attempts to clear the regular key and expects a specific result.
func (*TestEnv) DisableRequireAuth ¶
DisableRequireAuth disables the RequireAuth flag on an account.
func (*TestEnv) DisableRequireDest ¶
DisableRequireDest disables the RequireDest flag on an account.
func (*TestEnv) EnableDepositAuth ¶
EnableDepositAuth enables the DepositAuth flag on an account. When enabled, the account can only receive payments from preauthorized accounts.
func (*TestEnv) EnableDisallowIncomingCheck ¶
EnableDisallowIncomingCheck enables the DisallowIncomingCheck flag on an account.
func (*TestEnv) EnableDisallowIncomingNFTokenOffer ¶
EnableDisallowIncomingNFTokenOffer enables the DisallowIncomingNFTokenOffer flag on an account.
func (*TestEnv) EnableDisallowIncomingPayChan ¶
EnableDisallowIncomingPayChan enables the DisallowIncomingPayChan flag on an account.
func (*TestEnv) EnableDisallowIncomingTrustline ¶
EnableDisallowIncomingTrustline enables the DisallowIncomingTrustline flag on an account.
func (*TestEnv) EnableFeature ¶
EnableFeature enables an amendment by name for subsequent transactions. Matches rippled's Env::enableFeature() in test/jtx/impl/Env.cpp: the amendment is staged into the rules builder and only takes effect after the next Close() — call e.Close() before submitting transactions that depend on the new amendment.
func (*TestEnv) EnableGlobalFreeze ¶
EnableGlobalFreeze enables the GlobalFreeze flag on an account. When enabled, all trust lines for this account's issued currencies are frozen.
func (*TestEnv) EnableNoFreeze ¶
EnableNoFreeze enables the NoFreeze flag on an account. Once set, this flag cannot be cleared. It prevents the account from freezing trust lines.
func (*TestEnv) EnableOpenLedgerReplay ¶
func (e *TestEnv) EnableOpenLedgerReplay()
EnableOpenLedgerReplay enables the open-ledger consensus replay behavior. When enabled, Close() rebuilds the closed ledger from the parent closed ledger by replaying all tracked transactions in canonical order with retry passes. This matches rippled's standalone consensus simulation.
Use this for tests that depend on:
- terPRE_SEQ transactions being retried after close
- tec transactions being re-applied from a clean state after prerequisite objects are created by batch transactions
Must be called before any Submit calls in the test. Reference: rippled BuildLedger.cpp applyTransactions()
func (*TestEnv) EnableRequireAuth ¶
EnableRequireAuth enables the RequireAuth flag on an account. When enabled, trust lines to this account require authorization.
func (*TestEnv) EnableRequireDest ¶
EnableRequireDest enables the RequireDest flag on an account. When enabled, the account requires a destination tag on incoming payments.
func (*TestEnv) EscalatedFee ¶
EscalatedFee returns the fee (in drops) a transaction should pay to bypass the queue and get directly into the current open ledger. This matches rippled's auto-fill fee computation in TransactionSign.cpp:
escalatedFee = toDrops(openLedgerFeeLevel - 1, baseFee) + 1
Reference: rippled getCurrentNetworkFee() in TransactionSign.cpp
func (*TestEnv) FeatureEnabled ¶
FeatureEnabled returns true if the named amendment is currently enabled. Reference: rippled's Env::enabled() in test/jtx/Env.h
func (*TestEnv) ForceOwnerDirEmptyAnchorWithNext ¶
ForceOwnerDirEmptyAnchorWithNext rewrites the anchor (root) page of an account's owner directory to have an empty Indexes slice while leaving IndexNext pointing at a non-zero continuation page. This reproduces the state rippled's dirIsEmpty must guard against: an emptied anchor whose directory is still non-empty because subsequent pages remain.
Reference: rippled View.cpp dirIsEmpty().
func (*TestEnv) FreezeTrustLine ¶
FreezeTrustLine freezes a specific trust line (issuer-side freeze). Reference: rippled's trust(account, amount, peer, tfSetFreeze)
func (*TestEnv) Fund ¶
Fund funds the specified accounts from the master account. Each account receives the specified amount or a default of 1000 XRP.
func (*TestEnv) FundAmount ¶
FundAmount funds an account with a specific amount. Like rippled's test environment, this also enables DefaultRipple on the account. This is important for trust line behavior - without DefaultRipple, trust lines cannot be deleted when limit is set to 0 (the NoRipple state would be "non-default").
func (*TestEnv) FundAmountNoRipple ¶
FundAmountNoRipple funds an account with a specific amount but does NOT enable DefaultRipple.
func (*TestEnv) FundNoRipple ¶
FundNoRipple funds accounts WITHOUT enabling DefaultRipple. Reference: rippled's noripple(accounts...) in Env.h
func (*TestEnv) GetAccount ¶
GetAccount returns a registered account by name.
func (*TestEnv) GetTxQ ¶
GetTxQ returns the test environment's transaction queue, or nil if not configured.
func (*TestEnv) HasNoRipple ¶
HasNoRipple checks if the account's side of the trust line has NoRipple set.
func (*TestEnv) IOUBalance ¶
IOUBalance returns the IOU balance of an account for a specific currency and issuer. The balance is returned from the perspective of the holder (not the issuer). Positive means the holder has tokens, negative means they owe tokens.
func (*TestEnv) IncLedgerSeqForAccDel ¶
IncLedgerSeqForAccDel closes enough ledgers so account deletion is allowed. rippled requires the account's sequence + 255 to be <= the current ledger sequence. Uses addition instead of subtraction to avoid uint32 underflow. Reference: rippled's incLgrSeqForAccDel() in acctdelete.h
func (*TestEnv) IsReplayEnabled ¶
IsReplayEnabled returns whether open-ledger replay is enabled.
func (*TestEnv) LastClosedLedger ¶
LastClosedLedger returns the most recently closed ledger (LCL), the parent of the current open ledger. Useful for replay-style tests that need to anchor on a real, fully-constructed parent ledger (e.g., post-state derivation tests that replay txs from one closed ledger into a verified successor).
func (*TestEnv) LedgerEntry ¶
LedgerEntry reads a raw ledger entry by keylet.
func (*TestEnv) LedgerEntryExists ¶
LedgerEntryExists checks if a ledger entry exists by keylet.
func (*TestEnv) Limit ¶
Limit returns the trust line limit for an account/issue. Returns 0 if the trust line doesn't exist. Reference: rippled's Env::limit(account, issue)
func (*TestEnv) MasterAccount ¶
MasterAccount returns the master account for the test environment.
func (*TestEnv) MintedCount ¶
MintedCount returns the number of NFTokens minted by this issuer. Reference: rippled's mintedCount() test helper.
func (*TestEnv) Noop ¶
Noop submits a no-op AccountSet to bump an account's sequence number. Reference: rippled's noop(account) in noop.h
func (*TestEnv) NoopWithFee ¶
NoopWithFee submits a no-op AccountSet with a custom fee. Reference: rippled's env(noop(account), fee(f))
func (*TestEnv) OpenLedgerFee ¶
OpenLedgerFee returns the fee (in drops) needed to bypass the queue for a transaction with the given customBaseFee. This is used for batch transactions where the "base fee" is the batch fee (which is higher than the standard base fee due to signers and inner transactions).
Reference: rippled Batch_test.cpp openLedgerFee():
toDrops(metrics.openLedgerFeeLevel, batchFee) + 1
func (*TestEnv) OwnerCount ¶
OwnerCount returns the owner count for an account. It fatals if the account does not exist, matching rippled's Env which throws when querying a non-existent account. Reference: rippled's Env::ownerCount(account) in Env.h
func (*TestEnv) Pay ¶
Pay sends XRP from master to an already-funded account. This is useful for tests that need to top-up an account with additional XRP (e.g., to meet reserve requirements). Unlike FundAmount, this does not register the account or enable DefaultRipple.
func (*TestEnv) PayIOU ¶
func (e *TestEnv) PayIOU(sender, receiver *Account, issuer *Account, currency string, amount float64)
PayIOU sends an IOU payment from sender to receiver. The issuer is the gateway that issued the currency. Reference: rippled's env(pay(sender, receiver, amount))
func (*TestEnv) PayIOUWithSendMax ¶
func (e *TestEnv) PayIOUWithSendMax(sender, receiver *Account, issuer *Account, currency string, amount, sendMax float64)
PayIOUWithSendMax sends an IOU payment with a SendMax limit. Reference: rippled's env(pay(sender, receiver, amount), sendmax(max))
func (*TestEnv) Preauthorize ¶
Preauthorize allows owner to preauthorize authorized for deposits. This creates a DepositPreauth ledger entry.
func (*TestEnv) ReimburseWithPayment ¶
ReimburseWithPayment submits a real Payment from master to reimburse the TrustSet fee, matching rippled's Env::trust() behavior where trust setup includes a Payment(master → account, baseFee) that costs master 2×baseFee (payment amount + tx fee). The Payment is tracked as a setup transaction when inSetupMode=true, so it participates in canonical sort salt and survives replay-on-close.
func (*TestEnv) RemoveSignerList ¶
RemoveSignerList removes the signer list from an account. Reference: rippled's signers(account, none) in multisign.h
func (*TestEnv) ReserveBase ¶
ReserveBase returns the base reserve in drops.
func (*TestEnv) ReserveIncrement ¶
ReserveIncrement returns the reserve increment in drops.
func (*TestEnv) ResetTxQMaxSize ¶
func (e *TestEnv) ResetTxQMaxSize()
ResetTxQMaxSize resets the TxQ's maxSize to nil (no limit). This matches rippled's initial state where maxSize_ is std::nullopt before the first user-initiated processClosedLedger call. In rippled, the genesis close (startGenesisLedger) does NOT call processClosedLedger, so maxSize_ remains nullopt until the first env.close() in the test.
func (*TestEnv) Seq ¶
Seq returns the current sequence number for an account. It fatals if the account does not exist, matching rippled's Env which throws when querying a non-existent account. Use SeqOrDefault for auto-fill paths where the account may not exist yet.
func (*TestEnv) SeqOrDefault ¶
SeqOrDefault returns the current sequence number for an account, or 1 if the account does not exist. This is useful for auto-fill paths where the account may not have been created yet (e.g., the Payment that creates it is the one being submitted).
func (*TestEnv) SetAmendments ¶
SetAmendments replaces the current amendment set with exactly the named amendments. Changes are deferred until the next Close(), matching rippled where enableFeature/disableFeature require close() to take effect. Reference: rippled Env.cpp: "Env::close() must be called for feature enable to take place."
func (*TestEnv) SetBaseFee ¶
SetBaseFee changes the base fee for subsequent transactions. Used to apply post-initFee() fee changes in conformance tests.
func (*TestEnv) SetBypassTxQ ¶
SetBypassTxQ temporarily bypasses TxQ routing. When true, Submit() goes directly to the engine even when a TxQ is configured. This matches rippled's distinction between apply() (direct, used for setup) and submit() (via TxQ).
func (*TestEnv) SetDelegate ¶
SetDelegate creates a Delegate SLE that grants delegation permissions from one account to another. permissions is a list of permission names like "Payment", "AccountDomainSet", etc. Reference: rippled's delegate::set(account, authorize, permissions) in Delegate_test.cpp
func (*TestEnv) SetFirstNFTokenSequenceDirect ¶
SetFirstNFTokenSequenceDirect directly modifies an account's FirstNFTokenSequence field in the ledger, bypassing normal transaction validation. This is used to test boundary conditions with fixNFTokenRemint. Reference: rippled NFToken_test.cpp testMintMaxTokens (env.app().openLedger().modify())
func (*TestEnv) SetInSetupMode ¶
SetInSetupMode controls whether subsequent transactions are tagged as setup (fund/trust) or user (fixture) for replay purposes. Setup transactions are replayed first in submission order; user transactions are replayed second in canonical sorted order.
func (*TestEnv) SetMintedNFTokensDirect ¶
SetMintedNFTokensDirect directly modifies an account's MintedNFTokens field in the ledger, bypassing normal transaction validation. This is used to test boundary conditions (e.g., near 0xFFFFFFFF) without actually minting billions of tokens. Reference: rippled NFToken_test.cpp testMintMaxTokens (env.app().openLedger().modify())
func (*TestEnv) SetNetworkID ¶
SetNetworkID sets the network identifier for the test environment. Networks with ID > 1024 require NetworkID in transactions. Networks with ID <= 1024 are legacy networks and cannot have NetworkID in transactions. Reference: rippled's Config::NETWORK_ID
func (*TestEnv) SetNextCloseSalt ¶
SetNextCloseSalt sets the canonical sort salt for the next replay close. When set, closeWithReplay() uses this salt instead of computing one from the transaction set. Cleared after use.
func (*TestEnv) SetOpenLedger ¶
SetOpenLedger controls whether the engine checks fee adequacy. When false, fee adequacy checks are skipped (matching rippled's closed-ledger behavior).
func (*TestEnv) SetRegularKey ¶
SetRegularKey sets a regular key on an account. Reference: rippled's regkey(account, signer) in regkey.h
func (*TestEnv) SetReserves ¶
SetReserves changes the reserve base and increment for subsequent transactions. Used to apply post-initFee() reserve changes in conformance tests.
func (*TestEnv) SetSignerList ¶
func (e *TestEnv) SetSignerList(acc *Account, quorum uint32, signers []TestSigner)
SetSignerList sets a signer list on an account. Reference: rippled's signers(account, quorum, signerList) in multisign.h
func (*TestEnv) SetTransferRate ¶
SetTransferRate sets the transfer rate for an account. Rate is specified as a multiplier * 1e9 (1e9 = 100%, 1.1e9 = 110% means 10% fee). Use 0 to clear the transfer rate (sets it back to 1e9 / 100%).
func (*TestEnv) SetTransferRateDirect ¶
SetTransferRateDirect modifies the TransferRate directly in ledger state. This bypasses transaction validation, allowing out-of-bounds rates for testing legacy MainNet accounts. Reference: rippled AccountSet_test.cpp lines 446-460 (env.app().openLedger().modify())
func (*TestEnv) SetVerifySignatures ¶
SetVerifySignatures enables or disables signature verification in the engine.
func (*TestEnv) SignWith ¶
func (e *TestEnv) SignWith(txn tx.Transaction, signer *Account) tx.Transaction
SignWith signs a transaction using a specific account's key pair. Sets SigningPubKey and TxnSignature on the transaction. Reference: rippled's sig.h -- sig(account) funclet.
func (*TestEnv) Submit ¶
Submit submits a transaction to the current open ledger. If the transaction doesn't have a sequence number set, it will be auto-filled from the account's current sequence in the ledger.
When a TxQ is configured (via NewTestEnvWithTxQ), Submit routes through the TxQ for fee escalation and sequence-gap queuing. Transactions that cannot afford the escalated fee or have a future sequence are queued and return terQUEUED or terPRE_SEQ respectively.
func (*TestEnv) SubmitMultiSigned ¶
SubmitMultiSigned attaches multi-signatures from the given signers and submits with signature verification enabled. Each signer signs the transaction with their key, sorted by account ID. Reference: rippled's msig(signers...) funclet.
func (*TestEnv) SubmitPseudo ¶
SubmitPseudo submits a pseudo-transaction (EnableAmendment, SetFee, UNLModify) directly to the engine. Pseudo-transactions bypass account lookup, sequence auto-fill, fee deduction, and signature verification. Reference: rippled Change.cpp -- pseudo-txs have zero account, zero fee, no sigs.
func (*TestEnv) SubmitSigned ¶
SubmitSigned signs the transaction with the account's own key and submits with signature verification enabled. The signing account is inferred from the transaction's Account field.
func (*TestEnv) SubmitSignedWith ¶
SubmitSignedWith signs the transaction with a different key (e.g. a regular key) and submits with signature verification enabled. Reference: rippled's sig(account) -- sign with regular key.
func (*TestEnv) TicketCount ¶
TicketCount returns the ticket count for an account (0 if account doesn't exist). Reference: rippled sfTicketCount field on AccountRoot
func (*TestEnv) Trust ¶
Trust creates a trust line and refunds the fee from master. Reference: rippled's Env::trust(amount, account) in Env.h
func (*TestEnv) TrustLineExists ¶
TrustLineExists checks if a trust line exists between two accounts for a currency.
func (*TestEnv) TrustLineFlags ¶
TrustLineFlags returns the flags on a trust line between two accounts. Returns the flags from the perspective of 'account' (which side's flags).
func (*TestEnv) TxInLedger ¶
TxInLedger returns the number of transactions applied to the current open ledger. This is useful for TxQ-related test assertions (e.g., checkMetrics).
func (*TestEnv) TxQMetrics ¶
TxQMetrics returns the current TxQ metrics. Panics if TxQ is not configured. Reference: rippled TxQ::getMetrics(*env.current())
func (*TestEnv) Unauthorize ¶
Unauthorize removes preauthorization for authorized from owner.
func (*TestEnv) UnfreezeTrustLine ¶
UnfreezeTrustLine unfreezes a specific trust line.
type TestSigner ¶
TestSigner represents a signer entry for use in SetSignerList.
type TxResult ¶
type TxResult struct {
// Code is the transaction engine result code (e.g., "tesSUCCESS").
Code string
// Success indicates whether the transaction was successfully applied.
Success bool
// Message provides additional details about the result.
Message string
// Metadata contains the transaction metadata (AffectedNodes, etc.).
Metadata *tx.Metadata
}
TxResult represents the result of applying a transaction.
func ResultSuccess ¶
func ResultSuccess() TxResult
ResultSuccess returns a successful transaction result.
func ResultWithCode ¶
ResultWithCode creates a TxResult with the specified code.
func (TxResult) IsClaimed ¶
IsClaimed returns true if the result code indicates the fee was claimed but the transaction was not applied (tec codes).
func (TxResult) IsMalformed ¶
IsMalformed returns true if the result code indicates the transaction is malformed.
type TxResultCode ¶
type TxResultCode = string
TxResultCode is a type alias for transaction result codes for better documentation.
const ( // Success TesSUCCESS TxResultCode = "tesSUCCESS" // Claimed (tec) - fee claimed but transaction not applied TecCLAIM TxResultCode = "tecCLAIM" TecPATH_PARTIAL TxResultCode = "tecPATH_PARTIAL" TecUNFUNDED_ADD TxResultCode = "tecUNFUNDED_ADD" TecUNFUNDED_OFFER TxResultCode = "tecUNFUNDED_OFFER" TecUNFUNDED_PAYMENT TxResultCode = "tecUNFUNDED_PAYMENT" TecFAILED_PROCESSING TxResultCode = "tecFAILED_PROCESSING" TecDIR_FULL TxResultCode = "tecDIR_FULL" TecINSUF_RESERVE_LINE TxResultCode = "tecINSUF_RESERVE_LINE" TecINSUF_RESERVE_OFFER TxResultCode = "tecINSUF_RESERVE_OFFER" TecNO_DST TxResultCode = "tecNO_DST" TecNO_DST_INSUF_XRP TxResultCode = "tecNO_DST_INSUF_XRP" TecNO_LINE_INSUF_RESERVE TxResultCode = "tecNO_LINE_INSUF_RESERVE" TecNO_LINE_REDUNDANT TxResultCode = "tecNO_LINE_REDUNDANT" TecPATH_DRY TxResultCode = "tecPATH_DRY" TecUNFUNDED TxResultCode = "tecUNFUNDED" TecNO_ALTERNATIVE_KEY TxResultCode = "tecNO_ALTERNATIVE_KEY" TecNO_REGULAR_KEY TxResultCode = "tecNO_REGULAR_KEY" TecOWNERS TxResultCode = "tecOWNERS" TecNO_ISSUER TxResultCode = "tecNO_ISSUER" TecNO_AUTH TxResultCode = "tecNO_AUTH" TecNO_LINE TxResultCode = "tecNO_LINE" TecINSUFF_FEE TxResultCode = "tecINSUFF_FEE" TecFROZEN TxResultCode = "tecFROZEN" TecNO_TARGET TxResultCode = "tecNO_TARGET" TecNO_PERMISSION TxResultCode = "tecNO_PERMISSION" TecNO_ENTRY TxResultCode = "tecNO_ENTRY" TecINSUFFICIENT_RESERVE TxResultCode = "tecINSUFFICIENT_RESERVE" TecNEED_MASTER_KEY TxResultCode = "tecNEED_MASTER_KEY" TecDST_TAG_NEEDED TxResultCode = "tecDST_TAG_NEEDED" TecINTERNAL TxResultCode = "tecINTERNAL" TecOVERSIZE TxResultCode = "tecOVERSIZE" TecCRYPTOCONDITION_ERROR TxResultCode = "tecCRYPTOCONDITION_ERROR" TecINVARIANT_FAILED TxResultCode = "tecINVARIANT_FAILED" TecDUPLICATE TxResultCode = "tecDUPLICATE" TecEXPIRED TxResultCode = "tecEXPIRED" TecHAS_OBLIGATIONS TxResultCode = "tecHAS_OBLIGATIONS" TecINSUFFICIENT_FUNDS TxResultCode = "tecINSUFFICIENT_FUNDS" TecOBJECT_NOT_FOUND TxResultCode = "tecOBJECT_NOT_FOUND" TecLOCKED TxResultCode = "tecLOCKED" TecKILLED TxResultCode = "tecKILLED" // Failure (tef) - transaction not applied, retry possible TefFAILURE TxResultCode = "tefFAILURE" TefALREADY TxResultCode = "tefALREADY" TefBAD_ADD_AUTH TxResultCode = "tefBAD_ADD_AUTH" TefBAD_AUTH TxResultCode = "tefBAD_AUTH" TefBAD_LEDGER TxResultCode = "tefBAD_LEDGER" TefCREATED TxResultCode = "tefCREATED" TefEXCEPTION TxResultCode = "tefEXCEPTION" TefINTERNAL TxResultCode = "tefINTERNAL" TefNO_AUTH_REQUIRED TxResultCode = "tefNO_AUTH_REQUIRED" TefPAST_SEQ TxResultCode = "tefPAST_SEQ" TefWRONG_PRIOR TxResultCode = "tefWRONG_PRIOR" TefMASTER_DISABLED TxResultCode = "tefMASTER_DISABLED" TefMAX_LEDGER TxResultCode = "tefMAX_LEDGER" TefBAD_SIGNATURE TxResultCode = "tefBAD_SIGNATURE" TefBAD_QUORUM TxResultCode = "tefBAD_QUORUM" TefINVARIANT_FAILED TxResultCode = "tefINVARIANT_FAILED" TefTOO_BIG TxResultCode = "tefTOO_BIG" // Retry (ter) - not applied, retry later TerRETRY TxResultCode = "terRETRY" TerFUNDS_SPENT TxResultCode = "terFUNDS_SPENT" TerINSUF_FEE_B TxResultCode = "terINSUF_FEE_B" TerNO_ACCOUNT TxResultCode = "terNO_ACCOUNT" TerNO_AUTH TxResultCode = "terNO_AUTH" TerNO_LINE TxResultCode = "terNO_LINE" TerOWNERS TxResultCode = "terOWNERS" TerPRE_SEQ TxResultCode = "terPRE_SEQ" TerLAST TxResultCode = "terLAST" TerNO_RIPPLE TxResultCode = "terNO_RIPPLE" TerQUEUED TxResultCode = "terQUEUED" // Malformed (tem) - invalid transaction format TemMALFORMED TxResultCode = "temMALFORMED" TemBAD_AMOUNT TxResultCode = "temBAD_AMOUNT" TemBAD_CURRENCY TxResultCode = "temBAD_CURRENCY" TemBAD_EXPIRATION TxResultCode = "temBAD_EXPIRATION" TemBAD_FEE TxResultCode = "temBAD_FEE" TemBAD_ISSUER TxResultCode = "temBAD_ISSUER" TemBAD_LIMIT TxResultCode = "temBAD_LIMIT" TemBAD_OFFER TxResultCode = "temBAD_OFFER" TemBAD_PATH TxResultCode = "temBAD_PATH" TemBAD_PATH_LOOP TxResultCode = "temBAD_PATH_LOOP" TemBAD_REGKEY TxResultCode = "temBAD_REGKEY" TemBAD_SEQUENCE TxResultCode = "temBAD_SEQUENCE" TemBAD_SIGNATURE TxResultCode = "temBAD_SIGNATURE" TemBAD_SRC_ACCOUNT TxResultCode = "temBAD_SRC_ACCOUNT" TemBAD_TRANSFER_RATE TxResultCode = "temBAD_TRANSFER_RATE" TemBAD_TRANSFER_FEE TxResultCode = "temBAD_TRANSFER_FEE" TemDST_IS_SRC TxResultCode = "temDST_IS_SRC" TemDST_NEEDED TxResultCode = "temDST_NEEDED" TemINVALID TxResultCode = "temINVALID" TemINVALID_FLAG TxResultCode = "temINVALID_FLAG" TemREDUNDANT TxResultCode = "temREDUNDANT" TemRIPPLE_EMPTY TxResultCode = "temRIPPLE_EMPTY" TemDISABLED TxResultCode = "temDISABLED" TemBAD_SIGNER TxResultCode = "temBAD_SIGNER" TemBAD_QUORUM TxResultCode = "temBAD_QUORUM" TemBAD_WEIGHT TxResultCode = "temBAD_WEIGHT" TemBAD_TICK_SIZE TxResultCode = "temBAD_TICK_SIZE" TemINVALID_ACCOUNT_ID TxResultCode = "temINVALID_ACCOUNT_ID" TemUNCERTAIN TxResultCode = "temUNCERTAIN" TemUNKNOWN TxResultCode = "temUNKNOWN" TemSEQ_AND_TICKET TxResultCode = "temSEQ_AND_TICKET" TemBAD_SEND_XRP_PATHS TxResultCode = "temBAD_SEND_XRP_PATHS" TemBAD_SEND_XRP_MAX TxResultCode = "temBAD_SEND_XRP_MAX" TemBAD_SEND_XRP_PARTIAL TxResultCode = "temBAD_SEND_XRP_PARTIAL" TemBAD_SEND_XRP_NO_DIRECT TxResultCode = "temBAD_SEND_XRP_NO_DIRECT" )
Transaction result codes for use in assertions.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package amm provides test builders for AMM transactions.
|
Package amm provides test builders for AMM transactions. |
|
Package batch provides test builder helpers for Batch transactions.
|
Package batch provides test builder helpers for Batch transactions. |
|
Package conformance provides a test runner for xrpl-fixtures test vectors.
|
Package conformance provides a test runner for xrpl-fixtures test vectors. |
|
Package consensus provides integration test utilities for multi-node consensus testing.
|
Package consensus provides integration test utilities for multi-node consensus testing. |
|
Package depositpreauth provides fluent transaction builder helpers for DepositPreauth testing, plus integration tests matching rippled's DepositAuth_test.cpp and DepositPreauth_test sections.
|
Package depositpreauth provides fluent transaction builder helpers for DepositPreauth testing, plus integration tests matching rippled's DepositAuth_test.cpp and DepositPreauth_test sections. |
|
Package metadata provides test helpers for validating transaction metadata.
|
Package metadata provides test helpers for validating transaction metadata. |
|
Package mpt provides test helpers for MPT (Multi-Purpose Token) transaction testing.
|
Package mpt provides test helpers for MPT (Multi-Purpose Token) transaction testing. |
|
Package builders provides fluent transaction builder helpers for testing.
|
Package builders provides fluent transaction builder helpers for testing. |
|
Package permissioneddex provides test helpers for PermissionedDEX tests.
|
Package permissioneddex provides test helpers for PermissionedDEX tests. |
|
Package ticket provides test helpers for Ticket transaction testing.
|
Package ticket provides test helpers for Ticket transaction testing. |