From 635f996c0372f37157ecb0c65f0c944335f9cf43 Mon Sep 17 00:00:00 2001 From: Alex Mikhalevich <2990126+alexmikhalevich@users.noreply.github.com> Date: Mon, 25 Mar 2024 23:26:48 +0100 Subject: [PATCH] fix tests --- rollup-http/echo-dapp/src/main.rs | 2 +- rollup-http/rollup-http-client/src/rollup.rs | 2 +- rollup-http/rollup-http-server/Cargo.lock | 514 +++++++++++++++++- rollup-http/rollup-http-server/Cargo.toml | 9 +- .../rollup-http-server/src/http_service.rs | 10 +- .../rollup-http-server/src/rollup/mod.rs | 69 ++- .../tests/rollup-http-server-tests.rs | 122 +++-- 7 files changed, 641 insertions(+), 87 deletions(-) diff --git a/rollup-http/echo-dapp/src/main.rs b/rollup-http/echo-dapp/src/main.rs index 319a5a55..a9fc0e34 100644 --- a/rollup-http/echo-dapp/src/main.rs +++ b/rollup-http/echo-dapp/src/main.rs @@ -44,7 +44,7 @@ pub async fn process_advance_request( let voucher_payload = request.payload.clone(); let voucher = Voucher { destination: request.metadata.msg_sender.clone(), - data: voucher_payload.clone(), + value: "0xdeadbeef".to_string(), payload: voucher_payload, }; diff --git a/rollup-http/rollup-http-client/src/rollup.rs b/rollup-http/rollup-http-client/src/rollup.rs index da7fe2fc..93e06da6 100644 --- a/rollup-http/rollup-http-client/src/rollup.rs +++ b/rollup-http/rollup-http-client/src/rollup.rs @@ -51,7 +51,7 @@ pub struct Notice { #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct Voucher { pub destination: String, - pub data: String, + pub value: String, pub payload: String, } diff --git a/rollup-http/rollup-http-server/Cargo.lock b/rollup-http/rollup-http-server/Cargo.lock index d9a3d29b..fea9b208 100644 --- a/rollup-http/rollup-http-server/Cargo.lock +++ b/rollup-http/rollup-http-server/Cargo.lock @@ -181,6 +181,28 @@ dependencies = [ "syn 2.0.53", ] +[[package]] +name = "actix-web-validator" +version = "5.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40ee5ed4e266dad8d980f964c5ddd746f1f4f85b7f3b54f7099ab861ec6d746" +dependencies = [ + "actix-http", + "actix-router", + "actix-web", + "bytes", + "futures", + "futures-util", + "log", + "mime", + "serde", + "serde_json", + "serde_qs", + "serde_urlencoded", + "thiserror", + "validator", +] + [[package]] name = "addr2line" version = "0.21.0" @@ -239,6 +261,12 @@ version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" +[[package]] +name = "arrayvec" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" + [[package]] name = "async-mutex" version = "1.4.0" @@ -332,6 +360,18 @@ version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +[[package]] +name = "bitvec" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" +dependencies = [ + "funty", + "radium", + "tap", + "wyz", +] + [[package]] name = "block-buffer" version = "0.10.4" @@ -362,6 +402,18 @@ dependencies = [ "alloc-stdlib", ] +[[package]] +name = "byte-slice-cast" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3ac9f8b63eca6fd385229b3675f6cc0dc5c8a5c8a54a59d4f52ffd670d87b0c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + [[package]] name = "bytes" version = "1.5.0" @@ -448,6 +500,12 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "crunchy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" + [[package]] name = "crypto-common" version = "0.1.6" @@ -534,6 +592,50 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "ethabi" +version = "18.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7413c5f74cc903ea37386a8965a936cbeb334bd270862fdece542c1b2dcbc898" +dependencies = [ + "ethereum-types", + "hex", + "once_cell", + "regex", + "serde", + "serde_json", + "sha3", + "thiserror", + "uint", +] + +[[package]] +name = "ethbloom" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c22d4b5885b6aa2fe5e8b9329fb8d232bf739e434e6b87347c63bdd00c120f60" +dependencies = [ + "crunchy", + "fixed-hash", + "impl-rlp", + "impl-serde", + "tiny-keccak", +] + +[[package]] +name = "ethereum-types" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02d215cbf040552efcbe99a38372fe80ab9d00268e20012b79fcd0f073edd8ee" +dependencies = [ + "ethbloom", + "fixed-hash", + "impl-rlp", + "impl-serde", + "primitive-types", + "uint", +] + [[package]] name = "event-listener" version = "2.5.3" @@ -546,6 +648,18 @@ version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" +[[package]] +name = "fixed-hash" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "835c052cb0c08c1acf6ffd71c022172e18723949c8282f2b9f27efbc51e64534" +dependencies = [ + "byteorder", + "rand", + "rustc-hex", + "static_assertions", +] + [[package]] name = "fixedbitset" version = "0.2.0" @@ -577,6 +691,27 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "funty" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" + +[[package]] +name = "futures" +version = "0.3.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da0290714b38af9b4a7b094b8a37086d1b4e61f2df9122c3cad2577669145335" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + [[package]] name = "futures-channel" version = "0.3.29" @@ -584,6 +719,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff4dd66668b557604244583e3e1e1eada8c5c2e96a6d0d6653ede395b78bbacb" dependencies = [ "futures-core", + "futures-sink", ] [[package]] @@ -592,6 +728,34 @@ version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eb1d22c66e66d9d72e1758f0bd7d4fd0bee04cad842ee34587d68c07e45d088c" +[[package]] +name = "futures-executor" +version = "0.3.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f4fb8693db0cf099eadcca0efe2a5a22e4550f98ed16aba6c48700da29597bc" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53b153fd91e4b0147f4aced87be237c98248656bb01050b96bf3ee89220a8ddb" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.53", +] + [[package]] name = "futures-sink" version = "0.3.29" @@ -610,10 +774,16 @@ version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a19526d624e703a3179b3d322efec918b6246ea0fa51d41124525f00f1cc8104" dependencies = [ + "futures-channel", "futures-core", + "futures-io", + "futures-macro", + "futures-sink", "futures-task", + "memchr", "pin-project-lite", "pin-utils", + "slab", ] [[package]] @@ -791,6 +961,16 @@ dependencies = [ "want", ] +[[package]] +name = "idna" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d20d6b07bfbc108882d88ed8e37d39636dcc260e15e30c45e6ba089610b917c" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + [[package]] name = "idna" version = "0.5.0" @@ -801,6 +981,50 @@ dependencies = [ "unicode-normalization", ] +[[package]] +name = "if_chain" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb56e1aa765b4b4f3aadfab769793b7087bb03a4ea4920644a6d238e2df5b9ed" + +[[package]] +name = "impl-codec" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba6a270039626615617f3f36d15fc827041df3b78c439da2cadfa47455a77f2f" +dependencies = [ + "parity-scale-codec", +] + +[[package]] +name = "impl-rlp" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f28220f89297a075ddc7245cd538076ee98b01f2a9c23a53a4f1105d5a322808" +dependencies = [ + "rlp", +] + +[[package]] +name = "impl-serde" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc88fc67028ae3db0c853baa36269d398d5f45b6982f95549ff5def78c935cd" +dependencies = [ + "serde", +] + +[[package]] +name = "impl-trait-for-tuples" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11d7a9f6330b71fea57921c9b61c47ee6e84f72d394754eff6163ae67e7395eb" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "indexmap" version = "1.9.3" @@ -845,6 +1069,15 @@ dependencies = [ "libc", ] +[[package]] +name = "keccak" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ecc2af9a1119c51f12a14607e783cb977bde58bc069ff0c3da1095e635d70654" +dependencies = [ + "cpufeatures", +] + [[package]] name = "language-tags" version = "0.3.2" @@ -865,9 +1098,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.150" +version = "0.2.153" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c" +checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" [[package]] name = "libloading" @@ -881,9 +1114,9 @@ dependencies = [ [[package]] name = "linux-raw-sys" -version = "0.4.11" +version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "969488b55f8ac402214f3f5fd243ebb7206cf82de60d3172994707a4bcc2b829" +checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" [[package]] name = "local-channel" @@ -994,9 +1227,35 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.18.0" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "parity-scale-codec" +version = "3.6.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "881331e34fa842a2fb61cc2db9643a8fedc615e47cfcc52597d1af0db9a7e8fe" +dependencies = [ + "arrayvec", + "bitvec", + "byte-slice-cast", + "impl-trait-for-tuples", + "parity-scale-codec-derive", + "serde", +] + +[[package]] +name = "parity-scale-codec-derive" +version = "3.6.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" +checksum = "be30eaf4b0a9fba5336683b38de57bb86d179a35862ba6bfcf57625d006bde5b" +dependencies = [ + "proc-macro-crate", + "proc-macro2", + "quote", + "syn 1.0.109", +] [[package]] name = "parking_lot" @@ -1083,6 +1342,53 @@ dependencies = [ "syn 2.0.53", ] +[[package]] +name = "primitive-types" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b34d9fd68ae0b74a41b21c03c2f62847aa0ffea044eee893b4c140b37e244e2" +dependencies = [ + "fixed-hash", + "impl-codec", + "impl-rlp", + "impl-serde", + "uint", +] + +[[package]] +name = "proc-macro-crate" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b00f26d3400549137f92511a46ac1cd8ce37cb5598a96d382381458b992a5d24" +dependencies = [ + "toml_datetime", + "toml_edit", +] + +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn 1.0.109", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] + [[package]] name = "proc-macro2" version = "1.0.79" @@ -1152,6 +1458,12 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "radium" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" + [[package]] name = "rand" version = "0.8.5" @@ -1220,6 +1532,16 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" +[[package]] +name = "rlp" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb919243f34364b6bd2fc10ef797edbfa75f33c252e7998527479c6d6b47e1ec" +dependencies = [ + "bytes", + "rustc-hex", +] + [[package]] name = "rollup-http-client" version = "0.1.0" @@ -1236,17 +1558,20 @@ dependencies = [ [[package]] name = "rollup-http-server" -version = "0.1.0" +version = "0.2.0" dependencies = [ "actix-server", "actix-web", + "actix-web-validator", "async-mutex", "bindgen", "cc", "env_logger", + "ethabi", "getopts", "hex", "hyper", + "lazy_static", "libc", "log", "rand", @@ -1257,6 +1582,7 @@ dependencies = [ "serde_json", "tokio", "tonic-build", + "validator", ] [[package]] @@ -1284,6 +1610,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" +[[package]] +name = "rustc-hex" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e75f6a532d0fd9f7f13144f392b6ad56a32696bfcd9c78f797f16bbb6f072d6" + [[package]] name = "rustc_version" version = "0.4.0" @@ -1295,15 +1627,15 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.25" +version = "0.38.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc99bc2d4f1fed22595588a013687477aedf3cdcfb26558c559edb67b4d9b22e" +checksum = "65e04861e65f21776e67888bfbea442b3642beaa0138fdb1dd7a84a52dffdb89" dependencies = [ "bitflags 2.4.1", "errno", "libc", "linux-raw-sys", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] @@ -1355,6 +1687,19 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_qs" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8cac3f1e2ca2fe333923a1ae72caca910b98ed0630bb35ef6f8c8517d6e81afa" +dependencies = [ + "actix-web", + "futures", + "percent-encoding", + "serde", + "thiserror", +] + [[package]] name = "serde_urlencoded" version = "0.7.1" @@ -1378,6 +1723,16 @@ dependencies = [ "digest", ] +[[package]] +name = "sha3" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75872d278a8f37ef87fa0ddbda7802605cb18344497949862c0d4dcb291eba60" +dependencies = [ + "digest", + "keccak", +] + [[package]] name = "shlex" version = "1.2.0" @@ -1428,6 +1783,12 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + [[package]] name = "syn" version = "1.0.109" @@ -1450,17 +1811,22 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "tap" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" + [[package]] name = "tempfile" -version = "3.8.1" +version = "3.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ef1adac450ad7f4b3c28589471ade84f25f731a7a0fe30d71dfa9f60fd808e5" +checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" dependencies = [ "cfg-if", "fastrand", - "redox_syscall", "rustix", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] @@ -1472,6 +1838,26 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "thiserror" +version = "1.0.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03468839009160513471e86a034bb2c5c0e4baae3b43f79ffc55c4a5427b3297" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.53", +] + [[package]] name = "time" version = "0.3.30" @@ -1501,6 +1887,15 @@ dependencies = [ "time-core", ] +[[package]] +name = "tiny-keccak" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237" +dependencies = [ + "crunchy", +] + [[package]] name = "tinyvec" version = "1.6.0" @@ -1560,6 +1955,23 @@ dependencies = [ "tracing", ] +[[package]] +name = "toml_datetime" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b" + +[[package]] +name = "toml_edit" +version = "0.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "396e4d48bbb2b7554c944bde63101b5ae446cff6ec4a24227428f15eb72ef338" +dependencies = [ + "indexmap 2.1.0", + "toml_datetime", + "winnow", +] + [[package]] name = "tonic-build" version = "0.5.2" @@ -1610,6 +2022,18 @@ version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" +[[package]] +name = "uint" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76f64bba2c53b04fcab63c01a7d7427eadc821e3bc48c34dc9ba29c501164b52" +dependencies = [ + "byteorder", + "crunchy", + "hex", + "static_assertions", +] + [[package]] name = "unicode-bidi" version = "0.3.13" @@ -1650,10 +2074,52 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" dependencies = [ "form_urlencoded", - "idna", + "idna 0.5.0", "percent-encoding", ] +[[package]] +name = "validator" +version = "0.16.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b92f40481c04ff1f4f61f304d61793c7b56ff76ac1469f1beb199b1445b253bd" +dependencies = [ + "idna 0.4.0", + "lazy_static", + "regex", + "serde", + "serde_derive", + "serde_json", + "url", + "validator_derive", +] + +[[package]] +name = "validator_derive" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc44ca3088bb3ba384d9aecf40c6a23a676ce23e09bdaca2073d99c207f864af" +dependencies = [ + "if_chain", + "lazy_static", + "proc-macro-error", + "proc-macro2", + "quote", + "regex", + "syn 1.0.109", + "validator_types", +] + +[[package]] +name = "validator_types" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "111abfe30072511849c5910134e8baf8dc05de4c0e5903d681cbd5c9c4d611e3" +dependencies = [ + "proc-macro2", + "syn 1.0.109", +] + [[package]] name = "version_check" version = "0.9.4" @@ -1850,6 +2316,24 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" +[[package]] +name = "winnow" +version = "0.5.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f593a95398737aeed53e489c785df13f3618e41dbcd6718c6addbf1395aa6876" +dependencies = [ + "memchr", +] + +[[package]] +name = "wyz" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" +dependencies = [ + "tap", +] + [[package]] name = "zerocopy" version = "0.7.26" diff --git a/rollup-http/rollup-http-server/Cargo.toml b/rollup-http/rollup-http-server/Cargo.toml index 623b2866..1ba18f4c 100644 --- a/rollup-http/rollup-http-server/Cargo.toml +++ b/rollup-http/rollup-http-server/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rollup-http-server" -version = "0.1.0" +version = "0.2.0" edition = "2021" authors = ["Marko Atanasievski , Sofia Rodrigues , Alex Mikhalevich "] @@ -17,7 +17,10 @@ getopts = "0.2" libc = "0.2" regex = "1.5.5" actix-web = "4.0.0-rc.2" +validator = { version = "0.16", features = ["derive"] } actix-server = "2.0" +actix-web-validator = "5.0.1" +lazy_static = "1.4.0" serde = { version = "1.0", features = ["derive"]} serde_json = "1.0" log = "0.4" @@ -28,7 +31,6 @@ hyper = { version = "0.14", features = ["http1", "runtime", "client"] } hex = "0.4" rstest = "0.12" - [build-dependencies] bindgen = "0.69.4" cc = "1.0" @@ -37,11 +39,10 @@ tonic-build = "0.5" [dev-dependencies] rollup-http-client = {path = "../rollup-http-client"} rand = "0.8.5" - +ethabi = "18.0.0" [profile.release] strip = true lto = true # Enable Link Time Optimization opt-level = "z" # Optimize for size. codegen-units = 1 # Reduce number of codegen units to increase optimizations, but slower build -# panic = "abort" # Abort on panic diff --git a/rollup-http/rollup-http-server/src/http_service.rs b/rollup-http/rollup-http-server/src/http_service.rs index ee30a6ad..67fc14c6 100644 --- a/rollup-http/rollup-http-server/src/http_service.rs +++ b/rollup-http/rollup-http-server/src/http_service.rs @@ -16,7 +16,8 @@ use std::sync::Arc; -use actix_web::{middleware::Logger, web::Data, web::Json, App, HttpResponse, HttpServer}; +use actix_web::{middleware::Logger, web::Data, App, HttpResponse, HttpServer}; +use actix_web_validator::Json; use async_mutex::Mutex; use serde::{Deserialize, Serialize}; use tokio::sync::Notify; @@ -24,7 +25,7 @@ use tokio::sync::Notify; use crate::config::Config; use crate::rollup::{self, RollupFd}; use crate::rollup::{ - AdvanceRequest, Exception, InspectRequest, Notice, Report, RollupRequest, Voucher, + AdvanceRequest, Exception, InspectRequest, Notice, Report, RollupRequest, FinishRequest, Voucher, }; #[derive(Debug, Serialize, Deserialize)] @@ -236,11 +237,6 @@ async fn finish(finish: Json, data: Data>) -> Http .json(http_rollup_request) } -#[derive(Debug, Clone, Deserialize)] -struct FinishRequest { - status: String, -} - #[derive(Debug, Clone, Serialize)] struct IndexResponse { index: u64, diff --git a/rollup-http/rollup-http-server/src/rollup/mod.rs b/rollup-http/rollup-http-server/src/rollup/mod.rs index f6e60481..5a61a1f8 100644 --- a/rollup-http/rollup-http-server/src/rollup/mod.rs +++ b/rollup-http/rollup-http-server/src/rollup/mod.rs @@ -22,6 +22,9 @@ use std::io::ErrorKind; use libc::c_void; use serde::{Deserialize, Serialize}; +use validator::Validate; +use regex::Regex; +use lazy_static::lazy_static; include!(concat!(env!("OUT_DIR"), "/bindings.rs")); @@ -58,6 +61,11 @@ pub const REQUEST_TYPE_ADVANCE_STATE: &str = "advance_state"; pub const REQUEST_TYPE_INSPECT_STATE: &str = "inspect_state"; pub const CARTESI_ROLLUP_ADDRESS_SIZE: u32 = 20; +lazy_static! { + static ref ETH_ADDR_REGEXP: Regex = Regex::new(r"0x[0-9a-fA-F]{1,42}$").unwrap(); + static ref ETH_U256_REGEXP: Regex = Regex::new(r"0x[0-9a-fA-F]{1,64}$").unwrap(); +} + #[derive(Debug, Default)] pub struct RollupError { message: String, @@ -155,29 +163,36 @@ pub enum RollupRequest { Advance(AdvanceRequest), } +#[derive(Debug, Clone, Deserialize, Validate)] +pub struct FinishRequest { + pub status: String, +} + #[derive(Debug, Clone, Serialize, Deserialize)] pub struct InspectReport { pub reports: Vec } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, Validate)] pub struct Notice { pub payload: String, } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, Validate)] pub struct Voucher { + #[validate(regex = "ETH_ADDR_REGEXP")] pub destination: String, - pub data: String, + #[validate(regex = "ETH_U256_REGEXP")] + pub value: String, pub payload: String, } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, Validate)] pub struct Report { pub payload: String, } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, Validate)] pub struct Exception { pub payload: String, } @@ -281,6 +296,7 @@ pub fn rollup_read_inspect_state_request( log::info!("read zero size payload from inspect state request"); } + println!("inspect_request.payload_length: {}", inspect_request.payload_length); let mut payload: Vec = Vec::with_capacity(inspect_request.payload_length as usize); if inspect_request.payload_length > 0 { unsafe { @@ -313,7 +329,7 @@ pub fn rollup_write_notice( let mut buffer: Vec = Vec::with_capacity(binary_payload.len()); let length = binary_payload.len() as u64; - let notice_index: std::os::raw::c_ulong = 0; + let mut notice_index: std::os::raw::c_ulong = 0; let res = unsafe { std::ptr::copy( @@ -322,7 +338,7 @@ pub fn rollup_write_notice( binary_payload.len(), ); - cmt_rollup_emit_notice(fd.0, length as u32, buffer.as_mut_ptr() as *mut c_void) + cmt_rollup_emit_notice(fd.0, length as u32, buffer.as_mut_ptr() as *mut c_void, &mut notice_index) }; if res != 0 { @@ -348,27 +364,25 @@ pub fn rollup_write_voucher( Ok(payload) => payload, Err(_err) => { return Err(Box::new(RollupError::new(&format!( - "Error decoding voucher payload, payload must be in Ethereum hex binary format" + "Error decoding voucher payload, it must be in Ethereum hex binary format" )))); } }; + let mut payload_buffer: Vec = Vec::with_capacity(binary_payload.len()); + let payload_data = payload_buffer.as_mut_ptr(); + let payload_length = binary_payload.len(); - let binary_message = match hex::decode(&voucher.data[2..]) { + let binary_value = match hex::decode(&voucher.value[2..]) { Ok(data) => data, Err(_err) => { return Err(Box::new(RollupError::new(&format!( - "Error decoding voucher message data, data must be in Ethereum hex binary format" + "Error decoding voucher value, it must be in Ethereum hex binary format" )))); } }; - - let mut payload_buffer: Vec = Vec::with_capacity(binary_payload.len()); - let payload_data = payload_buffer.as_mut_ptr(); - let payload_length = binary_payload.len(); - - let mut message_buffer: Vec = Vec::with_capacity(binary_message.len()); - let message_data = message_buffer.as_mut_ptr(); - let message_length = binary_message.len(); + let mut value_buffer: Vec = Vec::with_capacity(binary_value.len()); + let value_data = value_buffer.as_mut_ptr(); + let value_length = binary_value.len(); let address_c = match hex::decode(&voucher.destination[2..]) { Ok(res) => res, @@ -380,7 +394,7 @@ pub fn rollup_write_voucher( } }; - let voucher_index: std::os::raw::c_ulong = 0; + let mut voucher_index: std::os::raw::c_ulong = 0; let res = unsafe { std::ptr::copy( binary_payload.as_ptr(), @@ -388,19 +402,20 @@ pub fn rollup_write_voucher( binary_payload.len(), ); std::ptr::copy( - binary_message.as_ptr(), - message_buffer.as_mut_ptr(), - binary_message.len(), + binary_value.as_ptr(), + value_buffer.as_mut_ptr(), + binary_value.len(), ); cmt_rollup_emit_voucher( fd.0, address_c.len() as u32, address_c.as_ptr() as *const c_void, + value_length as u32, + value_data as *mut c_void, payload_length as u32, payload_data as *mut c_void, - message_length as u32, - message_data as *mut c_void, + &mut voucher_index, ) }; @@ -499,13 +514,15 @@ pub async fn perform_rollup_finish_request( finish_request.accept_previous_request = true; match rollup_finish_request(fd, &mut finish_request) { - Ok(_) => Ok(finish_request), + Ok(_) => { + dbg!(&finish_request); + Ok(finish_request) + } Err(e) => { log::error!("error inserting finish request, details: {}", e.to_string()); Err(std::io::Error::new(ErrorKind::Other, e.to_string())) } } - } /// Read advance/inspect request from rollup device diff --git a/rollup-http/rollup-http-server/tests/rollup-http-server-tests.rs b/rollup-http/rollup-http-server/tests/rollup-http-server-tests.rs index 69bc07c6..d7888b56 100644 --- a/rollup-http/rollup-http-server/tests/rollup-http-server-tests.rs +++ b/rollup-http/rollup-http-server/tests/rollup-http-server-tests.rs @@ -26,11 +26,12 @@ use rollup_http_server::config::Config; use rollup_http_server::rollup::RollupFd; use rollup_http_server::*; use rstest::*; -use std::fs::File; use std::future::Future; use std::sync::Arc; use rand::Rng; use std::env; +use std::fs::File; +use std::io::Write; const HOST: &str = "127.0.0.1"; @@ -118,7 +119,38 @@ async fn test_server_instance_creation( async fn test_finish_request( context_future: impl Future, ) -> Result<(), Box> { - env::set_var("CMT_INPUTS", "0:advance.bin,1:inspect.bin"); + /* + * cast calldata 'EvmAdvance(uint256,address,address,uint256,uint256,uint256,bytes)' \ + * 0 $(cast address-zero) $(printf 0x%040x 1) 0 0 0 0xdeadbeef | xxd -r -p + */ + let advance_payload_data = "cc7dee1f00000000000000000000000000000000000000000000000000000000000\ + 0000000000000000000000000000000000000000000000000000000000000000000\ + 0000000000000000000000000000000000000000000000000000000000000000010\ + 0000000000000000000000000000000000000000000000000000000000000000000\ + 0000000000000000000000000000000000000000000000000000000000000000000\ + 0000000000000000000000000000000000000000000000000000000000000000000\ + 0000000000000000000000000000000000000000000000000000e00000000000000\ + 000000000000000000000000000000000000000000000000004deadbeef00000000\ + 000000000000000000000000000000000000000000000000"; + + /* + * cast calldata 'EvmInspect(bytes)' 0xdeadbeef | xxd -r -p + */ + let inspect_payload_data = "73d4414300000000000000000000000000000000000000000000000000000000000\ + 0002000000000000000000000000000000000000000000000000000000000000000\ + 04deadbeef00000000000000000000000000000000000000000000000000000000"; + + let advance_binary_data = hex::decode(advance_payload_data).unwrap(); + let advance_path = "advance_payload.bin"; + let mut advance_file = File::create(advance_path)?; + advance_file.write_all(&advance_binary_data)?; + + let inspect_binary_data = hex::decode(inspect_payload_data).unwrap(); + let inspect_path = "inspect_payload.bin"; + let mut inspect_file = File::create(inspect_path)?; + inspect_file.write_all(&inspect_binary_data)?; + + env::set_var("CMT_INPUTS", format!("0:{0},1:{1}", advance_path, inspect_path)); env::set_var("CMT_DEBUG", "yes"); let context = context_future.await; @@ -137,7 +169,7 @@ async fn test_finish_request( assert_eq!(advance_request.payload.len(), 10); assert_eq!( advance_request.metadata.msg_sender, - "0x0000000000000000000000000000000000000000" + "0x0000000000000000000000000000000000000001" ); assert_eq!( &advance_request.payload[2..], @@ -154,7 +186,7 @@ async fn test_finish_request( { Ok(request) => match request { RollupRequest::Inspect(inspect_request) => { - println!("Got new inspect request: {:?}", inspect_request); + //println!("Got new inspect request: {:?}", inspect_request); context.server_handle.stop(true).await; assert_eq!(inspect_request.payload.len(), 10); assert_eq!( @@ -173,54 +205,70 @@ async fn test_finish_request( } } context.server_handle.stop(true).await; + + std::fs::remove_file(advance_path)?; + std::fs::remove_file(inspect_path)?; + Ok(()) } +fn check_voucher_or_fail( + original_voucher: Voucher, + output_filename: &str, +) { + // we try to decode the produced voucher with a third-party lib to see if it matches + // the expected values + let data = + std::fs::read(output_filename).expect("error reading voucher file"); + let decoded_voucher = ethabi::decode( + &[ethabi::ParamType::Address, ethabi::ParamType::Uint(256), ethabi::ParamType::Bytes], + &data[4..], // skip the first 4 bytes that are the function signature + ).ok().unwrap(); + + assert_eq!( + "0x".to_string() + &decoded_voucher[0].to_string(), + original_voucher.destination, + ); + assert_eq!( + "0x".to_string() + &decoded_voucher[1].to_string(), + original_voucher.value, + ); + assert_eq!( + "0x".to_string() + &decoded_voucher[2].to_string(), + original_voucher.payload, + ); +} + #[rstest] #[tokio::test] async fn test_write_voucher( context_future: impl Future, ) -> Result<(), Box> { - env::set_var("CMT_INPUTS", "0:advance.bin,1:inspect.bin"); - env::set_var("CMT_DEBUG", "yes"); - let context = context_future.await; println!("Writing voucher"); let test_voucher_01 = Voucher { destination: "0x1111111111111111111111111111111111111111".to_string(), - data: "0x".to_string() + &hex::encode("voucher test payload 02"), + value: "0xdeadbeef".to_string(), payload: "0x".to_string() + &hex::encode("voucher test payload 01"), }; let test_voucher_02 = Voucher { destination: "0x2222222222222222222222222222222222222222".to_string(), - data: "0x".to_string() + &hex::encode("voucher test payload 02"), + value: "0xdeadbeef".to_string(), payload: "0x".to_string() + &hex::encode("voucher test payload 02"), }; - rollup_http_client::client::send_voucher(&context.address, test_voucher_01).await; + rollup_http_client::client::send_voucher(&context.address, test_voucher_01.clone()).await; - let voucher1 = - std::fs::read("none.output-0.bin").expect("error reading voucher 1 file"); - assert_eq!( - voucher1, - [35, 122, 129, 111, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 118, 111, 117, 99, 104, 101, 114, 32, 116, 101, 115, 116, 32, 112, 97, 121, 108, 111, 97, 100, 32, 48, 49, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 96, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 23, 118, 111, 117, 99, 104, 101, 114, 32, 116, 101, 115, 116, 32, 112, 97, 121, 108, 111, 97, 100, 32, 48, 49, 0, 0, 0, 0, 0, 0, 0, 0, 0] - ); + check_voucher_or_fail(test_voucher_01, "none.output-0.bin"); std::fs::remove_file("none.output-0.bin")?; println!("Writing second voucher!"); - rollup_http_client::client::send_voucher(&context.address, test_voucher_02).await; + rollup_http_client::client::send_voucher(&context.address, test_voucher_02.clone()).await; context.server_handle.stop(true).await; - //Read text file with results - - let voucher2 = - std::fs::read("none.output-0.bin").expect("error reading voucher 2 file"); - assert_eq!( - voucher2, - [35, 122, 129, 111, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 0, 0, 0, 0, 0, 0, 0, 0, 0, 118, 111, 117, 99, 104, 101, 114, 32, 116, 101, 115, 116, 32, 112, 97, 121, 108, 111, 97, 100, 32, 48, 50, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 96, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 23, 118, 111, 117, 99, 104, 101, 114, 32, 116, 101, 115, 116, 32, 112, 97, 121, 108, 111, 97, 100, 32, 48, 50, 0, 0, 0, 0, 0, 0, 0, 0, 0] - ); - + check_voucher_or_fail(test_voucher_02, "none.output-0.bin"); std::fs::remove_file("none.output-0.bin")?; + Ok(()) } @@ -235,16 +283,24 @@ async fn test_write_notice( let test_notice = Notice { payload: "0x".to_string() + &hex::encode("notice test payload 01"), }; - rollup_http_client::client::send_notice(&context.address, test_notice).await; + rollup_http_client::client::send_notice(&context.address, test_notice.clone()).await; context.server_handle.stop(true).await; - //Read text file with results - let notice1 = + + // we try to decode the produced voucher with a third-party lib to see if it matches + // the expected values + let data = std::fs::read("none.output-0.bin").expect("error reading test notice file"); - //assert_eq!( - // notice1, - // "index: 1, payload_size: 22, payload: notice test payload 01" - //); + let decoded_notice = ethabi::decode( + &[ethabi::ParamType::Bytes], + &data[4..], // skip the first 4 bytes that are the function signature + ).ok().unwrap(); + + assert_eq!( + "0x".to_string() + &decoded_notice[0].to_string(), + test_notice.payload, + ); std::fs::remove_file("none.output-0.bin")?; + Ok(()) }