Skip to content

Commit

Permalink
[GH-757] Better tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cytadela8 committed Nov 29, 2018
1 parent 563af70 commit 1eb1f54
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
16 changes: 16 additions & 0 deletions apps/aecore/lib/aecore/channel/channel_state_peer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 7 additions & 4 deletions apps/aecore/test/aecore_channels_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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)) ===
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 1eb1f54

Please sign in to comment.