Skip to content

Commit 2ec0fb1

Browse files
committed
eth: add simulator integration tests for eth tx data streaming
1 parent 8f103f6 commit 2ec0fb1

1 file changed

Lines changed: 174 additions & 0 deletions

File tree

tests/test_eth.rs

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
#![cfg(feature = "simulator")]
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
// Simulators only run on linux/amd64.
5+
#![cfg(all(target_os = "linux", target_arch = "x86_64"))]
6+
7+
#[cfg(not(feature = "tokio"))]
8+
compile_error!("Enable the tokio feature to run simulator tests");
9+
10+
mod util;
11+
12+
use bitbox_api::eth::{EIP1559Transaction, Transaction};
13+
use util::test_initialized_simulators;
14+
15+
#[tokio::test]
16+
async fn test_eth_address() {
17+
test_initialized_simulators(async |paired_bitbox| {
18+
let address = paired_bitbox
19+
.eth_address(1, &"m/44'/60'/0'/0/0".try_into().unwrap(), false)
20+
.await
21+
.unwrap();
22+
// Verify address format (0x prefix, 40 hex chars)
23+
assert!(address.starts_with("0x"));
24+
assert_eq!(address.len(), 42);
25+
})
26+
.await
27+
}
28+
29+
#[tokio::test]
30+
async fn test_eth_sign_transaction_nonstreaming() {
31+
test_initialized_simulators(async |paired_bitbox| {
32+
// Skip if firmware doesn't support ETH
33+
if !paired_bitbox.eth_supported() {
34+
return;
35+
}
36+
37+
// Small data (under threshold) - traditional mode
38+
let tx = Transaction {
39+
nonce: vec![0x01],
40+
gas_price: vec![0x01],
41+
gas_limit: vec![0x52, 0x08],
42+
recipient: [
43+
0x04, 0xf2, 0x64, 0xcf, 0x34, 0x44, 0x03, 0x13, 0xb4, 0xa0, 0x19, 0x2a, 0x35, 0x28,
44+
0x14, 0xfb, 0xe9, 0x27, 0xb8, 0x85,
45+
],
46+
value: vec![0x01],
47+
data: vec![0xAB; 100],
48+
};
49+
50+
let result = paired_bitbox
51+
.eth_sign_transaction(1, &"m/44'/60'/0'/0/0".try_into().unwrap(), &tx, None)
52+
.await;
53+
assert!(
54+
result.is_ok(),
55+
"eth_sign_transaction failed: {:?}",
56+
result.err()
57+
);
58+
assert_eq!(result.unwrap().len(), 65);
59+
})
60+
.await
61+
}
62+
63+
#[tokio::test]
64+
async fn test_eth_sign_transaction_streaming() {
65+
test_initialized_simulators(async |paired_bitbox| {
66+
// Skip if firmware doesn't support streaming (requires >=9.26.0)
67+
if !semver::VersionReq::parse(">=9.26.0")
68+
.unwrap()
69+
.matches(paired_bitbox.version())
70+
{
71+
return;
72+
}
73+
74+
// Large data (over threshold) - streaming mode
75+
let tx = Transaction {
76+
nonce: vec![0x01],
77+
gas_price: vec![0x01],
78+
gas_limit: vec![0x52, 0x08],
79+
recipient: [
80+
0x04, 0xf2, 0x64, 0xcf, 0x34, 0x44, 0x03, 0x13, 0xb4, 0xa0, 0x19, 0x2a, 0x35, 0x28,
81+
0x14, 0xfb, 0xe9, 0x27, 0xb8, 0x85,
82+
],
83+
value: vec![0x01],
84+
data: vec![0xAB; 10000],
85+
};
86+
87+
let result = paired_bitbox
88+
.eth_sign_transaction(1, &"m/44'/60'/0'/0/0".try_into().unwrap(), &tx, None)
89+
.await;
90+
assert!(
91+
result.is_ok(),
92+
"eth_sign_transaction streaming failed: {:?}",
93+
result.err()
94+
);
95+
assert_eq!(result.unwrap().len(), 65);
96+
})
97+
.await
98+
}
99+
100+
#[tokio::test]
101+
async fn test_eth_sign_1559_transaction_nonstreaming() {
102+
test_initialized_simulators(async |paired_bitbox| {
103+
// EIP-1559 requires >=9.16.0
104+
if !semver::VersionReq::parse(">=9.16.0")
105+
.unwrap()
106+
.matches(paired_bitbox.version())
107+
{
108+
return;
109+
}
110+
111+
let tx = EIP1559Transaction {
112+
chain_id: 1,
113+
nonce: vec![0x01],
114+
max_priority_fee_per_gas: vec![0x01],
115+
max_fee_per_gas: vec![0x01],
116+
gas_limit: vec![0x52, 0x08],
117+
recipient: [
118+
0x04, 0xf2, 0x64, 0xcf, 0x34, 0x44, 0x03, 0x13, 0xb4, 0xa0, 0x19, 0x2a, 0x35, 0x28,
119+
0x14, 0xfb, 0xe9, 0x27, 0xb8, 0x85,
120+
],
121+
value: vec![0x01],
122+
data: vec![0xAB; 100],
123+
};
124+
125+
let result = paired_bitbox
126+
.eth_sign_1559_transaction(&"m/44'/60'/0'/0/0".try_into().unwrap(), &tx, None)
127+
.await;
128+
assert!(
129+
result.is_ok(),
130+
"eth_sign_1559_transaction failed: {:?}",
131+
result.err()
132+
);
133+
assert_eq!(result.unwrap().len(), 65);
134+
})
135+
.await
136+
}
137+
138+
#[tokio::test]
139+
async fn test_eth_sign_1559_transaction_streaming() {
140+
test_initialized_simulators(async |paired_bitbox| {
141+
// Skip if firmware doesn't support streaming (requires >=9.26.0)
142+
if !semver::VersionReq::parse(">=9.26.0")
143+
.unwrap()
144+
.matches(paired_bitbox.version())
145+
{
146+
return;
147+
}
148+
149+
let tx = EIP1559Transaction {
150+
chain_id: 1,
151+
nonce: vec![0x01],
152+
max_priority_fee_per_gas: vec![0x01],
153+
max_fee_per_gas: vec![0x01],
154+
gas_limit: vec![0x52, 0x08],
155+
recipient: [
156+
0x04, 0xf2, 0x64, 0xcf, 0x34, 0x44, 0x03, 0x13, 0xb4, 0xa0, 0x19, 0x2a, 0x35, 0x28,
157+
0x14, 0xfb, 0xe9, 0x27, 0xb8, 0x85,
158+
],
159+
value: vec![0x01],
160+
data: vec![0xCD; 8000],
161+
};
162+
163+
let result = paired_bitbox
164+
.eth_sign_1559_transaction(&"m/44'/60'/0'/0/0".try_into().unwrap(), &tx, None)
165+
.await;
166+
assert!(
167+
result.is_ok(),
168+
"eth_sign_1559_transaction streaming failed: {:?}",
169+
result.err()
170+
);
171+
assert_eq!(result.unwrap().len(), 65);
172+
})
173+
.await
174+
}

0 commit comments

Comments
 (0)