~dcrck/solana

515ad70ec5b1b8788e17c5166617f7842d76e4b3 — dcrck 5 months ago 9f039ee
add Key.pair_from_file/1 tests
M test/solana/key_test.exs => test/solana/key_test.exs +18 -0
@@ 117,4 117,22 @@ defmodule Solana.KeyTest do
      assert {:ok, ^address} = Key.derive_address(["", nonce], program_id)
    end
  end

  describe "pair_from_file/1" do
    test "loads a keypair from a valid file system wallet" do
      pk = Solana.pubkey!("ntnHWe6sXd1SZaLa5gqHndAsyRwEfoR21ggNxkuyBtK")
      assert {:ok, {_sk, ^pk}} = Key.pair_from_file("test/support/wallet.json")
    end

    test "does not load a keypair from a non-existant files" do
      assert {:error, _} = Key.pair_from_file("test/support/nonexistant.json")
    end

    test "does not load a keypair from invalid files" do
      ["invalid1", "invalid2"]
      |> Enum.each(fn name ->
        assert {:error, "invalid wallet format"} = Key.pair_from_file("test/support/#{name}.json")
      end)
    end
  end
end

A test/support/invalid1.json => test/support/invalid1.json +1 -0
@@ 0,0 1,1 @@
[15,71,250,29,115,195,43,15,127,223,205,118,122,34,251,10,145,145,226,10,251,179,187,167,178,25,249,98,144,174,233,161,11,193,175,99,126,187,46,212,170,91,91,230,255,102,225,128,42,255,58,1,3,187,219,93,51,1,22,255,237,169,42]

A test/support/invalid2.json => test/support/invalid2.json +1 -0
@@ 0,0 1,1 @@
{}

A test/support/wallet.json => test/support/wallet.json +1 -0
@@ 0,0 1,1 @@
[15,71,250,29,115,195,43,15,127,223,205,118,122,34,251,10,145,145,226,10,251,179,187,167,178,25,249,98,144,174,233,161,11,193,175,99,126,187,46,212,170,91,91,230,255,102,225,128,42,255,58,1,3,187,219,93,51,1,22,255,237,169,42,40]
\ No newline at end of file