From 62ef5f2de0576e9bbde5ccfd867fb7a9cac71319 Mon Sep 17 00:00:00 2001 From: okalouti Date: Mon, 23 Nov 2020 14:32:34 +0700 Subject: [PATCH 01/14] refactor blockchain action buttons and remove Metamask logic --- .../BlockchainActionSelector.tsx | 105 ++++++++++++++++ .../HotWalletTransferChooser.js | 115 ----------------- .../index.js | 119 +++++++++++------- 3 files changed, 176 insertions(+), 163 deletions(-) create mode 100644 apps/frontend/assets/src/omg-page-blockchain-wallet-detail/BlockchainActionSelector.tsx delete mode 100644 apps/frontend/assets/src/omg-page-blockchain-wallet-detail/HotWalletTransferChooser.js diff --git a/apps/frontend/assets/src/omg-page-blockchain-wallet-detail/BlockchainActionSelector.tsx b/apps/frontend/assets/src/omg-page-blockchain-wallet-detail/BlockchainActionSelector.tsx new file mode 100644 index 000000000..c495bc8f5 --- /dev/null +++ b/apps/frontend/assets/src/omg-page-blockchain-wallet-detail/BlockchainActionSelector.tsx @@ -0,0 +1,105 @@ +import React from 'react' +import { useDispatch } from 'react-redux' +import styled from 'styled-components' + +import PopperRenderer from 'omg-popper' +import withDropdownState from 'omg-uikit/dropdown/withDropdownState' +import { openModal } from 'omg-modal/action' +import { Icon, Button } from 'omg-uikit' +import { DropdownBox } from 'omg-uikit/dropdown' + +const DropdownItem = styled.div` + padding: 7px 10px; + padding-right: 20px; + font-size: 12px; + color: ${props => props.theme.colors.B100}; + cursor: pointer; + i, + span { + vertical-align: middle; + display: inline-block; + } + :hover { + color: ${props => props.theme.colors.B400}; + } + i { + margin-right: 5px; + } +` +const ButtonStyle = styled(Button)` + margin-left: 10px; + i { + margin-left: 10px; + margin-right: 0 !important; + } +` + +interface BlockchainActionSelectorProps { + name: string + onClickButton: React.MouseEventHandler + open: boolean + actions: Array<{ + name: string + modal: { id: string; args: {} } + icon: string + }> + fromAddress: string +} + +const BlockchainActionSelector = ({ + name, + actions, + open, + onClickButton, + fromAddress +}: BlockchainActionSelectorProps) => { + const dispatch = useDispatch() + + const renderDropdown = () => { + return ( + + {actions.map((action, index) => { + const onClick = () => + dispatch( + openModal({ + id: action.modal.id, + fromAddress, + ...action.modal.args + }) + ) + return ( + + + {action.name} + + ) + })} + + ) + } + + const renderButton = () => { + return ( + + {name} + {open ? : } + + ) + } + + return ( + + ) +} + +export default withDropdownState(BlockchainActionSelector) diff --git a/apps/frontend/assets/src/omg-page-blockchain-wallet-detail/HotWalletTransferChooser.js b/apps/frontend/assets/src/omg-page-blockchain-wallet-detail/HotWalletTransferChooser.js deleted file mode 100644 index 73f16c0ba..000000000 --- a/apps/frontend/assets/src/omg-page-blockchain-wallet-detail/HotWalletTransferChooser.js +++ /dev/null @@ -1,115 +0,0 @@ -import React, { Component } from 'react' -import { connect } from 'react-redux' -import PropTypes from 'prop-types' -import styled from 'styled-components' -import { compose } from 'recompose' - -import PopperRenderer from '../omg-popper' -import { openModal } from '../omg-modal/action' -import withDropdownState from '../omg-uikit/dropdown/withDropdownState' -import { Icon, Button } from '../omg-uikit' -import { DropdownBox } from '../omg-uikit/dropdown' - -const DropdownItem = styled.div` - padding: 7px 10px; - padding-right: 20px; - font-size: 12px; - color: ${props => props.theme.colors.B100}; - cursor: pointer; - i, - span { - vertical-align: middle; - display: inline-block; - } - :hover { - color: ${props => props.theme.colors.B400}; - } - i { - margin-right: 5px; - } -` -const ButtonStyle = styled(Button)` - margin-left: 10px; - i { - margin-left: 10px; - margin-right: 0 !important; - } -` -class HotWalletTransferChooser extends Component { - static propTypes = { - open: PropTypes.bool, - onClickButton: PropTypes.func, - onDepositComplete: PropTypes.func, - openModal: PropTypes.func, - fromAddress: PropTypes.string, - isColdWallet: PropTypes.bool - } - renderDropdown = () => { - return ( - - {this.props.isColdWallet && ( - { - this.props.openModal({ - id: 'hotWalletTransferModal', - fromAddress: this.props.fromAddress - }) - }} - > - - Transfer to Cold Wallet - - )} - this.props.openModal({ - id: 'plasmaDepositModal', - fromAddress: this.props.fromAddress, - onDepositComplete: this.props.onDepositComplete - })} - > - - OMG Network Deposit - - - ) - } - renderButton = () => { - return ( - - Transfer - {this.props.open - ? - : - } - - ) - } - render () { - return ( - - ) - } -} - -const enhance = compose( - withDropdownState, - connect( - null, - { openModal } - ) -) - -export default enhance(HotWalletTransferChooser) diff --git a/apps/frontend/assets/src/omg-page-blockchain-wallet-detail/index.js b/apps/frontend/assets/src/omg-page-blockchain-wallet-detail/index.js index 72f82b27e..e50ff41fb 100644 --- a/apps/frontend/assets/src/omg-page-blockchain-wallet-detail/index.js +++ b/apps/frontend/assets/src/omg-page-blockchain-wallet-detail/index.js @@ -1,23 +1,22 @@ import React, { useEffect, useState } from 'react' import PropTypes from 'prop-types' import { Route, Switch, Redirect } from 'react-router-dom' -import { connect, useSelector, useDispatch } from 'react-redux' +import { connect } from 'react-redux' -import { Button } from '../omg-uikit' -import { enableMetamaskEthereumConnection } from '../omg-web3/action' -import { selectMetamaskUsable } from '../omg-web3/selector' import { selectBlockchainWallets, selectBlockchainWalletBalance, selectBlockchainWalletById, selectPlasmaDepositByAddress } from '../omg-blockchain-wallet/selector' -import { getAllBlockchainWallets, getBlockchainWalletBalance } from '../omg-blockchain-wallet/action' -import CreateBlockchainTransactionButton from '../omg-transaction/CreateBlockchainTransactionButton' +import { + getAllBlockchainWallets, + getBlockchainWalletBalance +} from '../omg-blockchain-wallet/action' import TopNavigation from '../omg-page-layout/TopNavigation' import { getTransactionById } from '../omg-transaction/action' -import HotWalletTransferChooser from './HotWalletTransferChooser' +import BlockchainActionSelector from './BlockchainActionSelector' import BlockchainSettingsPage from './BlockchainSettingsPage' import BlockchainTransactionsPage from './BlockchainTransactionsPage' import BlockchainTokensPage from './BlockchainTokensPage' @@ -34,12 +33,12 @@ const BlockchainWalletDetailPage = ({ ...rest }) => { const { address } = match.params - const dispatch = useDispatch() - const metamaskUsable = useSelector(selectMetamaskUsable) - const balance = selectBlockchainWalletBalance(address) - .reduce((acc, curr) => acc + curr.amount, 0) + + const balance = selectBlockchainWalletBalance(address).reduce( + (acc, curr) => acc + curr.amount, + 0 + ) const walletType = selectBlockchainWalletById(address).type - const isColdWallet = !!selectBlockchainWallets.filter(i => i.type === 'cold').length const [pollingState, setPollingState] = useState(false) @@ -56,8 +55,12 @@ const BlockchainWalletDetailPage = ({ if (pollingState) { const pollBalance = async () => { try { - const { id: depositTransactionId } = selectPlasmaDepositByAddress(address) - const { data: { status } } = await getTransactionById(depositTransactionId) + const { id: depositTransactionId } = selectPlasmaDepositByAddress( + address + ) + const { + data: { status } + } = await getTransactionById(depositTransactionId) if (status === 'confirmed') { getBlockchainWalletBalance({ @@ -77,58 +80,78 @@ const BlockchainWalletDetailPage = ({ const balancePolling = setInterval(pollBalance, 2000) return () => clearInterval(balancePolling) } - }, [address, getBlockchainWalletBalance, getTransactionById, pollingState, selectPlasmaDepositByAddress]) + }, [ + address, + getBlockchainWalletBalance, + getTransactionById, + pollingState, + selectPlasmaDepositByAddress + ]) - const renderTopupButton = () => ( - - ) + const renderActionButtons = () => { + const ethereumActions = [ + { + name: 'Transfer to Cold Wallet', + modal: { id: 'hotWalletTransferModal' }, + icon: 'Transaction' + } + ] - const renderMetamaskConnectButton = () => ( - - ) + const plasmaActions = [ + { + name: 'Deposit to the OMG Network', + modal: { + id: 'plasmaDepositModal', + args: { onDepositComplete: () => setPollingState(true) } + }, + icon: 'Download' + } + ] - const renderActionButton = () => { if (walletType === 'hot' && balance > 0) { return ( - setPollingState(true)} - /> + <> + + + ) } - if (metamaskUsable) { - return balance ? renderTopupButton() : null - } - return renderMetamaskConnectButton() } return ( <> - - - + + + From 6459902f54a3e9204feb76d7c09e4245ceaf2f12 Mon Sep 17 00:00:00 2001 From: okalouti Date: Tue, 24 Nov 2020 09:15:32 +0700 Subject: [PATCH 02/14] pull mederic-p/plasma-deposit --- .circleci/config.yml | 19 ++ .tool-versions | 3 +- Dockerfile | 3 + .../blockchain_wallet_controller_test.exs | 103 +++++----- .../lib/eth_blockchain/abi_encoder.ex | 10 +- .../lib/eth_blockchain/childchain.ex | 34 +--- .../lib/eth_blockchain/token.ex | 2 +- .../lib/eth_blockchain/transaction.ex | 33 +-- apps/eth_blockchain/mix.exs | 2 +- .../eth_blockchain/adapter_server_test.exs | 18 +- .../test/eth_blockchain/childchain_test.exs | 192 +++++++++--------- .../test/eth_blockchain/transaction_test.exs | 81 ++++---- .../test/support/dumb_cc_adapter.ex | 16 +- apps/eth_geth_adapter/mix.exs | 2 +- .../lib/eth_omisego_adapter/transaction.ex | 75 +------ apps/eth_omisego_adapter/mix.exs | 6 +- .../eth_omisego_adapter/transaction_test.exs | 20 +- .../test/support/eth_omisego_adapter_case.ex | 9 +- apps/eth_omisego_adapter/test/test_helper.exs | 2 +- .../gates/transactions/blockchain_gate.ex | 35 +++- .../gates/transactions/childchain_gate.ex | 56 +++-- .../childchain_transaction_gate_test.exs | 136 ++++++------- apps/ewallet/test/support/db_case.ex | 5 +- apps/ewallet_config/config/config.exs | 10 +- mix.lock | 10 +- 25 files changed, 443 insertions(+), 439 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index af066b567..e85a16678 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -145,12 +145,31 @@ commands: name: Attach workspace at: ~/ + add_rust_to_path: + description: "Add path to PATH env var" + steps: + - run: + name: Add rust to PATH env + command: echo 'export PATH=~/.cargo/bin/:$PATH' >> $BASH_ENV + - run: + name: Export flags + command: echo 'export RUSTFLAGS="-C target-feature=-crt-static"' >> $BASH_ENV + + install_rust: + description: "Install Rust" + steps: + - run: + name: Install Rust + command: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y + - add_rust_to_path + jobs: build: executor: builder steps: - checkout + - install_rust - run: | mkdir -p ~/var elixir --version | tee ~/var/elixir-version diff --git a/.tool-versions b/.tool-versions index 55fcb9c94..a578dc5b6 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,2 +1,3 @@ elixir 1.8.1 -erlang 21.0 \ No newline at end of file +erlang 21.0 +rust 1.46.0 \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 22baa4722..58cd3e352 100644 --- a/Dockerfile +++ b/Dockerfile @@ -31,6 +31,9 @@ RUN apk add --update --no-cache --virtual .ewallet-runtime \ libressl \ libressl-dev \ lksctp-tools + +# ex_keccak +RUN apk add --no-cache rust=1.44.0-r0 cargo=1.44.0-r0 COPY rootfs / diff --git a/apps/admin_api/test/admin_api/v1/controllers/blockchain_wallet_controller_test.exs b/apps/admin_api/test/admin_api/v1/controllers/blockchain_wallet_controller_test.exs index 511d7661e..38956a2b9 100644 --- a/apps/admin_api/test/admin_api/v1/controllers/blockchain_wallet_controller_test.exs +++ b/apps/admin_api/test/admin_api/v1/controllers/blockchain_wallet_controller_test.exs @@ -61,58 +61,57 @@ defmodule AdminAPI.V1.BlockchainWalletControllerTest do end end - # TODO: update these tests when fixing deposits - # describe "/blockchain_wallet.deposit_to_childchain" do - # test_with_auths "deposit to childchain with the given attributes" do - # identifier = BlockchainHelper.rootchain_identifier() - # hot_wallet = BlockchainWallet.get_primary_hot_wallet(identifier) - - # token = - # insert(:external_blockchain_token, - # blockchain_address: "0x0000000000000000000000000000000000000000" - # ) - - # adapter = BlockchainHelper.adapter() - # {:ok, _adapter_pid} = adapter.server().start_link([]) - - # attrs = %{ - # token_id: token.id, - # amount: 100, - # address: hot_wallet.address, - # idempotency_token: UUID.generate() - # } - - # response = request("/blockchain_wallet.deposit_to_childchain", attrs) - - # assert response["success"] - # assert response["data"]["blockchain_transaction"] != nil - # assert response["data"]["type"] == "deposit" - - # transaction = Transaction.get(response["data"]["id"], preload: :blockchain_transaction) - # {:ok, pid} = BlockchainTransactionTracker.lookup(transaction.blockchain_transaction_uuid) - - # {:ok, %{pid: blockchain_listener_pid}} = - # adapter.lookup_listener(transaction.blockchain_transaction.hash) - - # on_exit(fn -> - # :ok = GenServer.stop(pid) - # :ok = GenServer.stop(blockchain_listener_pid) - # end) - # end - - # test_with_auths "fails to deposit with a missing address" do - # token = insert(:token, blockchain_address: "0x0000000000000000000000000000000000000000") - - # response = - # request("/blockchain_wallet.deposit_to_childchain", %{ - # token_id: token.id, - # amount: 100 - # }) - - # refute response["success"] - # assert response["data"]["code"] == "client:invalid_parameter" - # end - # end + describe "/blockchain_wallet.deposit_to_childchain" do + test_with_auths "deposit to childchain with the given attributes" do + identifier = BlockchainHelper.rootchain_identifier() + hot_wallet = BlockchainWallet.get_primary_hot_wallet(identifier) + + token = + insert(:external_blockchain_token, + blockchain_address: "0x0000000000000000000000000000000000000000" + ) + + adapter = BlockchainHelper.adapter() + {:ok, _adapter_pid} = adapter.server().start_link([]) + + attrs = %{ + token_id: token.id, + amount: 100, + address: hot_wallet.address, + idempotency_token: UUID.generate() + } + + response = request("/blockchain_wallet.deposit_to_childchain", attrs) + + assert response["success"] + assert response["data"]["blockchain_transaction"] != nil + assert response["data"]["type"] == "deposit" + + transaction = Transaction.get(response["data"]["id"], preload: :blockchain_transaction) + {:ok, pid} = BlockchainTransactionTracker.lookup(transaction.blockchain_transaction_uuid) + + {:ok, %{pid: blockchain_listener_pid}} = + adapter.lookup_listener(transaction.blockchain_transaction.hash) + + on_exit(fn -> + :ok = GenServer.stop(pid) + :ok = GenServer.stop(blockchain_listener_pid) + end) + end + + test_with_auths "fails to deposit with a missing address" do + token = insert(:token, blockchain_address: "0x0000000000000000000000000000000000000000") + + response = + request("/blockchain_wallet.deposit_to_childchain", %{ + token_id: token.id, + amount: 100 + }) + + refute response["success"] + assert response["data"]["code"] == "client:invalid_parameter" + end + end describe "/blockchain_wallet.get" do test_with_auths "returns a wallet when given an existing blockchain wallet address" do diff --git a/apps/eth_blockchain/lib/eth_blockchain/abi_encoder.ex b/apps/eth_blockchain/lib/eth_blockchain/abi_encoder.ex index 6ff8da7c1..e34138481 100644 --- a/apps/eth_blockchain/lib/eth_blockchain/abi_encoder.ex +++ b/apps/eth_blockchain/lib/eth_blockchain/abi_encoder.ex @@ -48,22 +48,18 @@ defmodule EthBlockchain.ABIEncoder do end def encode_erc20_attrs(name, symbol, decimals, initial_amount) do - [{name, symbol, decimals, initial_amount}] + [name, symbol, decimals, initial_amount] |> TypeEncoder.encode(%FunctionSelector{ function: nil, - types: [{:tuple, [:string, :string, {:uint, 8}, {:uint, 256}]}] + types: [:string, :string, {:uint, 8}, {:uint, 256}] }) |> Base.encode16(case: :lower) end - def child_chain_eth_deposit(tx_bytes) do + def child_chain_deposit(tx_bytes) do {:ok, ABI.encode("deposit(bytes)", [tx_bytes])} end - def child_chain_erc20_deposit(tx_bytes) do - {:ok, ABI.encode("depositFrom(bytes)", [tx_bytes])} - end - def mint("0x" <> _ = address, amount) do {:ok, ABI.encode("mint(address,uint)", [ diff --git a/apps/eth_blockchain/lib/eth_blockchain/childchain.ex b/apps/eth_blockchain/lib/eth_blockchain/childchain.ex index eca741aa3..518b99995 100644 --- a/apps/eth_blockchain/lib/eth_blockchain/childchain.ex +++ b/apps/eth_blockchain/lib/eth_blockchain/childchain.ex @@ -37,43 +37,21 @@ defmodule EthBlockchain.Childchain do opts \\ [] ) do with :ok <- check_childchain(childchain_identifier), - # TODO: this is broken with new config, :get_contract_address does not exist anymore, - # need to use the eth or erc20 vaults instead - # (:get_childchain_eth_vault_address or :get_childchain_erc20_vault_address) - {:ok, contract_address} <- AdapterServer.childchain_call({:get_contract_address}, opts), {:ok, tx_bytes} <- AdapterServer.childchain_call({:get_deposit_tx_bytes, to, amount, currency}, opts) do - submit_deposit(tx_bytes, to, amount, currency, contract_address, opts) + submit_deposit(tx_bytes, to, amount, currency, opts) end end - defp submit_deposit(tx_bytes, to, amount, @eth, root_chain_contract, opts) do - Transaction.deposit_eth( - %{tx_bytes: tx_bytes, from: to, amount: amount, root_chain_contract: root_chain_contract}, - opts - ) + defp submit_deposit(tx_bytes, to, amount, @eth, opts) do + Transaction.deposit_eth(%{tx_bytes: tx_bytes, from: to, amount: amount}, opts) end - defp submit_deposit(tx_bytes, to, amount, erc20, root_chain_contract, opts) do + defp submit_deposit(tx_bytes, to, amount, erc20, opts) do with {:ok, _attrs} <- - Transaction.approve_erc20( - %{ - from: to, - to: root_chain_contract, - amount: amount, - contract_address: erc20 - }, - opts - ), + Transaction.approve_erc20(%{from: to, amount: amount, contract_address: erc20}, opts), {:ok, _attrs} = response <- - Transaction.deposit_erc20( - %{ - tx_bytes: tx_bytes, - from: to, - root_chain_contract: root_chain_contract - }, - opts - ) do + Transaction.deposit_erc20(%{tx_bytes: tx_bytes, from: to}, opts) do response end end diff --git a/apps/eth_blockchain/lib/eth_blockchain/token.ex b/apps/eth_blockchain/lib/eth_blockchain/token.ex index 8816c9ecd..923bbea49 100644 --- a/apps/eth_blockchain/lib/eth_blockchain/token.ex +++ b/apps/eth_blockchain/lib/eth_blockchain/token.ex @@ -74,7 +74,7 @@ defmodule EthBlockchain.Token do end defp parse_response({:ok, "0x" <> data}, _field, _opts) do - [{str}] = decode_abi(data, [{:tuple, [:string]}]) + [str] = decode_abi(data, [:string]) {:ok, str} end diff --git a/apps/eth_blockchain/lib/eth_blockchain/transaction.ex b/apps/eth_blockchain/lib/eth_blockchain/transaction.ex index 2101b6ce5..3e2af3000 100644 --- a/apps/eth_blockchain/lib/eth_blockchain/transaction.ex +++ b/apps/eth_blockchain/lib/eth_blockchain/transaction.ex @@ -152,21 +152,22 @@ defmodule EthBlockchain.Transaction do end @doc """ - Submit a deposit eth transaction to the specified root chain contract + Submit a deposit eth transaction """ def deposit_eth( %{ tx_bytes: tx_bytes, from: from, - amount: amount, - root_chain_contract: root_chain_contract + amount: amount } = attrs, opts \\ [] ) do - with {:ok, meta} <- get_transaction_meta(attrs, :child_chain_deposit_eth, opts), - {:ok, encoded_abi_data} <- ABIEncoder.child_chain_eth_deposit(tx_bytes) do + with {:ok, vault_contract} <- + AdapterServer.childchain_call({:get_eth_vault_address}, opts), + {:ok, meta} <- get_transaction_meta(attrs, :child_chain_deposit_eth, opts), + {:ok, encoded_abi_data} <- ABIEncoder.child_chain_deposit(tx_bytes) do %__MODULE__{ - to: from_hex(root_chain_contract), + to: from_hex(vault_contract), data: encoded_abi_data, value: amount } @@ -176,20 +177,21 @@ defmodule EthBlockchain.Transaction do end @doc """ - Submit a deposit transaction of an ERC20 token to the specified root chain contract + Submit a deposit transaction of an ERC20 token """ def deposit_erc20( %{ tx_bytes: tx_bytes, - from: from, - root_chain_contract: root_chain_contract + from: from } = attrs, opts \\ [] ) do - with {:ok, meta} <- get_transaction_meta(attrs, :child_chain_deposit_token, opts), - {:ok, encoded_abi_data} <- ABIEncoder.child_chain_erc20_deposit(tx_bytes) do + with {:ok, vault_contract} <- + AdapterServer.childchain_call({:get_erc20_vault_address}, opts), + {:ok, meta} <- get_transaction_meta(attrs, :child_chain_deposit_token, opts), + {:ok, encoded_abi_data} <- ABIEncoder.child_chain_deposit(tx_bytes) do %__MODULE__{ - to: from_hex(root_chain_contract), + to: from_hex(vault_contract), data: encoded_abi_data } |> prepare_and_send(meta, from, opts) @@ -203,14 +205,15 @@ defmodule EthBlockchain.Transaction do def approve_erc20( %{ from: from, - to: to, amount: amount, contract_address: contract_address } = attrs, opts \\ [] ) do - with {:ok, meta} <- get_transaction_meta(attrs, :contract_transaction, opts), - {:ok, encoded_abi_data} <- ABIEncoder.approve(to, amount) do + with {:ok, vault_contract} <- + AdapterServer.childchain_call({:get_erc20_vault_address}, opts), + {:ok, meta} <- get_transaction_meta(attrs, :contract_transaction, opts), + {:ok, encoded_abi_data} <- ABIEncoder.approve(vault_contract, amount) do %__MODULE__{ to: from_hex(contract_address), data: encoded_abi_data diff --git a/apps/eth_blockchain/mix.exs b/apps/eth_blockchain/mix.exs index 3701e1595..c9f6f65c6 100644 --- a/apps/eth_blockchain/mix.exs +++ b/apps/eth_blockchain/mix.exs @@ -33,7 +33,7 @@ defmodule EthBlockchain.MixProject do [ {:exth_crypto, "~> 0.1.6"}, {:deferred_config, "~> 0.1.0"}, - {:ex_rlp, "~> 0.5.2"}, + {:ex_rlp, "~> 0.5.3"}, {:utils, in_umbrella: true}, {:keychain, in_umbrella: true}, {:ewallet_config, in_umbrella: true}, diff --git a/apps/eth_blockchain/test/eth_blockchain/adapter_server_test.exs b/apps/eth_blockchain/test/eth_blockchain/adapter_server_test.exs index d841fb91d..af0d73f36 100644 --- a/apps/eth_blockchain/test/eth_blockchain/adapter_server_test.exs +++ b/apps/eth_blockchain/test/eth_blockchain/adapter_server_test.exs @@ -74,39 +74,39 @@ defmodule EthBlockchain.AdapterServerTest do end describe "childchain_call/2" do - test "delegates get_childchain_framework_address call to the adapter", state do + test "delegates get_framework_address call to the adapter", state do dumb_resp1 = AdapterServer.childchain_call( - {:get_childchain_framework_address}, + {:get_framework_address}, state[:adapter_opts] ) dumb_resp2 = AdapterServer.childchain_call( - {:get_childchain_framework_address}, + {:get_framework_address}, state[:adapter_opts] ) - assert {:ok, "0xa72c9dceeef26c9d103d55c53d411c36f5cdf7ec"} == dumb_resp1 - assert {:ok, "0xa72c9dceeef26c9d103d55c53d411c36f5cdf7ec"} == dumb_resp2 + assert {:ok, "0xc673e4ffcb8464faff908a6804fe0e635af0ea2f"} == dumb_resp1 + assert {:ok, "0xc673e4ffcb8464faff908a6804fe0e635af0ea2f"} == dumb_resp2 end test "shutdowns the worker once finished handling tasks", state do {:ok, _} = AdapterServer.childchain_call( - {:get_childchain_framework_address}, + {:get_framework_address}, state[:adapter_opts] ) {:ok, _} = AdapterServer.childchain_call( - {:get_childchain_framework_address}, + {:get_framework_address}, state[:adapter_opts] ) {:ok, _} = AdapterServer.childchain_call( - {:get_childchain_framework_address}, + {:get_framework_address}, state[:adapter_opts] ) @@ -117,7 +117,7 @@ defmodule EthBlockchain.AdapterServerTest do test "returns an error if no such adapter is registered", state do assert {:error, :no_handler} == AdapterServer.childchain_call( - {:get_childchain_framework_address}, + {:get_framework_address}, cc_node_adapter: :foobar, cc_node_adapter_pid: state[:adapter_opts][:cc_node_adapter_pid] ) diff --git a/apps/eth_blockchain/test/eth_blockchain/childchain_test.exs b/apps/eth_blockchain/test/eth_blockchain/childchain_test.exs index 79a167fae..b389a9297 100644 --- a/apps/eth_blockchain/test/eth_blockchain/childchain_test.exs +++ b/apps/eth_blockchain/test/eth_blockchain/childchain_test.exs @@ -34,104 +34,100 @@ defmodule EthBlockchain.ChildchainTest do |> Map.put(:adapter_opts, overwritten_opts) end - # TODO: update these test when fixing deposits - - # describe "deposit/2" do - # test "submits an eth deposit transaction to ethereum", state do - # address = state[:valid_sender] - # amount = 100 - # currency = @eth - - # {res, encoded_trx} = - # Childchain.deposit( - # %{ - # to: address, - # amount: amount, - # currency: currency, - # childchain_identifier: :omisego_network - # }, - # state[:adapter_opts] - # ) - - # assert res == :ok - - # {:ok, tx_bytes} = - # AdapterServer.childchain_call( - # {:get_deposit_tx_bytes, address, amount, currency}, - # state[:adapter_opts] - # ) - - # {:ok, encoded_abi_data} = ABIEncoder.child_chain_eth_deposit(tx_bytes) - - # # TODO: :get_contract_adress does not exit anymore, deposits need to be made to vaults - # {:ok, contract_address} = - # AdapterServer.childchain_call({:get_contract_address}, state[:adapter_opts]) - - # trx = decode_transaction_response(encoded_trx) - # sender_public_key = recover_public_key(trx) - - # assert trx.data == encoded_abi_data - # assert to_hex(sender_public_key) == "0x" <> state[:public_key] - # assert trx.gas_limit == GasHelper.get_gas_limit_or_default(:child_chain_deposit_eth, %{}) - # assert trx.gas_price == Application.get_env(:eth_blockchain, :blockchain_default_gas_price) - # assert trx.value == amount - # assert to_hex(trx.to) == contract_address - # end - - # test "submits an erc20 deposit transaction to ethereum", state do - # address = state[:valid_sender] - # amount = 100 - # currency = Crypto.fake_eth_address() - - # {res, encoded_trx} = - # Childchain.deposit( - # %{ - # to: address, - # amount: amount, - # currency: currency, - # childchain_identifier: :omisego_network - # }, - # state[:adapter_opts] - # ) - - # assert res == :ok - - # {:ok, tx_bytes} = - # AdapterServer.childchain_call( - # {:get_deposit_tx_bytes, address, amount, currency}, - # state[:adapter_opts] - # ) - - # {:ok, encoded_abi_data} = ABIEncoder.child_chain_erc20_deposit(tx_bytes) - - # # TODO: :get_contract_adress does not exit anymore, deposits need to be made to vaults - # {:ok, contract_address} = - # AdapterServer.childchain_call({:get_contract_address}, state[:adapter_opts]) - - # trx = decode_transaction_response(encoded_trx) - # sender_public_key = recover_public_key(trx) - - # assert trx.data == encoded_abi_data - # assert to_hex(sender_public_key) == "0x" <> state[:public_key] - # assert trx.gas_limit == GasHelper.get_gas_limit_or_default(:child_chain_deposit_token, %{}) - # assert trx.gas_price == Application.get_env(:eth_blockchain, :blockchain_default_gas_price) - # assert trx.value == 0 - # assert to_hex(trx.to) == contract_address - # end - - # test "returns an error when given an invalid childchain identifier", state do - # {res, error} = - # Childchain.deposit(%{ - # to: state[:valid_sender], - # amount: 100, - # currency: @eth, - # childchain_identifier: :invalid - # }) - - # assert res == :error - # assert error == :childchain_not_supported - # end - # end + describe "deposit/2" do + test "submits an eth deposit transaction to ethereum", state do + address = state[:valid_sender] + amount = 100 + currency = @eth + + {res, encoded_trx} = + Childchain.deposit( + %{ + to: address, + amount: amount, + currency: currency, + childchain_identifier: :omisego_network + }, + state[:adapter_opts] + ) + + assert res == :ok + + {:ok, tx_bytes} = + AdapterServer.childchain_call( + {:get_deposit_tx_bytes, address, amount, currency}, + state[:adapter_opts] + ) + + {:ok, encoded_abi_data} = ABIEncoder.child_chain_deposit(tx_bytes) + + {:ok, vault_address} = + AdapterServer.childchain_call({:get_eth_vault_address}, state[:adapter_opts]) + + trx = decode_transaction_response(encoded_trx) + sender_public_key = recover_public_key(trx) + + assert trx.data == encoded_abi_data + assert to_hex(sender_public_key) == "0x" <> state[:public_key] + assert trx.gas_limit == GasHelper.get_gas_limit_or_default(:child_chain_deposit_eth, %{}) + assert trx.gas_price == Application.get_env(:eth_blockchain, :blockchain_default_gas_price) + assert trx.value == amount + assert to_hex(trx.to) == vault_address + end + + test "submits an erc20 deposit transaction to ethereum", state do + address = state[:valid_sender] + amount = 100 + currency = Crypto.fake_eth_address() + + {res, encoded_trx} = + Childchain.deposit( + %{ + to: address, + amount: amount, + currency: currency, + childchain_identifier: :omisego_network + }, + state[:adapter_opts] + ) + + assert res == :ok + + {:ok, tx_bytes} = + AdapterServer.childchain_call( + {:get_deposit_tx_bytes, address, amount, currency}, + state[:adapter_opts] + ) + + {:ok, encoded_abi_data} = ABIEncoder.child_chain_deposit(tx_bytes) + + {:ok, vault_address} = + AdapterServer.childchain_call({:get_erc20_vault_address}, state[:adapter_opts]) + + trx = decode_transaction_response(encoded_trx) + sender_public_key = recover_public_key(trx) + + assert trx.data == encoded_abi_data + assert to_hex(sender_public_key) == "0x" <> state[:public_key] + assert trx.gas_limit == GasHelper.get_gas_limit_or_default(:child_chain_deposit_token, %{}) + assert trx.gas_price == Application.get_env(:eth_blockchain, :blockchain_default_gas_price) + assert trx.value == 0 + assert to_hex(trx.to) == vault_address + end + + test "returns an error when given an invalid childchain identifier", state do + {res, error} = + Childchain.deposit(%{ + to: state[:valid_sender], + amount: 100, + currency: @eth, + childchain_identifier: :invalid + }) + + assert res == :error + assert error == :childchain_not_supported + end + end describe "send/2" do test "successfuly submit a transfer transaction to the childchain", state do diff --git a/apps/eth_blockchain/test/eth_blockchain/transaction_test.exs b/apps/eth_blockchain/test/eth_blockchain/transaction_test.exs index f744ec441..dda729e9b 100644 --- a/apps/eth_blockchain/test/eth_blockchain/transaction_test.exs +++ b/apps/eth_blockchain/test/eth_blockchain/transaction_test.exs @@ -15,7 +15,7 @@ defmodule EthBlockchain.TransactionTest do use EthBlockchain.EthBlockchainCase, async: true - alias EthBlockchain.{GasHelper, Transaction, ABIEncoder, NonceRegistry} + alias EthBlockchain.{AdapterServer, GasHelper, Transaction, ABIEncoder, NonceRegistry} alias ExthCrypto.Math alias Keychain.Wallet alias Utils.Helpers.Encoding @@ -349,68 +349,70 @@ defmodule EthBlockchain.TransactionTest do %{ tx_bytes: tx_bytes, from: state[:valid_sender], - amount: amount, - root_chain_contract: state[:addr_1] + amount: amount }, state[:adapter_opts] ) assert resp == :ok - {:ok, encoded_abi_data} = ABIEncoder.child_chain_eth_deposit(tx_bytes) + {:ok, encoded_abi_data} = ABIEncoder.child_chain_deposit(tx_bytes) trx = decode_transaction_response(encoded_trx) sender_public_key = recover_public_key(trx) + {:ok, expected_vault_address} = + AdapterServer.childchain_call({:get_eth_vault_address}, state[:adapter_opts]) + assert trx.data == encoded_abi_data assert Encoding.to_hex(sender_public_key) == "0x" <> state[:public_key] assert trx.gas_limit == GasHelper.get_gas_limit_or_default(:child_chain_deposit_eth, %{}) assert trx.gas_price == Application.get_env(:eth_blockchain, :blockchain_default_gas_price) assert trx.value == amount - assert Encoding.to_hex(trx.to) == state[:addr_1] + assert Encoding.to_hex(trx.to) == expected_vault_address end end - # TODO: fix update this test when fixing deposit - # describe "deposit_erc20/2" do - # test "generates a desposit transaction for erc20 currency", state do - # tx_bytes = "0x01" - - # {resp, encoded_trx} = - # Transaction.deposit_erc20( - # %{ - # tx_bytes: tx_bytes, - # from: state[:valid_sender], - # root_chain_contract: state[:addr_1] - # }, - # state[:adapter_opts] - # ) - - # assert resp == :ok - - # {:ok, encoded_abi_data} = ABIEncoder.child_chain_erc20_deposit(tx_bytes) - - # trx = decode_transaction_response(encoded_trx) - # sender_public_key = recover_public_key(trx) - - # assert trx.data == encoded_abi_data - # assert Encoding.to_hex(sender_public_key) == "0x" <> state[:public_key] - # assert trx.gas_limit == GasHelper.get_gas_limit_or_default(:child_chain_deposit_token, %{}) - # assert trx.gas_price == Application.get_env(:eth_blockchain, :blockchain_default_gas_price) - # assert trx.value == 0 - # assert Encoding.to_hex(trx.to) == state[:addr_1] - # end - # end + describe "deposit_erc20/2" do + test "generates a desposit transaction for erc20 currency", state do + tx_bytes = "0x01" + + {resp, encoded_trx} = + Transaction.deposit_erc20( + %{ + tx_bytes: tx_bytes, + from: state[:valid_sender] + }, + state[:adapter_opts] + ) + + assert resp == :ok + + {:ok, encoded_abi_data} = ABIEncoder.child_chain_deposit(tx_bytes) + + trx = decode_transaction_response(encoded_trx) + sender_public_key = recover_public_key(trx) + + {:ok, expected_vault_address} = + AdapterServer.childchain_call({:get_erc20_vault_address}, state[:adapter_opts]) + + assert trx.data == encoded_abi_data + assert Encoding.to_hex(sender_public_key) == "0x" <> state[:public_key] + assert trx.gas_limit == GasHelper.get_gas_limit_or_default(:child_chain_deposit_token, %{}) + assert trx.gas_price == Application.get_env(:eth_blockchain, :blockchain_default_gas_price) + assert trx.value == 0 + assert Encoding.to_hex(trx.to) == expected_vault_address + end + end describe "approve_erc20/2" do - test "generates a desposit transaction for erc20 currency", state do + test "generates an approve transaction", state do amount = 100 {resp, encoded_trx} = Transaction.approve_erc20( %{ from: state[:valid_sender], - to: state[:addr_1], amount: amount, contract_address: state[:addr_2] }, @@ -419,7 +421,10 @@ defmodule EthBlockchain.TransactionTest do assert resp == :ok - {:ok, encoded_abi_data} = ABIEncoder.approve(state[:addr_1], amount) + {:ok, vault_contract} = + AdapterServer.childchain_call({:get_erc20_vault_address}, state[:adapter_opts]) + + {:ok, encoded_abi_data} = ABIEncoder.approve(vault_contract, amount) trx = decode_transaction_response(encoded_trx) sender_public_key = recover_public_key(trx) diff --git a/apps/eth_blockchain/test/support/dumb_cc_adapter.ex b/apps/eth_blockchain/test/support/dumb_cc_adapter.ex index 7b05fd2dc..4018c0f95 100644 --- a/apps/eth_blockchain/test/support/dumb_cc_adapter.ex +++ b/apps/eth_blockchain/test/support/dumb_cc_adapter.ex @@ -32,20 +32,20 @@ defmodule EthBlockchain.DumbCCAdapter do state} end - def handle_call({:get_childchain_framework_address}, _from, state) do - {:reply, {:ok, "0xa72c9dceeef26c9d103d55c53d411c36f5cdf7ec"}, state} + def handle_call({:get_framework_address}, _from, state) do + {:reply, {:ok, "0xc673e4ffcb8464faff908a6804fe0e635af0ea2f"}, state} end - def handle_call({:get_childchain_eth_vault_address}, _from, state) do - {:reply, {:ok, "0x2c7533f76567241341d1c27f0f239a20b6115714"}, state} + def handle_call({:get_eth_vault_address}, _from, state) do + {:reply, {:ok, "0x4e3aeff70f022a6d4cc5947423887e7152826cf7"}, state} end - def handle_call({:get_childchain_erc20_vault_address}, _from, state) do - {:reply, {:ok, "0x2bed2ff4ee93a208edbf4185c7813103d8c4ab7f"}, state} + def handle_call({:get_erc20_vault_address}, _from, state) do + {:reply, {:ok, "0x135505d9f4ea773dd977de3b2b108f2dae67b63a"}, state} end - def handle_call({:get_childchain_payment_exit_game_address}, _from, state) do - {:reply, {:ok, "0x960ca6b9faa85118ba6badbe0097b1afd8827fac"}, state} + def handle_call({:get_payment_exit_game_address}, _from, state) do + {:reply, {:ok, "0x89afce326e7da55647d22e24336c6a2816c99f6b"}, state} end def handle_call({:get_errors}, _from, state) do diff --git a/apps/eth_geth_adapter/mix.exs b/apps/eth_geth_adapter/mix.exs index 8539c26ae..5ef6719d6 100644 --- a/apps/eth_geth_adapter/mix.exs +++ b/apps/eth_geth_adapter/mix.exs @@ -30,7 +30,7 @@ defmodule EthGethAdapter.MixProject do {:ewallet_config, in_umbrella: true}, {:deferred_config, "~> 0.1.0"}, {:ethereumex, "~> 0.5"}, - {:ex_abi, "0.2.1"}, + {:ex_abi, "0.5.1"}, # Tests {:exexec, git: "https://github.com/pthomalla/exexec.git", branch: "add_streams", runtime: true, only: [:test]} ] diff --git a/apps/eth_omisego_adapter/lib/eth_omisego_adapter/transaction.ex b/apps/eth_omisego_adapter/lib/eth_omisego_adapter/transaction.ex index 11d7df9fc..864c3e60d 100644 --- a/apps/eth_omisego_adapter/lib/eth_omisego_adapter/transaction.ex +++ b/apps/eth_omisego_adapter/lib/eth_omisego_adapter/transaction.ex @@ -19,34 +19,25 @@ defmodule EthOmiseGOAdapter.Transaction do import Utils.Helpers.Encoding alias EthOmiseGOAdapter.HTTPClient + alias ExPlasma.Builder alias Keychain.Signature @eth "0x0000000000000000000000000000000000000000" - @max_inputs 4 - @max_outputs 4 - - defstruct [:inputs, :outputs] @doc """ - Creates a new transaction from a list of inputs and a list of outputs. - Adds empty (zeroes) inputs and/or outputs to reach the expected size - of `@max_inputs` inputs and `@max_outputs` outputs. - - assumptions: - ``` - length(inputs) <= @max_inputs - length(outputs) <= @max_outputs - ``` + Creates an encoded deposit transaction given an address, amount and currency. Returns {:ok, tx_bytes} """ @spec get_deposit_tx_bytes(Sting.t(), integer(), String.t()) :: {:ok, String.t()} def get_deposit_tx_bytes(address, amount, currency) do - tx_bytes = - [] - |> new([{from_hex(address), from_hex(currency), amount}]) - |> encode() - - {:ok, tx_bytes} + ExPlasma.payment_v1() + |> Builder.new() + |> Builder.add_output( + output_guard: from_hex(address), + token: from_hex(currency), + amount: amount + ) + |> ExPlasma.encode(signed: false) end @doc """ @@ -144,52 +135,6 @@ defmodule EthOmiseGOAdapter.Transaction do |> HTTPClient.post_request("transaction.submit_typed") end - defp new(inputs, outputs) - when length(inputs) <= @max_inputs and length(outputs) <= @max_outputs do - inputs = - Enum.map(inputs, fn {blknum, txindex, oindex} -> - %{blknum: blknum, txindex: txindex, oindex: oindex} - end) - - inputs = - inputs ++ - List.duplicate(%{blknum: 0, txindex: 0, oindex: 0}, @max_inputs - Kernel.length(inputs)) - - outputs = - Enum.map(outputs, fn {owner, currency, amount} -> - %{owner: owner, currency: currency, amount: amount} - end) - - outputs = - outputs ++ - List.duplicate( - %{owner: from_hex(@eth), currency: from_hex(@eth), amount: 0}, - @max_outputs - Kernel.length(outputs) - ) - - %__MODULE__{inputs: inputs, outputs: outputs} - end - - defp encode(%__MODULE__{} = transaction) do - transaction - |> get_data_for_rlp() - |> ExRLP.encode() - end - - defp get_data_for_rlp(%__MODULE__{inputs: inputs, outputs: outputs}) do - [ - # contract expects 4 inputs and outputs - Enum.map(inputs, fn %{blknum: blknum, txindex: txindex, oindex: oindex} -> - [blknum, txindex, oindex] - end) ++ - List.duplicate([0, 0, 0], 4 - length(inputs)), - Enum.map(outputs, fn %{owner: owner, currency: currency, amount: amount} -> - [owner, currency, amount] - end) ++ - List.duplicate([from_hex(@eth), from_hex(@eth), 0], 4 - length(outputs)) - ] - end - defp respond_submit({:ok, %{"blknum" => blknum, "txindex" => txindex, "txhash" => txhash}}) do {:ok, %{block_number: blknum, transaction_index: txindex, transaction_hash: txhash}} end diff --git a/apps/eth_omisego_adapter/mix.exs b/apps/eth_omisego_adapter/mix.exs index a41b37927..a31606d64 100644 --- a/apps/eth_omisego_adapter/mix.exs +++ b/apps/eth_omisego_adapter/mix.exs @@ -19,7 +19,8 @@ defmodule EthOmiseGOAdapter.MixProject do # Run "mix help compile.app" to learn about applications. def application do [ - extra_applications: [:logger] + extra_applications: [:logger], + mod: {EthOmiseGOAdapter.Application, []} ] end @@ -30,9 +31,10 @@ defmodule EthOmiseGOAdapter.MixProject do {:keychain, in_umbrella: true}, {:ewallet_config, in_umbrella: true}, {:deferred_config, "~> 0.1.0"}, - {:ex_rlp, "~> 0.5.2"}, + {:ex_rlp, "~> 0.5.3"}, {:jason, "~> 1.1"}, {:httpoison, "~> 1.4.0"}, + {:ex_plasma, git: "https://github.com/omgnetwork/ex_plasma.git", ref: "0336be01bea7b4aeb5b7fbd75edcbe4ad0d1c69f"}, {:plug_cowboy, "~> 1.0", only: [:dev]} ] end diff --git a/apps/eth_omisego_adapter/test/eth_omisego_adapter/transaction_test.exs b/apps/eth_omisego_adapter/test/eth_omisego_adapter/transaction_test.exs index e8822c75e..d5dbb4d0b 100644 --- a/apps/eth_omisego_adapter/test/eth_omisego_adapter/transaction_test.exs +++ b/apps/eth_omisego_adapter/test/eth_omisego_adapter/transaction_test.exs @@ -39,13 +39,21 @@ defmodule EthOmiseGOAdapter.TransactionTest do {:ok, deposit_bytes} = Transaction.get_deposit_tx_bytes(address, amount, currency) expected_transaction = [ - [[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]], + <<1>>, + [], [ - [from_hex(address), from_hex(currency), 100], - [from_hex(@eth), from_hex(@eth), 0], - [from_hex(@eth), from_hex(@eth), 0], - [from_hex(@eth), from_hex(@eth), 0] - ] + [ + <<1>>, + [ + from_hex(address), + from_hex(currency), + amount + ] + ] + ], + "", + <<0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0>> ] assert deposit_bytes == ExRLP.encode(expected_transaction) diff --git a/apps/eth_omisego_adapter/test/support/eth_omisego_adapter_case.ex b/apps/eth_omisego_adapter/test/support/eth_omisego_adapter_case.ex index b4e400e0b..c9120322c 100644 --- a/apps/eth_omisego_adapter/test/support/eth_omisego_adapter_case.ex +++ b/apps/eth_omisego_adapter/test/support/eth_omisego_adapter_case.ex @@ -43,10 +43,11 @@ defmodule EthOmiseGOAdapter.EthOmiseGOAdapterCase do EWalletConfig.Repo, [:eth_omisego_adapter], %{ - "omisego_plasma_framework_address" => "0xa72c9dceeef26c9d103d55c53d411c36f5cdf7ec", - "omisego_eth_vault_address" => "0x2c7533f76567241341d1c27f0f239a20b6115714", - "omisego_erc20_vault_address" => "0x2bed2ff4ee93a208edbf4185c7813103d8c4ab7f", - "omisego_payment_exit_game_address" => "0x960ca6b9faa85118ba6badbe0097b1afd8827fac", + "omisego_rootchain_contract_address" => "0x316d3e9d574e91fd272fd24fb5cb7dfd4707a571", + "omisego_plasma_framework_address" => "0xc673e4ffcb8464faff908a6804fe0e635af0ea2f", + "omisego_eth_vault_address" => "0x4e3aeff70f022a6d4cc5947423887e7152826cf7", + "omisego_erc20_vault_address" => "0x135505d9f4ea773dd977de3b2b108f2dae67b63a", + "omisego_payment_exit_game_address" => "0x89afce326e7da55647d22e24336c6a2816c99f6b", "omisego_childchain_url" => "http://localhost:8082", "omisego_watcher_url" => "http://localhost:8081" } diff --git a/apps/eth_omisego_adapter/test/test_helper.exs b/apps/eth_omisego_adapter/test/test_helper.exs index d5d32ed95..d0013b34c 100644 --- a/apps/eth_omisego_adapter/test/test_helper.exs +++ b/apps/eth_omisego_adapter/test/test_helper.exs @@ -5,5 +5,5 @@ children = [ {Plug.Cowboy, scheme: :http, plug: EthOmiseGOAdapter.MockServer, options: [port: 8081]} ] -opts = [strategy: :one_for_one, name: EthOmiseGOAdapter.Supervisor] +opts = [strategy: :one_for_one, name: EthOmiseGOAdapter.MockSupervisor] {:ok, _pid} = Supervisor.start_link(children, opts) diff --git a/apps/ewallet/lib/ewallet/gates/transactions/blockchain_gate.ex b/apps/ewallet/lib/ewallet/gates/transactions/blockchain_gate.ex index ded3e0e14..7a12be8fb 100644 --- a/apps/ewallet/lib/ewallet/gates/transactions/blockchain_gate.ex +++ b/apps/ewallet/lib/ewallet/gates/transactions/blockchain_gate.ex @@ -43,6 +43,7 @@ defmodule EWallet.TransactionGate.Blockchain do @deposit_transaction Transaction.deposit() @rootchain_identifier BlockchainHelper.rootchain_identifier() + @token_cofirmed EWalletDB.Token.Blockchain.status_confirmed() # TODO: Check if blockchain is enabled # TODO: Check if blockchain is available @@ -155,6 +156,8 @@ defmodule EWallet.TransactionGate.Blockchain do {:error, :invalid_parameter, "Invalid parameter provided. `idempotency_token` is required."} end + def validate_blockchain_token(token), do: do_validate_token(token) + defp set_blockchain_addresses(attrs, hot_wallet, true) do attrs |> Map.put("from", attrs["from_address"]) @@ -176,8 +179,8 @@ defmodule EWallet.TransactionGate.Blockchain do # TODO: add check for blockchain token status with {:ok, %{from_token: from_token}, %{to_token: to_token}} <- TokenFetcher.fetch(attrs, %{}, %{}), - true <- - is_binary(from_token.blockchain_address) || {:error, :token_not_blockchain_enabled}, + :ok <- validate_blockchain_token(from_token), + :ok <- validate_blockchain_token(to_token), true <- from_token.uuid == to_token.uuid || {:error, :blockchain_exchange_not_allowed} do attrs |> Map.put("from_token_uuid", from_token.uuid) @@ -189,20 +192,30 @@ defmodule EWallet.TransactionGate.Blockchain do end end - defp enough_funds?( - %{"childchain_identifier" => _, "from_blockchain_address" => address} = attrs - ) do + defp do_validate_token(%{blockchain_address: nil}), do: {:error, :token_not_blockchain_enabled} + defp do_validate_token(%{blockchain_status: @token_cofirmed}), do: :ok + defp do_validate_token(%{blockchain_status: _}), do: {:error, :token_not_confirmed} + defp do_validate_token(%{blockchain_identifier: @rootchain_identifier}), do: :ok + defp do_validate_token(%{blockchain_identifier: _}), do: {:error, :rootchain_not_supported} + + defp enough_funds?(%{"type" => @deposit_transaction} = attrs) do + check_rootchain_funds(attrs) + end + + defp enough_funds?(%{"childchain_identifier" => _} = attrs) do + check_childchain_funds(attrs) + end + + defp enough_funds?(attrs), do: check_rootchain_funds(attrs) + + defp check_childchain_funds(%{"from_blockchain_address" => address} = attrs) do :get_childchain_balance |> BlockchainHelper.call(%{address: address}) |> process_balance_response(attrs) end - defp enough_funds?( - %{ - "rootchain_identifier" => _, - "from_blockchain_address" => address, - "from_token" => token - } = attrs + defp check_rootchain_funds( + %{"from_blockchain_address" => address, "from_token" => token} = attrs ) do :get_balances |> BlockchainHelper.call(%{ diff --git a/apps/ewallet/lib/ewallet/gates/transactions/childchain_gate.ex b/apps/ewallet/lib/ewallet/gates/transactions/childchain_gate.ex index 5d39cb612..779caa764 100644 --- a/apps/ewallet/lib/ewallet/gates/transactions/childchain_gate.ex +++ b/apps/ewallet/lib/ewallet/gates/transactions/childchain_gate.ex @@ -17,13 +17,20 @@ defmodule EWallet.TransactionGate.Childchain do This is an intermediary module that formats the params so they can be processed by the TransactionGate.Blockchain """ - alias EWallet.{TransactionGate, BlockchainHelper} + alias EWallet.{TokenFetcher, TransactionGate, BlockchainHelper} alias EWalletDB.Transaction + @eth BlockchainHelper.adapter().helper().default_token().address + def deposit(actor, %{"amount" => amount} = attrs) when is_integer(amount) do - attrs = build_transaction_attrs(attrs) - validation_tuple = address_validation_tuple(attrs) - TransactionGate.Blockchain.create(actor, attrs, validation_tuple) + case build_transaction_attrs(attrs) do + {:ok, attrs} -> + validation_tuple = address_validation_tuple(attrs) + TransactionGate.Blockchain.create(actor, attrs, validation_tuple) + + error -> + error + end end def deposit(_, _) do @@ -31,16 +38,37 @@ defmodule EWallet.TransactionGate.Childchain do end defp build_transaction_attrs(%{"address" => address} = attrs) do - # this doesn't exist anymore with ALD and need to be replaced with call to the vaults - {:ok, contract_address} = BlockchainHelper.call(:get_childchain_contract_address) - - attrs - |> Map.put("from_address", address) - |> Map.put("to_address", contract_address) - |> Map.delete("address") - |> Map.put("type", Transaction.deposit()) - |> Map.put("rootchain_identifier", BlockchainHelper.rootchain_identifier()) - |> Map.put("childchain_identifier", BlockchainHelper.childchain_identifier()) + case get_vault_address(attrs) do + {:ok, contract_address} -> + {:ok, + attrs + |> Map.put("from_address", address) + |> Map.put("to_address", contract_address) + |> Map.delete("address") + |> Map.put("type", Transaction.deposit()) + |> Map.put("rootchain_identifier", BlockchainHelper.rootchain_identifier()) + |> Map.put("childchain_identifier", BlockchainHelper.childchain_identifier())} + + error -> + error + end + end + + defp get_vault_address(attrs) do + with {:ok, token} <- TokenFetcher.fetch(attrs), + :ok <- TransactionGate.Blockchain.validate_blockchain_token(token) do + vault_address_for_token(token) + else + error -> error + end + end + + defp vault_address_for_token(%{blockchain_address: @eth}) do + BlockchainHelper.call(:get_childchain_eth_vault_address) + end + + defp vault_address_for_token(_) do + BlockchainHelper.call(:get_childchain_erc20_vault_address) end defp address_validation_tuple(attrs) do diff --git a/apps/ewallet/test/ewallet/gates/transactions/childchain_transaction_gate_test.exs b/apps/ewallet/test/ewallet/gates/transactions/childchain_transaction_gate_test.exs index 9b1bc49fd..782d45397 100644 --- a/apps/ewallet/test/ewallet/gates/transactions/childchain_transaction_gate_test.exs +++ b/apps/ewallet/test/ewallet/gates/transactions/childchain_transaction_gate_test.exs @@ -26,72 +26,72 @@ defmodule EWallet.TransactionGate.ChildchainTest do alias Ecto.UUID alias ActivityLogger.System - # TODO: Update this test when fixing deposit - # describe "deposit/2" do - # test "formats and forward attributes to the blockchain gate", meta do - # # TODO: switch to using the seeded Ethereum address - # admin = insert(:admin, global_role: "super_admin") - - # primary_blockchain_token = - # insert(:token, blockchain_address: "0x0000000000000000000000000000000000000000") - - # rootchain_identifier = BlockchainHelper.rootchain_identifier() - # hot_wallet = BlockchainWallet.get_primary_hot_wallet(rootchain_identifier) - - # attrs = %{ - # "idempotency_token" => UUID.generate(), - # "address" => hot_wallet.address, - # "token_id" => primary_blockchain_token.id, - # "amount" => 1, - # "originator" => %System{} - # } - - # {:ok, transaction} = TransactionGate.Childchain.deposit(admin, attrs) - - # # this doesn't exist anymore with ALD and need to be replaced with call to the vaults - # {:ok, contract_address} = BlockchainHelper.call(:get_childchain_contract_address) - - # assert transaction.status == TransactionState.blockchain_submitted() - # assert transaction.type == Transaction.deposit() - # assert transaction.blockchain_transaction.rootchain_identifier == rootchain_identifier - # assert transaction.blockchain_transaction.childchain_identifier == nil - # assert transaction.from_blockchain_address == hot_wallet.address - # assert transaction.to_blockchain_address == contract_address - - # {:ok, pid} = BlockchainTransactionTracker.lookup(transaction.blockchain_transaction_uuid) - - # {:ok, %{pid: blockchain_listener_pid}} = - # meta[:adapter].lookup_listener(transaction.blockchain_transaction.hash) - - # # to update the transactions after the test is done. - # on_exit(fn -> - # :ok = GenServer.stop(pid) - # :ok = GenServer.stop(blockchain_listener_pid) - # end) - # end - - # test "returns an error if the amount is not an integer" do - # admin = insert(:admin, global_role: "super_admin") - - # primary_blockchain_token = - # insert(:token, blockchain_address: "0x0000000000000000000000000000000000000000") - - # rootchain_identifier = BlockchainHelper.rootchain_identifier() - - # hot_wallet = BlockchainWallet.get_primary_hot_wallet(rootchain_identifier) - - # attrs = %{ - # "idempotency_token" => UUID.generate(), - # "address" => hot_wallet.address, - # "token_id" => primary_blockchain_token.id, - # "amount" => "1", - # "originator" => %System{} - # } - - # {res, code, error} = TransactionGate.Childchain.deposit(admin, attrs) - # assert res == :error - # assert code == :invalid_parameter - # assert error == "Invalid parameter provided. `amount` is required." - # end - # end + describe "deposit/2" do + test "formats and forward attributes to the blockchain gate", meta do + admin = insert(:admin, global_role: "super_admin") + + primary_blockchain_token = + insert(:token, + blockchain_status: "confirmed", + blockchain_address: "0x0000000000000000000000000000000000000000" + ) + + rootchain_identifier = BlockchainHelper.rootchain_identifier() + hot_wallet = BlockchainWallet.get_primary_hot_wallet(rootchain_identifier) + + attrs = %{ + "idempotency_token" => UUID.generate(), + "address" => hot_wallet.address, + "token_id" => primary_blockchain_token.id, + "amount" => 1, + "originator" => %System{} + } + + {:ok, transaction} = TransactionGate.Childchain.deposit(admin, attrs) + + {:ok, vault_address} = BlockchainHelper.call(:get_childchain_eth_vault_address) + + assert transaction.status == TransactionState.blockchain_submitted() + assert transaction.type == Transaction.deposit() + assert transaction.blockchain_transaction.rootchain_identifier == rootchain_identifier + assert transaction.blockchain_transaction.childchain_identifier == nil + assert transaction.from_blockchain_address == hot_wallet.address + assert transaction.to_blockchain_address == vault_address + + {:ok, pid} = BlockchainTransactionTracker.lookup(transaction.blockchain_transaction_uuid) + + {:ok, %{pid: blockchain_listener_pid}} = + meta[:adapter].lookup_listener(transaction.blockchain_transaction.hash) + + # to update the transactions after the test is done. + on_exit(fn -> + :ok = GenServer.stop(pid) + :ok = GenServer.stop(blockchain_listener_pid) + end) + end + + test "returns an error if the amount is not an integer" do + admin = insert(:admin, global_role: "super_admin") + + primary_blockchain_token = + insert(:token, blockchain_address: "0x0000000000000000000000000000000000000000") + + rootchain_identifier = BlockchainHelper.rootchain_identifier() + + hot_wallet = BlockchainWallet.get_primary_hot_wallet(rootchain_identifier) + + attrs = %{ + "idempotency_token" => UUID.generate(), + "address" => hot_wallet.address, + "token_id" => primary_blockchain_token.id, + "amount" => "1", + "originator" => %System{} + } + + {res, code, error} = TransactionGate.Childchain.deposit(admin, attrs) + assert res == :error + assert code == :invalid_parameter + assert error == "Invalid parameter provided. `amount` is required." + end + end end diff --git a/apps/ewallet/test/support/db_case.ex b/apps/ewallet/test/support/db_case.ex index 542006a02..80ae736b7 100644 --- a/apps/ewallet/test/support/db_case.ex +++ b/apps/ewallet/test/support/db_case.ex @@ -77,7 +77,7 @@ defmodule EWallet.DBCase do self(), config_pid, EWalletConfig.Repo, - [:ewallet_db, :ewallet], + [:ewallet_db, :ewallet, :eth_blockchain], %{ "enable_standalone" => false, "base_url" => "http://localhost:4000", @@ -89,7 +89,8 @@ defmodule EWallet.DBCase do "blockchain_state_save_interval" => 5, "blockchain_sync_interval" => 50, "blockchain_poll_interval" => 0, - "blockchain_deposit_pooling_interval" => 0 + "blockchain_deposit_pooling_interval" => 0, + "blockchain_transaction_poll_interval" => 50 } ) diff --git a/apps/ewallet_config/config/config.exs b/apps/ewallet_config/config/config.exs index 54ac0e387..0cc3d804a 100644 --- a/apps/ewallet_config/config/config.exs +++ b/apps/ewallet_config/config/config.exs @@ -213,35 +213,35 @@ config :ewallet_config, }, "omisego_watcher_url" => %{ key: "omisego_watcher_url", - value: "http://localhost:7434", + value: "http://localhost:7534", type: "string", position: 211, description: "The url used by the eWallet to interact with the OmiseGO Network's watcher." }, "omisego_plasma_framework_address" => %{ key: "omisego_plasma_framework_address", - value: "0xa72c9dceeef26c9d103d55c53d411c36f5cdf7ec", + value: "0xc673e4ffcb8464faff908a6804fe0e635af0ea2f", type: "string", position: 212, description: "The contract address of the deployed plasma framework." }, "omisego_eth_vault_address" => %{ key: "omisego_eth_vault_address", - value: "0x2c7533f76567241341d1c27f0f239a20b6115714", + value: "0x4e3aeff70f022a6d4cc5947423887e7152826cf7", type: "string", position: 213, description: "The contract address of the deployed ETH vault." }, "omisego_erc20_vault_address" => %{ key: "omisego_erc20_vault_address", - value: "0x2bed2ff4ee93a208edbf4185c7813103d8c4ab7f", + value: "0x135505d9f4ea773dd977de3b2b108f2dae67b63a", type: "string", position: 214, description: "The contract address of the deployed ERC20 vault." }, "omisego_payment_exit_game_address" => %{ key: "omisego_payment_exit_game_address", - value: "0x960ca6b9faa85118ba6badbe0097b1afd8827fac", + value: "0x89afce326e7da55647d22e24336c6a2816c99f6b", type: "string", position: 215, description: "The contract address of the deployed payment exit game." diff --git a/mix.lock b/mix.lock index aa130f43c..c1a545a0f 100644 --- a/mix.lock +++ b/mix.lock @@ -36,12 +36,15 @@ "erlex": {:hex, :erlex, "0.2.4", "23791959df45fe8f01f388c6f7eb733cc361668cbeedd801bf491c55a029917b", [:mix], [], "hexpm", "4a12ebc7cd8f24f2d0fce93d279fa34eb5068e0e885bb841d558c4d83c52c439"}, "erlexec": {:hex, :erlexec, "1.10.0", "cba7924cf526097d2082ceb0ec34e7db6bca2624b8f3867fb3fa89c4cf25d227", [:rebar3], [], "hexpm", "54901b6e565f4cb4d0de36532d3653d351a3d7bf700bcbe2cf6f242a434ade2f"}, "ethereumex": {:hex, :ethereumex, "0.5.3", "a1783a759692d9ca473e5f8afb5c2d8b6cfb1a89a6a8f779171d3a2840ada615", [:mix], [{:httpoison, "~> 1.4.0", [hex: :httpoison, repo: "hexpm", optional: false]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: false]}, {:poolboy, "~> 1.5.1", [hex: :poolboy, repo: "hexpm", optional: false]}], "hexpm", "89de028e8fcee223b5bf3b7200ac8101bc4237a17e45fe86d8d2372885024fcd"}, - "ex_abi": {:hex, :ex_abi, "0.2.1", "e8224ef22782b58d535bf3e29e73379af48df52cc9a941746980d14b32e793c2", [:mix], [{:exth_crypto, "~> 0.1.6", [hex: :exth_crypto, repo: "hexpm", optional: false]}], "hexpm", "4c5bd9852c9d6c56c9900c197d4859544b652ecbc8fbc90baf83303e2b588df5"}, + "ex_abi": {:hex, :ex_abi, "0.5.1", "e12373d4511de65c8c7e40011fa40ac05bda687de819eb0f41fc36d4e96e7b04", [:mix], [{:ex_keccak, "~> 0.1.2", [hex: :ex_keccak, repo: "hexpm", optional: false]}], "hexpm", "a2d8b8030cb6af03e69dba7395b1929422d7cb15b8275d89844c2495acf9da1f"}, "ex_aws": {:hex, :ex_aws, "2.1.0", "b92651527d6c09c479f9013caa9c7331f19cba38a650590d82ebf2c6c16a1d8a", [:mix], [{:configparser_ex, "~> 2.0", [hex: :configparser_ex, repo: "hexpm", optional: true]}, {:hackney, "1.6.3 or 1.6.5 or 1.7.1 or 1.8.6 or ~> 1.9", [hex: :hackney, repo: "hexpm", optional: true]}, {:jsx, "~> 2.8", [hex: :jsx, repo: "hexpm", optional: true]}, {:poison, ">= 1.2.0", [hex: :poison, repo: "hexpm", optional: true]}, {:sweet_xml, "~> 0.6", [hex: :sweet_xml, repo: "hexpm", optional: true]}, {:xml_builder, "~> 0.1.0", [hex: :xml_builder, repo: "hexpm", optional: true]}], "hexpm", "4223b096805cf3fc7b1af766d5039d2945cc82f9794094fdced49a721864956d"}, "ex_aws_s3": {:hex, :ex_aws_s3, "2.0.1", "9e09366e77f25d3d88c5393824e613344631be8db0d1839faca49686e99b6704", [:mix], [{:ex_aws, "~> 2.0", [hex: :ex_aws, repo: "hexpm", optional: false]}, {:sweet_xml, ">= 0.0.0", [hex: :sweet_xml, repo: "hexpm", optional: true]}], "hexpm", "44f830a9e89204498da779055eb5f249b0cb58aa7a97783fe91f158e58e8952f"}, "ex_doc": {:hex, :ex_doc, "0.19.3", "3c7b0f02851f5fc13b040e8e925051452e41248f685e40250d7e40b07b9f8c10", [:mix], [{:earmark, "~> 1.2", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.10", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm", "0e11d67e662142fc3945b0ee410c73c8c956717fbeae4ad954b418747c734973"}, + "ex_keccak": {:hex, :ex_keccak, "0.1.2", "4548914dc250a919712f03b4574fd2d048cd6d1245481b559abe9e7b9adafbd3", [:mix], [{:rustler, "~> 0.21.1", [hex: :rustler, repo: "hexpm", optional: false]}], "hexpm", "da2a11b1f95727193865f9184b6af9e1665e82b84f3c531ab4b7323532dafebd"}, "ex_machina": {:hex, :ex_machina, "2.2.2", "d84217a6fb7840ff771d2561b8aa6d74a0d8968e4b10ecc0d7e9890dc8fb1c6a", [:mix], [{:ecto, "~> 2.2 or ~> 3.0", [hex: :ecto, repo: "hexpm", optional: true]}, {:ecto_sql, "~> 3.0", [hex: :ecto_sql, repo: "hexpm", optional: true]}], "hexpm", "0d718f9b2dc1b952eab6223fd5fbe1698be7b6012a5717c66efe8a7920c43ac9"}, - "ex_rlp": {:hex, :ex_rlp, "0.5.2", "7f4ce7bd55e543c054ce6d49629b01e9833c3462e3d547952be89865f39f2c58", [:mix], [], "hexpm", "1b8b8f72f8399ace4e096b99c653cba8c52dc6db17b6b410771c0f088774db82"}, + "ex_plasma": {:git, "https://github.com/omgnetwork/ex_plasma.git", "0336be01bea7b4aeb5b7fbd75edcbe4ad0d1c69f", [ref: "0336be01bea7b4aeb5b7fbd75edcbe4ad0d1c69f"]}, + "ex_rlp": {:hex, :ex_rlp, "0.5.3", "9055bddade545ee3e734aaad62c4b4d08211834da3beb43ae269b75785909e5e", [:mix], [], "hexpm", "a755a5f8f9f66079f3ecbe021536b949077fac0df963d9e59a20321bab28722d"}, + "ex_secp256k1": {:hex, :ex_secp256k1, "0.1.2", "affe4e0fa1adc085ab47d7ab3cc44d594249d24bd0a37a9002f6648d112c2081", [:mix], [{:rustler, "~> 0.21.1 ", [hex: :rustler, repo: "hexpm", optional: false]}], "hexpm", "8ae0131380ada331b15924b563f89e7f56b4e74cc10978f3ea0836589e87730a"}, "ex_sha3": {:hex, :ex_sha3, "0.1.1", "8972638de7ded220cb885d6a8889c0df9da0d581d25c3b1b94a85a226b6fe874", [:mix], [], "hexpm", "3c0da4d7ca4c31dd1c7c4077b394f1fe113fbcdd8ae597683896570dcdb06841"}, "ex_ulid": {:git, "https://github.com/omisego/ex_ulid.git", "2572a88f2687c3aebc8e8657a999fa77bc769fa3", []}, "ex_unit_fixtures": {:hex, :ex_unit_fixtures, "0.3.1", "8ea3fcf6973529c016792b9a424d9e94101e9f7f01a111bd41a2d4e13cc5fa59", [:mix], [], "hexpm", "b4b988211bf4cd08a26eb76756e4563c94c6648c195e45af26ea62e4d37a65f6"}, @@ -67,6 +70,7 @@ "libsecp256k1": {:hex, :libsecp256k1, "0.1.10", "d27495e2b9851c7765129b76c53b60f5e275bd6ff68292c50536bf6b8d091a4d", [:make, :mix], [{:mix_erlang_tasks, "0.1.0", [hex: :mix_erlang_tasks, repo: "hexpm", optional: false]}], "hexpm", "09ea06239938571124f7f5a27bc9ac45dfb1cfc2df40d46ee9b59c3d51366652"}, "makeup": {:hex, :makeup, "0.8.0", "9cf32aea71c7fe0a4b2e9246c2c4978f9070257e5c9ce6d4a28ec450a839b55f", [:mix], [{:nimble_parsec, "~> 0.5.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "5fbc8e549aa9afeea2847c0769e3970537ed302f93a23ac612602e805d9d1e7f"}, "makeup_elixir": {:hex, :makeup_elixir, "0.13.0", "be7a477997dcac2e48a9d695ec730b2d22418292675c75aa2d34ba0909dcdeda", [:mix], [{:makeup, "~> 0.8", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "adf0218695e22caeda2820eaba703fa46c91820d53813a2223413da3ef4ba515"}, + "merkle_tree": {:hex, :merkle_tree, "2.0.0", "84a9cbfd3d8fab545d69c320460ff713ddea2f64ec4c14edfcc4f8eba899d5ab", [:mix], [], "hexpm", "351a764e385ce75bd782a972fc9597d99bed4d692631903e4a08936d4939c895"}, "metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm", "69b09adddc4f74a40716ae54d140f93beb0fb8978d8636eaded0c31b6f099f16"}, "mime": {:hex, :mime, "1.3.1", "30ce04ab3175b6ad0bdce0035cba77bba68b813d523d1aac73d9781b4d193cf8", [:mix], [], "hexpm", "6cbe761d6a0ca5a31a0931bf4c63204bceb64538e664a8ecf784a9a6f3b875f1"}, "mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [:rebar3], [], "hexpm", "f278585650aa581986264638ebf698f8bb19df297f66ad91b18910dfc6e19323"}, @@ -87,12 +91,14 @@ "pot": {:hex, :pot, "0.9.7", "11b33c1ef47e000ffc2027f12f623371897efb8a5755abcc67bcd30e984901c4", [:rebar3], [], "hexpm", "a0f288cc24c6f3f01b5dcabb64445d9d2c15678ea88b4af7f5cac0f9c572162d"}, "quantum": {:hex, :quantum, "2.3.4", "72a0e8855e2adc101459eac8454787cb74ab4169de6ca50f670e72142d4960e9", [:mix], [{:calendar, "~> 0.17", [hex: :calendar, repo: "hexpm", optional: true]}, {:crontab, "~> 1.1", [hex: :crontab, repo: "hexpm", optional: false]}, {:gen_stage, "~> 0.12", [hex: :gen_stage, repo: "hexpm", optional: false]}, {:swarm, "~> 3.3", [hex: :swarm, repo: "hexpm", optional: false]}, {:timex, "~> 3.1", [hex: :timex, repo: "hexpm", optional: true]}], "hexpm", "6de553ba9ac0668d3728b699d5065543f3e40c854154017461ee8c09038752da"}, "ranch": {:hex, :ranch, "1.3.2", "e4965a144dc9fbe70e5c077c65e73c57165416a901bd02ea899cfd95aa890986", [:rebar3], [], "hexpm", "6e56493a862433fccc3aca3025c946d6720d8eedf6e3e6fb911952a7071c357f"}, + "rustler": {:hex, :rustler, "0.21.1", "5299980be32da997c54382e945bacaa015ed97a60745e1e639beaf6a7b278c65", [:mix], [{:toml, "~> 0.5.2", [hex: :toml, repo: "hexpm", optional: false]}], "hexpm", "6ee1651e10645b2b2f3bb70502bf180341aa058709177e9bc28c105934094bc6"}, "sentry": {:hex, :sentry, "7.0.3", "093fa4b6937760afb9a5fcb0e4a9092a305b6c0ff26a710e977614b201feab75", [:mix], [{:hackney, "~> 1.8 or 1.6.5", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix, "~> 1.3", [hex: :phoenix, repo: "hexpm", optional: true]}, {:plug, "~> 1.6", [hex: :plug, repo: "hexpm", optional: true]}, {:plug_cowboy, "~> 1.0 or ~> 2.0", [hex: :plug_cowboy, repo: "hexpm", optional: true]}], "hexpm", "18ec42236068cf7c772447db5ca131b0cc0728fd03413cde7793e3ce0a08a6c9"}, "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.4", "f0eafff810d2041e93f915ef59899c923f4568f4585904d010387ed74988e77b", [:make, :mix, :rebar3], [], "hexpm", "603561dc0fd62f4f2ea9b890f4e20e1a0d388746d6e20557cafb1b16950de88c"}, "swarm": {:hex, :swarm, "3.4.0", "64f8b30055d74640d2186c66354b33b999438692a91be275bb89cdc7e401f448", [:mix], [{:gen_state_machine, "~> 2.0", [hex: :gen_state_machine, repo: "hexpm", optional: false]}, {:libring, "~> 1.0", [hex: :libring, repo: "hexpm", optional: false]}], "hexpm", "94884f84783fc1ba027aba8fe8a7dae4aad78c98e9f9c76667ec3471585c08c6"}, "sweet_xml": {:hex, :sweet_xml, "0.6.5", "dd9cde443212b505d1b5f9758feb2000e66a14d3c449f04c572f3048c66e6697", [:mix], [], "hexpm", "f79c597e7c511178028811061df8782740f1c7e176eb7807fcfdf42ce3d6eff7"}, "telemetry": {:hex, :telemetry, "0.3.0", "099a7f3ce31e4780f971b4630a3c22ec66d22208bc090fe33a2a3a6a67754a73", [:rebar3], [], "hexpm", "63d9f37d319ff331a51f6221310deb5aac8ea3dcf5e0369d689121b5e52f72d4"}, "timex": {:hex, :timex, "3.6.1", "efdf56d0e67a6b956cc57774353b0329c8ab7726766a11547e529357ffdc1d56", [:mix], [{:combine, "~> 0.10", [hex: :combine, repo: "hexpm", optional: false]}, {:gettext, "~> 0.10", [hex: :gettext, repo: "hexpm", optional: false]}, {:tzdata, "~> 0.1.8 or ~> 0.5 or ~> 1.0.0", [hex: :tzdata, repo: "hexpm", optional: false]}], "hexpm", "f354efb2400dd7a80fd9eb6c8419068c4f632da4ac47f3d8822d6e33f08bc852"}, + "toml": {:hex, :toml, "0.5.2", "e471388a8726d1ce51a6b32f864b8228a1eb8edc907a0edf2bb50eab9321b526", [:mix], [], "hexpm", "f1e3dabef71fb510d015fad18c0e05e7c57281001141504c6b69d94e99750a07"}, "tzdata": {:hex, :tzdata, "1.0.1", "f6027a331af7d837471248e62733c6ebee86a72e57c613aa071ebb1f750fc71a", [:mix], [{:hackney, "~> 1.0", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "cf1345dfbce6acdfd4e23cbb36e96e53d1981bc89181cd0b936f4f398f4c0b78"}, "unicode_util_compat": {:hex, :unicode_util_compat, "0.4.1", "d869e4c68901dd9531385bb0c8c40444ebf624e60b6962d95952775cac5e90cd", [:rebar3], [], "hexpm", "1d1848c40487cdb0b30e8ed975e34e025860c02e419cb615d255849f3427439d"}, "uuid": {:hex, :uuid, "1.1.8", "e22fc04499de0de3ed1116b770c7737779f226ceefa0badb3592e64d5cfb4eb9", [:mix], [], "hexpm", "c790593b4c3b601f5dc2378baae7efaf5b3d73c4c6456ba85759905be792f2ac"}, From e343b6c266d614f2953221ffce87b75e802d79eb Mon Sep 17 00:00:00 2001 From: okalouti Date: Tue, 24 Nov 2020 10:16:17 +0700 Subject: [PATCH 03/14] feat: allow string `amount` on endpoint --- apps/ewallet/lib/ewallet/gates/transactions/childchain_gate.ex | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/ewallet/lib/ewallet/gates/transactions/childchain_gate.ex b/apps/ewallet/lib/ewallet/gates/transactions/childchain_gate.ex index 779caa764..28ffca002 100644 --- a/apps/ewallet/lib/ewallet/gates/transactions/childchain_gate.ex +++ b/apps/ewallet/lib/ewallet/gates/transactions/childchain_gate.ex @@ -22,7 +22,8 @@ defmodule EWallet.TransactionGate.Childchain do @eth BlockchainHelper.adapter().helper().default_token().address - def deposit(actor, %{"amount" => amount} = attrs) when is_integer(amount) do + def deposit(actor, %{"amount" => amount} = attrs) + when is_integer(amount) or is_binary(amount) do case build_transaction_attrs(attrs) do {:ok, attrs} -> validation_tuple = address_validation_tuple(attrs) From 8bd77ba98971c166e3b7ee687967e48bb244cb3f Mon Sep 17 00:00:00 2001 From: okalouti Date: Tue, 24 Nov 2020 10:20:01 +0700 Subject: [PATCH 04/14] fix: send deposit amounts as string type --- apps/frontend/assets/src/omg-plasma-deposit-modal/index.js | 2 +- apps/frontend/assets/src/services/blockchainWalletService.js | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/apps/frontend/assets/src/omg-plasma-deposit-modal/index.js b/apps/frontend/assets/src/omg-plasma-deposit-modal/index.js index afcae23a5..2d9f2ff33 100644 --- a/apps/frontend/assets/src/omg-plasma-deposit-modal/index.js +++ b/apps/frontend/assets/src/omg-plasma-deposit-modal/index.js @@ -111,7 +111,7 @@ class PlasmaDeposit extends Component { ) const result = await this.props.plasmaDeposit({ address: this.state.fromAddress.trim(), - amount: parseInt(fromAmount), + amount: fromAmount, tokenId: _.get(this.state.fromTokenSelected, 'token.id') }) if (result.data) { diff --git a/apps/frontend/assets/src/services/blockchainWalletService.js b/apps/frontend/assets/src/services/blockchainWalletService.js index 4b6fd471d..a77c4b68d 100644 --- a/apps/frontend/assets/src/services/blockchainWalletService.js +++ b/apps/frontend/assets/src/services/blockchainWalletService.js @@ -5,6 +5,7 @@ export function getBlockchainWalletBalance ({ address, perPage, page, sort, matc return authenticatedRequest({ path: '/blockchain_wallet.get_balances', data: { + blockchain_identifier: 'ethereum', address, page, per_page: perPage, @@ -20,7 +21,7 @@ export function getBlockchainWalletPlasmaBalance ({ address, perPage, page, sort return authenticatedRequest({ path: '/blockchain_wallet.get_balances', data: { - blockchain_identifier: 'omg_network', + blockchain_identifier: 'omisego_network', address, page, per_page: perPage, @@ -68,7 +69,7 @@ export function plasmaDeposit ({ address, amount, tokenId }) { path: '/blockchain_wallet.deposit_to_childchain', data: { address, - amount, + amount: String(amount), token_id: tokenId, idempotency_token: uuid() } From 1024fb028ca9437af590fbfcbab58cb30b909ebd Mon Sep 17 00:00:00 2001 From: okalouti Date: Tue, 24 Nov 2020 10:37:51 +0700 Subject: [PATCH 05/14] edit: descriptions for OMG Network configuration variables --- apps/ewallet_config/config/config.exs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/ewallet_config/config/config.exs b/apps/ewallet_config/config/config.exs index 0cc3d804a..d61a8abe8 100644 --- a/apps/ewallet_config/config/config.exs +++ b/apps/ewallet_config/config/config.exs @@ -209,14 +209,14 @@ config :ewallet_config, value: "http://localhost:9656", type: "string", position: 210, - description: "The url used by the eWallet to interact with the OmiseGO Network's node." + description: "The URL for the OMG Network child chain." }, "omisego_watcher_url" => %{ key: "omisego_watcher_url", value: "http://localhost:7534", type: "string", position: 211, - description: "The url used by the eWallet to interact with the OmiseGO Network's watcher." + description: "The URL for the OMG Network information service." }, "omisego_plasma_framework_address" => %{ key: "omisego_plasma_framework_address", From da638b106bb68b318a874a920a3a6aaff02466b8 Mon Sep 17 00:00:00 2001 From: okalouti Date: Tue, 24 Nov 2020 11:25:46 +0700 Subject: [PATCH 06/14] fix: display bug --- .../BlockchainActionSelector.tsx | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/apps/frontend/assets/src/omg-page-blockchain-wallet-detail/BlockchainActionSelector.tsx b/apps/frontend/assets/src/omg-page-blockchain-wallet-detail/BlockchainActionSelector.tsx index c495bc8f5..66403e5bb 100644 --- a/apps/frontend/assets/src/omg-page-blockchain-wallet-detail/BlockchainActionSelector.tsx +++ b/apps/frontend/assets/src/omg-page-blockchain-wallet-detail/BlockchainActionSelector.tsx @@ -80,11 +80,7 @@ const BlockchainActionSelector = ({ const renderButton = () => { return ( - + {name} {open ? : } @@ -94,7 +90,10 @@ const BlockchainActionSelector = ({ return ( Date: Tue, 24 Nov 2020 13:40:14 +0700 Subject: [PATCH 07/14] convert component to TypeScript (initial) --- .../{index.js => index.tsx} | 59 +++++++------------ 1 file changed, 22 insertions(+), 37 deletions(-) rename apps/frontend/assets/src/omg-page-blockchain-wallet-detail/{index.js => index.tsx} (71%) diff --git a/apps/frontend/assets/src/omg-page-blockchain-wallet-detail/index.js b/apps/frontend/assets/src/omg-page-blockchain-wallet-detail/index.tsx similarity index 71% rename from apps/frontend/assets/src/omg-page-blockchain-wallet-detail/index.js rename to apps/frontend/assets/src/omg-page-blockchain-wallet-detail/index.tsx index e50ff41fb..024ec7466 100644 --- a/apps/frontend/assets/src/omg-page-blockchain-wallet-detail/index.js +++ b/apps/frontend/assets/src/omg-page-blockchain-wallet-detail/index.tsx @@ -1,46 +1,45 @@ import React, { useEffect, useState } from 'react' -import PropTypes from 'prop-types' -import { Route, Switch, Redirect } from 'react-router-dom' -import { connect } from 'react-redux' +import { Route, Switch, Redirect, RouteComponentProps } from 'react-router-dom' +import { connect, useSelector } from 'react-redux' +import _ from 'lodash' import { - selectBlockchainWallets, - selectBlockchainWalletBalance, selectBlockchainWalletById, selectPlasmaDepositByAddress -} from '../omg-blockchain-wallet/selector' +} from 'omg-blockchain-wallet/selector' import { getAllBlockchainWallets, getBlockchainWalletBalance -} from '../omg-blockchain-wallet/action' -import TopNavigation from '../omg-page-layout/TopNavigation' -import { getTransactionById } from '../omg-transaction/action' +} from 'omg-blockchain-wallet/action' +import TopNavigation from 'omg-page-layout/TopNavigation' +import { getTransactionById } from 'omg-transaction/action' import BlockchainActionSelector from './BlockchainActionSelector' import BlockchainSettingsPage from './BlockchainSettingsPage' import BlockchainTransactionsPage from './BlockchainTransactionsPage' import BlockchainTokensPage from './BlockchainTokensPage' +interface BlockchainWalletDetailPageProps extends RouteComponentProps { + selectPlasmaDepositByAddress: Function + getAllBlockchainWallets: Function + getBlockchainWalletBalance: Function + getTransactionById: Function +} + const BlockchainWalletDetailPage = ({ match, - selectBlockchainWalletBalance, - selectBlockchainWalletById, selectPlasmaDepositByAddress, getAllBlockchainWallets, getBlockchainWalletBalance, - getTransactionById, - selectBlockchainWallets, - ...rest -}) => { - const { address } = match.params + getTransactionById +}: BlockchainWalletDetailPageProps) => { + const address = _.get(match, ['params', 'address']) - const balance = selectBlockchainWalletBalance(address).reduce( - (acc, curr) => acc + curr.amount, - 0 - ) - const walletType = selectBlockchainWalletById(address).type + const walletType = useSelector(state => + selectBlockchainWalletById(state)(address) + ).type - const [pollingState, setPollingState] = useState(false) + const [pollingState, setPollingState] = useState(false) useEffect(() => { if (!walletType) { @@ -108,7 +107,7 @@ const BlockchainWalletDetailPage = ({ } ] - if (walletType === 'hot' && balance > 0) { + if (walletType === 'hot') { return ( <> ({ - selectBlockchainWalletBalance: selectBlockchainWalletBalance(state), - selectBlockchainWalletById: selectBlockchainWalletById(state), - selectBlockchainWallets: selectBlockchainWallets(state), selectPlasmaDepositByAddress: selectPlasmaDepositByAddress(state) }), { getAllBlockchainWallets, getBlockchainWalletBalance, getTransactionById } From db9ff51ddfea6b68ac092b98c10355470f5f98c3 Mon Sep 17 00:00:00 2001 From: okalouti Date: Tue, 24 Nov 2020 13:53:43 +0700 Subject: [PATCH 08/14] feat: add OMG network configurations to blockchain settings page --- .../BlockchainSettings.tsx | 47 ++++++++++++------- .../src/omg-page-configuration/index.js | 5 ++ 2 files changed, 34 insertions(+), 18 deletions(-) diff --git a/apps/frontend/assets/src/omg-page-configuration/BlockchainSettings.tsx b/apps/frontend/assets/src/omg-page-configuration/BlockchainSettings.tsx index 56dbefc15..c24c665ba 100644 --- a/apps/frontend/assets/src/omg-page-configuration/BlockchainSettings.tsx +++ b/apps/frontend/assets/src/omg-page-configuration/BlockchainSettings.tsx @@ -51,63 +51,74 @@ const BlockchainSettings = (props: BlockchainSettingsProps) => { displayName: string disableUpdate: boolean inputValidator?: (...args: any) => boolean - position: number } } const settings: displaySettings = { blockchain_json_rpc_url: { displayName: 'Blockchain JSON-RPC URL', - disableUpdate: true, - position: 0 + disableUpdate: true }, blockchain_chain_id: { displayName: 'Blockchain Chain ID', - disableUpdate: true, - position: 1 + disableUpdate: true }, blockchain_confirmations_threshold: { displayName: 'Blockchain Confirmations Threshold', disableUpdate: false, - inputValidator: isPositiveInteger, - position: 2 + inputValidator: isPositiveInteger }, blockchain_deposit_pooling_interval: { displayName: 'Blockchain Deposit Polling Interval', disableUpdate: false, - inputValidator: isPositiveInteger, - position: 3 + inputValidator: isPositiveInteger }, blockchain_transaction_poll_interval: { displayName: 'Blockchain Transaction Poll Interval', disableUpdate: false, - inputValidator: isPositiveInteger, - position: 4 + inputValidator: isPositiveInteger }, blockchain_state_save_interval: { displayName: 'Blockchain State Save Interval', disableUpdate: false, - inputValidator: isPositiveInteger, - position: 5 + inputValidator: isPositiveInteger }, blockchain_sync_interval: { displayName: 'Blockchain Sync Interval', disableUpdate: false, - inputValidator: isPositiveInteger, - position: 6 + inputValidator: isPositiveInteger }, blockchain_poll_interval: { displayName: 'Blockchain Poll Interval', disableUpdate: false, - inputValidator: isPositiveInteger, - position: 7 + inputValidator: isPositiveInteger + }, + omisego_childchain_url: { + disableUpdate: true, + displayName: 'OMG Network Child Chain URL' + }, + omisego_erc20_vault_address: { + disableUpdate: true, + displayName: 'OMG Network ERC20 Vault Address' + }, + omisego_eth_vault_address: { + disableUpdate: true, + displayName: 'OMG Network ETH Vault Address' + }, + omisego_plasma_framework_address: { + disableUpdate: true, + displayName: 'OMG Network Plasma Framework Address' + }, + omisego_watcher_url: { + disableUpdate: true, + displayName: 'OMG Network Information Service URL' } } const renderBlockchainSettings = () => { const sortedConfigurationList = _.sortBy( _.values(_.pick(configurations, _.keys(settings))), - config => settings[config.key].position + 'position' ) return ( diff --git a/apps/frontend/assets/src/omg-page-configuration/index.js b/apps/frontend/assets/src/omg-page-configuration/index.js index d8edb40b7..26676479d 100644 --- a/apps/frontend/assets/src/omg-page-configuration/index.js +++ b/apps/frontend/assets/src/omg-page-configuration/index.js @@ -135,6 +135,11 @@ class ConfigurationPage extends React.Component { blockchainStateSaveInterval: config.blockchain_state_save_interval.value, blockchainSyncInterval: config.blockchain_sync_interval.value, blockchainTransactionPollInterval: config.blockchain_transaction_poll_interval.value, + omisegoChildchainUrl: config.omisego_childchain_url.value, + omisegoErc20VaultAddress: config.omisego_erc20_vault_address.value, + omisegoEthVaultAddress: config.omisego_eth_vault_address.value, + omisegoPlasmaFrameworkAddress: config.omisego_plasma_framework_address.value, + omisegoWatcherUrl: config.omisego_watcher_url.value, } return { originalState: derivedState, From db61a723d039a488b2233ab4967f876fb67ed7b2 Mon Sep 17 00:00:00 2001 From: okalouti Date: Tue, 24 Nov 2020 13:58:21 +0700 Subject: [PATCH 09/14] fix: connection to Ethereum message --- apps/frontend/assets/src/omg-page-configuration/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/frontend/assets/src/omg-page-configuration/index.js b/apps/frontend/assets/src/omg-page-configuration/index.js index 26676479d..cc94ba459 100644 --- a/apps/frontend/assets/src/omg-page-configuration/index.js +++ b/apps/frontend/assets/src/omg-page-configuration/index.js @@ -401,9 +401,9 @@ class ConfigurationPage extends React.Component { ]} types={false} /> - + - {`The app is currently ${_.get(this.props.configurations, 'enable_blockchain.value', false) ? '' : ' not'} connected to Ethereum.`} + {`The app is currently ${_.get(this.props.configurations, 'blockchain_enabled.value', false) ? '' : ' not'} connected to Ethereum.`} From a5a1591fb12fa38707a6557185b24f023759395c Mon Sep 17 00:00:00 2001 From: okalouti Date: Wed, 25 Nov 2020 08:28:47 +0700 Subject: [PATCH 10/14] add: test for string deposit `amount` --- .../blockchain_wallet_controller_test.exs | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/apps/admin_api/test/admin_api/v1/controllers/blockchain_wallet_controller_test.exs b/apps/admin_api/test/admin_api/v1/controllers/blockchain_wallet_controller_test.exs index 38956a2b9..d0e71849e 100644 --- a/apps/admin_api/test/admin_api/v1/controllers/blockchain_wallet_controller_test.exs +++ b/apps/admin_api/test/admin_api/v1/controllers/blockchain_wallet_controller_test.exs @@ -99,6 +99,41 @@ defmodule AdminAPI.V1.BlockchainWalletControllerTest do end) end + test_with_auths "accepts string `amount` attribute" do + identifier = BlockchainHelper.rootchain_identifier() + hot_wallet = BlockchainWallet.get_primary_hot_wallet(identifier) + + token = + insert(:external_blockchain_token, + blockchain_address: "0x0000000000000000000000000000000000000000" + ) + + adapter = BlockchainHelper.adapter() + {:ok, _adapter_pid} = adapter.server().start_link([]) + + attrs = %{ + token_id: token.id, + amount: Integer.to_string(100), + address: hot_wallet.address, + idempotency_token: UUID.generate() + } + + response = request("/blockchain_wallet.deposit_to_childchain", attrs) + assert response["success"] + assert response["data"]["from"]["amount"] == 100 + + transaction = Transaction.get(response["data"]["id"], preload: :blockchain_transaction) + {:ok, pid} = BlockchainTransactionTracker.lookup(transaction.blockchain_transaction_uuid) + + {:ok, %{pid: blockchain_listener_pid}} = + adapter.lookup_listener(transaction.blockchain_transaction.hash) + + on_exit(fn -> + :ok = GenServer.stop(pid) + :ok = GenServer.stop(blockchain_listener_pid) + end) + end + test_with_auths "fails to deposit with a missing address" do token = insert(:token, blockchain_address: "0x0000000000000000000000000000000000000000") From d800b42a2a3ee3b5c26da820137bcb331ed89646 Mon Sep 17 00:00:00 2001 From: okalouti Date: Wed, 25 Nov 2020 09:06:44 +0700 Subject: [PATCH 11/14] fix: Header --- apps/frontend/assets/src/omg-plasma-deposit-modal/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/frontend/assets/src/omg-plasma-deposit-modal/index.js b/apps/frontend/assets/src/omg-plasma-deposit-modal/index.js index 2d9f2ff33..e47588c7e 100644 --- a/apps/frontend/assets/src/omg-plasma-deposit-modal/index.js +++ b/apps/frontend/assets/src/omg-plasma-deposit-modal/index.js @@ -199,7 +199,7 @@ class PlasmaDeposit extends Component {
-

OMG Network Network Deposit

+

OMG Network Deposit

{this.renderFromSection()} Date: Wed, 9 Dec 2020 11:30:51 +0700 Subject: [PATCH 14/14] test: accepts string amount --- .../childchain_transaction_gate_test.exs | 35 ++++++++++++++----- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/apps/ewallet/test/ewallet/gates/transactions/childchain_transaction_gate_test.exs b/apps/ewallet/test/ewallet/gates/transactions/childchain_transaction_gate_test.exs index 782d45397..a3c054a61 100644 --- a/apps/ewallet/test/ewallet/gates/transactions/childchain_transaction_gate_test.exs +++ b/apps/ewallet/test/ewallet/gates/transactions/childchain_transaction_gate_test.exs @@ -70,28 +70,47 @@ defmodule EWallet.TransactionGate.ChildchainTest do end) end - test "returns an error if the amount is not an integer" do + test "accepts a string amount", meta do admin = insert(:admin, global_role: "super_admin") primary_blockchain_token = - insert(:token, blockchain_address: "0x0000000000000000000000000000000000000000") + insert(:token, + blockchain_status: "confirmed", + blockchain_address: "0x0000000000000000000000000000000000000000" + ) rootchain_identifier = BlockchainHelper.rootchain_identifier() - hot_wallet = BlockchainWallet.get_primary_hot_wallet(rootchain_identifier) attrs = %{ "idempotency_token" => UUID.generate(), "address" => hot_wallet.address, "token_id" => primary_blockchain_token.id, - "amount" => "1", + "amount" => Integer.to_string(1), "originator" => %System{} } - {res, code, error} = TransactionGate.Childchain.deposit(admin, attrs) - assert res == :error - assert code == :invalid_parameter - assert error == "Invalid parameter provided. `amount` is required." + {:ok, transaction} = TransactionGate.Childchain.deposit(admin, attrs) + + {:ok, vault_address} = BlockchainHelper.call(:get_childchain_eth_vault_address) + + assert transaction.status == TransactionState.blockchain_submitted() + assert transaction.type == Transaction.deposit() + assert transaction.blockchain_transaction.rootchain_identifier == rootchain_identifier + assert transaction.blockchain_transaction.childchain_identifier == nil + assert transaction.from_blockchain_address == hot_wallet.address + assert transaction.to_blockchain_address == vault_address + + {:ok, pid} = BlockchainTransactionTracker.lookup(transaction.blockchain_transaction_uuid) + + {:ok, %{pid: blockchain_listener_pid}} = + meta[:adapter].lookup_listener(transaction.blockchain_transaction.hash) + + # to update the transactions after the test is done. + on_exit(fn -> + :ok = GenServer.stop(pid) + :ok = GenServer.stop(blockchain_listener_pid) + end) end end end