kaspad/integration/ibd_test.go
Ori Newman 8e170cf327
[NOD-1225] Rename wire to domainmessage and get rid of InvType (#853)
* [NOD-1225] Rename wire to domainmessage

* [NOD-1225] Get rid of references to package wire in the code, and get rid of InvType
2020-08-09 12:39:15 +03:00

52 lines
1.1 KiB
Go

package integration
import (
"sync"
"testing"
"time"
"github.com/kaspanet/kaspad/util/locks"
"github.com/kaspanet/kaspad/domainmessage"
)
func TestIBD(t *testing.T) {
const numBlocks = 100
syncer, syncee, _, teardown := standardSetup(t)
defer teardown()
for i := 0; i < numBlocks; i++ {
mineNextBlock(t, syncer)
}
blockAddedWG := sync.WaitGroup{}
blockAddedWG.Add(numBlocks)
receivedBlocks := 0
setOnBlockAddedHandler(t, syncee, func(header *domainmessage.BlockHeader) {
receivedBlocks++
blockAddedWG.Done()
})
connect(t, syncer, syncee)
select {
case <-time.After(defaultTimeout):
t.Fatalf("Timeout waiting for IBD to finish. Received %d blocks out of %d", receivedBlocks, numBlocks)
case <-locks.ReceiveFromChanWhenDone(func() { blockAddedWG.Wait() }):
}
tip1, err := syncer.rpcClient.GetSelectedTip()
if err != nil {
t.Fatalf("Error getting tip for syncer")
}
tip2, err := syncee.rpcClient.GetSelectedTip()
if err != nil {
t.Fatalf("Error getting tip for syncee")
}
if tip1.Hash != tip2.Hash {
t.Errorf("Tips of syncer: '%s' and syncee '%s' are not equal", tip1.Hash, tip2.Hash)
}
}