Skip to content

Commit 13a908b

Browse files
committed
ledger_zemu
1 parent 8214693 commit 13a908b

File tree

3 files changed

+82
-1
lines changed

3 files changed

+82
-1
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
local config = import 'default.jsonnet';
2+
local chain = (import 'chains.jsonnet')[std.extVar('CHAIN_CONFIG')];
3+
4+
config {
5+
'evm-canary-net-1'+: {
6+
hw_account: {
7+
name: 'hw',
8+
coins: '8000000000000000000' + chain.evm_denom,
9+
'coin-type': 118,
10+
},
11+
},
12+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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)

tests/nix/evm/default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ let
2323
tags =
2424
[
2525
"ledger"
26+
"ledger_zemu"
2627
"netgo"
2728
"osusergo"
2829
"pebbledb"
2930
]
3031
++ lib.optionals nativeByteOrder [ "nativebyteorder" ]
31-
++ lib.optionals buildStdenv.isDarwin [ "static_wasm" ]
3232
++ lib.optionals buildStdenv.isLinux [ "muslc" ];
3333

3434
ldflags =

0 commit comments

Comments
 (0)