Skip to content

Commit

Permalink
fixes tests and Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
sudeepdino008 committed Feb 17, 2023
1 parent 303da13 commit 1813f84
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 151 deletions.
18 changes: 1 addition & 17 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,6 @@ RUN mix local.hex --force && \
# dev release (copy release to next stage from _build) [Enable once tests work in docker]
RUN mix release

#===========
#(EVM) Build Stage
#===========
FROM golang:1.19.4 as builder-evm
#RUN apk update && apk add --virtual build-dependencies build-base gcc git
RUN apt-get update && apt-get install -y build-essential && apt-get clean && rm -rf /var/lib/apt/lists/*
RUN git clone --depth 1 -b covalent https://github.com/covalenthq/erigon /erigon
WORKDIR /erigon
RUN go version
RUN mkdir -p /erigon/build/bin
RUN make evm-prod

#================
#Deployment Stage
#================
Expand All @@ -47,15 +35,14 @@ FROM elixir:1.13.4-otp-25 as deployer

RUN apt-get update && apt-get install -y git bash curl netcat-traditional && apt-get clean && rm -rf /var/lib/apt/lists/*

RUN mkdir -p /app/_build /app/config /app/deps /app/lib /app/plugins /app/priv node/test /app/test-data /app/evm-out
RUN mkdir -p /app/_build /app/config /app/deps /app/lib /app/plugins /app/priv node/test /app/test-data

# used in case alpine image are used
# RUN apk update && apk add --no-cache git=2.36.3-r0 bash=5.1.16-r2 curl=7.83.1-r4 go=1.18.7-r0 make=4.3-r0 gcc=11.2.1_git20220219-r2
WORKDIR /app
RUN mix local.hex --force
RUN mix local.rebar --force

COPY --from=builder-evm /erigon/build/bin/ /app/plugins/
COPY --from=builder-elixir /mix/_build /app/_build
COPY --from=builder-elixir /mix/config /app/config
COPY --from=builder-elixir /mix/deps /app/deps
Expand All @@ -67,9 +54,6 @@ COPY --from=builder-elixir /mix/_build/dev/rel/rudder/ /app/prod/
COPY --from=builder-elixir /mix/test/ /app/test
COPY --from=builder-elixir /mix/test-data/ /app/test-data


RUN chmod +x /app/plugins/evm

# Used only for testing in compose
# CMD [ "mix", "test", "./test/block_specimen_decoder_test.exs", "./test/block_result_uploader_test.exs"]

Expand Down
15 changes: 14 additions & 1 deletion docker-compose-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ services:
- "4001:4001"
- "3000:3000"

evm-server:
image: "gcr.io/covalent-project/evm-server:latest"
container_name: evm-server
restart: on-failure
expose:
- "3002:3002"
networks:
- cqt-net
ports:
- "3002:3002"

rudder:
image: "gcr.io/covalent-project/rudder:latest"
container_name: rudder
Expand All @@ -68,6 +79,8 @@ services:
depends_on:
ipfs-pinner:
condition: service_started
evm-server:
condition: service_started
entrypoint: >
/bin/bash -l -c "
echo "ipfs-node-address:" $IPFS_PINNER_URL;
Expand Down Expand Up @@ -95,4 +108,4 @@ services:
- cqt-net

networks:
cqt-net:
cqt-net:
3 changes: 1 addition & 2 deletions lib/rudder/block_result/block_result_uploader.ex
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,11 @@ defmodule Rudder.BlockResultUploader do
)

:ok = Events.brp_upload_failure(System.monotonic_time(:millisecond) - start_upload_ms)

{:reply, {:error, errormsg, ""}, state}

{:error, :irreparable, errormsg} ->
{:reply, {:error, :irreparable, errormsg}, state}
:ok = Events.brp_upload_failure(System.monotonic_time(:millisecond) - start_upload_ms)
{:reply, {:error, :irreparable, errormsg}, state}
end

{:error, error} ->
Expand Down
23 changes: 15 additions & 8 deletions lib/rudder/evm/block_processor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,21 @@ defmodule Rudder.BlockProcessor do

start_execute_ms = System.monotonic_time(:millisecond)

{:ok, block_result} =
GenServer.call(Rudder.BlockProcessor, {:process, block_specimen.contents}, 60_000)

block_result_path = Briefly.create!()
File.write!(block_result_path, block_result)
Events.bsp_execute(System.monotonic_time(:millisecond) - start_execute_ms)
Logger.info("writing block result into #{inspect(block_result_path)}")
{:ok, block_result_path}
case GenServer.call(Rudder.BlockProcessor, {:process, block_specimen.contents}, 60_000) do
{:ok, block_result} ->
block_result_path = Briefly.create!()
File.write!(block_result_path, block_result)
Logger.info("writing block result into #{inspect(block_result_path)}")
Events.bsp_execute(System.monotonic_time(:millisecond) - start_execute_ms)
{:ok, block_result_path}

{:error, errormsg} ->
Logger.info(
"error in executing #{block_specimen.block_height} specimen: #{inspect(errormsg)}"
)

{:error, errormsg}
end
end

@impl true
Expand Down
26 changes: 0 additions & 26 deletions lib/rudder/evm/block_processor_api.ex

This file was deleted.

16 changes: 0 additions & 16 deletions lib/rudder/evm/structs.ex

This file was deleted.

95 changes: 14 additions & 81 deletions test/evm/evm_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ defmodule SupervisionTreeTest do
use ExUnit.Case, async: false
@moduletag :spawn
require Logger
alias Rudder.BlockProcessor.Worker.Executor
alias Rudder.BlockProcessor.Struct

alias TestHelper.EVMInputGenerator
Expand All @@ -22,96 +21,30 @@ defmodule SupervisionTreeTest do

contents = get_sample_specimen!()

inp = %Struct.InputParams{block_id: block_id, contents: contents, sender: self()}
evm = Struct.EVMParams.new()

_ =
SupervisorUtils.start_link_supervised!(%{
id: "sample",
start: {Executor, :start_link, [inp, evm]},
type: :worker,
restart: :transient
})

receive do
%Struct.ExecResult{
block_id: ^block_id,
status: status,
output_path: _,
misc: nil
} ->
ExUnit.Assertions.assert(status == :success, "status is not success")

msg ->
Logger.info("unhandled message: #{inspect(msg)}")
ExUnit.Assertions.assert(false, "unhandled message")
after
3000 ->
ExUnit.Assertions.assert(false, "didn't receive status within timeout interval")
end
{:ok, filepath} = Rudder.BlockProcessor.sync_queue(contents)
File.rm(filepath)
end

test "status code !=0 execution (json cannot be unmarshalled into evm structure)" do
block_id = "1234_f_"

contents = get_sample_specimen!()
specimen = get_sample_specimen!()

inp = %Struct.InputParams{
block_id: block_id,
contents: "[" <> contents <> "]",
sender: self()
}

evm = Struct.EVMParams.new()

_ =
TestHelper.SupervisorUtils.start_link_supervised!(%{
id: "sample",
start: {Executor, :start_link, [inp, evm]},
type: :worker,
restart: :transient
{:error, errormsg} =
Rudder.BlockProcessor.sync_queue(%Rudder.BlockSpecimen{
chain_id: specimen.chain_id,
block_height: specimen.block_height,
contents: "[" <> specimen.contents <> "]"
})

receive do
%Struct.ExecResult{
block_id: ^block_id,
status: status,
output_path: _,
misc: nil
} ->
ExUnit.Assertions.assert(status != :success, "status is unexpectedly success")

msg ->
Logger.info("unhandled message: #{inspect(msg)}")
ExUnit.Assertions.assert(false, "unhandled message")
after
3000 ->
ExUnit.Assertions.assert(false, "didn't receive status within timeout interval")
end
end

test "evm executable not present" do
block_id = "1234_f_"
contents = get_sample_specimen!()

inp = %Struct.InputParams{block_id: block_id, contents: contents, sender: self()}
evm = %Struct.EVMParams{evm_exec_path: "./blahblahrandomness/evm"}

Process.flag(:trap_exit, true)

_ =
SupervisorUtils.start_link_supervised!(%{
id: "sample",
start: {Executor, :start_link, [inp, evm]},
type: :worker,
restart: :transient
})

assert_receive({:EXIT, _, _}, 3_000)
end

def get_sample_specimen!() do
path = Path.join([__DIR__, "data", "15548376-segment.json"])
File.read!(path)

%Rudder.BlockSpecimen{
chain_id: 1,
block_height: 15_548_376,
contents: File.read!(path)
}
end
end

0 comments on commit 1813f84

Please sign in to comment.