Skip to content
Closed
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
1,016 changes: 558 additions & 458 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ ic-http-types = { workspace = true }
ic-metrics-encoder = { workspace = true }
ic-stable-structures = { workspace = true }
ic-cdk = { workspace = true }
ic-cdk-macros = { workspace = true }
ic-management-canister-types = { workspace = true }
maplit = { workspace = true }
minicbor = { workspace = true }
Expand Down Expand Up @@ -75,7 +74,7 @@ alloy-rpc-types = "1.0.23"
assert_matches = "1.5.0"
async-trait = "0.1.88"
candid = { version = "0.10.13" }
canhttp = { version = "0.2.0", features = ["json", "multi"] }
canhttp = { version = "0.3.0", features = ["json", "multi"] }
canlog = { version = "0.2.0", features = ["derive"] }
candid_parser = { version = "0.1.4" }
derive_more = { version = "2.0.1", features = ["from", "into"] }
Expand All @@ -84,7 +83,7 @@ ethnum = { version = "1.5.0", features = ["serde"] }
getrandom = { version = "0.2", features = ["custom"] }
hex = "0.4.3"
http = "1.3.1"
ic-cdk = "0.17.2"
ic-cdk = "0.18.7"
ic-cdk-bindgen = "0.1"
ic-cdk-macros = "0.17.2"
ic-certified-map = "0.4"
Expand Down
2 changes: 1 addition & 1 deletion e2e/motoko/main.mo
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ shared ({ caller = installer }) persistent actor class Main() {

// (`subnet name`, `nodes in subnet`, `expected cycles for JSON-RPC call`)
type SubnetTarget = (Text, Nat32, Nat);
transient let fiduciarySubnet : SubnetTarget = ("fiduciary", 34, 540_545_600);
transient let fiduciarySubnet : SubnetTarget = ("fiduciary", 34, 400_299_200);

transient let testTargets = [
// (`canister module`, `canister type`, `subnet`)
Expand Down
56 changes: 30 additions & 26 deletions e2e/rust/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use std::str::FromStr;

use candid::{candid_method, Principal};
use ic_cdk_macros::update;

use evm_rpc_types::{
Block, BlockTag, ConsensusStrategy, EthMainnetService, Hex32, MultiRpcResult, ProviderError,
RpcConfig, RpcError, RpcResult, RpcService, RpcServices,
};
use ic_cdk::{call::Call, update};
use std::str::FromStr;

fn main() {}

Expand All @@ -21,7 +19,7 @@ const CANISTER_ID: Option<&str> = None;
#[update]
#[candid_method(update)]
pub async fn test() {
assert!(ic_cdk::api::is_controller(&ic_cdk::caller()));
assert!(ic_cdk::api::is_controller(&ic_cdk::api::msg_caller()));

let canister_id = Principal::from_str(CANISTER_ID.unwrap())
.expect("Error parsing canister ID environment variable");
Expand All @@ -34,18 +32,22 @@ pub async fn test() {
);

// Get cycles cost
let (cycles_result,): (Result<u128, RpcError>,) =
ic_cdk::api::call::call(canister_id, "requestCost", params.clone())
.await
.unwrap();
let cycles_result = Call::unbounded_wait(canister_id, "requestCost")
.with_args(&params)
.await
.unwrap()
.candid::<Result<u128, RpcError>>()
.unwrap();
let cycles = cycles_result
.unwrap_or_else(|e| ic_cdk::trap(&format!("error in `request_cost`: {:?}", e)));

// Call without sending cycles
let (result_without_cycles,): (Result<String, RpcError>,) =
ic_cdk::api::call::call(canister_id, "request", params.clone())
.await
.unwrap();
let result_without_cycles = Call::unbounded_wait(canister_id, "request")
.with_args(&params)
.await
.unwrap()
.candid::<Result<String, RpcError>>()
.unwrap();
match result_without_cycles {
Ok(s) => ic_cdk::trap(&format!("response from `request` without cycles: {:?}", s)),
Err(RpcError::ProviderError(ProviderError::TooFewCycles { expected, .. })) => {
Expand All @@ -55,10 +57,13 @@ pub async fn test() {
}

// Call with expected number of cycles
let (result,): (Result<String, RpcError>,) =
ic_cdk::api::call::call_with_payment128(canister_id, "request", params, cycles)
.await
.unwrap();
let result: Result<String, RpcError> = Call::unbounded_wait(canister_id, "request")
.with_args(&params)
.with_cycles(cycles)
.await
.unwrap()
.candid::<Result<String, RpcError>>()
.unwrap();
match result {
Ok(response) => {
// Check response structure around gas price
Expand All @@ -72,10 +77,8 @@ pub async fn test() {
}

// Call a Candid-RPC method
let (results,): (MultiRpcResult<Block>,) = ic_cdk::api::call::call_with_payment128(
canister_id,
"eth_getBlockByNumber",
(
let results = Call::unbounded_wait(canister_id, "eth_getBlockByNumber")
.with_args(&(
RpcServices::EthMainnet(Some(vec![
// EthMainnetService::Ankr, // Need API key
EthMainnetService::BlockPi,
Expand All @@ -90,11 +93,12 @@ pub async fn test() {
..Default::default()
}),
BlockTag::Number(19709434_u32.into()),
),
10000000000,
)
.await
.unwrap();
))
.with_cycles(10000000000)
.await
.unwrap()
.candid::<MultiRpcResult<Block>>()
.unwrap();
match results {
MultiRpcResult::Consistent(result) => match result {
Ok(block) => {
Expand Down
25 changes: 25 additions & 0 deletions evm_rpc_client/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,29 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.4.0] - 2025-10-20

### Added

- Add methods to modify RPC config to `RequestBuilder` ([#494](https://github.com/dfinity/evm-rpc-canister/pull/494))
- Add `alloy` feature flag to `evm_rpc_client` ([#484](https://github.com/dfinity/evm-rpc-canister/pull/484))
- Add new `json_request` endpoint ([#477](https://github.com/dfinity/evm-rpc-canister/pull/477))
- Add client support for `eth_getTransactionReceipt` ([#476](https://github.com/dfinity/evm-rpc-canister/pull/476))
- Add `eth_sendRawTransaction` client support ([#467](https://github.com/dfinity/evm-rpc-canister/pull/467))
- Add client support for `eth_call` ([#466](https://github.com/dfinity/evm-rpc-canister/pull/466))
- Add client support for `eth_getTransactionCount` ([#465](https://github.com/dfinity/evm-rpc-canister/pull/465))
- Add support for `eth_feeHistory` to client ([#460](https://github.com/dfinity/evm-rpc-canister/pull/460))
- Add support for `eth_getBlockByNumber` to client ([#459](https://github.com/dfinity/evm-rpc-canister/pull/459))
- Add EVM RPC canister client ([#447](https://github.com/dfinity/evm-rpc-canister/pull/447))

### Changed

- Increase `IcError` granularity
- Merge branch 'main' into lpahlavi/XC-502-update-ic-cdk

### Fixed

- Client integration test infrastructure ([#448](https://github.com/dfinity/evm-rpc-canister/pull/448))


## [Unreleased]
3 changes: 2 additions & 1 deletion evm_rpc_client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ ic-error-types = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
strum = { workspace = true }
thiserror = { workspace = true }

[dev-dependencies]
alloy-dyn-abi = { workspace = true }
Expand All @@ -30,4 +31,4 @@ evm_rpc_types = { path = "../evm_rpc_types", features = ["alloy"] }
tokio = { workspace = true, features = ["full"] }

[features]
alloy = ["evm_rpc_types/alloy", "dep:alloy-primitives", "dep:alloy-rpc-types"]
alloy = ["evm_rpc_types/alloy", "dep:alloy-primitives", "dep:alloy-rpc-types"]
9 changes: 4 additions & 5 deletions evm_rpc_client/src/fixtures/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
//!
//! Types and methods for this module are only available for non-canister architecture (non `wasm32`).

use crate::{ClientBuilder, Runtime};
use crate::{ClientBuilder, IcError, Runtime};
use async_trait::async_trait;
use candid::{utils::ArgumentEncoder, CandidType, Decode, Encode, Principal};
use ic_error_types::RejectCode;
use serde::de::DeserializeOwned;
use std::collections::BTreeMap;

Expand Down Expand Up @@ -82,7 +81,7 @@ impl StubRuntime {
self
}

fn call<Out>(&self, method: &str) -> Result<Out, (RejectCode, String)>
fn call<Out>(&self, method: &str) -> Result<Out, IcError>
where
Out: CandidType + DeserializeOwned,
{
Expand All @@ -109,7 +108,7 @@ impl Runtime for StubRuntime {
method: &str,
_args: In,
_cycles: u128,
) -> Result<Out, (RejectCode, String)>
) -> Result<Out, IcError>
where
In: ArgumentEncoder + Send,
Out: CandidType + DeserializeOwned,
Expand All @@ -122,7 +121,7 @@ impl Runtime for StubRuntime {
_id: Principal,
method: &str,
_args: In,
) -> Result<Out, (RejectCode, String)>
) -> Result<Out, IcError>
where
In: ArgumentEncoder + Send,
Out: CandidType + DeserializeOwned,
Expand Down
5 changes: 2 additions & 3 deletions evm_rpc_client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ use evm_rpc_types::{
BlockTag, CallArgs, ConsensusStrategy, FeeHistoryArgs, GetLogsArgs, GetTransactionCountArgs,
Hex, Hex32, RpcConfig, RpcServices,
};
use ic_error_types::RejectCode;
#[cfg(feature = "alloy")]
pub use request::alloy::AlloyResponseConverter;
use request::{
Expand All @@ -139,7 +138,7 @@ use request::{
SendRawTransactionRequest, SendRawTransactionRequestBuilder,
};
pub use request::{CandidResponseConverter, EvmRpcConfig};
pub use runtime::{IcRuntime, Runtime};
pub use runtime::{IcError, IcRuntime, Runtime};
use serde::de::DeserializeOwned;
use std::sync::Arc;

Expand Down Expand Up @@ -783,7 +782,7 @@ impl<R: Runtime, C> EvmRpcClient<R, C> {
async fn try_execute_request<Config, Params, CandidOutput, Output>(
&self,
request: Request<Config, Params, CandidOutput, Output>,
) -> Result<Output, (RejectCode, String)>
) -> Result<Output, IcError>
where
Config: CandidType + Send,
Params: CandidType + Send,
Expand Down
4 changes: 2 additions & 2 deletions evm_rpc_client/src/request/mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#[cfg(feature = "alloy")]
pub(crate) mod alloy;

use crate::runtime::IcError;
use crate::{EvmRpcClient, Runtime};
use candid::CandidType;
use evm_rpc_types::{
BlockTag, CallArgs, ConsensusStrategy, FeeHistoryArgs, GetLogsArgs, GetLogsRpcConfig,
GetTransactionCountArgs, Hex, Hex20, Hex32, MultiRpcResult, Nat256, RpcConfig, RpcServices,
};
use ic_error_types::RejectCode;
use serde::de::DeserializeOwned;
use std::fmt::{Debug, Formatter};
use strum::EnumIter;
Expand Down Expand Up @@ -508,7 +508,7 @@ impl<R: Runtime, Converter, Config, Params, CandidOutput, Output>

/// Constructs the [`Request`] and sends it using the [`EvmRpcClient`]. This method returns
/// either the request response or any error that occurs while sending the request.
pub async fn try_send(self) -> Result<Output, (RejectCode, String)>
pub async fn try_send(self) -> Result<Output, IcError>
where
Config: CandidType + Send,
Params: CandidType + Send,
Expand Down
Loading