-
Notifications
You must be signed in to change notification settings - Fork 16
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!: adjust Candid-RPC methods for state machine tests #95
Conversation
…ic-eth-rpc into test-unexpected-response-fields
#[ic_cdk_macros::update] | ||
#[candid_method] | ||
#[update(name = "eth_getLogs")] | ||
#[candid_method(rename = "eth_getLogs")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question for anyone more familiar with the Rust CDK: is there a way to avoid all these duplicate attributes (aside from renaming the function itself)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know the answer. What happens if you only use rename
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only using one or the other results in the generated Candid interface having a different name from the canister method.
@@ -199,11 +200,15 @@ impl BoundedStorable for PrincipalStorable { | |||
|
|||
#[derive(Clone, Debug, Eq, PartialEq, CandidType, Deserialize)] | |||
pub struct ProviderView { | |||
#[serde(rename = "providerId")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Candid unfortunately doesn't support #[serde(rename_all = ...)]
, so these individual attributes are necessary. Leaving out the attributes results in an encoding / decoding mismatch, so this is required for supporting both JSON and Candid (de)serialization from the same data structure.
) | ||
cycles: u128, | ||
) -> RpcResult<HttpResponse> { | ||
if !is_authorized(&ic_cdk::caller(), Auth::FreeRpc) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cycles payment logic was originally in the forked ckETH codebase; I moved it here to support the FreeRpc
authorization for Candid-RPC methods. Everything else works the same as before.
src/candid_rpc.rs
Outdated
} | ||
.into()); | ||
} | ||
ic_cdk::api::call::msg_cycles_accept128(cycles); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit confused about the logic here: Shouldn't the attached cycles match a predetermined amount required to make the outcall? What is the point of passing along a cycles parameter that may or may not be sufficient (nor necessarily the same as the number of attached cycles)?
Why is any amount greater than cycles
allowed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cycles
(now renamed to cycles_cost
for clarity) is the cost calculated within the ckETH codebase based on the HTTPS outcall. msg_cycles_accept128()
only consumes this cost, so you can send more cycles than necessary without being overcharged.
This will eventually be replaced with the get_request_cost()
function in this repository, but it's quite a large refactor so I'm making incremental steps towards that.
} | ||
|
||
#[test] | ||
fn eth_send_raw_transaction_should_succeed() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to add a few tests for the unhappy path? For example, sending an invalid transaction should result in an error, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was planning to add these separately, but I'll include them here for efficiency given the review time zone offset.
Update: added several unhappy path / "fail case" tests.
This PR adds initial state machine tests for the Candid-RPC endpoints.
Progress:
EvmRpcSetup
implementation based on feedback in previous code reviewsCandidType
trait implementations in ckETH codebaseNote that this PR also switches the canister to use the original JSON-RPC camelCase naming conventions, which ended up being necessary due to limitations with the Candid Rust implementation. This has the side benefit of being more consistent with the large amount of existing documentation on JSON-RPC methods across the Internet.
Resolves #91.
Future work: