fix the overflow issue (#891)

This commit is contained in:
guanqun
2018-10-09 16:50:08 +08:00
committed by Gav Wood
parent 0666759b16
commit ceda61f13c
+12 -1
View File
@@ -165,7 +165,7 @@ impl<Hash: hash::Hash + Member> ReadyTransactions<Hash> {
let transaction = TransactionRef { let transaction = TransactionRef {
insertion_id, insertion_id,
valid_till: block_number + tx.longevity, valid_till: block_number.saturating_add(tx.longevity),
transaction: Arc::new(tx), transaction: Arc::new(tx),
}; };
@@ -493,6 +493,14 @@ mod tests {
tx4.requires = vec![tx1.provides[0].clone()]; tx4.requires = vec![tx1.provides[0].clone()];
tx4.provides = vec![]; tx4.provides = vec![];
let block_number = 1; let block_number = 1;
let tx5 = Transaction {
ex: vec![5],
hash: 5,
priority: 1,
longevity: u64::max_value(), // use the max_value() here for testing.
requires: vec![tx1.provides[0].clone()],
provides: vec![],
};
// when // when
let x = WaitingTransaction::new(tx1, &ready.provided_tags()); let x = WaitingTransaction::new(tx1, &ready.provided_tags());
@@ -503,6 +511,8 @@ mod tests {
ready.import(block_number, x).unwrap(); ready.import(block_number, x).unwrap();
let x = WaitingTransaction::new(tx4, &ready.provided_tags()); let x = WaitingTransaction::new(tx4, &ready.provided_tags());
ready.import(block_number, x).unwrap(); ready.import(block_number, x).unwrap();
let x = WaitingTransaction::new(tx5, &ready.provided_tags());
ready.import(block_number, x).unwrap();
// then // then
assert_eq!(ready.best.len(), 1); assert_eq!(ready.best.len(), 1);
@@ -513,6 +523,7 @@ mod tests {
assert_eq!(it.next(), Some(2)); assert_eq!(it.next(), Some(2));
assert_eq!(it.next(), Some(3)); assert_eq!(it.next(), Some(3));
assert_eq!(it.next(), Some(4)); assert_eq!(it.next(), Some(4));
assert_eq!(it.next(), Some(5));
assert_eq!(it.next(), None); assert_eq!(it.next(), None);
} }