Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ExecPayload base structs definition #33

Merged
merged 1 commit into from
Sep 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions lib/types/env_data.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
defmodule Kadena.Types.EnvData do
@moduledoc """
`EnvData` struct definition.
"""

@behaviour Kadena.Types.Spec

@type data :: map()

@type t :: %__MODULE__{data: data()}

defstruct [:data]

@impl true
def new(data) when is_map(data), do: %__MODULE__{data: data}
def new(_data), do: {:error, [data: :invalid]}
end
17 changes: 17 additions & 0 deletions lib/types/pact_code.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
defmodule Kadena.Types.PactCode do
@moduledoc """
`PactCode` struct definition.
"""

@behaviour Kadena.Types.Spec

@type code :: String.t()

@type t :: %__MODULE__{code: code()}

defstruct [:code]

@impl true
def new(code) when is_binary(code), do: %__MODULE__{code: code}
def new(_code), do: {:error, [code: :invalid]}
end
27 changes: 27 additions & 0 deletions test/types/env_data_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
defmodule Kadena.Types.EnvDataTest do
@moduledoc """
`EnvData` struct definition tests.
"""

use ExUnit.Case

alias Kadena.Types.EnvData

describe "new/1" do
test "with valid env data" do
%EnvData{data: %{}} = EnvData.new(%{})
end

test "with nil env data" do
{:error, [data: :invalid]} = EnvData.new(nil)
end

test "with number env data" do
{:error, [data: :invalid]} = EnvData.new(12_345)
end

test "with atom env data" do
{:error, [data: :invalid]} = EnvData.new(:atom)
end
end
end
28 changes: 28 additions & 0 deletions test/types/pact_code_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
defmodule Kadena.Types.PactCodeTest do
@moduledoc """
`PactCode` struct definition tests.
"""

use ExUnit.Case

alias Kadena.Types.PactCode

describe "new/1" do
test "with a valid pact code" do
%PactCode{code: ~S(format \"hello {}\" [\"world\"])} =
PactCode.new(~S(format \"hello {}\" [\"world\"]))
end

test "with a number pact code" do
{:error, [code: :invalid]} = PactCode.new(12_345)
end

test "with a atom pact code" do
{:error, [code: :invalid]} = PactCode.new(:atom)
end

test "with a nil pact code" do
{:error, [code: :invalid]} = PactCode.new(nil)
end
end
end