Skip to content

Integration Tests

JinGyeong Jeong edited this page Aug 24, 2018 · 7 revisions

Integration tests are for testing CodeChain application as a whole. Related files are located under test/ directory, and uses Typescript as script language.

Installing Dependencies

yarn is used for a package manager. To install dependencies, run following command in the test directory:

yarn install

Building CodeChain executable

Currently, It requires you to compile in advance to run the tests. The integration tests will directly execute the binary in target/debug directory or target/release directory.

# debug
cargo build
# release
cargo build --release

Running Tests

To run integration tests, run following command in integration test directory.

# debug
yarn start
# release
NODE_ENV=production yarn start

Writing Test

Simple integration test that sends a parcel and gets an invoice from CodeChain is implemented at src/basic.test.ts. It would be a good starting point for implementing new tests.

Writing an integration test involves spawning a new CodeChain process and attaching SDK to it. Helper class for automating this process is defined under src/helper/spawn.ts, named CodeChain. Some important functions are described below:

constructor

Assigns globally unique instance id to this object. Many parameters that need to avoid conflict(such as a port number) are derived from this instance id.

start

Spawns a new CodeChain node, and returns Promise that resolves when initialization is completed.

clean

Kills a process and cleanup files created while running this node.