Skip to content

Commit 9796af9

Browse files
committed
test(unit): ContractId
Signed-off-by: Skyler Ross <[email protected]>
1 parent be0f840 commit 9796af9

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed

src/contract/contract_id.rs

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,3 +269,89 @@ impl From<EntityId> for ContractId {
269269
Self { shard, realm, num, evm_address: None, checksum }
270270
}
271271
}
272+
273+
#[cfg(test)]
274+
mod tests {
275+
use std::str::FromStr;
276+
277+
use crate::ContractId;
278+
279+
#[test]
280+
fn parse() {
281+
expect_test::expect!["0.0.5005"]
282+
.assert_eq(&ContractId::from_str("0.0.5005").unwrap().to_string());
283+
}
284+
285+
#[test]
286+
fn from_solidity_address() {
287+
expect_test::expect!["0.0.5005"].assert_eq(
288+
&ContractId::from_solidity_address("000000000000000000000000000000000000138D")
289+
.unwrap()
290+
.to_string(),
291+
);
292+
}
293+
294+
#[test]
295+
fn from_solidity_address_0x() {
296+
expect_test::expect!["0.0.5005"].assert_eq(
297+
&ContractId::from_solidity_address("0x000000000000000000000000000000000000138D")
298+
.unwrap()
299+
.to_string(),
300+
);
301+
}
302+
303+
#[test]
304+
fn from_evm_address() {
305+
expect_test::expect!["1.2.98329e006610472e6b372c080833f6d79ed833cf"].assert_eq(
306+
&ContractId::from_evm_address(1, 2, "98329e006610472e6B372C080833f6D79ED833cf")
307+
.unwrap()
308+
.to_string(),
309+
)
310+
}
311+
312+
#[test]
313+
fn from_evm_address_0x() {
314+
expect_test::expect!["1.2.98329e006610472e6b372c080833f6d79ed833cf"].assert_eq(
315+
&ContractId::from_evm_address(1, 2, "0x98329e006610472e6B372C080833f6D79ED833cf")
316+
.unwrap()
317+
.to_string(),
318+
)
319+
}
320+
321+
#[test]
322+
fn parse_evm_address() {
323+
expect_test::expect!["1.2.98329e006610472e6b372c080833f6d79ed833cf"].assert_eq(
324+
&ContractId::from_str("1.2.0x98329e006610472e6B372C080833f6D79ED833cf")
325+
.unwrap()
326+
.to_string(),
327+
)
328+
}
329+
330+
#[test]
331+
fn to_from_bytes() {
332+
let a = ContractId::from_str("1.2.3").unwrap();
333+
assert_eq!(ContractId::from_bytes(&a.to_bytes()).unwrap(), a);
334+
let b = ContractId::from_evm_address(1, 2, "0x98329e006610472e6B372C080833f6D79ED833cf")
335+
.unwrap();
336+
assert_eq!(ContractId::from_bytes(&b.to_bytes()).unwrap(), b);
337+
}
338+
339+
#[test]
340+
fn to_solidity_address() {
341+
expect_test::expect!["000000000000000000000000000000000000138d"].assert_eq(
342+
&ContractId { shard: 0, realm: 0, num: 5005, checksum: None, evm_address: None }
343+
.to_solidity_address()
344+
.unwrap(),
345+
)
346+
}
347+
348+
#[test]
349+
fn to_solidity_address_2() {
350+
expect_test::expect!["98329e006610472e6b372c080833f6d79ed833cf"].assert_eq(
351+
&ContractId::from_evm_address(1, 2, "0x98329e006610472e6B372C080833f6D79ED833cf")
352+
.unwrap()
353+
.to_solidity_address()
354+
.unwrap(),
355+
)
356+
}
357+
}

0 commit comments

Comments
 (0)