Skip to content

Commit

Permalink
ci: separate tests that require network and run localnet in ci (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan-mysten authored Oct 22, 2024
1 parent 494b3a6 commit 86ad4b2
Show file tree
Hide file tree
Showing 4 changed files with 253 additions and 193 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,57 @@ jobs:

- name: Run tests in wasm
run: make wasm


run_tests_with_network:
runs-on: ubuntu-latest
env:
EPOCH_DURATION_MS: 10000
services:
postgres: # we need this postgres instance for running a local network with indexer and graphql
image: postgres
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgrespw
POSTGRES_DB: sui_indexer_v2
POSTGRES_HOST_AUTH_METHOD: trust
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: rust version
run: |
rustc --version
cargo --version
- uses: taiki-e/install-action@cargo-nextest

- name: Get the Sui testnet binary and start a local network
shell: bash
env:
SUI_BINARY_VERSION: "1.35.1" # used for downloading a specific Sui binary versions that matches the GraphQL schema for local network tests
SUI_NETWORK_RELEASE: "testnet" # which release to use
run: |
ASSET_NAME="sui-$SUI_NETWORK_RELEASE-v$SUI_BINARY_VERSION-ubuntu-x86_64.tgz"
download_url="https://github.com/mystenlabs/sui/releases/download/$SUI_NETWORK_RELEASE-v$SUI_BINARY_VERSION/$ASSET_NAME"
echo "Downloading testnet binary from $download_url"
wget -q $download_url -O sui.tgz
tar -zxvf sui.tgz ./sui
echo "Starting local network with a faucet, an indexer (port 5432) and GraphQL. Epoch duration is set to $EPOCH_DURATION_MS ms"
./sui start --force-regenesis --with-faucet --with-indexer --with-graphql --pg-port 5432 --pg-db-name sui_indexer_v2 --epoch-duration-ms $EPOCH_DURATION_MS &
- name: Run tests that require local network (GraphQL Client and Tx Builder)
env:
NETWORK: "local" # other expected options are mainnet, testnet, or devnet, or an actual URL to a GraphQL server: http://localhost:port
run: |
sleep $((EPOCH_DURATION_MS / 1000)) # wait for the network to get to epoch #2
make test-with-localnet
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ clippy:

.PHONY: test
test:
cargo nextest run --all-features
cargo nextest run --all-features -p sui-sdk-types -p sui-crypto
cargo test --doc

.PHONY: test-with-localnet
test-with-localnet:
cargo nextest run -p sui-graphql-client

.PHONY: wasm
wasm:
$(MAKE) -C crates/sui-sdk-types wasm
Expand Down
6 changes: 3 additions & 3 deletions crates/sui-graphql-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ executing transactions and more.
## Connecting to a GraphQL server
Instantiate a client with [`Client::new(server: &str)`] or use one of the predefined functions for different networks [`Client`].

```rust
```rust, no_run
use sui_graphql_client::Client;
use anyhow::Result;
Expand Down Expand Up @@ -118,7 +118,7 @@ The generated query types are defined below. Note that the `id` variable is opti
Note that instead of using `Uint53`, the scalar is mapped to `u64` in the library using `impl_scalar(u64, schema::Uint53)`, thus all references to `Uint53` in the schema are replaced with `u64` in the code below.


```rust,ignore
```rust, ignore
#[derive(cynic::QueryVariables, Debug)]
pub struct CustomQueryVariables {
pub id: Option<u64>,
Expand All @@ -145,7 +145,7 @@ pub struct BigInt(pub String);
```

The complete example is shown below:
```rust
```rust, ignore
use anyhow::Result;
use cynic::QueryBuilder;
Expand Down
Loading

0 comments on commit 86ad4b2

Please sign in to comment.