Skip to content

Commit ef4b058

Browse files
committed
Merge branch 'ada-xpubs-tests'
2 parents e6cc02f + b9e3e43 commit ef4b058

File tree

1 file changed

+84
-0
lines changed
  • src/rust/bitbox02-rust/src/hww/api/cardano

1 file changed

+84
-0
lines changed

src/rust/bitbox02-rust/src/hww/api/cardano/xpubs.rs

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,87 @@ pub fn process(request: &pb::CardanoXpubsRequest) -> Result<Response, Error> {
3737
}
3838
Ok(Response::Xpubs(pb::CardanoXpubsResponse { xpubs }))
3939
}
40+
41+
#[cfg(test)]
42+
mod tests {
43+
use super::*;
44+
45+
use bitbox02::testing::mock_unlocked;
46+
use util::bip32::HARDENED;
47+
48+
#[test]
49+
fn test_process() {
50+
bitbox02::keystore::lock();
51+
assert_eq!(
52+
process(&pb::CardanoXpubsRequest { keypaths: vec![] }),
53+
Ok(Response::Xpubs(pb::CardanoXpubsResponse { xpubs: vec![] })),
54+
);
55+
56+
// Locked.
57+
assert_eq!(
58+
process(&pb::CardanoXpubsRequest {
59+
keypaths: vec![pb::Keypath {
60+
keypath: vec![1852 + HARDENED, 1815 + HARDENED, HARDENED]
61+
}],
62+
}),
63+
Err(Error::Generic),
64+
);
65+
66+
mock_unlocked();
67+
assert_eq!(
68+
process(&pb::CardanoXpubsRequest {
69+
keypaths: vec![
70+
pb::Keypath {
71+
keypath: vec![1852 + HARDENED, 1815 + HARDENED, HARDENED]
72+
},
73+
pb::Keypath {
74+
keypath: vec![1852 + HARDENED, 1815 + HARDENED, 1 + HARDENED]
75+
}
76+
],
77+
}),
78+
Ok(Response::Xpubs(pb::CardanoXpubsResponse {
79+
xpubs: vec![
80+
vec![
81+
135, 93, 21, 165, 177, 234, 235, 114, 75, 217, 61, 109, 54, 203, 75, 97,
82+
188, 69, 219, 186, 120, 219, 156, 176, 139, 147, 231, 40, 146, 89, 211,
83+
216, 174, 223, 100, 1, 197, 31, 45, 152, 27, 1, 127, 215, 4, 53, 226, 217,
84+
223, 160, 215, 78, 124, 206, 75, 146, 6, 29, 251, 8, 139, 95, 8, 206
85+
],
86+
vec![
87+
205, 217, 152, 187, 63, 149, 35, 26, 115, 72, 234, 223, 192, 248, 151, 77,
88+
20, 221, 211, 158, 71, 189, 60, 40, 26, 217, 150, 150, 122, 49, 129, 126,
89+
93, 199, 240, 91, 226, 212, 218, 106, 29, 25, 36, 178, 129, 146, 0, 184,
90+
113, 4, 22, 225, 46, 250, 1, 192, 77, 21, 220, 167, 234, 215, 191, 233
91+
]
92+
],
93+
})),
94+
);
95+
96+
// Invalid keypaths
97+
let invalid_keypaths: &[&[u32]] = &[
98+
// Invalid purpose
99+
&[1851 + HARDENED, 1815 + HARDENED, HARDENED],
100+
// Invalid coin
101+
&[1852 + HARDENED, 1814 + HARDENED, HARDENED],
102+
// Account too low
103+
&[1852 + HARDENED, 1815 + HARDENED, 0],
104+
&[1852 + HARDENED, 1815 + HARDENED, HARDENED - 1],
105+
// Account too high
106+
&[1852 + HARDENED, 1815 + HARDENED, 100 + HARDENED],
107+
// Wrong number of elements (too short)
108+
&[1852 + HARDENED, 1815 + HARDENED],
109+
// Wrong number of elements (too long)
110+
&[1852 + HARDENED, 1815 + HARDENED, HARDENED, 0],
111+
];
112+
for invalid_keypath in invalid_keypaths {
113+
assert_eq!(
114+
process(&pb::CardanoXpubsRequest {
115+
keypaths: vec![pb::Keypath {
116+
keypath: invalid_keypath.to_vec(),
117+
},],
118+
}),
119+
Err(Error::InvalidInput),
120+
);
121+
}
122+
}
123+
}

0 commit comments

Comments
 (0)