testutil

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2026 License: Apache-2.0, MIT Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CalibnetChainID          = 314159
	CalibnetDDOContract      = "0x889fD50196BE300D06dc4b8F0F17fdB0af587095"
	CalibnetPaymentsContract = "0x09a0fDc2723fAd1A7b8e3e00eE5DF73841df55a0"
	CalibnetUSDFC            = "0xb3042734b608a1B16e9e86B374A3f3e389B4cDf0"

	// CalibnetDDOProviderActorID is the FF calibnet miner t0178773.
	CalibnetDDOProviderActorID uint64 = 178773
)
View Source
const TestPrivateKeyHex = "" /* 160-byte string literal not displayed */
View Source
const TestWalletAddr = "f1fib3pv7jua2ockdugtz7viz3cyy6lkhh7rfx3sa"

Variables

View Source
var (
	FVMResolveAddress     = common.HexToAddress("0xfe00000000000000000000000000000000000001")
	FVMCallActorByAddress = common.HexToAddress("0xfe00000000000000000000000000000000000003")
	FVMCallActorByID      = common.HexToAddress("0xfe00000000000000000000000000000000000005")
)
View Source
var CalibnetRPC = envOr("SINGULARITY_TEST_CALIBNET_RPC", "https://static.187.115.235.167.clients.your-server.de/calibnet/rpc/v1")

CalibnetRPC defaults to the self-hosted forest gateway; glif rate-limited CI.

View Source
var OneEther = new(big.Int).Exp(big.NewInt(10), big.NewInt(18), nil)

OneEther is 1e18 wei, useful as a unit for test funding amounts.

View Source
var SupportedTestDialects = []string{"sqlite", "postgres"}
View Source
var TestCid = cid.NewCidV1(cid.Raw, util.Hash([]byte("test")))
View Source
var TestLotusAPI = envOr("SINGULARITY_TEST_LOTUS_API", "https://static.187.115.235.167.clients.your-server.de/rpc/v1")

TestLotusAPI defaults to the self-hosted forest gateway; glif rate-limited CI.

View Source
var TestLotusToken = os.Getenv("FOREST_JWT")

TestLotusToken is the bearer token for the forest gateway; empty in local dev and on fork PRs (see SkipIfNotExternalAPI).

Functions

func All added in v0.4.0

func All(t *testing.T, testFunc func(ctx context.Context, t *testing.T, db *gorm.DB))

func AnvilFunderKey added in v1.0.0

func AnvilFunderKey(t *testing.T) *ecdsa.PrivateKey

AnvilFunderKey returns the parsed private key for Anvil's first pre-funded account.

func AnvilImpersonate added in v1.0.0

func AnvilImpersonate(t *testing.T, rpcURL string, addr common.Address)

AnvilImpersonate enables Anvil's impersonation for the given address, allowing transactions to be sent from it without a private key.

func EscapePath added in v0.4.0

func EscapePath(p string) string

func FundEVMWallet added in v1.0.0

func FundEVMWallet(t *testing.T, rpcURL string, to common.Address, amount *big.Int) common.Hash

FundEVMWallet sends ETH from Anvil's pre-funded account 0 to the given address. amount is in wei. Anvil automines the tx immediately.

func GenerateFixedBytes added in v0.4.0

func GenerateFixedBytes(length int) []byte

func GenerateRandomBytes

func GenerateRandomBytes(n int) []byte

func GenerateTestKey added in v1.0.0

func GenerateTestKey(t *testing.T) (*ecdsa.PrivateKey, common.Address)

GenerateTestKey creates a fresh ECDSA key pair for testing and returns the private key and its corresponding EVM address.

func GenerateUniqueName added in v1.0.0

func GenerateUniqueName(prefix string) string

GenerateUniqueName creates a unique name for testing by combining a prefix with a UUID suffix

func GetFileTimestamp

func GetFileTimestamp(t *testing.T, path string) int64

func One added in v0.4.0

func One(t *testing.T, testFunc func(ctx context.Context, t *testing.T, db *gorm.DB))

func OneWithoutReset added in v0.4.0

func OneWithoutReset(t *testing.T, testFunc func(ctx context.Context, t *testing.T, db *gorm.DB))

func ReadContractOwner added in v1.0.0

func ReadContractOwner(t *testing.T, rpcURL string, contractAddr common.Address) common.Address

ReadContractOwner reads the Diamond contract owner by calling the owner() function.

func RegisterActorID added in v1.0.0

func RegisterActorID(t *testing.T, rpcURL string, evmAddr common.Address, actorID uint64)

RegisterActorID adds an EVM address -> actor ID mapping to the mocked RESOLVE_ADDRESS precompile using the Filecoin delegated-address encoding.

func SendImpersonatedTx added in v1.0.0

func SendImpersonatedTx(t *testing.T, rpcURL string, from, to common.Address, data []byte) common.Hash

SendImpersonatedTx sends a transaction from an impersonated account via Anvil's eth_sendTransaction and waits for the receipt. The caller must have already called AnvilImpersonate for the from address.

func SetupFVMPrecompiles added in v1.0.0

func SetupFVMPrecompiles(t *testing.T, rpcURL string)

SetupFVMPrecompiles deploys narrow Filecoin precompile mocks on an Anvil fork.

These mocks are useful for tests that would otherwise revert on empty Filecoin precompile addresses. They cover address resolution plus minimal actor-call happy paths, but they do not emulate DataCap / VerifReg flows end-to-end.

func SkipIfNotExternalAPI added in v1.0.0

func SkipIfNotExternalAPI(t *testing.T)

SkipIfNotExternalAPI skips the test if external API access isn't configured. Two conditions must hold: SINGULARITY_TEST_EXTERNAL_API opts in, and either FOREST_JWT is set or one of the endpoint overrides (SINGULARITY_TEST_LOTUS_API / SINGULARITY_TEST_CALIBNET_RPC) points at something that doesn't need the gateway's bearer auth. Fork PRs and local devs without a token skip cleanly instead of hitting a 401.

func TransferERC20 added in v1.0.0

func TransferERC20(t *testing.T, rpcURL string, tokenAddr, recipient common.Address, amount *big.Int)

TransferERC20 sends ERC20 tokens from Anvil's pre-funded account 0 to a recipient. This works because account 0 already has a real private key (the well-known Anvil test key).

Types

type AnvilInstance added in v1.0.0

type AnvilInstance struct {
	RPCURL string
	// contains filtered or unexported fields
}

func StartAnvil added in v1.0.0

func StartAnvil(t *testing.T, upstreamRPC string) *AnvilInstance

StartAnvil forks the given upstream RPC on a random free port. Returns when the fork is ready to accept connections.

func (*AnvilInstance) Close added in v1.0.0

func (a *AnvilInstance) Close()

func (*AnvilInstance) MineBlock added in v1.0.0

func (a *AnvilInstance) MineBlock(t *testing.T)

MineBlock forces anvil to produce a block. In automine mode (default), blocks are mined on tx submission, but consumers that only read (e.g. Shovel) need an explicit nudge to see chain progress.

type CloserFunc added in v0.4.0

type CloserFunc func() error

func (CloserFunc) Close added in v0.4.0

func (f CloserFunc) Close() error

Jump to

Keyboard shortcuts

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