mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
cmd/devp2p/internal/ethtest: handle header requests in more places
This commit is contained in:
parent
2c359308a4
commit
a443a0f317
2 changed files with 25 additions and 6 deletions
|
|
@ -511,7 +511,7 @@ transaction gets propagated.`)
|
|||
if err != nil {
|
||||
t.Fatalf("failed to sign tx: %v", err)
|
||||
}
|
||||
if err := s.sendTxs([]*types.Transaction{tx}); err != nil {
|
||||
if err := s.sendTxs(t, []*types.Transaction{tx}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
s.chain.IncNonce(from, 1)
|
||||
|
|
@ -539,7 +539,7 @@ does not propagate them.`)
|
|||
if err != nil {
|
||||
t.Fatalf("failed to sign tx: %v", err)
|
||||
}
|
||||
if err := s.sendTxs([]*types.Transaction{tx}); err != nil {
|
||||
if err := s.sendTxs(t, []*types.Transaction{tx}); err != nil {
|
||||
t.Fatalf("failed to send txs: %v", err)
|
||||
}
|
||||
s.chain.IncNonce(from, 1)
|
||||
|
|
@ -595,7 +595,7 @@ does not propagate them.`)
|
|||
}
|
||||
txs = append(txs, tx)
|
||||
}
|
||||
if err := s.sendInvalidTxs(txs); err != nil {
|
||||
if err := s.sendInvalidTxs(t, txs); err != nil {
|
||||
t.Fatalf("failed to send invalid txs: %v", err)
|
||||
}
|
||||
}
|
||||
|
|
@ -636,7 +636,7 @@ on another peer connection using GetPooledTransactions.`)
|
|||
s.chain.IncNonce(from, uint64(count))
|
||||
|
||||
// Send txs.
|
||||
if err := s.sendTxs(txs); err != nil {
|
||||
if err := s.sendTxs(t, txs); err != nil {
|
||||
t.Fatalf("failed to send txs: %v", err)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,11 +25,12 @@ import (
|
|||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/eth/protocols/eth"
|
||||
"github.com/ethereum/go-ethereum/internal/utesting"
|
||||
)
|
||||
|
||||
// sendTxs sends the given transactions to the node and
|
||||
// expects the node to accept and propagate them.
|
||||
func (s *Suite) sendTxs(txs []*types.Transaction) error {
|
||||
func (s *Suite) sendTxs(t *utesting.T, txs []*types.Transaction) error {
|
||||
// Open sending conn.
|
||||
sendConn, err := s.dial()
|
||||
if err != nil {
|
||||
|
|
@ -74,6 +75,15 @@ func (s *Suite) sendTxs(txs []*types.Transaction) error {
|
|||
for _, hash := range msg.Hashes {
|
||||
got[hash] = true
|
||||
}
|
||||
case *eth.GetBlockHeadersPacket:
|
||||
headers, err := s.chain.GetHeaders(msg)
|
||||
if err != nil {
|
||||
t.Logf("invalid GetBlockHeaders request: %v", err)
|
||||
}
|
||||
recvConn.Write(ethProto, eth.BlockHeadersMsg, ð.BlockHeadersPacket{
|
||||
RequestId: msg.RequestId,
|
||||
BlockHeadersRequest: headers,
|
||||
})
|
||||
default:
|
||||
return fmt.Errorf("unexpected eth wire msg: %s", pretty.Sdump(msg))
|
||||
}
|
||||
|
|
@ -95,7 +105,7 @@ func (s *Suite) sendTxs(txs []*types.Transaction) error {
|
|||
return fmt.Errorf("timed out waiting for txs")
|
||||
}
|
||||
|
||||
func (s *Suite) sendInvalidTxs(txs []*types.Transaction) error {
|
||||
func (s *Suite) sendInvalidTxs(t *utesting.T, txs []*types.Transaction) error {
|
||||
// Open sending conn.
|
||||
sendConn, err := s.dial()
|
||||
if err != nil {
|
||||
|
|
@ -152,6 +162,15 @@ func (s *Suite) sendInvalidTxs(txs []*types.Transaction) error {
|
|||
return fmt.Errorf("received bad tx: %s", hash)
|
||||
}
|
||||
}
|
||||
case *eth.GetBlockHeadersPacket:
|
||||
headers, err := s.chain.GetHeaders(msg)
|
||||
if err != nil {
|
||||
t.Logf("invalid GetBlockHeaders request: %v", err)
|
||||
}
|
||||
recvConn.Write(ethProto, eth.BlockHeadersMsg, ð.BlockHeadersPacket{
|
||||
RequestId: msg.RequestId,
|
||||
BlockHeadersRequest: headers,
|
||||
})
|
||||
default:
|
||||
return fmt.Errorf("unexpected eth message: %v", pretty.Sdump(msg))
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue