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

feat: simple IPC test #65

Merged
merged 18 commits into from
Dec 8, 2023
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
51 changes: 51 additions & 0 deletions .github/scripts/install_test_binaries.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env bash
# Installs Solc and Geth binaries
# Note: intended for use only with CI (x86_64 Ubuntu, MacOS or Windows)
set -e

GETH_BUILD=${GETH_BUILD:-"1.11.2-73b01f40"}

BIN_DIR=${BIN_DIR:-"$HOME/bin"}

PLATFORM="$(uname -s | awk '{print tolower($0)}')"
if [ "$PLATFORM" != "linux" ] && [ "$PLATFORM" != "darwin" ]; then
EXT=".exe"
fi

main() {
mkdir -p "$BIN_DIR"
cd "$BIN_DIR"
export PATH="$BIN_DIR:$PATH"
if [ "$GITHUB_PATH" ]; then
echo "$BIN_DIR" >> "$GITHUB_PATH"
fi

install_geth

echo ""
echo "Installed Geth:"
geth version
}

# Installs geth from https://geth.ethereum.org/downloads
install_geth() {
case "$PLATFORM" in
linux|darwin)
name="geth-$PLATFORM-amd64-$GETH_BUILD"
curl -s "https://gethstore.blob.core.windows.net/builds/$name.tar.gz" | tar -xzf -
mv -f "$name/geth" ./
rm -rf "$name"
chmod +x geth
;;
*)
name="geth-windows-amd64-$GETH_BUILD"
zip="$name.zip"
curl -so "$zip" "https://gethstore.blob.core.windows.net/builds/$zip"
unzip "$zip"
mv -f "$name/geth.exe" ./
rm -rf "$name" "$zip"
;;
esac
}

main
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ jobs:
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly
- name: Install test binaries
shell: bash
run: ./.github/scripts/install_test_binaries.sh
- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
Expand Down
3 changes: 3 additions & 0 deletions crates/rpc-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ alloy-primitives.workspace = true
alloy-transport-ws.workspace = true
test-log = { version = "0.2.13", default-features = false, features = ["trace"] }
tracing-subscriber = { version = "0.3.17", features = ["std", "env-filter"] }
ethers-core = "2.0.10"
alloy-transport-ipc = { workspace = true, features = ["mock"] }
tempfile = "3"

Evalir marked this conversation as resolved.
Show resolved Hide resolved
[features]
default = ["reqwest"]
Expand Down
38 changes: 38 additions & 0 deletions crates/rpc-client/tests/it/ipc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use std::borrow::Cow;

use alloy_primitives::U64;
use alloy_pubsub::PubSubFrontend;
use alloy_rpc_client::{ClientBuilder, RpcCall, RpcClient};
use alloy_transport_ipc::IpcConnect;
use ethers_core::utils::{Geth, GethInstance};
use tempfile::NamedTempFile;

async fn connect() -> (RpcClient<PubSubFrontend>, GethInstance) {
let temp_file = NamedTempFile::new().unwrap();
let path = temp_file.into_temp_path().to_path_buf();
let geth = Geth::new().block_time(1u64).ipc_path(&path).spawn();

// [Windows named pipes](https://learn.microsoft.com/en-us/windows/win32/ipc/named-pipes)
// are located at `\\<machine_address>\pipe\<pipe_name>`.
#[cfg(windows)]
let path = format!(r"\\.\pipe\{}", path.display());

let connector: IpcConnect<_> = path.into();

let client = ClientBuilder::default().pubsub(connector).await.unwrap();

(client, geth)
}

#[test_log::test(tokio::test)]
async fn it_makes_a_request() {
let (client, _geth) = connect().await;

let params: Cow<'static, _> = Cow::Owned(vec![]);

let req: RpcCall<_, Cow<'static, Vec<String>>, U64> = client.prepare("eth_blockNumber", params);

let timeout = tokio::time::timeout(std::time::Duration::from_secs(2), req);

timeout.await.unwrap().unwrap();
}
3 changes: 3 additions & 0 deletions crates/rpc-client/tests/it/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ mod http;

#[cfg(feature = "pubsub")]
mod ws;

#[cfg(feature = "pubsub")]
mod ipc;
2 changes: 1 addition & 1 deletion crates/rpc-types/src/eth/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ impl FilteredParams {
}

/// Returns `true` if the bloom matches the topics
pub fn matches_topics(bloom: Bloom, topic_filters: &Vec<BloomFilter>) -> bool {
pub fn matches_topics(bloom: Bloom, topic_filters: &[BloomFilter]) -> bool {
if topic_filters.is_empty() {
return true;
}
Expand Down