forked from CalloraOrg/Callora-Contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrewrite_tests.py
More file actions
38 lines (29 loc) · 1.77 KB
/
Copy pathrewrite_tests.py
File metadata and controls
38 lines (29 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import os
import re
def rewrite_test_file(path):
with open(path, 'r') as f:
content = f.read()
# 1. Find all `client.init(...)` calls
# Usually they look like: client.init(&owner, &usdc, &Some(500), &None, &None, &None, &None);
# We want to change it to: client.init(&owner, &usdc, &500, &caller, &1, &None, &10000000000, &settlement);
# But wait, we need `caller` and `settlement`!
# Actually, the easiest way to fix the E0061 and E0308 errors in tests is to write a regex that matches client.init(7 args)
def repl_init(m):
args = m.group(1).split(',')
args = [a.strip() for a in args]
if len(args) != 7: return m.group(0)
owner, usdc, initial_balance, auth_caller, min_dep, rev_pool, max_ded = args
# Convert Option to raw values
def unwrap_val(val, default):
if 'Some' in val:
return "&" + re.search(r'Some\((.*)\)', val).group(1)
return default
initial_balance = unwrap_val(initial_balance, "&0")
auth_caller = unwrap_val(auth_caller, owner)
min_dep = unwrap_val(min_dep, "&1")
max_ded = unwrap_val(max_ded, "&10000000000")
# We need to pass settlement. Let's just pass `owner` as settlement temporarily if we don't have one, or just `settlement` if it's in scope.
# But `settlement` might not be in scope.
# Actually, let's just do a regex replace for the whole test file where we insert `let settlement = Address::generate(&env);` before init.
return f"let settlement = Address::generate(&env);\n client.init({owner}, {usdc}, {initial_balance}, {auth_caller}, {min_dep}, {rev_pool}, {max_ded}, &settlement);"
# This is getting too complex and error-prone.