File tree Expand file tree Collapse file tree 2 files changed +38
-1
lines changed Expand file tree Collapse file tree 2 files changed +38
-1
lines changed Original file line number Diff line number Diff line change @@ -253,7 +253,13 @@ func (s *service) getTx(h util.Uint256) block.Transaction {
253
253
254
254
tx , _ , _ := s .Config .Chain .GetTransaction (h )
255
255
256
- return tx
256
+ // this is needed because in case of absent tx dBFT expects to
257
+ // get nil interface, not a nil pointer to any concrete type
258
+ if tx != nil {
259
+ return tx
260
+ }
261
+
262
+ return nil
257
263
}
258
264
259
265
func (s * service ) verifyBlock (b block.Block ) bool {
Original file line number Diff line number Diff line change @@ -56,6 +56,37 @@ func TestService_ValidatePayload(t *testing.T) {
56
56
})
57
57
}
58
58
59
+ func TestService_getTx (t * testing.T ) {
60
+ srv := newTestService (t )
61
+
62
+ t .Run ("transaction in mempool" , func (t * testing.T ) {
63
+ tx := newMinerTx (1234 )
64
+ h := tx .Hash ()
65
+
66
+ require .Equal (t , nil , srv .getTx (h ))
67
+
68
+ item := core .NewPoolItem (tx , new (feer ))
69
+ srv .Chain .GetMemPool ().TryAdd (h , item )
70
+
71
+ got := srv .getTx (h )
72
+ require .NotNil (t , got )
73
+ require .Equal (t , h , got .Hash ())
74
+ })
75
+
76
+ t .Run ("transaction in local cache" , func (t * testing.T ) {
77
+ tx := newMinerTx (4321 )
78
+ h := tx .Hash ()
79
+
80
+ require .Equal (t , nil , srv .getTx (h ))
81
+
82
+ srv .txx .Add (tx )
83
+
84
+ got := srv .getTx (h )
85
+ require .NotNil (t , got )
86
+ require .Equal (t , h , got .Hash ())
87
+ })
88
+ }
89
+
59
90
func TestService_OnPayload (t * testing.T ) {
60
91
srv := newTestService (t )
61
92
You can’t perform that action at this time.
0 commit comments