forked from Crowdfunding-DApp/stellar-raise-contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix_tests2.py
More file actions
41 lines (34 loc) · 1.95 KB
/
fix_tests2.py
File metadata and controls
41 lines (34 loc) · 1.95 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
39
40
41
#!/usr/bin/env python3
import re
# Read the file
with open('contracts/crowdfund/src/test.rs', 'r') as f:
content = f.read()
# Fix multiline initialize calls with 6 parameters (auto_extension_threshold)
# This pattern matches:
# client.initialize(
# &creator,
# &token_address,
# &goal,
# &deadline,
# &min_contribution,
# &Some(auto_extension_threshold),
# );
pattern = r'client\.initialize\(\s*&creator,\s*&token_address,\s*&goal,\s*&deadline,\s*&min_contribution,\s*&Some\(auto_extension_threshold\),\s*\)'
replacement = r'client.initialize(&creator, &creator, &token_address, &goal, &deadline, &min_contribution, &None, &Some(auto_extension_threshold), &None)'
content = re.sub(pattern, replacement, content, flags=re.MULTILINE | re.DOTALL)
# Fix initialize with &None at the end (6 params)
pattern2 = r'client\.initialize\(\s*&creator,\s*&token_address,\s*&goal,\s*&deadline,\s*&min_contribution,\s*&None\s*\)'
replacement2 = r'client.initialize(&creator, &creator, &token_address, &goal, &deadline, &min_contribution, &None, &None, &None)'
content = re.sub(pattern2, replacement2, content, flags=re.MULTILINE | re.DOTALL)
# Fix initialize with deadline variable names
pattern3 = r'client\.initialize\(\s*&creator,\s*&token_address,\s*&goal,\s*&past_deadline,\s*&1_000,\s*&None,\s*&None,\s*&None\s*\)'
replacement3 = r'client.initialize(&creator, &creator, &token_address, &goal, &past_deadline, &1_000, &None, &None, &None)'
content = re.sub(pattern3, replacement3, content)
# Fix try_initialize with past_deadline
pattern4 = r'client\.try_initialize\(\s*&creator,\s*&token_address,\s*&goal,\s*&past_deadline,\s*&1_000,\s*&None,\s*&None,\s*&None\s*\)'
replacement4 = r'client.try_initialize(&creator, &creator, &token_address, &goal, &past_deadline, &1_000, &None, &None, &None)'
content = re.sub(pattern4, replacement4, content)
# Write back
with open('contracts/crowdfund/src/test.rs', 'w') as f:
f.write(content)
print("Fixed more initialize patterns")