Merge pull request #315 from gmale/zip-313-impl

ZIP 313 Implementation
This commit is contained in:
str4d 2020-11-24 02:10:17 +00:00 committed by GitHub
commit 7ced7f3c56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 17 deletions

View File

@ -505,7 +505,7 @@ mod tests {
Ok(_) => panic!("Should have failed"),
Err(e) => assert_eq!(
e.to_string(),
"Insufficient balance (have 0, need 10001 including fee)"
"Insufficient balance (have 0, need 1001 including fee)"
),
}
}
@ -571,7 +571,7 @@ mod tests {
Ok(_) => panic!("Should have failed"),
Err(e) => assert_eq!(
e.to_string(),
"Insufficient balance (have 50000, need 80000 including fee)"
"Insufficient balance (have 50000, need 71000 including fee)"
),
}
@ -603,7 +603,7 @@ mod tests {
Ok(_) => panic!("Should have failed"),
Err(e) => assert_eq!(
e.to_string(),
"Insufficient balance (have 50000, need 80000 including fee)"
"Insufficient balance (have 50000, need 71000 including fee)"
),
}
@ -690,7 +690,7 @@ mod tests {
Ok(_) => panic!("Should have failed"),
Err(e) => assert_eq!(
e.to_string(),
"Insufficient balance (have 0, need 12000 including fee)"
"Insufficient balance (have 0, need 3000 including fee)"
),
}
@ -722,7 +722,7 @@ mod tests {
Ok(_) => panic!("Should have failed"),
Err(e) => assert_eq!(
e.to_string(),
"Insufficient balance (have 0, need 12000 including fee)"
"Insufficient balance (have 0, need 3000 including fee)"
),
}

View File

@ -475,7 +475,10 @@ mod tests {
sapling::Node,
transaction::{
builder::Builder,
components::{Amount, OutPoint, TzeIn, TzeOut},
components::{
amount::{Amount, DEFAULT_FEE},
OutPoint, TzeIn, TzeOut,
},
Transaction, TransactionData,
},
zip32::ExtendedSpendingKey,
@ -739,7 +742,7 @@ mod tests {
extension_id: 0,
};
let prevout_a = (OutPoint::new(tx_a.txid().0, 0), tx_a.tze_outputs[0].clone());
let value_xfr = Amount::from_u64(90000).unwrap();
let value_xfr = value - DEFAULT_FEE;
db_b.demo_transfer_to_close(prevout_a, value_xfr, preimage_1, h2)
.map_err(|e| format!("transfer failure: {:?}", e))
.unwrap();
@ -765,7 +768,7 @@ mod tests {
builder_c
.add_transparent_output(
&TransparentAddress::PublicKey([0; 20]),
Amount::from_u64(80000).unwrap(),
value_xfr - DEFAULT_FEE,
)
.unwrap();

View File

@ -870,7 +870,7 @@ mod tests {
primitives::Rseed,
prover::mock::MockTxProver,
sapling::Node,
transaction::components::Amount,
transaction::components::{amount::Amount, amount::DEFAULT_FEE},
zip32::{ExtendedFullViewingKey, ExtendedSpendingKey},
};
@ -990,7 +990,7 @@ mod tests {
let builder = Builder::new(TEST_NETWORK, H0);
assert_eq!(
builder.build(consensus::BranchId::Sapling, &MockTxProver),
Err(Error::ChangeIsNegative(Amount::from_i64(-10000).unwrap()))
Err(Error::ChangeIsNegative(Amount::zero() - DEFAULT_FEE))
);
}
@ -999,7 +999,7 @@ mod tests {
let to = extfvk.default_address().unwrap().1;
// Fail if there is only a Sapling output
// 0.0005 z-ZEC out, 0.0001 t-ZEC fee
// 0.0005 z-ZEC out, 0.00001 t-ZEC fee
{
let mut builder = Builder::new(TEST_NETWORK, H0);
builder
@ -1007,12 +1007,14 @@ mod tests {
.unwrap();
assert_eq!(
builder.build(consensus::BranchId::Sapling, &MockTxProver),
Err(Error::ChangeIsNegative(Amount::from_i64(-60000).unwrap()))
Err(Error::ChangeIsNegative(
Amount::from_i64(-50000).unwrap() - DEFAULT_FEE
))
);
}
// Fail if there is only a transparent output
// 0.0005 t-ZEC out, 0.0001 t-ZEC fee
// 0.0005 t-ZEC out, 0.00001 t-ZEC fee
{
let mut builder = Builder::new(TEST_NETWORK, H0);
builder
@ -1023,12 +1025,14 @@ mod tests {
.unwrap();
assert_eq!(
builder.build(consensus::BranchId::Sapling, &MockTxProver),
Err(Error::ChangeIsNegative(Amount::from_i64(-60000).unwrap()))
Err(Error::ChangeIsNegative(
Amount::from_i64(-50000).unwrap() - DEFAULT_FEE
))
);
}
let note1 = to
.create_note(59999, Rseed::BeforeZip212(jubjub::Fr::random(&mut rng)))
.create_note(50999, Rseed::BeforeZip212(jubjub::Fr::random(&mut rng)))
.unwrap();
let cmu1 = Node::new(note1.cmu().to_repr());
let mut tree = CommitmentTree::new();
@ -1036,7 +1040,7 @@ mod tests {
let mut witness1 = IncrementalWitness::from_tree(&tree);
// Fail if there is insufficient input
// 0.0003 z-ZEC out, 0.0002 t-ZEC out, 0.0001 t-ZEC fee, 0.00059999 z-ZEC in
// 0.0003 z-ZEC out, 0.0002 t-ZEC out, 0.00001 t-ZEC fee, 0.00050999 z-ZEC in
{
let mut builder = Builder::new(TEST_NETWORK, H0);
builder

View File

@ -4,7 +4,7 @@ use std::ops::{Add, AddAssign, Sub, SubAssign};
pub const COIN: i64 = 1_0000_0000;
pub const MAX_MONEY: i64 = 21_000_000 * COIN;
pub const DEFAULT_FEE: Amount = Amount(10000);
pub const DEFAULT_FEE: Amount = Amount(1000);
/// A type-safe representation of some quantity of Zcash.
///