Skip to content

Commit c58a3b2

Browse files
committed
add btc teleport tests
1 parent 023c227 commit c58a3b2

File tree

2 files changed

+57
-5
lines changed

2 files changed

+57
-5
lines changed

modules/btc_teleport.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import json
21
import os
32
import subprocess
3+
from typing import Optional
44

55
from modules.module import MtcModule
6-
from mypylib.mypylib import run_as_root, color_print, bcolors, print_table
6+
from mypylib.mypylib import run_as_root, color_print
77
from mytoncore.utils import get_package_resource_path
88
from mytonctrl.utils import get_current_user
99

@@ -55,14 +55,14 @@ def create_env_file(self, reinit=False):
5555
with open(env_path, 'w') as f:
5656
f.write(text)
5757

58-
def add_daemon(self, user: str = None):
58+
def add_daemon(self, user: Optional[str] = None):
5959
start = f'{self.bin_dir}/oracle'
6060
if user is None:
6161
user = get_current_user()
6262
with get_package_resource_path('mytoninstaller', 'scripts/add2systemd.sh') as script_path:
6363
run_as_root(['bash', script_path, '-n', 'btc_teleport', '-u', user, '-g', user, '-s', start, '-w', self.bin_dir])
6464

65-
def install(self, branch: str, user: str = None):
65+
def install(self, branch: str, user: Optional[str] = None):
6666
if user is None:
6767
user = get_current_user()
6868
with get_package_resource_path('mytonctrl', 'scripts/btc_teleport1.sh') as script_path:
@@ -72,7 +72,7 @@ def install(self, branch: str, user: str = None):
7272
with get_package_resource_path('mytonctrl', 'scripts/btc_teleport2.sh') as script_path:
7373
subprocess.run(["bash", script_path, "-s", self.src_dir])
7474

75-
def init(self, reinstall=False, branch: str = 'master', user: str = None):
75+
def init(self, reinstall=False, branch: str = 'master', user: Optional[str] = None):
7676
if os.path.exists(self.src_dir) and not reinstall:
7777
return
7878
if self.ton.local.db.get('btcTeleportDisabled'):
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
from modules import btc_teleport as btc_teleport_module
2+
from mytoncore import get_package_resource_path
3+
from mytoncore.mytoncore import MyTonCore
4+
5+
6+
def test_remove_btc_teleport(cli, monkeypatch, ton):
7+
with get_package_resource_path('mytonctrl', 'scripts/remove_btc_teleport.sh') as script_path:
8+
assert script_path.is_file()
9+
10+
# non-masterchain validator, no --force needed
11+
return_code = 0
12+
run_args = []
13+
def fake_run_as_root(args: list):
14+
nonlocal return_code, run_args
15+
run_args = args
16+
return return_code
17+
18+
monkeypatch.setattr(btc_teleport_module, "run_as_root", fake_run_as_root)
19+
20+
monkeypatch.setattr(MyTonCore, "GetValidatorIndex", lambda self: -1)
21+
monkeypatch.setattr(MyTonCore, "GetConfig34", lambda self: {"mainValidators": 100})
22+
23+
output = cli.execute("remove_btc_teleport", no_color=True)
24+
assert "Removed btc_teleport" in output
25+
assert run_args == ['bash', script_path, '-s', '/usr/src/ton-teleport-btc-periphery', '-k', ton.local.buffer.my_work_dir + '/btc_oracle_keystore']
26+
27+
# bad args
28+
run_args = []
29+
output = cli.execute("remove_btc_teleport arg1 arg2")
30+
assert "Bad args" in output
31+
assert not run_args
32+
33+
# masterchain validator without --force
34+
monkeypatch.setattr(MyTonCore, "GetValidatorIndex", lambda self: 10)
35+
monkeypatch.setattr(MyTonCore, "GetConfig34", lambda self: {"mainValidators": 100})
36+
output = cli.execute("remove_btc_teleport", no_color=True)
37+
assert run_args == []
38+
assert 'You can not remove btc_teleport on working masterchain validator' in output
39+
40+
# masterchain validator with --force
41+
monkeypatch.setattr(MyTonCore, "GetValidatorIndex", lambda self: 0)
42+
monkeypatch.setattr(MyTonCore, "GetConfig34", lambda self: {"mainValidators": 10})
43+
output = cli.execute("remove_btc_teleport --force", no_color=True)
44+
assert "Removed btc_teleport" in output
45+
assert run_args == ['bash', script_path, '-s', '/usr/src/ton-teleport-btc-periphery', '-k', ton.local.buffer.my_work_dir + '/btc_oracle_keystore']
46+
47+
# non-masterchain validator
48+
monkeypatch.setattr(MyTonCore, "GetValidatorIndex", lambda self: 10)
49+
monkeypatch.setattr(MyTonCore, "GetConfig34", lambda self: {"mainValidators": 10})
50+
output = cli.execute("remove_btc_teleport", no_color=True)
51+
assert "Removed btc_teleport" in output
52+
assert run_args == ['bash', script_path, '-s', '/usr/src/ton-teleport-btc-periphery', '-k', ton.local.buffer.my_work_dir + '/btc_oracle_keystore']

0 commit comments

Comments
 (0)