Use last_id instead of seed

It doesn't really matter, but was confusing since the seed points
to an entry before the mint's deposit.
This commit is contained in:
Greg Fitzgerald 2018-04-02 15:02:23 -06:00
parent daadae7987
commit 49708e92d3
3 changed files with 15 additions and 11 deletions

View File

@ -202,11 +202,11 @@ mod tests {
let alice = Mint::new(10_000); let alice = Mint::new(10_000);
let bob_pubkey = KeyPair::new().pubkey(); let bob_pubkey = KeyPair::new().pubkey();
let mut acc = Accountant::new(&alice); let mut acc = Accountant::new(&alice);
acc.transfer(1_000, &alice.keypair(), bob_pubkey, alice.seed()) acc.transfer(1_000, &alice.keypair(), bob_pubkey, alice.last_id())
.unwrap(); .unwrap();
assert_eq!(acc.get_balance(&bob_pubkey).unwrap(), 1_000); assert_eq!(acc.get_balance(&bob_pubkey).unwrap(), 1_000);
acc.transfer(500, &alice.keypair(), bob_pubkey, alice.seed()) acc.transfer(500, &alice.keypair(), bob_pubkey, alice.last_id())
.unwrap(); .unwrap();
assert_eq!(acc.get_balance(&bob_pubkey).unwrap(), 1_500); assert_eq!(acc.get_balance(&bob_pubkey).unwrap(), 1_500);
} }
@ -216,10 +216,10 @@ mod tests {
let alice = Mint::new(11_000); let alice = Mint::new(11_000);
let mut acc = Accountant::new(&alice); let mut acc = Accountant::new(&alice);
let bob_pubkey = KeyPair::new().pubkey(); let bob_pubkey = KeyPair::new().pubkey();
acc.transfer(1_000, &alice.keypair(), bob_pubkey, alice.seed()) acc.transfer(1_000, &alice.keypair(), bob_pubkey, alice.last_id())
.unwrap(); .unwrap();
assert_eq!( assert_eq!(
acc.transfer(10_001, &alice.keypair(), bob_pubkey, alice.seed()), acc.transfer(10_001, &alice.keypair(), bob_pubkey, alice.last_id()),
Err(AccountingError::InsufficientFunds) Err(AccountingError::InsufficientFunds)
); );
@ -233,7 +233,7 @@ mod tests {
let alice = Mint::new(1); let alice = Mint::new(1);
let mut acc = Accountant::new(&alice); let mut acc = Accountant::new(&alice);
let bob_pubkey = KeyPair::new().pubkey(); let bob_pubkey = KeyPair::new().pubkey();
let mut tr = Transaction::new(&alice.keypair(), bob_pubkey, 1, alice.seed()); let mut tr = Transaction::new(&alice.keypair(), bob_pubkey, 1, alice.last_id());
if let Plan::Pay(ref mut payment) = tr.plan { if let Plan::Pay(ref mut payment) = tr.plan {
payment.tokens = 2; // <-- attack! payment.tokens = 2; // <-- attack!
} }
@ -258,7 +258,7 @@ mod tests {
let mut acc = Accountant::new(&alice); let mut acc = Accountant::new(&alice);
let alice_keypair = alice.keypair(); let alice_keypair = alice.keypair();
let bob_pubkey = KeyPair::new().pubkey(); let bob_pubkey = KeyPair::new().pubkey();
acc.transfer(500, &alice_keypair, bob_pubkey, alice.seed()) acc.transfer(500, &alice_keypair, bob_pubkey, alice.last_id())
.unwrap(); .unwrap();
assert_eq!(acc.get_balance(&bob_pubkey).unwrap(), 500); assert_eq!(acc.get_balance(&bob_pubkey).unwrap(), 500);
} }
@ -270,7 +270,7 @@ mod tests {
let alice_keypair = alice.keypair(); let alice_keypair = alice.keypair();
let bob_pubkey = KeyPair::new().pubkey(); let bob_pubkey = KeyPair::new().pubkey();
let dt = Utc::now(); let dt = Utc::now();
acc.transfer_on_date(1, &alice_keypair, bob_pubkey, dt, alice.seed()) acc.transfer_on_date(1, &alice_keypair, bob_pubkey, dt, alice.last_id())
.unwrap(); .unwrap();
// Alice's balance will be zero because all funds are locked up. // Alice's balance will be zero because all funds are locked up.
@ -299,7 +299,7 @@ mod tests {
acc.process_verified_timestamp(alice.pubkey(), dt).unwrap(); acc.process_verified_timestamp(alice.pubkey(), dt).unwrap();
// It's now past now, so this transfer should be processed immediately. // It's now past now, so this transfer should be processed immediately.
acc.transfer_on_date(1, &alice_keypair, bob_pubkey, dt, alice.seed()) acc.transfer_on_date(1, &alice_keypair, bob_pubkey, dt, alice.last_id())
.unwrap(); .unwrap();
assert_eq!(acc.get_balance(&alice.pubkey()), Some(0)); assert_eq!(acc.get_balance(&alice.pubkey()), Some(0));
@ -313,7 +313,7 @@ mod tests {
let alice_keypair = alice.keypair(); let alice_keypair = alice.keypair();
let bob_pubkey = KeyPair::new().pubkey(); let bob_pubkey = KeyPair::new().pubkey();
let dt = Utc::now(); let dt = Utc::now();
let sig = acc.transfer_on_date(1, &alice_keypair, bob_pubkey, dt, alice.seed()) let sig = acc.transfer_on_date(1, &alice_keypair, bob_pubkey, dt, alice.last_id())
.unwrap(); .unwrap();
// Alice's balance will be zero because all funds are locked up. // Alice's balance will be zero because all funds are locked up.

View File

@ -106,10 +106,10 @@ mod tests {
let acc = Accountant::new(&alice); let acc = Accountant::new(&alice);
let bob_pubkey = KeyPair::new().pubkey(); let bob_pubkey = KeyPair::new().pubkey();
let exit = Arc::new(AtomicBool::new(false)); let exit = Arc::new(AtomicBool::new(false));
let historian = Historian::new(&alice.seed(), Some(30)); let historian = Historian::new(&alice.last_id(), Some(30));
let acc = Arc::new(Mutex::new(AccountantSkel::new( let acc = Arc::new(Mutex::new(AccountantSkel::new(
acc, acc,
alice.seed(), alice.last_id(),
sink(), sink(),
historian, historian,
))); )));

View File

@ -33,6 +33,10 @@ impl Mint {
hash(&self.pkcs8) hash(&self.pkcs8)
} }
pub fn last_id(&self) -> Hash {
self.create_entries()[1].id
}
pub fn keypair(&self) -> KeyPair { pub fn keypair(&self) -> KeyPair {
KeyPair::from_pkcs8(Input::from(&self.pkcs8)).unwrap() KeyPair::from_pkcs8(Input::from(&self.pkcs8)).unwrap()
} }