forked from TrueCloudLab/neoneo-go
Merge pull request #583 from nspcc-dev/fix/gettx
consensus: return nil interface from getTx
This commit is contained in:
commit
d0ffa2d79d
2 changed files with 38 additions and 1 deletions
|
@ -253,7 +253,13 @@ func (s *service) getTx(h util.Uint256) block.Transaction {
|
||||||
|
|
||||||
tx, _, _ := s.Config.Chain.GetTransaction(h)
|
tx, _, _ := s.Config.Chain.GetTransaction(h)
|
||||||
|
|
||||||
|
// this is needed because in case of absent tx dBFT expects to
|
||||||
|
// get nil interface, not a nil pointer to any concrete type
|
||||||
|
if tx != nil {
|
||||||
return tx
|
return tx
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *service) verifyBlock(b block.Block) bool {
|
func (s *service) verifyBlock(b block.Block) bool {
|
||||||
|
|
|
@ -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) {
|
func TestService_OnPayload(t *testing.T) {
|
||||||
srv := newTestService(t)
|
srv := newTestService(t)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue