Skip to content

Commit b80c840

Browse files
rjl493456442karalabe
authored andcommitted
core, les: fix les unit tests (#19823)
1 parent a32a2b9 commit b80c840

File tree

5 files changed

+22
-12
lines changed

5 files changed

+22
-12
lines changed

core/tx_pool.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -745,13 +745,13 @@ func (pool *TxPool) AddRemotes(txs []*types.Transaction) []error {
745745
}
746746

747747
// This is like AddRemotes, but waits for pool reorganization. Tests use this method.
748-
func (pool *TxPool) addRemotesSync(txs []*types.Transaction) []error {
748+
func (pool *TxPool) AddRemotesSync(txs []*types.Transaction) []error {
749749
return pool.addTxs(txs, false, true)
750750
}
751751

752752
// This is like AddRemotes with a single transaction, but waits for pool reorganization. Tests use this method.
753753
func (pool *TxPool) addRemoteSync(tx *types.Transaction) error {
754-
errs := pool.addRemotesSync([]*types.Transaction{tx})
754+
errs := pool.AddRemotesSync([]*types.Transaction{tx})
755755
return errs[0]
756756
}
757757

core/tx_pool_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ func TestStateChangeDuringTransactionPoolReset(t *testing.T) {
200200
t.Fatalf("Invalid nonce, want 0, got %d", nonce)
201201
}
202202

203-
pool.addRemotesSync([]*types.Transaction{tx0, tx1})
203+
pool.AddRemotesSync([]*types.Transaction{tx0, tx1})
204204

205205
nonce = pool.Nonce(address)
206206
if nonce != 2 {
@@ -587,7 +587,7 @@ func TestTransactionPostponing(t *testing.T) {
587587
txs = append(txs, tx)
588588
}
589589
}
590-
for i, err := range pool.addRemotesSync(txs) {
590+
for i, err := range pool.AddRemotesSync(txs) {
591591
if err != nil {
592592
t.Fatalf("tx %d: failed to add transactions: %v", i, err)
593593
}
@@ -683,7 +683,7 @@ func TestTransactionGapFilling(t *testing.T) {
683683
defer sub.Unsubscribe()
684684

685685
// Create a pending and a queued transaction with a nonce-gap in between
686-
pool.addRemotesSync([]*types.Transaction{
686+
pool.AddRemotesSync([]*types.Transaction{
687687
transaction(0, 100000, key),
688688
transaction(2, 100000, key),
689689
})
@@ -800,7 +800,7 @@ func testTransactionQueueGlobalLimiting(t *testing.T, nolocals bool) {
800800
nonces[addr]++
801801
}
802802
// Import the batch and verify that limits have been enforced
803-
pool.addRemotesSync(txs)
803+
pool.AddRemotesSync(txs)
804804

805805
queued := 0
806806
for addr, list := range pool.queue {
@@ -988,7 +988,7 @@ func TestTransactionPendingGlobalLimiting(t *testing.T) {
988988
}
989989
}
990990
// Import the batch and verify that limits have been enforced
991-
pool.addRemotesSync(txs)
991+
pool.AddRemotesSync(txs)
992992

993993
pending := 0
994994
for _, list := range pool.pending {
@@ -1068,7 +1068,7 @@ func TestTransactionPendingMinimumAllowance(t *testing.T) {
10681068
}
10691069
}
10701070
// Import the batch and verify that limits have been enforced
1071-
pool.addRemotesSync(txs)
1071+
pool.AddRemotesSync(txs)
10721072

10731073
for addr, list := range pool.pending {
10741074
if list.Len() != int(config.AccountSlots) {
@@ -1124,7 +1124,7 @@ func TestTransactionPoolRepricing(t *testing.T) {
11241124
ltx := pricedTransaction(0, 100000, big.NewInt(1), keys[3])
11251125

11261126
// Import the batch and that both pending and queued transactions match up
1127-
pool.addRemotesSync(txs)
1127+
pool.AddRemotesSync(txs)
11281128
pool.AddLocal(ltx)
11291129

11301130
pending, queued := pool.Stats()
@@ -1404,7 +1404,7 @@ func TestTransactionPoolStableUnderpricing(t *testing.T) {
14041404
for i := uint64(0); i < config.GlobalSlots; i++ {
14051405
txs = append(txs, pricedTransaction(i, 100000, big.NewInt(1), keys[0]))
14061406
}
1407-
pool.addRemotesSync(txs)
1407+
pool.AddRemotesSync(txs)
14081408

14091409
pending, queued := pool.Stats()
14101410
if pending != int(config.GlobalSlots) {
@@ -1658,7 +1658,7 @@ func TestTransactionStatusCheck(t *testing.T) {
16581658
txs = append(txs, pricedTransaction(2, 100000, big.NewInt(1), keys[2])) // Queued only
16591659

16601660
// Import the transaction and ensure they are correctly added
1661-
pool.addRemotesSync(txs)
1661+
pool.AddRemotesSync(txs)
16621662

16631663
pending, queued := pool.Stats()
16641664
if pending != 2 {

les/handler.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ type BlockChain interface {
8585

8686
type txPool interface {
8787
AddRemotes(txs []*types.Transaction) []error
88+
AddRemotesSync(txs []*types.Transaction) []error
8889
Status(hashes []common.Hash) []core.TxStatus
8990
}
9091

@@ -125,6 +126,9 @@ type ProtocolManager struct {
125126

126127
// Callbacks
127128
synced func() bool
129+
130+
// Testing fields
131+
addTxsSync bool
128132
}
129133

130134
// NewProtocolManager returns a new ethereum sub protocol manager. The Ethereum sub protocol manages peers capable
@@ -1044,7 +1048,12 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
10441048
hash := tx.Hash()
10451049
stats[i] = pm.txStatus(hash)
10461050
if stats[i].Status == core.TxStatusUnknown {
1047-
if errs := pm.txpool.AddRemotes([]*types.Transaction{tx}); errs[0] != nil {
1051+
addFn := pm.txpool.AddRemotes
1052+
// Add txs synchronously for testing purpose
1053+
if pm.addTxsSync {
1054+
addFn = pm.txpool.AddRemotesSync
1055+
}
1056+
if errs := addFn([]*types.Transaction{tx}); errs[0] != nil {
10481057
stats[i].Error = errs[0].Error()
10491058
continue
10501059
}

les/handler_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,7 @@ func TestGetBloombitsProofs(t *testing.T) {
496496
func TestTransactionStatusLes2(t *testing.T) {
497497
server, tearDown := newServerEnv(t, 0, 2, nil)
498498
defer tearDown()
499+
server.pm.addTxsSync = true
499500

500501
chain := server.pm.blockchain.(*core.BlockChain)
501502
config := core.DefaultTxPoolConfig

les/transactions.rlp

Whitespace-only changes.

0 commit comments

Comments
 (0)