@@ -37,6 +37,11 @@ fn proof_cardano_transaction(
37
37
}
38
38
39
39
mod handlers {
40
+ use mithril_common:: {
41
+ entities:: { CardanoTransactionsSnapshot , SignedEntity } ,
42
+ messages:: CardanoTransactionsProofsMessage ,
43
+ StdResult ,
44
+ } ;
40
45
use reqwest:: StatusCode ;
41
46
use slog_scope:: { debug, warn} ;
42
47
use std:: { convert:: Infallible , sync:: Arc } ;
@@ -72,23 +77,9 @@ mod handlers {
72
77
"proof_cardano_transaction::error"
73
78
) {
74
79
Some ( signed_entity) => {
75
- let transactions_set_proofs = unwrap_to_internal_server_error ! (
76
- prover_service
77
- . compute_transactions_proofs(
78
- & signed_entity. artifact. beacon,
79
- transaction_hashes. as_slice( ) ,
80
- )
81
- . await ,
82
- "proof_cardano_transaction::error"
83
- ) ;
84
-
85
80
let message = unwrap_to_internal_server_error ! (
86
- ToCardanoTransactionsProofsMessageAdapter :: try_adapt(
87
- & signed_entity. certificate_id,
88
- transactions_set_proofs,
89
- transaction_hashes,
90
- ) ,
91
- "proof_cardano_transaction::error"
81
+ build_response_message( prover_service, signed_entity, transaction_hashes) . await ,
82
+ "proof_cardano_transaction"
92
83
) ;
93
84
Ok ( reply:: json ( & message, StatusCode :: OK ) )
94
85
}
@@ -98,14 +89,35 @@ mod handlers {
98
89
}
99
90
}
100
91
}
92
+
93
+ pub async fn build_response_message (
94
+ prover_service : Arc < dyn ProverService > ,
95
+ signed_entity : SignedEntity < CardanoTransactionsSnapshot > ,
96
+ transaction_hashes : Vec < String > ,
97
+ ) -> StdResult < CardanoTransactionsProofsMessage > {
98
+ let transactions_set_proofs = prover_service
99
+ . compute_transactions_proofs (
100
+ & signed_entity. artifact . beacon ,
101
+ transaction_hashes. as_slice ( ) ,
102
+ )
103
+ . await ?;
104
+ let message = ToCardanoTransactionsProofsMessageAdapter :: try_adapt (
105
+ & signed_entity. certificate_id ,
106
+ transactions_set_proofs,
107
+ transaction_hashes,
108
+ signed_entity. artifact . beacon . immutable_file_number ,
109
+ ) ?;
110
+
111
+ Ok ( message)
112
+ }
101
113
}
102
114
103
115
#[ cfg( test) ]
104
116
mod tests {
105
117
use super :: * ;
106
118
use std:: vec;
107
119
108
- use mithril_common:: test_utils:: apispec:: APISpec ;
120
+ use mithril_common:: { entities :: Beacon , test_utils:: apispec:: APISpec } ;
109
121
110
122
use anyhow:: anyhow;
111
123
use mithril_common:: entities:: {
@@ -136,6 +148,42 @@ mod tests {
136
148
. and ( routes ( dependency_manager) . with ( cors) )
137
149
}
138
150
151
+ #[ tokio:: test]
152
+ async fn build_response_message_return_immutable_file_number_from_artifact_beacon ( ) {
153
+ // Arrange
154
+ let mut mock_prover_service = MockProverService :: new ( ) ;
155
+ mock_prover_service
156
+ . expect_compute_transactions_proofs ( )
157
+ . returning ( |_, _| Ok ( vec ! [ CardanoTransactionsSetProof :: dummy( ) ] ) ) ;
158
+
159
+ let cardano_transactions_snapshot = {
160
+ let merkle_root = String :: new ( ) ;
161
+ let beacon = Beacon {
162
+ immutable_file_number : 2309 ,
163
+ ..Beacon :: default ( )
164
+ } ;
165
+ CardanoTransactionsSnapshot :: new ( merkle_root, beacon)
166
+ } ;
167
+
168
+ let signed_entity = SignedEntity :: < CardanoTransactionsSnapshot > {
169
+ artifact : cardano_transactions_snapshot,
170
+ ..SignedEntity :: < CardanoTransactionsSnapshot > :: dummy ( )
171
+ } ;
172
+
173
+ // Action
174
+ let transaction_hashes = vec ! [ ] ;
175
+ let message = handlers:: build_response_message (
176
+ Arc :: new ( mock_prover_service) ,
177
+ signed_entity,
178
+ transaction_hashes,
179
+ )
180
+ . await
181
+ . unwrap ( ) ;
182
+
183
+ // Assert
184
+ assert_eq ! ( message. latest_immutable_file_number, 2309 )
185
+ }
186
+
139
187
#[ tokio:: test]
140
188
async fn proof_cardano_transaction_ok ( ) {
141
189
let config = Configuration :: new_sample ( ) ;
0 commit comments