Skip to content
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
29 changes: 29 additions & 0 deletions .github/actions/setup-surfpool/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: "Setup Surfpool"
description: "Installs and caches the Surfpool CLI"
runs:
using: "composite"
steps:
- uses: actions/cache@v3
name: Cache Surfpool Binary
id: cache-surfpool
with:
path: /usr/local/bin/surfpool
key: surfpool-${{ runner.os }}-v${{ env.SURFPOOL_CLI_VERSION }}

- uses: nick-fields/retry@v2
if: steps.cache-surfpool.outputs.cache-hit != 'true'
with:
retry_wait_seconds: 300
timeout_minutes: 2
max_attempts: 10
retry_on: error
shell: bash
command: |
echo "Installing Surfpool version ${{ env.SURFPOOL_CLI_VERSION }}"
curl -sL https://run.surfpool.run/ | bash
echo "$HOME/.local/bin" >> $GITHUB_PATH
echo "$PATH"
ls -al $HOME/.local/bin

1 change: 1 addition & 0 deletions .github/workflows/no-caching-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ jobs:
node_version: 20.18.0
cargo_profile: release
anchor_binary_name: anchor-binary-no-caching
surfpool_cli_version: 0.11.2
13 changes: 11 additions & 2 deletions .github/workflows/reusable-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,16 @@ on:
anchor_binary_name:
required: true
type: string
surfpool_cli_version:
required: true
type: string
env:
CACHE: ${{ inputs.cache }}
SOLANA_CLI_VERSION: ${{ inputs.solana_cli_version }}
NODE_VERSION: ${{ inputs.node_version }}
CARGO_PROFILE: ${{ inputs.cargo_profile }}
ANCHOR_BINARY_NAME: ${{ inputs.anchor_binary_name }}
SURFPOOL_CLI_VERSION: ${{ inputs.surfpool_cli_version }}
CARGO_CACHE_PATH: |
~/.cargo/bin/
~/.cargo/registry/index/
Expand Down Expand Up @@ -111,6 +115,7 @@ jobs:
- uses: ./.github/actions/setup/
- uses: ./.github/actions/setup-solana/
- uses: ./.github/actions/setup-ts/
- uses: ./.github/actions/setup-surfpool/

- uses: actions/cache@v3
if: ${{ env.CACHE != 'false' }}
Expand Down Expand Up @@ -236,6 +241,7 @@ jobs:
path: client/example/target
key: cargo-${{ runner.os }}-client/example-${{ env.ANCHOR_VERSION }}-${{ env.SOLANA_CLI_VERSION }}-${{ hashFiles('**/Cargo.lock') }}
- uses: ./.github/actions/setup-solana/
- uses: ./.github/actions/setup-surfpool/
- run: cd client/example && ./run-test.sh
- uses: ./.github/actions/git-diff/

Expand All @@ -249,6 +255,7 @@ jobs:
- uses: ./.github/actions/setup/
- uses: ./.github/actions/setup-ts/
- uses: ./.github/actions/setup-solana/
- uses: ./.github/actions/setup-surfpool/

- uses: actions/cache@v3
if: ${{ env.CACHE != 'false' }}
Expand All @@ -272,8 +279,8 @@ jobs:
path: tests/bpf-upgradeable-state/target
key: cargo-${{ runner.os }}-tests/bpf-upgradeable-state-${{ env.ANCHOR_VERSION }}-${{ env.SOLANA_CLI_VERSION }}-${{ hashFiles('**/Cargo.lock') }}

- run: solana-test-validator -r --quiet &
name: start validator
- run: surfpool start --ci --offline &
name: start surfpool
- run: cd tests/bpf-upgradeable-state && yarn --frozen-lockfile
- run: cd tests/bpf-upgradeable-state
- run: cd tests/bpf-upgradeable-state && anchor build --skip-lint --ignore-keys
Expand Down Expand Up @@ -346,6 +353,7 @@ jobs:
- uses: ./.github/actions/setup/
- uses: ./.github/actions/setup-ts/
- uses: ./.github/actions/setup-solana/
- uses: ./.github/actions/setup-surfpool/

- uses: actions/cache@v3
if: ${{ env.CACHE != 'false' }}
Expand Down Expand Up @@ -473,6 +481,7 @@ jobs:
- uses: ./.github/actions/setup/
- uses: ./.github/actions/setup-ts/
- uses: ./.github/actions/setup-solana/
- uses: ./.github/actions/setup-surfpool/

- uses: actions/cache@v3
if: ${{ env.CACHE != 'false' }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ jobs:
node_version: 20.18.0
cargo_profile: debug
anchor_binary_name: anchor-binary
surfpool_cli_version: 0.11.2
117 changes: 117 additions & 0 deletions cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use std::str::FromStr;
use std::{fmt, io};
use walkdir::WalkDir;

pub const SURFPOOL_HOST: &str = "127.0.0.1";
/// Wrapper around CommitmentLevel to support case-insensitive parsing
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct CaseInsensitiveCommitmentLevel(pub CommitmentLevel);
Expand Down Expand Up @@ -328,10 +329,19 @@ pub struct Config {
// Separate entry next to test_config because
// "anchor localnet" only has access to the Anchor.toml,
// not the Test.toml files
pub validator: Option<ValidatorType>,
pub test_validator: Option<TestValidator>,
pub test_config: Option<TestConfig>,
pub surfpool_config: Option<SurfpoolConfig>,
}

#[derive(ValueEnum, Parser, Clone, Copy, PartialEq, Eq, Debug)]
pub enum ValidatorType {
/// Use Surfpool validator (default)
Surfpool,
/// Use Solana test validator
Legacy,
}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct ToolchainConfig {
pub anchor_version: Option<String>,
Expand Down Expand Up @@ -618,6 +628,7 @@ struct _Config {
scripts: Option<ScriptsConfig>,
hooks: Option<HooksConfig>,
test: Option<_TestValidator>,
surfpool: Option<_SurfpoolConfig>,
}

#[derive(Debug, Serialize, Deserialize)]
Expand Down Expand Up @@ -719,6 +730,7 @@ impl fmt::Display for Config {
programs,
workspace: (!self.workspace.members.is_empty() || !self.workspace.exclude.is_empty())
.then(|| self.workspace.clone()),
surfpool: self.surfpool_config.clone().map(Into::into),
};

let cfg = toml::to_string(&cfg).expect("Must be well formed");
Expand All @@ -742,10 +754,12 @@ impl FromStr for Config {
},
scripts: cfg.scripts.unwrap_or_default(),
hooks: cfg.hooks.unwrap_or_default(),
validator: None, // Will be set based on CLI flags
test_validator: cfg.test.map(Into::into),
test_config: None,
programs: cfg.programs.map_or(Ok(BTreeMap::new()), deser_programs)?,
workspace: cfg.workspace.unwrap_or_default(),
surfpool_config: cfg.surfpool.map(Into::into),
})
}
}
Expand Down Expand Up @@ -830,6 +844,23 @@ pub struct TestValidator {
pub upgradeable: bool,
}

#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct SurfpoolConfig {
pub startup_wait: i32,
pub shutdown_wait: i32,
pub rpc_port: u16,
pub ws_port: Option<u16>,
pub host: String,
pub online: Option<bool>,
pub datasource_rpc_url: Option<String>,
pub airdrop_addresses: Option<Vec<String>>,
pub manifest_file_path: Option<String>,
pub runbooks: Option<Vec<String>>,
pub slot_time: Option<u16>,
pub log_level: Option<String>,
pub block_production_mode: Option<String>,
}

#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct _TestValidator {
#[serde(skip_serializing_if = "Option::is_none")]
Expand All @@ -844,6 +875,75 @@ pub struct _TestValidator {
pub upgradeable: Option<bool>,
}

#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct _SurfpoolConfig {
#[serde(skip_serializing_if = "Option::is_none")]
pub startup_wait: Option<i32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub shutdown_wait: Option<i32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub rpc_port: Option<u16>,
#[serde(skip_serializing_if = "Option::is_none")]
pub ws_port: Option<u16>,
#[serde(skip_serializing_if = "Option::is_none")]
pub host: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub online: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub datasource_rpc_url: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub airdrop_addresses: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub manifest_file_path: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub runbooks: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub slot_time: Option<u16>,
#[serde(skip_serializing_if = "Option::is_none")]
pub log_level: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub block_production_mode: Option<String>,
}

impl From<_SurfpoolConfig> for SurfpoolConfig {
fn from(_surfpool_config: _SurfpoolConfig) -> Self {
Self {
startup_wait: _surfpool_config.startup_wait.unwrap_or(STARTUP_WAIT),
shutdown_wait: _surfpool_config.shutdown_wait.unwrap_or(SHUTDOWN_WAIT),
rpc_port: _surfpool_config.rpc_port.unwrap_or(DEFAULT_RPC_PORT),
host: _surfpool_config.host.unwrap_or(SURFPOOL_HOST.to_string()),
ws_port: _surfpool_config.ws_port,
online: _surfpool_config.online,
datasource_rpc_url: _surfpool_config.datasource_rpc_url,
airdrop_addresses: _surfpool_config.airdrop_addresses,
manifest_file_path: _surfpool_config.manifest_file_path,
runbooks: _surfpool_config.runbooks,
slot_time: _surfpool_config.slot_time,
log_level: _surfpool_config.log_level,
block_production_mode: _surfpool_config.block_production_mode,
}
}
}

impl From<SurfpoolConfig> for _SurfpoolConfig {
fn from(surfpool_config: SurfpoolConfig) -> Self {
Self {
startup_wait: Some(surfpool_config.startup_wait),
shutdown_wait: Some(surfpool_config.shutdown_wait),
rpc_port: Some(surfpool_config.rpc_port),
ws_port: surfpool_config.ws_port,
host: Some(surfpool_config.host),
online: surfpool_config.online,
datasource_rpc_url: surfpool_config.datasource_rpc_url,
airdrop_addresses: surfpool_config.airdrop_addresses,
manifest_file_path: surfpool_config.manifest_file_path,
runbooks: surfpool_config.runbooks,
slot_time: surfpool_config.slot_time,
log_level: surfpool_config.log_level,
block_production_mode: surfpool_config.block_production_mode,
}
}
}
pub const STARTUP_WAIT: i32 = 5000;
pub const SHUTDOWN_WAIT: i32 = 2000;

Expand Down Expand Up @@ -1461,6 +1561,23 @@ impl AnchorPackage {
}
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SurfnetInfoResponse {
pub runbook_executions: Vec<RunbookExecution>,
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RunbookExecution {
#[serde(rename = "startedAt")]
pub started_at: u32,
#[serde(rename = "completedAt")]
pub completed_at: Option<u32>,
#[serde(rename = "runbookId")]
pub runbook_id: String,
pub errors: Option<Vec<String>>,
}

#[macro_export]
macro_rules! home_path {
($my_struct:ident, $path:literal) => {
Expand Down
Loading
Loading