Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli-fix: anchor test with --skip-deploy should fail if validator exists already #1675

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
63 changes: 49 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -40,3 +41,4 @@ pathdiff = "0.2.0"
cargo_toml = "0.9.2"
walkdir = "2"
chrono = "0.4.19"
portpicker = "0.1.1"
14 changes: 9 additions & 5 deletions cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
// Enable the faucet on this port [deafult: 9900].
#[serde(skip_serializing_if = "Option::is_none")]
pub faucet_port: Option<u16>,
// 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<String>,
Expand Down Expand Up @@ -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)]
Expand Down
22 changes: 22 additions & 0 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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)
Expand Down