Skip to content

Commit

Permalink
fix: test in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
chris13524 committed Oct 8, 2024
1 parent 0eb0faa commit bca00fc
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 69 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/event_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,35 @@ jobs:
check-udeps: false
rust-toolchain: stable

test_bundler:
name: Test with mock bundler
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Run sccache-cache
uses: mozilla-actions/[email protected]
- run: rustup update stable && rustup default stable
- run: cd irn && docker compose up -d
- run: docker compose up -d redis postgres
- run: docker compose -f docker-compose.mock-bundler.yaml up -d
working-directory: test/scripts/forked_state
- run: while ! curl localhost:5432/health; do sleep 1; done # Postgres
- run: while ! curl localhost:6379/health; do sleep 1; done # Redis
- run: while ! curl localhost:8545/health; do sleep 1; done # Anvil
- run: while ! curl localhost:4337/health; do sleep 1; done # Mock Bundler
- run: while ! curl localhost:3000/ping; do sleep 1; done # Mock Paymaster
- run: cargo test --features=test-mock-bundler --lib --bins
env:
RPC_PROXY_POSTGRES_URI: "postgres://postgres@localhost/postgres"
RPC_PROXY_PROVIDER_INFURA_PROJECT_ID: ""
RPC_PROXY_PROVIDER_POKT_PROJECT_ID: ""
RPC_PROXY_PROVIDER_QUICKNODE_API_TOKENS: ""
RPC_PROXY_PROVIDER_PIMLICO_API_KEY: ""
RPC_PROXY_PROVIDER_SOLSCAN_API_V1_TOKEN: ""
RPC_PROXY_PROVIDER_SOLSCAN_API_V2_TOKEN: ""

merge_check:
name: Merge Check
needs: [ check_pr, ci ]
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ vergen = { version = "6", default-features = false, features = ["build", "cargo"
[features]
full = []
test-localhost = []
test-mock-bundler = []

[profile.release-debug]
inherits = "release"
Expand Down
23 changes: 23 additions & 0 deletions docker-compose.mock-bundler.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
services:
anvil:
image: ghcr.io/foundry-rs/foundry:nightly-96105b4d240681c336e063eac0e250cc51a84414
restart: unless-stopped
ports: ["8545:8545"]
entrypoint: [ "anvil", "--fork-url", "https://gateway.tenderly.co/public/sepolia", "--host", "0.0.0.0", "--block-time", "0.1", "--gas-price", "1", "--silent", "--hardfork", "prague" ]
platform: linux/amd64

mock-paymaster:
image: ghcr.io/pimlicolabs/mock-verifying-paymaster:main
restart: unless-stopped
ports: ["3000:3000"]
environment:
- ALTO_RPC=http://alto:4337
- ANVIL_RPC=http://anvil:8545

alto:
image: ghcr.io/pimlicolabs/mock-alto-bundler:main
restart: unless-stopped
ports: ["4337:4337"]
environment:
- ANVIL_RPC=http://anvil:8545
- SKIP_DEPLOYMENTS=true
109 changes: 40 additions & 69 deletions src/handlers/wallet/get_calls_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,19 +173,34 @@ fn user_operation_receipt_to_call_receipt(
mod self_transport {
use {
crate::{
handlers::RpcQueryParams, json_rpc::JSON_RPC_VERSION, providers::SupportedBundlerOps,
state::AppState,
error::RpcError, handlers::RpcQueryParams, json_rpc::JSON_RPC_VERSION,
providers::SupportedBundlerOps, state::AppState,
},
alloy::{
rpc::json_rpc::{RequestPacket, Response, ResponsePacket},
transports::{TransportError, TransportFut},
transports::{TransportError, TransportErrorKind, TransportFut},
},
hyper::HeaderMap,
std::{net::SocketAddr, sync::Arc, task::Poll},
tower::Service,
yttrium::chain::ChainId,
};

#[derive(thiserror::Error, Debug)]
pub enum SelfBundlerTransportError {
#[error("RPC error: {0}")]
Rpc(RpcError),

#[error("Parse params: {0}")]
ParseParams(serde_json::Error),

#[error("No result")]
NoResult,

#[error("Parse result: {0}")]
ParseResult(serde_json::Error),
}

#[derive(Clone)]
pub struct SelfBundlerTransport {
pub state: Arc<AppState>,
Expand Down Expand Up @@ -221,27 +236,17 @@ mod self_transport {
RequestPacket::Batch(_) => unimplemented!(),
};

let method_result =
serde_json::from_value::<SupportedBundlerOps>(serde_json::json!(req.method()));
// let method = match method_result {
// Ok(m) => m,
// Err(_) => {
// return Ok(ResponsePacket::Single(Response {
// id: req.id().clone(),
// payload: alloy::rpc::json_rpc::ResponsePayload::Failure(
// serde_json::value::RawValue::from_string(
// serde_json::json!({
// "code": -32601,
// "message": "Method not found",
// })
// .to_string(),
// )
// .unwrap(),
// ),
// }));
// }
// };
let method = method_result.unwrap();
let method =
serde_json::from_value::<SupportedBundlerOps>(serde_json::json!(req.method()))
.map_err(|_| TransportErrorKind::custom_str("Unsupported method"))?;
let params = serde_json::from_str(
req.params()
.ok_or_else(|| TransportErrorKind::custom_str("Params is null"))?
.get(),
)
.map_err(|e| {
TransportErrorKind::custom(SelfBundlerTransportError::ParseParams(e))
})?;

let response = state
.providers
Expand All @@ -251,53 +256,17 @@ mod self_transport {
req.id().clone(),
JSON_RPC_VERSION.clone(),
&method,
serde_json::from_str(req.params().unwrap().get()).unwrap(),
params,
)
.await
.unwrap(); // TODO remove
let body = serde_json::to_string(response.get("result").unwrap()).unwrap();

// TODO handle error response status
// if response.status() != StatusCode::OK {
// return Err(SelfProviderError::ProviderError {
// status: response.status(),
// body: format!("{:?}", response.body()),
// });
// }
// response.body().

// let bytes = to_bytes(response.into_body()).await.unwrap();
// .map_err(SelfProviderError::ProviderBody)?;

// let body = String::from_utf8(bytes.to_vec()).unwrap();
// let response = serde_json::from_slice::<JsonRpcResponse>(&bytes)
// .unwrap();
// // .map_err(SelfProviderError::ProviderBodySerde)?;

// let result = match response {
// JsonRpcResponse::Error(e) => return
// Err(SelfProviderError::JsonRpcError(e)),
// JsonRpcResponse::Result(r) => {
// // We shouldn't process with `0x` result because this leads to the
// ethers-rs // panic when looking for an avatar
// if r.result == EMPTY_RPC_RESPONSE {
// return Err(SelfProviderError::ProviderError {
// status: StatusCode::METHOD_NOT_ALLOWED,
// body: format!("JSON-RPC result is {}", EMPTY_RPC_RESPONSE),
// });
// } else {
// r.result
// }
// }
// };

// let result = serde_json::from_value(result).unwrap();
// // .map_err(|_| {
// // SelfProviderError::GenericParameterError(
// // "Caller always provides generic parameter R=Bytes".into(),
// // )
// // })?;
// Ok(result)
.map_err(|e| TransportErrorKind::custom(SelfBundlerTransportError::Rpc(e)))?;
// TODO check for error
let body = serde_json::to_string(response.get("result").ok_or_else(|| {
TransportErrorKind::custom(SelfBundlerTransportError::NoResult)
})?)
.map_err(|e| {
TransportErrorKind::custom(SelfBundlerTransportError::ParseResult(e))
})?;

Ok(ResponsePacket::Single(Response {
id: req.id().clone(),
Expand All @@ -315,6 +284,7 @@ mod self_transport {
// - what about missing Option in alloy's getUserOperationReceipt

#[cfg(test)]
#[cfg(feature = "test-mock-bundler")]
mod tests {
use crate::{
handlers::wallet::{
Expand Down Expand Up @@ -414,6 +384,7 @@ mod tests {
}

#[tokio::test]
#[ignore]
async fn test_get_calls_status_failed() {
// let anvil = Anvil::new().spawn();
let config = Config::local();
Expand Down

0 comments on commit bca00fc

Please sign in to comment.