mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-02-22 06:21:40 +01:00
itest: add GetBlockHeader to ChainKit tests
This commit is contained in:
parent
c20e4871cd
commit
c5d041f2f4
1 changed files with 44 additions and 0 deletions
|
@ -26,6 +26,7 @@ func testChainKit(ht *lntest.HarnessTest) {
|
|||
// during execution. By calling sub-test functions as seen below we
|
||||
// avoid the need to start separate nodes.
|
||||
testChainKitGetBlock(ht)
|
||||
testChainKitGetBlockHeader(ht)
|
||||
testChainKitGetBlockHash(ht)
|
||||
testChainKitSendOutputsAnchorReserve(ht)
|
||||
}
|
||||
|
@ -58,6 +59,49 @@ func testChainKitGetBlock(ht *lntest.HarnessTest) {
|
|||
require.Equal(ht, expected, actual)
|
||||
}
|
||||
|
||||
// testChainKitGetBlockHeader ensures that given a block hash, the RPC endpoint
|
||||
// returns the correct target block header.
|
||||
func testChainKitGetBlockHeader(ht *lntest.HarnessTest) {
|
||||
// Get best block hash.
|
||||
bestBlockRes := ht.Alice.RPC.GetBestBlock(nil)
|
||||
|
||||
var (
|
||||
bestBlockHash chainhash.Hash
|
||||
bestBlockHeader wire.BlockHeader
|
||||
msgBlock = &wire.MsgBlock{}
|
||||
)
|
||||
err := bestBlockHash.SetBytes(bestBlockRes.BlockHash)
|
||||
require.NoError(ht, err)
|
||||
|
||||
// Retrieve the best block by hash.
|
||||
getBlockReq := &chainrpc.GetBlockRequest{
|
||||
BlockHash: bestBlockHash[:],
|
||||
}
|
||||
getBlockRes := ht.Alice.RPC.GetBlock(getBlockReq)
|
||||
|
||||
// Deserialize the block which was retrieved by hash.
|
||||
blockReader := bytes.NewReader(getBlockRes.RawBlock)
|
||||
err = msgBlock.Deserialize(blockReader)
|
||||
require.NoError(ht, err)
|
||||
|
||||
// Retrieve the block header for the best block.
|
||||
getBlockHeaderReq := &chainrpc.GetBlockHeaderRequest{
|
||||
BlockHash: bestBlockHash[:],
|
||||
}
|
||||
getBlockHeaderRes := ht.Alice.RPC.GetBlockHeader(getBlockHeaderReq)
|
||||
|
||||
// Deserialize the block header which was retrieved by hash.
|
||||
blockHeaderReader := bytes.NewReader(getBlockHeaderRes.RawBlockHeader)
|
||||
err = bestBlockHeader.Deserialize(blockHeaderReader)
|
||||
require.NoError(ht, err)
|
||||
|
||||
// Ensure the header of the best block is the same as retrieved block
|
||||
// header.
|
||||
expected := bestBlockHeader
|
||||
actual := msgBlock.Header
|
||||
require.Equal(ht, expected, actual)
|
||||
}
|
||||
|
||||
// testChainKitGetBlockHash ensures that given a block height, the RPC endpoint
|
||||
// returns the correct target block hash.
|
||||
func testChainKitGetBlockHash(ht *lntest.HarnessTest) {
|
||||
|
|
Loading…
Add table
Reference in a new issue