mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-03-30 15:08:33 +00:00

* Replace BlockMessage with RpcBlock in rpc.proto. * Convert everything in kaspad to use RPCBlocks and fix tests. * Fix compilation errors in stability tests and the miner. * Update TransactionVerboseData in rpc.proto. * Update TransactionVerboseData in the rest of kaspad. * Make golint happy. * Include RpcTransactionVerboseData in RpcTransaction instead of the other way around. * Regenerate rpc.pb.go after merge. * Update appmessage types. * Update appmessage request and response types. * Reimplement conversion functions between appmessage.RPCTransaction and protowire.RpcTransaction. * Extract RpcBlockHeader toAppMessage/fromAppMessage out of RpcBlock. * Fix compilation errors in getBlock, getBlocks, and submitBlock. * Fix compilation errors in getMempoolEntry. * Fix compilation errors in notifyBlockAdded. * Update verbosedata.go. * Fix compilation errors in getBlock and getBlocks. * Fix compilation errors in getBlocks tests. * Fix conversions between getBlocks message types. * Fix integration tests. * Fix a comment. * Add selectedParent to the verbose block response.
66 lines
2.1 KiB
Go
66 lines
2.1 KiB
Go
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)
|
|
}
|
|
}
|