Skip to main content

Testing

All SDK functionality is covered by a comprehensive suite of unit and integration tests. To run these tests, you will need a development-mode Lattice, as some tests require loading a known seed.

info

Many tests require a development Lattice, which GridPlus does not distribute publicly. Unit tests can be run without a device, but integration and end-to-end tests require a connected Lattice.

Setting Up the Local Test Environmentโ€‹

The test suite now uses Foundry and Anvil for local EVM testing, which is required for features like EIP-7702.

1. Initial Setupโ€‹

First, ensure you have a .env file in the project root with your DEVICE_ID. You can copy from .env.example.

Then, run the setup script. This will install Foundry, all dependencies, and start a local Anvil node:

# This needs to be run once before starting a testing session.
# It will keep running and output Anvil logs to your terminal.
npm run setup:anvil

2. Pairing Your Deviceโ€‹

If this is your first time running tests, you must pair the SDK with your Lattice:

# Option 1: Use the dedicated pairing script
npm run pair-device

# Option 2: Run the test suite (will prompt for pairing if needed)
npm run test

Once paired, the connection info is saved in client.temp, and you won't need to pair again unless you delete this file.

3. Running Testsโ€‹

With the setup script running in one terminal, you can run tests in another terminal:

# Run all tests
npm run test

# Run only unit tests (no device required)
npm run test-unit

# Run specific test suites
npm run e2e-eth # Ethereum message signing
npm run e2e-eip7702 # EIP-7702 authorization signing
npm run e2e-sign # All signing tests

4. Cleanupโ€‹

When finished testing, stop the setup script (Ctrl+C) and run cleanup:

npm run cleanup:anvil

Environment Variablesโ€‹

The following environment variables can be configured in your .env file:

VariableDescriptionDefault
DEVICE_IDYour Lattice device ID (6 characters)Required
PASSWORDDevice password for pairing"password"
APP_NAMEName shown on device during pairing"SDK Test"
ENC_PWDevice-level password for encrypted exportsNone
ETHERSCAN_KEYAPI key for ABI fetching testsNone
baseUrlMessage routing URL"https://signing.gridpl.us"

Setting up the .env fileโ€‹

Alternatively, you may input env options into a .env file to make it easier to run scripts. To create your .env file, follow these steps:

  1. Copy the .env.template file.
  2. Rename the .env.template file to .env.
  3. Update the desired params in that file, probably your DEVICE_ID.

Firmware Test Runnerโ€‹

Several tests require dev Lattice firmware with the following flag in the root CMakeLists.txt:

FEATURE_TEST_RUNNER = 1;

See table in the next section.

SafeCard Setup for End-to-End Testsโ€‹

Important

Many end-to-end tests (especially those marked with FEATURE_TEST_RUNNER=1) require a SafeCard loaded with a specific test mnemonic to ensure deterministic test results.

The tests use a standardized test mnemonic for consistent, reproducible results across all test environments:

test test test test test test test test test test test junk

Setting Up Your Test SafeCardโ€‹

Before running end-to-end tests that require FEATURE_TEST_RUNNER=1, you must:

  1. Create a SafeCard on your development Lattice
  2. Load the test mnemonic shown above into the SafeCard
  3. Set the SafeCard as active before running tests

If you run tests with a different mnemonic or seed, the tests will fail with incorrect address derivations and signature mismatches. When debugging test failures, always verify your SafeCard is loaded with the correct test mnemonic.

For details on which tests require the test SafeCard, refer to the table in the next section.

Reference: Tests and Optionsโ€‹

You can run the following tests with npm run <test name>.

TestDescriptionRequires FEATURE_TEST_RUNNER=1
testRuns integration tests. Does not use Lattice.No
test-unitRuns SDK unit tests. Does not use Lattice.No
e2eRuns all end-to-end tests.Yes
e2e-btcTests BTC signatures (legacy signing)Yes
e2e-ethTests EIP712 and personal_sign messages (legacy signing)No
e2e-eip7702Tests EIP-7702 authorization signingYes
e2e-genTests seveal Lattice message routes and some SDK functionality. Bit of a legacy test but still useful.No
e2e-kvTests KV-files, which are used primarily for tags.No
e2e-neTests non-exportable seeded SafeCards (legacy).No
e2e-signRuns all signing tests.Yes
e2e-sign-blsTests BLS signatures and key derivations.Yes
e2e-sign-determinismTests determinism of signatures using known seed loading.Yes
e2e-sign-evm-abiTests ABI decoding and fetching for EVM transactions.Yes
e2e-sign-evm-txTests EVM transaction types.Yes
e2e-sign-solanaTests Solana transactions and address derivation.Yes
e2e-sign-unformattedTests signing unformatted payloads (ASCII or hex strings).Yes
e2e-wjTests wallet jobs, validating path derivations, seed management, etc.Yes
contractsTests smart contract interactions on local Anvil networkYes