Skip to content

Commit

Permalink
fix(beta-toolchain): Warnings (#8404)
Browse files Browse the repository at this point in the history
* fix beta imports and other warnings

* clippy lints beta

* move attributes to after docs

Co-authored-by: Marek <mail@marek.onl>

* move some code to test module

* implement display instead of direct tostring for LongPollId

Co-authored-by: Arya <aryasolhi@gmail.com>

* fix typo

---------

Co-authored-by: Marek <mail@marek.onl>
Co-authored-by: Arya <aryasolhi@gmail.com>
  • Loading branch information
3 people committed Apr 18, 2024
1 parent 2995ea0 commit 887d4a2
Show file tree
Hide file tree
Showing 92 changed files with 165 additions and 256 deletions.
13 changes: 2 additions & 11 deletions zebra-chain/src/block/arbitrary.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
//! Randomised property testing for [`Block`]s.

use std::{collections::HashMap, sync::Arc};

use proptest::{
arbitrary::{any, Arbitrary},
prelude::*,
};
use proptest::prelude::*;

use crate::{
amount::NonNegative,
block,
fmt::{HexDebug, SummaryDebug},
history_tree::HistoryTree,
parameters::{
Network,
NetworkUpgrade::{self, *},
GENESIS_PREVIOUS_BLOCK_HASH,
},
parameters::{NetworkUpgrade::*, GENESIS_PREVIOUS_BLOCK_HASH},
serialization,
transaction::arbitrary::MAX_ARBITRARY_ITEMS,
transparent::{
Expand Down
6 changes: 2 additions & 4 deletions zebra-chain/src/block/tests/prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,19 @@

use std::{env, io::ErrorKind};

use proptest::{arbitrary::any, prelude::*, test_runner::Config};
use proptest::{prelude::*, test_runner::Config};

use hex::{FromHex, ToHex};

use zebra_test::prelude::*;

use crate::{
parameters::{Network, GENESIS_PREVIOUS_BLOCK_HASH},
parameters::GENESIS_PREVIOUS_BLOCK_HASH,
serialization::{SerializationError, ZcashDeserializeInto, ZcashSerialize},
LedgerState,
};

use super::super::{
arbitrary::{allow_all_transparent_coinbase_spends, PREVOUTS_CHAIN_HEIGHT},
serialize::MAX_BLOCK_BYTES,
*,
};

Expand Down
2 changes: 1 addition & 1 deletion zebra-chain/src/orchard/action.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{convert::TryFrom, io};
use std::io;

use halo2::pasta::pallas;
use reddsa::orchard::SpendAuth;
Expand Down
2 changes: 1 addition & 1 deletion zebra-chain/src/orchard/arbitrary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use group::{
use halo2::pasta::pallas;
use reddsa::{orchard::SpendAuth, Signature, SigningKey, VerificationKey, VerificationKeyBytes};

use proptest::{arbitrary::any, array, collection::vec, prelude::*};
use proptest::{array, collection::vec, prelude::*};

use super::{
keys::*, note, tree, Action, AuthorizedAction, Flags, NoteCommitment, ValueCommitment,
Expand Down
2 changes: 1 addition & 1 deletion zebra-chain/src/orchard/note/arbitrary.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use proptest::{arbitrary::any, collection::vec, prelude::*};
use proptest::{collection::vec, prelude::*};

use super::*;

Expand Down
2 changes: 1 addition & 1 deletion zebra-chain/src/orchard/shielded_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::{

use byteorder::{ReadBytesExt, WriteBytesExt};
use halo2::pasta::pallas;
use reddsa::{self, orchard::Binding, orchard::SpendAuth, Signature};
use reddsa::{orchard::Binding, orchard::SpendAuth, Signature};

use crate::{
amount::{Amount, NegativeAllowed},
Expand Down
2 changes: 1 addition & 1 deletion zebra-chain/src/orchard/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use std::{
};

use bitvec::prelude::*;
use bridgetree::{self, NonEmptyFrontier};
use bridgetree::NonEmptyFrontier;
use halo2::pasta::{group::ff::PrimeField, pallas};
use hex::ToHex;
use incrementalmerkletree::Hashable;
Expand Down
2 changes: 1 addition & 1 deletion zebra-chain/src/primitives/proofs/bctv14.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl ZcashDeserialize for Bctv14Proof {
}

#[cfg(any(test, feature = "proptest-impl"))]
use proptest::{arbitrary::Arbitrary, collection::vec, prelude::*};
use proptest::{collection::vec, prelude::*};

#[cfg(any(test, feature = "proptest-impl"))]
impl Arbitrary for Bctv14Proof {
Expand Down
2 changes: 1 addition & 1 deletion zebra-chain/src/primitives/proofs/groth16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl ZcashDeserialize for Groth16Proof {
}

#[cfg(any(test, feature = "proptest-impl"))]
use proptest::{arbitrary::Arbitrary, collection::vec, prelude::*};
use proptest::{collection::vec, prelude::*};

#[cfg(any(test, feature = "proptest-impl"))]
impl Arbitrary for Groth16Proof {
Expand Down
2 changes: 1 addition & 1 deletion zebra-chain/src/primitives/proofs/halo2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl ZcashDeserialize for Halo2Proof {
}
}
#[cfg(any(test, feature = "proptest-impl"))]
use proptest::{arbitrary::Arbitrary, prelude::*};
use proptest::prelude::*;

#[cfg(any(test, feature = "proptest-impl"))]
impl Arbitrary for Halo2Proof {
Expand Down
2 changes: 1 addition & 1 deletion zebra-chain/src/primitives/zcash_history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

mod tests;

use std::{collections::BTreeMap, convert::TryInto, io, sync::Arc};
use std::{collections::BTreeMap, io, sync::Arc};

use serde_big_array::BigArray;
pub use zcash_history::{V1, V2};
Expand Down
2 changes: 1 addition & 1 deletion zebra-chain/src/sapling/arbitrary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use jubjub::{AffinePoint, ExtendedPoint};
use rand::SeedableRng;
use rand_chacha::ChaChaRng;

use proptest::{arbitrary::any, collection::vec, prelude::*};
use proptest::{collection::vec, prelude::*};

use crate::primitives::Groth16Proof;

Expand Down
5 changes: 1 addition & 4 deletions zebra-chain/src/sapling/commitment.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
//! Note and value commitments.

use std::{
convert::{TryFrom, TryInto},
fmt, io,
};
use std::{fmt, io};

use bitvec::prelude::*;
use jubjub::ExtendedPoint;
Expand Down
2 changes: 1 addition & 1 deletion zebra-chain/src/sapling/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use rand_core::{CryptoRng, RngCore};

use crate::{
error::{AddressError, RandError},
primitives::redjubjub::{self, SpendAuth},
primitives::redjubjub::SpendAuth,
serialization::{
serde_helpers, ReadZcashExt, SerializationError, ZcashDeserialize, ZcashSerialize,
},
Expand Down
2 changes: 1 addition & 1 deletion zebra-chain/src/sapling/note/arbitrary.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use proptest::{arbitrary::any, collection::vec, prelude::*};
use proptest::{collection::vec, prelude::*};

use super::*;

Expand Down
7 changes: 2 additions & 5 deletions zebra-chain/src/sapling/spend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@
//! Zebra uses a generic spend type for `V4` and `V5` transactions.
//! The anchor change is handled using the `AnchorVariant` type trait.

use std::{convert::TryInto, fmt, io};
use std::{fmt, io};

use crate::{
block::MAX_BLOCK_BYTES,
primitives::{
redjubjub::{self, SpendAuth},
Groth16Proof,
},
primitives::{redjubjub::SpendAuth, Groth16Proof},
serialization::{
ReadZcashExt, SerializationError, TrustedPreallocate, WriteZcashExt, ZcashDeserialize,
ZcashDeserializeInto, ZcashSerialize,
Expand Down
1 change: 0 additions & 1 deletion zebra-chain/src/sapling/tests/prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use crate::{
serialization::{ZcashDeserializeInto, ZcashSerialize},
transaction::{LockTime, Transaction},
};
use std::convert::TryInto;

proptest! {
/// Serialize and deserialize `Spend<PerSpendAnchor>`
Expand Down
2 changes: 1 addition & 1 deletion zebra-chain/src/sapling/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use std::{
};

use bitvec::prelude::*;
use bridgetree::{self, NonEmptyFrontier};
use bridgetree::NonEmptyFrontier;
use hex::ToHex;
use incrementalmerkletree::{frontier::Frontier, Hashable};

Expand Down
4 changes: 1 addition & 3 deletions zebra-chain/src/serialization/arbitrary.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
//! Arbitrary data generation for serialization proptests

use std::convert::TryInto;

use chrono::{DateTime, TimeZone, Utc};
use proptest::{arbitrary::any, prelude::*};
use proptest::prelude::*;

use super::{
CompactSizeMessage, DateTime32, TrustedPreallocate, ZcashSerialize, MAX_PROTOCOL_MESSAGE_LEN,
Expand Down
2 changes: 0 additions & 2 deletions zebra-chain/src/serialization/compact_size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
//! - [`CompactSizeMessage`] for sizes that must be less than the network message limit, and
//! - [`CompactSize64`] for flags, arbitrary counts, and sizes that span multiple blocks.

use std::convert::{TryFrom, TryInto};

use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};

use crate::serialization::{
Expand Down
5 changes: 1 addition & 4 deletions zebra-chain/src/serialization/constraint.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
//! Serialization constraint helpers.

use std::{
convert::{TryFrom, TryInto},
ops::Deref,
};
use std::ops::Deref;

use crate::serialization::SerializationError;

Expand Down
2 changes: 1 addition & 1 deletion zebra-chain/src/serialization/tests/preallocate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use proptest::{collection::size_range, prelude::*};

use std::{convert::TryInto, matches};
use std::matches;

use crate::serialization::{
arbitrary::max_allocation_is_big_enough, zcash_deserialize::MAX_U8_ALLOCATION,
Expand Down
2 changes: 1 addition & 1 deletion zebra-chain/src/sprout/arbitrary.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use proptest::{arbitrary::any, array, prelude::*};
use proptest::{array, prelude::*};

use crate::{
amount::{Amount, NonNegative},
Expand Down
2 changes: 1 addition & 1 deletion zebra-chain/src/sprout/note/arbitrary.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use proptest::{arbitrary::any, collection::vec, prelude::*};
use proptest::{collection::vec, prelude::*};

impl Arbitrary for super::EncryptedNote {
type Parameters = ();
Expand Down
2 changes: 2 additions & 0 deletions zebra-chain/src/tests/vectors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ impl Network {
}
}

/// Returns blocks indexed by height in a [`BTreeMap`].
///
/// Returns Mainnet blocks if `self` is set to Mainnet, and Testnet blocks otherwise.
pub fn block_map(&self) -> BTreeMap<u32, &'static [u8]> {
if self.is_mainnet() {
zebra_test::vectors::MAINNET_BLOCKS.clone()
Expand Down
12 changes: 2 additions & 10 deletions zebra-chain/src/transaction/arbitrary.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
//! Arbitrary data generation for transaction proptests

use std::{
cmp::max,
collections::HashMap,
convert::{TryFrom, TryInto},
ops::Neg,
sync::Arc,
};
use std::{cmp::max, collections::HashMap, ops::Neg, sync::Arc};

use chrono::{TimeZone, Utc};
use proptest::{
arbitrary::any, array, collection::vec, option, prelude::*, test_runner::TestRunner,
};
use proptest::{array, collection::vec, option, prelude::*, test_runner::TestRunner};
use reddsa::{orchard::Binding, Signature};

use crate::{
Expand Down
6 changes: 1 addition & 5 deletions zebra-chain/src/transaction/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@
//!
//! [1]: crate::transaction::UnminedTx

use std::{
convert::{TryFrom, TryInto},
fmt,
sync::Arc,
};
use std::{fmt, sync::Arc};

#[cfg(any(test, feature = "proptest-impl"))]
use proptest_derive::Arbitrary;
Expand Down
2 changes: 1 addition & 1 deletion zebra-chain/src/transaction/memo.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{cmp, convert::TryFrom, fmt};
use std::{cmp, fmt};

/// A 512-byte (plaintext) memo associated with a note, as described in
/// [protocol specification §5.5][ps].
Expand Down
7 changes: 3 additions & 4 deletions zebra-chain/src/transaction/serialize.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
//! Contains impls of `ZcashSerialize`, `ZcashDeserialize` for all of the
//! transaction types, so that all of the serialization logic is in one place.

use std::{borrow::Borrow, convert::TryInto, io, sync::Arc};
use std::{borrow::Borrow, io, sync::Arc};

use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
use halo2::pasta::{group::ff::PrimeField, pallas};
use halo2::pasta::group::ff::PrimeField;
use hex::FromHex;
use reddsa::{orchard::Binding, orchard::SpendAuth, Signature};

use crate::{
amount,
block::MAX_BLOCK_BYTES,
parameters::{OVERWINTER_VERSION_GROUP_ID, SAPLING_VERSION_GROUP_ID, TX_V5_VERSION_GROUP_ID},
primitives::{Groth16Proof, Halo2Proof, ZkSnarkProof},
primitives::{Halo2Proof, ZkSnarkProof},
serialization::{
zcash_deserialize_external_count, zcash_serialize_empty_list,
zcash_serialize_external_count, AtLeastOne, ReadZcashExt, SerializationError,
TrustedPreallocate, ZcashDeserialize, ZcashDeserializeInto, ZcashSerialize,
},
sprout,
};

use super::*;
Expand Down
5 changes: 2 additions & 3 deletions zebra-chain/src/transaction/tests/vectors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ use color_eyre::eyre::Result;
use lazy_static::lazy_static;

use crate::{
amount::Amount,
block::{Block, Height, MAX_BLOCK_BYTES},
parameters::{Network, NetworkUpgrade},
parameters::Network,
serialization::{SerializationError, ZcashDeserialize, ZcashDeserializeInto, ZcashSerialize},
transaction::{hash::WtxId, sighash::SigHasher, txid::TxIdBuilder, Transaction},
transaction::{sighash::SigHasher, txid::TxIdBuilder},
transparent::Script,
};

Expand Down
2 changes: 1 addition & 1 deletion zebra-chain/src/transaction/txid.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Transaction ID computation. Contains code for generating the Transaction ID
//! from the transaction.
use std::{convert::TryInto, io};
use std::io;

use super::{Hash, Transaction};
use crate::serialization::{sha256d, ZcashSerialize};
Expand Down
Loading

0 comments on commit 887d4a2

Please sign in to comment.