11use crate :: startup;
2+ use assert_fs:: TempDir ;
3+ use chain_impl_mockchain:: { block:: BlockDate , fragment:: Fragment } ;
24use jormungandr_automation:: {
35 jcli:: JCli ,
4- jormungandr:: { explorer:: configuration:: ExplorerParams , ConfigurationBuilder } ,
6+ jormungandr:: {
7+ explorer:: { configuration:: ExplorerParams , verifier:: ExplorerVerifier } ,
8+ ConfigurationBuilder , Starter ,
9+ } ,
510} ;
6- use jormungandr_lib:: interfaces:: ActiveSlotCoefficient ;
7- //TODO still wip
8- #[ ignore]
11+ use jormungandr_lib:: interfaces:: { ActiveSlotCoefficient , FragmentStatus } ;
12+ use jortestkit:: process:: Wait ;
13+ use std:: { collections:: HashMap , time:: Duration } ;
14+ use thor:: TransactionHash ;
15+
916#[ test]
1017pub fn explorer_address_test ( ) {
11- let _jcli: JCli = Default :: default ( ) ;
1218 let sender = thor:: Wallet :: default ( ) ;
13- let _receiver = thor:: Wallet :: default ( ) ;
14- let _transaction_value = 1_000 ;
15- let address_bech32_prefix = "ca" . to_string ( ) ;
19+ let address_bech32_prefix = sender. address ( ) . 0 ;
1620
1721 let mut config = ConfigurationBuilder :: new ( ) ;
1822 config. with_consensus_genesis_praos_active_slot_coeff ( ActiveSlotCoefficient :: MAXIMUM ) ;
@@ -32,9 +36,166 @@ pub fn explorer_address_test() {
3236 explorer_address. errors. unwrap( )
3337 ) ;
3438
35- assert_eq ! (
36- explorer_address. data. unwrap( ) . address. id,
37- sender. address( ) . to_string( ) ,
38- "Addresses is not the same"
39+ ExplorerVerifier :: assert_address ( sender. address ( ) , explorer_address. data . unwrap ( ) . address ) ;
40+ }
41+
42+ #[ test]
43+ pub fn explorer_transactions_not_existing_address_test ( ) {
44+ let jcli: JCli = Default :: default ( ) ;
45+ let sender = thor:: Wallet :: default ( ) ;
46+ let receiver = thor:: Wallet :: default ( ) ;
47+ let test_address = thor:: Wallet :: default ( ) ;
48+ let transaction_value = 1_000 ;
49+ let attempts_number = 20 ;
50+
51+ let mut config = ConfigurationBuilder :: new ( ) ;
52+ config. with_consensus_genesis_praos_active_slot_coeff ( ActiveSlotCoefficient :: MAXIMUM ) ;
53+
54+ let ( jormungandr, _initial_stake_pools) =
55+ startup:: start_stake_pool ( & [ sender. clone ( ) ] , & [ sender. clone ( ) ] , & mut config) . unwrap ( ) ;
56+
57+ let transaction = thor:: FragmentBuilder :: new (
58+ & jormungandr. genesis_block_hash ( ) ,
59+ & jormungandr. fees ( ) ,
60+ BlockDate :: first ( ) . next_epoch ( ) ,
61+ )
62+ . transaction ( & sender, receiver. address ( ) , transaction_value. into ( ) )
63+ . unwrap ( ) ;
64+
65+ let wait = Wait :: new ( Duration :: from_secs ( 3 ) , attempts_number) ;
66+
67+ jcli. fragment_sender ( & jormungandr)
68+ . send ( & transaction. encode ( ) )
69+ . assert_in_block_with_wait ( & wait) ;
70+
71+ let explorer_process = jormungandr. explorer ( ExplorerParams :: default ( ) ) ;
72+ let explorer = explorer_process. client ( ) ;
73+
74+ let explorer_address = explorer
75+ . transactions_address ( test_address. address ( ) . to_string ( ) )
76+ . unwrap ( ) ;
77+
78+ assert ! (
79+ explorer_address. errors. is_none( ) ,
80+ "{:?}" ,
81+ explorer_address. errors. unwrap( )
82+ ) ;
83+ let explorer_transactions_by_address =
84+ explorer_address. data . unwrap ( ) . tip . transactions_by_address ;
85+
86+ ExplorerVerifier :: assert_transactions_address ( HashMap :: new ( ) , explorer_transactions_by_address) ;
87+ }
88+
89+ // BUG NPG-2869
90+ // TODO comment out the fields (inputs,outputs, certificate) in transaction_by_address.graphql when the bug is fixed
91+ // add the verifier for those fields (inputs,outputs,certificate) in explorer_verifier
92+ #[ test]
93+ pub fn explorer_transactions_address_test ( ) {
94+ let jcli: JCli = Default :: default ( ) ;
95+ let mut sender = thor:: Wallet :: default ( ) ;
96+ let receiver = thor:: Wallet :: default ( ) ;
97+ let transaction1_value = 1_000 ;
98+ let transaction2_value = 2_0 ;
99+ let transaction3_value = 3_0 ;
100+ let attempts_number = 20 ;
101+ let temp_dir = TempDir :: new ( ) . unwrap ( ) ;
102+ let mut fragments = vec ! [ ] ;
103+
104+ let config = ConfigurationBuilder :: default ( )
105+ . with_funds ( vec ! [ sender. to_initial_fund( 1_000_000 ) ] )
106+ . build ( & temp_dir) ;
107+
108+ let jormungandr = Starter :: new ( )
109+ . temp_dir ( temp_dir)
110+ . config ( config)
111+ . start ( )
112+ . expect ( "Cannot start jormungandr" ) ;
113+
114+ let wait = Wait :: new ( Duration :: from_secs ( 3 ) , attempts_number) ;
115+
116+ let fragment_builder = thor:: FragmentBuilder :: new (
117+ & jormungandr. genesis_block_hash ( ) ,
118+ & jormungandr. fees ( ) ,
119+ BlockDate :: first ( ) . next_epoch ( ) ,
120+ ) ;
121+
122+ let transaction_1 = fragment_builder
123+ . transaction ( & sender, receiver. address ( ) , transaction1_value. into ( ) )
124+ . unwrap ( ) ;
125+
126+ jcli. fragment_sender ( & jormungandr)
127+ . send ( & transaction_1. encode ( ) )
128+ . assert_in_block_with_wait ( & wait) ;
129+
130+ fragments. push ( & transaction_1) ;
131+
132+ sender. confirm_transaction ( ) ;
133+
134+ let transaction_2 = fragment_builder
135+ . transaction ( & sender, receiver. address ( ) , transaction2_value. into ( ) )
136+ . unwrap ( ) ;
137+
138+ jcli. fragment_sender ( & jormungandr)
139+ . send ( & transaction_2. encode ( ) )
140+ . assert_in_block_with_wait ( & wait) ;
141+
142+ fragments. push ( & transaction_2) ;
143+
144+ let transaction_3 = fragment_builder
145+ . transaction ( & receiver, sender. address ( ) , transaction3_value. into ( ) )
146+ . unwrap ( ) ;
147+
148+ jcli. fragment_sender ( & jormungandr)
149+ . send ( & transaction_3. encode ( ) )
150+ . assert_in_block_with_wait ( & wait) ;
151+
152+ fragments. push ( & transaction_3) ;
153+
154+ let mut fragments_log = jcli. rest ( ) . v0 ( ) . message ( ) . logs ( jormungandr. rest_uri ( ) ) ;
155+
156+ fragments_log. sort ( ) ;
157+ fragments. sort_by_key ( |a| a. hash ( ) ) ;
158+
159+ // make and hashmap of tuples of fragment and fragment status
160+ let mut fragments_statuses: HashMap < _ , _ > = fragments
161+ . iter ( )
162+ . zip ( fragments_log. iter ( ) )
163+ . map ( |( & a, b) | ( a. hash ( ) . to_string ( ) , ( a, b. status ( ) ) ) )
164+ . collect ( ) ;
165+
166+ let block0 = jormungandr. block0_configuration ( ) . to_block ( ) ;
167+ let block0fragment: & Fragment = block0. fragments ( ) . last ( ) . unwrap ( ) ;
168+ let block0_fragment_status = FragmentStatus :: InABlock {
169+ date : block0. header ( ) . block_date ( ) . into ( ) ,
170+ block : block0. header ( ) . block_content_hash ( ) . into ( ) ,
171+ } ;
172+ fragments_statuses. insert (
173+ block0fragment. hash ( ) . to_string ( ) ,
174+ ( block0fragment, & block0_fragment_status) ,
175+ ) ;
176+
177+ let explorer_process = jormungandr. explorer ( ExplorerParams :: default ( ) ) ;
178+ let explorer = explorer_process. client ( ) ;
179+
180+ assert ! ( explorer
181+ . transactions_address( sender. address( ) . to_string( ) )
182+ . is_ok( ) ) ;
183+
184+ let explorer_address = explorer
185+ . transactions_address ( sender. address ( ) . to_string ( ) )
186+ . unwrap ( ) ;
187+
188+ assert ! (
189+ explorer_address. errors. is_none( ) ,
190+ "{:?}" ,
191+ explorer_address. errors. unwrap( )
192+ ) ;
193+
194+ let explorer_transactions_by_address =
195+ explorer_address. data . unwrap ( ) . tip . transactions_by_address ;
196+
197+ ExplorerVerifier :: assert_transactions_address (
198+ fragments_statuses,
199+ explorer_transactions_by_address,
39200 ) ;
40201}
0 commit comments