Skip to content

Commit 86ad4b2

Browse files
ci: separate tests that require network and run localnet in ci (#38)
1 parent 494b3a6 commit 86ad4b2

File tree

4 files changed

+253
-193
lines changed

4 files changed

+253
-193
lines changed

.github/workflows/ci.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,57 @@ jobs:
6262

6363
- name: Run tests in wasm
6464
run: make wasm
65+
66+
67+
run_tests_with_network:
68+
runs-on: ubuntu-latest
69+
env:
70+
EPOCH_DURATION_MS: 10000
71+
services:
72+
postgres: # we need this postgres instance for running a local network with indexer and graphql
73+
image: postgres
74+
env:
75+
POSTGRES_USER: postgres
76+
POSTGRES_PASSWORD: postgrespw
77+
POSTGRES_DB: sui_indexer_v2
78+
POSTGRES_HOST_AUTH_METHOD: trust
79+
options: >-
80+
--health-cmd pg_isready
81+
--health-interval 10s
82+
--health-timeout 5s
83+
--health-retries 5
84+
ports:
85+
- 5432:5432
86+
steps:
87+
- name: Checkout repository
88+
uses: actions/checkout@v4
89+
90+
- name: rust version
91+
run: |
92+
rustc --version
93+
cargo --version
94+
95+
- uses: taiki-e/install-action@cargo-nextest
96+
97+
- name: Get the Sui testnet binary and start a local network
98+
shell: bash
99+
env:
100+
SUI_BINARY_VERSION: "1.35.1" # used for downloading a specific Sui binary versions that matches the GraphQL schema for local network tests
101+
SUI_NETWORK_RELEASE: "testnet" # which release to use
102+
run: |
103+
ASSET_NAME="sui-$SUI_NETWORK_RELEASE-v$SUI_BINARY_VERSION-ubuntu-x86_64.tgz"
104+
download_url="https://github.com/mystenlabs/sui/releases/download/$SUI_NETWORK_RELEASE-v$SUI_BINARY_VERSION/$ASSET_NAME"
105+
106+
echo "Downloading testnet binary from $download_url"
107+
wget -q $download_url -O sui.tgz
108+
tar -zxvf sui.tgz ./sui
109+
echo "Starting local network with a faucet, an indexer (port 5432) and GraphQL. Epoch duration is set to $EPOCH_DURATION_MS ms"
110+
./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 &
111+
112+
- name: Run tests that require local network (GraphQL Client and Tx Builder)
113+
env:
114+
NETWORK: "local" # other expected options are mainnet, testnet, or devnet, or an actual URL to a GraphQL server: http://localhost:port
115+
run: |
116+
sleep $((EPOCH_DURATION_MS / 1000)) # wait for the network to get to epoch #2
117+
make test-with-localnet
118+

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,13 @@ clippy:
2121

2222
.PHONY: test
2323
test:
24-
cargo nextest run --all-features
24+
cargo nextest run --all-features -p sui-sdk-types -p sui-crypto
2525
cargo test --doc
2626

27+
.PHONY: test-with-localnet
28+
test-with-localnet:
29+
cargo nextest run -p sui-graphql-client
30+
2731
.PHONY: wasm
2832
wasm:
2933
$(MAKE) -C crates/sui-sdk-types wasm

crates/sui-graphql-client/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ executing transactions and more.
2020
## Connecting to a GraphQL server
2121
Instantiate a client with [`Client::new(server: &str)`] or use one of the predefined functions for different networks [`Client`].
2222

23-
```rust
23+
```rust, no_run
2424
use sui_graphql_client::Client;
2525
use anyhow::Result;
2626
@@ -118,7 +118,7 @@ The generated query types are defined below. Note that the `id` variable is opti
118118
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.
119119

120120

121-
```rust,ignore
121+
```rust, ignore
122122
#[derive(cynic::QueryVariables, Debug)]
123123
pub struct CustomQueryVariables {
124124
pub id: Option<u64>,
@@ -145,7 +145,7 @@ pub struct BigInt(pub String);
145145
```
146146

147147
The complete example is shown below:
148-
```rust
148+
```rust, ignore
149149
use anyhow::Result;
150150
use cynic::QueryBuilder;
151151

0 commit comments

Comments
 (0)