@@ -40,11 +40,26 @@ The state system consists of several key components:
4040
41411. **State Transition**
4242 ```rust
43+ use frost_protocol::state::{BlockId, StateTransition};
44+
4345 pub struct StateTransition {
4446 source: BlockId,
4547 target: BlockId,
4648 state_data: Vec<u8>,
4749 }
50+
51+ // Example usage:
52+ # fn main() {
53+ let source = BlockId::Number(1000);
54+ let target = BlockId::Number(1001);
55+ let data = vec![1, 2, 3];
56+ let transition = StateTransition::new(
57+ frost_protocol::state::ChainId::new("ethereum"),
58+ source,
59+ target,
60+ data
61+ );
62+ # }
4863 ```
4964 - State changes
5065 - Transition validation
@@ -53,10 +68,32 @@ The state system consists of several key components:
5368
54692. **State Proof**
5570 ```rust
71+ use frost_protocol::state::{StateTransition, StateProof, proof::ProofData};
72+ use std::time::SystemTime;
73+
5674 pub struct StateProof {
5775 transition: StateTransition,
5876 proof: ProofData,
5977 }
78+
79+ // Example usage:
80+ # fn main() {
81+ let transition = StateTransition::new(
82+ frost_protocol::state::ChainId::new("ethereum"),
83+ BlockId::Number(1000),
84+ BlockId::Number(1001),
85+ vec![1, 2, 3]
86+ );
87+ let proof_data = ProofData {
88+ proof_type: frost_protocol::state::proof::ProofType::Basic,
89+ data: vec![1, 2, 3],
90+ metadata: None,
91+ generated_at: SystemTime::now(),
92+ expires_at: None,
93+ version: 1,
94+ };
95+ let proof = StateProof::new(transition, proof_data);
96+ # }
6097 ```
6198 - Proof generation
6299 - Verification
@@ -65,11 +102,23 @@ The state system consists of several key components:
65102
661033. **State Types**
67104 ```rust
105+ use frost_protocol::state::BlockId;
106+
68107 pub enum BlockId {
69108 Hash([u8; 32]),
70109 Number(u64),
71110 Composite { number: u64, hash: [u8; 32] },
72111 }
112+
113+ // Example usage:
114+ # fn main() {
115+ let block_by_number = BlockId::Number(1000);
116+ let block_by_hash = BlockId::Hash([0; 32]);
117+ let block_composite = BlockId::Composite {
118+ number: 1000,
119+ hash: [0; 32],
120+ };
121+ # }
73122 ```
74123 - Block identification
75124 - Chain references
@@ -207,26 +256,38 @@ mod tests {
207256
208257 #[ test]
209258 fn test_state_transition_validation ( ) {
259+ let chain_id = ChainId :: new ( "test-chain" ) ;
210260 let source = BlockId :: Composite {
211261 number : 1 ,
212- hash : [ 0 ; 32 ] ,
262+ hash : [ 0 ; 32 ] , // Source hash all zeros
213263 } ;
214264 let target = BlockId :: Composite {
215- number : 1 ,
216- hash : [ 0 ; 32 ] ,
265+ number : 2 ,
266+ hash : [ 1 ; 32 ] , // Target hash all ones
217267 } ;
218268
219269 let transition = StateTransition :: new (
270+ chain_id. clone ( ) ,
220271 source,
221272 target,
222273 vec ! [ 1 , 2 , 3 ] ,
223274 ) ;
224275 assert ! ( transition. validate( ) ) ;
225276
277+ // Create invalid transition with same hash (will fail validation)
278+ let invalid_source = BlockId :: Composite {
279+ number : 1 ,
280+ hash : [ 0 ; 32 ] ,
281+ } ;
282+ let invalid_target = BlockId :: Composite {
283+ number : 2 , // Valid height difference
284+ hash : [ 0 ; 32 ] , // Same hash as source - should fail validation
285+ } ;
226286 let invalid_transition = StateTransition :: new (
227- BlockId :: Number ( 0 ) ,
228- BlockId :: Number ( 0 ) ,
229- vec ! [ ] ,
287+ chain_id,
288+ invalid_source,
289+ invalid_target,
290+ vec ! [ 1 ] , // Valid data
230291 ) ;
231292 assert ! ( !invalid_transition. validate( ) ) ;
232293 }
0 commit comments