Find all transactions that precede a set of acknowledgments

This commit is contained in:
Mark Spanbroek 2021-07-08 12:00:13 +02:00
parent 1cc48e754a
commit db1d8d3ae8
2 changed files with 18 additions and 6 deletions

View File

@ -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)

View File

@ -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]