finished fixing errors in zebra-chain - all crate tests pass
This commit is contained in:
parent
5be0d8626b
commit
69066346fc
|
@ -348,11 +348,12 @@ impl Arbitrary for Block {
|
|||
type Parameters = LedgerState;
|
||||
|
||||
fn arbitrary_with(ledger_state: Self::Parameters) -> Self::Strategy {
|
||||
let ledger_state_clone = ledger_state.clone();
|
||||
let transactions_strategy =
|
||||
// Generate a random number transactions. A coinbase tx is always generated, so if
|
||||
// `transaction_count` is zero, the block will contain only the coinbase tx.
|
||||
(0..MAX_ARBITRARY_ITEMS).prop_flat_map(move |transaction_count| {
|
||||
Transaction::vec_strategy(ledger_state, transaction_count)
|
||||
Transaction::vec_strategy(ledger_state_clone.clone(), transaction_count)
|
||||
});
|
||||
|
||||
// TODO: if needed, fixup:
|
||||
|
@ -411,7 +412,7 @@ impl Block {
|
|||
|
||||
// generate block strategies with the correct heights
|
||||
for _ in 0..count {
|
||||
vec.push((Just(current.height), Block::arbitrary_with(current)));
|
||||
vec.push((Just(current.height), Block::arbitrary_with(current.clone())));
|
||||
current.height.0 += 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ impl Transaction {
|
|||
/// Generate a proptest strategy for V1 Transactions
|
||||
pub fn v1_strategy(ledger_state: LedgerState) -> BoxedStrategy<Self> {
|
||||
(
|
||||
transparent::Input::vec_strategy(ledger_state, MAX_ARBITRARY_ITEMS),
|
||||
transparent::Input::vec_strategy(&ledger_state, MAX_ARBITRARY_ITEMS),
|
||||
vec(any::<transparent::Output>(), 0..MAX_ARBITRARY_ITEMS),
|
||||
any::<LockTime>(),
|
||||
)
|
||||
|
@ -61,7 +61,7 @@ impl Transaction {
|
|||
/// Generate a proptest strategy for V2 Transactions
|
||||
pub fn v2_strategy(ledger_state: LedgerState) -> BoxedStrategy<Self> {
|
||||
(
|
||||
transparent::Input::vec_strategy(ledger_state, MAX_ARBITRARY_ITEMS),
|
||||
transparent::Input::vec_strategy(&ledger_state, MAX_ARBITRARY_ITEMS),
|
||||
vec(any::<transparent::Output>(), 0..MAX_ARBITRARY_ITEMS),
|
||||
any::<LockTime>(),
|
||||
option::of(any::<JoinSplitData<Bctv14Proof>>()),
|
||||
|
@ -80,7 +80,7 @@ impl Transaction {
|
|||
/// Generate a proptest strategy for V3 Transactions
|
||||
pub fn v3_strategy(ledger_state: LedgerState) -> BoxedStrategy<Self> {
|
||||
(
|
||||
transparent::Input::vec_strategy(ledger_state, MAX_ARBITRARY_ITEMS),
|
||||
transparent::Input::vec_strategy(&ledger_state, MAX_ARBITRARY_ITEMS),
|
||||
vec(any::<transparent::Output>(), 0..MAX_ARBITRARY_ITEMS),
|
||||
any::<LockTime>(),
|
||||
any::<block::Height>(),
|
||||
|
@ -101,7 +101,7 @@ impl Transaction {
|
|||
/// Generate a proptest strategy for V4 Transactions
|
||||
pub fn v4_strategy(ledger_state: LedgerState) -> BoxedStrategy<Self> {
|
||||
(
|
||||
transparent::Input::vec_strategy(ledger_state, MAX_ARBITRARY_ITEMS),
|
||||
transparent::Input::vec_strategy(&ledger_state, MAX_ARBITRARY_ITEMS),
|
||||
vec(any::<transparent::Output>(), 0..MAX_ARBITRARY_ITEMS),
|
||||
any::<LockTime>(),
|
||||
any::<block::Height>(),
|
||||
|
@ -146,7 +146,7 @@ impl Transaction {
|
|||
NetworkUpgrade::branch_id_strategy(),
|
||||
any::<LockTime>(),
|
||||
any::<block::Height>(),
|
||||
transparent::Input::vec_strategy(ledger_state, MAX_ARBITRARY_ITEMS),
|
||||
transparent::Input::vec_strategy(&ledger_state, MAX_ARBITRARY_ITEMS),
|
||||
vec(any::<transparent::Output>(), 0..MAX_ARBITRARY_ITEMS),
|
||||
option::of(any::<sapling::ShieldedData<sapling::SharedAnchor>>()),
|
||||
option::of(any::<orchard::ShieldedData>()),
|
||||
|
@ -196,7 +196,7 @@ impl Transaction {
|
|||
len: usize,
|
||||
) -> BoxedStrategy<Vec<Arc<Self>>> {
|
||||
// TODO: fixup coinbase miner subsidy
|
||||
let coinbase = Transaction::arbitrary_with(ledger_state).prop_map(Arc::new);
|
||||
let coinbase = Transaction::arbitrary_with(ledger_state.clone()).prop_map(Arc::new);
|
||||
ledger_state.has_coinbase = false;
|
||||
let remainder = vec(
|
||||
Transaction::arbitrary_with(ledger_state).prop_map(Arc::new),
|
||||
|
@ -787,7 +787,7 @@ impl Arbitrary for Transaction {
|
|||
Self::v4_strategy(ledger_state)
|
||||
}
|
||||
NetworkUpgrade::Nu5 => prop_oneof![
|
||||
Self::v4_strategy(ledger_state),
|
||||
Self::v4_strategy(ledger_state.clone()),
|
||||
Self::v5_strategy(ledger_state)
|
||||
]
|
||||
.boxed(),
|
||||
|
|
|
@ -150,7 +150,7 @@ fn transaction_valid_network_upgrade_strategy() -> Result<()> {
|
|||
// Update with new transaction versions as needed
|
||||
let strategy = LedgerState::coinbase_strategy(None, 5, true).prop_flat_map(|ledger_state| {
|
||||
(
|
||||
Just(ledger_state.network),
|
||||
Just(ledger_state.network.clone()),
|
||||
Block::arbitrary_with(ledger_state),
|
||||
)
|
||||
});
|
||||
|
|
|
@ -426,7 +426,7 @@ impl Output {
|
|||
/// Return the destination address from a transparent output.
|
||||
///
|
||||
/// Returns None if the address type is not valid or unrecognized.
|
||||
pub fn address(&self, network: Network) -> Option<Address> {
|
||||
pub fn address(&self, network: &Network) -> Option<Address> {
|
||||
zcash_primitives::transparent_output_address(self, &network)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -103,7 +103,7 @@ fn get_transparent_output_address_with_blocks_for_network(network: Network) {
|
|||
|
||||
for (idx, tx) in block.transactions.iter().enumerate() {
|
||||
for output in tx.outputs() {
|
||||
let addr = output.address(network);
|
||||
let addr = output.address(&network);
|
||||
if addr.is_none() && idx == 0 && output.lock_script.as_raw_bytes()[0] == 0x21 {
|
||||
// There are a bunch of coinbase transactions with pay-to-pubkey scripts
|
||||
// which we don't support; skip them
|
||||
|
|
|
@ -100,7 +100,7 @@ async fn test_rpc_response_data_for_network(network: Network) {
|
|||
|
||||
// build addresses
|
||||
let address = &first_block_first_transaction.outputs()[1]
|
||||
.address(network)
|
||||
.address(&network)
|
||||
.unwrap();
|
||||
let addresses = vec![address.to_string()];
|
||||
|
||||
|
|
|
@ -669,7 +669,7 @@ async fn rpc_getaddresstxids_response() {
|
|||
|
||||
// Get the address.
|
||||
let address = first_block_first_transaction.outputs()[1]
|
||||
.address(network)
|
||||
.address(&network)
|
||||
.unwrap();
|
||||
|
||||
// Create a populated state service
|
||||
|
@ -808,7 +808,7 @@ async fn rpc_getaddressutxos_response() {
|
|||
let first_block_first_transaction = &blocks[1].transactions[0];
|
||||
// get the address, this is always `t3Vz22vK5z2LcKEdg16Yv4FFneEL1zg9ojd`
|
||||
let address = &first_block_first_transaction.outputs()[1]
|
||||
.address(Mainnet)
|
||||
.address(&Mainnet)
|
||||
.unwrap();
|
||||
|
||||
let mut mempool: MockService<_, _, _, BoxError> = MockService::build().for_unit_tests();
|
||||
|
|
|
@ -368,7 +368,7 @@ impl ZebraDb {
|
|||
.values()
|
||||
.map(|ordered_utxo| &ordered_utxo.utxo),
|
||||
)
|
||||
.filter_map(|utxo| utxo.output.address(network))
|
||||
.filter_map(|utxo| utxo.output.address(&network))
|
||||
.unique()
|
||||
.collect();
|
||||
|
||||
|
|
|
@ -413,7 +413,7 @@ impl DiskWriteBatch {
|
|||
// Index all new transparent outputs
|
||||
for (new_output_location, utxo) in new_outputs_by_out_loc {
|
||||
let unspent_output = &utxo.output;
|
||||
let receiving_address = unspent_output.address(network);
|
||||
let receiving_address = unspent_output.address(&network);
|
||||
|
||||
// Update the address balance by adding this UTXO's value
|
||||
if let Some(receiving_address) = receiving_address {
|
||||
|
@ -490,7 +490,7 @@ impl DiskWriteBatch {
|
|||
// Coinbase inputs represent new coins, so there are no UTXOs to mark as spent.
|
||||
for (spent_output_location, utxo) in spent_utxos_by_out_loc {
|
||||
let spent_output = &utxo.output;
|
||||
let sending_address = spent_output.address(network);
|
||||
let sending_address = spent_output.address(&network);
|
||||
|
||||
// Fetch the balance, and the link from the address to the AddressLocation, from memory.
|
||||
if let Some(sending_address) = sending_address {
|
||||
|
@ -548,7 +548,7 @@ impl DiskWriteBatch {
|
|||
let spent_utxo = spent_utxos_by_outpoint
|
||||
.get(&spent_outpoint)
|
||||
.expect("unexpected missing spent output");
|
||||
let sending_address = spent_utxo.output.address(network);
|
||||
let sending_address = spent_utxo.output.address(&network);
|
||||
|
||||
// Fetch the balance, and the link from the address to the AddressLocation, from memory.
|
||||
if let Some(sending_address) = sending_address {
|
||||
|
|
|
@ -1754,7 +1754,7 @@ impl
|
|||
);
|
||||
|
||||
// Update the address index with this UTXO
|
||||
if let Some(receiving_address) = created_utxo.utxo.output.address(self.network) {
|
||||
if let Some(receiving_address) = created_utxo.utxo.output.address(&self.network) {
|
||||
let address_transfers = self
|
||||
.partial_transparent_transfers
|
||||
.entry(receiving_address)
|
||||
|
@ -1793,7 +1793,7 @@ impl
|
|||
);
|
||||
|
||||
// Revert the address index for this UTXO
|
||||
if let Some(receiving_address) = created_utxo.utxo.output.address(self.network) {
|
||||
if let Some(receiving_address) = created_utxo.utxo.output.address(&self.network) {
|
||||
let address_transfers = self
|
||||
.partial_transparent_transfers
|
||||
.get_mut(&receiving_address)
|
||||
|
@ -1857,7 +1857,7 @@ impl
|
|||
};
|
||||
|
||||
// Index the spent output for the address
|
||||
if let Some(spending_address) = spent_output.utxo.output.address(self.network) {
|
||||
if let Some(spending_address) = spent_output.utxo.output.address(&self.network) {
|
||||
let address_transfers = self
|
||||
.partial_transparent_transfers
|
||||
.entry(spending_address)
|
||||
|
@ -1909,7 +1909,7 @@ impl
|
|||
};
|
||||
|
||||
// Revert the spent output for the address
|
||||
if let Some(receiving_address) = spent_output.utxo.output.address(self.network) {
|
||||
if let Some(receiving_address) = spent_output.utxo.output.address(&self.network) {
|
||||
let address_transfers = self
|
||||
.partial_transparent_transfers
|
||||
.get_mut(&receiving_address)
|
||||
|
|
|
@ -77,7 +77,7 @@ impl AddressUtxos {
|
|||
self.utxos.iter().map(|(out_loc, output)| {
|
||||
(
|
||||
output
|
||||
.address(self.network)
|
||||
.address(&self.network)
|
||||
.expect("address indexes only contain outputs with addresses"),
|
||||
self.tx_ids
|
||||
.get(&out_loc.transaction_location())
|
||||
|
|
Loading…
Reference in New Issue