testutils

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: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TSSAddressEVMMainnet the EVM TSS address for test purposes
	// Note: public key is zetapub1addwnpepqtadxdyt037h86z60nl98t6zk56mw5zpnm79tsmvspln3hgt5phdc79kvfc
	TSSAddressEVMMainnet = "0x70e967acFcC17c3941E87562161406d41676FD83"

	// TSSAddressBTCMainnet the BTC TSS address for test purposes
	TSSAddressBTCMainnet = "bc1qm24wp577nk8aacckv8np465z3dvmu7ry45el6y"

	// TSSAddressEVMAthens3 the EVM TSS address for test purposes
	// Note: public key is zetapub1addwnpepq28c57cvcs0a2htsem5zxr6qnlvq9mzhmm76z3jncsnzz32rclangr2g35p
	TSSAddressEVMAthens3 = "0x8531a5aB847ff5B22D855633C25ED1DA3255247e"

	// TSSAddressBTCAthens3 the BTC TSS address for test purposes
	TSSAddressBTCAthens3 = "tb1qy9pqmk2pd9sv63g27jt8r657wy0d9ueeh0nqur"

	OtherAddress1 = "0x21248Decd0B7EcB0F30186297766b8AB6496265b"
	OtherAddress2 = "0x33A351C90aF486AebC35042Bb0544123cAed26AB"
	OtherAddress3 = "0x86B77E4fBd07CFdCc486cAe4F2787fB5C5a62cd3"

	// evm event names for test data naming
	EventZetaSent      = "ZetaSent"
	EventZetaReceived  = "ZetaReceived"
	EventZetaReverted  = "ZetaReverted"
	EventERC20Deposit  = "Deposited"
	EventERC20Withdraw = "Withdrawn"

	// SQLiteMemory is a SQLite in-memory database connection string.
	SQLiteMemory = "file::memory:?cache=shared"
)
View Source
const (
	APIURLBlocks          = "https://mempool.space/api/v1/blocks"
	APIURLBlockTxs        = "https://mempool.space/api/block/%s/txs"
	APIURLBlocksTestnet   = "https://mempool.space/testnet/api/v1/blocks"
	APIURLBlockTxsTestnet = "https://mempool.space/testnet/api/block/%s/txs"
)
View Source
const (
	TestDataPathEVM          = "testdata/evm"
	TestDataPathBTC          = "testdata/btc"
	TestDataPathCctx         = "testdata/cctx"
	RestrictedEVMAddressTest = "0x8a81Ba8eCF2c418CAe624be726F505332DF119C6"
	RestrictedBtcAddressTest = "bcrt1qzp4gt6fc7zkds09kfzaf9ln9c5rvrzxmy6qmpp"
)

Variables

View Source
var ConnectorAddresses = map[int64]ethcommon.Address{

	1: ethcommon.HexToAddress("0x000007Cf399229b2f5A4D043F20E90C9C98B7C6a"),

	56: ethcommon.HexToAddress("0x000063A6e758D9e2f438d430108377564cf4077D"),

	5:        ethcommon.HexToAddress("0x00005E3125aBA53C5652f9F0CE1a4Cf91D8B15eA"),
	97:       ethcommon.HexToAddress("0x0000ecb8cdd25a18F12DAA23f6422e07fBf8B9E1"),
	11155111: ethcommon.HexToAddress("0x3963341dad121c9CD33046089395D66eBF20Fb03"),

	1337: ethcommon.HexToAddress("0xD28D6A0b8189305551a0A8bd247a6ECa9CE781Ca"),
}

ConnectorAddresses contains constants ERC20 connector addresses for testing

View Source
var CustodyAddresses = map[int64]ethcommon.Address{

	1: ethcommon.HexToAddress("0x0000030Ec64DF25301d8414eE5a29588C4B0dE10"),

	56: ethcommon.HexToAddress("0x00000fF8fA992424957F97688015814e707A0115"),

	5:        ethcommon.HexToAddress("0x000047f11C6E42293F433C82473532E869Ce4Ec5"),
	97:       ethcommon.HexToAddress("0x0000a7Db254145767262C6A81a7eE1650684258e"),
	11155111: ethcommon.HexToAddress("0x84725b70a239d3Faa7C6EF0C6C8E8b6c8e28338b"),
}

CustodyAddresses contains constants ERC20 custody addresses for testing

Functions

func ComplianceConfigTest

func ComplianceConfigTest() config.ComplianceConfig

ComplianceConfigTest returns a test compliance config TODO(revamp): move to sample package

func FileNameBTCInbound

func FileNameBTCInbound(chainID int64, inboundHash string, donation bool) string

FileNameBTCInbound returns unified archive file name for inbound tx

func FileNameBTCMsgTx

func FileNameBTCMsgTx(chainID int64, txHash string) string

FileNameBTCMsgTx returns unified archive file name for btc MsgTx

func FileNameBTCOutbound

func FileNameBTCOutbound(chainID int64, nonce uint64) string

FileNameBTCOutbound returns unified archive file name for outbound tx

func FileNameBTCTxByType

func FileNameBTCTxByType(chainID int64, txType string, txHash string) string

FileNameBTCTxByType returns unified archive file name for tx by type txType: "P2TR", "P2WPKH", "P2WSH", "P2PKH", "P2SH

func FileNameCctxByInbound

func FileNameCctxByInbound(chainID int64, inboundHash string, coinType coin.CoinType) string

FileNameCctxByInbound returns unified archive cctx file name by inbound

func FileNameCctxByNonce

func FileNameCctxByNonce(chainID int64, nonce uint64) string

FileNameCctxByNonce returns unified archive cctx file name by nonce

func FileNameEVMBlock

func FileNameEVMBlock(chainID int64, blockNumber uint64, trimmed bool) string

FileNameEVMBlock returns unified archive file name for block

func FileNameEVMInbound

func FileNameEVMInbound(chainID int64, inboundHash string, coinType coin.CoinType, donation bool) string

FileNameEVMInbound returns unified archive file name for inbound tx

func FileNameEVMInboundReceipt

func FileNameEVMInboundReceipt(chainID int64, inboundHash string, coinType coin.CoinType, donation bool) string

FileNameEVMInboundReceipt returns unified archive file name for inbound tx receipt

func FileNameEVMOutbound

func FileNameEVMOutbound(chainID int64, txHash string, coinType coin.CoinType) string

FileNameEVMOutbound returns unified archive file name for outbound tx

func FileNameEVMOutboundReceipt

func FileNameEVMOutboundReceipt(chainID int64, txHash string, coinType coin.CoinType, eventName string) string

FileNameEVMOutboundReceipt returns unified archive file name for outbound tx receipt

func Get

func Get(ctx context.Context, path string, v interface{}) error

Get makes a GET request to the given path and decodes the response

func LoadBTCInboundRawResult

func LoadBTCInboundRawResult(
	t *testing.T,
	dir string,
	chainID int64,
	txHash string,
	donation bool,
) *btcjson.TxRawResult

LoadBTCInboundRawResult loads archived Bitcoin inbound raw result from file

func LoadBTCTxRawResult

func LoadBTCTxRawResult(t *testing.T, dir string, chainID int64, txType string, txHash string) *btcjson.TxRawResult

LoadBTCTxRawResult loads archived Bitcoin tx raw result from file

func LoadBTCTxRawResultNCctx

func LoadBTCTxRawResultNCctx(
	t *testing.T,
	dir string,
	chainID int64,
	nonce uint64,
) (*btcjson.TxRawResult, *crosschaintypes.CrossChainTx)

LoadBTCTxRawResultNCctx loads archived Bitcoin outbound raw result and corresponding cctx

func LoadCctxByInbound

func LoadCctxByInbound(
	t *testing.T,
	chainID int64,
	coinType coin.CoinType,
	inboundHash string,
) *crosschaintypes.CrossChainTx

LoadCctxByInbound loads archived cctx by inbound

func LoadCctxByNonce

func LoadCctxByNonce(
	t *testing.T,
	chainID int64,
	nonce uint64,
) *crosschaintypes.CrossChainTx

LoadCctxByNonce loads archived cctx by nonce

func LoadEVMBlock

func LoadEVMBlock(t *testing.T, dir string, chainID int64, blockNumber uint64, trimmed bool) *ethrpc.Block

LoadEVMBlock loads archived evm block from file

func LoadEVMCctxNOutboundNReceipt

func LoadEVMCctxNOutboundNReceipt(
	t *testing.T,
	dir string,
	chainID int64,
	nonce uint64,
	eventName string) (*crosschaintypes.CrossChainTx, *ethtypes.Transaction, *ethtypes.Receipt)

LoadEVMCctxNOutboundNReceipt loads archived cctx, outbound and receipt from file

func LoadEVMInbound

func LoadEVMInbound(
	t *testing.T,
	dir string,
	chainID int64,
	inboundHash string,
	coinType coin.CoinType) *ethrpc.Transaction

LoadEVMInbound loads archived inbound from file

func LoadEVMInboundDonation

func LoadEVMInboundDonation(
	t *testing.T,
	dir string,
	chainID int64,
	inboundHash string,
	coinType coin.CoinType) *ethrpc.Transaction

LoadEVMInboundDonation loads archived donation inbound from file

func LoadEVMInboundNReceipt

func LoadEVMInboundNReceipt(
	t *testing.T,
	dir string,
	chainID int64,
	inboundHash string,
	coinType coin.CoinType) (*ethrpc.Transaction, *ethtypes.Receipt)

LoadEVMInboundNReceipt loads archived inbound and receipt from file

func LoadEVMInboundNReceiptDonation

func LoadEVMInboundNReceiptDonation(
	t *testing.T,
	dir string,
	chainID int64,
	inboundHash string,
	coinType coin.CoinType) (*ethrpc.Transaction, *ethtypes.Receipt)

LoadEVMInboundNReceiptDonation loads archived donation inbound and receipt from file

func LoadEVMInboundNReceiptNCctx

func LoadEVMInboundNReceiptNCctx(
	t *testing.T,
	dir string,
	chainID int64,
	inboundHash string,
	coinType coin.CoinType) (*ethrpc.Transaction, *ethtypes.Receipt, *crosschaintypes.CrossChainTx)

LoadEVMInboundNReceiptNCctx loads archived inbound, receipt and corresponding cctx from file

func LoadEVMInboundReceipt

func LoadEVMInboundReceipt(
	t *testing.T,
	dir string,
	chainID int64,
	inboundHash string,
	coinType coin.CoinType) *ethtypes.Receipt

LoadEVMInboundReceipt loads archived inbound receipt from file

func LoadEVMInboundReceiptDonation

func LoadEVMInboundReceiptDonation(
	t *testing.T,
	dir string,
	chainID int64,
	inboundHash string,
	coinType coin.CoinType) *ethtypes.Receipt

LoadEVMInboundReceiptDonation loads archived donation inbound receipt from file

func LoadEVMOutbound

func LoadEVMOutbound(
	t *testing.T,
	dir string,
	chainID int64,
	txHash string,
	coinType coin.CoinType) *ethtypes.Transaction

LoadEVMOutbound loads archived evm outbound from file

func LoadEVMOutboundNReceipt

func LoadEVMOutboundNReceipt(
	t *testing.T,
	dir string,
	chainID int64,
	txHash string,
	coinType coin.CoinType) (*ethtypes.Transaction, *ethtypes.Receipt)

LoadEVMOutboundNReceipt loads archived evm outbound and receipt from file

func LoadEVMOutboundReceipt

func LoadEVMOutboundReceipt(
	t *testing.T,
	dir string,
	chainID int64,
	txHash string,
	coinType coin.CoinType,
	eventName string) *ethtypes.Receipt

LoadEVMOutboundReceipt loads archived evm outbound receipt from file

func LoadObjectFromJSONFile

func LoadObjectFromJSONFile(t *testing.T, obj interface{}, filename string)

LoadObjectFromJSONFile loads an object from a file in JSON format

func ParseReceiptERC20Deposited

func ParseReceiptERC20Deposited(
	receipt *ethtypes.Receipt,
	custody *erc20custody.ERC20Custody,
) *erc20custody.ERC20CustodyDeposited

ParseReceiptERC20Deposited parses an Deposited event from a receipt

func ParseReceiptZetaSent

func ParseReceiptZetaSent(
	receipt *ethtypes.Receipt,
	connector *zetaconnector.ZetaConnectorNonEth,
) *zetaconnector.ZetaConnectorNonEthZetaSent

ParseReceiptZetaSent parses a ZetaSent event from a receipt

func SaveBTCBlockTrimTx

func SaveBTCBlockTrimTx(blockVb *btcjson.GetBlockVerboseTxResult, filename string) error

SaveBTCBlockTrimTx trims tx data from a block and saves it to a file NOTE: this function is not used in the tests but used when creating test data

func SaveEVMBlockTrimTxInput

func SaveEVMBlockTrimTxInput(block *ethrpc.Block, filename string) error

SaveEVMBlockTrimTxInput trims tx input data from a block and saves it to a file NOTE: this function is not used in the tests but used when creating test data

func SaveObjectToJSONFile

func SaveObjectToJSONFile(obj interface{}, filename string) error

SaveObjectToJSONFile saves an object to a file in JSON format NOTE: this function is not used in the tests but used when creating test data

Types

type BlockExtra

type BlockExtra struct {
	TotalFees int       `json:"totalFees"`
	MedianFee float64   `json:"medianFee"`
	FeeRange  []float64 `json:"feeRange"`
	Reward    int       `json:"reward"`
	Pool      struct {
		ID   int    `json:"id"`
		Name string `json:"name"`
		Slug string `json:"slug"`
	} `json:"pool"`
	AvgFee                 int     `json:"avgFee"`
	AvgFeeRate             int     `json:"avgFeeRate"`
	CoinbaseRaw            string  `json:"coinbaseRaw"`
	CoinbaseAddress        string  `json:"coinbaseAddress"`
	CoinbaseSignature      string  `json:"coinbaseSignature"`
	CoinbaseSignatureASCII string  `json:"coinbaseSignatureAscii"`
	AvgTxSize              float64 `json:"avgTxSize"`
	TotalInputs            int     `json:"totalInputs"`
	TotalOutputs           int     `json:"totalOutputs"`
	TotalOutputAmt         int     `json:"totalOutputAmt"`
	MedianFeeAmt           int     `json:"medianFeeAmt"`
	FeePercentiles         []int   `json:"feePercentiles"`
	SegwitTotalTxs         int     `json:"segwitTotalTxs"`
	SegwitTotalSize        int     `json:"segwitTotalSize"`
	SegwitTotalWeight      int     `json:"segwitTotalWeight"`
	Header                 string  `json:"header"`
	UTXOSetChange          int     `json:"utxoSetChange"`
	UTXOSetSize            int     `json:"utxoSetSize"`
	TotalInputAmt          int     `json:"totalInputAmt"`
	VirtualSize            float64 `json:"virtualSize"`
	Orphans                []struct {
		Height int    `json:"height"`
		Hash   string `json:"hash"`
		Status string `json:"status"`
	} `json:"orphans"`
	MatchRate      float64 `json:"matchRate"`
	EXpectedFees   big.Int `json:"expectedFees"`
	ExpectedWeight int     `json:"expectedWeight"`
}

BlockExtra represents extra information about a block

type MempoolBlock

type MempoolBlock struct {
	ID                string     `json:"id"`
	Height            int        `json:"height"`
	Version           int        `json:"version"`
	Time              int        `json:"timestamp"`
	Bits              int        `json:"bits"`
	Nonce             int        `json:"nonce"`
	Difficulty        float64    `json:"difficulty"`
	MerkleRoot        string     `json:"merkle_root"`
	TxCount           int        `json:"tx_count"`
	Size              int        `json:"size"`
	Weight            int        `json:"weight"`
	PreviousBlockHash string     `json:"previousblockhash"`
	MedianTime        int        `json:"mediantime"`
	Extras            BlockExtra `json:"extras"`
}

MempoolBlock represents a block in the mempool

func GetBlocks

func GetBlocks(ctx context.Context, n int, testnet bool) ([]MempoolBlock, error)

GetBlocks returns return 15 mempool.space blocks [n-14, n] per request

type MempoolTx

type MempoolTx struct {
	TxID     string `json:"txid"`
	Version  int    `json:"version"`
	LockTime int    `json:"locktime"`
	Vin      []Vin  `json:"vin"`
	Vout     []Vout `json:"vout"`
	Size     int    `json:"size"`
	Weight   int    `json:"weight"`
	Fee      int    `json:"fee"`
}

MempoolTx represents a transaction in the mempool

func GetBlockTxs

func GetBlockTxs(ctx context.Context, blockHash string, testnet bool) ([]MempoolTx, error)

GetBlockTxs a list of transactions in the block (up to 25 transactions beginning at index 0)

type Vin

type Vin struct {
	TxID    string `json:"txid"`
	Vout    uint32 `json:"vout"`
	Prevout struct {
		Scriptpubkey        string `json:"scriptpubkey"`
		ScriptpubkeyAsm     string `json:"scriptpubkey_asm"`
		ScriptpubkeyType    string `json:"scriptpubkey_type"`
		ScriptpubkeyAddress string `json:"scriptpubkey_address"`
		Value               int64  `json:"value"`
	} `json:"prevout"`
	Scriptsig  string `json:"scriptsig"`
	IsCoinbase bool   `json:"is_coinbase"`
	Sequence   uint32 `json:"sequence"`
}

Vin represents a Bitcoin transaction input

type Vout

type Vout struct {
	Scriptpubkey     string `json:"scriptpubkey"`
	ScriptpubkeyAsm  string `json:"scriptpubkey_asm"`
	ScriptpubkeyType string `json:"scriptpubkey_type"`
	Value            int64  `json:"value"`
}

Vout represents a Bitcoin transaction output

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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