From 4e441fbd885eb91b1e2a2ddc1ee286a6bdea8f97 Mon Sep 17 00:00:00 2001 From: Will Qiu Date: Mon, 19 Dec 2022 13:45:46 +0800 Subject: [PATCH] integration test --- Cargo.lock | 269 +++++++++++++++++++------------------- Cargo.toml | 7 +- Makefile | 11 +- bin/compile_contracts.rs | 6 + src/contracts/mod.rs | 17 +++ tests/common/gen.rs | 10 ++ tests/common/mod.rs | 90 +++++++++++++ tests/integration_test.rs | 153 ++++++++++++++++++++++ 8 files changed, 427 insertions(+), 136 deletions(-) create mode 100644 bin/compile_contracts.rs create mode 100644 tests/common/gen.rs create mode 100644 tests/common/mod.rs create mode 100644 tests/integration_test.rs diff --git a/Cargo.lock b/Cargo.lock index 42c682bb..01f75fe6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -24,6 +24,7 @@ dependencies = [ "ethereum-interfaces", "ethers", "expanded-pathbuf", + "eyre", "hex", "jsonrpsee", "parking_lot 0.12.1", @@ -62,9 +63,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.66" +version = "1.0.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "216261ddc8289130e551ddcd5ce8a064710c0d064a4d2895c67151c92b5443f6" +checksum = "2cb2f989d18dd141ab8ae82f64d1a8cdd37e0840f73a406896cf5e99502fab61" [[package]] name = "arrayref" @@ -110,9 +111,9 @@ dependencies = [ [[package]] name = "async-trait" -version = "0.1.58" +version = "0.1.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e805d94e6b5001b651426cf4cd446b1ab5f319d27bab5c644f61de0a804360c" +checksum = "677d1d8ab452a3936018a687b20e6f7cf5363d713b732b8884001317b0e48aa3" dependencies = [ "proc-macro2", "quote", @@ -182,9 +183,9 @@ dependencies = [ [[package]] name = "axum" -version = "0.5.17" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acee9fd5073ab6b045a275b3e709c163dd36c90685219cb21804a147b58dba43" +checksum = "08b108ad2665fa3f6e6a517c3d80ec3e77d224c47d605167aefaa5d7ef97fa48" dependencies = [ "async-trait", "axum-core", @@ -200,9 +201,9 @@ dependencies = [ "mime", "percent-encoding", "pin-project-lite", + "rustversion", "serde", "sync_wrapper", - "tokio", "tower", "tower-http", "tower-layer", @@ -211,9 +212,9 @@ dependencies = [ [[package]] name = "axum-core" -version = "0.2.9" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37e5939e02c56fecd5c017c37df4238c0a839fa76b7f97acdd7efb804fd181cc" +checksum = "79b8558f5a0581152dc94dcd289132a1d377494bdeafcd41869b3258e3e2ad92" dependencies = [ "async-trait", "bytes", @@ -221,6 +222,7 @@ dependencies = [ "http", "http-body", "mime", + "rustversion", "tower-layer", "tower-service", ] @@ -334,9 +336,9 @@ dependencies = [ [[package]] name = "blake2" -version = "0.10.5" +version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b12e5fd123190ce1c2e559308a94c9bacad77907d4c6005d9e58fe1a0689e55e" +checksum = "46502ad458c9a52b69d4d4d32775c788b7a1b85e8bc9d482d92250fc0e3f8efe" dependencies = [ "digest 0.10.6", ] @@ -462,9 +464,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.77" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9f73505338f7d905b19d18738976aae232eb46b8efc15554ffc56deb5d9ebe4" +checksum = "a20104e2335ce8a659d6dd92a51a767a0c062599c73b343fd152cb401e828c3d" [[package]] name = "cfg-if" @@ -494,9 +496,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.0.27" +version = "4.0.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0acbd8d28a0a60d7108d7ae850af6ba34cf2d1257fc646980e5f97ce14275966" +checksum = "4d63b9e9c07271b9957ad22c173bae2a4d9a81127680962039296abcd2f8251d" dependencies = [ "bitflags", "clap_derive", @@ -698,9 +700,9 @@ dependencies = [ [[package]] name = "der" -version = "0.6.0" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13dd2ae565c0a381dde7fade45fce95984c568bdcb4700a4fdbe3175e0380b2f" +checksum = "f1a467a65c5e759bce6e65eaf91cc29f466cdc57cb65777bd646872a8a1fd4de" dependencies = [ "const-oid", "zeroize", @@ -961,7 +963,7 @@ dependencies = [ [[package]] name = "ethereum-interfaces" version = "0.1.0" -source = "git+https://github.com/ledgerwatch/interfaces#87d4311d40beec2e93cfff4102e775d559ba1ed6" +source = "git+https://github.com/ledgerwatch/interfaces#09084da85bb57e4a8b422b705562fc8d79ea8a35" dependencies = [ "arrayref", "ethereum-types", @@ -975,9 +977,9 @@ dependencies = [ [[package]] name = "ethereum-types" -version = "0.14.0" +version = "0.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81224dc661606574f5a0f28c9947d0ee1d93ff11c5f1c4e7272f52e8c0b5483c" +checksum = "02d215cbf040552efcbe99a38372fe80ab9d00268e20012b79fcd0f073edd8ee" dependencies = [ "ethbloom", "fixed-hash", @@ -991,9 +993,9 @@ dependencies = [ [[package]] name = "ethers" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d338f456cf5158d8cb630d39202cca4416ad2248193eadf9562bfb563d123176" +checksum = "11f26f9d8d80da18ca72aca51804c65eb2153093af3bec74fd5ce32aa0c1f665" dependencies = [ "ethers-addressbook", "ethers-contract", @@ -1007,9 +1009,9 @@ dependencies = [ [[package]] name = "ethers-addressbook" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3fb042cc02501fd7c1338d229ff2f10562efa430136ac8c467190c5cfe46eba" +checksum = "fe4be54dd2260945d784e06ccdeb5ad573e8f1541838cee13a1ab885485eaa0b" dependencies = [ "ethers-core", "once_cell", @@ -1019,9 +1021,9 @@ dependencies = [ [[package]] name = "ethers-contract" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40ce616689f073bdfbe317314abbe018f1baedf1209d32f1b01220a68ff120cf" +checksum = "e9c3c3e119a89f0a9a1e539e7faecea815f74ddcf7c90d0b00d1f524db2fdc9c" dependencies = [ "ethers-contract-abigen", "ethers-contract-derive", @@ -1038,9 +1040,9 @@ dependencies = [ [[package]] name = "ethers-contract-abigen" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c4c4cef2795a98b861ef4729556b3b4d72e6ef3f1d8c426cd78d9cf7d087e54" +checksum = "3d4e5ad46aede34901f71afdb7bb555710ed9613d88d644245c657dc371aa228" dependencies = [ "Inflector", "cfg-if", @@ -1063,9 +1065,9 @@ dependencies = [ [[package]] name = "ethers-contract-derive" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcc9816ce5d707cff3a75d6cd2c96ae60e157eb83f6754438064e30873f2196e" +checksum = "f192e8e4cf2b038318aae01e94e7644e0659a76219e94bcd3203df744341d61f" dependencies = [ "ethers-contract-abigen", "ethers-core", @@ -1078,9 +1080,9 @@ dependencies = [ [[package]] name = "ethers-core" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6e97a2dcf550b681966f9392f4e1389ffe54ebb1667e64583104ee4e01c058c" +checksum = "ade3e9c97727343984e1ceada4fdab11142d2ee3472d2c67027d56b1251d4f15" dependencies = [ "arrayvec", "bytes", @@ -1109,9 +1111,9 @@ dependencies = [ [[package]] name = "ethers-etherscan" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb8547a8b696795f027350be348c9a2faff94ad4e08103e7916360dd15da5919" +checksum = "a9713f525348e5dde025d09b0a4217429f8074e8ff22c886263cc191e87d8216" dependencies = [ "ethers-core", "getrandom", @@ -1126,9 +1128,9 @@ dependencies = [ [[package]] name = "ethers-middleware" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21af40f8e3808e165cb624704786656670d37dce73fec5eb8d3346d981f68e70" +checksum = "e71df7391b0a9a51208ffb5c7f2d068900e99d6b3128d3a4849d138f194778b7" dependencies = [ "async-trait", "auto_impl 0.5.0", @@ -1152,9 +1154,9 @@ dependencies = [ [[package]] name = "ethers-providers" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7405eaf127aec599f839799111315b8c2e7bfe767e2536412dbb16e284f2d8c" +checksum = "a1a9e0597aa6b2fdc810ff58bc95e4eeaa2c219b3e615ed025106ecb027407d8" dependencies = [ "async-trait", "auto_impl 1.0.1", @@ -1187,9 +1189,9 @@ dependencies = [ [[package]] name = "ethers-signers" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "341b582c30f5949b63bd76b2a08b6b997d8fe08fbe8026bd6ae042f5f9190eb4" +checksum = "3f41ced186867f64773db2e55ffdd92959e094072a1d09a5e5e831d443204f98" dependencies = [ "async-trait", "coins-bip32", @@ -1205,9 +1207,9 @@ dependencies = [ [[package]] name = "ethers-solc" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2671a3c0a1801e0d8c066940d26e263534515cb6e97bdfa5dbf396b8d54a3a4c" +checksum = "cbe9c0a6d296c57191e5f8a613a3b5e816812c28f4a28d6178a17c21db903d77" dependencies = [ "cfg-if", "dunce", @@ -1375,9 +1377,9 @@ checksum = "00f5fb52a06bdcadeb54e8d3671f8888a39697dcb0b81b23b55174030427f4eb" [[package]] name = "futures-locks" -version = "0.7.0" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3eb42d4fb72227be5778429f9ef5240a38a358925a49f05b5cf702ce7c7e558a" +checksum = "45ec6fe3675af967e67c5536c0b9d44e34e6c52f86bedc4ea49c5317b8e94d06" dependencies = [ "futures-channel", "futures-task", @@ -1649,9 +1651,9 @@ dependencies = [ [[package]] name = "hyper-rustls" -version = "0.23.1" +version = "0.23.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59df7c4e19c950e6e0e868dcc0a300b09a9b88e9ec55bd879ca819087a77355d" +checksum = "1788965e61b367cd03a62950836d5cd41560c3577d90e40e0819373194d1661c" dependencies = [ "http", "hyper", @@ -1759,9 +1761,9 @@ dependencies = [ [[package]] name = "io-lifetimes" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e394faa0efb47f9f227f1cd89978f854542b318a6f64fa695489c9c993056656" +checksum = "46112a93252b123d31a119a8d1a1ac19deac4fac6e0e8b0df58f0d4e5870e63c" dependencies = [ "libc", "windows-sys", @@ -1769,15 +1771,15 @@ dependencies = [ [[package]] name = "ipnet" -version = "2.5.1" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f88c5561171189e69df9d98bcf18fd5f9558300f7ea7b801eb8a0fd748bd8745" +checksum = "11b0d96e660696543b251e58030cf9787df56da39dab19ad60eae7353040917e" [[package]] name = "is-terminal" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aae5bc6e2eb41c9def29a3e0f1306382807764b9b53112030eff57435667352d" +checksum = "927609f78c2913a6f6ac3c27a4fe87f43e2a35367c0c4b0f8265e8f49a104330" dependencies = [ "hermit-abi 0.2.6", "io-lifetimes", @@ -1796,9 +1798,9 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.4" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc" +checksum = "fad582f4b9e86b6caa621cabeb0963332d92eea04729ab12892c2533951e6440" [[package]] name = "js-sys" @@ -1811,9 +1813,9 @@ dependencies = [ [[package]] name = "jsonrpsee" -version = "0.16.1" +version = "0.16.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5af9646e616e37c61093ef85e25bd883ae0c22e2fa1e6eedfe590048247116e3" +checksum = "7d291e3a5818a2384645fd9756362e6d89cf0541b0b916fa7702ea4a9833608e" dependencies = [ "jsonrpsee-core", "jsonrpsee-proc-macros", @@ -1824,9 +1826,9 @@ dependencies = [ [[package]] name = "jsonrpsee-core" -version = "0.16.1" +version = "0.16.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "673d68136e2f0f67323bab95b3a7177df26ac21ddbf395fc32d60f30fe5a1364" +checksum = "a4e70b4439a751a5de7dd5ed55eacff78ebf4ffe0fc009cb1ebb11417f5b536b" dependencies = [ "anyhow", "arrayvec", @@ -1850,9 +1852,9 @@ dependencies = [ [[package]] name = "jsonrpsee-proc-macros" -version = "0.16.1" +version = "0.16.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ed8b96f9d2d6a984fd75784ac8bfed994ee40980626b85791782dcd13ffb7ac" +checksum = "baa6da1e4199c10d7b1d0a6e5e8bd8e55f351163b6f4b3cbb044672a69bd4c1c" dependencies = [ "heck", "proc-macro-crate", @@ -1863,9 +1865,9 @@ dependencies = [ [[package]] name = "jsonrpsee-server" -version = "0.16.1" +version = "0.16.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a78f34520019321bd466d00620606db2f40827362d0185b3b95040328eb502f6" +checksum = "1fb69dad85df79527c019659a992498d03f8495390496da2f07e6c24c2b356fc" dependencies = [ "futures-channel", "futures-util", @@ -1885,9 +1887,9 @@ dependencies = [ [[package]] name = "jsonrpsee-types" -version = "0.16.1" +version = "0.16.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7985a27ee315c7c8c5c5033ac133e9472aec881edfd947780f5a9970efb7cbbf" +checksum = "5bd522fe1ce3702fd94812965d7bb7a3364b1c9aba743944c5a00529aae80f8c" dependencies = [ "anyhow", "beef", @@ -1959,15 +1961,15 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.137" +version = "0.2.138" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc7fcc620a3bff7cdd7a365be3376c97191aeaccc2a603e600951e452615bf89" +checksum = "db6d7e329c562c5dfab7a46a2afabc8b987ab9a4834c9d1ca04dc54c1546cef8" [[package]] name = "linux-raw-sys" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f9f08d8963a6c613f4b1a78f4f4a4dbfadf8e6545b2d72861731e4858b8b47f" +checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4" [[package]] name = "lock_api" @@ -1990,9 +1992,9 @@ dependencies = [ [[package]] name = "matchit" -version = "0.5.0" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73cbba799671b762df5a175adf59ce145165747bb891505c43d09aefbbf38beb" +checksum = "b87248edafb776e59e6ee64a79086f65890d3510f2c656c000bf2a7e8a0aea40" [[package]] name = "md-5" @@ -2187,7 +2189,7 @@ checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" dependencies = [ "instant", "lock_api", - "parking_lot_core 0.8.5", + "parking_lot_core 0.8.6", ] [[package]] @@ -2197,14 +2199,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" dependencies = [ "lock_api", - "parking_lot_core 0.9.4", + "parking_lot_core 0.9.5", ] [[package]] name = "parking_lot_core" -version = "0.8.5" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d76e8e1493bcac0d2766c42737f34458f1c8c50c0d23bcb24ea953affb273216" +checksum = "60a2cfe6f0ad2bfc16aefa463b497d5c7a5ecd44a23efa72aa342d90177356dc" dependencies = [ "cfg-if", "instant", @@ -2216,9 +2218,9 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.9.4" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dc9e0dc2adc1c69d09143aff38d3d30c5c3f0df0dad82e6d25547af174ebec0" +checksum = "7ff9f3fef3968a3ec5945535ed654cb38ff72d7495a25619e2247fb15a2ed9ba" dependencies = [ "cfg-if", "libc", @@ -2388,9 +2390,9 @@ checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" [[package]] name = "prettyplease" -version = "0.1.21" +version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c142c0e46b57171fe0c528bee8c5b7569e80f0c17e377cd0e30ea57dbc11bb51" +checksum = "2c8992a85d8e93a28bdf76137db888d3874e3b230dee5ed8bebac4c9f7617773" dependencies = [ "proc-macro2", "syn", @@ -2453,18 +2455,18 @@ checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" [[package]] name = "proc-macro2" -version = "1.0.47" +version = "1.0.49" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725" +checksum = "57a8eca9f9c4ffde41714334dee777596264c7825420f521abc92b5b5deb63a5" dependencies = [ "unicode-ident", ] [[package]] name = "prost" -version = "0.11.2" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0841812012b2d4a6145fae9a6af1534873c32aa67fff26bd09f8fa42c83f95a" +checksum = "c0b18e655c21ff5ac2084a5ad0611e827b3f92badf79f4910b5a5c58f4d87ff0" dependencies = [ "bytes", "prost-derive", @@ -2472,9 +2474,9 @@ dependencies = [ [[package]] name = "prost-build" -version = "0.11.2" +version = "0.11.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d8b442418ea0822409d9e7d047cbf1e7e9e1760b172bf9982cf29d517c93511" +checksum = "276470f7f281b0ed53d2ae42dd52b4a8d08853a3c70e7fe95882acbb98a6ae94" dependencies = [ "bytes", "heck", @@ -2526,9 +2528,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.21" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" +checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" dependencies = [ "proc-macro2", ] @@ -2577,11 +2579,10 @@ dependencies = [ [[package]] name = "rayon" -version = "1.6.0" +version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e060280438193c554f654141c9ea9417886713b7acd75974c85b18a69a88e0b" +checksum = "6db3a213adf02b3bcfd2d3846bb41cb22857d131789e01df434fb7e7bc0759b7" dependencies = [ - "crossbeam-deque", "either", "rayon-core", ] @@ -2773,9 +2774,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.36.3" +version = "0.36.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b1fbb4dfc4eb1d390c02df47760bb19a84bb80b301ecc947ab5406394d8223e" +checksum = "a3807b5d10909833d3e9acd1eb5fb988f79376ff10fce42937de71a449c4c588" dependencies = [ "bitflags", "errno", @@ -2808,15 +2809,15 @@ dependencies = [ [[package]] name = "rustversion" -version = "1.0.9" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97477e48b4cf8603ad5f7aaf897467cf42ab4218a38ef76fb14c2d6773a6d6a8" +checksum = "5583e89e108996506031660fe09baa5011b9dd0341b89029313006d1fb508d70" [[package]] name = "ryu" -version = "1.0.11" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" +checksum = "7b4b9743ed687d4b4bcedf9ff5eaa7398495ae14e61cba0a295704edbc7decde" [[package]] name = "salsa20" @@ -2838,9 +2839,9 @@ dependencies = [ [[package]] name = "scale-info" -version = "2.3.0" +version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88d8a765117b237ef233705cc2cc4c6a27fccd46eea6ef0c8c6dae5f3ef407f8" +checksum = "001cf62ece89779fd16105b5f515ad0e5cedcd5440d3dd806bb067978e7c3608" dependencies = [ "cfg-if", "derive_more", @@ -2850,9 +2851,9 @@ dependencies = [ [[package]] name = "scale-info-derive" -version = "2.3.0" +version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdcd47b380d8c4541044e341dcd9475f55ba37ddc50c908d945fc036a8642496" +checksum = "303959cf613a6f6efd19ed4b4ad5bf79966a13352716299ad532cfb115f4205c" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -2904,9 +2905,9 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.14" +version = "1.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e25dfac463d778e353db5be2449d1cce89bd6fd23c9f1ea21310ce6e5a1b29c4" +checksum = "58bc9567378fc7690d6b2addae4e60ac2eeea07becb2c64b9f218b53865cba2a" dependencies = [ "serde", ] @@ -2919,9 +2920,9 @@ checksum = "930c0acf610d3fdb5e2ab6213019aaa04e227ebe9547b0649ba599b16d788bd7" [[package]] name = "serde" -version = "1.0.147" +version = "1.0.151" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d193d69bae983fc11a79df82342761dfbf28a99fc8d203dca4c3c1b590948965" +checksum = "97fed41fc1a24994d044e6db6935e69511a1153b52c15eb42493b26fa87feba0" dependencies = [ "serde_derive", ] @@ -2938,9 +2939,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.147" +version = "1.0.151" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f1d362ca8fc9c3e3a7484440752472d68a6caa98f1ab81d99b5dfe517cec852" +checksum = "255abe9a125a985c05190d687b320c12f9b1f0b99445e608c21ba0782c719ad8" dependencies = [ "proc-macro2", "quote", @@ -2949,9 +2950,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.89" +version = "1.0.91" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "020ff22c755c2ed3f8cf162dbb41a7268d934702f3ed3631656ea597e08fc3db" +checksum = "877c235533714907a8c2464236f5c4b2a17262ef1bd71f38f35ea592c8da6883" dependencies = [ "itoa", "ryu", @@ -3184,9 +3185,9 @@ checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" [[package]] name = "syn" -version = "1.0.103" +version = "1.0.107" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a864042229133ada95abf3b54fdc62ef5ccabe9515b64717bcb9a1919e59445d" +checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" dependencies = [ "proc-macro2", "quote", @@ -3241,18 +3242,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.37" +version = "1.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10deb33631e3c9018b9baf9dcbbc4f737320d2b576bac10f6aefa048fa407e3e" +checksum = "6a9cd18aa97d5c45c6603caea1da6628790b37f7a34b6ca89522331c5180fed0" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.37" +version = "1.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "982d17546b47146b28f7c22e3d08465f6b8903d0ea13c1660d9d84a6e7adcdbb" +checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f" dependencies = [ "proc-macro2", "quote", @@ -3294,9 +3295,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "1.22.0" +version = "1.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d76ce4a75fb488c605c54bf610f221cea8b0dafb53333c1a67e8ee199dcd2ae3" +checksum = "eab6d665857cc6ca78d6e80303a02cea7a7851e85dfbd77cbdc09bd129f1ef46" dependencies = [ "autocfg", "bytes", @@ -3309,7 +3310,7 @@ dependencies = [ "signal-hook-registry", "socket2", "tokio-macros", - "winapi", + "windows-sys", ] [[package]] @@ -3324,9 +3325,9 @@ dependencies = [ [[package]] name = "tokio-macros" -version = "1.8.0" +version = "1.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9724f9a975fb987ef7a3cd9be0350edcbe130698af5b8f7a631e23d42d052484" +checksum = "d266c00fde287f55d3f1c3e96c500c362a2b8c695076ec180f27918820bc6df8" dependencies = [ "proc-macro2", "quote", @@ -3372,18 +3373,18 @@ dependencies = [ [[package]] name = "toml" -version = "0.5.9" +version = "0.5.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d82e1a7758622a465f8cee077614c73484dac5b836c02ff6a40d5d1010324d7" +checksum = "1333c76748e868a4d9d1017b5ab53171dfd095f70c712fdb4653a406547f598f" dependencies = [ "serde", ] [[package]] name = "tonic" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55b9af819e54b8f33d453655bef9b9acc171568fb49523078d0cc4e7484200ec" +checksum = "8f219fad3b929bef19b1f86fbc0358d35daed8f2cac972037ac0dc10bbb8d5fb" dependencies = [ "async-stream", "async-trait", @@ -3413,9 +3414,9 @@ dependencies = [ [[package]] name = "tonic-build" -version = "0.8.2" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48c6fd7c2581e36d63388a9e04c350c21beb7a8b059580b2e93993c526899ddc" +checksum = "5bf5e9b9c0f7e0a7c027dcfaba7b2c60816c7049171f679d99ee2ff65d0de8c4" dependencies = [ "prettyplease", "proc-macro2", @@ -3446,9 +3447,9 @@ dependencies = [ [[package]] name = "tower-http" -version = "0.3.4" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c530c8675c1dbf98facee631536fa116b5fb6382d7dd6dc1b118d970eafe3ba" +checksum = "f873044bf02dd1e8239e9c1293ea39dad76dc594ec16185d0a1bf31d8dc8d858" dependencies = [ "bitflags", "bytes", @@ -3552,15 +3553,15 @@ checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" [[package]] name = "typenum" -version = "1.15.0" +version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" +checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" [[package]] name = "uint" -version = "0.9.4" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a45526d29728d135c2900b0d30573fe3ee79fceb12ef534c7bb30e810a91b601" +checksum = "76f64bba2c53b04fcab63c01a7d7427eadc821e3bc48c34dc9ba29c501164b52" dependencies = [ "byteorder", "crunchy", @@ -3576,9 +3577,9 @@ checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" [[package]] name = "unicode-ident" -version = "1.0.5" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3" +checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" [[package]] name = "unicode-normalization" @@ -3770,9 +3771,9 @@ dependencies = [ [[package]] name = "webpki-roots" -version = "0.22.5" +version = "0.22.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "368bfe657969fb01238bb756d351dcade285e0f6fcbd36dcb23359a5169975be" +checksum = "b6c71e40d7d2c34a5106301fb632274ca37242cd0c9d3e64dbece371a40a2d87" dependencies = [ "webpki", ] diff --git a/Cargo.toml b/Cargo.toml index b6adc91c..b054f1ef 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,7 @@ clap = { version = "4", features = ["derive"] } dirs = "4.0" educe = { version = "0.4", features = ["Debug", "Default"] } ethereum-interfaces = { git = "https://github.com/ledgerwatch/interfaces" } -ethers = "1.0.0" +ethers = {version = "1.0.0", features = ["ethers-solc"]} expanded-pathbuf = "0.1" hex = { version = "0.4.3", default-features = false, features = ["std"] } jsonrpsee = { version = "0.16", features = ["server", "macros"] } @@ -30,6 +30,7 @@ tonic = { version = "0.8", default-features = false, features = [ tracing = "0.1" tracing-subscriber = "0.3" regex = "1" +eyre = "0.6.8" [build-dependencies] anyhow = "1" @@ -53,3 +54,7 @@ name = "bundler-rpc" [[bin]] path = "bin/create-wallet.rs" name = "create-wallet" + +[[bin]] +path = "bin/compile_contracts.rs" +name = "compile-contracts" \ No newline at end of file diff --git a/Makefile b/Makefile index 32621f4a..9fb3d85c 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,16 @@ cargo-fmt: cargo fmt --all cargo-test: + make fetch-thirdparty + make compile-thirdparty cargo test fetch-thirdparty: - git submodule update --init \ No newline at end of file + git submodule update --init && cd thirdparty/account-abstraction && yarn install && cd ../.. + +compile-thirdparty: + cargo run --bin compile-contracts + +clean: + cd thirdparty/account-abstraction && yarn clean && cd ../.. + cargo clean diff --git a/bin/compile_contracts.rs b/bin/compile_contracts.rs new file mode 100644 index 00000000..d20c9641 --- /dev/null +++ b/bin/compile_contracts.rs @@ -0,0 +1,6 @@ +use aa_bundler::contracts::compile_account_abstraction; + +fn main() -> anyhow::Result<()> { + compile_account_abstraction()?; + Ok(()) +} diff --git a/src/contracts/mod.rs b/src/contracts/mod.rs index 76713363..6fdad983 100644 --- a/src/contracts/mod.rs +++ b/src/contracts/mod.rs @@ -1,4 +1,21 @@ mod entrypoint; mod gen; +use std::path::PathBuf; + pub use entrypoint::*; +use ethers::solc::{Project, ProjectCompileOutput, ProjectPathsConfig}; + +// It would skip compiling if cached arctifacts are found +pub fn compile_account_abstraction() -> anyhow::Result { + let root = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("thirdparty/account-abstraction"); + let build_path_config = ProjectPathsConfig::hardhat(root)?; + let project = Project::builder().paths(build_path_config).build()?; + let compiled = project.compile()?; + assert!( + !compiled.has_compiler_errors(), + "Compile with errore:\n{:?}", + compiled.output().errors + ); + Ok(compiled) +} diff --git a/tests/common/gen.rs b/tests/common/gen.rs new file mode 100644 index 00000000..d8cb7d08 --- /dev/null +++ b/tests/common/gen.rs @@ -0,0 +1,10 @@ +use ethers::prelude::abigen; + +abigen!(SimpleAccountFactory, "$CARGO_MANIFEST_DIR/thirdparty/account-abstraction/artifacts/SimpleAccountFactory.sol/SimpleAccountFactory.json"); + +abigen!(SimpleAccount, "$CARGO_MANIFEST_DIR/thirdparty/account-abstraction/artifacts/SimpleAccount.sol/SimpleAccount.json"); + +abigen!( + EntryPointContract, + "$CARGO_MANIFEST_DIR/thirdparty/account-abstraction/artifacts/EntryPoint.sol/EntryPoint.json" +); diff --git a/tests/common/mod.rs b/tests/common/mod.rs new file mode 100644 index 00000000..33b7b665 --- /dev/null +++ b/tests/common/mod.rs @@ -0,0 +1,90 @@ +use std::{path::PathBuf, sync::Arc}; + +use aa_bundler::contracts::compile_account_abstraction; +use ethers::{ + abi::Abi, + prelude::ContractFactory, + providers::Middleware, + solc::{Artifact, Project, ProjectCompileOutput, ProjectPathsConfig}, + types::{Address, Bytes}, +}; +pub mod gen; + +pub const ANVIL_TEST_KEY_PHRASE: &'static str = + "test test test test test test test test test test test junk"; + +pub struct CompiledContract { + abi: Abi, + bytecode: Bytes, + runtime_bytecode: Bytes, +} + +pub struct AACompiledContracts { + entry_point: CompiledContract, + simple_account_factory: CompiledContract, +} +impl AACompiledContracts { + pub async fn deploy(self, client: Arc) -> anyhow::Result<(Address, Address)> + where + M: Middleware + 'static, + { + let AACompiledContracts { + entry_point, + simple_account_factory, + } = self; + let entry_point_contract = + ContractFactory::new(entry_point.abi, entry_point.bytecode, client.clone()) + .deploy(())? + .send() + .await?; + + let simple_account_factory = ContractFactory::new( + simple_account_factory.abi, + simple_account_factory.bytecode, + client, + ) + .deploy(entry_point_contract.address())? + .send() + .await?; + Ok(( + entry_point_contract.address(), + simple_account_factory.address(), + )) + } +} + +pub fn compile_project() -> anyhow::Result { + let compiled = compile_account_abstraction()?; + + let entry_point = compiled + .find_first("EntryPoint") + .expect("could not find contract"); + let (abi, bytecode, runtime_bytecode) = entry_point + .clone() + .into_compact_contract() + .into_parts_or_default(); + + let entry_point_contract = CompiledContract { + abi, + bytecode, + runtime_bytecode, + }; + + let simple_account_factory = compiled + .find_first("SimpleAccountFactory") + .expect("could not find contract"); + let (abi, bytecode, runtime_bytecode) = simple_account_factory + .clone() + .into_compact_contract() + .into_parts_or_default(); + let simple_account_factory = CompiledContract { + abi, + bytecode, + runtime_bytecode, + }; + + Ok(AACompiledContracts { + entry_point: entry_point_contract, + simple_account_factory: simple_account_factory, + }) +} diff --git a/tests/integration_test.rs b/tests/integration_test.rs new file mode 100644 index 00000000..b27a621c --- /dev/null +++ b/tests/integration_test.rs @@ -0,0 +1,153 @@ +pub mod common; + +use aa_bundler::contracts::EntryPoint; +use aa_bundler::types::user_operation::UserOperation; +use anyhow::Ok; +use ethers::prelude::k256::ecdsa::SigningKey; +use ethers::providers::Middleware; +use ethers::signers::Wallet; +use ethers::types::TransactionRequest; +use ethers::utils::WEI_IN_ETHER; +use ethers::{ + abi::Address, + core::utils::Anvil, + prelude::SignerMiddleware, + providers::{Http, Provider}, + signers::{coins_bip39::English, LocalWallet, MnemonicBuilder, Signer}, + types::{Bytes, U256}, +}; +use std::{convert::TryFrom, sync::Arc, time::Duration}; + +use crate::common::gen::SimpleAccountFactory; +use crate::common::{compile_project, ANVIL_TEST_KEY_PHRASE}; + +struct TestContest { + pub entry_point_address: Address, + pub simple_account_factory_address: Address, + pub owner_wallet: LocalWallet, + pub simple_account_address: Address, +} + +pub async fn sign( + user_op: &mut UserOperation, + entry_point_address: Address, + chain_id: U256, + key: Wallet, +) -> anyhow::Result<()> { + let user_op_hash = user_op.hash(entry_point_address, chain_id); + let signature = key.sign_message(user_op_hash.as_bytes()).await?; + user_op.signature = Bytes::from(signature.to_vec()); + Ok(()) +} + +async fn deploy_initial_contracts( + endpoint: String, + owner_wallet: LocalWallet, +) -> anyhow::Result { + let provider = + Arc::new(Provider::::try_from(endpoint)?.interval(Duration::from_millis(10u64))); + let chain_id = provider.clone().get_chainid().await?; + let client = SignerMiddleware::new( + provider, + owner_wallet.clone().with_chain_id(chain_id.as_u64()), + ); + let client = Arc::new(client); + let cimpiled_contracts = compile_project()?; + + // 1. deploy the entrypoint contract and the simple account factory contract + let (entry_point_address, simple_account_factory_address) = + cimpiled_contracts.deploy(client.clone()).await?; + + let simple_account_factory = + SimpleAccountFactory::new(simple_account_factory_address, client.clone()); + + // 2. create a simple account based on the simple account factory contract + let tx = simple_account_factory.create_account(owner_wallet.address(), U256::from(1)); + let simple_account_address = tx.clone().await?; + let res = tx.send().await?; + + // 3. send some initial money to the simple account address and make sure it could prepay + let tx = TransactionRequest::new() + .to(simple_account_address) + .value(U256::from(10) * WEI_IN_ETHER) + .from(owner_wallet.address()); + client.clone().send_transaction(tx, None).await?.await?; + let receipt = client + .clone() + .get_transaction_receipt(res.tx_hash()) + .await?; + println!( + "result: {:?}\n {:?}\n{:?}", + receipt, simple_account_factory_address, entry_point_address + ); + Ok(TestContest { + entry_point_address, + simple_account_factory_address, + owner_wallet, + simple_account_address, + }) +} + +#[tokio::test] +async fn interact_local() -> anyhow::Result<()> { + let wallet2: LocalWallet = MnemonicBuilder::::default() + .phrase(ANVIL_TEST_KEY_PHRASE) + .build() + .unwrap() + .into(); + deploy_initial_contracts("http://127.0.0.1:8545".to_string(), wallet2).await?; + Ok(()) +} + +#[tokio::test] +async fn interact_with_local() -> anyhow::Result<()> { + use aa_bundler::types::user_operation::UserOperation; + use std::convert::From; + let anvil = Anvil::new().spawn(); + + let context = + deploy_initial_contracts(anvil.endpoint(), anvil.keys()[0].clone().into()).await?; + let provider = Provider::try_from(anvil.endpoint())?.interval(Duration::from_millis(10u64)); + let wallet: LocalWallet = anvil.keys()[0].clone().into(); + let wallet2: LocalWallet = MnemonicBuilder::::default() + .phrase(ANVIL_TEST_KEY_PHRASE) + .build() + .unwrap() + .into(); + println!("signer : {:?}", wallet.address()); + println!("pk: {:?}", wallet2.address()); + let chain_id = provider.get_chainid().await?; + + let client = SignerMiddleware::new(provider, wallet.clone().with_chain_id(chain_id.as_u64())); + let client = Arc::new(client); + let chain_id = client.clone().get_chainid().await?; + println!( + "Currently working on chain id: {}, {:?}\n Entrypoint: {:?}", + chain_id, + wallet.address(), + context.entry_point_address + ); + let entry_point_contract = EntryPoint::new(client.clone(), context.entry_point_address.clone()); + let mut user_op = UserOperation { + sender: context.simple_account_address, + nonce: U256::zero(), + init_code: Bytes::default(), + call_data: Bytes::default(), + call_gas_limit: U256::from(200000), + verification_gas_limit: U256::from(100000), + pre_verification_gas: U256::from(21000), + max_fee_per_gas: U256::from(3000000000u64), + max_priority_fee_per_gas: U256::from(1000000000), + paymaster_and_data: Bytes::default(), + signature: Bytes::default(), + }; + + user_op.pack_for_signature(); + sign(&mut user_op, context.entry_point_address, chain_id, wallet).await?; + let hash = entry_point_contract + .simulate_validation(user_op) + .await + .expect("error"); + println!("{:?}", hash); + Ok(()) +}