Ensure the server isn't passed a Plan that spends more than is bonded

This commit is contained in:
Greg Fitzgerald
2018-03-11 11:53:45 -06:00
parent 0eb3669fbf
commit aa0a184ebe
2 changed files with 42 additions and 4 deletions

View File

@@ -5,7 +5,7 @@
use hash::Hash;
use entry::Entry;
use event::Event;
use transaction::{Action, Condition, Plan, Transaction};
use transaction::{Action, Plan, Transaction};
use signature::{KeyPair, PublicKey, Signature};
use mint::Mint;
use historian::{reserve_signature, Historian};
@@ -281,6 +281,21 @@ mod tests {
);
}
#[test]
fn test_overspend_attack() {
let alice = Mint::new(1);
let mut acc = Accountant::new(&alice, None);
let bob_pubkey = KeyPair::new().pubkey();
let mut tr = Transaction::new(&alice.keypair(), bob_pubkey, 1, alice.seed());
if let Plan::Action(Action::Pay(ref mut payment)) = tr.plan {
payment.asset = 2; // <-- Attack!
}
assert_eq!(
acc.process_transaction(tr),
Err(AccountingError::InvalidTransfer)
);
}
#[test]
fn test_transfer_to_newb() {
let alice = Mint::new(10_000);