certichain

Blockchain built from scratch for verifying document's legitimacy.
Log | Files | Refs | README | LICENSE

commit 52ec6099609daf2f567b39de592b12de10d38d0b
parent ca1ee631c44693b79e44faa790de1864bb84c4b0
Author: Shivakumar <[email protected]>
Date:   Thu,  6 Aug 2026 00:31:35 +0530

feat(mempool): add Get method and tests

Signed-off-by: Shivakumar <[email protected]>

Diffstat:
Minternal/mempool/mempool.go | 10++++++++++
Minternal/mempool/mempool_test.go | 21+++++++++++++++++++++
2 files changed, 31 insertions(+), 0 deletions(-)

diff --git a/internal/mempool/mempool.go b/internal/mempool/mempool.go @@ -117,6 +117,16 @@ func (mp *Mempool) sortedTransactions() []*transaction.Transaction { return result } +// Get checks if the transaction exists in the mempool and returns it. +func (mp *Mempool) Get(txID []byte) *transaction.Transaction { + mp.mu.Lock() + defer mp.mu.Unlock() + if tx, exists := mp.txs[string(txID)]; exists { + return tx.Clone() + } + return nil +} + // Pending returns all the transactions deterministically sorted. func (mp *Mempool) Pending() []*transaction.Transaction { mp.mu.RLock() diff --git a/internal/mempool/mempool_test.go b/internal/mempool/mempool_test.go @@ -223,6 +223,27 @@ func TestAdd_DefensiveCopy(t *testing.T) { } } +func TestGet(t *testing.T) { + t.Parallel() + + mp := New() + tx := mustTx(t) + + if mp.Get(tx.TxID) != nil { + t.Error("Get Error: found transaction in empty mempool") + } + + mustAdd(t, mp, tx) + if mp.Get(tx.TxID) == nil { + t.Error("Get Error: missing transaction") + } + + mp.Remove([][]byte{tx.TxID}) + if mp.Get(tx.TxID) != nil { + t.Error("Get Error: transction in mempool after removed") + } +} + func TestPending_Determinism(t *testing.T) { t.Parallel()