1- use crate :: ethproofs_demo:: validate_proof ;
1+ use crate :: ethproofs_demo:: { EthproofsValidator , ProofValidator } ;
22use crate :: proof_verification:: { ProofVerificationResult , ProofVerifier , VerificationError } ;
3+ use std:: sync:: Arc ;
34use std:: time:: Duration ;
45use tracing:: debug;
56use types:: { ExecutionProof , ExecutionProofId } ;
@@ -12,6 +13,7 @@ use types::{ExecutionProof, ExecutionProofId};
1213pub struct DummyVerifier {
1314 proof_id : ExecutionProofId ,
1415 verification_delay : Duration ,
16+ validator : Arc < dyn ProofValidator > ,
1517}
1618
1719impl DummyVerifier {
@@ -20,6 +22,7 @@ impl DummyVerifier {
2022 Self {
2123 proof_id,
2224 verification_delay : Duration :: from_millis ( 0 ) ,
25+ validator : Arc :: new ( EthproofsValidator ) ,
2326 }
2427 }
2528
@@ -28,6 +31,20 @@ impl DummyVerifier {
2831 Self {
2932 proof_id,
3033 verification_delay : delay,
34+ validator : Arc :: new ( EthproofsValidator ) ,
35+ }
36+ }
37+
38+ /// Create a new dummy verifier with a custom validator (for testing)
39+ #[ cfg( test) ]
40+ fn with_validator (
41+ proof_id : ExecutionProofId ,
42+ validator : Arc < dyn ProofValidator > ,
43+ ) -> Self {
44+ Self {
45+ proof_id,
46+ verification_delay : Duration :: from_millis ( 0 ) ,
47+ validator,
3148 }
3249 }
3350}
@@ -50,8 +67,8 @@ impl ProofVerifier for DummyVerifier {
5067 "[Ethproofs] Verifying proof"
5168 ) ;
5269
53- // Perform cryptographic verification using Ethproofs verifiers
54- Ok ( validate_proof ( proof) )
70+ // Perform cryptographic verification using the injected validator
71+ Ok ( self . validator . validate ( proof) )
5572 }
5673
5774 fn proof_id ( & self ) -> ExecutionProofId {
@@ -62,13 +79,20 @@ impl ProofVerifier for DummyVerifier {
6279#[ cfg( test) ]
6380mod tests {
6481 use super :: * ;
65- use types:: { ExecutionBlockHash , FixedBytesExtended } ;
82+ use mockall:: mock;
83+ use types:: { ExecutionBlockHash , FixedBytesExtended , Hash256 , Slot } ;
84+
85+ mock ! {
86+ TestValidator { }
87+ impl ProofValidator for TestValidator {
88+ fn validate( & self , proof: & ExecutionProof ) -> bool ;
89+ }
90+ }
6691
6792 fn create_test_proof (
6893 subnet_id : ExecutionProofId ,
6994 block_hash : types:: ExecutionBlockHash ,
7095 ) -> ExecutionProof {
71- use types:: { Hash256 , Slot } ;
7296 ExecutionProof :: new (
7397 subnet_id,
7498 Slot :: new ( 100 ) ,
@@ -82,10 +106,17 @@ mod tests {
82106 #[ tokio:: test]
83107 async fn test_dummy_verifier_success ( ) {
84108 let subnet = ExecutionProofId :: new ( 0 ) . unwrap ( ) ;
85- let verifier = DummyVerifier :: new ( subnet) ;
86109 let block_hash = ExecutionBlockHash :: zero ( ) ;
87110 let proof = create_test_proof ( subnet, block_hash) ;
88111
112+ let mut mock_validator = MockTestValidator :: new ( ) ;
113+ mock_validator
114+ . expect_validate ( )
115+ . withf ( move |p| p. proof_id == subnet)
116+ . returning ( |_| true ) ;
117+
118+ let verifier = DummyVerifier :: with_validator ( subnet, Arc :: new ( mock_validator) ) ;
119+
89120 let result = verifier. verify ( & proof) ;
90121 assert ! ( result. is_ok( ) ) ;
91122 assert ! ( result. unwrap( ) ) ;
@@ -95,10 +126,12 @@ mod tests {
95126 async fn test_dummy_verifier_wrong_subnet ( ) {
96127 let subnet_0 = ExecutionProofId :: new ( 0 ) . unwrap ( ) ;
97128 let subnet_1 = ExecutionProofId :: new ( 1 ) . unwrap ( ) ;
98- let verifier = DummyVerifier :: new ( subnet_0) ;
99129 let block_hash = ExecutionBlockHash :: zero ( ) ;
100130 let proof = create_test_proof ( subnet_1, block_hash) ;
101131
132+ let mock_validator = MockTestValidator :: new ( ) ;
133+ let verifier = DummyVerifier :: with_validator ( subnet_0, Arc :: new ( mock_validator) ) ;
134+
102135 let result = verifier. verify ( & proof) ;
103136 assert ! ( result. is_err( ) ) ;
104137 assert ! ( matches!(
0 commit comments