cmd/devp2p: add eth66 test suite (#22363)

Co-authored-by: Martin Holst Swende <martin@swende.se>
This commit is contained in:
rene
2021-02-25 18:36:01 +01:00
committed by GitHub
parent bbfb1e4008
commit de9465f991
8 changed files with 721 additions and 27 deletions

View File

@ -30,6 +30,10 @@ var faucetKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c666
func sendSuccessfulTx(t *utesting.T, s *Suite, tx *types.Transaction) {
sendConn := s.setupConnection(t)
sendSuccessfulTxWithConn(t, s, tx, sendConn)
}
func sendSuccessfulTxWithConn(t *utesting.T, s *Suite, tx *types.Transaction, sendConn *Conn) {
t.Logf("sending tx: %v %v %v\n", tx.Hash().String(), tx.GasPrice(), tx.Gas())
// Send the transaction
if err := sendConn.Write(&Transactions{tx}); err != nil {
@ -41,20 +45,21 @@ func sendSuccessfulTx(t *utesting.T, s *Suite, tx *types.Transaction) {
switch msg := recvConn.ReadAndServe(s.chain, timeout).(type) {
case *Transactions:
recTxs := *msg
if len(recTxs) < 1 {
t.Fatalf("received transactions do not match send: %v", recTxs)
}
if tx.Hash() != recTxs[len(recTxs)-1].Hash() {
t.Fatalf("received transactions do not match send: got %v want %v", recTxs, tx)
for _, gotTx := range recTxs {
if gotTx.Hash() == tx.Hash() {
// Ok
return
}
}
t.Fatalf("missing transaction: got %v missing %v", recTxs, tx.Hash())
case *NewPooledTransactionHashes:
txHashes := *msg
if len(txHashes) < 1 {
t.Fatalf("received transactions do not match send: %v", txHashes)
}
if tx.Hash() != txHashes[len(txHashes)-1] {
t.Fatalf("wrong announcement received, wanted %v got %v", tx, txHashes)
for _, gotHash := range txHashes {
if gotHash == tx.Hash() {
return
}
}
t.Fatalf("missing transaction announcement: got %v missing %v", txHashes, tx.Hash())
default:
t.Fatalf("unexpected message in sendSuccessfulTx: %s", pretty.Sdump(msg))
}
@ -62,6 +67,10 @@ func sendSuccessfulTx(t *utesting.T, s *Suite, tx *types.Transaction) {
func sendFailingTx(t *utesting.T, s *Suite, tx *types.Transaction) {
sendConn, recvConn := s.setupConnection(t), s.setupConnection(t)
sendFailingTxWithConns(t, s, tx, sendConn, recvConn)
}
func sendFailingTxWithConns(t *utesting.T, s *Suite, tx *types.Transaction, sendConn, recvConn *Conn) {
// Wait for a transaction announcement
switch msg := recvConn.ReadAndServe(s.chain, timeout).(type) {
case *NewPooledTransactionHashes: