Skip to content

Commit b334acd

Browse files
committed
try some ideas to break the convex contracts
1 parent 15af860 commit b334acd

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
"""
2+
3+
4+
Test Convex Breaking
5+
6+
"""
7+
8+
import pytest
9+
import secrets
10+
11+
from tests.helpers import auto_topup_account
12+
13+
from convex_api.account import Account
14+
from convex_api.convex_api import ConvexAPI
15+
from convex_api.exceptions import ConvexAPIError
16+
17+
18+
def test_convex_recursion(convex, test_account):
19+
chain_length = 4
20+
address_list = []
21+
for index in range(0, chain_length):
22+
contract = f"""
23+
(def chain-{index}
24+
(deploy
25+
'(do
26+
(def stored-data nil)
27+
(def chain-address nil)
28+
(defn get [] (call chain-address (get)))
29+
(defn set [x] (if chain-address (call chain-address(set x)) (def stored-data x)) )
30+
(defn set-chain-address [x] (def chain-address x))
31+
(export get set set-chain-address)
32+
)
33+
)
34+
)
35+
"""
36+
auto_topup_account(convex, test_account)
37+
result = convex.send(contract, test_account)
38+
address_list.append(result['value'])
39+
for index in range(0, chain_length):
40+
next_index = index + 1
41+
if next_index == chain_length:
42+
next_index = 0
43+
call_address = address_list[next_index]
44+
result = convex.send(f'(call chain-{index} (set-chain-address {call_address}))', test_account)
45+
test_number = secrets.randbelow(1000)
46+
if index == chain_length - 1:
47+
with pytest.raises(ConvexAPIError, match='DEPTH'):
48+
result = convex.send(f'(call chain-{index} (set {test_number}))', test_account)
49+
else:
50+
result = convex.send(f'(call chain-0 (set {test_number}))', test_account)
51+
assert(result)
52+
assert(result['value'] == test_number)
53+
with pytest.raises(ConvexAPIError, match='DEPTH'):
54+
convex.query('(call chain-0 (get))', test_account)

0 commit comments

Comments
 (0)