From e7390e054361008b3f773b187ca1394e805d2eae Mon Sep 17 00:00:00 2001 From: Juan Rigada <62958725+Jrigada@users.noreply.github.com> Date: Fri, 13 Dec 2024 08:59:12 -0300 Subject: [PATCH] chore: Move zk tests to different files (#775) * Add zkout to gitignore template when in zksync forge init mode * Add test for forge init --zksync * Move zk test to a different file to avoid merge conflicts * Move aave test outside the file --- crates/cast/tests/cli/main.rs | 138 +------------------ crates/cast/tests/cli/zk.rs | 137 ++++++++++++++++++ crates/forge/tests/cli/build.rs | 14 +- crates/forge/tests/cli/cmd.rs | 72 ---------- crates/forge/tests/cli/ext_integration.rs | 7 - crates/forge/tests/cli/main.rs | 4 + crates/forge/tests/cli/script.rs | 110 +-------------- crates/forge/tests/cli/test_cmd.rs | 34 ----- crates/forge/tests/cli/zk_build.rs | 13 ++ crates/forge/tests/cli/zk_cmd.rs | 124 +++++++++++++++++ crates/forge/tests/cli/zk_ext_integration.rs | 8 ++ crates/forge/tests/cli/zk_script.rs | 111 +++++++++++++++ 12 files changed, 400 insertions(+), 372 deletions(-) create mode 100644 crates/cast/tests/cli/zk.rs create mode 100644 crates/forge/tests/cli/zk_build.rs create mode 100644 crates/forge/tests/cli/zk_cmd.rs create mode 100644 crates/forge/tests/cli/zk_ext_integration.rs create mode 100644 crates/forge/tests/cli/zk_script.rs diff --git a/crates/cast/tests/cli/main.rs b/crates/cast/tests/cli/main.rs index 0d945fe8f..f7e1c1b81 100644 --- a/crates/cast/tests/cli/main.rs +++ b/crates/cast/tests/cli/main.rs @@ -11,13 +11,9 @@ use foundry_test_utils::{ }, str, util::OutputExt, - ZkSyncNode, }; use std::{fs, io::Write, path::Path, str::FromStr}; - -const PAYMASTER_BYTECODE: &str = "0x0002000000000002000300000000000200000000030100190000006003300270000001080330019700010000003103550000008004000039000000400040043f00000001002001900000002d0000c13d000000040030008c000000380000413d000000000201043b000000e0022002700000010e0020009c0000003c0000213d000001120020009c000000760000613d000001130020009c000000b80000613d000001140020009c0000010b0000c13d0000000001000416000000000001004b0000010b0000c13d000000000100041a0000010a021001970000000005000411000000000052004b0000010d0000c13d0000010901100197000000000010041b0000000001000414000001080010009c0000010801008041000000c0011002100000010b011001c70000800d0200003900000003030000390000010c040000410000000006000019041c04120000040f00000001002001900000003a0000c13d0000010b0000013d0000000001000416000000000001004b0000010b0000c13d0000000006000411000000000006004b000000610000c13d0000011701000041000000000010043f000000040000043f00000116010000410000041e00010430000000000003004b0000010b0000c13d00000000010000190000041d0001042e0000010f0020009c000000dd0000613d000001100020009c000001030000613d000001110020009c0000010b0000c13d000000240030008c0000010b0000413d0000000002000416000000000002004b0000010b0000c13d0000000401100370000000000101043b0000010a0010009c0000010b0000213d000000000200041a0000010a032001970000000005000411000000000053004b0000010d0000c13d0000010a06100198000000330000613d0000010901200197000000000161019f000000000010041b0000000001000414000001080010009c0000010801008041000000c0011002100000010b011001c70000800d0200003900000003030000390000010c04000041041c04120000040f00000001002001900000003a0000c13d0000010b0000013d000000000100041a0000010902100197000000000262019f000000000020041b00000000020004140000010a05100197000001080020009c0000010802008041000000c0012002100000010b011001c70000800d0200003900000003030000390000010c04000041041c04120000040f00000001002001900000010b0000613d0000002001000039000001000010044300000120000004430000010d010000410000041d0001042e000000640030008c0000010b0000413d0000004402100370000000000402043b000001190040009c0000010b0000213d00000000054300490000011a0050009c0000010b0000213d000002640050008c0000010b0000413d0000000002000411000080010020008c000001170000c13d0000022402400039000000000621034f000000000606043b000000230550008a00000124076001970000012408500197000000000987013f000000000087004b00000000070000190000012407004041000000000056004b00000000050000190000012405008041000001240090009c000000000705c019000000000007004b0000010b0000c13d00000004044000390000000005640019000000000451034f000000000404043b000001190040009c0000010b0000213d0000000006430049000000200350003900000124056001970000012407300197000000000857013f000000000057004b00000000050000190000012405004041000000000063004b00000000060000190000012406002041000001240080009c000000000506c019000000000005004b0000010b0000c13d000000030040008c000001730000213d0000011f01000041000000800010043f0000002001000039000000840010043f0000003a01000039000000a40010043f0000013d01000041000000c40010043f0000013e01000041000000e40010043f00000123010000410000041e00010430000000240030008c0000010b0000413d0000000002000416000000000002004b0000010b0000c13d0000000401100370000000000301043b0000010a0030009c0000010b0000213d000000000100041a0000010a021001970000000001000411000000000012004b000001120000c13d000300000003001d0000011b010000410000000000100443000000000100041000000004001004430000000001000414000001080010009c0000010801008041000000c0011002100000011c011001c70000800a02000039041c04170000040f0000000100200190000001bb0000613d00000003020000290000010a04200197000000000301043b0000000001000414000000040040008c000001230000c13d00000001020000390000000001000031000001320000013d000000c40030008c0000010b0000413d0000000402100370000000000202043b000001190020009c0000010b0000213d0000002304200039000000000034004b0000010b0000813d0000000404200039000000000441034f000000000404043b000001190040009c0000010b0000213d00000000024200190000002402200039000000000032004b0000010b0000213d0000002402100370000000000202043b000001190020009c0000010b0000213d00000000022300490000011a0020009c0000010b0000213d000002640020008c0000010b0000413d0000008401100370000000000101043b000000010010008c0000010b0000213d0000000001000411000080010010008c00000000010000390000000101006039041c03fa0000040f00000000010000190000041d0001042e0000000001000416000000000001004b0000010b0000c13d000000000100041a0000010a01100197000000800010043f00000118010000410000041d0001042e00000000010000190000041e000104300000011501000041000000000010043f000000040050043f00000116010000410000041e000104300000011502000041000000000020043f000000040010043f00000116010000410000041e000104300000011f01000041000000800010043f0000002001000039000000840010043f0000002401000039000000a40010043f0000012101000041000000c40010043f0000012201000041000000e40010043f00000123010000410000041e00010430000001080010009c0000010801008041000000c001100210000000000003004b0000012a0000c13d00000000020400190000012d0000013d0000010b011001c700008009020000390000000005000019041c04120000040f00010000000103550000006001100270000001080010019d0000010801100197000000000001004b0000014a0000c13d00000001002001900000003a0000c13d000000400100043d00000064021000390000011d03000041000000000032043500000044021000390000011e0300004100000000003204350000002402100039000000280300003900000000003204350000011f020000410000000000210435000000040210003900000020030000390000000000320435000001080010009c0000010801008041000000400110021000000120011001c70000041e00010430000001190010009c000001b50000213d0000001f041000390000013f044001970000003f044000390000013f05400197000000400400043d0000000005540019000000000045004b00000000060000390000000106004039000001190050009c000001b50000213d0000000100600190000001b50000c13d000000400050043f00000000061404360000013f031001980000001f0410018f00000000013600190000000105000367000001650000613d000000000705034f000000007807043c0000000006860436000000000016004b000001610000c13d000000000004004b000001340000613d000000000335034f0000000304400210000000000501043300000000054501cf000000000545022f000000000303043b0000010004400089000000000343022f00000000034301cf000000000353019f0000000000310435000001340000013d000000000331034f000000000303043b0000012503300197000001260030009c000001bc0000c13d000001c00320008a000000000331034f000001800220008a000000000121034f000000000201043b000000000103043b000300000002001d00000000031200a9000200000001001d000000000001004b000001860000613d00000002013000fa000000030010006b000001c80000c13d0000000b01000039000000800010043f0000012a02000041000000a00020043f0000012b02000041000000e00020043f0000004002000039000000e40020043f000001240010043f000001440100043d0000012c011001970000012a011001c7000001440010043f0000014f0000043f000100000003001d000001040030043f0000008401000039000000c00010043f0000018001000039000000400010043f0000000001000414000001080010009c0000010801008041000000c0011002100000012d011001c70000012e02000041041c04170000040f00000000020100190000006002200270000001080020019d00010000000103550000011b010000410000000000100443000000000100041000000004001004430000000001000414000001080010009c0000010801008041000000c0011002100000011c011001c70000800a02000039041c04170000040f0000000100200190000001bb0000613d000000400400043d0000012f0040009c000001ce0000413d0000012901000041000000000010043f0000004101000039000000040010043f00000116010000410000041e00010430000000000001042f0000011f01000041000000800010043f0000002001000039000000840010043f0000002e01000039000000a40010043f0000012701000041000000c40010043f0000012801000041000000e40010043f00000123010000410000041e000104300000012901000041000000000010043f0000001101000039000000040010043f00000116010000410000041e00010430000000000301043b0000004001400039000000400010043f00000020054000390000013001000041000000000015043500000007010000390000000000140435000000400100043d00000020021000390000012b0600004100000000006204350000002406100039000000400700003900000000007604350000000004040433000000640610003900000000004604350000013f084001970000001f0740018f0000008406100039000000000065004b000001f50000813d000000000008004b000001f10000613d000000000a7500190000000009760019000000200990008a000000200aa0008a000000000b890019000000000c8a0019000000000c0c04330000000000cb0435000000200880008c000001eb0000c13d000000000007004b0000020b0000613d0000000009060019000002010000013d0000000009860019000000000008004b000001fe0000613d000000000a050019000000000b06001900000000ac0a0434000000000bcb043600000000009b004b000001fa0000c13d000000000007004b0000020b0000613d00000000058500190000000307700210000000000809043300000000087801cf000000000878022f00000000050504330000010007700089000000000575022f00000000057501cf000000000585019f000000000059043500000000056400190000000000050435000000440510003900000000003504350000001f034000390000013f05000041000000000353016f00000064043000390000000000410435000000a303300039000000000453016f0000000003140019000000000043004b00000000040000390000000104004039000001190030009c000001b50000213d0000000100400190000001b50000c13d000000400030043f000001080020009c000001080200804100000040022002100000000001010433000001080010009c00000108010080410000006001100210000000000121019f0000000002000414000001080020009c0000010802008041000000c002200210000000000121019f0000012e02000041041c04170000040f00000000020100190000006002200270000001080020019d0001000000010355000000400300043d000001310030009c000001b50000213d0000004001300039000000400010043f00000020043000390000013201000041000000000014043500000009010000390000000000130435000000400100043d00000020021000390000012b05000041000000000052043500000024051000390000004006000039000000000065043500000000030304330000006405100039000000000035043500000000050004160000013f083001970000001f0730018f0000008406100039000000000064004b0000025c0000813d000000000008004b000002580000613d000000000a7400190000000009760019000000200990008a000000200aa0008a000000000b890019000000000c8a0019000000000c0c04330000000000cb0435000000200880008c000002520000c13d000000000007004b000002720000613d0000000009060019000002680000013d0000000009860019000000000008004b000002650000613d000000000a040019000000000b06001900000000ac0a0434000000000bcb043600000000009b004b000002610000c13d000000000007004b000002720000613d00000000048400190000000307700210000000000809043300000000087801cf000000000878022f00000000040404330000010007700089000000000474022f00000000047401cf000000000484019f000000000049043500000000046300190000000000040435000000440410003900000000005404350000001f033000390000013f05000041000000000353016f00000064043000390000000000410435000000a303300039000000000453016f0000000003140019000000000043004b00000000040000390000000104004039000001190030009c000001b50000213d0000000100400190000001b50000c13d000000400030043f000001080020009c000001080200804100000040022002100000000001010433000001080010009c00000108010080410000006001100210000000000121019f0000000002000414000001080020009c0000010802008041000000c002200210000000000121019f0000012e02000041041c04170000040f00000000020100190000006002200270000001080020019d0001000000010355000000400300043d000001310030009c000001b50000213d0000004001300039000000400010043f00000020043000390000013301000041000000000014043500000008010000390000000000130435000000400100043d00000020021000390000012b0500004100000000005204350000002405100039000000400600003900000000006504350000000003030433000000640510003900000000003504350000013f073001970000001f0630018f0000008405100039000000000054004b000002c20000813d000000000007004b000002be0000613d00000000096400190000000008650019000000200880008a000000200990008a000000000a780019000000000b790019000000000b0b04330000000000ba0435000000200770008c000002b80000c13d000000000006004b000002d80000613d0000000008050019000002ce0000013d0000000008750019000000000007004b000002cb0000613d0000000009040019000000000a050019000000009b090434000000000aba043600000000008a004b000002c70000c13d000000000006004b000002d80000613d00000000047400190000000306600210000000000708043300000000076701cf000000000767022f00000000040404330000010006600089000000000464022f00000000046401cf000000000474019f0000000000480435000000000453001900000000000404350000004404100039000000030500002900000000005404350000001f033000390000013f05000041000000000353016f00000064043000390000000000410435000000a303300039000000000453016f0000000003140019000000000043004b00000000040000390000000104004039000001190030009c000001b50000213d0000000100400190000001b50000c13d000000400030043f000001080020009c000001080200804100000040022002100000000001010433000001080010009c00000108010080410000006001100210000000000121019f0000000002000414000001080020009c0000010802008041000000c002200210000000000121019f0000012e02000041041c04170000040f00000000020100190000006002200270000001080020019d0001000000010355000000400300043d000001310030009c000001b50000213d0000004001300039000000400010043f00000020043000390000013401000041000000000014043500000008010000390000000000130435000000400100043d00000020021000390000012b0500004100000000005204350000002405100039000000400600003900000000006504350000000003030433000000640510003900000000003504350000013f073001970000001f0630018f0000008405100039000000000054004b000003290000813d000000000007004b000003250000613d00000000096400190000000008650019000000200880008a000000200990008a000000000a780019000000000b790019000000000b0b04330000000000ba0435000000200770008c0000031f0000c13d000000000006004b0000033f0000613d0000000008050019000003350000013d0000000008750019000000000007004b000003320000613d0000000009040019000000000a050019000000009b090434000000000aba043600000000008a004b0000032e0000c13d000000000006004b0000033f0000613d00000000047400190000000306600210000000000708043300000000076701cf000000000767022f00000000040404330000010006600089000000000464022f00000000046401cf000000000474019f0000000000480435000000000453001900000000000404350000004404100039000000020500002900000000005404350000001f033000390000013f05000041000000000353016f00000064043000390000000000410435000000a303300039000000000453016f0000000003140019000000000043004b00000000040000390000000104004039000001190030009c000001b50000213d0000000100400190000001b50000c13d000000400030043f000001080020009c000001080200804100000040022002100000000001010433000001080010009c00000108010080410000006001100210000000000121019f0000000002000414000001080020009c0000010802008041000000c002200210000000000121019f0000012e02000041041c04170000040f00000000020100190000006002200270000001080020019d00010000000103550000000001000414000001080010009c0000010801008041000000c001100210000000010000006b0000036f0000c13d0000800102000039000003740000013d0000010b011001c70000800902000039000080010400003900000001030000290000000005000019041c04120000040f000100000001035500000000030100190000006003300270000001080030019d00000108033001980000039b0000c13d000000400100043d0000000100200190000003c10000613d0000002002100039000000400300003900000000003204350000013c0200004100000000002104350000004003100039000000600200043d00000000002304350000013f052001970000001f0420018f0000006003100039000000810030008c000003d70000413d000000000005004b000003960000613d000000000743001900000060064001bf000000200770008a0000000008570019000000000956001900000000090904330000000000980435000000200550008c000003900000c13d000000000004004b000003ed0000613d00000080050000390000000006030019000003e30000013d0000001f0430003900000135044001970000003f044000390000013604400197000000400500043d0000000004450019000000000054004b00000000060000390000000106004039000001190040009c000001b50000213d0000000100600190000001b50000c13d000000400040043f0000001f0430018f000000000635043600000137053001980000000003560019000003b30000613d000000000701034f000000007807043c0000000006860436000000000036004b000003af0000c13d000000000004004b0000037b0000613d000000000151034f0000000304400210000000000503043300000000054501cf000000000545022f000000000101043b0000010004400089000000000141022f00000000014101cf000000000151019f00000000001304350000037b0000013d00000084021000390000013803000041000000000032043500000064021000390000013903000041000000000032043500000044021000390000013a0300004100000000003204350000002402100039000000530300003900000000003204350000011f020000410000000000210435000000040210003900000020030000390000000000320435000001080010009c000001080100804100000040011002100000013b011001c70000041e000104300000000006530019000000000005004b0000008009000039000003e00000613d000000000703001900000000980904340000000007870436000000000067004b000003dc0000c13d000000000004004b000003ed0000613d00000080055000390000000304400210000000000706043300000000074701cf000000000747022f00000000050504330000010004400089000000000545022f00000000044501cf000000000474019f00000000004604350000001f042000390000013f04400197000000000232001900000000000204350000006002400039000001080020009c00000108020080410000006002200210000001080010009c00000108010080410000004001100210000000000112019f0000041d0001042e000000000001004b000003fd0000613d000000000001042d000000400100043d0000006402100039000001220300004100000000003204350000004402100039000001210300004100000000003204350000002402100039000000240300003900000000003204350000011f020000410000000000210435000000040210003900000020030000390000000000320435000001080010009c0000010801008041000000400110021000000120011001c70000041e00010430000000000001042f00000415002104210000000102000039000000000001042d0000000002000019000000000001042d0000041a002104230000000102000039000000000001042d0000000002000019000000000001042d0000041c000004320000041d0001042e0000041e00010430000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffffffffffff0000000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffffffffffffffffffff02000000000000000000000000000000000000000000000000000000000000008be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0000000020000000000000000000000000000004000000100000000000000000000000000000000000000000000000000000000000000000000000000817b17ef00000000000000000000000000000000000000000000000000000000817b17f0000000000000000000000000000000000000000000000000000000008da5cb5b00000000000000000000000000000000000000000000000000000000f2fde38b00000000000000000000000000000000000000000000000000000000038a24bc0000000000000000000000000000000000000000000000000000000051cff8d900000000000000000000000000000000000000000000000000000000715018a6118cdaa70000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000240000000000000000000000001e4fbdf7000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000800000000000000000000000000000000000000000000000000000000000000000ffffffffffffffff7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9cc7f708afc65944829bd487b90b72536b1951864fbfc14e125fc972a6507f390200000200000000000000000000000000000024000000000000000000000000796d61737465722e0000000000000000000000000000000000000000000000004661696c656420746f2077697468647261772066756e64732066726f6d20706108c379a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000840000000000000000000000004f6e6c7920626f6f746c6f616465722063616e2063616c6c2074686973206d6574686f640000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000840000008000000000000000008000000000000000000000000000000000000000000000000000000000000000ffffffff000000000000000000000000000000000000000000000000000000008c5a344500000000000000000000000000000000000000000000000000000000556e737570706f72746564207061796d617374657220666c6f7720696e207061796d6173746572506172616d732e0000000000000000000000000000000000004e487b710000000000000000000000000000000000000000000000000000000072657175697265644554480000000000000000000000000000000000000000009710a9d0000000000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffffffffffffffffffffff0000000000000000000000000000000000000084000000e00000000000000000000000000000000000000000000000000000000000636f6e736f6c652e6c6f67000000000000000000000000000000000000000000000000ffffffffffffffc062616c616e636500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffffbf6d73672e76616c7565000000000000000000000000000000000000000000000067617350726963650000000000000000000000000000000000000000000000006761734c696d697400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001ffffffe000000000000000000000000000000000000000000000000000000003ffffffe000000000000000000000000000000000000000000000000000000000ffffffe069676874206e6f7420626520656e6f7567682e0000000000000000000000000020426f6f746c6f616465722e205061796d61737465722062616c616e6365206d4661696c656420746f207472616e736665722074782066656520746f2074686500000000000000000000000000000000000000a4000000000000000000000000038a24bc00000000000000000000000000000000000000000000000000000000546865207374616e64617264207061796d617374657220696e707574206d757374206265206174206c656173742034206279746573206c6f6e67000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0665706818478a33d2e5c855cee339a5e2954659335637b967b7e5433b81a588b"; - -const COUNTER_BYTECODE: &str = "0x0000008003000039000000400030043f0000000100200190000000150000c13d000000000201001900000010002001980000002d0000613d000000000101043b000000e001100270000000110010009c000000200000613d000000120010009c0000002d0000c13d0000000001000416000000000001004b0000002d0000c13d000000000100041a000000ff0110018f000000800010043f0000001501000041000000370001042e0000000001000416000000000001004b0000002d0000c13d000000000200041a0000001601200197000000000010041b0000002001000039000001000010044300000120000004430000000f01000041000000370001042e0000000001000416000000000001004b0000002d0000c13d000000000100041a000000ff0210018f000000ff0020008c0000002f0000c13d0000001301000041000000000010043f0000001101000039000000040010043f000000140100004100000038000104300000000001000019000000380001043000000016021001970000000101100039000000ff0110018f000000000121019f000000000010041b0000000001000019000000370001042e0000003600000432000000370001042e0000003800010430000000000000000000000000000000000000000000000000000000020000000000000000000000000000004000000100000000000000000000000000000000000000000000000000fffffffc00000000000000000000000000000000000000000000000000000000000000000000000000000000d09de08a000000000000000000000000000000000000000000000000000000008381f58a4e487b710000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000240000000000000000000000000000000000000000000000000000000000000020000000800000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000000000000000000000000000000000000000000000000000000000000027b95d8697efbdb44a7508247e8c640a64fb3ead050f40cb23deb1910c501315"; +mod zk; // tests `--help` is printed to std out casttest!(print_help, |_prj, cmd| { @@ -1601,135 +1597,3 @@ casttest!(fetch_artifact_from_etherscan, |_prj, cmd| { "#]]); }); - -casttest!(zk_cast_using_paymaster, async |_prj, cmd| { - let node = ZkSyncNode::start(); - let url = node.url(); - - let (addr, private_key) = ZkSyncNode::rich_wallets() - .next() - .map(|(addr, pk, _)| (addr, pk)) - .expect("No rich wallets available"); - - // Deploy paymaster - cmd.args([ - "rpc", - "hardhat_setCode", - "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - PAYMASTER_BYTECODE, - "--rpc-url", - &url, - ]) - .assert_success(); - - // Deploy counter - cmd.cast_fuse() - .args([ - "rpc", - "hardhat_setCode", - "0x70997970C51812dc3A010C7d01b50e0d17dc79C8", - COUNTER_BYTECODE, - "--rpc-url", - &url, - ]) - .assert_success(); - - // Fund the paymaster - cmd.cast_fuse() - .args([ - "send", - "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - "0x", - "--value", - "0.1ether", - "--private-key", - private_key, - "--rpc-url", - &url, - ]) - .assert_success(); - - let balance_before = cmd - .cast_fuse() - .args(["balance", addr, "--rpc-url", &url]) - .assert_success() - .get_output() - .stdout_lossy(); - - // Interact with the counter using the paymaster - cmd.cast_fuse().args([ - "send", - "0x70997970C51812dc3A010C7d01b50e0d17dc79C8", - "increment()", - "--private-key", - private_key, - "--zk-paymaster-address", - "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - "--zk-paymaster-input", - "0x8c5a344500000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000", - "--rpc-url", - &url - ]) - .assert_success(); - - let balance_after = cmd - .cast_fuse() - .args(["balance", addr, "--rpc-url", &url]) - .assert_success() - .get_output() - .stdout_lossy(); - - assert_eq!(balance_after, balance_before); -}); - -casttest!(zk_cast_without_paymaster, async |_prj, cmd| { - let node = ZkSyncNode::start(); - let url = node.url(); - - let (addr, private_key) = ZkSyncNode::rich_wallets() - .next() - .map(|(addr, pk, _)| (addr, pk)) - .expect("No rich wallets available"); - - // Deploy counter - cmd.cast_fuse() - .args([ - "rpc", - "hardhat_setCode", - "0x70997970C51812dc3A010C7d01b50e0d17dc79C8", - COUNTER_BYTECODE, - "--rpc-url", - &url, - ]) - .assert_success(); - - let balance_before = cmd - .cast_fuse() - .args(["balance", addr, "--rpc-url", &url]) - .assert_success() - .get_output() - .stdout_lossy(); - - cmd.cast_fuse() - .args([ - "send", - "0x70997970C51812dc3A010C7d01b50e0d17dc79C8", - "increment()", - "--private-key", - private_key, - "--rpc-url", - &url, - "--gas-price", - "1000000000000002", - ]) - .assert_success(); - - let balance_after = cmd - .cast_fuse() - .args(["balance", addr, "--rpc-url", &url]) - .assert_success() - .get_output() - .stdout_lossy(); - - assert!(balance_after != balance_before); -}); diff --git a/crates/cast/tests/cli/zk.rs b/crates/cast/tests/cli/zk.rs new file mode 100644 index 000000000..894431854 --- /dev/null +++ b/crates/cast/tests/cli/zk.rs @@ -0,0 +1,137 @@ +use foundry_test_utils::{casttest, util::OutputExt, ZkSyncNode}; + +const PAYMASTER_BYTECODE: &str = "0x0002000000000002000300000000000200000000030100190000006003300270000001080330019700010000003103550000008004000039000000400040043f00000001002001900000002d0000c13d000000040030008c000000380000413d000000000201043b000000e0022002700000010e0020009c0000003c0000213d000001120020009c000000760000613d000001130020009c000000b80000613d000001140020009c0000010b0000c13d0000000001000416000000000001004b0000010b0000c13d000000000100041a0000010a021001970000000005000411000000000052004b0000010d0000c13d0000010901100197000000000010041b0000000001000414000001080010009c0000010801008041000000c0011002100000010b011001c70000800d0200003900000003030000390000010c040000410000000006000019041c04120000040f00000001002001900000003a0000c13d0000010b0000013d0000000001000416000000000001004b0000010b0000c13d0000000006000411000000000006004b000000610000c13d0000011701000041000000000010043f000000040000043f00000116010000410000041e00010430000000000003004b0000010b0000c13d00000000010000190000041d0001042e0000010f0020009c000000dd0000613d000001100020009c000001030000613d000001110020009c0000010b0000c13d000000240030008c0000010b0000413d0000000002000416000000000002004b0000010b0000c13d0000000401100370000000000101043b0000010a0010009c0000010b0000213d000000000200041a0000010a032001970000000005000411000000000053004b0000010d0000c13d0000010a06100198000000330000613d0000010901200197000000000161019f000000000010041b0000000001000414000001080010009c0000010801008041000000c0011002100000010b011001c70000800d0200003900000003030000390000010c04000041041c04120000040f00000001002001900000003a0000c13d0000010b0000013d000000000100041a0000010902100197000000000262019f000000000020041b00000000020004140000010a05100197000001080020009c0000010802008041000000c0012002100000010b011001c70000800d0200003900000003030000390000010c04000041041c04120000040f00000001002001900000010b0000613d0000002001000039000001000010044300000120000004430000010d010000410000041d0001042e000000640030008c0000010b0000413d0000004402100370000000000402043b000001190040009c0000010b0000213d00000000054300490000011a0050009c0000010b0000213d000002640050008c0000010b0000413d0000000002000411000080010020008c000001170000c13d0000022402400039000000000621034f000000000606043b000000230550008a00000124076001970000012408500197000000000987013f000000000087004b00000000070000190000012407004041000000000056004b00000000050000190000012405008041000001240090009c000000000705c019000000000007004b0000010b0000c13d00000004044000390000000005640019000000000451034f000000000404043b000001190040009c0000010b0000213d0000000006430049000000200350003900000124056001970000012407300197000000000857013f000000000057004b00000000050000190000012405004041000000000063004b00000000060000190000012406002041000001240080009c000000000506c019000000000005004b0000010b0000c13d000000030040008c000001730000213d0000011f01000041000000800010043f0000002001000039000000840010043f0000003a01000039000000a40010043f0000013d01000041000000c40010043f0000013e01000041000000e40010043f00000123010000410000041e00010430000000240030008c0000010b0000413d0000000002000416000000000002004b0000010b0000c13d0000000401100370000000000301043b0000010a0030009c0000010b0000213d000000000100041a0000010a021001970000000001000411000000000012004b000001120000c13d000300000003001d0000011b010000410000000000100443000000000100041000000004001004430000000001000414000001080010009c0000010801008041000000c0011002100000011c011001c70000800a02000039041c04170000040f0000000100200190000001bb0000613d00000003020000290000010a04200197000000000301043b0000000001000414000000040040008c000001230000c13d00000001020000390000000001000031000001320000013d000000c40030008c0000010b0000413d0000000402100370000000000202043b000001190020009c0000010b0000213d0000002304200039000000000034004b0000010b0000813d0000000404200039000000000441034f000000000404043b000001190040009c0000010b0000213d00000000024200190000002402200039000000000032004b0000010b0000213d0000002402100370000000000202043b000001190020009c0000010b0000213d00000000022300490000011a0020009c0000010b0000213d000002640020008c0000010b0000413d0000008401100370000000000101043b000000010010008c0000010b0000213d0000000001000411000080010010008c00000000010000390000000101006039041c03fa0000040f00000000010000190000041d0001042e0000000001000416000000000001004b0000010b0000c13d000000000100041a0000010a01100197000000800010043f00000118010000410000041d0001042e00000000010000190000041e000104300000011501000041000000000010043f000000040050043f00000116010000410000041e000104300000011502000041000000000020043f000000040010043f00000116010000410000041e000104300000011f01000041000000800010043f0000002001000039000000840010043f0000002401000039000000a40010043f0000012101000041000000c40010043f0000012201000041000000e40010043f00000123010000410000041e00010430000001080010009c0000010801008041000000c001100210000000000003004b0000012a0000c13d00000000020400190000012d0000013d0000010b011001c700008009020000390000000005000019041c04120000040f00010000000103550000006001100270000001080010019d0000010801100197000000000001004b0000014a0000c13d00000001002001900000003a0000c13d000000400100043d00000064021000390000011d03000041000000000032043500000044021000390000011e0300004100000000003204350000002402100039000000280300003900000000003204350000011f020000410000000000210435000000040210003900000020030000390000000000320435000001080010009c0000010801008041000000400110021000000120011001c70000041e00010430000001190010009c000001b50000213d0000001f041000390000013f044001970000003f044000390000013f05400197000000400400043d0000000005540019000000000045004b00000000060000390000000106004039000001190050009c000001b50000213d0000000100600190000001b50000c13d000000400050043f00000000061404360000013f031001980000001f0410018f00000000013600190000000105000367000001650000613d000000000705034f000000007807043c0000000006860436000000000016004b000001610000c13d000000000004004b000001340000613d000000000335034f0000000304400210000000000501043300000000054501cf000000000545022f000000000303043b0000010004400089000000000343022f00000000034301cf000000000353019f0000000000310435000001340000013d000000000331034f000000000303043b0000012503300197000001260030009c000001bc0000c13d000001c00320008a000000000331034f000001800220008a000000000121034f000000000201043b000000000103043b000300000002001d00000000031200a9000200000001001d000000000001004b000001860000613d00000002013000fa000000030010006b000001c80000c13d0000000b01000039000000800010043f0000012a02000041000000a00020043f0000012b02000041000000e00020043f0000004002000039000000e40020043f000001240010043f000001440100043d0000012c011001970000012a011001c7000001440010043f0000014f0000043f000100000003001d000001040030043f0000008401000039000000c00010043f0000018001000039000000400010043f0000000001000414000001080010009c0000010801008041000000c0011002100000012d011001c70000012e02000041041c04170000040f00000000020100190000006002200270000001080020019d00010000000103550000011b010000410000000000100443000000000100041000000004001004430000000001000414000001080010009c0000010801008041000000c0011002100000011c011001c70000800a02000039041c04170000040f0000000100200190000001bb0000613d000000400400043d0000012f0040009c000001ce0000413d0000012901000041000000000010043f0000004101000039000000040010043f00000116010000410000041e00010430000000000001042f0000011f01000041000000800010043f0000002001000039000000840010043f0000002e01000039000000a40010043f0000012701000041000000c40010043f0000012801000041000000e40010043f00000123010000410000041e000104300000012901000041000000000010043f0000001101000039000000040010043f00000116010000410000041e00010430000000000301043b0000004001400039000000400010043f00000020054000390000013001000041000000000015043500000007010000390000000000140435000000400100043d00000020021000390000012b0600004100000000006204350000002406100039000000400700003900000000007604350000000004040433000000640610003900000000004604350000013f084001970000001f0740018f0000008406100039000000000065004b000001f50000813d000000000008004b000001f10000613d000000000a7500190000000009760019000000200990008a000000200aa0008a000000000b890019000000000c8a0019000000000c0c04330000000000cb0435000000200880008c000001eb0000c13d000000000007004b0000020b0000613d0000000009060019000002010000013d0000000009860019000000000008004b000001fe0000613d000000000a050019000000000b06001900000000ac0a0434000000000bcb043600000000009b004b000001fa0000c13d000000000007004b0000020b0000613d00000000058500190000000307700210000000000809043300000000087801cf000000000878022f00000000050504330000010007700089000000000575022f00000000057501cf000000000585019f000000000059043500000000056400190000000000050435000000440510003900000000003504350000001f034000390000013f05000041000000000353016f00000064043000390000000000410435000000a303300039000000000453016f0000000003140019000000000043004b00000000040000390000000104004039000001190030009c000001b50000213d0000000100400190000001b50000c13d000000400030043f000001080020009c000001080200804100000040022002100000000001010433000001080010009c00000108010080410000006001100210000000000121019f0000000002000414000001080020009c0000010802008041000000c002200210000000000121019f0000012e02000041041c04170000040f00000000020100190000006002200270000001080020019d0001000000010355000000400300043d000001310030009c000001b50000213d0000004001300039000000400010043f00000020043000390000013201000041000000000014043500000009010000390000000000130435000000400100043d00000020021000390000012b05000041000000000052043500000024051000390000004006000039000000000065043500000000030304330000006405100039000000000035043500000000050004160000013f083001970000001f0730018f0000008406100039000000000064004b0000025c0000813d000000000008004b000002580000613d000000000a7400190000000009760019000000200990008a000000200aa0008a000000000b890019000000000c8a0019000000000c0c04330000000000cb0435000000200880008c000002520000c13d000000000007004b000002720000613d0000000009060019000002680000013d0000000009860019000000000008004b000002650000613d000000000a040019000000000b06001900000000ac0a0434000000000bcb043600000000009b004b000002610000c13d000000000007004b000002720000613d00000000048400190000000307700210000000000809043300000000087801cf000000000878022f00000000040404330000010007700089000000000474022f00000000047401cf000000000484019f000000000049043500000000046300190000000000040435000000440410003900000000005404350000001f033000390000013f05000041000000000353016f00000064043000390000000000410435000000a303300039000000000453016f0000000003140019000000000043004b00000000040000390000000104004039000001190030009c000001b50000213d0000000100400190000001b50000c13d000000400030043f000001080020009c000001080200804100000040022002100000000001010433000001080010009c00000108010080410000006001100210000000000121019f0000000002000414000001080020009c0000010802008041000000c002200210000000000121019f0000012e02000041041c04170000040f00000000020100190000006002200270000001080020019d0001000000010355000000400300043d000001310030009c000001b50000213d0000004001300039000000400010043f00000020043000390000013301000041000000000014043500000008010000390000000000130435000000400100043d00000020021000390000012b0500004100000000005204350000002405100039000000400600003900000000006504350000000003030433000000640510003900000000003504350000013f073001970000001f0630018f0000008405100039000000000054004b000002c20000813d000000000007004b000002be0000613d00000000096400190000000008650019000000200880008a000000200990008a000000000a780019000000000b790019000000000b0b04330000000000ba0435000000200770008c000002b80000c13d000000000006004b000002d80000613d0000000008050019000002ce0000013d0000000008750019000000000007004b000002cb0000613d0000000009040019000000000a050019000000009b090434000000000aba043600000000008a004b000002c70000c13d000000000006004b000002d80000613d00000000047400190000000306600210000000000708043300000000076701cf000000000767022f00000000040404330000010006600089000000000464022f00000000046401cf000000000474019f0000000000480435000000000453001900000000000404350000004404100039000000030500002900000000005404350000001f033000390000013f05000041000000000353016f00000064043000390000000000410435000000a303300039000000000453016f0000000003140019000000000043004b00000000040000390000000104004039000001190030009c000001b50000213d0000000100400190000001b50000c13d000000400030043f000001080020009c000001080200804100000040022002100000000001010433000001080010009c00000108010080410000006001100210000000000121019f0000000002000414000001080020009c0000010802008041000000c002200210000000000121019f0000012e02000041041c04170000040f00000000020100190000006002200270000001080020019d0001000000010355000000400300043d000001310030009c000001b50000213d0000004001300039000000400010043f00000020043000390000013401000041000000000014043500000008010000390000000000130435000000400100043d00000020021000390000012b0500004100000000005204350000002405100039000000400600003900000000006504350000000003030433000000640510003900000000003504350000013f073001970000001f0630018f0000008405100039000000000054004b000003290000813d000000000007004b000003250000613d00000000096400190000000008650019000000200880008a000000200990008a000000000a780019000000000b790019000000000b0b04330000000000ba0435000000200770008c0000031f0000c13d000000000006004b0000033f0000613d0000000008050019000003350000013d0000000008750019000000000007004b000003320000613d0000000009040019000000000a050019000000009b090434000000000aba043600000000008a004b0000032e0000c13d000000000006004b0000033f0000613d00000000047400190000000306600210000000000708043300000000076701cf000000000767022f00000000040404330000010006600089000000000464022f00000000046401cf000000000474019f0000000000480435000000000453001900000000000404350000004404100039000000020500002900000000005404350000001f033000390000013f05000041000000000353016f00000064043000390000000000410435000000a303300039000000000453016f0000000003140019000000000043004b00000000040000390000000104004039000001190030009c000001b50000213d0000000100400190000001b50000c13d000000400030043f000001080020009c000001080200804100000040022002100000000001010433000001080010009c00000108010080410000006001100210000000000121019f0000000002000414000001080020009c0000010802008041000000c002200210000000000121019f0000012e02000041041c04170000040f00000000020100190000006002200270000001080020019d00010000000103550000000001000414000001080010009c0000010801008041000000c001100210000000010000006b0000036f0000c13d0000800102000039000003740000013d0000010b011001c70000800902000039000080010400003900000001030000290000000005000019041c04120000040f000100000001035500000000030100190000006003300270000001080030019d00000108033001980000039b0000c13d000000400100043d0000000100200190000003c10000613d0000002002100039000000400300003900000000003204350000013c0200004100000000002104350000004003100039000000600200043d00000000002304350000013f052001970000001f0420018f0000006003100039000000810030008c000003d70000413d000000000005004b000003960000613d000000000743001900000060064001bf000000200770008a0000000008570019000000000956001900000000090904330000000000980435000000200550008c000003900000c13d000000000004004b000003ed0000613d00000080050000390000000006030019000003e30000013d0000001f0430003900000135044001970000003f044000390000013604400197000000400500043d0000000004450019000000000054004b00000000060000390000000106004039000001190040009c000001b50000213d0000000100600190000001b50000c13d000000400040043f0000001f0430018f000000000635043600000137053001980000000003560019000003b30000613d000000000701034f000000007807043c0000000006860436000000000036004b000003af0000c13d000000000004004b0000037b0000613d000000000151034f0000000304400210000000000503043300000000054501cf000000000545022f000000000101043b0000010004400089000000000141022f00000000014101cf000000000151019f00000000001304350000037b0000013d00000084021000390000013803000041000000000032043500000064021000390000013903000041000000000032043500000044021000390000013a0300004100000000003204350000002402100039000000530300003900000000003204350000011f020000410000000000210435000000040210003900000020030000390000000000320435000001080010009c000001080100804100000040011002100000013b011001c70000041e000104300000000006530019000000000005004b0000008009000039000003e00000613d000000000703001900000000980904340000000007870436000000000067004b000003dc0000c13d000000000004004b000003ed0000613d00000080055000390000000304400210000000000706043300000000074701cf000000000747022f00000000050504330000010004400089000000000545022f00000000044501cf000000000474019f00000000004604350000001f042000390000013f04400197000000000232001900000000000204350000006002400039000001080020009c00000108020080410000006002200210000001080010009c00000108010080410000004001100210000000000112019f0000041d0001042e000000000001004b000003fd0000613d000000000001042d000000400100043d0000006402100039000001220300004100000000003204350000004402100039000001210300004100000000003204350000002402100039000000240300003900000000003204350000011f020000410000000000210435000000040210003900000020030000390000000000320435000001080010009c0000010801008041000000400110021000000120011001c70000041e00010430000000000001042f00000415002104210000000102000039000000000001042d0000000002000019000000000001042d0000041a002104230000000102000039000000000001042d0000000002000019000000000001042d0000041c000004320000041d0001042e0000041e00010430000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffffffffffff0000000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffffffffffffffffffff02000000000000000000000000000000000000000000000000000000000000008be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0000000020000000000000000000000000000004000000100000000000000000000000000000000000000000000000000000000000000000000000000817b17ef00000000000000000000000000000000000000000000000000000000817b17f0000000000000000000000000000000000000000000000000000000008da5cb5b00000000000000000000000000000000000000000000000000000000f2fde38b00000000000000000000000000000000000000000000000000000000038a24bc0000000000000000000000000000000000000000000000000000000051cff8d900000000000000000000000000000000000000000000000000000000715018a6118cdaa70000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000240000000000000000000000001e4fbdf7000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000800000000000000000000000000000000000000000000000000000000000000000ffffffffffffffff7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9cc7f708afc65944829bd487b90b72536b1951864fbfc14e125fc972a6507f390200000200000000000000000000000000000024000000000000000000000000796d61737465722e0000000000000000000000000000000000000000000000004661696c656420746f2077697468647261772066756e64732066726f6d20706108c379a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000840000000000000000000000004f6e6c7920626f6f746c6f616465722063616e2063616c6c2074686973206d6574686f640000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000840000008000000000000000008000000000000000000000000000000000000000000000000000000000000000ffffffff000000000000000000000000000000000000000000000000000000008c5a344500000000000000000000000000000000000000000000000000000000556e737570706f72746564207061796d617374657220666c6f7720696e207061796d6173746572506172616d732e0000000000000000000000000000000000004e487b710000000000000000000000000000000000000000000000000000000072657175697265644554480000000000000000000000000000000000000000009710a9d0000000000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffffffffffffffffffffff0000000000000000000000000000000000000084000000e00000000000000000000000000000000000000000000000000000000000636f6e736f6c652e6c6f67000000000000000000000000000000000000000000000000ffffffffffffffc062616c616e636500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffffbf6d73672e76616c7565000000000000000000000000000000000000000000000067617350726963650000000000000000000000000000000000000000000000006761734c696d697400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001ffffffe000000000000000000000000000000000000000000000000000000003ffffffe000000000000000000000000000000000000000000000000000000000ffffffe069676874206e6f7420626520656e6f7567682e0000000000000000000000000020426f6f746c6f616465722e205061796d61737465722062616c616e6365206d4661696c656420746f207472616e736665722074782066656520746f2074686500000000000000000000000000000000000000a4000000000000000000000000038a24bc00000000000000000000000000000000000000000000000000000000546865207374616e64617264207061796d617374657220696e707574206d757374206265206174206c656173742034206279746573206c6f6e67000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0665706818478a33d2e5c855cee339a5e2954659335637b967b7e5433b81a588b"; + +const COUNTER_BYTECODE: &str = "0x0000008003000039000000400030043f0000000100200190000000150000c13d000000000201001900000010002001980000002d0000613d000000000101043b000000e001100270000000110010009c000000200000613d000000120010009c0000002d0000c13d0000000001000416000000000001004b0000002d0000c13d000000000100041a000000ff0110018f000000800010043f0000001501000041000000370001042e0000000001000416000000000001004b0000002d0000c13d000000000200041a0000001601200197000000000010041b0000002001000039000001000010044300000120000004430000000f01000041000000370001042e0000000001000416000000000001004b0000002d0000c13d000000000100041a000000ff0210018f000000ff0020008c0000002f0000c13d0000001301000041000000000010043f0000001101000039000000040010043f000000140100004100000038000104300000000001000019000000380001043000000016021001970000000101100039000000ff0110018f000000000121019f000000000010041b0000000001000019000000370001042e0000003600000432000000370001042e0000003800010430000000000000000000000000000000000000000000000000000000020000000000000000000000000000004000000100000000000000000000000000000000000000000000000000fffffffc00000000000000000000000000000000000000000000000000000000000000000000000000000000d09de08a000000000000000000000000000000000000000000000000000000008381f58a4e487b710000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000240000000000000000000000000000000000000000000000000000000000000020000000800000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000000000000000000000000000000000000000000000000000000000000027b95d8697efbdb44a7508247e8c640a64fb3ead050f40cb23deb1910c501315"; + +casttest!(test_zk_cast_using_paymaster, async |_prj, cmd| { + let node = ZkSyncNode::start(); + let url = node.url(); + + let (addr, private_key) = ZkSyncNode::rich_wallets() + .next() + .map(|(addr, pk, _)| (addr, pk)) + .expect("No rich wallets available"); + + // Deploy paymaster + cmd.args([ + "rpc", + "hardhat_setCode", + "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + PAYMASTER_BYTECODE, + "--rpc-url", + &url, + ]) + .assert_success(); + + // Deploy counter + cmd.cast_fuse() + .args([ + "rpc", + "hardhat_setCode", + "0x70997970C51812dc3A010C7d01b50e0d17dc79C8", + COUNTER_BYTECODE, + "--rpc-url", + &url, + ]) + .assert_success(); + + // Fund the paymaster + cmd.cast_fuse() + .args([ + "send", + "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + "0x", + "--value", + "0.1ether", + "--private-key", + private_key, + "--rpc-url", + &url, + ]) + .assert_success(); + + let balance_before = cmd + .cast_fuse() + .args(["balance", addr, "--rpc-url", &url]) + .assert_success() + .get_output() + .stdout_lossy(); + + // Interact with the counter using the paymaster + cmd.cast_fuse().args([ + "send", + "0x70997970C51812dc3A010C7d01b50e0d17dc79C8", + "increment()", + "--private-key", + private_key, + "--zk-paymaster-address", + "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + "--zk-paymaster-input", + "0x8c5a344500000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000", + "--rpc-url", + &url + ]) + .assert_success(); + + let balance_after = cmd + .cast_fuse() + .args(["balance", addr, "--rpc-url", &url]) + .assert_success() + .get_output() + .stdout_lossy(); + + assert_eq!(balance_after, balance_before); +}); + +casttest!(test_zk_cast_without_paymaster, async |_prj, cmd| { + let node = ZkSyncNode::start(); + let url = node.url(); + + let (addr, private_key) = ZkSyncNode::rich_wallets() + .next() + .map(|(addr, pk, _)| (addr, pk)) + .expect("No rich wallets available"); + + // Deploy counter + cmd.cast_fuse() + .args([ + "rpc", + "hardhat_setCode", + "0x70997970C51812dc3A010C7d01b50e0d17dc79C8", + COUNTER_BYTECODE, + "--rpc-url", + &url, + ]) + .assert_success(); + + let balance_before = cmd + .cast_fuse() + .args(["balance", addr, "--rpc-url", &url]) + .assert_success() + .get_output() + .stdout_lossy(); + + cmd.cast_fuse() + .args([ + "send", + "0x70997970C51812dc3A010C7d01b50e0d17dc79C8", + "increment()", + "--private-key", + private_key, + "--rpc-url", + &url, + "--gas-price", + "1000000000000002", + ]) + .assert_success(); + + let balance_after = cmd + .cast_fuse() + .args(["balance", addr, "--rpc-url", &url]) + .assert_success() + .get_output() + .stdout_lossy(); + + assert!(balance_after != balance_before); +}); diff --git a/crates/forge/tests/cli/build.rs b/crates/forge/tests/cli/build.rs index 43ded2945..dfc70e10f 100644 --- a/crates/forge/tests/cli/build.rs +++ b/crates/forge/tests/cli/build.rs @@ -1,8 +1,7 @@ use crate::utils::generate_large_contract; use foundry_config::Config; -use foundry_test_utils::{forgetest, snapbox::IntoData, str, util::OutputExt}; +use foundry_test_utils::{forgetest, snapbox::IntoData, str}; use globset::Glob; -use regex::Regex; forgetest_init!(can_parse_build_filters, |prj, cmd| { prj.clear(); @@ -166,17 +165,6 @@ forgetest_init!(build_sizes_no_forge_std, |prj, cmd| { ); }); -// tests build output is as expected in zksync mode -forgetest_init!(test_zk_build_sizes, |prj, cmd| { - cmd.args(["build", "--sizes", "--zksync", "--evm-version", "shanghai"]); - let stdout = cmd.assert_success().get_output().stdout_lossy(); - let pattern = - Regex::new(r"\|\s*Counter\s*\|\s*800\s*\|\s*800\s*\|\s*450,199\s*\|\s*450,199\s*\|") - .unwrap(); - - assert!(pattern.is_match(&stdout), "Unexpected size output:\n{stdout}"); -}); - // tests that skip key in config can be used to skip non-compilable contract forgetest_init!(test_can_skip_contract, |prj, cmd| { prj.add_source( diff --git a/crates/forge/tests/cli/cmd.rs b/crates/forge/tests/cli/cmd.rs index bf7f9f6d7..6c06d00b2 100644 --- a/crates/forge/tests/cli/cmd.rs +++ b/crates/forge/tests/cli/cmd.rs @@ -2676,78 +2676,6 @@ Suite result: ok. 1 passed; 0 failed; 0 skipped; [ELAPSED] ); }); -forgetest!(zk_gas_report, |prj, cmd| { - prj.insert_ds_test(); - prj.add_source( - "Contracts.sol", - r#" -//SPDX-license-identifier: MIT - -import "./test.sol"; - -contract ContractOne { - int public i; - - constructor() { - i = 0; - } - - function foo() public{ - while(i<5){ - i++; - } - } -} - -contract ContractOneTest is DSTest { - ContractOne c1; - - function setUp() public { - c1 = new ContractOne(); - } - - function testFoo() public { - c1.foo(); - } -} - "#, - ) - .unwrap(); - - prj.write_config(Config { - gas_reports: (vec!["*".to_string()]), - gas_reports_ignore: (vec![]), - ..Default::default() - }); - let out = cmd.arg("test").arg("--gas-report").assert_success().get_output().stdout_lossy(); - cmd.forge_fuse(); - let out_zk = cmd - .arg("test") - .arg("--gas-report") - .arg("--zksync") - .assert_success() - .get_output() - .stdout_lossy(); - - let mut cells = out.split('|'); - let deployment_cost: u64 = cells.nth(22).unwrap().trim().parse().unwrap(); - let deployment_size: u64 = cells.next().unwrap().trim().parse().unwrap(); - let function = cells.nth(12).unwrap().trim(); - let gas: u64 = cells.next().unwrap().trim().parse().unwrap(); - - let mut cells_zk = out_zk.split('|'); - let deployment_cost_zk: u64 = cells_zk.nth(22).unwrap().trim().parse().unwrap(); - let deployment_size_zk: u64 = cells_zk.next().unwrap().trim().parse().unwrap(); - let function_zk = cells_zk.nth(12).unwrap().trim(); - let gas_zk: u64 = cells_zk.next().unwrap().trim().parse().unwrap(); - - assert!(deployment_cost_zk > deployment_cost); - assert!(deployment_size_zk > deployment_size); - assert!(gas_zk > gas); - assert_eq!(function, "foo"); - assert_eq!(function_zk, "foo"); -}); - forgetest_init!(can_use_absolute_imports, |prj, cmd| { let remapping = prj.paths().libraries[0].join("myDependency"); let config = Config { diff --git a/crates/forge/tests/cli/ext_integration.rs b/crates/forge/tests/cli/ext_integration.rs index af0f74dde..e9437f04c 100644 --- a/crates/forge/tests/cli/ext_integration.rs +++ b/crates/forge/tests/cli/ext_integration.rs @@ -146,10 +146,3 @@ fn convex_shutdown_simulation() { .fork_block(14445961) .run(); } - -#[test] -fn test_zk_aave_di() { - ExtTester::new("Moonsong-Labs", "aave-delivery-infrastructure", "ci") - .args(["--zksync", "--skip", "\"*/PayloadScripts.t.sol\""]) - .run() -} diff --git a/crates/forge/tests/cli/main.rs b/crates/forge/tests/cli/main.rs index a53a26d2a..2698df9fe 100644 --- a/crates/forge/tests/cli/main.rs +++ b/crates/forge/tests/cli/main.rs @@ -26,3 +26,7 @@ mod verify; mod verify_bytecode; mod ext_integration; +mod zk_build; +mod zk_cmd; +mod zk_ext_integration; +mod zk_script; diff --git a/crates/forge/tests/cli/script.rs b/crates/forge/tests/cli/script.rs index 0de0e744f..82c61ccbc 100644 --- a/crates/forge/tests/cli/script.rs +++ b/crates/forge/tests/cli/script.rs @@ -6,7 +6,7 @@ use anvil::{spawn, NodeConfig}; use forge_script_sequence::ScriptSequence; use foundry_test_utils::{ rpc, - util::{OutputExt, OTHER_SOLC_VERSION, SOLC_VERSION}, + util::{OTHER_SOLC_VERSION, SOLC_VERSION}, ScriptOutcome, ScriptTester, }; use regex::Regex; @@ -2037,114 +2037,6 @@ forgetest_async!(can_deploy_library_create2_different_sender, |prj, cmd| { .await; }); -forgetest_async!(test_zk_can_execute_script_with_arguments, |prj, cmd| { - #[derive(serde::Deserialize, Debug)] - #[allow(dead_code)] - struct ZkTransactions { - transactions: Vec, - } - - #[derive(serde::Deserialize, Debug)] - #[allow(dead_code)] - struct ZkTransaction { - zk: Zk, - } - - #[derive(serde::Deserialize, Debug)] - #[serde(rename_all = "camelCase")] - #[allow(dead_code)] - struct Zk { - #[serde(default)] - factory_deps: Vec>, - } - - let node = foundry_test_utils::ZkSyncNode::start(); - - cmd.args(["init", "--force"]).arg(prj.root()); - cmd.assert_success(); - cmd.forge_fuse(); - - prj.add_script( - "Deploy.s.sol", - r#" -pragma solidity ^0.8.18; - -import {Script} from "forge-std/Script.sol"; - -contract Greeter { - string name; - uint256 age; - - event Greet(string greet); - - function greeting(string memory _name) public returns (string memory) { - name = _name; - string memory greet = string(abi.encodePacked("Hello ", _name)); - emit Greet(greet); - return greet; - } - - function setAge(uint256 _age) public { - age = _age; - } - - function getAge() public view returns (uint256) { - return age; - } -} - -contract DeployScript is Script { - Greeter greeter; - string greeting; - - function run() external { - // test is using old Vm.sol interface, so we call manually - address(vm).call(abi.encodeWithSignature("zkVm(bool)", true)); - - vm.startBroadcast(); - greeter = new Greeter(); - greeter.greeting("john"); - greeter.setAge(123); - vm.stopBroadcast(); - } -} - "#, - ) - .unwrap(); - - cmd.arg("script").args([ - "--zksync", - "DeployScript", - "--broadcast", - "--private-key", - "0x3d3cbc973389cb26f657686445bcc75662b415b656078503592ac8c1abb8810e", - "--chain", - "260", - "--gas-estimate-multiplier", - "310", - "--rpc-url", - node.url().as_str(), - "--slow", - "--evm-version", - "shanghai", - ]); - - cmd.assert_success() - .get_output() - .stdout_lossy() - .contains("ONCHAIN EXECUTION COMPLETE & SUCCESSFUL"); - - let run_latest = foundry_common::fs::json_files(prj.root().join("broadcast").as_path()) - .find(|file| file.ends_with("run-latest.json")) - .expect("No broadcast artifacts"); - - let content = foundry_common::fs::read_to_string(run_latest).unwrap(); - - let transactions: ZkTransactions = serde_json::from_str(&content).unwrap(); - let transactions = transactions.transactions; - assert_eq!(transactions.len(), 3); -}); - // forgetest_async!(test_broadcast_raw_create2_deployer, |prj, cmd| { let (_api, handle) = diff --git a/crates/forge/tests/cli/test_cmd.rs b/crates/forge/tests/cli/test_cmd.rs index 96c89953a..8e064c63c 100644 --- a/crates/forge/tests/cli/test_cmd.rs +++ b/crates/forge/tests/cli/test_cmd.rs @@ -1339,40 +1339,6 @@ Traces: ]]); }); -// Related to: https://github.com/matter-labs/foundry-zksync/issues/478 -forgetest_async!(test_zk_can_detect_call_to_empty_contract, |prj, cmd| { - foundry_test_utils::util::initialize(prj.root()); - - prj.add_test( - "CallEmptyCode.t.sol", - r#" -import "forge-std/Test.sol"; - -// https://github.com/matter-labs/foundry-zksync/issues/478 -contract CallEmptyCode is Test { - // This test should make our EraVM tracer print out an ERROR trace - function testFailDetectEmptyCodeContracts() external { - address mockMe = address(123456789); - - vm.mockCall(mockMe, abi.encodeWithSignature("foo()"), abi.encode(42)); - - (bool success, bytes memory ret) = mockMe.call(abi.encodeWithSignature("bar()")); - - require(success, "callMethod failed"); - require(keccak256(ret) == keccak256(abi.encode(42)), "return not as expected"); - } -} -"#, - ) - .unwrap(); - cmd.args(["test", "--zksync", "--evm-version", "shanghai", "--mc", "CallEmptyCode"]); - - cmd.assert_success() - .get_output() - .stdout_lossy() - .contains("call may fail or behave unexpectedly due to empty code"); -}); - // tests that `forge test` with a seed produces deterministic random values for uint and addresses. forgetest_init!(deterministic_randomness_with_seed, |prj, cmd| { prj.wipe_contracts(); diff --git a/crates/forge/tests/cli/zk_build.rs b/crates/forge/tests/cli/zk_build.rs new file mode 100644 index 000000000..aa350886b --- /dev/null +++ b/crates/forge/tests/cli/zk_build.rs @@ -0,0 +1,13 @@ +use foundry_test_utils::util::OutputExt; +use regex::Regex; + +// tests build output is as expected in zksync mode +forgetest_init!(test_zk_build_sizes, |prj, cmd| { + cmd.args(["build", "--sizes", "--zksync", "--evm-version", "shanghai"]); + let stdout = cmd.assert_success().get_output().stdout_lossy(); + let pattern = + Regex::new(r"\|\s*Counter\s*\|\s*800\s*\|\s*800\s*\|\s*450,199\s*\|\s*450,199\s*\|") + .unwrap(); + + assert!(pattern.is_match(&stdout), "Unexpected size output:\n{stdout}"); +}); diff --git a/crates/forge/tests/cli/zk_cmd.rs b/crates/forge/tests/cli/zk_cmd.rs new file mode 100644 index 000000000..644d9c810 --- /dev/null +++ b/crates/forge/tests/cli/zk_cmd.rs @@ -0,0 +1,124 @@ +//! Contains various tests for checking forge's commands in zksync + +use foundry_config::Config; +use foundry_test_utils::util::OutputExt; +use similar_asserts::assert_eq; + +forgetest!(test_zk_gas_report, |prj, cmd| { + prj.insert_ds_test(); + prj.add_source( + "Contracts.sol", + r#" +//SPDX-license-identifier: MIT + +import "./test.sol"; + +contract ContractOne { + int public i; + + constructor() { + i = 0; + } + + function foo() public{ + while(i<5){ + i++; + } + } +} + +contract ContractOneTest is DSTest { + ContractOne c1; + + function setUp() public { + c1 = new ContractOne(); + } + + function testFoo() public { + c1.foo(); + } +} + "#, + ) + .unwrap(); + + prj.write_config(Config { + gas_reports: (vec!["*".to_string()]), + gas_reports_ignore: (vec![]), + ..Default::default() + }); + let out = cmd.arg("test").arg("--gas-report").assert_success().get_output().stdout_lossy(); + cmd.forge_fuse(); + let out_zk = cmd + .arg("test") + .arg("--gas-report") + .arg("--zksync") + .assert_success() + .get_output() + .stdout_lossy(); + + let mut cells = out.split('|'); + let deployment_cost: u64 = cells.nth(22).unwrap().trim().parse().unwrap(); + let deployment_size: u64 = cells.next().unwrap().trim().parse().unwrap(); + let function = cells.nth(12).unwrap().trim(); + let gas: u64 = cells.next().unwrap().trim().parse().unwrap(); + + let mut cells_zk = out_zk.split('|'); + let deployment_cost_zk: u64 = cells_zk.nth(22).unwrap().trim().parse().unwrap(); + let deployment_size_zk: u64 = cells_zk.next().unwrap().trim().parse().unwrap(); + let function_zk = cells_zk.nth(12).unwrap().trim(); + let gas_zk: u64 = cells_zk.next().unwrap().trim().parse().unwrap(); + + assert!(deployment_cost_zk > deployment_cost); + assert!(deployment_size_zk > deployment_size); + assert!(gas_zk > gas); + assert_eq!(function, "foo"); + assert_eq!(function_zk, "foo"); +}); + +forgetest_init!(test_zk_can_init_with_zksync, |prj, cmd| { + cmd.args(["init", "--zksync", "--force"]).assert_success(); + + // Check that zkout/ is in .gitignore + let gitignore_path = prj.root().join(".gitignore"); + assert!(gitignore_path.exists()); + let gitignore_contents = std::fs::read_to_string(&gitignore_path).unwrap(); + assert!(gitignore_contents.contains("zkout/")); + + // Assert that forge-zksync-std is installed + assert!(prj.root().join("lib/forge-zksync-std").exists()); +}); + +// Related to: https://github.com/matter-labs/foundry-zksync/issues/478 +forgetest_async!(test_zk_can_detect_call_to_empty_contract, |prj, cmd| { + foundry_test_utils::util::initialize(prj.root()); + + prj.add_test( + "CallEmptyCode.t.sol", + r#" +import "forge-std/Test.sol"; + +// https://github.com/matter-labs/foundry-zksync/issues/478 +contract CallEmptyCode is Test { + // This test should make our EraVM tracer print out an ERROR trace + function testFailDetectEmptyCodeContracts() external { + address mockMe = address(123456789); + + vm.mockCall(mockMe, abi.encodeWithSignature("foo()"), abi.encode(42)); + + (bool success, bytes memory ret) = mockMe.call(abi.encodeWithSignature("bar()")); + + require(success, "callMethod failed"); + require(keccak256(ret) == keccak256(abi.encode(42)), "return not as expected"); + } +} +"#, + ) + .unwrap(); + cmd.args(["test", "--zksync", "--evm-version", "shanghai", "--mc", "CallEmptyCode"]); + + cmd.assert_success() + .get_output() + .stdout_lossy() + .contains("call may fail or behave unexpectedly due to empty code"); +}); diff --git a/crates/forge/tests/cli/zk_ext_integration.rs b/crates/forge/tests/cli/zk_ext_integration.rs new file mode 100644 index 000000000..85a58e31b --- /dev/null +++ b/crates/forge/tests/cli/zk_ext_integration.rs @@ -0,0 +1,8 @@ +use foundry_test_utils::util::ExtTester; + +#[test] +fn test_zk_aave_di() { + ExtTester::new("Moonsong-Labs", "aave-delivery-infrastructure", "ci") + .args(["--zksync", "--skip", "\"*/PayloadScripts.t.sol\""]) + .run() +} diff --git a/crates/forge/tests/cli/zk_script.rs b/crates/forge/tests/cli/zk_script.rs new file mode 100644 index 000000000..2c3c37ddf --- /dev/null +++ b/crates/forge/tests/cli/zk_script.rs @@ -0,0 +1,111 @@ +//! Contains tests related to `forge script` with zksync. + +use foundry_test_utils::util::OutputExt; + +forgetest_async!(test_zk_can_execute_script_with_arguments, |prj, cmd| { + #[derive(serde::Deserialize, Debug)] + #[allow(dead_code)] + struct ZkTransactions { + transactions: Vec, + } + + #[derive(serde::Deserialize, Debug)] + #[allow(dead_code)] + struct ZkTransaction { + zk: Zk, + } + + #[derive(serde::Deserialize, Debug)] + #[serde(rename_all = "camelCase")] + #[allow(dead_code)] + struct Zk { + #[serde(default)] + factory_deps: Vec>, + } + + let node = foundry_test_utils::ZkSyncNode::start(); + + cmd.args(["init", "--force"]).arg(prj.root()); + cmd.assert_success(); + cmd.forge_fuse(); + + prj.add_script( + "Deploy.s.sol", + r#" +pragma solidity ^0.8.18; + +import {Script} from "forge-std/Script.sol"; + +contract Greeter { + string name; + uint256 age; + + event Greet(string greet); + + function greeting(string memory _name) public returns (string memory) { + name = _name; + string memory greet = string(abi.encodePacked("Hello ", _name)); + emit Greet(greet); + return greet; + } + + function setAge(uint256 _age) public { + age = _age; + } + + function getAge() public view returns (uint256) { + return age; + } +} + +contract DeployScript is Script { + Greeter greeter; + string greeting; + + function run() external { + // test is using old Vm.sol interface, so we call manually + address(vm).call(abi.encodeWithSignature("zkVm(bool)", true)); + + vm.startBroadcast(); + greeter = new Greeter(); + greeter.greeting("john"); + greeter.setAge(123); + vm.stopBroadcast(); + } +} + "#, + ) + .unwrap(); + + cmd.arg("script").args([ + "--zksync", + "DeployScript", + "--broadcast", + "--private-key", + "0x3d3cbc973389cb26f657686445bcc75662b415b656078503592ac8c1abb8810e", + "--chain", + "260", + "--gas-estimate-multiplier", + "310", + "--rpc-url", + node.url().as_str(), + "--slow", + "--evm-version", + "shanghai", + ]); + + cmd.assert_success() + .get_output() + .stdout_lossy() + .contains("ONCHAIN EXECUTION COMPLETE & SUCCESSFUL"); + + let run_latest = foundry_common::fs::json_files(prj.root().join("broadcast").as_path()) + .find(|file| file.ends_with("run-latest.json")) + .expect("No broadcast artifacts"); + + let content = foundry_common::fs::read_to_string(run_latest).unwrap(); + + let transactions: ZkTransactions = serde_json::from_str(&content).unwrap(); + let transactions = transactions.transactions; + assert_eq!(transactions.len(), 3); +});