testhelpers

package
v0.0.0-...-b096497 Latest Latest
Warning

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

Go to latest
Published: May 26, 2026 License: MIT Imports: 43 Imported by: 0

Documentation

Index

Constants

View Source
const ParticipantInputEnvVar = "PARTICIPANT_INPUT"
View Source
const SpliceVersion = "0.6.3"

SpliceVersion overrides the default version specified by CTF

Variables

This section is empty.

Functions

func AcceptPendingTransferInstruction

func AcceptPendingTransferInstruction(
	ctx context.Context,
	participant canton.Participant,
	transferInstructionClient transferInstructionV1.ClientWithResponsesInterface,
	executingParty string,
	pendingTransferInstructionCID string,
) error

func AllocateParty

func AllocateParty(t *testing.T, participant canton.Participant, partyHint string) string

AllocateParty allocates a new party on the given participant, given the partyHint. It will fail if the party already exists. Returns the new party ID.

func ArchiveAllContracts

func ArchiveAllContracts(t *testing.T, ctx context.Context, participant canton.Participant)

func ChoiceContextFromData

func ChoiceContextFromData(choiceContextData map[string]any) (*apiv2.Value, error)

func ContractCleanup

func ContractCleanup(t *testing.T, ctx context.Context, participants []canton.Participant)

ContractCleanup performs a best-effort attempt at removing all CCIP and MCMS contracts. It can be run as a test cleanup function in order to allow multiple tests to run on a participant in sequence, without having to re-create the participant(s).

func ContractToDisclosedContract

func ContractToDisclosedContract(contract scanProxy.ContractWithState) (*apiv2.DisclosedContract, error)

func CreateTransferPreapproval

func CreateTransferPreapproval(
	ctx context.Context,
	participant canton.Participant,
	scanProxyClient scanProxy.ClientWithResponsesInterface,
	party string,
	holdingCid string,
) (types.CONTRACT_ID, error)

CreateTransferPreapproval creates an AmuletRules TransferPreapproval for the specified party as a receiver. It returns the ContractId of the Preapproval contract at the time of creation. Due to Amulets implementation of preapprovals, the contract ID is not long-lived and should not be used directly. When interacting/using the preapproval, always look it up using the ACS.

func DeduplicateDisclosedContracts

func DeduplicateDisclosedContracts(disclosedContracts ...*apiv2.DisclosedContract) []*apiv2.DisclosedContract

func ExtractChoiceContextValues

func ExtractChoiceContextValues(choiceContext *apiv2.Value) map[string]splice_api_token_metadata_v1.AnyValue

ExtractChoiceContextValues converts a Splice ChoiceContext proto value into the typed map expected by TokenInput.ExtraArgs.Context.Values.

func GetCurrentOffset

func GetCurrentOffset(ctx context.Context, stateService apiv2.StateServiceClient) (int64, error)

func GetDisclosedContractById

func GetDisclosedContractById(ctx context.Context, participant canton.Participant, contractId string) (*apiv2.DisclosedContract, error)

func GetDisclosedContractByTemplateId

func GetDisclosedContractByTemplateId(ctx context.Context, participant canton.Participant, templateId *apiv2.Identifier) (*apiv2.DisclosedContract, error)

func GetFirstOpenMiningRound

func GetFirstOpenMiningRound(ctx context.Context, scanProxyClient scanProxy.ClientWithResponsesInterface) (*apiv2.DisclosedContract, error)

func GetHoldingsBalance

func GetHoldingsBalance(
	ctx context.Context,
	participant canton.Participant,
	instrument *splice_api_token_holding_v1.InstrumentId,
	filters ...Filter,
) (*big.Rat, error)

GetHoldingsBalance sums Numeric amounts for all holdings that pass filters. If instrument is non-nil, only that instrument is included; if nil, every instrument counts.

func GetRegistryAdmin

func GetRegistryAdmin(ctx context.Context, metadataClient tokenMetadataV1.ClientWithResponsesInterface) (string, error)

GetRegistryAdmin reads the already-provisioned token registry admin (AdminId) from scan-proxy registry info. It does not register or mutate admin state.

func GetTransferFactory

func GetTransferFactory(ctx context.Context, transferInstructionClient transferInstructionV1.ClientWithResponsesInterface, registryAdmin, sender, receiver string) (string, []*apiv2.DisclosedContract, map[string]any, error)

PREFERRED: use GetTransferFactoryV2 where amount, instrumentId, and input holdings can be set.

func GrantCanActAs

func GrantCanActAs(t *testing.T, participant canton.Participant, partyID string)

GrantCanActAs grants the participant's user actAs rights for the given partyID

func GrantCanReadAs

func GrantCanReadAs(t *testing.T, participant canton.Participant, partyID string)

GrantCanReadAs grants the participant's user readAs rights for the given partyID.

func HoldingV1InterfaceID

func HoldingV1InterfaceID() *apiv2.Identifier

HoldingV1InterfaceID is the ledger Identifier for the Splice HoldingV1 interface (package name + module + entity).

func ListActiveContractsByInterfaceId

func ListActiveContractsByInterfaceId(ctx context.Context, participant canton.Participant, interfaceId *apiv2.Identifier) ([]*apiv2.ActiveContract, error)

func ListActiveContractsByTemplateId

func ListActiveContractsByTemplateId(ctx context.Context, participant canton.Participant, templateId *apiv2.Identifier) ([]*apiv2.ActiveContract, error)

func LoadChainFromFile

func LoadChainFromFile(t *testing.T, path string) (*canton.Chain, error)

func LoadChainWithCTF

func LoadChainWithCTF(t *testing.T, numberOfValidators int) (*canton.Chain, error)

func MintAMT

func MintAMT(
	ctx context.Context,
	participant canton.Participant,
	metadataClient tokenMetadataV1.ClientWithResponsesInterface,
	transferInstructionClient transferInstructionV1.ClientWithResponsesInterface,
	scanProxyClient scanProxy.ClientWithResponsesInterface,
	toParty string,
	amount string,
) (string, error)

func ResolveAddressFromDatastore

func ResolveAddressFromDatastore(
	ds datastore.DataStore,
	chainsel uint64,
	contractType deployment.ContractType,
	version *semver.Version,
	qualifier string,
) (
	datastore.AddressRef,
	contracts.RawInstanceAddress,
	error,
)

func ResolveRegistryAdmin

func ResolveRegistryAdmin(ctx context.Context, participant canton.Participant) (string, error)

func TemplateIdFromString

func TemplateIdFromString(s string) (*apiv2.Identifier, error)

func UploadDARstoMultipleParticipants

func UploadDARstoMultipleParticipants(ctx context.Context, dars [][]byte, participants ...canton.Participant) ([]string, error)

Types

type Filter

type Filter func(contractID string, hv splice_api_token_holding_v1.HoldingView) bool

Filter decides whether a holding row is included. It receives the contract id and the HoldingV1 view parsed from the create event’s interface views.

func ExcludeCIDs

func ExcludeCIDs(cids []string) Filter

ExcludeCIDs drops holdings whose contract id appears in cids.

func WithHoldingOwner

func WithHoldingOwner(party string) Filter

WithHoldingOwner keeps only holdings whose view owner matches party (after trimming).

func WithUnlockedHoldingsOnly

func WithUnlockedHoldingsOnly() Filter

WithUnlockedHoldingsOnly keeps only holdings with no Lock in the view (unlocked balance).

type ListedHolding

type ListedHolding struct {
	ContractID string
	View       splice_api_token_holding_v1.HoldingView
	Amount     *big.Rat
}

ListedHolding is one on-ledger row for a token holding: the contract id, the HoldingV1 view from the create event, and Amount parsed as *big.Rat for sums and comparisons.

func ListHoldingsForInstrument

func ListHoldingsForInstrument(
	ctx context.Context,
	participant canton.Participant,
	instrument *splice_api_token_holding_v1.InstrumentId,
	filters ...Filter,
) ([]ListedHolding, error)

ListHoldingsForInstrument loads active contracts that implement HoldingV1, parses each Holding view, applies instrument and Filter predicates, and returns ListedHolding rows with parseable amounts. instrument nil matches every instrument (same rule as GetHoldingsBalance).

func ListedHoldingsFromTransactionEventsForInstrument

func ListedHoldingsFromTransactionEventsForInstrument(events []*apiv2.Event, inst splice_api_token_holding_v1.InstrumentId, filters ...Filter) ([]ListedHolding, error)

ListedHoldingsFromTransactionEventsForInstrument returns HoldingV1 rows parsed from Created events in a transaction that match inst and pass all filters (same rules as ListHoldingsForInstrument).

func SelectHoldingsForInstrument

func SelectHoldingsForInstrument(rows []ListedHolding, minAmounts []*big.Rat) ([]ListedHolding, error)

SelectHoldingsForInstrument assigns len(minAmounts) different contract IDs from rows to output slots.

Rows must already be limited to a single instrument and any caller-side filters (for example via ListHoldingsForInstrument with the desired instrument and Filter values).

Greedy: sort rows by amount ascending, sort slots by required minimum descending, then for each slot choose the smallest unused row whose amount meets that minimum. Output index i corresponds to minAmounts[i]; a nil entry in minAmounts is treated as zero. TODO: should receive instrument as parameter to allow instrument-specific selection

type ParticipantConfig

type ParticipantConfig struct {
	Name             string `toml:"name,omitempty"`
	JWT              string `toml:"jwt"`
	UserName         string `toml:"username"`
	Party            string `toml:"party,omitempty"`
	JSONLedgerAPIURL string `toml:"json_ledger_api_url"`
	GRPCLedgerAPIURL string `toml:"grpc_ledger_api_url"`
	AdminAPIURL      string `toml:"admin_api_url"`
	ValidatorAPIURL  string `toml:"validator_api_url"`
}

type ParticipantInput

type ParticipantInput struct {
	Selector     uint64              `toml:"chain_selector"`
	Participants []ParticipantConfig `toml:"participants"`
}

ParticipantInput provides the input configuration for participants, when not using CTF

type TestConfig

type TestConfig struct {
	NumberOfParticipants int
}

func DefaultTestConfig

func DefaultTestConfig() TestConfig

type TestEnvironment

type TestEnvironment struct {
	Logger zerolog.Logger
	Chain  canton.Chain
}

func NewTestEnvironment

func NewTestEnvironment(t *testing.T, options ...TestOption) TestEnvironment

type TestOption

type TestOption func(env *TestConfig)

func WithNumberOfParticipants

func WithNumberOfParticipants(n int) TestOption

type TransferFactoryV2

type TransferFactoryV2 struct {
	FactoryID          string
	DisclosedContracts []*apiv2.DisclosedContract
	ChoiceContextData  map[string]any
	TransferKind       transferInstructionV1.TransferFactoryWithChoiceContextTransferKind
}

TransferFactoryV2 is the transfer-instruction registry response (factory id, disclosures, choice context, transfer kind).

func GetTransferFactoryV2

func GetTransferFactoryV2(
	ctx context.Context,
	transferInstructionClient transferInstructionV1.ClientWithResponsesInterface,
	registryAdmin string,
	transfer splice_api_token_transfer_instruction_v1.Transfer,
) (*TransferFactoryV2, error)

GetTransferFactoryV2 returns factory id, disclosures, choice context data, and transfer kind for the given transfer probe. Callers should not reuse the same response across materially different transfers (see Splice OpenAPI notes).

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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