-
Notifications
You must be signed in to change notification settings - Fork 235
/
Copy pathbasic_sync_test.go
65 lines (53 loc) · 2.06 KB
/
basic_sync_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package integration
import (
"testing"
"time"
"github.com/kaspanet/kaspad/domain/consensus/utils/consensushashing"
"github.com/kaspanet/kaspad/app/appmessage"
)
func TestIntegrationBasicSync(t *testing.T) {
appHarness1, appHarness2, appHarness3, teardown := standardSetup(t)
defer teardown()
// Connect nodes in chain: 1 <--> 2 <--> 3
// So that node 3 doesn't directly get blocks from node 1
connect(t, appHarness1, appHarness2)
connect(t, appHarness2, appHarness3)
app2OnBlockAddedChan := make(chan *appmessage.RPCBlock)
setOnBlockAddedHandler(t, appHarness2, func(notification *appmessage.BlockAddedNotificationMessage) {
app2OnBlockAddedChan <- notification.Block
})
app3OnBlockAddedChan := make(chan *appmessage.RPCBlock)
setOnBlockAddedHandler(t, appHarness3, func(notification *appmessage.BlockAddedNotificationMessage) {
app3OnBlockAddedChan <- notification.Block
})
block := mineNextBlock(t, appHarness1)
var rpcBlock *appmessage.RPCBlock
select {
case rpcBlock = <-app2OnBlockAddedChan:
case <-time.After(defaultTimeout):
t.Fatalf("Timeout waiting for block added notification on node directly connected to miner")
}
domainBlockFromRPC, err := appmessage.RPCBlockToDomainBlock(rpcBlock)
if err != nil {
t.Fatalf("Could not convert RPC block: %s", err)
}
rpcBlockHash := consensushashing.BlockHash(domainBlockFromRPC)
blockHash := consensushashing.BlockHash(block)
if !rpcBlockHash.Equal(blockHash) {
t.Errorf("Expected block with hash '%s', but got '%s'", blockHash, rpcBlockHash)
}
select {
case rpcBlock = <-app3OnBlockAddedChan:
case <-time.After(defaultTimeout):
t.Fatalf("Timeout waiting for block added notification on node indirectly connected to miner")
}
domainBlockFromRPC, err = appmessage.RPCBlockToDomainBlock(rpcBlock)
if err != nil {
t.Fatalf("Could not convert RPC block: %s", err)
}
rpcBlockHash = consensushashing.BlockHash(domainBlockFromRPC)
blockHash = consensushashing.BlockHash(block)
if !rpcBlockHash.Equal(blockHash) {
t.Errorf("Expected block with hash '%s', but got '%s'", blockHash, rpcBlockHash)
}
}