Skip to content

Commit bf4821d

Browse files
committed
Fixed format; test is to be done
1 parent 27929b8 commit bf4821d

File tree

3 files changed

+90
-82
lines changed

3 files changed

+90
-82
lines changed

Cargo.lock

Lines changed: 55 additions & 75 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

common/src/types.rs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2125,12 +2125,14 @@ mod tests {
21252125

21262126
#[test]
21272127
fn parse_voting_values() -> Result<()> {
2128-
let count = VoteCount::from_str("0/5/1")?;
2128+
let count = VoteCount::from_str("y0/n5/a1")?;
21292129
assert_eq!(count.yes, 0);
21302130
assert_eq!(count.no, 5);
21312131
assert_eq!(count.abstain, 1);
21322132

2133-
let counts: VoteResult<VoteCount> = VoteResult::from_str("c0/5/1:d0/1/2:s123/456/0788890")?;
2133+
let counts: VoteResult<VoteCount> = VoteResult::from_str(
2134+
"cy0/n5/a1:dy0/n1/a2:sy123/n456/a0788890"
2135+
)?;
21342136
assert_eq!(counts.committee, count);
21352137
assert_eq!(counts.drep.yes, 0);
21362138
assert_eq!(counts.drep.no, 1);
@@ -2140,4 +2142,30 @@ mod tests {
21402142
assert_eq!(counts.pool.abstain, 788890);
21412143
Ok(())
21422144
}
2145+
2146+
#[test]
2147+
fn serialize_stake_addres() -> Result<()> {
2148+
let serialized = "{\
2149+
\"network\":\"Mainnet\",\
2150+
\"credential\":{\
2151+
\"AddrKeyHash\":\"45dee6ee5d7f631b6226d45f29da411c42fa7e816dc0948d31e0dba7\"\
2152+
}\
2153+
}";
2154+
2155+
let addr = serde_json::from_str::<StakeAddress>(serialized)?;
2156+
assert_eq!(addr.network, NetworkId::Mainnet);
2157+
assert_eq!(addr.credential, StakeCredential::AddrKeyHash(KeyHash::from(
2158+
[
2159+
0x45, 0xde, 0xe6, 0xee, 0x5d, 0x7f, 0x63, 0x1b,
2160+
0x62, 0x26, 0xd4, 0x5f, 0x29, 0xda, 0x41, 0x1c,
2161+
0x42, 0xfa, 0x7e, 0x81, 0x6d, 0xc0, 0x94, 0x8d,
2162+
0x31, 0xe0, 0xdb, 0xa7,
2163+
]
2164+
)));
2165+
2166+
let serialized_back = serde_json::to_string(&addr)?;
2167+
assert_eq!(serialized_back, serialized);
2168+
2169+
Ok(())
2170+
}
21432171
}

0 commit comments

Comments
 (0)