Skip to content

Commit

Permalink
fix case
Browse files Browse the repository at this point in the history
fix tests

remove call_data

fix tests

solve issues with contract cases

fetch deps

install elixir first

fix set_contract

fix generate-localchain-env

use mixed case for decoding

optionally use mixed case

fix merkle tests

fix conformance tests

fix root_chain_test

install_elixir after setup_childchain

install elixir on `setup_childchain`

decode plasma framework contract address with mixed case

use mixed case for `get_block_submitted_events`

use mixed case for integration fixtures

fix deposit helper

fix block_getter tests

fix eth_test

update submodule

copy env file to the root
  • Loading branch information
ayrat555 committed Dec 7, 2020
1 parent 5b0ec8b commit 01d179f
Show file tree
Hide file tree
Showing 40 changed files with 326 additions and 140 deletions.
25 changes: 19 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,19 @@ commands:
steps:
# otherwise docker compose down errors with ERROR: Couldn't find env file
- run: touch localchain_contract_addresses.env
- restore_cache:
key: v2-asdf-install
- run:
name: Install Erlang and Elixir
command: |
[ -d ~/.asdf-vm ] || git clone https://github.com/asdf-vm/asdf.git ~/.asdf-vm --branch v0.8.0
echo 'source ~/.asdf-vm/asdf.sh' >> $BASH_ENV
source $BASH_ENV
asdf plugin-add erlang || asdf plugin-update erlang
asdf plugin-add elixir || asdf plugin-update elixir
asdf install
no_output_timeout: 2400
- run: make install-hex-rebar
- run: docker-compose down
- run: sudo rm -rf data/
- run:
Expand Down Expand Up @@ -605,6 +618,7 @@ jobs:
parallelism: 4
steps:
- checkout
- install_elixir
- run:
name: "Pull Submodules"
command: |
Expand All @@ -620,14 +634,13 @@ jobs:
name: Start daemon services
command: |
make init_test
cp ./localchain_contract_addresses.env ./priv/cabbage/apps/itest/localchain_contract_addresses.env
cp ./localchain_contract_addresses.env ./priv/cabbage/localchain_contract_addresses.env
docker-compose -f docker-compose.yml -f docker-compose.feefeed.yml -f docker-compose.specs.yml up -d || (START_RESULT=$?; docker-compose logs; exit $START_RESULT;)
- run:
name: Log daemon services
command: make cabbage-logs
background: true
- check_docker_status
- install_elixir
- run: sh .circleci/status.sh
- run:
name: Run specs
Expand All @@ -650,6 +663,7 @@ jobs:
STATIX_TAG: "env:perf_circleci"
steps:
- checkout
- install_elixir
- run:
name: Setup data dir
command: |
Expand All @@ -659,7 +673,6 @@ jobs:
- run:
name: Build perf docker image
command: make docker-perf IMAGE_NAME=$PERF_IMAGE_NAME
- install_elixir
- run:
name: Start daemon services
command: |
Expand Down Expand Up @@ -717,6 +730,7 @@ jobs:
REORG: true
steps:
- checkout
- install_elixir
- run:
name: "Pull Submodules"
command: |
Expand All @@ -734,14 +748,13 @@ jobs:
name: Start daemon services
command: |
make init_test_reorg
cp ./localchain_contract_addresses.env ./priv/cabbage/apps/itest/localchain_contract_addresses.env
cp ./localchain_contract_addresses.env ./priv/cabbage/localchain_contract_addresses.env
docker-compose -f docker-compose.yml -f docker-compose.feefeed.yml -f docker-compose.reorg.yml -f docker-compose.specs.yml up -d || (START_RESULT=$?; docker-compose logs; exit $START_RESULT;)
- run:
name: Log daemon services
command: make cabbage-logs-reorg
background: true
- check_docker_status
- install_elixir
- run: sh .circleci/status.sh
- run:
name: Print watcher logs
Expand Down Expand Up @@ -780,6 +793,7 @@ jobs:
TERM: xterm-256color
steps:
- checkout
- install_elixir
- run:
name: "Pull Submodules"
command: |
Expand All @@ -792,7 +806,6 @@ jobs:
command: make start-services
background: true
- run: echo 'export PATH=~/.cargo/bin:$PATH' >> $BASH_ENV
- install_elixir
- install_deps
- run: make install-hex-rebar
- restore_cache:
Expand Down
25 changes: 14 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -190,19 +190,22 @@ init-contracts: clean-contracts
cd data && \
tar --strip-components 1 -zxvf snapshot.tar.gz data/geth && \
tar --exclude=data/* -xvzf snapshot.tar.gz && \
AUTHORITY_ADDRESS=$$(cat plasma-contracts/build/authority_address) && \
ETH_VAULT=$$(cat plasma-contracts/build/eth_vault) && \
ERC20_VAULT=$$(cat plasma-contracts/build/erc20_vault) && \
PAYMENT_EXIT_GAME=$$(cat plasma-contracts/build/payment_exit_game) && \
PLASMA_FRAMEWORK_TX_HASH=$$(cat plasma-contracts/build/plasma_framework_tx_hash) && \
PLASMA_FRAMEWORK=$$(cat plasma-contracts/build/plasma_framework) && \
PAYMENT_EIP712_LIBMOCK=$$(cat plasma-contracts/build/paymentEip712LibMock) && \
MERKLE_WRAPPER=$$(cat plasma-contracts/build/merkleWrapper) && \
ERC20_MINTABLE=$$(cat plasma-contracts/build/erc20Mintable) && \
sh ../bin/generate-localchain-env AUTHORITY_ADDRESS=$$AUTHORITY_ADDRESS ETH_VAULT=$$ETH_VAULT \
AUTHORITY_ADDRESS=$$(cat plasma-contracts/build/authority_address) \
ETH_VAULT=$$(cat plasma-contracts/build/eth_vault) \
ERC20_VAULT=$$(cat plasma-contracts/build/erc20_vault) \
PAYMENT_EXIT_GAME=$$(cat plasma-contracts/build/payment_exit_game) \
PLASMA_FRAMEWORK_TX_HASH=$$(cat plasma-contracts/build/plasma_framework_tx_hash) \
PLASMA_FRAMEWORK=$$(cat plasma-contracts/build/plasma_framework) \
PAYMENT_EIP712_LIBMOCK=$$(cat plasma-contracts/build/paymentEip712LibMock) \
MERKLE_WRAPPER=$$(cat plasma-contracts/build/merkleWrapper) \
ERC20_MINTABLE=$$(cat plasma-contracts/build/erc20Mintable) \
ERC20_VAULT=$$ERC20_VAULT PAYMENT_EXIT_GAME=$$PAYMENT_EXIT_GAME \
PLASMA_FRAMEWORK_TX_HASH=$$PLASMA_FRAMEWORK_TX_HASH PLASMA_FRAMEWORK=$$PLASMA_FRAMEWORK \
PAYMENT_EIP712_LIBMOCK=$$PAYMENT_EIP712_LIBMOCK MERKLE_WRAPPER=$$MERKLE_WRAPPER ERC20_MINTABLE=$$ERC20_MINTABLE
PAYMENT_EIP712_LIBMOCK=$$PAYMENT_EIP712_LIBMOCK MERKLE_WRAPPER=$$MERKLE_WRAPPER ERC20_MINTABLE=$$ERC20_MINTABLE \
sh ../bin/generate-localchain-env && \
cd ../bin/eip55_normalizer && \
mix deps.get && mix run -e "Eip55Normalizer.run()" ../../localchain_contract_addresses.env


init-contracts-reorg: clean-contracts
mkdir data1/ || true && \
Expand Down
8 changes: 2 additions & 6 deletions apps/omg/lib/omg/state/core.ex
Original file line number Diff line number Diff line change
Expand Up @@ -291,20 +291,16 @@ defmodule OMG.State.Core do
def extract_exiting_utxo_positions([%{utxo_pos: _} | _] = utxo_position_events, state),
do: utxo_position_events |> Enum.map(& &1.utxo_pos) |> extract_exiting_utxo_positions(state)

# list of full exit events (from ethereum listeners)
def extract_exiting_utxo_positions([%{call_data: %{utxo_pos: _}} | _] = utxo_position_events, state),
do: utxo_position_events |> Enum.map(& &1.call_data) |> extract_exiting_utxo_positions(state)

# list of utxo positions (encoded)
def extract_exiting_utxo_positions([encoded_utxo_pos | _] = encoded_utxo_positions, %Core{})
when is_integer(encoded_utxo_pos),
do: Enum.map(encoded_utxo_positions, &Utxo.Position.decode!/1)

# list of IFE input/output piggybacked events
def extract_exiting_utxo_positions([%{call_data: %{in_flight_tx: _}} | _] = start_ife_events, %Core{}) do
def extract_exiting_utxo_positions([%{in_flight_tx: _} | _] = start_ife_events, %Core{}) do
_ = Logger.info("Recognized exits from IFE starts #{inspect(start_ife_events)}")

Enum.flat_map(start_ife_events, fn %{call_data: %{in_flight_tx: tx_bytes}} ->
Enum.flat_map(start_ife_events, fn %{in_flight_tx: tx_bytes} ->
{:ok, tx} = Transaction.decode(tx_bytes)
Transaction.get_inputs(tx)
end)
Expand Down
4 changes: 3 additions & 1 deletion apps/omg/lib/omg/typed_data_hash/config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ defmodule OMG.TypedDataHash.Config do
@spec domain_data_from_config() :: Tools.eip712_domain_t()
def domain_data_from_config() do
verifying_contract_addr =
Application.get_env(:omg_eth, :contract_addr) |> Access.get(:plasma_framework) |> Encoding.from_hex()
Application.get_env(:omg_eth, :contract_addr)
|> Access.get(:plasma_framework)
|> Encoding.from_hex(:mixed)

Application.fetch_env!(:omg, :eip_712_domain)
|> Map.new()
Expand Down
1 change: 1 addition & 0 deletions apps/omg/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ defmodule OMG.MixProject do
{:ex_rlp, "~> 0.5.3"},
{:merkle_tree, "~> 2.0.0"},
{:telemetry, "~> 0.4.1"},
{:eip_55, "~> 0.1"},
# UMBRELLA
{:omg_bus, in_umbrella: true},
{:omg_db, in_umbrella: true},
Expand Down
6 changes: 3 additions & 3 deletions apps/omg/test/omg/state/core_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ defmodule OMG.State.CoreTest do

assert utxo_pos_exits ==
utxo_pos_exits
|> Enum.map(&%{call_data: %{utxo_pos: Utxo.Position.encode(&1)}})
|> Enum.map(&%{utxo_pos: Utxo.Position.encode(&1)})
|> Core.extract_exiting_utxo_positions(state_empty)

assert utxo_pos_exits ==
Expand Down Expand Up @@ -695,7 +695,7 @@ defmodule OMG.State.CoreTest do

state = state |> Core.exec(tx, @fee) |> success?

utxo_pos_exits_in_flight = [%{call_data: %{in_flight_tx: Transaction.raw_txbytes(tx)}}]
utxo_pos_exits_in_flight = [%{in_flight_tx: Transaction.raw_txbytes(tx)}]

utxo_pos_exits_piggyback = [
%{tx_hash: Transaction.raw_txhash(tx), output_index: 0, omg_data: %{piggyback_type: :output}}
Expand Down Expand Up @@ -731,7 +731,7 @@ defmodule OMG.State.CoreTest do

tx = create_recovered([{@blknum1, 0, 0, alice}], @eth, [{alice, 2}, {alice, 3}])

utxo_pos_exits_in_flight = [%{call_data: %{in_flight_tx: Transaction.raw_txbytes(tx)}}]
utxo_pos_exits_in_flight = [%{in_flight_tx: Transaction.raw_txbytes(tx)}]
expected_position = Utxo.position(@blknum1, 0, 0)

exiting_utxos = Core.extract_exiting_utxo_positions(utxo_pos_exits_in_flight, state)
Expand Down
1 change: 0 additions & 1 deletion apps/omg/test/omg/state/transaction/fee_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ defmodule OMG.State.Transaction.FeeTest do
use ExUnitFixtures
use ExUnit.Case, async: true

alias OMG.Output
alias OMG.State.Transaction

@eth OMG.Eth.zero_address()
Expand Down
2 changes: 1 addition & 1 deletion apps/omg/test/support/integration/deposit_helper.ex
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ defmodule Support.Integration.DepositHelper do
end

def deposit_to_child_chain(to, value, token_addr) when is_binary(token_addr) and byte_size(token_addr) == 20 do
contract_addr = Encoding.from_hex(Configuration.contracts().erc20_vault)
contract_addr = Encoding.from_hex(Configuration.contracts().erc20_vault, :mixed)

{:ok, _} = Eth.Token.approve(to, contract_addr, value, token_addr) |> DevHelper.transact_sync!()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ defmodule OMG.Conformance.MerkleProofPropertyTest do

on_exit(exit_fn)

[contract: OMG.Eth.Encoding.from_hex(merkle_wrapper_address_hex)]
[contract: OMG.Eth.Encoding.from_hex(merkle_wrapper_address_hex, :mixed)]
end

property "any root hash and proof created by the Elixir implementation validates in the contract, for all leaves",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ defmodule OMG.Conformance.MerkleProofTest do

on_exit(exit_fn)

[contract: OMG.Eth.Encoding.from_hex(merkle_wrapper_address_hex)]
[contract: OMG.Eth.Encoding.from_hex(merkle_wrapper_address_hex, :mixed)]
end

test "a simple, 3-leaf merkle proof validates fine", %{contract: contract} do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ defmodule Support.Conformance.SignaturesHashesCase do
exit_fn.()
end)

[contract: OMG.Eth.Encoding.from_hex(signtest_addr_hex)]
[contract: OMG.Eth.Encoding.from_hex(signtest_addr_hex, :mixed)]
end
end
6 changes: 3 additions & 3 deletions apps/omg_eth/lib/eth.ex
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ defmodule OMG.Eth do
alias OMG.Eth.RootChain.SubmitBlock

require Logger
import OMG.Eth.Encoding, only: [from_hex: 1, to_hex: 1, int_from_hex: 1]
import OMG.Eth.Encoding, only: [from_hex: 2, to_hex: 1, int_from_hex: 1]

@type address :: <<_::160>>
@type hash :: <<_::256>>
Expand All @@ -58,8 +58,8 @@ defmodule OMG.Eth do
@spec submit_block(binary(), pos_integer(), pos_integer()) ::
{:error, binary() | atom() | map()} | {:ok, <<_::256>>}
def submit_block(hash, nonce, gas_price) do
contract = from_hex(Configuration.contracts().plasma_framework)
from = from_hex(Configuration.authority_address())
contract = from_hex(Configuration.contracts().plasma_framework, :mixed)
from = from_hex(Configuration.authority_address(), :mixed)
backend = Configuration.eth_node()
SubmitBlock.submit(backend, hash, nonce, gas_price, from, contract)
end
Expand Down
4 changes: 2 additions & 2 deletions apps/omg_eth/lib/omg_eth/encoding.ex
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ defmodule OMG.Eth.Encoding do
"""
# because https://github.com/rrrene/credo/issues/583, we need to:
# credo:disable-for-next-line Credo.Check.Consistency.SpaceAroundOperators
@spec from_hex(<<_::16, _::_*8>>) :: binary
def from_hex("0x" <> encoded), do: Base.decode16!(encoded, case: :lower)
@spec from_hex(<<_::16, _::_*8>>, atom()) :: binary
def from_hex("0x" <> encoded, format \\ :lower), do: Base.decode16!(encoded, case: format)

@doc """
Decodes to an integer, see `to_hex`
Expand Down
23 changes: 20 additions & 3 deletions apps/omg_eth/lib/omg_eth/release_tasks/set_contract.ex
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,18 @@ defmodule OMG.Eth.ReleaseTasks.SetContract do
when is_binary(txhash_contract) and
is_binary(authority_address) and is_map(contract_addresses) and is_integer(min_exit_period_seconds) and
is_binary(contract_semver) and is_binary(network) do
contract_addresses = Enum.into(contract_addresses, %{}, fn {name, addr} -> {name, String.downcase(addr)} end)
contract_addresses =
Enum.into(contract_addresses, %{}, fn {name, addr} ->
value = encode_eip55(addr)
{name, value}
end)

authority_address_formatted = encode_eip55(authority_address)

Config.Reader.merge(config,
omg_eth: [
txhash_contract: String.downcase(txhash_contract),
authority_address: String.downcase(authority_address),
txhash_contract: txhash_contract,
authority_address: authority_address_formatted,
contract_addr: contract_addresses,
min_exit_period_seconds: min_exit_period_seconds,
contract_semver: contract_semver,
Expand Down Expand Up @@ -210,4 +216,15 @@ defmodule OMG.Eth.ReleaseTasks.SetContract do
{:ok, _} = Application.ensure_all_started(:logger)
{:ok, _} = Application.ensure_all_started(:ethereumex)
end

defp encode_eip55(value) do
case value do
"" ->
""

other ->
{:ok, address} = EIP55.encode(other)
address
end
end
end
6 changes: 3 additions & 3 deletions apps/omg_eth/lib/omg_eth/root_chain.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ defmodule OMG.Eth.RootChain do
"""

require Logger
import OMG.Eth.Encoding, only: [from_hex: 1, int_from_hex: 1]
import OMG.Eth.Encoding, only: [from_hex: 2, int_from_hex: 1]

alias OMG.Eth
alias OMG.Eth.Configuration
Expand Down Expand Up @@ -56,7 +56,7 @@ defmodule OMG.Eth.RootChain do
Returns lists of block submissions from Ethereum logs
"""
def get_block_submitted_events(from_height, to_height) do
contract = from_hex(Configuration.contracts().plasma_framework)
contract = from_hex(Configuration.contracts().plasma_framework, :mixed)
signature = "BlockSubmitted(uint256)"
{:ok, logs} = Rpc.get_ethereum_events(from_height, to_height, signature, contract)

Expand Down Expand Up @@ -98,7 +98,7 @@ defmodule OMG.Eth.RootChain do
@spec get_root_deployment_height() ::
{:ok, integer()} | Ethereumex.HttpClient.error()
def get_root_deployment_height() do
plasma_framework = Configuration.contracts().plasma_framework
plasma_framework = String.downcase(Configuration.contracts().plasma_framework)
txhash = Configuration.txhash_contract()

case Ethereumex.HttpClient.eth_get_transaction_receipt(txhash) do
Expand Down
2 changes: 1 addition & 1 deletion apps/omg_eth/test/fixtures.exs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ defmodule OMG.Eth.Fixtures do

defp has_exit_queue(vault_id, token) do
plasma_framework = Configuration.contracts().plasma_framework
token = Encoding.from_hex(token)
token = Encoding.from_hex(token, :mixed)
call_contract(plasma_framework, "hasExitQueue(uint256,address)", [vault_id, token], [:bool])
end

Expand Down
2 changes: 1 addition & 1 deletion apps/omg_eth/test/omg_eth/eth_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ defmodule OMG.EthTest do
end

test "submit_block/1 submits a block to the contract" do
response = Eth.submit_block(<<234::256>>, 1, 20_000_000_000)
response = Eth.submit_block(<<234::256>>, 0, 20_000_000_000)

assert {:ok, _} = DevHelper.transact_sync!(response)
end
Expand Down
Loading

0 comments on commit 01d179f

Please sign in to comment.