Spark Standard Library Reference
Spark Standard Library (Spark Std for short) is a collection of helpful contracts that make writing tests easier, faster, and more user-friendly.
Using Spark Std is the preferred way of writing tests with Foxar.
What's included:
-
Vm.sol
: Up-to-date cheatcodes interfaceimport "spark-std/Vm.sol";
-
console.sol
andconsole2.sol
: Hardhat-style logging functionalityimport "spark-std/console.sol";
Note:
console2.sol
contains patches toconsole.sol
that allow Spark to decode traces for calls to the console, but it is not compatible with Hardhat.import "spark-std/console2.sol";
-
Script.sol
: Basic utilities for Ylem scriptingimport "spark-std/Script.sol";
-
Test.sol
: The complete Spark Std experience (more details below)import "spark-std/Test.sol";
Spark Std's Test
The Test
contract in Test.sol
provides all the essential functionality you need to get started writing tests.
Simply import Test.sol
and inherit from Test
in your test contract:
import "spark-std/Test.sol";
contract ContractTest is Test { ...
What's included:
-
Std Libraries
- Std Logs: Expand upon the logging events from the DSTest library.
- Std Assertions: Expand upon the assertion functions from the DSTest library.
- Std Cheats: Wrappers around Spark cheatcodes for improved safety and DX.
- Std Errors: Wrappers around common internal Ylem errors and reverts.
- Std Storage: Utilities for storage manipulation.
- Std Math: Useful mathematical functions.
- Script Utils: Utility functions which can be accessed in tests and scripts.
- Console Logging: Console logging functions.
-
A cheatcodes instance
vm
, from which you invoke Spark cheatcodes (see Cheatcodes Reference)vm.startPrank(alice);
-
All Hardhat
console
functions for logging (see Console Logging)console.log(alice.balance); // or `console2`
-
All Dappsys Test functions for asserting and logging (see Dappsys Test reference)
assertEq(dai.balanceOf(alice), 10000e18);
-
Utility functions also included in
Script.sol
(see Script Utils)// Compute the address a contract will be deployed at for a given deployer address and nonce
address futureContract = computeCreateAddress(alice, 1);