-
Notifications
You must be signed in to change notification settings - Fork 15
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
Test: Ethereum Settlement Client #81
Conversation
e35fc0b
to
0ea20a1
Compare
1edc905
to
e7023af
Compare
9b8c738
to
391d693
Compare
crates/settlement-clients/ethereum/src/test_data/ABI/starknet_core_contract.json
Outdated
Show resolved
Hide resolved
39317e5
to
6c03f7b
Compare
e2dba9a
to
0fa24ba
Compare
0fa24ba
to
4de6e8b
Compare
…ks & update_state_blob_with_dummy_contract_works
Reworking Settlement Client test cases to be independent of env vars and work in minimalism. --------- Co-authored-by: Heemank Verma <[email protected]>
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 would need to understand the context a bit more to review this PR meaningfully. I added a few comments but they're not super interesting.
@@ -15,7 +15,7 @@ MADARA_RPC_URL="http://localhost:3000" | |||
ETHEREUM_RPC_URL="http://localhost:3001" | |||
MEMORY_PAGES_CONTRACT_ADDRESS="0x000000000000000000000000000000000001dead" | |||
PRIVATE_KEY="0xdead" | |||
ETHEREUM_PRIVATE_KEY="0x000000000000000000000000000000000000000000000000000000000000beef" | |||
ETHEREUM_PRIVATE_KEY="0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" |
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.
Are you okay with this being public? If this is not a problem, document why this is set in Github.
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.
Ideally, we can remove this but it's genuinely no harm since this is Private_key provided by Anvil, will add a comment to explain the same
@@ -4,11 +4,14 @@ version.workspace = true | |||
edition.workspace = true | |||
|
|||
[dependencies] | |||
alloy = { workspace = true, features = ["full"] } | |||
alloy = { workspace = true, features = ["full", "node-bindings"] } | |||
alloy-primitives = { version = "0.7.7", default-features = false } |
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.
Unrelated to the PR, but I think it makes sense to define all your dependencies at the workspace level and then pull them in each crate like you're doing with alloy
.
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.
Created an issue for the same to be thoroughly checked later on : #99
use alloy_primitives::FixedBytes; | ||
use c_kzg::{Blob, KzgCommitment, KzgProof, KzgSettings}; | ||
use color_eyre::{eyre::ContextCompat, Result as EyreResult}; | ||
use std::fmt::Write; | ||
|
||
/// Converts a `&[Vec<u8>]` to `Vec<U256>`. Each inner slice is expected to be exactly 32 bytes long. |
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.
This comment is slightly wrong as you're taking &[[u8; 32]]
. Update it?
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.
Valid, updated.
|
||
// Function to convert a slice of u8 to a padded hex string | ||
// Function only takes a slice of length up to 32 elements | ||
// Pads the value on the right side with zeros only if the converted string has lesser than 64 characters. |
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.
Use docstrings to document functions (///
instead of //
).
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.
Valid, updated.
Ok(input_data) | ||
} | ||
|
||
pub(crate) fn vec_u8_32_to_hex_string(data: Vec<[u8; 32]>) -> String { |
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.
Why do you need ownership here? Can't you pass a slice in all cases?
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.
Valid, improved. using &[[u8; 32]]
now
} | ||
|
||
struct EthereumTest { | ||
_anvil: AnvilInstance, |
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.
Why are you prefixing this with an underscore?
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.
So,
We notices the an anvil
server is needed to be in scope in any function that is using RPC calls to anvil
.
We create anvil
server in EthereumTestBuilder
if we don't pass it to update_state_blob_with_dummy_contract_works
we get ConnectionRefused
Error suggesting that the server that was started in EthereumTestBuilder
has now been closed.
I believe this has to do with how rust
handles variable scoping
.
So, _anvil
as a variable is never used, it's only there to be in the scope, hence the _
.
This is my understanding, please feel free to correct it / broaden the perspective / suggest an alternative & optimised way to achieve the same.
* update: settlement-client: ethereum test cases for conversion fns * update: removed .expect from slice_u8_to_u256 * update: Eth Settlement client: tests for conversions * update: Eth Settlement client : prepare_sidecar * update: settlement_client: eth: prepare_sidecar tests * chore: optimisations * update: working test case * update: working test #2 * update: added cfg test for update_state_with_blobs * update: cleaner cfg(test) implemented code for update_state_and_blob_test * chore: liniting fixes * update: linting fixes * docs: changelog * update: Nonce prefetch for state_update * update: creation of input_data works * update: using correct input bytes * chore: lint fix * update: test normal transaction * update: dummy contract and impersonation tests ready * update: test cases for settlement client * chore: lint fixes * chore: fix lints * update: Changes for PR review * chore: fixing test cases for eth settlement client * update: tests fix * chore: lint fix * chore: lint fix * update: path fix * update: testing anvil install on gh * update: fixing path * update: added Blast rpc for eth * update: Coverage CI fixes * update: correct Pr checks * update: PR reviews fixes * update: PR reviews fixes * update: adding rationale for update_state_blob_with_impersonation_works & update_state_blob_with_dummy_contract_works * update: cleaner test integration on update_state_with_blobs * update: removing EthProvider * Reworking Settlement Client Changes (#89) Reworking Settlement Client test cases to be independent of env vars and work in minimalism. --------- Co-authored-by: Heemank Verma <[email protected]> * update PR reviews fixed * update PR reviews fixed --------- Co-authored-by: apoorvsadana <[email protected]>
This PR adds tests for
Ethereum Settlement Client
.External Dependencies :
Points to note :
Test code blocks are included with
#[cfg(test)]
between prod code, to ensure possibility of testing, please feel free to suggest any other way.Two tests :
update_state_blob_with_dummy_contract_works
&update_state_blob_with_impersonation_works
use a test param to make aware about impersonation or dummy contract call.Nonce
: To ensure consistency in nonce while doing multipleupdate state
transactions we extract thenonce
fetch call from the child :update_state_with_blobs
and managenonce
fromprocess_job
, this doesn't affect thedistributed
fashion of code since each machine will have a pre-existing lock over the jobs.(
update_state_with_blobs
is called byupdate_state_for_block
which is called inside a loop byprocess_job
)