-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add unit test to BeaconBlocksByRoot handler
- Loading branch information
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
defmodule Unit.P2PBlocks do | ||
Check warning on line 1 in test/unit/p2p_blocks_test.ex GitHub Actions / Lint
|
||
use ExUnit.Case, async: true | ||
use Patch | ||
|
||
alias LambdaEthereumConsensus.Store.BlockStore | ||
alias LambdaEthereumConsensus.P2P.BlockDownloader | ||
alias LambdaEthereumConsensus.Libp2pPort | ||
alias LambdaEthereumConsensus.P2P.IncomingRequests.Handler | ||
alias SszTypes.BeaconBlocksByRootRequest | ||
|
||
setup do | ||
expose(Handler, :all) | ||
end | ||
|
||
test "one block retrieve" do | ||
# | ||
signed_block_input = Fixtures.Block.signed_beacon_block() | ||
block_root = Ssz.hash_tree_root!(signed_block.message) | ||
|
||
# store the block in the BlockStore | ||
BlockStore.store_block(signed_block_input) | ||
|
||
# ssz serialize and snappy compress the block root | ||
with {:ok, ssz_serialized} <- Ssz.to_ssz(%BeaconBlocksByRootRequest{body: [block_root]}), | ||
{:ok, snappy_compressed_message} <- Snappy.compress(ssz_serialized) do | ||
# patch the Libp2pPort's send_request function to call the incoming_requests handler function we want to test | ||
patch(Libp2pPort, :send_request, fn root -> | ||
Handler.handle_req("beacon_blocks_by_root/2/ssz_snappy", 1, snappy_compressed_message) | ||
end) | ||
|
||
# call the block_downloader's request_blocks_by_root function | ||
with {:ok, signed_beacon_blocks} <- BlockDownloader.request_blocks_by_root([block_root]) do | ||
assert Enum.at(signed_beacon_blocks, 0) == signed_block_input | ||
end | ||
end | ||
end | ||
end |