@@ -19,6 +19,7 @@ package ethtest
1919import (
2020 "fmt"
2121 "net"
22+ "strings"
2223 "time"
2324
2425 "github.com/davecgh/go-spew/spew"
@@ -84,6 +85,8 @@ func (s *Suite) AllEthTests() []utesting.Test {
8485 {Name : "Broadcast_66" , Fn : s .TestBroadcast_66 },
8586 {Name : "TestLargeAnnounce" , Fn : s .TestLargeAnnounce },
8687 {Name : "TestLargeAnnounce_66" , Fn : s .TestLargeAnnounce_66 },
88+ {Name : "TestOldAnnounce" , Fn : s .TestOldAnnounce },
89+ {Name : "TestOldAnnounce_66" , Fn : s .TestOldAnnounce_66 },
8790 // malicious handshakes + status
8891 {Name : "TestMaliciousHandshake" , Fn : s .TestMaliciousHandshake },
8992 {Name : "TestMaliciousStatus" , Fn : s .TestMaliciousStatus },
@@ -389,6 +392,36 @@ func (s *Suite) TestLargeAnnounce(t *utesting.T) {
389392 }
390393}
391394
395+ func (s * Suite ) TestOldAnnounce (t * utesting.T ) {
396+ s .oldAnnounce (t , s .setupConnection (t ), s .setupConnection (t ))
397+ }
398+
399+ func (s * Suite ) oldAnnounce (t * utesting.T , sendConn , receiveConn * Conn ) {
400+ oldBlockAnnounce := & NewBlock {
401+ Block : s .chain .blocks [len (s .chain .blocks )/ 2 ],
402+ TD : s .chain .blocks [len (s .chain .blocks )/ 2 ].Difficulty (),
403+ }
404+
405+ if err := sendConn .Write (oldBlockAnnounce ); err != nil {
406+ t .Fatalf ("could not write to connection: %v" , err )
407+ }
408+
409+ switch msg := receiveConn .ReadAndServe (s .chain , timeout * 2 ).(type ) {
410+ case * NewBlock :
411+ t .Fatalf ("unexpected: block propagated: %s" , pretty .Sdump (msg ))
412+ case * NewBlockHashes :
413+ t .Fatalf ("unexpected: block announced: %s" , pretty .Sdump (msg ))
414+ case * Error :
415+ errMsg := * msg
416+ // check to make sure error is timeout (propagation didn't come through == test successful)
417+ if ! strings .Contains (errMsg .String (), "timeout" ) {
418+ t .Fatalf ("unexpected error: %v" , pretty .Sdump (msg ))
419+ }
420+ default :
421+ t .Fatalf ("unexpected: %s" , pretty .Sdump (msg ))
422+ }
423+ }
424+
392425func (s * Suite ) testAnnounce (t * utesting.T , sendConn , receiveConn * Conn , blockAnnouncement * NewBlock ) {
393426 // Announce the block.
394427 if err := sendConn .Write (blockAnnouncement ); err != nil {
0 commit comments