From d6f22399a59e55f7eed530e161b02164d545fe25 Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Mon, 12 Jul 2021 15:22:57 +0200 Subject: [PATCH] Add genesis hash to past --- abc/history.nim | 3 +++ tests/abc/testHistory.nim | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/abc/history.nim b/abc/history.nim index 51f7943..c1d5f44 100644 --- a/abc/history.nim +++ b/abc/history.nim @@ -5,6 +5,7 @@ export sets type History* = object + genesis*: TxHash transactions*: HashSet[TxHash] missingTx*: HashSet[TxHash] missingAck*: HashSet[AckHash] @@ -55,9 +56,11 @@ func past(store: TxStore, ackHash: AckHash, history: var History) = history.missingAck.incl(ackHash) func past*(store: TxStore, hash: TxHash|AckHash): History = + result.genesis = store.genesis store.past(hash, result) func past*(store: TxStore, hashes: varargs[AckHash]): History = + result.genesis = store.genesis for hash in hashes: store.past(hash, result) diff --git a/tests/abc/testHistory.nim b/tests/abc/testHistory.nim index faca38b..f2155b7 100644 --- a/tests/abc/testHistory.nim +++ b/tests/abc/testHistory.nim @@ -62,6 +62,14 @@ suite "Past transactions and acknowledgements": check store.past(ack1.hash, ack2.hash).transactions == set(genesis.hash, tx1.hash, tx2.hash) + test "past contains the genesis hash": + var store = TxStore.init(genesis) + store.add(tx1, tx3) + store.add(ack3) + check store.past(tx1.hash).genesis == store.genesis + check store.past(tx3.hash).genesis == store.genesis + check store.past(ack3.hash).genesis == store.genesis + suite "Transaction validation": let alice = PublicKey.alice