From 8830785f9274e3a50a00c88acf6b0e78fc44adc1 Mon Sep 17 00:00:00 2001 From: Akash SM Date: Wed, 13 Dec 2023 19:30:13 +0530 Subject: [PATCH] fix some bugs --- ...esponse.ex => beacon_blocks_ by_root_request.ex} | 2 +- ...request.ex => beacon_blocks_by_root_response.ex} | 2 +- test/unit/p2p_blocks_test.exs | 13 ++++++++----- 3 files changed, 10 insertions(+), 7 deletions(-) rename lib/ssz_types/p2p/{beacon_blocks_ by_root_response.ex => beacon_blocks_ by_root_request.ex} (84%) rename lib/ssz_types/p2p/{beacon_blocks_by_root_request.ex => beacon_blocks_by_root_response.ex} (84%) diff --git a/lib/ssz_types/p2p/beacon_blocks_ by_root_response.ex b/lib/ssz_types/p2p/beacon_blocks_ by_root_request.ex similarity index 84% rename from lib/ssz_types/p2p/beacon_blocks_ by_root_response.ex rename to lib/ssz_types/p2p/beacon_blocks_ by_root_request.ex index ae763a9c4..efd81121f 100644 --- a/lib/ssz_types/p2p/beacon_blocks_ by_root_response.ex +++ b/lib/ssz_types/p2p/beacon_blocks_ by_root_request.ex @@ -12,6 +12,6 @@ defmodule SszTypes.BeaconBlocksByRootRequest do defstruct fields @type t :: %__MODULE__{ - body: list(SszTypes.SignedBeaconBlock.t()) + body: list(SszTypes.root()) } end diff --git a/lib/ssz_types/p2p/beacon_blocks_by_root_request.ex b/lib/ssz_types/p2p/beacon_blocks_by_root_response.ex similarity index 84% rename from lib/ssz_types/p2p/beacon_blocks_by_root_request.ex rename to lib/ssz_types/p2p/beacon_blocks_by_root_response.ex index e8c3631f7..05bbdfeac 100644 --- a/lib/ssz_types/p2p/beacon_blocks_by_root_request.ex +++ b/lib/ssz_types/p2p/beacon_blocks_by_root_response.ex @@ -12,6 +12,6 @@ defmodule SszTypes.BeaconBlocksByRootResponse do defstruct fields @type t :: %__MODULE__{ - body: list(SszTypes.root()) + body: list(SszTypes.SignedBeaconBlock.t()) } end diff --git a/test/unit/p2p_blocks_test.exs b/test/unit/p2p_blocks_test.exs index 57200fb98..32b74e56c 100644 --- a/test/unit/p2p_blocks_test.exs +++ b/test/unit/p2p_blocks_test.exs @@ -7,28 +7,31 @@ defmodule Unit.P2PBlocks do alias LambdaEthereumConsensus.Libp2pPort alias LambdaEthereumConsensus.P2P.IncomingRequests.Handler alias SszTypes.BeaconBlocksByRootRequest + alias LambdaEthereumConsensus.Store.Db setup do expose(Handler, :all) + start_supervised!(Db) + :ok end test "one block retrieve" do # signed_block_input = Fixtures.Block.signed_beacon_block() - block_root = Ssz.hash_tree_root!(signed_block.message) + block_root = Ssz.hash_tree_root!(signed_block_input.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]}), + 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 _peer_id, _protocol, _message -> - Handler.handle_req("beacon_blocks_by_root/2/ssz_snappy", 1, snappy_compressed_message) + patch(Libp2pPort, :send_request, fn _peer_id, _protocol, message -> + Handler.handle("beacon_blocks_by_root/2/ssz_snappy", 1, message) end) - patch(Libp2pPort, :send_response, fn _request_id, message -> {:ok, message} end) + patch(Libp2pPort, :send_response, fn _request_id, message -> :ok end) # call the block_downloader's request_blocks_by_root function with {:ok, signed_beacon_blocks} <- BlockDownloader.request_blocks_by_root([block_root]) do