-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Use strongly typed fields in JSON requests and responses (#291
) Ensures that all fields in JSON requests/responses that are serialized/deserialized by the EVM-RPC canister are strongly typed, e.g. use a wrapper around`[u8; 32]` instead of a `String` for fields that represent hashes. This ensures that the EVM-RPC canister only uses with syntactically valid data.
- Loading branch information
1 parent
f32960e
commit 9a94dba
Showing
9 changed files
with
287 additions
and
228 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
use crate::candid_rpc::process_result; | ||
use crate::rpc_client::{MultiCallError, MultiCallResults}; | ||
use crate::types::RpcMethod; | ||
use evm_rpc_types::MultiRpcResult; | ||
use evm_rpc_types::{ProviderError, RpcError}; | ||
|
||
#[test] | ||
fn test_process_result_mapping() { | ||
use evm_rpc_types::{EthMainnetService, RpcService}; | ||
|
||
let method = RpcMethod::EthGetTransactionCount; | ||
|
||
assert_eq!( | ||
process_result(method, Ok(5)), | ||
MultiRpcResult::Consistent(Ok(5)) | ||
); | ||
assert_eq!( | ||
process_result( | ||
method, | ||
Err(MultiCallError::<()>::ConsistentError( | ||
RpcError::ProviderError(ProviderError::MissingRequiredProvider) | ||
)) | ||
), | ||
MultiRpcResult::Consistent(Err(RpcError::ProviderError( | ||
ProviderError::MissingRequiredProvider | ||
))) | ||
); | ||
assert_eq!( | ||
process_result( | ||
method, | ||
Err(MultiCallError::<()>::InconsistentResults( | ||
MultiCallResults::default() | ||
)) | ||
), | ||
MultiRpcResult::Inconsistent(vec![]) | ||
); | ||
assert_eq!( | ||
process_result( | ||
method, | ||
Err(MultiCallError::InconsistentResults( | ||
MultiCallResults::from_non_empty_iter(vec![( | ||
RpcService::EthMainnet(EthMainnetService::Ankr), | ||
Ok(5) | ||
)]) | ||
)) | ||
), | ||
MultiRpcResult::Inconsistent(vec![( | ||
RpcService::EthMainnet(EthMainnetService::Ankr), | ||
Ok(5) | ||
)]) | ||
); | ||
assert_eq!( | ||
process_result( | ||
method, | ||
Err(MultiCallError::InconsistentResults( | ||
MultiCallResults::from_non_empty_iter(vec![ | ||
(RpcService::EthMainnet(EthMainnetService::Ankr), Ok(5)), | ||
( | ||
RpcService::EthMainnet(EthMainnetService::Cloudflare), | ||
Err(RpcError::ProviderError(ProviderError::NoPermission)) | ||
) | ||
]) | ||
)) | ||
), | ||
MultiRpcResult::Inconsistent(vec![ | ||
(RpcService::EthMainnet(EthMainnetService::Ankr), Ok(5)), | ||
( | ||
RpcService::EthMainnet(EthMainnetService::Cloudflare), | ||
Err(RpcError::ProviderError(ProviderError::NoPermission)) | ||
) | ||
]) | ||
); | ||
} |
Oops, something went wrong.