Skip to content

Commit

Permalink
Update boundary to operation for InvokeHostFunction (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
keliumJU authored Mar 31, 2023
1 parent 5e77a0d commit 1b42ed1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
4 changes: 2 additions & 2 deletions lib/xdr/transactions/operation_body.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ defmodule StellarBase.XDR.OperationBody do
SetTrustLineFlags,
LiquidityPoolDeposit,
LiquidityPoolWithdraw,
InvokeHostFunctionOp
InvokeHostFunction
}

@behaviour XDR.Declaration
Expand Down Expand Up @@ -58,7 +58,7 @@ defmodule StellarBase.XDR.OperationBody do
SET_TRUST_LINE_FLAGS: SetTrustLineFlags,
LIQUIDITY_POOL_DEPOSIT: LiquidityPoolDeposit,
LIQUIDITY_POOL_WITHDRAW: LiquidityPoolWithdraw,
INVOKE_HOST_FUNCTION: InvokeHostFunctionOp
INVOKE_HOST_FUNCTION: InvokeHostFunction
]

@type operation :: any()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule StellarBase.XDR.InvokeHostFunctionOp do
defmodule StellarBase.XDR.Operations.InvokeHostFunction do
@moduledoc """
Representation of Stellar `InvokeHostFunctionOp` type.
Representation of Stellar `InvokeHostFunction` type.
"""

alias StellarBase.XDR.{ContractAuthList, LedgerFootprint, HostFunction}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
defmodule StellarBase.XDR.InvokeHostFunctionOpTest do
defmodule StellarBase.XDR.Operations.InvokeHostFunctionTest do
use ExUnit.Case

alias StellarBase.XDR.{
InvokeHostFunctionOp,
SCVal,
SCValType,
SCVec,
Expand Down Expand Up @@ -38,9 +37,11 @@ defmodule StellarBase.XDR.InvokeHostFunctionOpTest do
UInt64
}

alias StellarBase.XDR.Operations.InvokeHostFunction

alias StellarBase.StrKey

describe "InvokeHostFunctionOp" do
describe "InvokeHostFunction" do
setup do
## HostFunction
scval1 = SCVal.new(Int64.new(3), SCValType.new(:SCV_U63))
Expand Down Expand Up @@ -99,7 +100,7 @@ defmodule StellarBase.XDR.InvokeHostFunctionOpTest do
host_function: host_function,
footprint: footprint,
auth: auth_list,
invoke_host_function_op: InvokeHostFunctionOp.new(host_function, footprint, auth_list),
invoke_host_function_op: InvokeHostFunction.new(host_function, footprint, auth_list),
binary:
<<0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 114, 213, 178, 144, 98, 27, 186, 154,
Expand All @@ -124,40 +125,40 @@ defmodule StellarBase.XDR.InvokeHostFunctionOpTest do
end

test "new/1", %{host_function: host_function, footprint: footprint, auth: auth} do
%InvokeHostFunctionOp{host_function: ^host_function, footprint: ^footprint, auth: ^auth} =
InvokeHostFunctionOp.new(host_function, footprint, auth)
%InvokeHostFunction{host_function: ^host_function, footprint: ^footprint, auth: ^auth} =
InvokeHostFunction.new(host_function, footprint, auth)
end

test "encode_xdr/1", %{
invoke_host_function_op: invoke_host_function_op,
binary: binary
} do
{:ok, ^binary} = InvokeHostFunctionOp.encode_xdr(invoke_host_function_op)
{:ok, ^binary} = InvokeHostFunction.encode_xdr(invoke_host_function_op)
end

test "encode_xdr!/1", %{
invoke_host_function_op: invoke_host_function_op,
binary: binary
} do
^binary = InvokeHostFunctionOp.encode_xdr!(invoke_host_function_op)
^binary = InvokeHostFunction.encode_xdr!(invoke_host_function_op)
end

test "decode_xdr/2", %{
invoke_host_function_op: invoke_host_function_op,
binary: binary
} do
{:ok, {^invoke_host_function_op, ""}} = InvokeHostFunctionOp.decode_xdr(binary)
{:ok, {^invoke_host_function_op, ""}} = InvokeHostFunction.decode_xdr(binary)
end

test "decode_xdr/2 with an invalid binary" do
{:error, :not_binary} = InvokeHostFunctionOp.decode_xdr(123)
{:error, :not_binary} = InvokeHostFunction.decode_xdr(123)
end

test "decode_xdr!/2", %{
invoke_host_function_op: invoke_host_function_op,
binary: binary
} do
{^invoke_host_function_op, ^binary} = InvokeHostFunctionOp.decode_xdr!(binary <> binary)
{^invoke_host_function_op, ^binary} = InvokeHostFunction.decode_xdr!(binary <> binary)
end
end
end

0 comments on commit 1b42ed1

Please sign in to comment.