|
| 1 | +from pathlib import Path |
| 2 | + |
| 3 | +import pytest |
| 4 | +from pystarport.ledger import Ledger |
| 5 | + |
| 6 | +from .network import setup_custom_evm |
| 7 | +from .utils import DEFAULT_DENOM, WEI_PER_DENOM, find_fee |
| 8 | + |
| 9 | +pytestmark = pytest.mark.slow |
| 10 | + |
| 11 | + |
| 12 | +@pytest.fixture(scope="module") |
| 13 | +def custom_evm(request, tmp_path_factory): |
| 14 | + chain = request.config.getoption("chain_config") |
| 15 | + path = tmp_path_factory.mktemp("hw") |
| 16 | + ledger = Ledger() |
| 17 | + try: |
| 18 | + ledger.start() |
| 19 | + assert ledger.is_running(), "failed to start Ledger simulator" |
| 20 | + |
| 21 | + yield from setup_custom_evm( |
| 22 | + path, |
| 23 | + 27300, |
| 24 | + Path(__file__).parent / "configs/hw.jsonnet", |
| 25 | + chain=chain, |
| 26 | + ) |
| 27 | + finally: |
| 28 | + try: |
| 29 | + ledger.stop() |
| 30 | + except Exception as e: |
| 31 | + print(f"error during ledger cleanup: {e}") |
| 32 | + |
| 33 | + |
| 34 | +def test_ledger(custom_evm): |
| 35 | + cli = custom_evm.cosmos_cli() |
| 36 | + name = "hw" |
| 37 | + hw = cli.address(name) |
| 38 | + community = cli.address("community") |
| 39 | + amt1 = 8_000_000_000_000_000_000 // WEI_PER_DENOM |
| 40 | + assert cli.balance(hw) == amt1 |
| 41 | + community_balance = cli.balance(community) |
| 42 | + amt2 = 4_000_000_000_000_000_000 // WEI_PER_DENOM |
| 43 | + rsp = cli.transfer( |
| 44 | + hw, community, f"{amt2}{DEFAULT_DENOM}", ledger=True, sign_mode="amino-json" |
| 45 | + ) |
| 46 | + print("mm-rsp", rsp) |
| 47 | + assert rsp["code"] == 0, rsp["raw_log"] |
| 48 | + assert cli.balance(hw) == amt2 - find_fee(rsp) |
| 49 | + assert cli.balance(community) == community_balance + amt2 |
| 50 | + |
| 51 | + cli.delete_account(name) |
| 52 | + |
| 53 | + def check_account(name): |
| 54 | + res = cli.create_account(name, ledger=True, coin_type=118, key_type="secp256k1") |
| 55 | + assert "address" in res |
| 56 | + assert "pubkey" in res |
| 57 | + assert res["type"] == "ledger" |
| 58 | + cli.delete_account(name) |
| 59 | + |
| 60 | + names = [ |
| 61 | + "abc 1", |
| 62 | + r"\&a\)bcd*^", |
| 63 | + "钱對중ガジÑá", |
| 64 | + "this_is_a_very_long_long_long_long_long_long_long_long_long_long_long_long_name", # noqa: E501 |
| 65 | + "1 abc &abcd*^ 钱對중ガジÑá long_long_long_long_long_long_long_long_long_long_long_long_name", # noqa: E501 |
| 66 | + ] |
| 67 | + |
| 68 | + for name in names: |
| 69 | + check_account(name) |
0 commit comments