utils

package
v0.0.0-...-2da98db Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EmergencyPolicyName   = "emergency"
	AdminPolicyName       = "admin"
	OperationalPolicyName = "operational"

	DefaultCctxTimeout = 4 * time.Minute
)
View Source
const (
	DefaultReceiptTimeout = 30 * time.Second
)

Variables

This section is empty.

Functions

func CheckNonce

func CheckNonce(
	ctx context.Context,
	client *ethclient.Client,
	addr ethcommon.Address,
	expectedNonce uint64,
) error

func IsTerminalStatus

func IsTerminalStatus(status crosschaintypes.CctxStatus) bool

func MustWaitForTxReceipt

func MustWaitForTxReceipt(
	ctx context.Context,
	client *ethclient.Client,
	tx *ethtypes.Transaction,
	logger infoLogger,
	timeout time.Duration,
) *ethtypes.Receipt

MustWaitForTxReceipt waits until a broadcasted tx to be mined and return its receipt

func RequireCCTXStatus

func RequireCCTXStatus(
	t require.TestingT,
	cctx *crosschaintypes.CrossChainTx,
	expected crosschaintypes.CctxStatus,
	msgAndArgs ...any,
)

RequireCCTXStatus checks if the cctx status is equal to the expected status

func RequireTxSuccessful

func RequireTxSuccessful(t require.TestingT, receipt *ethtypes.Receipt, msgAndArgs ...any)

RequireTxSuccessful checks if the receipt status is successful. Currently, it accepts eth receipt, but we can make this more generic by using type assertion.

func RequiredTxFailed

func RequiredTxFailed(t require.TestingT, receipt *ethtypes.Receipt, msgAndArgs ...any)

RequiredTxFailed checks if the receipt status is failed. Currently, it accepts eth receipt, but we can make this more generic by using type assertion.

func ScriptPKToAddress

func ScriptPKToAddress(scriptPKHex string, params *chaincfg.Params) string

ScriptPKToAddress is a hex string for P2WPKH script

func TestingFromContext

func TestingFromContext(ctx context.Context) require.TestingT

TestingFromContext extracts require.TestingT from the context or panics.

func TraceTx

func TraceTx(ctx context.Context, tx *ethtypes.Transaction, rpcURL string) (string, error)

TraceTx traces the tx and returns the trace result

func WaitCCTXMinedByIndex

func WaitCCTXMinedByIndex(
	ctx context.Context,
	cctxIndex string,
	client crosschaintypes.QueryClient,
	logger infoLogger,
	timeout time.Duration,
) *crosschaintypes.CrossChainTx

WaitCCTXMinedByIndex waits until cctx is mined; returns the cctxIndex

func WaitCctxByInboundHash

func WaitCctxByInboundHash(
	ctx context.Context,
	t require.TestingT,
	hash string,
	c CCTXClient,
	opts ...WaitOpts,
) []crosschaintypes.CrossChainTx

WaitCctxByInboundHash waits until cctx appears by inbound hash.

func WaitCctxMinedByInboundHash

func WaitCctxMinedByInboundHash(
	ctx context.Context,
	inboundHash string,
	client crosschaintypes.QueryClient,
	logger infoLogger,
	timeout time.Duration,
) *crosschaintypes.CrossChainTx

WaitCctxMinedByInboundHash waits until cctx is mined; returns the cctxIndex (the last one)

func WaitCctxsMinedByInboundHash

func WaitCctxsMinedByInboundHash(
	ctx context.Context,
	inboundHash string,
	client crosschaintypes.QueryClient,
	cctxsCount int,
	logger infoLogger,
	timeout time.Duration,
) []*crosschaintypes.CrossChainTx

WaitCctxsMinedByInboundHash waits until cctx is mined; returns the cctxIndex (the last one)

func WaitForBlockHeight

func WaitForBlockHeight(
	ctx context.Context,
	desiredHeight int64,
	rpcURL string,
	logger infoLogger,
) error

WaitForBlockHeight waits until the block height reaches the given height

func WithTesting

func WithTesting(ctx context.Context, t require.TestingT) context.Context

WithTesting allows to store a testing.T instance in the context

Types

type CCTXClient

type CCTXClient = crosschaintypes.QueryClient

type NoopLogger

type NoopLogger struct{}

func (NoopLogger) Info

func (nl NoopLogger) Info(_ string, _ ...interface{})

type WaitOpts

type WaitOpts func(c *waitConfig)

func MatchStatus

func MatchStatus(s crosschaintypes.CctxStatus) WaitOpts

MatchStatus waits for a specific CCTX status.

func Matches

func Matches(fn func(tx crosschaintypes.CrossChainTx) bool) WaitOpts

Matches adds a filter to WaitCctxByInboundHash that checks cctxs match provided callback. ALL cctxs should match this filter.

Jump to

Keyboard shortcuts

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