Skip to main content

Module: test

This module exports a simple testing framework.

Specifically, it exposes the TestDK class (and its more specific variant CubistTestDK) which abstracts over a Cubist project's testing infrastructure. TestDK can be used to:

TestDK can be used for testing well-typed CubistORM projects too (see Overview).

Exports

Testing

Testing

Service: Object

Cubist service we can start/stop.

Defined in

submodules/cubist-node-sdk/src/test.ts:51

CubistTestDK: Object

Wrapper for TestDK specific to Cubist, eliding the need for (1) a type parameter and (2) passing Cubist as an argument.

Example

Testing already-built (and deployed) project.

const testdk = new CubistTestDK();

Defined in

submodules/cubist-node-sdk/src/test.ts:326

TestDK<T>: Object

Class that abstracts over a Cubist project's testing process. In particular, this class makes it possible to (1) create Cubist (or CubistORM) projects with temporary build and deploy directories and (2) start and stop services when running tests.

Example

Using TestDK to test CubistORM projects with Jest. The cubist build command generates CubistORM at build time; this class extends Cubist with project-specific contracts (see the Overview).

import { TestDK, } from '@cubist-labs/cubist';
import { CubistORM } from '../build/orm';

const testdk = new TestDK<CubistORM>(CubistORM, { tmp_deploy_dir: true });

beforeAll(async () => {
await testdk.startService();
});

afterAll(async () => {
await testdk.stopService();
});

beforeEach(async () => {
await testdk.emptyDeployDir();
});

// get the project under test
const cubist = testdk.cubist;

// .. use cubist to get contracts and contract factories, as usual ...

In this example, we create a new testing CubistORM project whose deploy directory is set to a new temporary directory. This lets you test your project without clobbering existing deploy receipts.

We start services---chains and relayer---before all tests, and stop them at the end.

We also empty the deploy directory before each test.

Type parameters

NameType
Textends Cubist

Defined in

submodules/cubist-node-sdk/src/test.ts:118

TestDKOptions: Object

Options for creating a TestDK instance.

Defined in

submodules/cubist-node-sdk/src/test.ts:37

CubistClassRef

Ƭ CubistClassRef<T>: (config?: Config) => T

Type parameters

NameType
Textends Cubist

Type declaration

new CubistClassRef(config?): T

Cubist class reference. We define this type to restrict the kinds of constructors TestDK can be used for. This constructor is called to create a new project, so anything that extends Cubist is sufficient.

Parameters
NameType
config?Config
Returns

T

Defined in

submodules/cubist-node-sdk/src/test.ts:65