|
| 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