@@ -214,129 +214,78 @@ impl Tx {
214214 }
215215}
216216
217- // #[cfg(test)]
218- // mod tests {
219- // use proptest::prelude::{any, any_with, Arbitrary, BoxedStrategy, Strategy};
220- // use test_strategy::proptest;
221-
222- // use super::*;
223- // use crate::crypto::ed25519::PrivateKey;
224-
225- // impl Arbitrary for Tx {
226- // type Parameters = ();
227- // type Strategy = BoxedStrategy<Self>;
228-
229- // fn arbitrary_with((): Self::Parameters) -> Self::Strategy {
230- // any::<(
231- // [u8; 32],
232- // u8,
233- // VotePayload,
234- // PrivateKey,
235- // [u8; Signature::BYTES_SIZE],
236- // )>()
237- // .prop_map(
238- // |(vote_plan_id, proposal_index, vote, sk, signature_bytes)| {
239- // Tx {
240- // vote_plan_id,
241- // proposal_index,
242- // vote,
243- // public_key: sk.public_key(),
244- // signature: Signature::from_bytes(&signature_bytes),
245- // }
246- // },
247- // )
248- // .boxed()
249- // }
250- // }
251-
252- // impl Arbitrary for VotePayload {
253- // type Parameters = ();
254- // type Strategy = BoxedStrategy<Self>;
255-
256- // fn arbitrary_with((): Self::Parameters) -> Self::Strategy {
257- // any::<bool>()
258- // .prop_flat_map(|b| {
259- // if b {
260- // any::<u8>().prop_map(VotePayload::Public).boxed()
261- // } else {
262- // any::<(u8, u8)>()
263- // .prop_flat_map(|(s1, s2)| {
264- // any_with::<(EncryptedVote, VoterProof)>((s1.into(),
265- // s2.into())) .prop_map(|(v, p)|
266- // VotePayload::Private(v, p)) })
267- // .boxed()
268- // }
269- // })
270- // .boxed()
271- // }
272- // }
273-
274- // #[proptest]
275- // fn tx_to_bytes_from_bytes_test(t1: Tx) {
276- // let bytes = t1.to_bytes();
277-
278- // let mut reader = bytes.as_slice();
279-
280- // let size = read_be_u32(&mut reader).unwrap();
281- // assert_eq!(size as usize, bytes.len() - 4);
282-
283- // let padding_tag = read_be_u8(&mut reader).unwrap();
284- // assert_eq!(padding_tag, PADDING_TAG);
285-
286- // let fragment_tag = read_be_u8(&mut reader).unwrap();
287- // assert_eq!(fragment_tag, FRAGMENT_TAG);
288-
289- // let vote_plan_id = read_array(&mut reader).unwrap();
290- // assert_eq!(vote_plan_id, t1.vote_plan_id);
291-
292- // let proposal_index = read_be_u8(&mut reader).unwrap();
293- // assert_eq!(proposal_index, t1.proposal_index);
294-
295- // let vote_tag = read_be_u8(&mut reader).unwrap();
296- // assert!(vote_tag == PUBLIC_VOTE_TAG || vote_tag == PRIVATE_VOTE_TAG);
297- // match vote_tag {
298- // PUBLIC_VOTE_TAG => {
299- // let vote = read_be_u8(&mut reader).unwrap();
300- // assert_eq!(VotePayload::Public(vote), t1.vote);
301- // },
302- // PRIVATE_VOTE_TAG => {
303- // let size = read_be_u8(&mut reader).unwrap();
304- // let vote = EncryptedVote::from_bytes(&mut reader,
305- // size.into()).unwrap(); let size = read_be_u8(&mut reader).unwrap();
306- // let proof = VoterProof::from_bytes(&mut reader, size.into()).unwrap();
307- // assert_eq!(VotePayload::Private(vote, proof), t1.vote);
308- // },
309- // _ => {},
310- // }
311-
312- // let block_date = read_be_u64(&mut reader).unwrap();
313- // assert_eq!(block_date, 0);
314-
315- // let inputs_amount = read_be_u8(&mut reader).unwrap();
316- // assert_eq!(inputs_amount, NUMBER_OF_INPUTS);
317-
318- // let outputs_amount = read_be_u8(&mut reader).unwrap();
319- // assert_eq!(outputs_amount, NUMBER_OF_OUTPUTS);
320-
321- // let input_tag = read_be_u8(&mut reader).unwrap();
322- // assert_eq!(input_tag, INPUT_TAG);
323-
324- // let value = read_be_u64(&mut reader).unwrap();
325- // assert_eq!(value, 0);
326-
327- // let public_key = read_array(&mut reader).unwrap();
328- // assert_eq!(PublicKey::from_bytes(&public_key).unwrap(), t1.public_key);
329-
330- // let witness_tag = read_be_u8(&mut reader).unwrap();
331- // assert_eq!(witness_tag, WITNESS_TAG);
332-
333- // let nonce = read_be_u32(&mut reader).unwrap();
334- // assert_eq!(nonce, 0);
335-
336- // let signature = read_array(&mut reader).unwrap();
337- // assert_eq!(Signature::from_bytes(&signature), t1.signature);
338-
339- // let t2 = Tx::from_bytes(&mut bytes.as_slice()).unwrap();
340- // assert_eq!(t1, t2);
341- // }
342- // }
217+ #[ cfg( test) ]
218+ mod tests {
219+ use test_strategy:: proptest;
220+
221+ use super :: * ;
222+
223+ #[ proptest]
224+ fn tx_to_bytes_from_bytes_test ( t1 : Tx ) {
225+ let bytes = t1. to_bytes ( ) ;
226+
227+ let mut reader = bytes. as_slice ( ) ;
228+
229+ let size = read_be_u32 ( & mut reader) . unwrap ( ) ;
230+ assert_eq ! ( size as usize , bytes. len( ) - 4 ) ;
231+
232+ let padding_tag = read_be_u8 ( & mut reader) . unwrap ( ) ;
233+ assert_eq ! ( padding_tag, PADDING_TAG ) ;
234+
235+ let fragment_tag = read_be_u8 ( & mut reader) . unwrap ( ) ;
236+ assert_eq ! ( fragment_tag, FRAGMENT_TAG ) ;
237+
238+ let vote_plan_id = read_array ( & mut reader) . unwrap ( ) ;
239+ assert_eq ! ( vote_plan_id, t1. vote_plan_id) ;
240+
241+ let proposal_index = read_be_u8 ( & mut reader) . unwrap ( ) ;
242+ assert_eq ! ( proposal_index, t1. proposal_index) ;
243+
244+ let vote_tag = read_be_u8 ( & mut reader) . unwrap ( ) ;
245+ assert ! ( vote_tag == PUBLIC_VOTE_TAG || vote_tag == PRIVATE_VOTE_TAG ) ;
246+ match vote_tag {
247+ PUBLIC_VOTE_TAG => {
248+ let vote = read_be_u8 ( & mut reader) . unwrap ( ) ;
249+ assert_eq ! ( VotePayload :: Public ( vote) , t1. vote) ;
250+ } ,
251+ PRIVATE_VOTE_TAG => {
252+ let size = read_be_u8 ( & mut reader) . unwrap ( ) ;
253+ let vote = EncryptedVote :: from_bytes ( & mut reader, size. into ( ) ) . unwrap ( ) ;
254+ let size = read_be_u8 ( & mut reader) . unwrap ( ) ;
255+ let proof = VoterProof :: from_bytes ( & mut reader, size. into ( ) ) . unwrap ( ) ;
256+ assert_eq ! ( VotePayload :: Private ( vote, proof) , t1. vote) ;
257+ } ,
258+ _ => { } ,
259+ }
260+
261+ let block_date = read_be_u64 ( & mut reader) . unwrap ( ) ;
262+ assert_eq ! ( block_date, 0 ) ;
263+
264+ let inputs_amount = read_be_u8 ( & mut reader) . unwrap ( ) ;
265+ assert_eq ! ( inputs_amount, NUMBER_OF_INPUTS ) ;
266+
267+ let outputs_amount = read_be_u8 ( & mut reader) . unwrap ( ) ;
268+ assert_eq ! ( outputs_amount, NUMBER_OF_OUTPUTS ) ;
269+
270+ let input_tag = read_be_u8 ( & mut reader) . unwrap ( ) ;
271+ assert_eq ! ( input_tag, INPUT_TAG ) ;
272+
273+ let value = read_be_u64 ( & mut reader) . unwrap ( ) ;
274+ assert_eq ! ( value, 0 ) ;
275+
276+ let public_key = read_array ( & mut reader) . unwrap ( ) ;
277+ assert_eq ! ( PublicKey :: from_bytes( & public_key) . unwrap( ) , t1. public_key) ;
278+
279+ let witness_tag = read_be_u8 ( & mut reader) . unwrap ( ) ;
280+ assert_eq ! ( witness_tag, WITNESS_TAG ) ;
281+
282+ let nonce = read_be_u32 ( & mut reader) . unwrap ( ) ;
283+ assert_eq ! ( nonce, 0 ) ;
284+
285+ let signature = read_array ( & mut reader) . unwrap ( ) ;
286+ assert_eq ! ( Signature :: from_bytes( & signature) , t1. signature) ;
287+
288+ let t2 = Tx :: from_bytes ( & mut bytes. as_slice ( ) ) . unwrap ( ) ;
289+ assert_eq ! ( t1, t2) ;
290+ }
291+ }
0 commit comments