-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_deposit.py
More file actions
122 lines (75 loc) · 4.88 KB
/
Copy pathtest_deposit.py
File metadata and controls
122 lines (75 loc) · 4.88 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import os
import time
import json
import signal
import psutil
import unittest
import subprocess
from web3 import Web3
from web3.middleware import geth_poa_middleware
from optimism import CrossChainMessenger
from test.utils import TestUtil
class TestDeposit(unittest.TestCase, TestUtil):
def setUp(self) -> None:
self.node_process = subprocess.Popen(["start_devnet", "devnode"])
if self.node_process.returncode == None:
print("Local dev net started successfully")
else:
print(f"Error starting local dev net. Exit code: {self.node_process.returncode}")
time.sleep(40)
subprocess.Popen(["sshpass", "-p", "sandbox", "ssh", "-o", "IdentitiesOnly=yes", "-t", "[email protected]", "-p", "10022", "cd ~/optimism && make devnet-up"])
time.sleep(40)
vm_process = subprocess.Popen(["sshpass", "-p", "sandbox", "ssh", "-o", "IdentitiesOnly=yes", "-t", "[email protected]", "-p", "10022", "python3 extract_addresses.py"], stdout=subprocess.PIPE)
output, error = vm_process.communicate()
if error:
print(f"Error: {error}")
else:
l1_addresses_devnet = json.loads(output.decode().split("\r\n")[-2].strip("\r\n").replace("'", "\""))
with open("optimism/config.json", 'r') as file:
addresses = json.load(file)
addresses["900"]["901"]["l1_addresses"] = l1_addresses_devnet
with open("optimism/config.json", 'w') as json_file:
json.dump(addresses, json_file, indent=4)
subprocess.Popen(["sshpass", "-p", "sandbox", "ssh", "-o", "IdentitiesOnly=yes", "-t", "[email protected]", "-p", "10022", f"echo 'export L2OO_ADDRESS={l1_addresses_devnet['L2_OUTPUT_ORACLE']}' >> '/home/sandbox/.bashrc'"])
subprocess.Popen(["sshpass", "-p", "sandbox", "ssh", "-o", "IdentitiesOnly=yes", "-t", "[email protected]", "-p", "10022", f"echo 'export DGF_ADDRESS={l1_addresses_devnet['DISPUTE_GAME_FACTORY']}' >> '/home/sandbox/.bashrc'"])
subprocess.Popen(["sshpass", "-p", "sandbox", "ssh", "-o", "IdentitiesOnly=yes", "-t", "[email protected]", "-p", "10022", f"echo 'export DG_TYPE=0' >> '/home/sandbox/.bashrc'"])
subprocess.Popen(["sshpass", "-p", "sandbox", "ssh", "-o", "IdentitiesOnly=yes", "-t", "[email protected]", "-p", "10022", f"cd ~/optimism && python3 bedrock-devnet/main.py"])
time.sleep(20)
self.l1_provider = Web3(Web3.HTTPProvider("http://127.0.0.1:8545"))
self.l2_provider = Web3(Web3.HTTPProvider("http://127.0.0.1:9545"))
self.l1_provider.middleware_onion.inject(geth_poa_middleware, layer=0)
self.l2_provider.middleware_onion.inject(geth_poa_middleware, layer=0)
self.faucet = self.l1_provider.eth.account.from_key("0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80")
self.account = self.l1_provider.eth.account.from_key("0x" + "1" * 64)
self.fund_account(self.account, 10**18, layer="l1")
def tearDown(self) -> None:
print("Tearing down devnet")
subprocess.Popen(["sshpass", "-p", "sandbox", "ssh", "-o", "IdentitiesOnly=yes", "-t", "[email protected]", "-p", "10022", "cd ~/optimism && make devnet-down"])
time.sleep(30)
subprocess.Popen(["sshpass", "-p", "sandbox", "ssh", "-o", "IdentitiesOnly=yes", "-t", "[email protected]", "-p", "10022", "cd ~/optimism && make devnet-clean"])
time.sleep(30)
subprocess.Popen(["sshpass", "-p", "sandbox", "ssh", "-o", "IdentitiesOnly=yes", "-t", "[email protected]", "-p", "10022", "sudo poweroff"])
time.sleep(10)
node_process_pid = self.node_process.pid
parent_process = psutil.Process(node_process_pid)
child_processes = parent_process.children(recursive=True)
self.node_process.terminate()
# kill all child processes
for child in child_processes:
if parent_process.pid != child.pid:
os.kill(child.pid, signal.SIGTERM)
def testDepositETH(self):
l1_chain_id = 900
l2_chain_id = 901
cross_chain_messenger = CrossChainMessenger(l1_chain_id, l2_chain_id, account_l1=self.account, account_l2=self.account, provider_l1=self.l1_provider, provider_l2=self.l2_provider)
balance_l1 = self.l1_provider.eth.get_balance(self.account.address)
balance_l2 = self.l2_provider.eth.get_balance(self.account.address)
self.assertEqual(balance_l1, 10**18)
self.assertEqual(balance_l2, 0)
deposit_txn_hash, deposit_txn_receipt = cross_chain_messenger.deposit_eth(5*10**17)
time.sleep(30)
balance_l1 = self.l1_provider.eth.get_balance(self.account.address)
balance_l2 = self.l2_provider.eth.get_balance(self.account.address)
self.assertGreater(balance_l1, 0.498*10**18)
self.assertLess(balance_l1, 0.5*10**18)
self.assertEqual(balance_l2, 0.5*10**18)