Skip to content

Commit

Permalink
Add ChildIndex testsg
Browse files Browse the repository at this point in the history
  • Loading branch information
howardwu committed Sep 3, 2019
1 parent e076c11 commit 1685c3c
Show file tree
Hide file tree
Showing 4 changed files with 199 additions and 117 deletions.
78 changes: 39 additions & 39 deletions bitcoin/src/derivation_path.rs
Expand Up @@ -406,33 +406,33 @@ mod tests {
);
assert_eq!(
BitcoinDerivationPath::<N>::from_str("m/0"),
Ok(vec![ChildIndex::from_normal(0).unwrap()].try_into().unwrap())
Ok(vec![ChildIndex::normal(0).unwrap()].try_into().unwrap())
);
assert_eq!(
BitcoinDerivationPath::<N>::from_str("m/0/1"),
Ok(
vec![ChildIndex::from_normal(0).unwrap(), ChildIndex::from_normal(1).unwrap()]
vec![ChildIndex::normal(0).unwrap(), ChildIndex::normal(1).unwrap()]
.try_into()
.unwrap()
)
);
assert_eq!(
BitcoinDerivationPath::<N>::from_str("m/0/1/2"),
Ok(vec![
ChildIndex::from_normal(0).unwrap(),
ChildIndex::from_normal(1).unwrap(),
ChildIndex::from_normal(2).unwrap()
ChildIndex::normal(0).unwrap(),
ChildIndex::normal(1).unwrap(),
ChildIndex::normal(2).unwrap()
]
.try_into()
.unwrap())
);
assert_eq!(
BitcoinDerivationPath::<N>::from_str("m/0/1/2/3"),
Ok(vec![
ChildIndex::from_normal(0).unwrap(),
ChildIndex::from_normal(1).unwrap(),
ChildIndex::from_normal(2).unwrap(),
ChildIndex::from_normal(3).unwrap()
ChildIndex::normal(0).unwrap(),
ChildIndex::normal(1).unwrap(),
ChildIndex::normal(2).unwrap(),
ChildIndex::normal(3).unwrap()
]
.try_into()
.unwrap())
Expand All @@ -444,46 +444,46 @@ mod tests {
);
assert_eq!(
BitcoinDerivationPath::<N>::from_str("m/0'"),
Ok(vec![ChildIndex::from_hardened(0).unwrap()].try_into().unwrap())
Ok(vec![ChildIndex::hardened(0).unwrap()].try_into().unwrap())
);
assert_eq!(
BitcoinDerivationPath::<N>::from_str("m/0'/1"),
Ok(vec![
ChildIndex::from_hardened(0).unwrap(),
ChildIndex::from_normal(1).unwrap()
ChildIndex::hardened(0).unwrap(),
ChildIndex::normal(1).unwrap()
]
.try_into()
.unwrap())
);
assert_eq!(
BitcoinDerivationPath::<N>::from_str("m/0'/1/2'"),
Ok(vec![
ChildIndex::from_hardened(0).unwrap(),
ChildIndex::from_normal(1).unwrap(),
ChildIndex::from_hardened(2).unwrap(),
ChildIndex::hardened(0).unwrap(),
ChildIndex::normal(1).unwrap(),
ChildIndex::hardened(2).unwrap(),
]
.try_into()
.unwrap())
);
assert_eq!(
BitcoinDerivationPath::<N>::from_str("m/0'/1/2'/3"),
Ok(vec![
ChildIndex::from_hardened(0).unwrap(),
ChildIndex::from_normal(1).unwrap(),
ChildIndex::from_hardened(2).unwrap(),
ChildIndex::from_normal(3).unwrap(),
ChildIndex::hardened(0).unwrap(),
ChildIndex::normal(1).unwrap(),
ChildIndex::hardened(2).unwrap(),
ChildIndex::normal(3).unwrap(),
]
.try_into()
.unwrap())
);
assert_eq!(
BitcoinDerivationPath::<N>::from_str("m/0'/1/2'/3/4'"),
Ok(vec![
ChildIndex::from_hardened(0).unwrap(),
ChildIndex::from_normal(1).unwrap(),
ChildIndex::from_hardened(2).unwrap(),
ChildIndex::from_normal(3).unwrap(),
ChildIndex::from_hardened(4).unwrap(),
ChildIndex::hardened(0).unwrap(),
ChildIndex::normal(1).unwrap(),
ChildIndex::hardened(2).unwrap(),
ChildIndex::normal(3).unwrap(),
ChildIndex::hardened(4).unwrap(),
]
.try_into()
.unwrap())
Expand All @@ -495,46 +495,46 @@ mod tests {
);
assert_eq!(
BitcoinDerivationPath::<N>::from_str("m/0h"),
Ok(vec![ChildIndex::from_hardened(0).unwrap()].try_into().unwrap())
Ok(vec![ChildIndex::hardened(0).unwrap()].try_into().unwrap())
);
assert_eq!(
BitcoinDerivationPath::<N>::from_str("m/0h/1'"),
Ok(vec![
ChildIndex::from_hardened(0).unwrap(),
ChildIndex::from_hardened(1).unwrap()
ChildIndex::hardened(0).unwrap(),
ChildIndex::hardened(1).unwrap()
]
.try_into()
.unwrap())
);
assert_eq!(
BitcoinDerivationPath::<N>::from_str("m/0'/1h/2'"),
Ok(vec![
ChildIndex::from_hardened(0).unwrap(),
ChildIndex::from_hardened(1).unwrap(),
ChildIndex::from_hardened(2).unwrap(),
ChildIndex::hardened(0).unwrap(),
ChildIndex::hardened(1).unwrap(),
ChildIndex::hardened(2).unwrap(),
]
.try_into()
.unwrap())
);
assert_eq!(
BitcoinDerivationPath::<N>::from_str("m/0h/1'/2h/3'"),
Ok(vec![
ChildIndex::from_hardened(0).unwrap(),
ChildIndex::from_hardened(1).unwrap(),
ChildIndex::from_hardened(2).unwrap(),
ChildIndex::from_hardened(3).unwrap(),
ChildIndex::hardened(0).unwrap(),
ChildIndex::hardened(1).unwrap(),
ChildIndex::hardened(2).unwrap(),
ChildIndex::hardened(3).unwrap(),
]
.try_into()
.unwrap())
);
assert_eq!(
BitcoinDerivationPath::<N>::from_str("m/0'/1h/2'/3h/4'"),
Ok(vec![
ChildIndex::from_hardened(0).unwrap(),
ChildIndex::from_hardened(1).unwrap(),
ChildIndex::from_hardened(2).unwrap(),
ChildIndex::from_hardened(3).unwrap(),
ChildIndex::from_hardened(4).unwrap(),
ChildIndex::hardened(0).unwrap(),
ChildIndex::hardened(1).unwrap(),
ChildIndex::hardened(2).unwrap(),
ChildIndex::hardened(3).unwrap(),
ChildIndex::hardened(4).unwrap(),
]
.try_into()
.unwrap())
Expand Down
79 changes: 40 additions & 39 deletions ethereum/src/derivation_path.rs
Expand Up @@ -186,6 +186,7 @@ mod tests {

#[test]
fn valid_path() {

type N = Mainnet;

assert_eq!(
Expand All @@ -194,33 +195,33 @@ mod tests {
);
assert_eq!(
EthereumDerivationPath::<N>::from_str("m/0"),
Ok(vec![ChildIndex::from_normal(0).unwrap()].try_into().unwrap())
Ok(vec![ChildIndex::normal(0).unwrap()].try_into().unwrap())
);
assert_eq!(
EthereumDerivationPath::<N>::from_str("m/0/1"),
Ok(
vec![ChildIndex::from_normal(0).unwrap(), ChildIndex::from_normal(1).unwrap()]
vec![ChildIndex::normal(0).unwrap(), ChildIndex::normal(1).unwrap()]
.try_into()
.unwrap()
)
);
assert_eq!(
EthereumDerivationPath::<N>::from_str("m/0/1/2"),
Ok(vec![
ChildIndex::from_normal(0).unwrap(),
ChildIndex::from_normal(1).unwrap(),
ChildIndex::from_normal(2).unwrap()
ChildIndex::normal(0).unwrap(),
ChildIndex::normal(1).unwrap(),
ChildIndex::normal(2).unwrap()
]
.try_into()
.unwrap())
);
assert_eq!(
EthereumDerivationPath::<N>::from_str("m/0/1/2/3"),
Ok(vec![
ChildIndex::from_normal(0).unwrap(),
ChildIndex::from_normal(1).unwrap(),
ChildIndex::from_normal(2).unwrap(),
ChildIndex::from_normal(3).unwrap()
ChildIndex::normal(0).unwrap(),
ChildIndex::normal(1).unwrap(),
ChildIndex::normal(2).unwrap(),
ChildIndex::normal(3).unwrap()
]
.try_into()
.unwrap())
Expand All @@ -232,46 +233,46 @@ mod tests {
);
assert_eq!(
EthereumDerivationPath::<N>::from_str("m/0'"),
Ok(vec![ChildIndex::from_hardened(0).unwrap()].try_into().unwrap())
Ok(vec![ChildIndex::hardened(0).unwrap()].try_into().unwrap())
);
assert_eq!(
EthereumDerivationPath::<N>::from_str("m/0'/1"),
Ok(vec![
ChildIndex::from_hardened(0).unwrap(),
ChildIndex::from_normal(1).unwrap()
ChildIndex::hardened(0).unwrap(),
ChildIndex::normal(1).unwrap()
]
.try_into()
.unwrap())
);
assert_eq!(
EthereumDerivationPath::<N>::from_str("m/0'/1/2'"),
Ok(vec![
ChildIndex::from_hardened(0).unwrap(),
ChildIndex::from_normal(1).unwrap(),
ChildIndex::from_hardened(2).unwrap(),
ChildIndex::hardened(0).unwrap(),
ChildIndex::normal(1).unwrap(),
ChildIndex::hardened(2).unwrap(),
]
.try_into()
.unwrap())
);
assert_eq!(
EthereumDerivationPath::<N>::from_str("m/0'/1/2'/3"),
Ok(vec![
ChildIndex::from_hardened(0).unwrap(),
ChildIndex::from_normal(1).unwrap(),
ChildIndex::from_hardened(2).unwrap(),
ChildIndex::from_normal(3).unwrap(),
ChildIndex::hardened(0).unwrap(),
ChildIndex::normal(1).unwrap(),
ChildIndex::hardened(2).unwrap(),
ChildIndex::normal(3).unwrap(),
]
.try_into()
.unwrap())
);
assert_eq!(
EthereumDerivationPath::<N>::from_str("m/0'/1/2'/3/4'"),
Ok(vec![
ChildIndex::from_hardened(0).unwrap(),
ChildIndex::from_normal(1).unwrap(),
ChildIndex::from_hardened(2).unwrap(),
ChildIndex::from_normal(3).unwrap(),
ChildIndex::from_hardened(4).unwrap(),
ChildIndex::hardened(0).unwrap(),
ChildIndex::normal(1).unwrap(),
ChildIndex::hardened(2).unwrap(),
ChildIndex::normal(3).unwrap(),
ChildIndex::hardened(4).unwrap(),
]
.try_into()
.unwrap())
Expand All @@ -283,46 +284,46 @@ mod tests {
);
assert_eq!(
EthereumDerivationPath::<N>::from_str("m/0h"),
Ok(vec![ChildIndex::from_hardened(0).unwrap()].try_into().unwrap())
Ok(vec![ChildIndex::hardened(0).unwrap()].try_into().unwrap())
);
assert_eq!(
EthereumDerivationPath::<N>::from_str("m/0h/1'"),
Ok(vec![
ChildIndex::from_hardened(0).unwrap(),
ChildIndex::from_hardened(1).unwrap()
ChildIndex::hardened(0).unwrap(),
ChildIndex::hardened(1).unwrap()
]
.try_into()
.unwrap())
);
assert_eq!(
EthereumDerivationPath::<N>::from_str("m/0'/1h/2'"),
Ok(vec![
ChildIndex::from_hardened(0).unwrap(),
ChildIndex::from_hardened(1).unwrap(),
ChildIndex::from_hardened(2).unwrap(),
ChildIndex::hardened(0).unwrap(),
ChildIndex::hardened(1).unwrap(),
ChildIndex::hardened(2).unwrap(),
]
.try_into()
.unwrap())
);
assert_eq!(
EthereumDerivationPath::<N>::from_str("m/0h/1'/2h/3'"),
Ok(vec![
ChildIndex::from_hardened(0).unwrap(),
ChildIndex::from_hardened(1).unwrap(),
ChildIndex::from_hardened(2).unwrap(),
ChildIndex::from_hardened(3).unwrap(),
ChildIndex::hardened(0).unwrap(),
ChildIndex::hardened(1).unwrap(),
ChildIndex::hardened(2).unwrap(),
ChildIndex::hardened(3).unwrap(),
]
.try_into()
.unwrap())
);
assert_eq!(
EthereumDerivationPath::<N>::from_str("m/0'/1h/2'/3h/4'"),
Ok(vec![
ChildIndex::from_hardened(0).unwrap(),
ChildIndex::from_hardened(1).unwrap(),
ChildIndex::from_hardened(2).unwrap(),
ChildIndex::from_hardened(3).unwrap(),
ChildIndex::from_hardened(4).unwrap(),
ChildIndex::hardened(0).unwrap(),
ChildIndex::hardened(1).unwrap(),
ChildIndex::hardened(2).unwrap(),
ChildIndex::hardened(3).unwrap(),
ChildIndex::hardened(4).unwrap(),
]
.try_into()
.unwrap())
Expand Down

0 comments on commit 1685c3c

Please sign in to comment.