diff --git a/.github/actions/ts-e2e/action.yml b/.github/actions/ts-e2e/action.yml index c2f4cf6258ccf..962c75b8ba234 100644 --- a/.github/actions/ts-e2e/action.yml +++ b/.github/actions/ts-e2e/action.yml @@ -23,13 +23,13 @@ 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 @@ -37,9 +37,7 @@ runs: 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 @@ -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 diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index ce447d2a7a1f9..728253d3b4814 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -50,7 +50,7 @@ jobs: - uses: pnpm/action-setup@a3252b78c470c02df07e9d59298aecedc3ccdd6d # pin@v3.0.0 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 # pin@v4.0.2 with: @@ -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'}} @@ -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 diff --git a/apps/wallet/playwright.config.ts b/apps/wallet/playwright.config.ts index 16114b4a1c475..f367b4a76689b 100644 --- a/apps/wallet/playwright.config.ts +++ b/apps/wallet/playwright.config.ts @@ -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 */ diff --git a/crates/sui-graphql-rpc/README.md b/crates/sui-graphql-rpc/README.md index 44cdbe22ec89a..af7974546ddd0 100644 --- a/crates/sui-graphql-rpc/README.md +++ b/crates/sui-graphql-rpc/README.md @@ -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` diff --git a/crates/sui-indexer/README.md b/crates/sui-indexer/README.md index 91b17f603bf1b..bb7adeccfae27 100644 --- a/crates/sui-indexer/README.md +++ b/crates/sui-indexer/README.md @@ -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: diff --git a/crates/sui-rpc-loadgen/README.md b/crates/sui-rpc-loadgen/README.md index 37b230b0162dd..94ce35e0df541 100644 --- a/crates/sui-rpc-loadgen/README.md +++ b/crates/sui-rpc-loadgen/README.md @@ -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 diff --git a/docs/content/guides/developer/getting-started/get-coins.mdx b/docs/content/guides/developer/getting-started/get-coins.mdx index 3b4a7ad34df64..26bc17f2da942 100644 --- a/docs/content/guides/developer/getting-started/get-coins.mdx +++ b/docs/content/guides/developer/getting-started/get-coins.mdx @@ -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 diff --git a/docs/content/guides/developer/getting-started/local-network.mdx b/docs/content/guides/developer/getting-started/local-network.mdx index 3a44fe96a556c..ce9bdfc5745b3 100644 --- a/docs/content/guides/developer/getting-started/local-network.mdx +++ b/docs/content/guides/developer/getting-started/local-network.mdx @@ -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 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[=] 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[=] 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[=] 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 Port to start the Fullnode RPC server on. Default port is 9000 [default: 9000] + --pg-port Port for the Indexer Postgres DB. Default port is 5432 [default: 5432] + --pg-host Hostname for the Indexer Postgres DB. Default host is localhost [default: localhost] + --pg-db-name DB name for the Indexer Postgres DB. Default DB name is sui_indexer [default: sui_indexer] + --pg-user DB username for the Indexer Postgres DB. Default username is postgres [default: postgres] + --pg-password DB password for the Indexer Postgres DB. Default password is postgrespw [default: postgrespw] + --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 - The duration for epochs (defaults to one minute) [default: 60000] - --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 - 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 @@ -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 @@ -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` @@ -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. ::: @@ -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. + diff --git a/sdk/deepbook/package.json b/sdk/deepbook/package.json index 6bdb8ada43167..2280eaf65dafd 100644 --- a/sdk/deepbook/package.json +++ b/sdk/deepbook/package.json @@ -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:*" diff --git a/sdk/docs/pages/typescript/sui-client.mdx b/sdk/docs/pages/typescript/sui-client.mdx index ed3b31da34109..fe0b245bd2257 100644 --- a/sdk/docs/pages/typescript/sui-client.mdx +++ b/sdk/docs/pages/typescript/sui-client.mdx @@ -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. diff --git a/sdk/graphql-transport/package.json b/sdk/graphql-transport/package.json index 7cdabcbb5dda1..9502801d9944a 100644 --- a/sdk/graphql-transport/package.json +++ b/sdk/graphql-transport/package.json @@ -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": { diff --git a/sdk/kiosk/package.json b/sdk/kiosk/package.json index 5094d10feff93..6e9535afb59a4 100644 --- a/sdk/kiosk/package.json +++ b/sdk/kiosk/package.json @@ -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:*" diff --git a/sdk/typescript/README.md b/sdk/typescript/README.md index 9a9dfad293d7e..321d0b65dab30 100644 --- a/sdk/typescript/README.md +++ b/sdk/typescript/README.md @@ -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 diff --git a/sdk/typescript/package.json b/sdk/typescript/package.json index 8aebc1b6a5131..f04b51e986431 100644 --- a/sdk/typescript/package.json +++ b/sdk/typescript/package.json @@ -102,7 +102,7 @@ "test:unit": "vitest run unit __tests__", "test:e2e": "wait-on http://127.0.0.1:9123 -l --timeout 180000 && vitest run e2e", "test:e2e:nowait": "vitest run e2e", - "prepare:e2e": "docker-compose down && docker-compose up -d && 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 -- --with-indexer --pg-port 5435 --pg-db-name sui_indexer_v2 --graphql-host 127.0.0.1 --graphql-port 9125", + "prepare:e2e": "docker-compose down && docker-compose up -d && cargo build --bin sui --features indexer --profile dev && cross-env RUST_LOG=warn,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", "prepublishOnly": "pnpm build", "size": "size-limit", "analyze": "size-limit --why",