Skip to content

Commit

Permalink
feat: add more CLI related PRs (#1042)
Browse files Browse the repository at this point in the history
* Feat!(CLI): remove sandbox (#997)

* feat!: remove run_in_sandbox
* fix: reorganize tests that rely on network and ignore outside of go test
* fix: use feature instead of cfg so that cargo test --list can find tests
* fix: move common tests to single functions to skip setup time
* feat!: skip wasm in invoke
* fix: fully remove all sandbox related types and args

* fix: clippy --all (#1013)

* fix: clippy and git-hooks

* fix: split CLI tests and normal go tests so they can run concurrently

* fix(CLI): fund command now can accept a public strkey (#1020)

fixes #1014

Co-authored-by: Tsachi Herman <[email protected]>

---------

Co-authored-by: Tsachi Herman <[email protected]>
  • Loading branch information
willemneal and tsachiherman authored Oct 20, 2023
1 parent 3bde0b5 commit 3fcab5b
Show file tree
Hide file tree
Showing 45 changed files with 1,149 additions and 2,590 deletions.
3 changes: 0 additions & 3 deletions .cargo-husky/hooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,3 @@ set -e

echo '+cargo fmt --check'
cargo fmt --check || (cargo fmt && exit 1)

echo '+cargo run --bin doc-gen --features clap-markdown'
cargo run --bin doc-gen --features clap-markdown
6 changes: 5 additions & 1 deletion .cargo-husky/hooks/pre-push
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@ echo '+cargo clippy -- -Dwarnings -Dclippy::all -Dclippy::pedantic'
cargo clippy --all -- -Dwarnings

echo '+cargo test --all'
cargo test --all || (echo "might need to rebuild make build-snapshot` && exit 1)
cargo build
cargo test --all || (echo "might need to rebuild make build-snapshot" && exit 1)

echo '+cargo run --bin doc-gen --features clap-markdown'
cargo run --bin doc-gen --features clap-markdown
61 changes: 61 additions & 0 deletions .github/actions/setup-integration-tests/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: 'Set up integration tests'
description: 'Set up Go & Rust, build artifacts, work around cache issues and Ubuntu quirks'
inputs:
go-version:
required: true
runs:
using: "composite"
steps:
- uses: ./.github/actions/setup-go
with:
go-version: ${{ matrix.go }}
- uses: stellar/actions/rust-cache@main
- name: Build soroban contract fixtures
shell: bash
run: |
rustup update
rustup target add wasm32-unknown-unknown
make build_rust
make build-test-wasms
- name: Install Captive Core
shell: bash
run: |
# Workaround for https://github.com/actions/virtual-environments/issues/5245,
# libc++1-8 won't be installed if another version is installed (but apt won't give you a helpful
# message about why the installation fails)
sudo apt-get remove -y libc++1-10 libc++abi1-10 || true
sudo wget -qO - https://apt.stellar.org/SDF.asc | APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=true sudo apt-key add -
sudo bash -c 'echo "deb https://apt.stellar.org focal unstable" > /etc/apt/sources.list.d/SDF-unstable.list'
sudo apt-get update && sudo apt-get install -y stellar-core="$PROTOCOL_20_CORE_DEBIAN_PKG_VERSION"
echo "Using stellar core version $(stellar-core version)"
# Docker-compose's remote contexts on Ubuntu 20 started failing with an OpenSSL versioning error.
# See https://stackoverflow.com/questions/66579446/error-executing-docker-compose-building-webserver-unable-to-prepare-context-un
- name: Work around Docker Compose problem
shell: bash
run: |
sudo apt-get update
sudo apt-get install -y ca-certificates curl gnupg
# Install docker apt repo
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
# Install docker-compose v2 from apt repo
sudo apt-get update
sudo apt-get remove -y moby-compose
sudo apt-get install -y docker-compose-plugin
echo "Docker Compose Version:"
docker-compose version
- name: Build libpreflight
shell: bash
run: make build-libpreflight
56 changes: 5 additions & 51 deletions .github/workflows/soroban-rpc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,17 @@ jobs:

integration:
name: Integration tests
continue-on-error: true
strategy:
matrix:
os: [ubuntu-20.04]
go: [1.20.1]
test: ['.*CLI.*', '^Test(([^C])|(C[^L])|(CL[^I])).*$']
runs-on: ${{ matrix.os }}
env:
SOROBAN_RPC_INTEGRATION_TESTS_ENABLED: true
SOROBAN_RPC_INTEGRATION_TESTS_CAPTIVE_CORE_BIN: /usr/bin/stellar-core
PROTOCOL_20_CORE_DEBIAN_PKG_VERSION: 19.13.1-1481.3acf6dd26.focal
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
with:
Expand All @@ -119,57 +121,9 @@ jobs:
# We need to full history for git-restore-mtime to know what modification dates to use.
# Otherwise, the Go test cache will fail (due to the modification time of fixtures changing).
fetch-depth: "0"

- uses: ./.github/actions/setup-go
- uses: ./.github/actions/setup-integration-tests
with:
go-version: ${{ matrix.go }}
- uses: stellar/actions/rust-cache@main
- name: Build soroban contract fixtures
run: |
rustup update
rustup target add wasm32-unknown-unknown
make build_rust
make build-test-wasms
- name: Install Captive Core
run: |
# Workaround for https://github.com/actions/virtual-environments/issues/5245,
# libc++1-8 won't be installed if another version is installed (but apt won't give you a helpful
# message about why the installation fails)
sudo apt-get remove -y libc++1-10 libc++abi1-10 || true
sudo wget -qO - https://apt.stellar.org/SDF.asc | APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=true sudo apt-key add -
sudo bash -c 'echo "deb https://apt.stellar.org focal unstable" > /etc/apt/sources.list.d/SDF-unstable.list'
sudo apt-get update && sudo apt-get install -y stellar-core="$PROTOCOL_20_CORE_DEBIAN_PKG_VERSION"
echo "Using stellar core version $(stellar-core version)"
# Docker-compose's remote contexts on Ubuntu 20 started failing with an OpenSSL versioning error.
# See https://stackoverflow.com/questions/66579446/error-executing-docker-compose-building-webserver-unable-to-prepare-context-un
- name: Work around Docker Compose problem
run: |
sudo apt-get update
sudo apt-get install -y ca-certificates curl gnupg
# Install docker apt repo
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
# Install docker-compose v2 from apt repo
sudo apt-get update
sudo apt-get remove -y moby-compose
sudo apt-get install -y docker-compose-plugin
echo "Docker Compose Version:"
docker-compose version
- name: Build libpreflight
run: make build-libpreflight

- name: Run Soroban RPC Integration Tests
run: |
go test -race -timeout 25m -v ./cmd/soroban-rpc/internal/test/...
go test -race -run '${{ matrix.test }}' -timeout 60m -v ./cmd/soroban-rpc/internal/test/...
3 changes: 3 additions & 0 deletions cmd/crates/soroban-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ fs_extra = "1.3.0"
serde_json = "1.0.93"
which = { workspace = true }
tokio = "1.28.1"

[features]
integration = []
11 changes: 6 additions & 5 deletions cmd/crates/soroban-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl TestEnv {
/// ```rust,no_run
/// use soroban_test::TestEnv;
/// TestEnv::with_default(|env| {
/// env.invoke(&["--id", "1", "--", "hello", "--world=world"]).unwrap();
/// env.new_assert_cmd("contract").args(&["invoke", "--id", "1", "--", "hello", "--world=world"]).assert().success();
/// });
/// ```
///
Expand Down Expand Up @@ -122,7 +122,7 @@ impl TestEnv {
}

/// A convenience method for using the invoke command.
pub fn invoke<I: AsRef<str>>(&self, command_str: &[I]) -> Result<String, invoke::Error> {
pub async fn invoke<I: AsRef<str>>(&self, command_str: &[I]) -> Result<String, invoke::Error> {
let cmd = contract::invoke::Cmd::parse_arg_vec(
&command_str
.iter()
Expand All @@ -131,13 +131,13 @@ impl TestEnv {
.collect::<Vec<_>>(),
)
.unwrap();
self.invoke_cmd(cmd)
self.invoke_cmd(cmd).await
}

/// Invoke an already parsed invoke command
pub fn invoke_cmd(&self, mut cmd: invoke::Cmd) -> Result<String, invoke::Error> {
pub async fn invoke_cmd(&self, mut cmd: invoke::Cmd) -> Result<String, invoke::Error> {
cmd.set_pwd(self.dir());
cmd.run_in_sandbox(&global::Args {
cmd.run_against_rpc_server(&global::Args {
locator: config::locator::Args {
global: false,
config_dir: None,
Expand All @@ -148,6 +148,7 @@ impl TestEnv {
very_verbose: false,
list: false,
})
.await
}

/// Reference to current directory of the `TestEnv`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub struct Contract;

#[contractimpl]
impl Contract {
#[allow(clippy::unnecessary_fold)]
pub fn add(a: UdtEnum, b: UdtEnum) -> i64 {
let a = match a {
UdtEnum::UdtA => 0,
Expand All @@ -45,7 +46,7 @@ impl Contract {
UdtEnum::UdtA => 0,
UdtEnum::UdtB(udt) => udt.a + udt.b,
UdtEnum::UdtC(val) => val as i64,
UdtEnum::UdtD(tup) => tup.0 + tup.1.iter().fold(0i64, |sum, i| sum + i),
UdtEnum::UdtD(tup) => tup.0 + tup.1.iter().sum::<i64>(),
};
a + b
}
Expand Down
24 changes: 2 additions & 22 deletions cmd/crates/soroban-test/tests/it/config.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use assert_fs::TempDir;
use soroban_test::{temp_ledger_file, TestEnv};
use soroban_test::TestEnv;
use std::{fs, path::Path};

use crate::util::{add_identity, add_test_id, SecretKind, DEFAULT_SEED_PHRASE, HELLO_WORLD};
use crate::util::{add_identity, add_test_id, SecretKind, DEFAULT_SEED_PHRASE};
use soroban_cli::commands::config::network;

const NETWORK_PASSPHRASE: &str = "Local Sandbox Stellar Network ; September 2022";
Expand Down Expand Up @@ -205,26 +205,6 @@ fn seed_phrase() {
.stdout("test_seed\n");
}

#[test]
fn use_different_ledger_file() {
let sandbox = TestEnv::default();
sandbox
.new_assert_cmd("contract")
.arg("invoke")
.arg("--id=1")
.arg("--wasm")
.arg(HELLO_WORLD.path())
.arg("--ledger-file")
.arg(temp_ledger_file())
.arg("--")
.arg("hello")
.arg("--world=world")
.assert()
.stdout("[\"Hello\",\"world\"]\n")
.success();
assert!(fs::read(sandbox.dir().join(".soroban/ledger.json")).is_err());
}

#[test]
fn read_address() {
let sandbox = TestEnv::default();
Expand Down
Loading

0 comments on commit 3fcab5b

Please sign in to comment.