Skip to content

Commit

Permalink
Merge branch 'main' into fix/1014
Browse files Browse the repository at this point in the history
  • Loading branch information
tsachiherman authored Oct 16, 2023
2 parents 455d1ca + 2d9caec commit 914fc3d
Show file tree
Hide file tree
Showing 20 changed files with 225 additions and 165 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/...
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
target/
captive-core/
.soroban/
!test.toml
*.sqlite

cmd/crates/soroban-spec-typescript/fixtures/ts/package-lock.json
16 changes: 4 additions & 12 deletions cmd/crates/soroban-test/tests/fixtures/test-jsons/get-events.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
"AAAABQAAAAdDT1VOVEVSAA==",
"AAAABQAAAAlpbmNyZW1lbnQAAAA="
],
"value": {
"xdr": "AAAAAQAAAAE="
}
"value": "AAAAAQAAAAE="
},
{
"type": "system",
Expand All @@ -27,9 +25,7 @@
"AAAABQAAAAh0cmFuc2Zlcg==",
"AAAAAQB6Mcc="
],
"value": {
"xdr": "AAAABQAAAApHaWJNb255UGxzAAA="
}
"value": "AAAABQAAAApHaWJNb255UGxzAAA="
},
{
"type": "contract",
Expand All @@ -42,9 +38,7 @@
"AAAABQAAAAh0cmFuc2Zlcg==",
"AAAAAQB6Mcc="
],
"value": {
"xdr": "AAAABQAAAApHaWJNb255UGxzAAA="
}
"value": "AAAABQAAAApHaWJNb255UGxzAAA="
},
{
"type": "system",
Expand All @@ -57,9 +51,7 @@
"AAAABQAAAAh0cmFuc2Zlcg==",
"AAAAAQB6Mcc="
],
"value": {
"xdr": "AAAABQAAAApHaWJNb255UGxzAAA="
}
"value": "AAAABQAAAApHaWJNb255UGxzAAA="
}
]
}
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
19 changes: 10 additions & 9 deletions cmd/soroban-cli/src/commands/config/events_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use std::{
fs,
path::{Path, PathBuf},
};
use stellar_strkey::{Contract, Strkey};

#[derive(Debug, clap::Args, Clone, Default)]
#[group(skip)]
Expand Down Expand Up @@ -136,19 +137,19 @@ impl Args {
id,
ledger: ledger_info.sequence_number.to_string(),
ledger_closed_at: dt.format("%Y-%m-%dT%H:%M:%SZ").to_string(),
contract_id: hex::encode(
contract_id: Strkey::Contract(Contract(
contract_event
.contract_id
.as_ref()
.unwrap_or(&xdr::Hash([0; 32])),
),
.unwrap_or(&xdr::Hash([0; 32]))
.0,
))
.to_string(),
topic,
value: rpc::EventValue {
xdr: match &contract_event.body {
xdr::ContractEventBody::V0(e) => &e.data,
}
.to_xdr_base64()?,
},
value: match &contract_event.body {
xdr::ContractEventBody::V0(e) => &e.data,
}
.to_xdr_base64()?,
};

events.push(cereal_event);
Expand Down
14 changes: 10 additions & 4 deletions cmd/soroban-cli/src/commands/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ pub struct Cmd {
count: usize,

/// A set of (up to 5) contract IDs to filter events on. This parameter can
/// be passed multiple times, e.g. `--id abc --id def`, or passed with
/// multiple parameters, e.g. `--id abd def`.
/// be passed multiple times, e.g. `--id C123.. --id C456..`, or passed with
/// multiple parameters, e.g. `--id C123 C456`.
///
/// Though the specification supports multiple filter objects (i.e.
/// combinations of type, IDs, and topics), only one set can be specified on
Expand Down Expand Up @@ -352,8 +352,14 @@ mod tests {
assert_eq!(file.events.len(), 2);
assert_eq!(file.events[0].ledger, "2");
assert_eq!(file.events[1].ledger, "2");
assert_eq!(file.events[0].contract_id, "0".repeat(64));
assert_eq!(file.events[1].contract_id, "01".repeat(32));
assert_eq!(
file.events[0].contract_id,
"CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABSC4"
);
assert_eq!(
file.events[1].contract_id,
"CAAQCAIBAEAQCAIBAEAQCAIBAEAQCAIBAEAQCAIBAEAQCAIBAEAQC526"
);
assert_eq!(file.latest_ledger, 2);
}

Expand Down
21 changes: 6 additions & 15 deletions cmd/soroban-cli/src/rpc/fixtures/event_response.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,30 @@
"AAAABQAAAAh0cmFuc2Zlcg==",
"AAAAAQB6Mcc="
],
"value": {
"xdr": "AAAABQAAAApHaWJNb255UGxzAAA="
}
"value": "AAAABQAAAApHaWJNb255UGxzAAA="
}, {
"eventType": "contract",
"ledger": "43601284",
"ledgerClosedAt": "2022-11-16T16:10:41Z",
"contractId": "CDR6QKTWZQYW6YUJ7UP7XXZRLWQPFRV6SWBLQS4ZQOSAF4BOUD77OO5Z"
,
"contractId": "CDR6QKTWZQYW6YUJ7UP7XXZRLWQPFRV6SWBLQS4ZQOSAF4BOUD77OO5Z",
"id": "0164090849041387521-0000000003",
"pagingToken": "164090849041387521-3",
"topic": [
"AAAABQAAAAh0cmFuc2Zlcg==",
"AAAAAQB6Mcc="
],
"value": {
"xdr": "AAAABQAAAApHaWJNb255UGxzAAA="
}
"value": "AAAABQAAAApHaWJNb255UGxzAAA="
}, {
"eventType": "system",
"ledger": "43601285",
"ledgerClosedAt": "2022-11-16T16:10:41Z",
"contractId": "CCR6QKTWZQYW6YUJ7UP7XXZRLWQPFRV6SWBLQS4ZQOSAF4BOUD77OTE2"
,
"contractId": "CCR6QKTWZQYW6YUJ7UP7XXZRLWQPFRV6SWBLQS4ZQOSAF4BOUD77OTE2",
"id": "0164090849041387521-0000000003",
"pagingToken": "164090849041387521-3",
"topic": [
"AAAABQAAAAh0cmFuc2Zlcg==",
"AAAAAQB6Mcc="
],
"value": {
"xdr": "AAAABQAAAApHaWJNb255UGxzAAA="
}
}
]
"value": "AAAABQAAAApHaWJNb255UGxzAAA="
}]
}
13 changes: 4 additions & 9 deletions cmd/soroban-cli/src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ pub struct Event {
#[serde(rename = "contractId")]
pub contract_id: String,
pub topic: Vec<String>,
pub value: EventValue,
pub value: String,
}

impl Display for Event {
Expand All @@ -338,7 +338,7 @@ impl Display for Event {
let scval = xdr::ScVal::from_xdr_base64(topic).map_err(|_| std::fmt::Error)?;
writeln!(f, " {scval:?}")?;
}
let scval = xdr::ScVal::from_xdr_base64(&self.value.xdr).map_err(|_| std::fmt::Error)?;
let scval = xdr::ScVal::from_xdr_base64(&self.value).map_err(|_| std::fmt::Error)?;
writeln!(f, " Value: {scval:?}")
}
}
Expand Down Expand Up @@ -386,7 +386,7 @@ impl Event {

colored!(
stdout,
" Contract: {}0x{}{}\n",
" Contract: {}{}{}\n",
fg!(Some(Color::Green)),
self.contract_id,
reset!(),
Expand All @@ -404,7 +404,7 @@ impl Event {
)?;
}

let scval = xdr::ScVal::from_xdr_base64(&self.value.xdr)?;
let scval = xdr::ScVal::from_xdr_base64(&self.value)?;
colored!(
stdout,
" Value: {}{:?}{}\n",
Expand All @@ -417,11 +417,6 @@ impl Event {
}
}

#[derive(serde::Deserialize, serde::Serialize, Debug, Clone)]
pub struct EventValue {
pub xdr: String,
}

#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, clap::ValueEnum)]
pub enum EventType {
All,
Expand Down
Loading

0 comments on commit 914fc3d

Please sign in to comment.