Skip to content

Commit 48a3b48

Browse files
committed
primitives - balances_map - add another test case for repeating key
1 parent da64395 commit 48a3b48

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

primitives/src/balances_map.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ mod test {
6666
let balances_map: BalancesMap = data.into_iter().collect();
6767

6868
let actual_json = serde_json::to_string(&balances_map).expect("Should serialize it");
69-
// should be all lowercase!
7069
let expected_json = r#"{"0xC91763D7F14ac5c5dDfBCD012e0D2A61ab9bDED3":"100","0xce07CbB7e054514D590a0262C93070D838bFBA2e":"50"}"#;
7170

7271
assert_eq!(expected_json, actual_json);
@@ -76,4 +75,23 @@ mod test {
7675

7776
assert_eq!(balances_map, balances_map_from_json);
7877
}
78+
79+
#[test]
80+
fn test_balances_map_deserialization_with_same_keys() {
81+
// the first is ETH Checksummed, the second is lowercase!
82+
let json = r#"{"0xC91763D7F14ac5c5dDfBCD012e0D2A61ab9bDED3":"100","0xc91763d7f14ac5c5ddfbcd012e0d2a61ab9bded3":"20","0xce07CbB7e054514D590a0262C93070D838bFBA2e":"50"}"#;
83+
84+
let actual_deserialized: BalancesMap =
85+
serde_json::from_str(&json).expect("Should deserialize it");
86+
87+
let expected_deserialized: BalancesMap = vec![
88+
(IDS["leader"].clone(), BigNum::from(50_u64)),
89+
// only the second should be accepted, as it appears second in the string and it's the latest one
90+
(IDS["follower"].clone(), BigNum::from(20_u64)),
91+
]
92+
.into_iter()
93+
.collect();
94+
95+
assert_eq!(expected_deserialized, actual_deserialized);
96+
}
7997
}

0 commit comments

Comments
 (0)