diff --git a/Cargo.lock b/Cargo.lock index a5c2d557..14cf961f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -51,16 +51,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f4a4aaae80afd4be443a6aecd92a6b255dcdd000f97996928efb33d8a71e100" dependencies = [ "alloy-consensus", + "alloy-contract", "alloy-core", "alloy-eips", "alloy-genesis", "alloy-network", "alloy-provider", + "alloy-pubsub", "alloy-rpc-client", "alloy-rpc-types", "alloy-serde", + "alloy-signer", + "alloy-signer-local", "alloy-transport", "alloy-transport-http", + "alloy-transport-ipc", + "alloy-transport-ws", ] [[package]] @@ -87,6 +93,27 @@ dependencies = [ "serde", ] +[[package]] +name = "alloy-contract" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f4e0ef72b0876ae3068b2ed7dfae9ae1779ce13cfaec2ee1f08f5bd0348dc57" +dependencies = [ + "alloy-dyn-abi", + "alloy-json-abi", + "alloy-network", + "alloy-network-primitives", + "alloy-primitives", + "alloy-provider", + "alloy-pubsub", + "alloy-rpc-types-eth", + "alloy-sol-types", + "alloy-transport", + "futures", + "futures-util", + "thiserror", +] + [[package]] name = "alloy-core" version = "0.7.7" @@ -127,6 +154,7 @@ dependencies = [ "alloy-rlp", "alloy-serde", "c-kzg", + "derive_more", "k256", "once_cell", "serde", @@ -237,10 +265,13 @@ dependencies = [ "alloy-network", "alloy-network-primitives", "alloy-primitives", + "alloy-pubsub", "alloy-rpc-client", "alloy-rpc-types-eth", "alloy-transport", "alloy-transport-http", + "alloy-transport-ipc", + "alloy-transport-ws", "async-stream", "async-trait", "auto_impl", @@ -257,6 +288,25 @@ dependencies = [ "url", ] +[[package]] +name = "alloy-pubsub" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f5da2c55cbaf229bad3c5f8b00b5ab66c74ef093e5f3a753d874cfecf7d2281" +dependencies = [ + "alloy-json-rpc", + "alloy-primitives", + "alloy-transport", + "bimap", + "futures", + "serde", + "serde_json", + "tokio", + "tokio-stream", + "tower", + "tracing", +] + [[package]] name = "alloy-rlp" version = "0.3.7" @@ -286,8 +336,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b38e3ffdb285df5d9f60cb988d336d9b8e3505acb78750c3bc60336a7af41d3" dependencies = [ "alloy-json-rpc", + "alloy-primitives", + "alloy-pubsub", "alloy-transport", "alloy-transport-http", + "alloy-transport-ipc", + "alloy-transport-ws", "futures", "pin-project", "reqwest", @@ -306,9 +360,28 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6c31a3750b8f5a350d17354e46a52b0f2f19ec5f2006d816935af599dedc521" dependencies = [ + "alloy-rpc-types-engine", + "alloy-rpc-types-eth", + "alloy-serde", + "serde", +] + +[[package]] +name = "alloy-rpc-types-engine" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff63f51b2fb2f547df5218527fd0653afb1947bf7fead5b3ce58c75d170b30f7" +dependencies = [ + "alloy-consensus", + "alloy-eips", + "alloy-primitives", + "alloy-rlp", "alloy-rpc-types-eth", "alloy-serde", + "jsonwebtoken", + "rand 0.8.5", "serde", + "thiserror", ] [[package]] @@ -355,6 +428,22 @@ dependencies = [ "thiserror", ] +[[package]] +name = "alloy-signer-local" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b0707d4f63e4356a110b30ef3add8732ab6d181dd7be4607bf79b8777105cee" +dependencies = [ + "alloy-consensus", + "alloy-network", + "alloy-primitives", + "alloy-signer", + "async-trait", + "k256", + "rand 0.8.5", + "thiserror", +] + [[package]] name = "alloy-sol-macro" version = "0.7.7" @@ -375,6 +464,7 @@ version = "0.7.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "867a5469d61480fea08c7333ffeca52d5b621f5ca2e44f271b117ec1fc9a0525" dependencies = [ + "alloy-json-abi", "alloy-sol-macro-input", "const-hex", "heck 0.5.0", @@ -393,11 +483,13 @@ version = "0.7.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2e482dc33a32b6fadbc0f599adea520bd3aaa585c141a80b404d0a3e3fa72528" dependencies = [ + "alloy-json-abi", "const-hex", "dunce", "heck 0.5.0", "proc-macro2", "quote", + "serde_json", "syn 2.0.72", "syn-solidity", ] @@ -418,6 +510,7 @@ version = "0.7.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a91ca40fa20793ae9c3841b83e74569d1cc9af29a2f5237314fd3452d51e38c7" dependencies = [ + "alloy-json-abi", "alloy-primitives", "alloy-sol-macro", "const-hex", @@ -458,6 +551,43 @@ dependencies = [ "url", ] +[[package]] +name = "alloy-transport-ipc" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "804494366e20468776db4e18f9eb5db7db0fe14f1271eb6dbf155d867233405c" +dependencies = [ + "alloy-json-rpc", + "alloy-pubsub", + "alloy-transport", + "bytes", + "futures", + "interprocess", + "pin-project", + "serde_json", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "alloy-transport-ws" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af855163e7df008799941aa6dd324a43ef2bf264b08ba4b22d44aad6ced65300" +dependencies = [ + "alloy-pubsub", + "alloy-transport", + "futures", + "http 1.1.0", + "rustls 0.23.12", + "serde_json", + "tokio", + "tokio-tungstenite", + "tracing", + "ws_stream_wasm", +] + [[package]] name = "android-tzdata" version = "0.1.1" @@ -712,6 +842,17 @@ dependencies = [ "syn 2.0.72", ] +[[package]] +name = "async_io_stream" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6d7b9decdf35d8908a7e3ef02f64c5e9b1695e230154c0e8de3969142d9b94c" +dependencies = [ + "futures", + "pharos", + "rustc_version 0.4.0", +] + [[package]] name = "atomic" version = "0.6.0" @@ -808,6 +949,12 @@ dependencies = [ "serde", ] +[[package]] +name = "bimap" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "230c5f1ca6a325a32553f8640d31ac9b49f2411e901e427570154868b46da4f7" + [[package]] name = "bit-set" version = "0.5.3" @@ -1479,6 +1626,12 @@ dependencies = [ "parking_lot_core", ] +[[package]] +name = "data-encoding" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8566979429cf69b49a5c740c60791108e86440e8be149bbea4fe54d2c32d6e2" + [[package]] name = "der" version = "0.7.9" @@ -1489,6 +1642,15 @@ dependencies = [ "zeroize", ] +[[package]] +name = "deranged" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" +dependencies = [ + "powerfmt", +] + [[package]] name = "derivative" version = "2.2.0" @@ -1513,6 +1675,12 @@ dependencies = [ "syn 2.0.72", ] +[[package]] +name = "diff" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" + [[package]] name = "digest" version = "0.9.0" @@ -1585,6 +1753,12 @@ dependencies = [ "libloading", ] +[[package]] +name = "doctest-file" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aac81fa3e28d21450aa4d2ac065992ba96a1d7303efbce51a95f4fd175b67562" + [[package]] name = "dotenv" version = "0.15.0" @@ -2027,7 +2201,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f288b0a4f20f9a56b5d1da57e2227c661b7b16168e2f72365f57b63326e29b24" dependencies = [ "gloo-timers 0.2.6", - "send_wrapper", + "send_wrapper 0.4.0", ] [[package]] @@ -2284,6 +2458,8 @@ dependencies = [ "eyre", "hex", "plotters", + "pretty_assertions", + "rand 0.8.5", "serde", "tempfile", "tokio", @@ -2656,6 +2832,21 @@ version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c8fae54786f62fb2918dcfae3d568594e50eb9b5c25bf04371af6fe7516452fb" +[[package]] +name = "interprocess" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2f4e4a06d42fab3e85ab1b419ad32b09eab58b901d40c57935ff92db3287a13" +dependencies = [ + "doctest-file", + "futures-core", + "libc", + "recvmsg", + "tokio", + "widestring", + "windows-sys 0.52.0", +] + [[package]] name = "ipnet" version = "2.9.0" @@ -2754,7 +2945,7 @@ dependencies = [ "tokio-rustls 0.24.1", "tokio-util", "tracing", - "webpki-roots", + "webpki-roots 0.23.1", ] [[package]] @@ -2874,6 +3065,21 @@ dependencies = [ "jsonrpsee-types", ] +[[package]] +name = "jsonwebtoken" +version = "9.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9ae10193d25051e74945f1ea2d0b42e03cc3b890f7e4cc5faa44997d808193f" +dependencies = [ + "base64 0.21.7", + "js-sys", + "pem", + "ring 0.17.8", + "serde", + "serde_json", + "simple_asn1", +] + [[package]] name = "k256" version = "0.13.3" @@ -3110,6 +3316,12 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-conv" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" + [[package]] name = "num-integer" version = "0.1.46" @@ -3377,7 +3589,7 @@ checksum = "bdeeaa00ce488657faba8ebf44ab9361f9365a97bd39ffb8a60663f57ff4b467" dependencies = [ "inlinable_string", "pear_codegen", - "yansi", + "yansi 1.0.1", ] [[package]] @@ -3392,6 +3604,16 @@ dependencies = [ "syn 2.0.72", ] +[[package]] +name = "pem" +version = "3.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e459365e590736a54c3fa561947c84837534b8e9af6fc5bf781307e82658fae" +dependencies = [ + "base64 0.22.1", + "serde", +] + [[package]] name = "percent-encoding" version = "2.3.1" @@ -3409,6 +3631,16 @@ dependencies = [ "ucd-trie", ] +[[package]] +name = "pharos" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9567389417feee6ce15dd6527a8a1ecac205ef62c2932bcf3d9f6fc5b78b414" +dependencies = [ + "futures", + "rustc_version 0.4.0", +] + [[package]] name = "pin-project" version = "1.1.5" @@ -3525,12 +3757,28 @@ dependencies = [ "miniz_oxide", ] +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + [[package]] name = "ppv-lite86" version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" +[[package]] +name = "pretty_assertions" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af7cee1a6c8a5b9208b3cb1061f10c0cb689087b3d8ce85fb9d2dd7a29b6ba66" +dependencies = [ + "diff", + "yansi 0.5.1", +] + [[package]] name = "primitive-types" version = "0.6.2" @@ -3617,7 +3865,7 @@ dependencies = [ "quote", "syn 2.0.72", "version_check", - "yansi", + "yansi 1.0.1", ] [[package]] @@ -3767,6 +4015,12 @@ dependencies = [ "crossbeam-utils", ] +[[package]] +name = "recvmsg" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3edd4d5d42c92f0a659926464d4cce56b562761267ecf0f469d85b7de384175" + [[package]] name = "redox_syscall" version = "0.5.3" @@ -4113,6 +4367,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c58f8c84392efc0a126acce10fa59ff7b3d2ac06ab451a33f2741989b806b044" dependencies = [ "once_cell", + "ring 0.17.8", "rustls-pki-types", "rustls-webpki 0.102.6", "subtle", @@ -4362,6 +4617,12 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f638d531eccd6e23b980caf34876660d38e265409d8e99b397ab71eb3612fad0" +[[package]] +name = "send_wrapper" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd0b0ec5f1c1ca621c432a25813d8d60c88abe6d3e08a3eb9cf37d97a0fe3d73" + [[package]] name = "serde" version = "1.0.204" @@ -4452,6 +4713,17 @@ dependencies = [ "opaque-debug", ] +[[package]] +name = "sha1" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest 0.10.7", +] + [[package]] name = "sha2" version = "0.9.9" @@ -4520,6 +4792,18 @@ version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe" +[[package]] +name = "simple_asn1" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adc4e5204eb1910f40f9cfa375f6f05b68c3abac4b6fd879c8ff5e7ae8a0a085" +dependencies = [ + "num-bigint", + "num-traits", + "thiserror", + "time", +] + [[package]] name = "slab" version = "0.4.9" @@ -4823,6 +5107,37 @@ dependencies = [ "num_cpus", ] +[[package]] +name = "time" +version = "0.3.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" +dependencies = [ + "deranged", + "itoa", + "num-conv", + "powerfmt", + "serde", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" + +[[package]] +name = "time-macros" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f252a68540fde3a3877aeea552b832b40ab9a69e318efd078774a01ddee1ccf" +dependencies = [ + "num-conv", + "time-core", +] + [[package]] name = "tiny-keccak" version = "1.5.0" @@ -4938,6 +5253,22 @@ dependencies = [ "tokio-util", ] +[[package]] +name = "tokio-tungstenite" +version = "0.23.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6989540ced10490aaf14e6bad2e3d33728a2813310a0c71d1574304c49631cd" +dependencies = [ + "futures-util", + "log", + "rustls 0.23.12", + "rustls-pki-types", + "tokio", + "tokio-rustls 0.26.0", + "tungstenite", + "webpki-roots 0.26.3", +] + [[package]] name = "tokio-util" version = "0.7.11" @@ -5151,6 +5482,26 @@ version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "17f77d76d837a7830fe1d4f12b7b4ba4192c1888001c7164257e4bc6d21d96b4" +[[package]] +name = "tungstenite" +version = "0.23.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e2e2ce1e47ed2994fd43b04c8f618008d4cabdd5ee34027cf14f9d918edd9c8" +dependencies = [ + "byteorder", + "bytes", + "data-encoding", + "http 1.1.0", + "httparse", + "log", + "rand 0.8.5", + "rustls 0.23.12", + "rustls-pki-types", + "sha1", + "thiserror", + "utf-8", +] + [[package]] name = "typenum" version = "1.17.0" @@ -5252,6 +5603,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + [[package]] name = "utf8parse" version = "0.2.2" @@ -5426,12 +5783,27 @@ dependencies = [ "rustls-webpki 0.100.3", ] +[[package]] +name = "webpki-roots" +version = "0.26.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd7c23921eeb1713a4e851530e9b9756e4fb0e89978582942612524cf09f01cd" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "weezl" version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "53a85b86a771b1c87058196170769dd264f66c0782acf1ae6cc51bfd64b39082" +[[package]] +name = "widestring" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7219d36b6eac893fa81e84ebe06485e7dcbb616177469b142df14f1f4deb1311" + [[package]] name = "winapi" version = "0.3.9" @@ -5648,6 +6020,25 @@ dependencies = [ "winapi", ] +[[package]] +name = "ws_stream_wasm" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7999f5f4217fe3818726b66257a4475f71e74ffd190776ad053fa159e50737f5" +dependencies = [ + "async_io_stream", + "futures", + "js-sys", + "log", + "pharos", + "rustc_version 0.4.0", + "send_wrapper 0.6.0", + "thiserror", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", +] + [[package]] name = "wyz" version = "0.5.1" @@ -5657,6 +6048,12 @@ dependencies = [ "tap", ] +[[package]] +name = "yansi" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" + [[package]] name = "yansi" version = "1.0.1" diff --git a/Cargo.toml b/Cargo.toml index fe08d245..95efc1c1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -82,10 +82,10 @@ dotenv = "0.15.0" serde = { version = "1.0.154", features = ["derive"] } [target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies] +alloy = { version = "0.2.1", features = ["full"] } tokio = { version = "1", features = ["full"] } eyre = "0.6.8" dirs = "5.0.1" -alloy = "0.2.1" tracing-subscriber = { version = "0.3.17", features = ["env-filter"] } tracing = "0.1.37" tracing-test = "0.2.4" @@ -93,6 +93,8 @@ criterion = { version = "0.5.1", features = ["async_tokio", "plotters"] } plotters = "0.3.4" tempfile = "3.4.0" hex = "0.4.3" +pretty_assertions = "1.4.0" +rand = "0.8.5" ###################################### # Profiles diff --git a/consensus-core/src/types/utils.rs b/consensus-core/src/types/utils.rs index 0a1a17a4..c9fabca6 100644 --- a/consensus-core/src/types/utils.rs +++ b/consensus-core/src/types/utils.rs @@ -94,6 +94,7 @@ impl From for Block { fn from(value: ExecutionPayload) -> Block { let empty_nonce = "0x0000000000000000".to_string(); let empty_uncle_hash = "1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"; + let base_fee_per_gas = AU256::from_le_slice(&value.base_fee_per_gas().to_bytes_le()); let txs = value .transactions() @@ -152,6 +153,12 @@ impl From for Block { tx.access_list = Some(tx_inner.access_list.clone()); tx.max_fee_per_gas = Some(tx_inner.max_fee_per_gas); tx.max_priority_fee_per_gas = Some(tx_inner.max_priority_fee_per_gas); + + tx.gas_price = Some(gas_price( + tx_inner.max_fee_per_gas, + tx_inner.max_priority_fee_per_gas, + base_fee_per_gas.to(), + )); } TxEnvelope::Eip4844(inner) => { tx.from = inner.recover_signer().unwrap(); @@ -167,7 +174,14 @@ impl From for Block { tx.max_fee_per_gas = Some(tx_inner.max_fee_per_gas); tx.max_priority_fee_per_gas = Some(tx_inner.max_priority_fee_per_gas); tx.max_fee_per_blob_gas = Some(tx_inner.max_fee_per_blob_gas); + tx.gas_price = Some(tx_inner.max_fee_per_gas); tx.blob_versioned_hashes = Some(tx_inner.blob_versioned_hashes.clone()); + + tx.gas_price = Some(gas_price( + tx_inner.max_fee_per_gas, + tx_inner.max_priority_fee_per_gas, + base_fee_per_gas.to(), + )); } _ => todo!(), } @@ -178,7 +192,7 @@ impl From for Block { Block { number: U64::from(value.block_number().as_u64()), - base_fee_per_gas: AU256::from_le_slice(&value.base_fee_per_gas().to_bytes_le()), + base_fee_per_gas, difficulty: AU256::ZERO, extra_data: value.extra_data().to_vec().into(), gas_limit: U64::from(value.gas_limit().as_u64()), @@ -201,3 +215,7 @@ impl From for Block { } } } + +fn gas_price(max_fee: u128, max_prio_fee: u128, base_fee: u128) -> u128 { + u128::min(max_fee, max_prio_fee + base_fee) +} diff --git a/execution/src/types.rs b/execution/src/types.rs index e858fa65..3b4c097b 100644 --- a/execution/src/types.rs +++ b/execution/src/types.rs @@ -21,6 +21,7 @@ pub struct CallOpts { pub gas: Option, pub gas_price: Option, pub value: Option, + #[serde(alias = "input")] pub data: Option, } diff --git a/tests/rpc_equivalence.rs b/tests/rpc_equivalence.rs new file mode 100644 index 00000000..2dac582d --- /dev/null +++ b/tests/rpc_equivalence.rs @@ -0,0 +1,177 @@ +use std::env; + +use alloy::eips::BlockNumberOrTag; +use alloy::primitives::address; +use alloy::providers::{Provider, ProviderBuilder, RootProvider}; +use alloy::rpc::client::ClientBuilder as AlloyClientBuilder; +use alloy::sol; +use alloy::transports::http::{Client as ReqwestClient, Http}; +use alloy::transports::layers::{RetryBackoffLayer, RetryBackoffService}; +use pretty_assertions::assert_eq; + +use helios::client::{Client, ClientBuilder}; +use helios::consensus::database::ConfigDB; +use rand::Rng; + +async fn setup() -> ( + Client, + RootProvider>, + RootProvider>>, +) { + let execution_rpc = env::var("MAINNET_EXECUTION_RPC").unwrap(); + let consensus_rpc = "https://www.lightclientdata.org"; + + let port = rand::thread_rng().gen_range(0..=65535); + + let mut helios_client = ClientBuilder::new() + .network(config::Network::MAINNET) + .execution_rpc(&execution_rpc) + .consensus_rpc(&consensus_rpc) + .load_external_fallback() + .strict_checkpoint_age() + .rpc_port(port) + .build() + .unwrap(); + + helios_client.start().await.unwrap(); + helios_client.wait_synced().await; + + let client = AlloyClientBuilder::default() + .layer(RetryBackoffLayer::new(100, 50, 300)) + .http(execution_rpc.parse().unwrap()); + + let provider = ProviderBuilder::new().on_client(client); + + let url = format!("http://localhost:{}", port).parse().unwrap(); + let helios_provider = ProviderBuilder::new().on_http(url); + + (helios_client, helios_provider, provider) +} + +#[tokio::test] +async fn get_transaction_by_hash() { + let (_handle, helios_provider, provider) = setup().await; + + let block = helios_provider + .get_block_by_number(BlockNumberOrTag::Latest, false) + .await + .unwrap() + .unwrap(); + + let tx_hash = block.transactions.hashes().next().unwrap(); + let helios_tx = helios_provider + .get_transaction_by_hash(tx_hash) + .await + .unwrap() + .unwrap(); + + let tx = provider + .get_transaction_by_hash(tx_hash) + .await + .unwrap() + .unwrap(); + + assert_eq!(helios_tx, tx); +} + +// #[tokio::test] +// async fn get_block_by_number() { +// let (_handle, helios_provider, provider) = setup().await; +// +// let helios_block = helios_provider +// .get_block_by_number(BlockNumberOrTag::Latest, false) +// .await +// .unwrap() +// .unwrap(); +// +// let block = provider +// .get_block_by_number(helios_block.header.number.unwrap().into(), false) +// .await +// .unwrap() +// .unwrap(); +// +// assert_eq!(helios_block, block); +// } + +#[tokio::test] +async fn get_transaction_receipt() { + let (_handle, helios_provider, provider) = setup().await; + + let block = helios_provider + .get_block_by_number(BlockNumberOrTag::Latest, false) + .await + .unwrap() + .unwrap(); + + let tx_hash = block.transactions.hashes().next().unwrap(); + let helios_receipt = helios_provider + .get_transaction_receipt(tx_hash) + .await + .unwrap() + .unwrap(); + + let receipt = provider + .get_transaction_receipt(tx_hash) + .await + .unwrap() + .unwrap(); + + assert_eq!(helios_receipt, receipt); +} + +#[tokio::test] +async fn get_balance() { + let (_handle, helios_provider, provider) = setup().await; + let num = helios_provider.get_block_number().await.unwrap(); + + let address = address!("00000000219ab540356cBB839Cbe05303d7705Fa"); + let helios_balance = helios_provider + .get_balance(address) + .block_id(num.into()) + .await + .unwrap(); + + let balance = provider + .get_balance(address) + .block_id(num.into()) + .await + .unwrap(); + + assert_eq!(helios_balance, balance); +} + +#[tokio::test] +async fn call() { + let (_handle, helios_provider, provider) = setup().await; + let num = helios_provider.get_block_number().await.unwrap(); + let usdc = address!("a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"); + let user = address!("99C9fc46f92E8a1c0deC1b1747d010903E884bE1"); + + sol! { + #[sol(rpc)] + interface ERC20 { + function balanceOf(address who) external returns (uint256); + } + } + + let helios_token = ERC20::new(usdc, helios_provider); + let token = ERC20::new(usdc, provider); + + let helios_balance = helios_token + .balanceOf(user) + .block(num.into()) + .call() + .await + .unwrap() + ._0; + + let balance = token + .balanceOf(user) + .block(num.into()) + .call() + .await + .unwrap() + ._0; + + assert_eq!(helios_balance, balance); +}