Skip to content

Commit b017609

Browse files
committed
test: deposit and withdraw on honeypot
1 parent 94de2a4 commit b017609

File tree

4 files changed

+63
-23
lines changed

4 files changed

+63
-23
lines changed

prt/tests/rollups/dave/sender.lua

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -80,31 +80,10 @@ function Sender:new(input_box_address, dave_app_factory_address, app_contract_ad
8080
return sender
8181
end
8282

83-
local cast_impersonate_template = [[
84-
cast rpc anvil_impersonateAccount %s --rpc-url "%s" 2>&1
85-
]]
8683
local cast_send_template = [[
8784
cast send --from "%s" --rpc-url "%s" --value "%s" "%s" "%s" %s --unlocked 2>&1
8885
]]
8986
function Sender:_send_tx(tournament_address, sender, sig, args, value)
90-
-- impersonate
91-
do
92-
local cmd = string.format(
93-
cast_impersonate_template,
94-
sender,
95-
self.endpoint
96-
)
97-
98-
local handle = io.popen(cmd)
99-
assert(handle)
100-
101-
local ret = handle:read "*a"
102-
handle:close()
103-
if ret:find "Error" then
104-
error(string.format("impersonate %s reverted:\n%s", sender, ret))
105-
end
106-
end
107-
10887
value = value or bint.zero()
10988

11089
local quoted_args = quote_args(args)

prt/tests/rollups/justfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ test-yield-all:
4141
just test {{YIELD_DIR}} bad_commitment
4242

4343
test-honeypot-ci:
44-
just test {{HONEYPOT_DIR}} simple_honeypot
44+
just test {{HONEYPOT_DIR}} honeypot
4545

4646
test-yield-ci:
4747
just test {{YIELD_DIR}} simple
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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] })

prt/tests/rollups/test_env.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ local Env = {
4949
-- consensus_address = false,
5050
}
5151

52-
function Env.spawn_blockchain(inputs)
52+
function Env.spawn_blockchain(inputs, run_before_inputs)
5353
inputs = inputs or {}
5454

5555
local blockchain = Blockchain:new(ANVIL_PATH)
@@ -58,6 +58,9 @@ function Env.spawn_blockchain(inputs)
5858
Env.app_address = Env.reader.app_address
5959
Env.consensus_address = Env.reader.consensus_address
6060
Env.sender = Sender:new(INPUT_BOX_ADDRESS, DAVE_APP_FACTORY_ADDRESS, Env.app_address, blockchain.pks[1], blockchain.endpoint)
61+
if run_before_inputs then
62+
run_before_inputs()
63+
end
6164
Env.sender:tx_add_inputs(inputs)
6265
Env.sender:tx_new_dave_app(TEMPLATE_MACHINE_HASH, SALT)
6366
Env.sender:advance_blocks(2)

0 commit comments

Comments
 (0)