From 1eb1f542ac115c03c2b97ccd86f307906831c4bf Mon Sep 17 00:00:00 2001 From: Artur Puzio Date: Fri, 30 Nov 2018 01:58:54 +0800 Subject: [PATCH] [GH-757] Better tests --- .../lib/aecore/channel/channel_state_peer.ex | 16 ++++++++++++++++ apps/aecore/test/aecore_channels_test.exs | 11 +++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/apps/aecore/lib/aecore/channel/channel_state_peer.ex b/apps/aecore/lib/aecore/channel/channel_state_peer.ex index 8ebcbd80..7040b3a4 100644 --- a/apps/aecore/lib/aecore/channel/channel_state_peer.ex +++ b/apps/aecore/lib/aecore/channel/channel_state_peer.ex @@ -588,6 +588,22 @@ defmodule Aecore.Channel.ChannelStatePeer do """ @spec receive_fully_signed_tx(ChannelStatePeer.t(), ChannelTransaction.signed_tx()) :: {:ok, ChannelStatePeer.t()} | error() + def receive_fully_signed_tx( + %ChannelStatePeer{ + fsm_state: :open, + role: :delegate + } = peer_state, + tx + ) do + case process_fully_signed_tx(tx, peer_state) do + {:ok, %ChannelStatePeer{mutually_signed_tx: prev_mutually_signed_tx} = new_state} -> + {:ok, %ChannelStatePeer{new_state | mutually_signed_tx: [tx | prev_mutually_signed_tx]}} + + {:error, _} = err -> + err + end + end + def receive_fully_signed_tx( %ChannelStatePeer{ fsm_state: :awaiting_full_tx, diff --git a/apps/aecore/test/aecore_channels_test.exs b/apps/aecore/test/aecore_channels_test.exs index 9abc8f0a..8501ff6d 100644 --- a/apps/aecore/test/aecore_channels_test.exs +++ b/apps/aecore/test/aecore_channels_test.exs @@ -397,18 +397,19 @@ defmodule AecoreChannelTest do test "Create channel, transfer twice, slash with old, delegate slashes with correct and settle", ctx do id = create_channel(ctx) + export_import_peer_state(id, &call_s1/1, &call_s3/1) - perform_transfer(id, 50, &call_s1/1, ctx.sk1, &call_s2/1, ctx.sk2) + tx = perform_transfer(id, 50, &call_s1/1, ctx.sk1, &call_s2/1, ctx.sk2) + assert :ok == call_s3({:receive_fully_signed_tx, tx}) assert_offchain_state(id, 100, 200, 2) # prepare solo close but do not submit to pool solo_close_tx = prepare_solo_close_tx(id, &call_s2/1, 15, 1, ctx.sk2) - perform_transfer(id, 170, &call_s2/1, ctx.sk2, &call_s1/1, ctx.sk1) + tx2 = perform_transfer(id, 170, &call_s2/1, ctx.sk2, &call_s1/1, ctx.sk1) + assert :ok == call_s3({:receive_fully_signed_tx, tx2}) assert_offchain_state(id, 270, 30, 3) - export_import_peer_state(id, &call_s1/1, &call_s3/1) - assert_custom_tx_succeeds(solo_close_tx) assert ChannelStateOnChain.active?(ChannelStateTree.get(Chain.chain_state().channels, id)) === @@ -758,6 +759,8 @@ defmodule AecoreChannelTest do %ChannelOffChainTx{} = fully_signed_transfer_tx assert :open === get_fsm_state(id, responder_fun) :ok = initiator_fun.({:receive_fully_signed_tx, fully_signed_transfer_tx}) + + fully_signed_transfer_tx end defp perform_withdraw(