|
| 1 | +require "setup_path" |
| 2 | + |
| 3 | +local Hash = require "cryptography.hash" |
| 4 | +local env = require "test_env" |
| 5 | + |
| 6 | +local CONFIG_ERC20_PORTAL_ADDRESS = "ACA6586A0Cf05bD831f2501E7B4aea550dA6562D" |
| 7 | +local CONFIG_ERC20_WITHDRAWAL_ADDRESS = "70997970C51812dc3A010C7d01b50e0d17dc79C8" |
| 8 | +local CONFIG_ERC20_TOKEN_ADDRESS = "c6e7DF5E7b4f2A278906862b61205850344D4e7d" |
| 9 | +local ETH10K = "0x21e19e0c9bab2400000" |
| 10 | + |
| 11 | +local function exec(fmt, ...) |
| 12 | + local cmd = string.format(fmt, ...) |
| 13 | + local reader = io.popen(cmd) |
| 14 | + assert(reader, "`popen` returned nil reader") |
| 15 | + |
| 16 | + local data = reader:read("*a") |
| 17 | + local success, _, code = reader:close() |
| 18 | + assert(success, string.format("command [[%s]] failed on close:\n%d", cmd, code)) |
| 19 | + |
| 20 | + return data:gsub("\n$", "") -- remove trailing newline from data |
| 21 | +end |
| 22 | + |
| 23 | +local function set_balance(endpoint, account, value) |
| 24 | + return exec([[cast rpc -r "%s" anvil_setBalance "%s" "%s"]], endpoint, account, value) |
| 25 | +end |
| 26 | + |
| 27 | +local function auto_impersonate(endpoint, yes) |
| 28 | + return exec([[cast rpc -r "%s" anvil_autoImpersonateAccount %s]], endpoint, yes) |
| 29 | +end |
| 30 | + |
| 31 | +local deposit_payload = exec( |
| 32 | + [[cast abi-encode --packed '(address,address,uint256,bytes)' "%s" "%s" "%s" "%s"]], |
| 33 | + CONFIG_ERC20_TOKEN_ADDRESS, |
| 34 | + CONFIG_ERC20_PORTAL_ADDRESS, |
| 35 | + "1000", "0x" |
| 36 | +) |
| 37 | + |
| 38 | +local valid_deposit_inpuit = { sender = CONFIG_ERC20_PORTAL_ADDRESS, payload = deposit_payload } |
| 39 | +local invalid_deposit_input = { sender = CONFIG_ERC20_WITHDRAWAL_ADDRESS, payload = deposit_payload } |
| 40 | +local withdrawal_input = { sender = CONFIG_ERC20_WITHDRAWAL_ADDRESS, payload = "0x" } |
| 41 | + |
| 42 | +-- Main Execution |
| 43 | +env.spawn_blockchain({valid_deposit_inpuit, invalid_deposit_input, withdrawal_input}, function () |
| 44 | + set_balance(env.blockchain.endpoint, CONFIG_ERC20_PORTAL_ADDRESS, ETH10K) |
| 45 | + auto_impersonate(env.blockchain.endpoint, "true") |
| 46 | +end) |
| 47 | + |
| 48 | +-- Spawn Dave node |
| 49 | +env.spawn_node() |
| 50 | + |
| 51 | +-- advance such that epoch 0 is finished |
| 52 | +local sealed_epoch = env.roll_epoch() |
| 53 | + |
| 54 | +-- run epoch 1 |
| 55 | +env.run_epoch(sealed_epoch, { |
| 56 | + -- ustep + reset |
| 57 | + { hash = Hash.zero, meta_cycle = 1 << 44 } |
| 58 | +}, { env.sample_inputs[1], env.sample_inputs[1], env.sample_inputs[1] }) |
0 commit comments