testutils

package
v0.0.0-...-6e7f8b6 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2026 License: MIT Imports: 51 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DevnetUrl      = "https://fullnode.devnet.sui.io:443"
	TestnetUrl     = "https://fullnode.testnet.sui.io:443"
	LocalUrl       = "http://127.0.0.1:9000"
	LocalFaucetUrl = "http://127.0.0.1:9123/gas"
)

Network URLs

View Source
const (
	SuiMainnet  = "mainnet"
	SuiTestnet  = "testnet"
	SuiDevnet   = "devnet"
	SuiLocalnet = "localnet"
)

Network environments

View Source
const (
	ACCOUNT_1_SEED = "0000000000000000000000000000000000000000000000000000000000000001"
	ACCOUNT_2_SEED = "0000000000000000000000000000000000000000000000000000000000000002"
	ACCOUNT_3_SEED = "0000000000000000000000000000000000000000000000000000000000000003"
)
View Source
const (
	TokenPoolTypeLockRelease TokenPoolType = "lock_release_token_pool"
	TokenPoolTypeBurnMint    TokenPoolType = "burn_mint_token_pool"
	TokenPoolTypeManaged     TokenPoolType = "managed_token_pool"
	TokenPoolTypeBase        TokenPoolType = "token_pool"
	TokenPoolTypeUSDC        TokenPoolType = "usdc_token_pool"
	ZeroAddress              string        = "0x0000000000000000000000000000000000000000000000000000000000000000"
)
View Source
const ADDRESS_LENGTH = 20
View Source
const DefaultByteSize = 32
View Source
const KEYPAIR_LENGTH = 64
View Source
const PUBKEY_LENGTH = 32
View Source
const SignatureComponents = 2 // R and S components in ECDSA signature

Variables

This section is empty.

Functions

func BoolPointer

func BoolPointer(b bool) *bool

func BuildContract

func BuildContract(t *testing.T, contractPath string)

func BuildSetup

func BuildSetup(t *testing.T, packagePath string) string

func CalculateSignedHash

func CalculateSignedHash(rootHash [32]byte, validUntil uint64) [32]byte

func ComputeMessageDataHash

func ComputeMessageDataHash(
	metadataHash [32]byte,
	messageID [32]byte,
	receiver []byte,
	sequenceNumber uint64,
	gasLimit *big.Int,
	nonce uint64,
	sender []byte,
	data []byte,
	tokenAmounts []ccipocr3.RampTokenAmount,
	destGasAmount uint32,
) ([32]byte, error)

This is the equivalent of ccip_offramp::calculate_message_hash. This is similar to the EVM version, except for 32-byte addresses and no dynamic offsets.

func ComputeMetadataHash

func ComputeMetadataHash(
	sourceChainSelector uint64,
	destinationChainSelector uint64,
	onRamp []byte,
) ([32]byte, error)

This is the equivalent of ccip_offramp::calculate_metadata_hash. This is similar to the EVM version, except for the separator, 32-byte addresses, and no dynamic offsets. See https://github.com/smartcontractkit/chainlink-aptos/blob/d2cf1852ffdbf80fa55b0c834ebef7f44a46d843/contracts/ccip/ccip_offramp/sources/offramp.move#L1044

func ConfigureOnRampChainWriter

func ConfigureOnRampChainWriter(
	log logger.Logger,
	ccipPackageId string,
	ccipOnrampPackageId string,
	tokenPools []TokenToolDetails,
	publicKeyBytes []byte,
	feeTokenType string,
	linkTokenType string,
	ethTokenType string,
) (cwConfig.ChainWriterConfig, error)

ConfigureOnRampChainWriter creates a single ChainWriterConfig that contains two PTB configurations: one for message passing and one for token transfers with messaging

func DrainAccountCoins

func DrainAccountCoins(t *testing.T, ctx context.Context, lgr logger.Logger, accountAddress string, suiKeystore loop.Keystore, cli *client.PTBClient, suiCoins []models.CoinData, receiver string) error

func ExtractStruct

func ExtractStruct[T any](t *testing.T, payload any) *T

func FundWithFaucet

func FundWithFaucet(log logger.Logger, network string, recipient string) error

FundWithFaucet Funds a Sui account with test tokens using the Sui faucet API. NOTE: The Sui faucet must be already running.

It logs the funding details and attempts to request tokens from the faucet. Parameters: - logger: A logger instance used to log the funding process. - network: The network from which the faucet tokens are requested. Use "sui/constant" (e.g., "SuiLocalnet"). - recipient: The recipient's address to fund. Returns an error if the faucet request fails or if there is an issue determining the faucet host.

func GenerateAccountKeyPair

func GenerateAccountKeyPair(t *testing.T) (ed25519.PrivateKey, ed25519.PublicKey, string, error)

GenerateAccountKeyPair Generates a public/private keypair with the ed25519 signature algorithm, then derives the address from the public key. Returns (private key, public key, address, error).

func GenerateFromHexSeed

func GenerateFromHexSeed(seed string) (*ecdsa.PrivateKey, error)

GenerateFromHexSeed generates a deterministic Ethereum key pair from a hex seed

func GenerateKeyPair

func GenerateKeyPair() (*ecdsa.PrivateKey, error)

GenerateKeyPair generates a new Ethereum key pair for testing

func GenerateSignatures

func GenerateSignatures(t *testing.T, signers []ecdsa.PrivateKey, signedHash [32]byte) [][]byte

func GetAccountAndKeyFromSui

func GetAccountAndKeyFromSui(testKeystore *TestKeystore) (string, []byte)

func GetActiveAddressFromSuiConfig

func GetActiveAddressFromSuiConfig() (string, error)

GetActiveAddressFromSuiConfig retrieves the active address from the Sui client configuration file located at ~/.sui/sui_config/client.yaml

func GetFaucetHost

func GetFaucetHost(network string) string

func HashOp

func HashOp(op *Op) common.Hash

func HashPair

func HashPair(left, right [32]byte) [32]byte

func HashRootMetadata

func HashRootMetadata(metadata RootMetadata) common.Hash

func IntPointer

func IntPointer(i int) *int

func Keccak256Fixed

func Keccak256Fixed(in []byte) [32]byte

func LoadCompiledModules

func LoadCompiledModules(packageName string, contractPath string) ([]string, error)

LoadCompiledModules given a path to an already built contract, this method will find all the files ending with `.mv`

func PatchContractAddressTOML

func PatchContractAddressTOML(t *testing.T, contractPath, name, address string)

PatchContractAddressTOML edits one entry under [addresses]. Same as PatchContractDevAddressTOML, but for [addresses] section.

func PatchContractDevAddressTOML

func PatchContractDevAddressTOML(t *testing.T, contractPath, name, address string)

PatchContractDevAddressTOML edits one entry under [dev-addresses]. contractPath : folder that contains Move.toml name : key to patch (e.g. "mcms") address : new hex value (e.g. "0x0000")

func PrettyPrintDebug

func PrettyPrintDebug(log logger.Logger, data any, label string)

func QueryCreatedObjectID

func QueryCreatedObjectID(objectChanges []ObjectChange, packageID, module, structName string) (string, error)

QueryCreatedObjectID queries the created object ID for a given package ID, module, and struct name.

func SerializeCommitReport

func SerializeCommitReport(report CommitReport) ([]byte, error)

SerializeCommitReport serializes a CommitReport using BCS format to match the Move contract's expected deserialization format. The Move contract expects the following order: 1. TokenPriceUpdates (vector of TokenPriceUpdate) 2. GasPriceUpdates (vector of GasPriceUpdate) 3. BlessedMerkleRoots (vector of MerkleRoot) 4. UnblessedMerkleRoots (vector of MerkleRoot) 5. RMNSignatures (vector of fixed 64-byte vectors)

func SerializeExecutionReport

func SerializeExecutionReport(report ExecutionReport) ([]byte, error)

SerializeExecutionReport serializes an ExecutionReport using BCS format to match the Move contract's expected deserialization format. The Move contract expects the following order: 1. SourceChainSelector (u64) 2. Message (Any2SuiRampMessage) 3. OffchainTokenData (vector<vector<u8>>) 4. Proofs (vector<vector<u8>>)

func SerializeScheduleBatchParams

func SerializeScheduleBatchParams(ops []TimelockOperation, predecessor []byte, salt []byte, delay uint64) ([]byte, error)

func SetupClients

func SetupClients(
	t *testing.T,
	rpcURL string,
	keystore loop.Keystore,
	logg logger.Logger,
	gasLimit int64,
) (*client.PTBClient, *txm.SuiTxm, *txm.InMemoryStore)

setupClients initializes the Sui and relayer clients.

func StartSuiNode

func StartSuiNode(nodeType NodeEnvType) (*exec.Cmd, error)

StartSuiNode starts a local Sui node using Docker

func StringPointer

func StringPointer(s string) *string

func Uint16Pointer

func Uint16Pointer(i uint16) *uint16

func Uint32Pointer

func Uint32Pointer(i uint32) *uint32

func Uint64Pointer

func Uint64Pointer(i uint64) *uint64

func Uint8Pointer

func Uint8Pointer(i uint8) *uint8

func ValidateJSON

func ValidateJSON(input any, schemaJSON string) error

func VerifySignatureRecovery

func VerifySignatureRecovery(t *testing.T, signature []byte, signedHash []byte, address []byte) []byte

VerifySignatureRecovery verifies that a given signature and a signed hash can be used to recover the provided address

Types

type Any2SuiRampMessage

type Any2SuiRampMessage struct {
	Header        RampMessageHeader      `json:"header"`
	Sender        []byte                 `json:"sender"`
	Data          []byte                 `json:"data"`
	Receiver      []byte                 `json:"receiver"`  // address in Move becomes []byte for 32-byte Sui address
	GasLimit      *big.Int               `json:"gas_limit"` // u256 in Move becomes *big.Int in Go
	TokenReceiver []byte                 `json:"token_receiver"`
	TokenAmounts  []Any2SuiTokenTransfer `json:"token_amounts"`
}

Any2SuiRampMessage represents the ramp message structure from offramp.move Matches the Move struct: public struct Any2SuiRampMessage has drop

func NewAny2SuiRampMessage

func NewAny2SuiRampMessage(
	header RampMessageHeader,
	sender []byte,
	data []byte,
	receiver []byte,
	gasLimit *big.Int,
	tokenReceiver []byte,
	tokenAmounts []Any2SuiTokenTransfer,
) Any2SuiRampMessage

Helper function to create an Any2SuiRampMessage

type Any2SuiTokenTransfer

type Any2SuiTokenTransfer struct {
	SourcePoolAddress []byte   `json:"source_pool_address"`
	DestTokenAddress  []byte   `json:"dest_token_address"` // address in Move becomes []byte for 32-byte Sui address
	DestGasAmount     uint32   `json:"dest_gas_amount"`
	ExtraData         []byte   `json:"extra_data"`
	Amount            *big.Int `json:"amount"` // u256 in Move becomes *big.Int in Go
}

Any2SuiTokenTransfer represents a token transfer structure from offramp.move Matches the Move struct: public struct Any2SuiTokenTransfer has drop

func NewAny2SuiTokenTransfer

func NewAny2SuiTokenTransfer(
	sourcePoolAddress []byte,
	destTokenAddress []byte,
	destGasAmount uint32,
	extraData []byte,
	amount *big.Int,
) Any2SuiTokenTransfer

Helper function to create an Any2SuiTokenTransfer

type CommitReport

type CommitReport struct {
	PriceUpdates         PriceUpdates
	BlessedMerkleRoots   []MerkleRoot
	UnblessedMerkleRoots []MerkleRoot
	RMNSignatures        [][]byte
}

CommitReport represents the commit report structure from offramp.move Matches the Move struct: public struct CommitReport has store, drop, copy

func GetCommitReport

func GetCommitReport(
	onRampAddress []byte,
	merkleRoot []byte,
	tokenID string,
	price *big.Int,
	chainSelector uint64,
	seqNumStart uint64,
	seqNumEnd uint64,
	gasPrice *big.Int,
	r []byte,
	s []byte,
) CommitReport

func NewCommitReport

func NewCommitReport() *CommitReport

Helper function to create a CommitReport with proper byte slice initialization

type ContractObject

type ContractObject struct {
	ObjectID    string
	PackageName string
	StructName  string
}

type Contracts

type Contracts struct {
	Path     string
	Name     string
	ModuleID string
	Objects  []ContractObject
}

type ECDSAKeyPair

type ECDSAKeyPair struct {
	PrivateKey ecdsa.PrivateKey
	PublicKey  ecdsa.PublicKey
	Address    []byte
}

type ExecutionReport

type ExecutionReport struct {
	SourceChainSelector uint64             `json:"source_chain_selector"`
	Message             Any2SuiRampMessage `json:"message"`
	OffchainTokenData   [][]byte           `json:"offchain_token_data"`
	Proofs              [][]byte           `json:"proofs"`
}

ExecutionReport represents the execution report structure from offramp.move Matches the Move struct: public struct ExecutionReport has drop

func GetExecutionReportFromCCIP

func GetExecutionReportFromCCIP(
	sourceChainSelector uint64,
	message cciptypes.Message,
	offchainTokenData [][]byte,
	proofs [][]byte,
	gasAmount uint32,
	tokenReceiver []byte,
) ExecutionReport

Helper function to create an ExecutionReport from CCIP types

func NewExecutionReport

func NewExecutionReport(sourceChainSelector uint64) *ExecutionReport

Helper function to create a new ExecutionReport with proper initialization

type FakeSuiPTBClient

type FakeSuiPTBClient struct {
	// Status controls the simulated response for GetTransactionStatus
	Status client.TransactionResult
	// CoinsData controls the simulated response for GetCoinsByAddress
	CoinsData  []models.CoinData
	MockClient sui.ISuiAPI
}

FakeSuiPTBClient implements the SuiPTBClient interface for testing

func (*FakeSuiPTBClient) BlockByDigest

func (c *FakeSuiPTBClient) BlockByDigest(ctx context.Context, txDigest string) (*client.SuiTransactionBlockResponse, error)

func (*FakeSuiPTBClient) EstimateGas

func (c *FakeSuiPTBClient) EstimateGas(ctx context.Context, txBytes string) (uint64, error)

func (*FakeSuiPTBClient) FinishPTBAndSend

func (*FakeSuiPTBClient) GetBlockById

func (c *FakeSuiPTBClient) GetBlockById(ctx context.Context, checkpointId string) (models.CheckpointResponse, error)

func (*FakeSuiPTBClient) GetCCIPPackageID

func (c *FakeSuiPTBClient) GetCCIPPackageID(ctx context.Context, offRampPackageID string, signerAddress string) (string, error)

func (*FakeSuiPTBClient) GetCache

func (c *FakeSuiPTBClient) GetCache() *cache.Cache

func (*FakeSuiPTBClient) GetCachedValue

func (c *FakeSuiPTBClient) GetCachedValue(key string) (any, bool)

func (*FakeSuiPTBClient) GetCachedValues

func (c *FakeSuiPTBClient) GetCachedValues(keys []string) (map[string]any, bool)

func (*FakeSuiPTBClient) GetClient

func (c *FakeSuiPTBClient) GetClient() sui.ISuiAPI

func (*FakeSuiPTBClient) GetCoinsByAddress

func (c *FakeSuiPTBClient) GetCoinsByAddress(ctx context.Context, address string) ([]models.CoinData, error)

func (*FakeSuiPTBClient) GetLatestEpoch

func (c *FakeSuiPTBClient) GetLatestEpoch(ctx context.Context) (string, error)

func (*FakeSuiPTBClient) GetLatestPackageId

func (c *FakeSuiPTBClient) GetLatestPackageId(ctx context.Context, packageId string, module string) (string, error)

func (*FakeSuiPTBClient) GetNormalizedModule

func (c *FakeSuiPTBClient) GetNormalizedModule(ctx context.Context, packageId string, module string) (models.GetNormalizedMoveModuleResponse, error)

func (*FakeSuiPTBClient) GetParentObjectID

func (c *FakeSuiPTBClient) GetParentObjectID(ctx context.Context, packageID string, moduleID string, pointerObjectName string) (string, error)

func (*FakeSuiPTBClient) GetReferenceGasPrice

func (c *FakeSuiPTBClient) GetReferenceGasPrice(ctx context.Context) (*big.Int, error)

func (*FakeSuiPTBClient) GetSUIBalance

func (c *FakeSuiPTBClient) GetSUIBalance(ctx context.Context, address string) (*big.Int, error)

func (*FakeSuiPTBClient) GetTokenPoolConfigByPackageAddress

func (c *FakeSuiPTBClient) GetTokenPoolConfigByPackageAddress(ctx context.Context, accountAddress string, tokenPoolAddress string, ccipPackageAddress string) (module_token_admin_registry.TokenConfig, error)

func (*FakeSuiPTBClient) GetTransactionStatus

func (c *FakeSuiPTBClient) GetTransactionStatus(ctx context.Context, digest string) (client.TransactionResult, error)

func (*FakeSuiPTBClient) GetValuesFromPackageOwnedObjectField

func (c *FakeSuiPTBClient) GetValuesFromPackageOwnedObjectField(ctx context.Context, packageID string, moduleID string, objectName string, fieldKeys []string) (map[string]string, error)

func (*FakeSuiPTBClient) HashTxBytes

func (c *FakeSuiPTBClient) HashTxBytes(txBytes []byte) []byte

func (*FakeSuiPTBClient) LoadModulePackageIds

func (c *FakeSuiPTBClient) LoadModulePackageIds(ctx context.Context, packageId string, module string) ([]string, error)

func (*FakeSuiPTBClient) MoveCall

func (*FakeSuiPTBClient) QueryCoinsByAddress

func (c *FakeSuiPTBClient) QueryCoinsByAddress(ctx context.Context, address string, coinType string) ([]models.CoinData, error)

func (*FakeSuiPTBClient) QueryEvents

func (*FakeSuiPTBClient) QueryTransactions

func (c *FakeSuiPTBClient) QueryTransactions(ctx context.Context, fromAddress string, cursor *string, limit *uint64) (models.SuiXQueryTransactionBlocksResponse, error)

func (*FakeSuiPTBClient) ReadFilterOwnedObjectIds

func (c *FakeSuiPTBClient) ReadFilterOwnedObjectIds(ctx context.Context, ownerAddress string, structType string, cursor string) ([]models.SuiObjectData, error)

func (*FakeSuiPTBClient) ReadFunction

func (c *FakeSuiPTBClient) ReadFunction(ctx context.Context, signerAddress string, packageId string, module string, function string, args []any, argTypes []string, typeArgs []string) ([]any, error)

func (*FakeSuiPTBClient) ReadObjectId

func (c *FakeSuiPTBClient) ReadObjectId(ctx context.Context, objectId string) (models.SuiObjectData, error)

func (*FakeSuiPTBClient) ReadOwnedObjects

func (c *FakeSuiPTBClient) ReadOwnedObjects(ctx context.Context, ownerAddress string, cursor *models.ObjectId) ([]models.SuiObjectResponse, error)

func (*FakeSuiPTBClient) SendTransaction

func (*FakeSuiPTBClient) SetCachedValue

func (c *FakeSuiPTBClient) SetCachedValue(key string, value any)

func (*FakeSuiPTBClient) SetCachedValues

func (c *FakeSuiPTBClient) SetCachedValues(keyValues map[string]any)

func (*FakeSuiPTBClient) SignAndSendTransaction

func (c *FakeSuiPTBClient) SignAndSendTransaction(ctx context.Context, txBytesRaw string, signerPublicKey []byte, executionRequestType client.TransactionRequestType) (client.SuiTransactionBlockResponse, error)

func (*FakeSuiPTBClient) SuiXGetReferenceGasPrice

func (c *FakeSuiPTBClient) SuiXGetReferenceGasPrice(ctx context.Context) (string, error)

func (*FakeSuiPTBClient) ToPTBArg

func (c *FakeSuiPTBClient) ToPTBArg(ctx context.Context, builder any, argValue any, isMutable bool) (any, error)

func (*FakeSuiPTBClient) WithRateLimit

func (c *FakeSuiPTBClient) WithRateLimit(ctx context.Context, methodName string, f func(ctx context.Context) error) error

WithRateLimit is provided to maintain compatibility with previous implementations

type GasPriceUpdate

type GasPriceUpdate struct {
	DestChainSelector uint64   // u64 in Move
	UsdPerUnitGas     *big.Int // u256 in Move becomes *big.Int in Go
}

GasPriceUpdate represents a gas price update from offramp.move Matches the Move struct: public struct GasPriceUpdate has store, drop, copy

func NewGasPriceUpdate

func NewGasPriceUpdate(destChainSelector uint64, usdPerUnitGas *big.Int) GasPriceUpdate

Helper function to create a GasPriceUpdate

type MerkleRoot

type MerkleRoot struct {
	SourceChainSelector uint64 // u64 in Move
	OnRampAddress       []byte // vector<u8> in Move
	MinSeqNr            uint64 // u64 in Move
	MaxSeqNr            uint64 // u64 in Move
	MerkleRoot          []byte // vector<u8> in Move (32 bytes)
}

MerkleRoot represents a merkle root structure from offramp.move Matches the Move struct: public struct MerkleRoot has store, drop, copy

func NewMerkleRoot

func NewMerkleRoot(sourceChainSelector uint64, onRampAddress []byte, minSeqNr, maxSeqNr uint64, merkleRoot []byte) MerkleRoot

Helper function to create a MerkleRoot with proper byte slice initialization

type MerkleTree

type MerkleTree [][32]byte

func GenerateMerkleTree

func GenerateMerkleTree(ops []Op, rootMetadata RootMetadata) (MerkleTree, error)

func NewMerkleTree

func NewMerkleTree(leaves [][32]byte) (MerkleTree, error)

func (MerkleTree) GetProof

func (mt MerkleTree) GetProof(index int) [][32]byte

func (MerkleTree) GetRoot

func (mt MerkleTree) GetRoot() [32]byte

MerkleTree methods

func (MerkleTree) VerifyProof

func (mt MerkleTree) VerifyProof(proof [][32]byte, leaf [32]byte) bool

type NodeEnvType

type NodeEnvType int

NodeEnvType represents the type of Sui node environment to run the localnet with

const (
	// Docker represents running a Sui node in a Docker container
	Docker NodeEnvType = iota
	// CLI represents running a Sui node via the Sui CLI
	CLI
)

type ObjectChange

type ObjectChange struct {
	Type            string   `json:"type"` // "published", "created", etc.
	Sender          string   `json:"sender,omitempty"`
	Owner           Owner    `json:"owner,omitempty"`
	ObjectType      string   `json:"objectType,omitempty"`
	ObjectID        string   `json:"objectId,omitempty"`
	Version         string   `json:"version,omitempty"`
	PreviousVersion string   `json:"previousVersion,omitempty"`
	Digest          string   `json:"digest,omitempty"`
	PackageID       string   `json:"packageId,omitempty"` // Only in type == "published"
	Modules         []string `json:"modules,omitempty"`   // Only in type == "published"
}

type Op

type Op struct {
	Role         uint8
	ChainID      *big.Int
	MultiSig     []byte
	Nonce        uint64
	To           []byte
	ModuleName   string
	FunctionName string
	Data         []byte
}

type Owner

type Owner struct {
	AddressOwner *string      `json:"AddressOwner,omitempty"`
	Shared       *SharedOwner `json:"Shared,omitempty"`
	Immutable    *string      `json:"Immutable,omitempty"`
}

type PriceUpdates

type PriceUpdates struct {
	TokenPriceUpdates []TokenPriceUpdate
	GasPriceUpdates   []GasPriceUpdate
}

PriceUpdates represents the price updates structure from offramp.move Matches the Move struct: public struct PriceUpdates has store, drop, copy

type RampMessageHeader

type RampMessageHeader struct {
	MessageId           []byte `json:"message_id"`
	SourceChainSelector uint64 `json:"source_chain_selector"`
	DestChainSelector   uint64 `json:"dest_chain_selector"`
	SequenceNumber      uint64 `json:"sequence_number"`
	Nonce               uint64 `json:"nonce"`
}

RampMessageHeader represents the message header structure from offramp.move Matches the Move struct: public struct RampMessageHeader has drop

func NewRampMessageHeader

func NewRampMessageHeader(
	messageId []byte,
	sourceChainSelector uint64,
	destChainSelector uint64,
	sequenceNumber uint64,
	nonce uint64,
) RampMessageHeader

Helper function to create a RampMessageHeader

type RootMetadata

type RootMetadata struct {
	Role                 uint8
	ChainID              *big.Int
	MultiSig             []byte
	PreOpCount           uint64
	PostOpCount          uint64
	OverridePreviousRoot bool
}

type SharedOwner

type SharedOwner struct {
	InitialSharedVersion int `json:"initial_shared_version"`
}

type StatefulFakeSuiPTBClient

type StatefulFakeSuiPTBClient struct {
	CoinsData                    []models.CoinData
	GasBudgetThreshold           uint64 // Minimum gas budget required for success
	CallCount                    int    // Track number of calls to GetTransactionStatus
	ForcedTransactionStatusError string // Force the transaction status to be this value
	CurrentGasBudget             uint64 // Track the current gas budget being tested
	// MockClient allows tests to inject custom ISuiAPI behavior when GetClient() is called.
	// If nil, GetClient() will return nil, which is fine for most tests that don't use it.
	// Tests that need specific ISuiAPI behavior should set this field explicitly.
	MockClient sui.ISuiAPI
}

StatefulFakeSuiPTBClient is a more sophisticated fake client that can change behavior based on gas budget and track call counts for testing gas bump scenarios

func (*StatefulFakeSuiPTBClient) BlockByDigest

func (*StatefulFakeSuiPTBClient) EstimateGas

func (c *StatefulFakeSuiPTBClient) EstimateGas(ctx context.Context, txBytes string) (uint64, error)

func (*StatefulFakeSuiPTBClient) FinishPTBAndSend

func (*StatefulFakeSuiPTBClient) GetBlockById

func (c *StatefulFakeSuiPTBClient) GetBlockById(ctx context.Context, checkpointId string) (models.CheckpointResponse, error)

func (*StatefulFakeSuiPTBClient) GetCCIPPackageID

func (c *StatefulFakeSuiPTBClient) GetCCIPPackageID(ctx context.Context, offRampPackageID string, signerAddress string) (string, error)

func (*StatefulFakeSuiPTBClient) GetCache

func (c *StatefulFakeSuiPTBClient) GetCache() *cache.Cache

func (*StatefulFakeSuiPTBClient) GetCachedValue

func (c *StatefulFakeSuiPTBClient) GetCachedValue(key string) (any, bool)

func (*StatefulFakeSuiPTBClient) GetCachedValues

func (c *StatefulFakeSuiPTBClient) GetCachedValues(keys []string) (map[string]any, bool)

func (*StatefulFakeSuiPTBClient) GetClient

func (c *StatefulFakeSuiPTBClient) GetClient() sui.ISuiAPI

func (*StatefulFakeSuiPTBClient) GetCoinsByAddress

func (c *StatefulFakeSuiPTBClient) GetCoinsByAddress(ctx context.Context, address string) ([]models.CoinData, error)

func (*StatefulFakeSuiPTBClient) GetLatestEpoch

func (c *StatefulFakeSuiPTBClient) GetLatestEpoch(ctx context.Context) (string, error)

func (*StatefulFakeSuiPTBClient) GetLatestPackageId

func (c *StatefulFakeSuiPTBClient) GetLatestPackageId(ctx context.Context, packageId string, module string) (string, error)

func (*StatefulFakeSuiPTBClient) GetNormalizedModule

func (c *StatefulFakeSuiPTBClient) GetNormalizedModule(ctx context.Context, packageId string, module string) (models.GetNormalizedMoveModuleResponse, error)

func (*StatefulFakeSuiPTBClient) GetParentObjectID

func (c *StatefulFakeSuiPTBClient) GetParentObjectID(ctx context.Context, packageID string, moduleID string, pointerObjectName string) (string, error)

func (*StatefulFakeSuiPTBClient) GetReferenceGasPrice

func (c *StatefulFakeSuiPTBClient) GetReferenceGasPrice(ctx context.Context) (*big.Int, error)

func (*StatefulFakeSuiPTBClient) GetSUIBalance

func (c *StatefulFakeSuiPTBClient) GetSUIBalance(ctx context.Context, address string) (*big.Int, error)

func (*StatefulFakeSuiPTBClient) GetTokenPoolConfigByPackageAddress

func (c *StatefulFakeSuiPTBClient) GetTokenPoolConfigByPackageAddress(ctx context.Context, accountAddress string, tokenPoolAddress string, ccipPackageAddress string) (module_token_admin_registry.TokenConfig, error)

func (*StatefulFakeSuiPTBClient) GetTransactionStatus

func (c *StatefulFakeSuiPTBClient) GetTransactionStatus(ctx context.Context, digest string) (client.TransactionResult, error)

func (*StatefulFakeSuiPTBClient) GetValuesFromPackageOwnedObjectField

func (c *StatefulFakeSuiPTBClient) GetValuesFromPackageOwnedObjectField(ctx context.Context, packageID string, moduleID string, objectName string, fieldKeys []string) (map[string]string, error)

func (*StatefulFakeSuiPTBClient) HashTxBytes

func (c *StatefulFakeSuiPTBClient) HashTxBytes(txBytes []byte) []byte

func (*StatefulFakeSuiPTBClient) LoadModulePackageIds

func (c *StatefulFakeSuiPTBClient) LoadModulePackageIds(ctx context.Context, packageId string, module string) ([]string, error)

func (*StatefulFakeSuiPTBClient) MoveCall

func (*StatefulFakeSuiPTBClient) QueryCoinsByAddress

func (c *StatefulFakeSuiPTBClient) QueryCoinsByAddress(ctx context.Context, address string, coinType string) ([]models.CoinData, error)

func (*StatefulFakeSuiPTBClient) QueryEvents

func (*StatefulFakeSuiPTBClient) QueryTransactions

func (c *StatefulFakeSuiPTBClient) QueryTransactions(ctx context.Context, fromAddress string, cursor *string, limit *uint64) (models.SuiXQueryTransactionBlocksResponse, error)

func (*StatefulFakeSuiPTBClient) ReadFilterOwnedObjectIds

func (c *StatefulFakeSuiPTBClient) ReadFilterOwnedObjectIds(ctx context.Context, ownerAddress string, structType string, cursor string) ([]models.SuiObjectData, error)

func (*StatefulFakeSuiPTBClient) ReadFunction

func (c *StatefulFakeSuiPTBClient) ReadFunction(ctx context.Context, signerAddress string, packageId string, module string, function string, args []any, argTypes []string, typeArgs []string) ([]any, error)

func (*StatefulFakeSuiPTBClient) ReadObjectId

func (c *StatefulFakeSuiPTBClient) ReadObjectId(ctx context.Context, objectId string) (models.SuiObjectData, error)

func (*StatefulFakeSuiPTBClient) ReadOwnedObjects

func (c *StatefulFakeSuiPTBClient) ReadOwnedObjects(ctx context.Context, ownerAddress string, cursor *models.ObjectId) ([]models.SuiObjectResponse, error)

func (*StatefulFakeSuiPTBClient) SendTransaction

func (*StatefulFakeSuiPTBClient) SetCachedValue

func (c *StatefulFakeSuiPTBClient) SetCachedValue(key string, value any)

func (*StatefulFakeSuiPTBClient) SetCachedValues

func (c *StatefulFakeSuiPTBClient) SetCachedValues(keyValues map[string]any)

func (*StatefulFakeSuiPTBClient) SignAndSendTransaction

func (c *StatefulFakeSuiPTBClient) SignAndSendTransaction(ctx context.Context, txBytesRaw string, signerPublicKey []byte, executionRequestType client.TransactionRequestType) (client.SuiTransactionBlockResponse, error)

func (*StatefulFakeSuiPTBClient) SuiXGetReferenceGasPrice

func (c *StatefulFakeSuiPTBClient) SuiXGetReferenceGasPrice(ctx context.Context) (string, error)

func (*StatefulFakeSuiPTBClient) ToPTBArg

func (c *StatefulFakeSuiPTBClient) ToPTBArg(ctx context.Context, builder any, argValue any, isMutable bool) (any, error)

func (*StatefulFakeSuiPTBClient) WithRateLimit

func (c *StatefulFakeSuiPTBClient) WithRateLimit(ctx context.Context, methodName string, f func(ctx context.Context) error) error

type TestKeystore

type TestKeystore struct {
	Keys map[string]ed25519.PrivateKey
	// contains filtered or unexported fields
}

TestKeystore is a simple keystore for testing

func NewTestKeystore

func NewTestKeystore(t *testing.T) *TestKeystore

NewTestKeystore creates a new test keystore

func SetupTestEnv

func SetupTestEnv(
	t *testing.T,
	ctx context.Context,
	lgr logger.Logger,
	gasLimit int64,
) (*client.PTBClient, *txm.SuiTxm, *txm.InMemoryStore, string, *TestKeystore, []byte, string, string)

func SetupTestSigner

func SetupTestSigner(
	t *testing.T,
	ctx context.Context,
	lgr logger.Logger,
	gasLimit int64,
) (*TestKeystore, string, []byte)

func (*TestKeystore) Accounts

func (tk *TestKeystore) Accounts(ctx context.Context) ([]string, error)

func (*TestKeystore) AddKey

func (tk *TestKeystore) AddKey(key ed25519.PrivateKey)

AddKey adds a private key to the keystore

func (*TestKeystore) Decrypt

func (u *TestKeystore) Decrypt(ctx context.Context, account string, encrypted []byte) (decrypted []byte, err error)

func (*TestKeystore) GetSuiSigner

func (tk *TestKeystore) GetSuiSigner(ctx context.Context, publicKey string) *signer.Signer

func (*TestKeystore) Sign

func (tk *TestKeystore) Sign(ctx context.Context, id string, hash []byte) ([]byte, error)

type TestState

type TestState struct {
	AccountAddress  string
	PublicKeyBytes  []byte
	SuiGateway      *client.PTBClient
	KeystoreGateway loop.Keystore
	TxManager       *txm.SuiTxm
	TxStore         *txm.InMemoryStore
	Contracts       []Contracts
	Cmd             exec.Cmd
}

type TimelockOperation

type TimelockOperation struct {
	Target       []byte
	ModuleName   string
	FunctionName string
	Data         []byte
}

type TokenPoolType

type TokenPoolType string

TokenPoolType represents the different types of token pools available

func (TokenPoolType) String

func (t TokenPoolType) String() string

String returns the string representation of TokenPoolType

type TokenPriceUpdate

type TokenPriceUpdate struct {
	SourceToken []byte   // address in Move becomes []byte for 32-byte Sui address
	UsdPerToken *big.Int // u256 in Move becomes *big.Int in Go
}

TokenPriceUpdate represents a token price update from offramp.move Matches the Move struct: public struct TokenPriceUpdate has store, drop, copy

func NewTokenPriceUpdate

func NewTokenPriceUpdate(sourceToken string, usdPerToken *big.Int) TokenPriceUpdate

Helper function to create a TokenPriceUpdate with proper address formatting

type TokenToolDetails

type TokenToolDetails struct {
	TokenPoolPackageId string
	TokenPoolType      TokenPoolType
}

type TxnMetaWithObjectChanges

type TxnMetaWithObjectChanges struct {
	ObjectChanges []ObjectChange `json:"objectChanges"`
}

func PublishContract

func PublishContract(t *testing.T, packageName string, contractPath string, accountAddress string, gasBudget *int) (string, TxnMetaWithObjectChanges, error)

PublishContract publishes a Move contract to the Sui network and extracts its package ID.

The function constructs and executes a "sui client publish" command using the provided contractPath and gasBudget (if specified). It cleans the command output to remove any unwanted header text, unmarshals the resulting JSON, and iterates over the "objectChanges" array to find an entry of type "published". Once found, it returns the associated packageId along with the full cleaned JSON output.

Parameters:

t            - A testing.T instance for error reporting.
packageName  - A string representing the contract name (package name in Move.toml).
contractPath - A string representing the filesystem path to the Move contract.
gasBudget    - A pointer to an int that specifies the gas budget for the publish transaction.
               If nil, a default value is used.

Returns:

packageId    - The package ID extracted from the JSON output, typically for a published contract.
output       - The cleaned JSON output from the publish command.
error        - An error if the publish operation fails or if a valid package ID is not found.

Jump to

Keyboard shortcuts

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