@satlayer/testcontainers
v2.4.0
Published
A package providing testcontainer testing environments for both Ethereum (EVM) and CosmWasm blockchain applications. This package also includes utilities for bootstrapping SatLayer core contracts multiple control planes (EVM and CosmWasm) for testing purp
Downloads
718
Readme
@satlayer/testcontainers
A package providing testcontainer testing environments for both Ethereum (EVM) and CosmWasm blockchain applications. This package also includes utilities for bootstrapping SatLayer core contracts multiple control planes (EVM and CosmWasm) for testing purposes.
Overview
This package simplifies blockchain testing by providing testcontainer abstractions for:
- Ethereum testing via Anvil nodes (forked mainnet or testnet)
- CosmWasm testing via wasmd containers
- Bootstrapping SatLayer core contracts for both EVM and CosmWasm environments
It allows developers to easily set up isolated blockchain environments, deploy contracts, and test complex interactions without affecting external networks.
Installation
pnpm install -D @satlayer/testcontainersFeatures
Ethereum (EVM) Node
AnvilContainer provides a lightweight Ethereum node for testing purposes. It supports:
- Create isolated Anvil containers for Ethereum testing
- Deploy and interact with EVM contracts
- Create test accounts and fund them
- Mine blocks
- Support for different chains (Ethereum, Optimism)
- Utilities for contract deployment and interaction
CosmWasm Testing
CosmWasmContainer provides a testing environment for CosmWasm contracts. It supports:
- Create isolated wasmd containers for CosmWasm testing
- Deploy and interact with CosmWasm contracts
- Initialize different types of contracts
- Execute contract methods and query contract state
SatLayer Core Contracts Bootstrapping
The package includes utilities to bootstrap SatLayer core contracts for both EVM and CosmWasm environments:
EVMContractsfor EVM environments- Initialize
SLAY*core contracts - Initialize ERC20 tokens and
SLAYVaults
- Initialize
CosmWasmContractsfor CosmWasm environments- Initialize SatLayer core contracts (e.g.
bvs-registry,bvs-router, etc.) - Initialize CW20 tokens
- Initialize
bvs-vaults
- Initialize SatLayer core contracts (e.g.
Usage Examples
Ethereum Testing
Look at anvil-container.test.ts for detailed examples of how to use the AnvilContainer class.
CosmWasm Testing
Look at cosmwasm-container.test.ts for detailed examples of how to use the CosmWasmContainer class.
Bootstrapping SatLayer Core Contracts
Look at evm-contracts.test.ts and cosmwasm-contracts.test.ts for detailed examples of how to use the EVMContracts and CosmWasmContracts classes to bootstrap SatLayer core contracts in EVM and CosmWasm environments respectively.
API Reference
Ethereum (EVM)
AnvilContainer: Creates and manages Anvil containersStartedAnvilContainer: Provides methods for interacting with a running containerEVMContracts: Manages contract deployment and interaction
CosmWasm
CosmWasmContainer: Creates and manages wasmd containersStartedCosmWasmContainer: Provides methods for interacting with a running containerCosmWasmContracts: Manages contract deployment and interaction
EVMContracts
initERC20
Initialize a mocked ERC20 contracts that supports:
- Customizable decimals
- Minting and burning tokens by anyone
contract MockERC20 is ERC20 {
uint8 private _decimals;
/// @dev adds the decimals to be customizable
constructor(string memory name_, string memory symbol_, uint8 decimals_) ERC20(name_, symbol_) {
_decimals = decimals_;
}
function decimals() public view override returns (uint8) {
return _decimals;
}
function mint(address to, uint256 amount) external {
_mint(to, amount);
}
function burn(address from, uint256 amount) external {
_burn(from, amount);
}
}