From 8d1f564411f4e7632370185a65ecc003836e25a0 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Fri, 27 Dec 2019 14:09:58 +0300 Subject: [PATCH] consensus: add tests for getTx --- pkg/consensus/consensus_test.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/pkg/consensus/consensus_test.go b/pkg/consensus/consensus_test.go index d934906fc..3d86e969a 100644 --- a/pkg/consensus/consensus_test.go +++ b/pkg/consensus/consensus_test.go @@ -56,6 +56,37 @@ func TestService_ValidatePayload(t *testing.T) { }) } +func TestService_getTx(t *testing.T) { + srv := newTestService(t) + + t.Run("transaction in mempool", func(t *testing.T) { + tx := newMinerTx(1234) + h := tx.Hash() + + require.Equal(t, nil, srv.getTx(h)) + + item := core.NewPoolItem(tx, new(feer)) + srv.Chain.GetMemPool().TryAdd(h, item) + + got := srv.getTx(h) + require.NotNil(t, got) + require.Equal(t, h, got.Hash()) + }) + + t.Run("transaction in local cache", func(t *testing.T) { + tx := newMinerTx(4321) + h := tx.Hash() + + require.Equal(t, nil, srv.getTx(h)) + + srv.txx.Add(tx) + + got := srv.getTx(h) + require.NotNil(t, got) + require.Equal(t, h, got.Hash()) + }) +} + func TestService_OnPayload(t *testing.T) { srv := newTestService(t)