Skip to content
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

Merged
merged 45 commits into from
Aug 23, 2024
Merged

Test: Ethereum Settlement Client #81

merged 45 commits into from
Aug 23, 2024

Conversation

heemankv
Copy link
Contributor

@heemankv heemankv commented Aug 12, 2024

This PR adds tests for Ethereum Settlement Client.

External Dependencies :

  • Anvil for forking and running local test chain.
  • Ethereum RPC.

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 multiple update state transactions we extract the nonce fetch call from the child : update_state_with_blobs and manage nonce from process_job, this doesn't affect the distributed fashion of code since each machine will have a pre-existing lock over the jobs.
    ( update_state_with_blobs is called by update_state_for_block which is called inside a loop by process_job)

@heemankv heemankv requested a review from apoorvsadana August 12, 2024 09:30
@heemankv heemankv self-assigned this Aug 12, 2024
@heemankv heemankv force-pushed the test/settlement-client branch from e35fc0b to 0ea20a1 Compare August 12, 2024 10:08
@heemankv heemankv changed the title Test: Settlement Client [inProgress] Test: Settlement Client Aug 13, 2024
@heemankv heemankv force-pushed the test/settlement-client branch from 1edc905 to e7023af Compare August 14, 2024 10:41
@heemankv heemankv changed the title [inProgress] Test: Settlement Client Test: Settlement Client Aug 14, 2024
@heemankv heemankv changed the title Test: Settlement Client Test: Ethereum Settlement Client Aug 14, 2024
@heemankv heemankv added the tests label Aug 14, 2024
@heemankv heemankv force-pushed the test/settlement-client branch from 9b8c738 to 391d693 Compare August 14, 2024 15:44
@coveralls
Copy link

coveralls commented Aug 16, 2024

Coverage Status

coverage: 65.198% (+7.0%) from 58.192%
when pulling f9d3682 on test/settlement-client
into 5728df2 on main.

@heemankv heemankv force-pushed the test/settlement-client branch from e2dba9a to 0fa24ba Compare August 17, 2024 05:14
@heemankv heemankv force-pushed the test/settlement-client branch from 0fa24ba to 4de6e8b Compare August 17, 2024 05:15
crates/settlement-clients/ethereum/src/lib.rs Outdated Show resolved Hide resolved
crates/settlement-clients/ethereum/src/lib.rs Outdated Show resolved Hide resolved
crates/settlement-clients/ethereum/src/lib.rs Outdated Show resolved Hide resolved
crates/settlement-clients/ethereum/src/lib.rs Outdated Show resolved Hide resolved
crates/settlement-clients/ethereum/src/lib.rs Outdated Show resolved Hide resolved
crates/settlement-clients/ethereum/src/lib.rs Outdated Show resolved Hide resolved
crates/settlement-clients/ethereum/src/conversion.rs Outdated Show resolved Hide resolved
heemankv and others added 3 commits August 18, 2024 14:18
Reworking Settlement Client test cases to be independent of env vars and work in minimalism.
---------

Co-authored-by: Heemank Verma <[email protected]>
Copy link

@odesenfans odesenfans left a 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"

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.

Copy link
Contributor Author

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 }

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.

Copy link
Contributor Author

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.

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?

Copy link
Contributor Author

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.

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 //).

Copy link
Contributor Author

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 {

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?

Copy link
Contributor Author

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,

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?

Copy link
Contributor Author

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.

@apoorvsadana apoorvsadana merged commit 11dc132 into main Aug 23, 2024
9 checks passed
ocdbytes pushed a commit that referenced this pull request Oct 16, 2024
* 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants