This repository has been archived by the owner on Nov 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
38 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
defmodule Cashubrew.Nuts.Nut01Test do | ||
use Cashubrew.Test.ConnCase | ||
alias Cashubrew.Nuts.Nut01 | ||
|
||
test "active_keysets", %{conn: conn} do | ||
conn = get(conn, ~p"/api/v1/keys") | ||
data = json_response(conn, 200) | ||
|
||
keysets = Map.fetch!(data, "keysets") | ||
assert length(keysets) == 1 | ||
[keyset | _] = keysets | ||
|
||
id = Map.fetch!(keyset, "id") | ||
unit = Map.fetch!(keyset, "unit") | ||
keys = Map.fetch!(keyset, "keys") | ||
|
||
assert unit == "sat" | ||
assert is_bitstring(id) | ||
assert is_map(keys) | ||
assert Map.has_key?(keys, "1") | ||
|
||
Enum.each(keys, fn {k, v} -> | ||
# The keys are 1, 2, 4, 8, ... | ||
{amount, ""} = Integer.parse(k, 10) | ||
|
||
if amount != 1 do | ||
assert rem(amount, 2) == 0 | ||
assert Map.has_key?(keys, "#{div(amount, 2)}") | ||
end | ||
|
||
# The values are valid hex numbers | ||
{_, ""} = Integer.parse(v, 16) | ||
end) | ||
end | ||
end |