defmodule DexiWeb.SignTxControllerTest do use DexiWeb.ConnCase, async: false alias Dexi.GridsCallData setup %{conn: conn} do {:ok, conn: put_req_header(conn, "accept", "application/json")} end test "GET /api/sign/:message_id returns the stashed unsigned transaction", %{conn: conn} do {:ok, message_id} = GridsCallData.stash({self(), "ak_expected_public_key", "tx_unsigned"}) conn = get(conn, ~p"/api/sign/#{message_id}") assert %{ "network_id" => "test-network-id", "payload" => "tx_unsigned", "public_id" => "ak_expected_public_key", "type" => "tx" } = json_response(conn, 200) end test "POST rejects a public key that does not match the stashed request", %{conn: conn} do {:ok, message_id} = GridsCallData.stash({self(), "ak_expected_public_key", "tx_unsigned"}) conn = post(conn, ~p"/api/sign/#{message_id}", %{ "chain" => "gajumaru", "grids" => 1, "network_id" => "test-network-id", "payload" => "tx_signed", "public_id" => "ak_other_public_key", "type" => "tx" }) assert %{"error" => "not_found"} = json_response(conn, 404) refute_receive :tx_failed refute_receive {:tx_success, _tx_hash} end end