Skip to content

Commit

Permalink
[cli] Change all documentation and workflows to use sui binary inst…
Browse files Browse the repository at this point in the history
…ead of `sui-test-validator` (MystenLabs#18471)

## Description 

PR MystenLabs#18204 integrated `sui-test-validator` into `sui`. This PR updates
all relevant workflows and documentation to use `sui` binary with the
right options and flags instead of `sui-test-validator`.

## Test plan 

How did you test the new or updated feature?

---

## Release notes

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol: 
- [ ] Nodes (Validators and Full nodes): 
- [ ] Indexer: 
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [ ] CLI: 
- [ ] Rust SDK:
  • Loading branch information
stefan-mysten authored Jul 1, 2024
1 parent 5cad056 commit 1bc3c69
Show file tree
Hide file tree
Showing 14 changed files with 78 additions and 44 deletions.
10 changes: 4 additions & 6 deletions .github/actions/ts-e2e/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,21 @@ runs:
id: check_s3
run: |
echo "Checking if s3 binaries have been built for ${{ github.sha }}"
echo "s3_file_exist=$(curl -Is https://sui-releases.s3.us-east-1.amazonaws.com/${{ github.sha }}/debug/sui-test-validator | head -n 1 | grep '200 OK')" >> $GITHUB_ENV
echo "s3_file_exist=$(curl -Is https://sui-releases.s3.us-east-1.amazonaws.com/${{ github.sha }}/debug/sui-pg | head -n 1 | grep '200 OK')" >> $GITHUB_ENV
shell: bash

- name: cargo build
if: env.s3_file_exist == '' # if empty, we have not built and uploaded this binary to s3 yet
run: |
cargo build --bin sui-test-validator --bin sui
cargo build --bin sui --features indexer
shell: bash

- name: Dowload from S3
if: env.s3_file_exist != '' # only download if the s3 file exists
working-directory: ./target/debug
run: |
mkdir -p $PWD/target/debug
wget -O target/debug/sui-test-validator https://sui-releases.s3.us-east-1.amazonaws.com/${{ github.sha }}/debug/sui-test-validator
chmod +x $PWD/target/debug/sui-test-validator
wget -O target/debug/sui-test-validator https://sui-releases.s3.us-east-1.amazonaws.com/${{ github.sha }}/debug/sui
wget -O target/debug/sui https://sui-releases.s3.us-east-1.amazonaws.com/${{ github.sha }}/debug/sui-pg
chmod +x $PWD/target/debug/sui
shell: bash

Expand All @@ -59,7 +57,7 @@ runs:

- name: Set env
run: |
echo "E2E_RUN_LOCAL_NET_CMD=(RUST_LOG=\"consensus=off\" $(echo $PWD/target/debug/sui-test-validator) --with-indexer --pg-port 5432 --pg-db-name sui_indexer_v2 --graphql-host 127.0.0.1 --graphql-port 9125)" >> $GITHUB_ENV
echo "E2E_RUN_LOCAL_NET_CMD=(RUST_LOG=\"consensus=off\" $(echo $PWD/target/debug/sui) start --with-faucet --force-regenesis --with-indexer --pg-port 5432 --pg-db-name sui_indexer_v2 --with-graphql)" >> $GITHUB_ENV
echo "VITE_SUI_BIN=$PWD/target/debug/sui" >> $GITHUB_ENV
shell: bash

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
- uses: pnpm/action-setup@a3252b78c470c02df07e9d59298aecedc3ccdd6d # [email protected]
with:
version: 9.1.1
- run: cargo build --bin sui-test-validator --bin sui --profile dev
- run: cargo build --bin sui --features indexer --profile dev
- name: Install Nodejs
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # [email protected]
with:
Expand All @@ -64,7 +64,7 @@ jobs:
- name: Set env
run: |
echo "VITE_SUI_BIN=$PWD/target/debug/sui" >> $GITHUB_ENV
echo "E2E_RUN_LOCAL_NET_CMD=(RUST_LOG=warn RUST_BACKTRACE=1 $(echo $PWD/target/debug/sui-test-validator) --with-indexer --pg-port 5432 --pg-db-name sui_indexer_v2 --graphql-host 127.0.0.1 --graphql-port 9125)" >> $GITHUB_ENV
echo "E2E_RUN_LOCAL_NET_CMD=(RUST_LOG=warn RUST_BACKTRACE=1 $(echo $PWD/target/debug/sui) start --with-faucet --force-regenesis --with-indexer --pg-port 5432 --pg-db-name sui_indexer_v2 --with-graphql)" >> $GITHUB_ENV
- name: Run TS SDK e2e tests
if: ${{ needs.diff.outputs.isTypescriptSDK == 'true' || needs.diff.outputs.isRust == 'true'}}
Expand All @@ -75,7 +75,7 @@ jobs:
run: pnpm dlx concurrently --kill-others --success command-1 "$E2E_RUN_LOCAL_NET_CMD" 'pnpm --filter @mysten/graphql-transport test:e2e'

- name: Run Local net
run: cargo run --bin sui-test-validator -- --epoch-duration-ms 10000 &
run: cargo run --bin sui -- start --with-faucet --force-regenesis --epoch-duration-ms 10000 &
- name: Set Wallet env
run: echo "API_ENV=local" > "$PWD/apps/wallet/configs/environment/.env"
- name: Build Wallet
Expand Down
2 changes: 1 addition & 1 deletion apps/wallet/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const config: PlaywrightTestConfig = {
{
command:
process.env.E2E_RUN_LOCAL_NET_CMD ??
'RUST_LOG="consensus=off" cargo run --bin sui-test-validator',
'RUST_LOG="consensus=off" cargo run --bin sui -- start --with-faucet --force-regenesis',
port: 9123,
timeout: 120 * 1000,
/* Set this to true to reuse the server instance on step 'Run Local net' in e2e.yml */
Expand Down
2 changes: 1 addition & 1 deletion crates/sui-graphql-rpc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,6 @@ For local dev, it might be useful to spin up an indexer as well. Instructions ar

## Compatibility with json-rpc

`cargo run --bin sui-test-validator -- --with-indexer --pg-port 5432 --pg-db-name sui_indexer_v2 --graphql-host 127.0.0.1 --graphql-port 9125`
`cargo run --bin sui --features indexer -- start --with-faucet --force-regenesis --with-indexer --pg-port 5432 --pg-db-name sui_indexer_v2 --with-graphql`

`pnpm --filter @mysten/graphql-transport test:e2e`
12 changes: 11 additions & 1 deletion crates/sui-indexer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,17 @@ brew services start postgresql@version

### Local Development(Recommended)

Use [sui-test-validator](../../crates/sui-test-validator/README.md)
See the [docs](https://docs.sui.io/guides/developer/getting-started/local-network) for detailed information. Below is a quick start guide:

Start a local network using the `sui` binary:
```sh
cargo run --bin sui -- start --with-faucet --force-regenesis
```

If you want to run a local network with the indexer enabled (note that `libpq` is required), you can run the following command after following the steps in the next section to set up an indexer DB:
```sh
cargo run --bin sui --features indexer -- start --with-faucet --force-regenesis --with-indexer --pg-port 5432 --pg-db-name sui_indexer_v2
```

### Running standalone indexer
1. DB setup, under `sui/crates/sui-indexer` run:
Expand Down
2 changes: 1 addition & 1 deletion crates/sui-rpc-loadgen/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Run the following command to see available commands:
cargo run --bin sui-rpc-loadgen -- -h
```

To try this locally, refer to [sef](../sui-test-validator/README.md). Recommend setting `database-url` to an env variable. Note: run `RUST_LOG="consensus=off" cargo run sui-test-validator -- --with-indexer` to rebuild.
To try this locally, refer to the [docs](https://docs.sui.io/guides/developer/getting-started/local-network). Recommend setting `database-url` to an env variable. Note: run `RUST_LOG="consensus=off" cargo run sui --features indexer -- start --with-faucet --force-regenesis --with-indexer` to rebuild.

### Example 1: Get All Checkpoints

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ curl --location --request POST 'https://faucet.devnet.sui.io/gas' \
If you're working with a local network, replace `'https://faucet.devnet.sui.io/gas'` with the appropriate value based on which package runs your network:

- `sui-faucet`: `http://127.0.0.1:5003/gas`
- `sui-test-validator`: `http://127.0.0.1:9123/gas`
- `sui`: `http://127.0.0.1:9123/gas`

## Request test tokens through TypeScript SDK

Expand Down
70 changes: 48 additions & 22 deletions docs/content/guides/developer/getting-started/local-network.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,63 @@
title: Connect to a Local Network
---

Use a Sui local network to test your dApps against the latest changes to Sui, and to prepare for the next Sui release to the Devnet or Testnet network. To set up a local network, Sui provides the `sui-test-validator` binary. The `sui-test-validator` starts a local network that includes a Sui Full node, a Sui validator, and a Sui faucet. You can use the included faucet to get test SUI to use on the local network.
Use a Sui local network to test your dApps against the latest changes to Sui, and to prepare for the next Sui release to the Devnet or Testnet network. Sui CLI provides the `sui start` command to start a local network. There are several services that can be started when using `sui start`, such as an indexer, a faucet, or a local instance of the GraphQL service (including the online GraphiQL IDE). You can use the included faucet to get test SUI to use on the local network.

If you haven't already, you need to [install Sui](./sui-install.mdx) on your system.
If you haven't already, you need to [install Sui CLI](./sui-install.mdx) on your system.

## Start the local network

To start the local network, run the following command from your `sui` root folder.
To start the local network, run the following command after you install Sui CLI.

```bash
RUST_LOG="off,sui_node=info" cargo run --bin sui-test-validator
RUST_LOG="off,sui_node=info" sui start --with-faucet --force-regenesis
```

The command starts the `sui-test-validator`. The `RUST_LOG`=`off,sui_node=info` turns off logging for all components except
sui-node. If you want to see more detailed logs, you can remove `RUST_LOG` from the command.
This command:
* Calls the Sui CLI binary with two flags:
* `--with-faucet` to start a faucet service.
* `--force-regenesis` to generate a new genesis and not persist the local network state.
* Instructs Rust to set specific logging through the `RUST_LOG`=`off,sui_node=info` flags, which turns off logging for all components except `sui-node`. If you want to see more detailed logs, you can remove `RUST_LOG` from the command.

**Important:** Each time you start the `sui-test-validator`, the network starts as a new network with no previous data. The local network is not persistent.
:::info
Each time you start the network by passing `--force-regenesis`, the local network starts from a random genesis with no previous data, and the local network is not persisted. If you'd like to persist data, skip passing the `--force-regenesis` flag. For more details, see the [Persist local network state](#persist-local-network) section.
:::

To customize your local Sui network, such as changing the port used, include additional parameters in the command to start `sui-test-validator`:
To customize your local Sui network, such as starting other services or changing default ports and hosts, include additional flags or options in the `sui start` command. Note that `with-indexer` and `with-graphql` requires you to use the `sui-pg` binary from the GitHub release archive, or to build the `sui` binary the indexer feature enabled: `cargo build --bin sui --features indexer`.

The following is a list of possible options and flags to pass to `sui start`:
```
--network.config <CONFIG_DIR> Config directory that will be used to store network config, node db, keystore sui genesis -f --with-faucet generates a genesis config that can be used to start this process. Use with caution as the `-f` flag
will overwrite the existing config directory. We can use any config dir that is generated by the `sui genesis`
--force-regenesis A new genesis is created each time this flag is set, and state is not persisted between runs. Only use this flag when you want to start the network from scratch every time you run this command
--with-graphql[=<WITH_GRAPHQL>] Start a GraphQL server on localhost and port: 127.0.0.1:9125, or on the port provided. When providing a specific value, please use the = sign between the flag and value: `--with-graphql=6125`. Note that
GraphQL requires a running indexer
--with-faucet[=<WITH_FAUCET>] Start a faucet with default host and port: 127.0.0.1:9123, or on the port provided. When providing a specific value, please use the = sign between the flag and value: `--with-faucet=6123`
--with-indexer[=<WITH_INDEXER>] Start an indexer with default host and port: 0.0.0.0:9124, or on the port provided. When providing a specific value, please use the = sign between the flag and value: `--with-faucet=6124`. The indexer be started in writer mode and reader mode
--fullnode-rpc-port <FULLNODE_RPC_PORT> Port to start the Fullnode RPC server on. Default port is 9000 [default: 9000]
--pg-port <PG_PORT> Port for the Indexer Postgres DB. Default port is 5432 [default: 5432]
--pg-host <PG_HOST> Hostname for the Indexer Postgres DB. Default host is localhost [default: localhost]
--pg-db-name <PG_DB_NAME> DB name for the Indexer Postgres DB. Default DB name is sui_indexer [default: sui_indexer]
--pg-user <PG_USER> DB username for the Indexer Postgres DB. Default username is postgres [default: postgres]
--pg-password <PG_PASSWORD> DB password for the Indexer Postgres DB. Default password is postgrespw [default: postgrespw]
--epoch-duration-ms <EPOCH_DURATION_MS> Set the epoch duration. Can only be used when `--force-regenesis` flag is passed or if there's no genesis config and one will be auto-generated. When this flag is not set but `--force-regenesis` is set, the
epoch duration will be set to 60 seconds
--no-full-node Start the network without a fullnode
-h, --help Print help (see more with '--help')
```
OPTIONS:
--epoch-duration-ms <EPOCH_DURATION_MS>
The duration for epochs (defaults to one minute) [default: 60000]

--faucet-port <FAUCET_PORT>
Port to start the Sui faucet on [default: 9123]
Use `sui start --help` to see these options in your console.

--fullnode-rpc-port <FULLNODE_RPC_PORT>
Port to start the Fullnode RPC server on [default: 9000]
```
### Persist local network state

By default, when using `sui start` the command uses an existing genesis and network configuration if the `~/.sui/sui_config` folder exists and includes a `genesis.blob` file. If the folder doesn't exist, it creates the folder and generates a new genesis configuration. If you pass `--network.config`, the command checks for the network config file and tries to load the genesis blob as per the network config file.

Whenever you stop and start the network without passing the `--force-regenesis` flag, all history is preserved and accessible.

:::info
To generate a custom genesis, use the `sui genesis` command and pass the desired custom values. For more information about possible flags and options, run `sui genesis --help`.
:::

Use `sui-test-validator --help` to see these options in your console.

### Access your local Full node

Expand All @@ -60,9 +85,9 @@ If successful, the response resembles the following:
}
```

## Connect the Sui Client CLI to your local network
## Connect the Sui CLI to your local network

You can use the Sui Client CLI with any Sui network. By default it connects to Sui Devnet. To connect to your local network, create a new environment alias named `local` that sets the RPC URL the client uses to your local network.
You can use the Sui CLI with any Sui network. By default it connects to Sui Devnet. To connect to your local network, create a new environment alias named `local` that sets the RPC URL the client uses to your local network.

```shell
sui client new-env --alias local --rpc http://127.0.0.1:9000
Expand Down Expand Up @@ -96,7 +121,7 @@ The Sui Client CLI uses the active address for command if you don't specify one.
sui client active-address
```

The command returns an address:
The command returns an address, for example:

`0xbc33e6e4818f9f2ef77d020b35c24be738213e64d9e58839ee7b4222029610de`

Expand All @@ -110,13 +135,13 @@ The address returned when you run the command is unique and does not match the o

## Use the local faucet {#use-the-local-faucet}

Transactions on your local network require SUI coins to pay for gas fees just like other networks. You can use the currently active address with the faucet.
Transactions on your local network require SUI coins to pay for gas fees just like other networks. You can use the active address with the faucet.

Sui CLI provides the `sui client faucet` command to get coins from the faucet. In the most basic case, run `sui client faucet` and wait up to 60 seconds for the coins to reach your address. Use `sui client gas` to check for the new coins.

:::info

The `faucet` command uses the active address and the active network environment by default. If you need to pass in a different address or faucet server URL, check the `help` menu. If you're using a different network than a local network or the public ones (fullnode.network.sui.io), you will have to pass the URL to the faucet server.
The `faucet` command uses the active address and the active network environment by default. If you need to pass in a different address or faucet server URL, check the `help` menu. If you're using a different network than a local network or the public ones (`fullnode.network.sui.io`), pass the URL to the faucet server.

:::

Expand Down Expand Up @@ -163,3 +188,4 @@ To resolve this, switch or update to Node.js 18 and then try again.
## Test with the Sui TypeScript SDK

The published version of the Sui TypeScript SDK might be an earlier version than the version of Sui you installed for your local network. To make sure you're using the latest version of the SDK, use the `experimental`-tagged version (for example, `0.0.0-experimental-20230317184920`) in the [Current Tags](https://www.npmjs.com/package/@mysten/sui/v/0.0.0-experimental-20230127130009?activeTab=versions) section of the Sui NPM registry.

2 changes: 1 addition & 1 deletion sdk/deepbook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"lint": "pnpm run eslint:check && pnpm run prettier:check",
"lint:fix": "pnpm run eslint:fix && pnpm run prettier:fix",
"test:e2e": "wait-on http://127.0.0.1:9123 -l --timeout 120000 && vitest run e2e",
"prepare:e2e": "cargo build --bin sui-test-validator --bin sui --profile dev && cross-env RUST_LOG=warn,sui=error,anemo_tower=warn,consensus=off cargo run --bin sui-test-validator"
"prepare:e2e": "cargo build --bin sui --profile dev && cross-env RUST_LOG=warn,sui=error,anemo_tower=warn,consensus=off cargo run --bin sui -- start --with-faucet --force-regenesis"
},
"dependencies": {
"@mysten/sui": "workspace:*"
Expand Down
4 changes: 2 additions & 2 deletions sdk/docs/pages/typescript/sui-client.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ during development. In a production application, however, you should use the
- `testnet`
- `mainnet`

For local development, you can run `cargo run --bin sui-test-validator` to spin up a local network
with a local validator, a Full node, and a faucet server. Refer to
For local development, you can run `cargo run --bin sui -- start --with-faucet --force-regenesis` to
spin up a local network with a local validator, a Full node, and a faucet server. Refer to
[the Local Network guide](https://docs.sui.io/guides/developer/getting-started/local-network) for
more information.

Expand Down
2 changes: 1 addition & 1 deletion sdk/graphql-transport/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"prettier:check": "prettier -c --ignore-unknown .",
"prettier:fix": "prettier -w --ignore-unknown .",
"test:e2e:nowait": "vitest run e2e",
"test:e2e:prepare": "docker-compose down && docker-compose up -d && cargo build --bin sui-test-validator --bin sui --profile dev && cross-env RUST_LOG=info,sui=error,anemo_tower=warn,consensus=off cargo run --bin sui-test-validator -- --with-indexer --pg-port 5435 --pg-db-name sui_indexer_v2 --graphql-host 127.0.0.1 --graphql-port 9125",
"test:e2e:prepare": "docker-compose down && docker-compose up -d && cargo build --bin sui --features indexer --profile dev && cross-env RUST_LOG=info,sui=error,anemo_tower=warn,consensus=off cargo run --bin sui -- start --with-faucet --force-regenesis --with-indexer --pg-port 5435 --pg-db-name sui_indexer_v2 --with-graphql",
"test:e2e": "wait-on http://127.0.0.1:9123 -l --timeout 180000 && vitest"
},
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion sdk/kiosk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"lint": "pnpm run eslint:check && pnpm run prettier:check",
"lint:fix": "pnpm run eslint:fix && pnpm run prettier:fix",
"test:e2e": "wait-on http://127.0.0.1:9123 -l --timeout 120000 && vitest run e2e",
"prepare:e2e": "cargo build --bin sui-test-validator --bin sui --profile dev && cross-env RUST_LOG=warn,sui=error,anemo_tower=warn,consensus=off cargo run --bin sui-test-validator"
"prepare:e2e": "cargo build --bin sui --profile dev && cross-env RUST_LOG=warn,sui=error,anemo_tower=warn,consensus=off cargo run --bin sui -- start --with-faucet --force-regenesis"
},
"dependencies": {
"@mysten/sui": "workspace:*"
Expand Down
4 changes: 2 additions & 2 deletions sdk/typescript/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ await client.getCoins({
});
```

For local development, you can run `cargo run --bin sui-test-validator` to spin up a local network
with a local validator, a fullnode, and a faucet server. Refer to
For local development, you can run `cargo run --bin --with-faucet --force-regenesis` to spin up a
local network with a local validator, a fullnode, and a faucet server. Refer to
[this guide](https://docs.sui.io/build/sui-local-network) for more information.

```typescript
Expand Down
Loading

0 comments on commit 1bc3c69

Please sign in to comment.