diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 74167f69..29e37606 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -236,7 +236,7 @@ jobs: - run: cd tests/bpf-upgradeable-state && yarn link @project-serum/anchor - run: cd tests/bpf-upgradeable-state && anchor build --skip-lint - run: cd tests/bpf-upgradeable-state && solana program deploy --program-id program_with_different_programdata.json target/deploy/bpf_upgradeable_state.so - - run: cd tests/bpf-upgradeable-state && cp bpf_upgradeable_state-keypair.json target/deploy/bpf_upgradeable_state-keypair.json && anchor deploy && anchor test --skip-deploy --skip-build --skip-lint + - run: cd tests/bpf-upgradeable-state && cp bpf_upgradeable_state-keypair.json target/deploy/bpf_upgradeable_state-keypair.json && anchor test --skip-local-validator --skip-build --skip-lint - uses: ./.github/actions/git-diff/ test-anchor-init: diff --git a/CHANGELOG.md b/CHANGELOG.md index 49f64d99..59f1faf5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ The minor version will be incremented upon a breaking change and the patch versi ### Fixes * avm: `avm install` no longer downloads the version if already installed in the machine ([#1670](https://github.com/project-serum/anchor/pull/1670)). +* cli: make `anchor test` fail when used with `--skip-deploy` option and without `--skip-local-validator` option but there already is a running validator ([#1675](https://github.com/project-serum/anchor/pull/1675)). * lang: Return proper error instead of panicking if account length is smaller than discriminator in functions of `(Account)Loader` ([#1678](https://github.com/project-serum/anchor/pull/1678)). ### Breaking diff --git a/Cargo.lock b/Cargo.lock index 1799253b..81e68cd9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -163,7 +163,8 @@ dependencies = [ "flate2", "heck 0.3.3", "pathdiff", - "rand", + "portpicker", + "rand 0.7.3", "reqwest", "semver 1.0.6", "serde", @@ -171,6 +172,7 @@ dependencies = [ "shellexpand", "solana-cli-config", "solana-client", + "solana-faucet", "solana-program", "solana-sdk", "syn 1.0.88", @@ -1067,7 +1069,7 @@ checksum = "c762bae6dcaf24c4c84667b8579785430908723d5c889f469d76a41d59cc7a9d" dependencies = [ "curve25519-dalek 3.2.0", "ed25519", - "rand", + "rand 0.7.3", "serde", "serde_bytes", "sha2", @@ -1792,7 +1794,7 @@ dependencies = [ "libsecp256k1-core", "libsecp256k1-gen-ecmult", "libsecp256k1-gen-genmult", - "rand", + "rand 0.7.3", "serde", "sha2", "typenum", @@ -2260,6 +2262,15 @@ version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "58893f751c9b0412871a09abd62ecd2a00298c6c83befa223ef98c52aef40cbe" +[[package]] +name = "portpicker" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be97d76faf1bfab666e1375477b23fde79eccf0276e9b63b92a39d676a889ba9" +dependencies = [ + "rand 0.8.5", +] + [[package]] name = "ppv-lite86" version = "0.2.16" @@ -2375,11 +2386,22 @@ checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" dependencies = [ "getrandom 0.1.16", "libc", - "rand_chacha", + "rand_chacha 0.2.2", "rand_core 0.5.1", "rand_hc", ] +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha 0.3.1", + "rand_core 0.6.3", +] + [[package]] name = "rand_chacha" version = "0.2.2" @@ -2390,6 +2412,16 @@ dependencies = [ "rand_core 0.5.1", ] +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core 0.6.3", +] + [[package]] name = "rand_core" version = "0.5.1" @@ -2404,6 +2436,9 @@ name = "rand_core" version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" +dependencies = [ + "getrandom 0.2.5", +] [[package]] name = "rand_hc" @@ -2968,7 +3003,7 @@ dependencies = [ "bv", "fnv", "log", - "rand", + "rand 0.7.3", "rayon", "rustc_version 0.4.0", "serde", @@ -3082,7 +3117,7 @@ dependencies = [ "either", "lazy_static", "libc", - "rand_chacha", + "rand_chacha 0.2.2", "regex-syntax", "reqwest", "ring", @@ -3202,7 +3237,7 @@ dependencies = [ "clap 2.34.0", "log", "nix", - "rand", + "rand 0.7.3", "serde", "serde_derive", "socket2 0.3.19", @@ -3230,7 +3265,7 @@ dependencies = [ "libc", "log", "nix", - "rand", + "rand 0.7.3", "rayon", "serde", "solana-bloom", @@ -3263,7 +3298,7 @@ dependencies = [ "log", "num-derive", "num-traits", - "rand", + "rand 0.7.3", "rustc_version 0.2.3", "rustversion", "serde", @@ -3336,7 +3371,7 @@ dependencies = [ "num-traits", "num_cpus", "ouroboros", - "rand", + "rand 0.7.3", "rayon", "regex", "rustc_version 0.2.3", @@ -3395,8 +3430,8 @@ dependencies = [ "num-traits", "pbkdf2 0.6.0", "qstring", - "rand", - "rand_chacha", + "rand 0.7.3", + "rand_chacha 0.2.2", "rand_core 0.6.3", "rustc_version 0.2.3", "rustversion", @@ -3742,7 +3777,7 @@ dependencies = [ "hmac 0.8.1", "once_cell", "pbkdf2 0.4.0", - "rand", + "rand 0.7.3", "rustc-hash", "sha2", "thiserror", @@ -3887,7 +3922,7 @@ dependencies = [ "input_buffer", "log", "native-tls", - "rand", + "rand 0.7.3", "sha-1", "url", "utf-8", diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 830fc0a9..2b27bc59 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -29,6 +29,7 @@ solana-sdk = "~1.8.14" solana-program = "~1.8.14" solana-client = "~1.8.14" solana-cli-config = "~1.8.14" +solana-faucet = "~1.8.14" dirs = "3.0" heck = "0.3.1" flate2 = "1.0.19" @@ -40,3 +41,4 @@ pathdiff = "0.2.0" cargo_toml = "0.9.2" walkdir = "2" chrono = "0.4.19" +portpicker = "0.1.1" diff --git a/cli/src/config.rs b/cli/src/config.rs index 4d371172..31c9ab4b 100644 --- a/cli/src/config.rs +++ b/cli/src/config.rs @@ -574,9 +574,9 @@ pub struct Validator { // Range to use for dynamically assigned ports. [default: 1024-65535] #[serde(skip_serializing_if = "Option::is_none")] pub dynamic_port_range: Option, - // Enable the faucet on this port [deafult: 9900]. - #[serde(skip_serializing_if = "Option::is_none")] - pub faucet_port: Option, + // Enable the faucet on this port [default: 9900]. + #[serde(default = "default_faucet_port")] + pub faucet_port: u16, // Give the faucet address this much SOL in genesis. [default: 1000000] #[serde(skip_serializing_if = "Option::is_none")] pub faucet_sol: Option, @@ -614,8 +614,12 @@ fn default_bind_address() -> String { "0.0.0.0".to_string() } -fn default_rpc_port() -> u16 { - 8899 +pub fn default_rpc_port() -> u16 { + solana_sdk::rpc_port::DEFAULT_RPC_PORT +} + +pub fn default_faucet_port() -> u16 { + solana_faucet::faucet::FAUCET_PORT } #[derive(Debug, Clone)] diff --git a/cli/src/lib.rs b/cli/src/lib.rs index 2634b8cf..fdb63474 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -8,6 +8,7 @@ use anchor_lang::{AccountDeserialize, AnchorDeserialize, AnchorSerialize}; use anchor_syn::idl::Idl; use anyhow::{anyhow, Context, Result}; use clap::Parser; +use config::{default_faucet_port, default_rpc_port}; use flate2::read::GzDecoder; use flate2::read::ZlibDecoder; use flate2::write::{GzEncoder, ZlibEncoder}; @@ -2137,6 +2138,27 @@ fn start_test_validator( let rpc_url = test_validator_rpc_url(cfg); + let rpc_port = cfg + .test + .as_ref() + .and_then(|test| test.validator.as_ref().map(|v| v.rpc_port)) + .unwrap_or_else(default_rpc_port); + if !portpicker::is_free(rpc_port) { + return Err(anyhow!( + "Your configured rpc port: {rpc_port} is already in use" + )); + } + let faucet_port = cfg + .test + .as_ref() + .and_then(|test| test.validator.as_ref().map(|v| v.faucet_port)) + .unwrap_or_else(default_faucet_port); + if !portpicker::is_free(faucet_port) { + return Err(anyhow!( + "Your configured faucet port: {faucet_port} is already in use" + )); + } + let mut validator_handle = std::process::Command::new("solana-test-validator") .arg("--ledger") .arg(test_ledger_directory)