Skip to content

Commit

Permalink
feat(test-tooling): add Stellar test ledger
Browse files Browse the repository at this point in the history
- Add a Stellar test ledger class that can be used in integration tests
  to start and stop a Stellar test network based on the Stellar
  quickstart docker image: https://github.com/stellar/quickstart

- Inclues the following services for fetching ledger state, executing
classic transactions and also soroban smart contracts transactions.
  - Stellar Core
  - Horizon API
  - Soroban RPC
  - Friendbot

Fixes #3239

Signed-off-by: Peter Somogyvari <peter.somogyvari@accenture.com>
Signed-off-by: Fabricius Zatti <fazzatti@gmail.com>
  • Loading branch information
fazzatti authored and petermetz committed May 22, 2024
1 parent 9f77871 commit 58fa94e
Show file tree
Hide file tree
Showing 9 changed files with 737 additions and 202 deletions.
405 changes: 203 additions & 202 deletions .cspell.json

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions packages/cactus-test-tooling/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,43 @@
```
// TODO: DEMONSTRATE API
```

## Docker image for the ws-identity server

A docker image of the [ws-identity server](https://hub.docker.com/repository/docker/brioux/ws-identity) is used to test integration of WS-X.509 credential type in the fabric connector plugin.

[ws-identity](https://github.com/brioux/ws-identity) includes A Docker file to build the image:
clone the repo, install packages, build src and the image

```
npm install
npm run build
docker build . -t [image-name]
```

## Stellar Test Ledger Usage

The Stellar test ledger follows the same structure present in the test ledger tools for other networks within the Cacti project. It pulls up and manages the [Stellar Quickstart Docker Image](https://github.com/stellar/quickstart) and can be used by importing the class `StellarTestLedger`, then instantiating it with some key optional arguments to define how the image should be configure.

- `network`: Defines if the image should pull up a pristine local ledger or alternatively connect to an existing public test ledger. Defaults to `local`. It is important to note that connecting to an existing network can take up to several minutes to synchronize the ledger state.

- `limits`: Defines the resource limits for soroban smart contract transactions. A valid transaction and only be included in a ledger block if enough resources are available for that operation. Defaults to `testnet`, which mimics the actual resource limits applied to the mainnet based on its test environment.

Once the class is successfully instantiated, one can start the environment by triggering

```typescript
await stellarTestLedger.start();
```

The image will be pulled up and wait until the healthcheck ensures all of its services have started successfully and are accessible, then returns the container object.

When integrating to a Stellar environment, it is common to use a few key services provided at different ports and paths. Once the class has been started, one can use the method `getNetworkConfiguration()` to get an object containing the required information to connect to this services.

This object is already formatted to be used with the [stellar-plus](https://github.com/CheesecakeLabs/stellar-plus) open source js library to create a custom network configuration object that integrates with its provided tools, ensuring a frictionless development flow for this test ledger.

Once the image have been fully utilized, one can fully stop and remove the environment by triggering

```typescript
await stellarTestLedger.stop();
await stellarTestLedger.destroy();
```
5 changes: 5 additions & 0 deletions packages/cactus-test-tooling/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@
"name": "Peter Somogyvari",
"email": "peter.somogyvari@accenture.com",
"url": "https://accenture.com"
},
{
"name": "Fabricius Zatti",
"email": "fazzatti@gmail.com",
"url": "https://oififo.com"
}
],
"main": "dist/lib/main/typescript/index.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ export {
SawtoothTestLedger,
} from "./sawtooth/sawtooth-test-ledger";

export {
IStellarTestLedgerOptions,
StellarTestLedger,
} from "./stellar/stellar-test-ledger";

export {
ISubstrateTestLedgerOptions,
SubstrateTestLedger,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//
// List of supported networks to connect
// when the test ledger image is pulled up.
//
export enum Network {
LOCAL = "local", // (Default) pull up a new pristine network image locally.
FUTURENET = "futurenet", // pull up an image to connect to futurenet. Can take several minutes to sync the ledger state.
TESTNET = "testnet", // pull up an image to connect to testnet Can take several minutes to sync the ledger state.
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// Define the resource limits set to Soroban transactions
// when pulling up a local network. This defines how smart contract
// transactions are limited in terms of resources during execution.
//
// Transactions that exceed these limits will be rejected.
//
export enum ResourceLimits {
TESTNET = "testnet", // (Default) sets the limits to match those used on testnet.
DEFAULT = "default", // leaves resource limits set extremely low as per Stellar's core default configuration
UNLIMITED = "unlimited", // set limits to maximum resources that can be configured
}
Loading

0 comments on commit 58fa94e

Please sign in to comment.