Skip to content

Commit 1b7ce23

Browse files
committed
fix(fortuna): improve tests for query builder
1 parent f155a4f commit 1b7ce23

File tree

1 file changed

+108
-16
lines changed

1 file changed

+108
-16
lines changed

apps/fortuna/src/history.rs

Lines changed: 108 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -517,10 +517,6 @@ mod test {
517517
}
518518
}
519519

520-
fn to_hex_string<T: ToHex>(val: T) -> String {
521-
format!("0x{}", val.encode_hex::<String>())
522-
}
523-
524520
#[tokio::test]
525521
async fn test_history_return_correct_logs() {
526522
let history = History::new_in_memory().await.unwrap();
@@ -570,7 +566,19 @@ mod test {
570566

571567
let logs = history
572568
.query()
573-
.search(to_hex_string(status.request_tx_hash))
569+
.search(status.request_tx_hash.encode_hex())
570+
.unwrap()
571+
.execute()
572+
.await
573+
.unwrap();
574+
assert_eq!(logs, vec![status.clone()]);
575+
576+
let logs = history
577+
.query()
578+
.search(format!(
579+
"0x{}",
580+
status.request_tx_hash.encode_hex::<String>()
581+
))
574582
.unwrap()
575583
.execute()
576584
.await
@@ -579,7 +587,28 @@ mod test {
579587

580588
let logs = history
581589
.query()
582-
.search(to_hex_string(status.request_tx_hash))
590+
.search(status.request_tx_hash.encode_hex::<String>().to_uppercase())
591+
.unwrap()
592+
.execute()
593+
.await
594+
.unwrap();
595+
assert_eq!(logs, vec![status.clone()]);
596+
597+
let logs = history
598+
.query()
599+
.search(format!(
600+
"0x{}",
601+
status.request_tx_hash.encode_hex::<String>().to_uppercase()
602+
))
603+
.unwrap()
604+
.execute()
605+
.await
606+
.unwrap();
607+
assert_eq!(logs, vec![status.clone()]);
608+
609+
let logs = history
610+
.query()
611+
.search(status.request_tx_hash.encode_hex())
583612
.unwrap()
584613
.state(StateTag::Completed)
585614
.execute()
@@ -589,7 +618,7 @@ mod test {
589618

590619
let logs = history
591620
.query()
592-
.search(to_hex_string(reveal_tx_hash))
621+
.search(reveal_tx_hash.encode_hex())
593622
.unwrap()
594623
.execute()
595624
.await
@@ -598,7 +627,37 @@ mod test {
598627

599628
let logs = history
600629
.query()
601-
.search(to_hex_string(reveal_tx_hash))
630+
.search(format!("0x{}", reveal_tx_hash.encode_hex::<String>()))
631+
.unwrap()
632+
.execute()
633+
.await
634+
.unwrap();
635+
assert_eq!(logs, vec![status.clone()]);
636+
637+
let logs = history
638+
.query()
639+
.search(reveal_tx_hash.encode_hex::<String>().to_uppercase())
640+
.unwrap()
641+
.execute()
642+
.await
643+
.unwrap();
644+
assert_eq!(logs, vec![status.clone()]);
645+
646+
let logs = history
647+
.query()
648+
.search(format!(
649+
"0x{}",
650+
reveal_tx_hash.encode_hex::<String>().to_uppercase()
651+
))
652+
.unwrap()
653+
.execute()
654+
.await
655+
.unwrap();
656+
assert_eq!(logs, vec![status.clone()]);
657+
658+
let logs = history
659+
.query()
660+
.search(reveal_tx_hash.encode_hex())
602661
.unwrap()
603662
.state(StateTag::Completed)
604663
.execute()
@@ -608,7 +667,40 @@ mod test {
608667

609668
let logs = history
610669
.query()
611-
.search(to_hex_string(status.sender))
670+
.search(status.sender.encode_hex())
671+
.unwrap()
672+
.network_id(status.network_id)
673+
.execute()
674+
.await
675+
.unwrap();
676+
assert_eq!(logs, vec![status.clone()]);
677+
678+
let logs = history
679+
.query()
680+
.search(format!("0x{}", status.sender.encode_hex::<String>()))
681+
.unwrap()
682+
.network_id(status.network_id)
683+
.execute()
684+
.await
685+
.unwrap();
686+
assert_eq!(logs, vec![status.clone()]);
687+
688+
let logs = history
689+
.query()
690+
.search(status.sender.encode_hex::<String>().to_uppercase())
691+
.unwrap()
692+
.network_id(status.network_id)
693+
.execute()
694+
.await
695+
.unwrap();
696+
assert_eq!(logs, vec![status.clone()]);
697+
698+
let logs = history
699+
.query()
700+
.search(format!(
701+
"0x{}",
702+
status.sender.encode_hex::<String>().to_uppercase()
703+
))
612704
.unwrap()
613705
.network_id(status.network_id)
614706
.execute()
@@ -618,7 +710,7 @@ mod test {
618710

619711
let logs = history
620712
.query()
621-
.search(to_hex_string(status.sender))
713+
.search(status.sender.encode_hex())
622714
.unwrap()
623715
.execute()
624716
.await
@@ -627,7 +719,7 @@ mod test {
627719

628720
let logs = history
629721
.query()
630-
.search(to_hex_string(status.sender))
722+
.search(status.sender.encode_hex())
631723
.unwrap()
632724
.state(StateTag::Completed)
633725
.execute()
@@ -662,7 +754,7 @@ mod test {
662754

663755
let logs = history
664756
.query()
665-
.search(to_hex_string(reveal_tx_hash))
757+
.search(reveal_tx_hash.encode_hex())
666758
.unwrap()
667759
.execute()
668760
.await
@@ -682,7 +774,7 @@ mod test {
682774
History::update_request_status(&history.pool, status.clone()).await;
683775
let logs = history
684776
.query()
685-
.search(to_hex_string(status.request_tx_hash))
777+
.search(status.request_tx_hash.encode_hex())
686778
.unwrap()
687779
.execute()
688780
.await
@@ -738,7 +830,7 @@ mod test {
738830

739831
let logs = history
740832
.query()
741-
.search(to_hex_string(TxHash::zero()))
833+
.search(TxHash::zero().encode_hex())
742834
.unwrap()
743835
.execute()
744836
.await
@@ -747,7 +839,7 @@ mod test {
747839

748840
let logs = history
749841
.query()
750-
.search(to_hex_string(Address::zero()))
842+
.search(Address::zero().encode_hex())
751843
.unwrap()
752844
.network_id(status.network_id)
753845
.execute()
@@ -757,7 +849,7 @@ mod test {
757849

758850
let logs = history
759851
.query()
760-
.search(to_hex_string(Address::zero()))
852+
.search(Address::zero().encode_hex())
761853
.unwrap()
762854
.execute()
763855
.await

0 commit comments

Comments
 (0)