diff --git a/abc/past.nim b/abc/past.nim index 78d8422..bde5f22 100644 --- a/abc/past.nim +++ b/abc/past.nim @@ -18,3 +18,7 @@ func past(store: TxStore, ackHash: AckHash, accumulator: var seq[TxHash]) = func past*(store: TxStore, hash: TxHash|AckHash): seq[TxHash] = store.past(hash, result) + +func past*(store: TxStore, hashes: varargs[AckHash]): seq[TxHash] = + for hash in hashes: + store.past(hash, result) diff --git a/tests/abc/testPast.nim b/tests/abc/testPast.nim index 0dcc15b..eef4a3a 100644 --- a/tests/abc/testPast.nim +++ b/tests/abc/testPast.nim @@ -10,7 +10,7 @@ suite "Past transactions and acknowledgements": let bob = PublicKey.bob let victor = PublicKey.victor var tx1, tx2, tx3: Transaction - var ack1, ack2: Ack + var ack1, ack2, ack3: Ack setup: tx1 = !Transaction.init({genesis.hash: alice}, {bob: 100.u256}, victor) @@ -20,8 +20,9 @@ suite "Past transactions and acknowledgements": {alice: 200.u256}, victor ) - ack1 = !Ack.init([tx1.hash, tx2.hash], victor) - ack2 = !Ack.init(ack1.hash, [tx3.hash], victor) + ack1 = !Ack.init([tx1.hash], victor) + ack2 = !Ack.init([tx2.hash], victor) + ack3 = !Ack.init(ack1.hash, [tx2.hash, tx3.hash], victor) test "finds all transactions that precede a transaction": var store = TxStore.init(genesis) @@ -37,6 +38,13 @@ suite "Past transactions and acknowledgements": test "finds all transactions that precede an acknowledgement": var store = TxStore.init(genesis) store.add(tx1, tx2, tx3) - store.add(ack1, ack2) - check store.past(ack1.hash) == [tx1.hash, genesis.hash, tx2.hash] - check store.past(ack2.hash) == [tx1.hash, genesis.hash, tx2.hash, tx3.hash] + store.add(ack1, ack2, ack3) + check store.past(ack1.hash) == [tx1.hash, genesis.hash] + check store.past(ack2.hash) == [tx2.hash, genesis.hash] + check store.past(ack3.hash) == [tx1.hash, genesis.hash, tx2.hash, tx3.hash] + + test "finds all transactions that precede a set of acknowledgements": + var store = TxStore.init(genesis) + store.add(tx1, tx2, tx3) + store.add(ack1, ack2, ack3) + check store.past(ack1.hash, ack2.hash) == [tx1.hash, genesis.hash, tx2.hash]