mpt

package
v0.0.0-...-19a5819 Latest Latest
Warning

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

Go to latest
Published: May 18, 2026 License: ISC Imports: 14 Imported by: 0

Documentation

Overview

Package mpt provides test helpers for MPT (Multi-Purpose Token) transaction testing. These helpers mirror rippled's test/jtx/mpt.h MPTTester class.

Index

Constants

View Source
const (
	// MPTokenIssuanceCreate flags
	TfMPTCanLock     = mpttx.MPTokenIssuanceCreateFlagCanLock
	TfMPTRequireAuth = mpttx.MPTokenIssuanceCreateFlagRequireAuth
	TfMPTCanEscrow   = mpttx.MPTokenIssuanceCreateFlagCanEscrow
	TfMPTCanTrade    = mpttx.MPTokenIssuanceCreateFlagCanTrade
	TfMPTCanTransfer = mpttx.MPTokenIssuanceCreateFlagCanTransfer
	TfMPTCanClawback = mpttx.MPTokenIssuanceCreateFlagCanClawback

	// MPTokenIssuanceSet flags
	TfMPTLock   = mpttx.MPTokenIssuanceSetFlagLock
	TfMPTUnlock = mpttx.MPTokenIssuanceSetFlagUnlock

	// MPTokenAuthorize flags
	TfMPTUnauthorize = mpttx.MPTokenAuthorizeFlagUnauthorize

	// Payment flags for MPT payment tests
	TfNoRippleDirect = payment.PaymentFlagNoDirectRipple
	TfLimitQuality   = payment.PaymentFlagLimitQuality
	TfPartialPayment = payment.PaymentFlagPartialPayment

	// maxMPTokenAmount matches rippled's maxMPTokenAmount (63-bit max)
	MaxMPTokenAmount uint64 = 0x7FFFFFFFFFFFFFFF
)

Variables

This section is empty.

Functions

func MakeMPTIDHexFromAddr

func MakeMPTIDHexFromAddr(sequence uint32, address string) string

MakeMPTIDHexFromAddr creates a hex-encoded MPTokenIssuanceID from sequence and address string. Useful for tests that need to compute an ID before the tester's Create() is called.

func PtrString

func PtrString(v string) *string

PtrString returns a pointer to a string.

func PtrUint8

func PtrUint8(v uint8) *uint8

PtrUint8 returns a pointer to a uint8.

func PtrUint16

func PtrUint16(v uint16) *uint16

PtrUint16 returns a pointer to a uint16.

func PtrUint32

func PtrUint32(v uint32) *uint32

PtrUint32 returns a pointer to a uint32.

func PtrUint64

func PtrUint64(v uint64) *uint64

PtrUint64 returns a pointer to a uint64.

Types

type AuthorizeOpts

type AuthorizeOpts struct {
	// Account is who submits the transaction (default: issuer)
	Account *jtx.Account
	// Holder is the holder field in the transaction (for issuer authorizing a holder)
	Holder *jtx.Account
	// ID overrides the issuance ID
	ID string
	// OwnerCount is the expected owner count for the submitter after the operation
	OwnerCount *uint32
	// HolderCount is the expected owner count for the holder/account
	HolderCount *uint32
	// Flags are the transaction flags (e.g., tfMPTUnauthorize)
	Flags uint32
	// Err is the expected error code (empty means expect success)
	Err string
}

AuthorizeOpts configures an MPTokenAuthorize transaction. Reference: rippled MPTAuthorize struct

type CreateOpts

type CreateOpts struct {
	// MaxAmt is the maximum amount (optional)
	MaxAmt *uint64
	// AssetScale is the decimal scale (optional)
	AssetScale *uint8
	// TransferFee is the transfer fee in basis points (optional)
	TransferFee *uint16
	// Metadata is the hex-encoded metadata (optional).
	// Use nil to not set metadata, use &"" to set empty metadata (should return temMALFORMED).
	Metadata *string
	// OwnerCount is the expected owner count after the operation (for verification)
	OwnerCount *uint32
	// HolderCount is the expected holder owner count (not used for create, but for parity)
	HolderCount *uint32
	// Flags are the transaction flags
	Flags uint32
	// Err is the expected error code (nil means expect success)
	Err string
}

CreateOpts configures an MPTokenIssuanceCreate transaction. Reference: rippled MPTCreate struct

type DestroyOpts

type DestroyOpts struct {
	// Issuer overrides the account submitting the destroy (default: tester's issuer)
	Issuer *jtx.Account
	// ID overrides the issuance ID to destroy
	ID string
	// OwnerCount is the expected owner count after the operation
	OwnerCount *uint32
	// Flags are the transaction flags
	Flags uint32
	// Err is the expected error code (nil means expect success)
	Err string
}

DestroyOpts configures an MPTokenIssuanceDestroy transaction. Reference: rippled MPTDestroy struct

type MPTInit

type MPTInit struct {
	// Holders are the holder accounts to create and fund
	Holders []*jtx.Account

	// XRP is the amount to fund the issuer (in drops). Default: 10,000 XRP
	XRP uint64

	// XRPHolders is the amount to fund each holder (in drops). Default: 10,000 XRP
	XRPHolders uint64

	// Fund controls whether accounts are funded. Default: true
	Fund bool
}

MPTInit configures how the MPTTester is initialized. Reference: rippled MPTInit struct

type MPTTester

type MPTTester struct {
	// contains filtered or unexported fields
}

MPTTester manages an MPT issuance lifecycle for testing. It tracks the issuer, holders, and issuance ID, and provides convenience methods for creating, destroying, authorizing, and setting MPT issuances.

func NewMPTTester

func NewMPTTester(t *testing.T, env *jtx.TestEnv, issuer *jtx.Account, init ...MPTInit) *MPTTester

NewMPTTester creates a new MPTTester for the given issuer. It funds the issuer and holders unless Fund is false. Reference: rippled MPTTester::MPTTester()

func NewMPTTesterNoFund

func NewMPTTesterNoFund(t *testing.T, env *jtx.TestEnv, issuer *jtx.Account) *MPTTester

NewMPTTesterNoFund creates an MPTTester without funding accounts. Use this when you need to control funding yourself.

func (*MPTTester) Authorize

func (m *MPTTester) Authorize(opts AuthorizeOpts)

Authorize submits an MPTokenAuthorize transaction. Reference: rippled MPTTester::authorize()

func (*MPTTester) CheckMPTokenAmount

func (m *MPTTester) CheckMPTokenAmount(holder *jtx.Account, expected int64) bool

CheckMPTokenAmount verifies the MPTAmount balance for a holder. Reference: rippled MPTTester::checkMPTokenAmount()

func (*MPTTester) CheckMPTokenOutstandingAmount

func (m *MPTTester) CheckMPTokenOutstandingAmount(expected int64) bool

CheckMPTokenOutstandingAmount verifies the OutstandingAmount on the issuance. Reference: rippled MPTTester::checkMPTokenOutstandingAmount()

func (*MPTTester) Claw

func (m *MPTTester) Claw(issuer, holder *jtx.Account, amount int64, expectedErr ...string)

Claw submits an MPT clawback transaction. Reference: rippled MPTTester::claw()

func (*MPTTester) Create

func (m *MPTTester) Create(opts CreateOpts)

Create submits an MPTokenIssuanceCreate transaction. Reference: rippled MPTTester::create()

func (*MPTTester) Destroy

func (m *MPTTester) Destroy(opts DestroyOpts)

Destroy submits an MPTokenIssuanceDestroy transaction. Reference: rippled MPTTester::destroy()

func (*MPTTester) IssuanceID

func (m *MPTTester) IssuanceID() string

IssuanceID returns the 48-char hex MPTokenIssuanceID.

func (*MPTTester) Issuer

func (m *MPTTester) Issuer() *jtx.Account

Issuer returns the issuer account.

func (*MPTTester) MPTAmount

func (m *MPTTester) MPTAmount(amount int64) tx.Amount

MPTAmount creates an MPT tx.Amount for use in payments and other transactions. This creates an IOU-style amount with the MPT issuance ID as the "currency" and the issuer address.

func (*MPTTester) Pay

func (m *MPTTester) Pay(src, dest *jtx.Account, amount int64, expectedErr ...string)

Pay sends an MPT payment from src to dest. Reference: rippled MPTTester::pay()

func (*MPTTester) PayFull

func (m *MPTTester) PayFull(src, dest *jtx.Account, amount, sendMax, deliverMin int64, flags uint32, expectedErr ...string)

PayFull sends an MPT payment with SendMax, DeliverMin, and flags.

func (*MPTTester) PayWithFlags

func (m *MPTTester) PayWithFlags(src, dest *jtx.Account, amount int64, flags uint32, expectedErr ...string)

PayWithFlags sends an MPT payment with custom flags.

func (*MPTTester) PayWithSendMax

func (m *MPTTester) PayWithSendMax(src, dest *jtx.Account, amount int64, sendMax int64, expectedErr ...string)

PayWithSendMax sends an MPT payment with SendMax.

func (*MPTTester) RequireMPTokenAmount

func (m *MPTTester) RequireMPTokenAmount(holder *jtx.Account, expected int64)

RequireMPTokenAmount asserts the MPTAmount balance for a holder.

func (*MPTTester) Set

func (m *MPTTester) Set(opts SetOpts)

Set submits an MPTokenIssuanceSet transaction. Reference: rippled MPTTester::set()

type SetOpts

type SetOpts struct {
	// Account is who submits the transaction (default: issuer)
	Account *jtx.Account
	// Holder is the holder account to modify
	Holder *jtx.Account
	// ID overrides the issuance ID
	ID string
	// Flags are the transaction flags (tfMPTLock, tfMPTUnlock)
	Flags uint32
	// Err is the expected error code (empty means expect success)
	Err string
}

SetOpts configures an MPTokenIssuanceSet transaction. Reference: rippled MPTSet struct

Jump to

Keyboard shortcuts

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