Merge remote-tracking branch 'origin/main' into params-network-name

This commit is contained in:
Arya 2024-04-19 15:42:21 -04:00
commit c79e06f2b5
96 changed files with 174 additions and 259 deletions

View File

@ -151,7 +151,7 @@ jobs:
steps: steps:
- uses: actions/checkout@v4.1.2 - uses: actions/checkout@v4.1.2
- name: actionlint - name: actionlint
uses: reviewdog/action-actionlint@v1.43.0 uses: reviewdog/action-actionlint@v1.44.0
with: with:
level: warning level: warning
fail_on_error: false fail_on_error: false

View File

@ -281,7 +281,7 @@ jobs:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain=stable --profile=minimal curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain=stable --profile=minimal
- name: Install cargo-machete - name: Install cargo-machete
uses: baptiste0928/cargo-install@v3.0.1 uses: baptiste0928/cargo-install@v3.1.0
with: with:
crate: cargo-machete crate: cargo-machete

View File

@ -85,7 +85,7 @@ jobs:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain=stable --profile=minimal curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain=stable --profile=minimal
- name: Install cargo-release - name: Install cargo-release
uses: baptiste0928/cargo-install@v3.0.1 uses: baptiste0928/cargo-install@v3.1.0
with: with:
crate: cargo-release crate: cargo-release

View File

@ -1,22 +1,13 @@
//! Randomised property testing for [`Block`]s. //! Randomised property testing for [`Block`]s.
use std::{collections::HashMap, sync::Arc}; use proptest::prelude::*;
use proptest::{
arbitrary::{any, Arbitrary},
prelude::*,
};
use crate::{ use crate::{
amount::NonNegative, amount::NonNegative,
block, block,
fmt::{HexDebug, SummaryDebug}, fmt::{HexDebug, SummaryDebug},
history_tree::HistoryTree, history_tree::HistoryTree,
parameters::{ parameters::{NetworkUpgrade::*, GENESIS_PREVIOUS_BLOCK_HASH},
Network,
NetworkUpgrade::{self, *},
GENESIS_PREVIOUS_BLOCK_HASH,
},
serialization, serialization,
transaction::arbitrary::MAX_ARBITRARY_ITEMS, transaction::arbitrary::MAX_ARBITRARY_ITEMS,
transparent::{ transparent::{

View File

@ -2,21 +2,19 @@
use std::{env, io::ErrorKind}; use std::{env, io::ErrorKind};
use proptest::{arbitrary::any, prelude::*, test_runner::Config}; use proptest::{prelude::*, test_runner::Config};
use hex::{FromHex, ToHex}; use hex::{FromHex, ToHex};
use zebra_test::prelude::*; use zebra_test::prelude::*;
use crate::{ use crate::{
parameters::{Network, GENESIS_PREVIOUS_BLOCK_HASH}, parameters::GENESIS_PREVIOUS_BLOCK_HASH,
serialization::{SerializationError, ZcashDeserializeInto, ZcashSerialize}, serialization::{SerializationError, ZcashDeserializeInto, ZcashSerialize},
LedgerState,
}; };
use super::super::{ use super::super::{
arbitrary::{allow_all_transparent_coinbase_spends, PREVOUTS_CHAIN_HEIGHT}, arbitrary::{allow_all_transparent_coinbase_spends, PREVOUTS_CHAIN_HEIGHT},
serialize::MAX_BLOCK_BYTES,
*, *,
}; };

View File

@ -1,4 +1,4 @@
use std::{convert::TryFrom, io}; use std::io;
use halo2::pasta::pallas; use halo2::pasta::pallas;
use reddsa::orchard::SpendAuth; use reddsa::orchard::SpendAuth;

View File

@ -7,7 +7,7 @@ use group::{
use halo2::pasta::pallas; use halo2::pasta::pallas;
use reddsa::{orchard::SpendAuth, Signature, SigningKey, VerificationKey, VerificationKeyBytes}; use reddsa::{orchard::SpendAuth, Signature, SigningKey, VerificationKey, VerificationKeyBytes};
use proptest::{arbitrary::any, array, collection::vec, prelude::*}; use proptest::{array, collection::vec, prelude::*};
use super::{ use super::{
keys::*, note, tree, Action, AuthorizedAction, Flags, NoteCommitment, ValueCommitment, keys::*, note, tree, Action, AuthorizedAction, Flags, NoteCommitment, ValueCommitment,

View File

@ -1,4 +1,4 @@
use proptest::{arbitrary::any, collection::vec, prelude::*}; use proptest::{collection::vec, prelude::*};
use super::*; use super::*;

View File

@ -8,7 +8,7 @@ use std::{
use byteorder::{ReadBytesExt, WriteBytesExt}; use byteorder::{ReadBytesExt, WriteBytesExt};
use halo2::pasta::pallas; use halo2::pasta::pallas;
use reddsa::{self, orchard::Binding, orchard::SpendAuth, Signature}; use reddsa::{orchard::Binding, orchard::SpendAuth, Signature};
use crate::{ use crate::{
amount::{Amount, NegativeAllowed}, amount::{Amount, NegativeAllowed},

View File

@ -19,7 +19,7 @@ use std::{
}; };
use bitvec::prelude::*; use bitvec::prelude::*;
use bridgetree::{self, NonEmptyFrontier}; use bridgetree::NonEmptyFrontier;
use halo2::pasta::{group::ff::PrimeField, pallas}; use halo2::pasta::{group::ff::PrimeField, pallas};
use hex::ToHex; use hex::ToHex;
use incrementalmerkletree::Hashable; use incrementalmerkletree::Hashable;

View File

@ -53,7 +53,7 @@ impl ZcashDeserialize for Bctv14Proof {
} }
#[cfg(any(test, feature = "proptest-impl"))] #[cfg(any(test, feature = "proptest-impl"))]
use proptest::{arbitrary::Arbitrary, collection::vec, prelude::*}; use proptest::{collection::vec, prelude::*};
#[cfg(any(test, feature = "proptest-impl"))] #[cfg(any(test, feature = "proptest-impl"))]
impl Arbitrary for Bctv14Proof { impl Arbitrary for Bctv14Proof {

View File

@ -65,7 +65,7 @@ impl ZcashDeserialize for Groth16Proof {
} }
#[cfg(any(test, feature = "proptest-impl"))] #[cfg(any(test, feature = "proptest-impl"))]
use proptest::{arbitrary::Arbitrary, collection::vec, prelude::*}; use proptest::{collection::vec, prelude::*};
#[cfg(any(test, feature = "proptest-impl"))] #[cfg(any(test, feature = "proptest-impl"))]
impl Arbitrary for Groth16Proof { impl Arbitrary for Groth16Proof {

View File

@ -36,7 +36,7 @@ impl ZcashDeserialize for Halo2Proof {
} }
} }
#[cfg(any(test, feature = "proptest-impl"))] #[cfg(any(test, feature = "proptest-impl"))]
use proptest::{arbitrary::Arbitrary, prelude::*}; use proptest::prelude::*;
#[cfg(any(test, feature = "proptest-impl"))] #[cfg(any(test, feature = "proptest-impl"))]
impl Arbitrary for Halo2Proof { impl Arbitrary for Halo2Proof {

View File

@ -6,7 +6,7 @@
mod tests; mod tests;
use std::{collections::BTreeMap, convert::TryInto, io, sync::Arc}; use std::{collections::BTreeMap, io, sync::Arc};
use serde_big_array::BigArray; use serde_big_array::BigArray;
pub use zcash_history::{V1, V2}; pub use zcash_history::{V1, V2};

View File

@ -5,7 +5,7 @@ use jubjub::{AffinePoint, ExtendedPoint};
use rand::SeedableRng; use rand::SeedableRng;
use rand_chacha::ChaChaRng; use rand_chacha::ChaChaRng;
use proptest::{arbitrary::any, collection::vec, prelude::*}; use proptest::{collection::vec, prelude::*};
use crate::primitives::Groth16Proof; use crate::primitives::Groth16Proof;

View File

@ -1,9 +1,6 @@
//! Note and value commitments. //! Note and value commitments.
use std::{ use std::{fmt, io};
convert::{TryFrom, TryInto},
fmt, io,
};
use bitvec::prelude::*; use bitvec::prelude::*;
use jubjub::ExtendedPoint; use jubjub::ExtendedPoint;

View File

@ -16,7 +16,7 @@ use rand_core::{CryptoRng, RngCore};
use crate::{ use crate::{
error::{AddressError, RandError}, error::{AddressError, RandError},
primitives::redjubjub::{self, SpendAuth}, primitives::redjubjub::SpendAuth,
serialization::{ serialization::{
serde_helpers, ReadZcashExt, SerializationError, ZcashDeserialize, ZcashSerialize, serde_helpers, ReadZcashExt, SerializationError, ZcashDeserialize, ZcashSerialize,
}, },

View File

@ -1,4 +1,4 @@
use proptest::{arbitrary::any, collection::vec, prelude::*}; use proptest::{collection::vec, prelude::*};
use super::*; use super::*;

View File

@ -3,14 +3,11 @@
//! Zebra uses a generic spend type for `V4` and `V5` transactions. //! Zebra uses a generic spend type for `V4` and `V5` transactions.
//! The anchor change is handled using the `AnchorVariant` type trait. //! The anchor change is handled using the `AnchorVariant` type trait.
use std::{convert::TryInto, fmt, io}; use std::{fmt, io};
use crate::{ use crate::{
block::MAX_BLOCK_BYTES, block::MAX_BLOCK_BYTES,
primitives::{ primitives::{redjubjub::SpendAuth, Groth16Proof},
redjubjub::{self, SpendAuth},
Groth16Proof,
},
serialization::{ serialization::{
ReadZcashExt, SerializationError, TrustedPreallocate, WriteZcashExt, ZcashDeserialize, ReadZcashExt, SerializationError, TrustedPreallocate, WriteZcashExt, ZcashDeserialize,
ZcashDeserializeInto, ZcashSerialize, ZcashDeserializeInto, ZcashSerialize,

View File

@ -8,7 +8,6 @@ use crate::{
serialization::{ZcashDeserializeInto, ZcashSerialize}, serialization::{ZcashDeserializeInto, ZcashSerialize},
transaction::{LockTime, Transaction}, transaction::{LockTime, Transaction},
}; };
use std::convert::TryInto;
proptest! { proptest! {
/// Serialize and deserialize `Spend<PerSpendAnchor>` /// Serialize and deserialize `Spend<PerSpendAnchor>`

View File

@ -19,7 +19,7 @@ use std::{
}; };
use bitvec::prelude::*; use bitvec::prelude::*;
use bridgetree::{self, NonEmptyFrontier}; use bridgetree::NonEmptyFrontier;
use hex::ToHex; use hex::ToHex;
use incrementalmerkletree::{frontier::Frontier, Hashable}; use incrementalmerkletree::{frontier::Frontier, Hashable};

View File

@ -1,9 +1,7 @@
//! Arbitrary data generation for serialization proptests //! Arbitrary data generation for serialization proptests
use std::convert::TryInto;
use chrono::{DateTime, TimeZone, Utc}; use chrono::{DateTime, TimeZone, Utc};
use proptest::{arbitrary::any, prelude::*}; use proptest::prelude::*;
use super::{ use super::{
CompactSizeMessage, DateTime32, TrustedPreallocate, ZcashSerialize, MAX_PROTOCOL_MESSAGE_LEN, CompactSizeMessage, DateTime32, TrustedPreallocate, ZcashSerialize, MAX_PROTOCOL_MESSAGE_LEN,

View File

@ -5,8 +5,6 @@
//! - [`CompactSizeMessage`] for sizes that must be less than the network message limit, and //! - [`CompactSizeMessage`] for sizes that must be less than the network message limit, and
//! - [`CompactSize64`] for flags, arbitrary counts, and sizes that span multiple blocks. //! - [`CompactSize64`] for flags, arbitrary counts, and sizes that span multiple blocks.
use std::convert::{TryFrom, TryInto};
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
use crate::serialization::{ use crate::serialization::{

View File

@ -1,9 +1,6 @@
//! Serialization constraint helpers. //! Serialization constraint helpers.
use std::{ use std::ops::Deref;
convert::{TryFrom, TryInto},
ops::Deref,
};
use crate::serialization::SerializationError; use crate::serialization::SerializationError;

View File

@ -2,7 +2,7 @@
use proptest::{collection::size_range, prelude::*}; use proptest::{collection::size_range, prelude::*};
use std::{convert::TryInto, matches}; use std::matches;
use crate::serialization::{ use crate::serialization::{
arbitrary::max_allocation_is_big_enough, zcash_deserialize::MAX_U8_ALLOCATION, arbitrary::max_allocation_is_big_enough, zcash_deserialize::MAX_U8_ALLOCATION,

View File

@ -1,4 +1,4 @@
use proptest::{arbitrary::any, array, prelude::*}; use proptest::{array, prelude::*};
use crate::{ use crate::{
amount::{Amount, NonNegative}, amount::{Amount, NonNegative},

View File

@ -1,4 +1,4 @@
use proptest::{arbitrary::any, collection::vec, prelude::*}; use proptest::{collection::vec, prelude::*};
impl Arbitrary for super::EncryptedNote { impl Arbitrary for super::EncryptedNote {
type Parameters = (); type Parameters = ();

View File

@ -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]> { pub fn block_map(&self) -> BTreeMap<u32, &'static [u8]> {
if self.is_mainnet() { if self.is_mainnet() {
zebra_test::vectors::MAINNET_BLOCKS.clone() zebra_test::vectors::MAINNET_BLOCKS.clone()

View File

@ -1,17 +1,9 @@
//! Arbitrary data generation for transaction proptests //! Arbitrary data generation for transaction proptests
use std::{ use std::{cmp::max, collections::HashMap, ops::Neg, sync::Arc};
cmp::max,
collections::HashMap,
convert::{TryFrom, TryInto},
ops::Neg,
sync::Arc,
};
use chrono::{TimeZone, Utc}; use chrono::{TimeZone, Utc};
use proptest::{ use proptest::{array, collection::vec, option, prelude::*, test_runner::TestRunner};
arbitrary::any, array, collection::vec, option, prelude::*, test_runner::TestRunner,
};
use reddsa::{orchard::Binding, Signature}; use reddsa::{orchard::Binding, Signature};
use crate::{ use crate::{

View File

@ -28,11 +28,7 @@
//! //!
//! [1]: crate::transaction::UnminedTx //! [1]: crate::transaction::UnminedTx
use std::{ use std::{fmt, sync::Arc};
convert::{TryFrom, TryInto},
fmt,
sync::Arc,
};
#[cfg(any(test, feature = "proptest-impl"))] #[cfg(any(test, feature = "proptest-impl"))]
use proptest_derive::Arbitrary; use proptest_derive::Arbitrary;

View File

@ -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 /// A 512-byte (plaintext) memo associated with a note, as described in
/// [protocol specification §5.5][ps]. /// [protocol specification §5.5][ps].

View File

@ -1,10 +1,10 @@
//! Contains impls of `ZcashSerialize`, `ZcashDeserialize` for all of the //! Contains impls of `ZcashSerialize`, `ZcashDeserialize` for all of the
//! transaction types, so that all of the serialization logic is in one place. //! 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 byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
use halo2::pasta::{group::ff::PrimeField, pallas}; use halo2::pasta::group::ff::PrimeField;
use hex::FromHex; use hex::FromHex;
use reddsa::{orchard::Binding, orchard::SpendAuth, Signature}; use reddsa::{orchard::Binding, orchard::SpendAuth, Signature};
@ -12,13 +12,12 @@ use crate::{
amount, amount,
block::MAX_BLOCK_BYTES, block::MAX_BLOCK_BYTES,
parameters::{OVERWINTER_VERSION_GROUP_ID, SAPLING_VERSION_GROUP_ID, TX_V5_VERSION_GROUP_ID}, parameters::{OVERWINTER_VERSION_GROUP_ID, SAPLING_VERSION_GROUP_ID, TX_V5_VERSION_GROUP_ID},
primitives::{Groth16Proof, Halo2Proof, ZkSnarkProof}, primitives::{Halo2Proof, ZkSnarkProof},
serialization::{ serialization::{
zcash_deserialize_external_count, zcash_serialize_empty_list, zcash_deserialize_external_count, zcash_serialize_empty_list,
zcash_serialize_external_count, AtLeastOne, ReadZcashExt, SerializationError, zcash_serialize_external_count, AtLeastOne, ReadZcashExt, SerializationError,
TrustedPreallocate, ZcashDeserialize, ZcashDeserializeInto, ZcashSerialize, TrustedPreallocate, ZcashDeserialize, ZcashDeserializeInto, ZcashSerialize,
}, },
sprout,
}; };
use super::*; use super::*;

View File

@ -5,11 +5,10 @@ use color_eyre::eyre::Result;
use lazy_static::lazy_static; use lazy_static::lazy_static;
use crate::{ use crate::{
amount::Amount,
block::{Block, Height, MAX_BLOCK_BYTES}, block::{Block, Height, MAX_BLOCK_BYTES},
parameters::{Network, NetworkUpgrade}, parameters::Network,
serialization::{SerializationError, ZcashDeserialize, ZcashDeserializeInto, ZcashSerialize}, serialization::{SerializationError, ZcashDeserialize, ZcashDeserializeInto, ZcashSerialize},
transaction::{hash::WtxId, sighash::SigHasher, txid::TxIdBuilder, Transaction}, transaction::{sighash::SigHasher, txid::TxIdBuilder},
transparent::Script, transparent::Script,
}; };

View File

@ -1,6 +1,6 @@
//! Transaction ID computation. Contains code for generating the Transaction ID //! Transaction ID computation. Contains code for generating the Transaction ID
//! from the transaction. //! from the transaction.
use std::{convert::TryInto, io}; use std::io;
use super::{Hash, Transaction}; use super::{Hash, Transaction};
use crate::serialization::{sha256d, ZcashSerialize}; use crate::serialization::{sha256d, ZcashSerialize};

View File

@ -2,10 +2,6 @@
use std::{fmt, io}; use std::{fmt, io};
use ripemd::{Digest, Ripemd160};
use secp256k1::PublicKey;
use sha2::Sha256;
use crate::{ use crate::{
parameters::NetworkKind, parameters::NetworkKind,
serialization::{SerializationError, ZcashDeserialize, ZcashSerialize}, serialization::{SerializationError, ZcashDeserialize, ZcashSerialize},
@ -154,29 +150,6 @@ impl ZcashDeserialize for Address {
} }
} }
trait ToAddressWithNetwork {
/// Convert `self` to an `Address`, given the current `network`.
fn to_address(&self, network: NetworkKind) -> Address;
}
impl ToAddressWithNetwork for Script {
fn to_address(&self, network_kind: NetworkKind) -> Address {
Address::PayToScriptHash {
network_kind,
script_hash: Address::hash_payload(self.as_raw_bytes()),
}
}
}
impl ToAddressWithNetwork for PublicKey {
fn to_address(&self, network_kind: NetworkKind) -> Address {
Address::PayToPublicKeyHash {
network_kind,
pub_key_hash: Address::hash_payload(&self.serialize()[..]),
}
}
}
impl Address { impl Address {
/// Create an address for the given public key hash and network. /// Create an address for the given public key hash and network.
pub fn from_pub_key_hash(network_kind: NetworkKind, pub_key_hash: [u8; 20]) -> Self { pub fn from_pub_key_hash(network_kind: NetworkKind, pub_key_hash: [u8; 20]) -> Self {
@ -219,21 +192,6 @@ impl Address {
} }
} }
/// A hash of a transparent address payload, as used in
/// transparent pay-to-script-hash and pay-to-publickey-hash
/// addresses.
///
/// The resulting hash in both of these cases is always exactly 20
/// bytes.
/// <https://en.bitcoin.it/Base58Check_encoding#Encoding_a_Bitcoin_address>
fn hash_payload(bytes: &[u8]) -> [u8; 20] {
let sha_hash = Sha256::digest(bytes);
let ripe_hash = Ripemd160::digest(sha_hash);
let mut payload = [0u8; 20];
payload[..].copy_from_slice(&ripe_hash[..]);
payload
}
/// Given a transparent address (P2SH or a P2PKH), create a script that can be used in a coinbase /// Given a transparent address (P2SH or a P2PKH), create a script that can be used in a coinbase
/// transaction output. /// transaction output.
pub fn create_script_from_address(&self) -> Script { pub fn create_script_from_address(&self) -> Script {
@ -264,11 +222,53 @@ impl Address {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use ripemd::{Digest, Ripemd160};
use secp256k1::PublicKey; use secp256k1::PublicKey;
use sha2::Sha256;
use super::*; use super::*;
trait ToAddressWithNetwork {
/// Convert `self` to an `Address`, given the current `network`.
fn to_address(&self, network: NetworkKind) -> Address;
}
impl ToAddressWithNetwork for Script {
fn to_address(&self, network_kind: NetworkKind) -> Address {
Address::PayToScriptHash {
network_kind,
script_hash: Address::hash_payload(self.as_raw_bytes()),
}
}
}
impl ToAddressWithNetwork for PublicKey {
fn to_address(&self, network_kind: NetworkKind) -> Address {
Address::PayToPublicKeyHash {
network_kind,
pub_key_hash: Address::hash_payload(&self.serialize()[..]),
}
}
}
impl Address {
/// A hash of a transparent address payload, as used in
/// transparent pay-to-script-hash and pay-to-publickey-hash
/// addresses.
///
/// The resulting hash in both of these cases is always exactly 20
/// bytes.
/// <https://en.bitcoin.it/Base58Check_encoding#Encoding_a_Bitcoin_address>
#[allow(dead_code)]
fn hash_payload(bytes: &[u8]) -> [u8; 20] {
let sha_hash = Sha256::digest(bytes);
let ripe_hash = Ripemd160::digest(sha_hash);
let mut payload = [0u8; 20];
payload[..].copy_from_slice(&ripe_hash[..]);
payload
}
}
#[test] #[test]
fn pubkey_mainnet() { fn pubkey_mainnet() {
let _init_guard = zebra_test::init(); let _init_guard = zebra_test::init();

View File

@ -1,4 +1,4 @@
use proptest::{arbitrary::any, collection::vec, prelude::*}; use proptest::{collection::vec, prelude::*};
use crate::{block, parameters::NetworkKind, LedgerState}; use crate::{block, parameters::NetworkKind, LedgerState};

View File

@ -95,7 +95,6 @@ mod proptests {
use proptest::prelude::*; use proptest::prelude::*;
use super::*; use super::*;
use crate::serialization::{ZcashDeserialize, ZcashSerialize};
proptest! { proptest! {
#[test] #[test]

View File

@ -1,6 +1,6 @@
//! Unspent transparent output data structures and functions. //! Unspent transparent output data structures and functions.
use std::{collections::HashMap, convert::TryInto}; use std::collections::HashMap;
use crate::{ use crate::{
block::{self, Block, Height}, block::{self, Block, Height},

View File

@ -6,7 +6,7 @@ use crate::{
transparent, transparent,
}; };
use std::{borrow::Borrow, collections::HashMap, convert::TryInto}; use std::{borrow::Borrow, collections::HashMap};
#[cfg(any(test, feature = "proptest-impl"))] #[cfg(any(test, feature = "proptest-impl"))]
use crate::{amount::MAX_MONEY, transaction::Transaction}; use crate::{amount::MAX_MONEY, transaction::Transaction};

View File

@ -1,6 +1,6 @@
use super::*; use super::*;
use proptest::{arbitrary::Arbitrary, collection::vec, prelude::*}; use proptest::{collection::vec, prelude::*};
impl Arbitrary for equihash::Solution { impl Arbitrary for equihash::Solution {
type Parameters = (); type Parameters = ();

View File

@ -1,8 +1,6 @@
use super::*; use super::*;
use crate::block; use proptest::{collection::vec, prelude::*};
use proptest::{arbitrary::Arbitrary, collection::vec, prelude::*};
impl Arbitrary for CompactDifficulty { impl Arbitrary for CompactDifficulty {
type Parameters = (); type Parameters = ();

View File

@ -1,8 +1,4 @@
use proptest::{arbitrary::any, prelude::*}; use proptest::prelude::*;
use std::cmp::Ordering;
use crate::block;
use super::super::*; use super::super::*;

View File

@ -2,7 +2,7 @@
use std::{env, sync::Arc}; use std::{env, sync::Arc};
use proptest::{arbitrary::any, prelude::*, test_runner::Config}; use proptest::{prelude::*, test_runner::Config};
use crate::{ use crate::{
block::{self, Block}, block::{self, Block},

View File

@ -1,5 +1,3 @@
use std::convert::TryInto;
use crate::{ use crate::{
block::{Block, MAX_BLOCK_BYTES}, block::{Block, MAX_BLOCK_BYTES},
serialization::{CompactSizeMessage, ZcashDeserialize, ZcashDeserializeInto, ZcashSerialize}, serialization::{CompactSizeMessage, ZcashDeserialize, ZcashDeserializeInto, ZcashSerialize},

View File

@ -2,7 +2,7 @@
//! //!
//! [7.8]: https://zips.z.cash/protocol/protocol.pdf#subsidies //! [7.8]: https://zips.z.cash/protocol/protocol.pdf#subsidies
use std::{collections::HashSet, convert::TryFrom}; use std::collections::HashSet;
use zebra_chain::{ use zebra_chain::{
amount::{Amount, Error, NonNegative}, amount::{Amount, Error, NonNegative},

View File

@ -1,22 +1,18 @@
//! Tests for block verification //! Tests for block verification
use std::sync::Arc;
use chrono::Utc;
use color_eyre::eyre::{eyre, Report}; use color_eyre::eyre::{eyre, Report};
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use tower::{buffer::Buffer, util::BoxService}; use tower::{buffer::Buffer, util::BoxService};
use zebra_chain::{ use zebra_chain::{
amount::{Amount, MAX_MONEY}, amount::MAX_MONEY,
block::{ block::{
self,
tests::generate::{ tests::generate::{
large_multi_transaction_block, large_single_transaction_block_many_inputs, large_multi_transaction_block, large_single_transaction_block_many_inputs,
}, },
Block, Height, Block, Height,
}, },
parameters::{Network, NetworkUpgrade}, parameters::NetworkUpgrade,
serialization::{ZcashDeserialize, ZcashDeserializeInto}, serialization::{ZcashDeserialize, ZcashDeserializeInto},
transaction::{arbitrary::transaction_to_fake_v5, LockTime, Transaction}, transaction::{arbitrary::transaction_to_fake_v5, LockTime, Transaction},
work::difficulty::{ParameterDifficulty as _, INVALID_COMPACT_DIFFICULTY}, work::difficulty::{ParameterDifficulty as _, INVALID_COMPACT_DIFFICULTY},

View File

@ -5,8 +5,8 @@ use std::sync::Arc;
use num_integer::div_ceil; use num_integer::div_ceil;
use zebra_chain::{ use zebra_chain::{
block::{self, Block, HeightDiff, MAX_BLOCK_BYTES}, block::{Block, HeightDiff, MAX_BLOCK_BYTES},
parameters::{Network, Network::*}, parameters::Network::*,
serialization::ZcashDeserialize, serialization::ZcashDeserialize,
}; };
use zebra_node_services::constants::{MAX_CHECKPOINT_BYTE_COUNT, MAX_CHECKPOINT_HEIGHT_GAP}; use zebra_node_services::constants::{MAX_CHECKPOINT_BYTE_COUNT, MAX_CHECKPOINT_HEIGHT_GAP};

View File

@ -1,14 +1,10 @@
//! Tests for checkpoint-based block verification //! Tests for checkpoint-based block verification
use std::{cmp::min, mem::drop, time::Duration}; use std::{cmp::min, time::Duration};
use color_eyre::eyre::{eyre, Report}; use color_eyre::eyre::{eyre, Report};
use futures::{ use futures::stream::{FuturesUnordered, StreamExt};
future::TryFutureExt,
stream::{FuturesUnordered, StreamExt},
};
use tokio::time::timeout; use tokio::time::timeout;
use tower::{Service, ServiceExt};
use tracing_futures::Instrument; use tracing_futures::Instrument;
use zebra_chain::{parameters::Network::*, serialization::ZcashDeserialize}; use zebra_chain::{parameters::Network::*, serialization::ZcashDeserialize};

View File

@ -15,7 +15,7 @@ use tokio::sync::watch;
use tower::{util::ServiceFn, Service}; use tower::{util::ServiceFn, Service};
use tower_batch_control::{Batch, BatchControl}; use tower_batch_control::{Batch, BatchControl};
use tower_fallback::Fallback; use tower_fallback::Fallback;
use zebra_chain::primitives::ed25519::{batch, *}; use zebra_chain::primitives::ed25519::*;
use crate::BoxError; use crate::BoxError;

View File

@ -5,7 +5,6 @@ use std::time::Duration;
use color_eyre::eyre::{eyre, Report, Result}; use color_eyre::eyre::{eyre, Report, Result};
use futures::stream::{FuturesOrdered, StreamExt}; use futures::stream::{FuturesOrdered, StreamExt};
use tower::ServiceExt; use tower::ServiceExt;
use tower_batch_control::Batch;
use crate::primitives::ed25519::*; use crate::primitives::ed25519::*;

View File

@ -1,5 +1,3 @@
use std::convert::TryFrom;
use crate::groth16::h_sig; use crate::groth16::h_sig;
#[test] #[test]

View File

@ -16,7 +16,7 @@ use tower::{util::ServiceFn, Service};
use tower_batch_control::{Batch, BatchControl}; use tower_batch_control::{Batch, BatchControl};
use tower_fallback::Fallback; use tower_fallback::Fallback;
use zebra_chain::primitives::redjubjub::{batch, *}; use zebra_chain::primitives::redjubjub::*;
use crate::BoxError; use crate::BoxError;

View File

@ -7,7 +7,6 @@ use std::time::Duration;
use color_eyre::eyre::{eyre, Result}; use color_eyre::eyre::{eyre, Result};
use futures::stream::{FuturesUnordered, StreamExt}; use futures::stream::{FuturesUnordered, StreamExt};
use tower::ServiceExt; use tower::ServiceExt;
use tower_batch_control::Batch;
async fn sign_and_verify<V>(mut verifier: V, n: usize) -> Result<(), V::Error> async fn sign_and_verify<V>(mut verifier: V, n: usize) -> Result<(), V::Error>
where where

View File

@ -7,7 +7,6 @@ use std::time::Duration;
use color_eyre::eyre::{eyre, Result}; use color_eyre::eyre::{eyre, Result};
use futures::stream::{FuturesUnordered, StreamExt}; use futures::stream::{FuturesUnordered, StreamExt};
use tower::ServiceExt; use tower::ServiceExt;
use tower_batch_control::Batch;
use zebra_chain::primitives::reddsa::{ use zebra_chain::primitives::reddsa::{
orchard::{Binding, SpendAuth}, orchard::{Binding, SpendAuth},

View File

@ -4,18 +4,15 @@ use std::{sync::Arc, time::Duration};
use color_eyre::eyre::Report; use color_eyre::eyre::Report;
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use tower::{layer::Layer, timeout::TimeoutLayer, Service}; use tower::{layer::Layer, timeout::TimeoutLayer};
use zebra_chain::{ use zebra_chain::{
block::{self, Block}, block::Block,
parameters::Network,
serialization::{ZcashDeserialize, ZcashDeserializeInto}, serialization::{ZcashDeserialize, ZcashDeserializeInto},
}; };
use zebra_state as zs; use zebra_state as zs;
use zebra_test::transcript::{ExpectedTranscriptError, Transcript}; use zebra_test::transcript::{ExpectedTranscriptError, Transcript};
use crate::Config;
use super::*; use super::*;
/// The timeout we apply to each verify future during testing. /// The timeout we apply to each verify future during testing.

View File

@ -3,7 +3,6 @@
use std::{ use std::{
collections::HashMap, collections::HashMap,
future::Future, future::Future,
iter::FromIterator,
pin::Pin, pin::Pin,
sync::Arc, sync::Arc,
task::{Context, Poll}, task::{Context, Poll},

View File

@ -4,7 +4,6 @@
use std::{ use std::{
cmp::Reverse, cmp::Reverse,
collections::HashMap, collections::HashMap,
iter::Extend,
net::{IpAddr, SocketAddr}, net::{IpAddr, SocketAddr},
sync::{Arc, Mutex}, sync::{Arc, Mutex},
time::Instant, time::Instant,

View File

@ -5,7 +5,6 @@ use std::{
ffi::OsString, ffi::OsString,
io::{self, ErrorKind}, io::{self, ErrorKind},
net::{IpAddr, SocketAddr}, net::{IpAddr, SocketAddr},
string::String,
time::Duration, time::Duration,
}; };

View File

@ -1,7 +1,7 @@
//! An address-with-metadata type used in Bitcoin networking. //! An address-with-metadata type used in Bitcoin networking.
use std::{ use std::{
cmp::{max, Ord, Ordering}, cmp::{max, Ordering},
time::Instant, time::Instant,
}; };

View File

@ -2,7 +2,7 @@
use std::net::IpAddr; use std::net::IpAddr;
use proptest::{arbitrary::any, collection::vec, prelude::*}; use proptest::{collection::vec, prelude::*};
use zebra_chain::{parameters::Network::*, serialization::DateTime32}; use zebra_chain::{parameters::Network::*, serialization::DateTime32};

View File

@ -9,11 +9,7 @@
use std::{borrow::Cow, collections::HashSet, fmt, pin::Pin, sync::Arc, time::Instant}; use std::{borrow::Cow, collections::HashSet, fmt, pin::Pin, sync::Arc, time::Instant};
use futures::{ use futures::{future::Either, prelude::*};
future::{self, Either},
prelude::*,
stream::Stream,
};
use rand::{seq::SliceRandom, thread_rng, Rng}; use rand::{seq::SliceRandom, thread_rng, Rng};
use tokio::time::{sleep, Sleep}; use tokio::time::{sleep, Sleep};
use tower::{Service, ServiceExt}; use tower::{Service, ServiceExt};

View File

@ -1,7 +1,6 @@
//! Wrapper around handshake logic that also opens a TCP connection. //! Wrapper around handshake logic that also opens a TCP connection.
use std::{ use std::{
future::Future,
pin::Pin, pin::Pin,
task::{Context, Poll}, task::{Context, Poll},
}; };

View File

@ -106,7 +106,7 @@ use std::{
use futures::{ use futures::{
channel::{mpsc, oneshot}, channel::{mpsc, oneshot},
future::{Future, FutureExt, TryFutureExt}, future::{FutureExt, TryFutureExt},
prelude::*, prelude::*,
stream::FuturesUnordered, stream::FuturesUnordered,
task::noop_waker, task::noop_waker,

View File

@ -2,7 +2,7 @@
use std::net::SocketAddr; use std::net::SocketAddr;
use proptest::{arbitrary::any, arbitrary::Arbitrary, collection::vec, prelude::*}; use proptest::{collection::vec, prelude::*};
use zebra_chain::{block, transaction}; use zebra_chain::{block, transaction};

View File

@ -1,7 +1,5 @@
//! Randomised property tests for Zebra's Zcash network protocol types. //! Randomised property tests for Zebra's Zcash network protocol types.
use std::convert::TryInto;
use bytes::BytesMut; use bytes::BytesMut;
use proptest::{collection::vec, prelude::*}; use proptest::{collection::vec, prelude::*};
use tokio_util::codec::{Decoder, Encoder}; use tokio_util::codec::{Decoder, Encoder};

View File

@ -1,6 +1,6 @@
//! Fixed test vectors for external protocol messages. //! Fixed test vectors for external protocol messages.
use std::{convert::TryInto, io::Write}; use std::io::Write;
use byteorder::{LittleEndian, WriteBytesExt}; use byteorder::{LittleEndian, WriteBytesExt};

View File

@ -6,7 +6,7 @@
//! Some parts of the `zcashd` RPC documentation are outdated. //! Some parts of the `zcashd` RPC documentation are outdated.
//! So this implementation follows the `zcashd` server and `lightwalletd` client implementations. //! So this implementation follows the `zcashd` server and `lightwalletd` client implementations.
use std::{collections::HashSet, default::Default, fmt::Debug, sync::Arc}; use std::{collections::HashSet, fmt::Debug, sync::Arc};
use chrono::Utc; use chrono::Utc;
use futures::{stream::FuturesOrdered, FutureExt, StreamExt, TryFutureExt}; use futures::{stream::FuturesOrdered, FutureExt, StreamExt, TryFutureExt};

View File

@ -7,7 +7,7 @@ use jsonrpc_core::{self, BoxFuture, Error, ErrorCode, Result};
use jsonrpc_derive::rpc; use jsonrpc_derive::rpc;
use tower::{Service, ServiceExt}; use tower::{Service, ServiceExt};
use zcash_address::{self, unified::Encoding, TryFromAddress}; use zcash_address::{unified::Encoding, TryFromAddress};
use zebra_chain::{ use zebra_chain::{
amount::Amount, amount::Amount,

View File

@ -227,9 +227,8 @@ fn update_checksum(checksum: &mut u32, item: [u8; 32]) {
} }
} }
impl ToString for LongPollId { impl std::fmt::Display for LongPollId {
/// Exact conversion from LongPollId to a string. fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
fn to_string(&self) -> String {
let LongPollId { let LongPollId {
tip_height, tip_height,
tip_hash_checksum, tip_hash_checksum,
@ -240,7 +239,8 @@ impl ToString for LongPollId {
// We can't do this using `serde`, because it names each field, // We can't do this using `serde`, because it names each field,
// but we want a single string containing all the fields. // but we want a single string containing all the fields.
format!( write!(
f,
// Height as decimal, padded with zeroes to the width of Height::MAX // Height as decimal, padded with zeroes to the width of Height::MAX
// Checksums as hex, padded with zeroes to the width of u32::MAX // Checksums as hex, padded with zeroes to the width of u32::MAX
// Timestamp as decimal, padded with zeroes to the width of u32::MAX // Timestamp as decimal, padded with zeroes to the width of u32::MAX

View File

@ -5,7 +5,7 @@
//! cargo insta test --review -p zebra-rpc --lib -- test_rpc_response_data //! cargo insta test --review -p zebra-rpc --lib -- test_rpc_response_data
//! ``` //! ```
use std::{collections::BTreeMap, sync::Arc}; use std::collections::BTreeMap;
use insta::dynamic_redaction; use insta::dynamic_redaction;
use tower::buffer::Buffer; use tower::buffer::Buffer;

View File

@ -1,8 +1,7 @@
//! Fixed test vectors for RPC methods. //! Fixed test vectors for RPC methods.
use std::{ops::RangeInclusive, sync::Arc}; use std::ops::RangeInclusive;
use jsonrpc_core::ErrorCode;
use tower::buffer::Buffer; use tower::buffer::Buffer;
use zebra_chain::{ use zebra_chain::{
@ -11,8 +10,7 @@ use zebra_chain::{
chain_tip::{mock::MockChainTip, NoChainTip}, chain_tip::{mock::MockChainTip, NoChainTip},
parameters::Network::*, parameters::Network::*,
serialization::{ZcashDeserializeInto, ZcashSerialize}, serialization::{ZcashDeserializeInto, ZcashSerialize},
transaction::{UnminedTx, UnminedTxId}, transaction::UnminedTxId,
transparent,
}; };
use zebra_node_services::BoxError; use zebra_node_services::BoxError;

View File

@ -13,7 +13,7 @@ use jsonrpc_core::{Compatibility, MetaIoHandler};
use jsonrpc_http_server::{CloseHandle, ServerBuilder}; use jsonrpc_http_server::{CloseHandle, ServerBuilder};
use tokio::task::JoinHandle; use tokio::task::JoinHandle;
use tower::Service; use tower::Service;
use tracing::{Instrument, *}; use tracing::*;
use zebra_chain::{ use zebra_chain::{
block, chain_sync_status::ChainSyncStatus, chain_tip::ChainTip, parameters::Network, block, chain_sync_status::ChainSyncStatus, chain_tip::ChainTip, parameters::Network,

View File

@ -277,7 +277,6 @@ impl Drop for CachedFfiTransaction {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use hex::FromHex; use hex::FromHex;
use std::convert::TryInto;
use std::sync::Arc; use std::sync::Arc;
use zebra_chain::{ use zebra_chain::{
parameters::{ConsensusBranchId, NetworkUpgrade::*}, parameters::{ConsensusBranchId, NetworkUpgrade::*},

View File

@ -5,7 +5,7 @@
//! * the Testnet minimum difficulty adjustment from ZIPs 205 and 208, and //! * the Testnet minimum difficulty adjustment from ZIPs 205 and 208, and
//! * `median-time-past`. //! * `median-time-past`.
use std::{cmp::max, cmp::min, convert::TryInto}; use std::{cmp::max, cmp::min};
use chrono::{DateTime, Duration, Utc}; use chrono::{DateTime, Duration, Utc};

View File

@ -1,6 +1,6 @@
//! Randomised property tests for nullifier contextual validation //! Randomised property tests for nullifier contextual validation
use std::{convert::TryInto, env, sync::Arc}; use std::{env, sync::Arc};
use itertools::Itertools; use itertools::Itertools;
use proptest::prelude::*; use proptest::prelude::*;

View File

@ -1,7 +1,5 @@
//! Fixed test vectors for state contextual validation checks. //! Fixed test vectors for state contextual validation checks.
use std::sync::Arc;
use zebra_chain::serialization::ZcashDeserializeInto; use zebra_chain::serialization::ZcashDeserializeInto;
use super::super::*; use super::super::*;

View File

@ -502,6 +502,12 @@ impl FinalizedState {
let network = self.network(); let network = self.network();
rt.block_on(async move { rt.block_on(async move {
// Send a ping to the server to check if it is available before inserting.
if client.ping().send().await.is_err() {
tracing::error!("Elasticsearch is not available, skipping block indexing");
return;
}
let response = client let response = client
.bulk(elasticsearch::BulkParts::Index( .bulk(elasticsearch::BulkParts::Index(
format!("zcash_{}", network.to_string().to_lowercase()).as_str(), format!("zcash_{}", network.to_string().to_lowercase()).as_str(),

View File

@ -1,6 +1,6 @@
//! Randomised proptests for scanner database formats. //! Randomised proptests for scanner database formats.
use proptest::{arbitrary::any, prelude::*}; use proptest::prelude::*;
use crate::{ use crate::{
service::finalized_state::arbitrary::assert_value_properties, SaplingScannedDatabaseIndex, service::finalized_state::arbitrary::assert_value_properties, SaplingScannedDatabaseIndex,

View File

@ -1,6 +1,6 @@
//! Randomised tests for the finalized disk format. //! Randomised tests for the finalized disk format.
use proptest::{arbitrary::any, prelude::*}; use proptest::prelude::*;
use zebra_chain::{ use zebra_chain::{
amount::{Amount, NonNegative}, amount::{Amount, NonNegative},

View File

@ -636,13 +636,11 @@ impl Chain {
.next() .next()
.expect("Zebra should never reach the max height in normal operation."); .expect("Zebra should never reach the max height in normal operation.");
if self.sprout_trees_by_height.get(&next_height).is_none() { self.sprout_trees_by_height
// TODO: Use `try_insert` once it stabilises. .entry(next_height)
self.sprout_trees_by_height.insert( .or_insert_with(|| {
next_height, highest_removed_tree.expect("There should be a cached removed tree.")
highest_removed_tree.expect("There should be a cached removed tree."), });
);
}
} }
} }
@ -839,13 +837,11 @@ impl Chain {
.next() .next()
.expect("Zebra should never reach the max height in normal operation."); .expect("Zebra should never reach the max height in normal operation.");
if self.sapling_trees_by_height.get(&next_height).is_none() { self.sapling_trees_by_height
// TODO: Use `try_insert` once it stabilises. .entry(next_height)
self.sapling_trees_by_height.insert( .or_insert_with(|| {
next_height, highest_removed_tree.expect("There should be a cached removed tree.")
highest_removed_tree.expect("There should be a cached removed tree."), });
);
}
} }
} }
@ -1048,13 +1044,11 @@ impl Chain {
.next() .next()
.expect("Zebra should never reach the max height in normal operation."); .expect("Zebra should never reach the max height in normal operation.");
if self.orchard_trees_by_height.get(&next_height).is_none() { self.orchard_trees_by_height
// TODO: Use `try_insert` once it stabilises. .entry(next_height)
self.orchard_trees_by_height.insert( .or_insert_with(|| {
next_height, highest_removed_tree.expect("There should be a cached removed tree.")
highest_removed_tree.expect("There should be a cached removed tree."), });
);
}
} }
} }

View File

@ -10,7 +10,7 @@ use zebra_chain::{
fmt::DisplayToDebug, fmt::DisplayToDebug,
history_tree::{HistoryTree, NonEmptyHistoryTree}, history_tree::{HistoryTree, NonEmptyHistoryTree},
parameters::NetworkUpgrade::*, parameters::NetworkUpgrade::*,
parameters::{Network, *}, parameters::*,
value_balance::ValueBalance, value_balance::ValueBalance,
LedgerState, LedgerState,
}; };
@ -611,15 +611,15 @@ fn different_blocks_different_chains() -> Result<()> {
// blocks, heights, hashes // blocks, heights, hashes
chain1.blocks = chain2.blocks.clone(); chain1.blocks = chain2.blocks.clone();
chain1.height_by_hash = chain2.height_by_hash.clone(); chain1.height_by_hash.clone_from(&chain2.height_by_hash);
chain1.tx_loc_by_hash = chain2.tx_loc_by_hash.clone(); chain1.tx_loc_by_hash.clone_from(&chain2.tx_loc_by_hash);
// transparent UTXOs // transparent UTXOs
chain1.created_utxos = chain2.created_utxos.clone(); chain1.created_utxos.clone_from(&chain2.created_utxos);
chain1.spent_utxos = chain2.spent_utxos.clone(); chain1.spent_utxos.clone_from(&chain2.spent_utxos);
// note commitment trees // note commitment trees
chain1.sprout_trees_by_anchor = chain2.sprout_trees_by_anchor.clone(); chain1.sprout_trees_by_anchor.clone_from(&chain2.sprout_trees_by_anchor);
chain1.sprout_trees_by_height = chain2.sprout_trees_by_height.clone(); chain1.sprout_trees_by_height = chain2.sprout_trees_by_height.clone();
chain1.sapling_trees_by_height = chain2.sapling_trees_by_height.clone(); chain1.sapling_trees_by_height = chain2.sapling_trees_by_height.clone();
chain1.orchard_trees_by_height = chain2.orchard_trees_by_height.clone(); chain1.orchard_trees_by_height = chain2.orchard_trees_by_height.clone();
@ -640,9 +640,9 @@ fn different_blocks_different_chains() -> Result<()> {
chain1.orchard_anchors_by_height = chain2.orchard_anchors_by_height.clone(); chain1.orchard_anchors_by_height = chain2.orchard_anchors_by_height.clone();
// nullifiers // nullifiers
chain1.sprout_nullifiers = chain2.sprout_nullifiers.clone(); chain1.sprout_nullifiers.clone_from(&chain2.sprout_nullifiers);
chain1.sapling_nullifiers = chain2.sapling_nullifiers.clone(); chain1.sapling_nullifiers.clone_from(&chain2.sapling_nullifiers);
chain1.orchard_nullifiers = chain2.orchard_nullifiers.clone(); chain1.orchard_nullifiers.clone_from(&chain2.orchard_nullifiers);
// proof of work // proof of work
chain1.partial_cumulative_work = chain2.partial_cumulative_work; chain1.partial_cumulative_work = chain2.partial_cumulative_work;

View File

@ -966,6 +966,7 @@ impl<Request, Response, Error> ResponseSender<Request, Response, Error> {
/// ///
/// - [`PanicAssertion`] /// - [`PanicAssertion`]
/// - [`PropTestAssertion`] /// - [`PropTestAssertion`]
#[allow(dead_code)]
trait AssertionType {} trait AssertionType {}
/// Represents normal Rust assertions that panic, like [`assert_eq`]. /// Represents normal Rust assertions that panic, like [`assert_eq`].

View File

@ -5,7 +5,7 @@
use hex::FromHex; use hex::FromHex;
use lazy_static::lazy_static; use lazy_static::lazy_static;
use std::{collections::BTreeMap, convert::TryInto}; use std::collections::BTreeMap;
trait ReverseCollection { trait ReverseCollection {
/// Return a reversed copy of this collection /// Return a reversed copy of this collection

View File

@ -48,10 +48,6 @@ async fn self_check() {
assert!(t1.check(t2).await.is_ok()); assert!(t1.check(t2).await.is_ok());
} }
#[derive(Debug, thiserror::Error)]
#[error("Error")]
struct Error;
const TRANSCRIPT_DATA2: [(&str, Result<&str, ExpectedTranscriptError>); 4] = [ const TRANSCRIPT_DATA2: [(&str, Result<&str, ExpectedTranscriptError>); 4] = [
("req1", Ok("rsp1")), ("req1", Ok("rsp1")),
("req2", Ok("rsp2")), ("req2", Ok("rsp2")),

View File

@ -35,7 +35,7 @@
use std::{cmp::min, path::PathBuf}; use std::{cmp::min, path::PathBuf};
use abscissa_core::{config, Command, FrameworkError, Runnable}; use abscissa_core::{config, Command, FrameworkError};
use color_eyre::eyre::{eyre, Report}; use color_eyre::eyre::{eyre, Report};
use tokio::time::Instant; use tokio::time::Instant;
use tower::{Service, ServiceExt}; use tower::{Service, ServiceExt};

View File

@ -78,7 +78,7 @@
//! //!
//! Some of the diagnostic features are optional, and need to be enabled at compile-time. //! Some of the diagnostic features are optional, and need to be enabled at compile-time.
use abscissa_core::{config, Command, FrameworkError, Runnable}; use abscissa_core::{config, Command, FrameworkError};
use color_eyre::eyre::{eyre, Report}; use color_eyre::eyre::{eyre, Report};
use futures::FutureExt; use futures::FutureExt;
use tokio::{pin, select, sync::oneshot}; use tokio::{pin, select, sync::oneshot};

View File

@ -1,13 +1,6 @@
//! Inbound service tests with a fake peer set. //! Inbound service tests with a fake peer set.
use std::{ use std::{collections::HashSet, iter, net::SocketAddr, str::FromStr, sync::Arc, time::Duration};
collections::HashSet,
iter::{self, FromIterator},
net::SocketAddr,
str::FromStr,
sync::Arc,
time::Duration,
};
use futures::FutureExt; use futures::FutureExt;
use tokio::{sync::oneshot, task::JoinHandle, time::timeout}; use tokio::{sync::oneshot, task::JoinHandle, time::timeout};

View File

@ -8,11 +8,10 @@ use zebra_chain::{
amount::Amount, amount::Amount,
block::{Block, Height}, block::{Block, Height},
parameters::Network, parameters::Network,
transaction::{UnminedTxId, VerifiedUnminedTx},
}; };
use crate::components::mempool::{ use crate::components::mempool::{
config, storage::tests::unmined_transactions_in_blocks, storage::*, Mempool, storage::tests::unmined_transactions_in_blocks, storage::*, Mempool,
}; };
/// Eviction memory time used for tests. Most tests won't care about this /// Eviction memory time used for tests. Most tests won't care about this

View File

@ -1,6 +1,6 @@
//! Fixed test vectors for the mempool. //! Fixed test vectors for the mempool.
use std::{collections::HashSet, sync::Arc}; use std::sync::Arc;
use color_eyre::Report; use color_eyre::Report;
use tokio::time::{self, timeout}; use tokio::time::{self, timeout};
@ -15,12 +15,10 @@ use zebra_state::{Config as StateConfig, CHAIN_TIP_UPDATE_WAIT_LIMIT};
use zebra_test::mock_service::{MockService, PanicAssertion}; use zebra_test::mock_service::{MockService, PanicAssertion};
use crate::components::{ use crate::components::{
mempool::{self, storage::tests::unmined_transactions_in_blocks, *}, mempool::{self, *},
sync::RecentSyncLengths, sync::RecentSyncLengths,
}; };
use super::UnboxMempoolError;
/// A [`MockService`] representing the network service. /// A [`MockService`] representing the network service.
type MockPeerSet = MockService<zn::Request, zn::Response, PanicAssertion>; type MockPeerSet = MockService<zn::Request, zn::Response, PanicAssertion>;

View File

@ -2,7 +2,7 @@
use std::{ use std::{
collections::HashMap, collections::HashMap,
convert::{self, TryFrom}, convert,
pin::Pin, pin::Pin,
sync::Arc, sync::Arc,
task::{Context, Poll}, task::{Context, Poll},

View File

@ -9,7 +9,7 @@
use std::{future::Future, time::Duration}; use std::{future::Future, time::Duration};
use abscissa_core::{Application, Component, FrameworkError, Shutdown}; use abscissa_core::{Component, FrameworkError, Shutdown};
use color_eyre::Report; use color_eyre::Report;
use tokio::runtime::Runtime; use tokio::runtime::Runtime;

View File

@ -155,7 +155,7 @@ use std::{
}; };
use color_eyre::{ use color_eyre::{
eyre::{eyre, Result, WrapErr}, eyre::{eyre, WrapErr},
Help, Help,
}; };
use semver::Version; use semver::Version;
@ -480,7 +480,7 @@ fn ephemeral(cache_dir_config: EphemeralConfig, cache_dir_check: EphemeralCheck)
let ignored_cache_dir = run_dir.path().join("state"); let ignored_cache_dir = run_dir.path().join("state");
if cache_dir_config == EphemeralConfig::MisconfiguredCacheDir { if cache_dir_config == EphemeralConfig::MisconfiguredCacheDir {
// Write a configuration that sets both the cache_dir and ephemeral options // Write a configuration that sets both the cache_dir and ephemeral options
config.state.cache_dir = ignored_cache_dir.clone(); config.state.cache_dir.clone_from(&ignored_cache_dir);
} }
if cache_dir_check == EphemeralCheck::ExistingDirectory { if cache_dir_check == EphemeralCheck::ExistingDirectory {
// We set the cache_dir config to a newly created empty temp directory, // We set the cache_dir config to a newly created empty temp directory,
@ -3016,11 +3016,15 @@ fn scan_start_where_left() -> Result<()> {
config.shielded_scan.sapling_keys_to_scan = keys; config.shielded_scan.sapling_keys_to_scan = keys;
// Add the cache dir to shielded scan, make it the same as the zebrad cache state. // Add the cache dir to shielded scan, make it the same as the zebrad cache state.
config.shielded_scan.db_config_mut().cache_dir = cache_dir.clone(); config
.shielded_scan
.db_config_mut()
.cache_dir
.clone_from(&cache_dir);
config.shielded_scan.db_config_mut().ephemeral = false; config.shielded_scan.db_config_mut().ephemeral = false;
// Add the cache dir to state. // Add the cache dir to state.
config.state.cache_dir = cache_dir.clone(); config.state.cache_dir.clone_from(&cache_dir);
config.state.ephemeral = false; config.state.ephemeral = false;
// Remove the scan directory before starting. // Remove the scan directory before starting.

View File

@ -13,7 +13,6 @@ use std::{
time::Duration, time::Duration,
}; };
use color_eyre::eyre::Result;
use tempfile::TempDir; use tempfile::TempDir;
use zebra_chain::parameters::Network::{self, *}; use zebra_chain::parameters::Network::{self, *};

View File

@ -16,7 +16,7 @@ use tempfile::TempDir;
use zebra_chain::parameters::Network::{self, *}; use zebra_chain::parameters::Network::{self, *};
use zebra_test::{ use zebra_test::{
args, args,
command::{Arguments, TestChild, TestDirExt}, command::{Arguments, TestDirExt},
net::random_known_port, net::random_known_port,
prelude::*, prelude::*,
}; };

View File

@ -69,7 +69,10 @@ pub(crate) async fn run() -> Result<()> {
.expect("already checked that there is a cached state path"); .expect("already checked that there is a cached state path");
let mut scan_config = zebra_scan::Config::default(); let mut scan_config = zebra_scan::Config::default();
scan_config.db_config_mut().cache_dir = zebrad_state_path.clone(); scan_config
.db_config_mut()
.cache_dir
.clone_from(&zebrad_state_path);
// Logs the network as zebrad would as part of the metadata when starting up. // Logs the network as zebrad would as part of the metadata when starting up.
// This is currently needed for the 'Check startup logs' step in CI to pass. // This is currently needed for the 'Check startup logs' step in CI to pass.

View File

@ -7,7 +7,6 @@
use std::{path::PathBuf, time::Duration}; use std::{path::PathBuf, time::Duration};
use color_eyre::eyre::Result;
use tempfile::TempDir; use tempfile::TempDir;
use zebra_chain::{block::Height, parameters::Network}; use zebra_chain::{block::Height, parameters::Network};