-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
hash_id_preimage_contract_id_test.exs
79 lines (71 loc) · 2.08 KB
/
hash_id_preimage_contract_id_test.exs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
defmodule Stellar.TxBuild.HashIDPreimageContractIDTest do
use ExUnit.Case
alias Stellar.TxBuild.{
Asset,
HashIDPreimageContractID,
ContractIDPreimage
}
setup do
network_id = "network"
asset = Asset.new(:native)
contract_id_preimage = ContractIDPreimage.new(from_asset: asset)
%{
network_id: network_id,
contract_id_preimage: contract_id_preimage
}
end
test "new/1", %{
contract_id_preimage: contract_id_preimage,
network_id: network_id
} do
%HashIDPreimageContractID{
contract_id_preimage: ^contract_id_preimage,
network_id: ^network_id
} =
HashIDPreimageContractID.new(
network_id: network_id,
contract_id_preimage: contract_id_preimage
)
end
test "new/1 with invalid args" do
{:error, :invalid_hash_id_preimage_contract_id} =
HashIDPreimageContractID.new(
network_id: 1234,
contract_id_preimage: "invalid"
)
end
test "new/1 with invalid ContractIDPreimage", %{
network_id: network_id
} do
{:error, :invalid_contract_id_preimage} =
HashIDPreimageContractID.new(
network_id: network_id,
contract_id_preimage: "invalid"
)
end
test "to_xdr/1", %{
contract_id_preimage: contract_id_preimage,
network_id: network_id
} do
%StellarBase.XDR.HashIDPreimageContractID{
network_id: %StellarBase.XDR.Hash{value: "network"},
contract_id_preimage: %StellarBase.XDR.ContractIDPreimage{
value: %StellarBase.XDR.Asset{
asset: %StellarBase.XDR.Void{value: nil},
type: %StellarBase.XDR.AssetType{identifier: :ASSET_TYPE_NATIVE}
},
type: %StellarBase.XDR.ContractIDPreimageType{
identifier: :CONTRACT_ID_PREIMAGE_FROM_ASSET
}
}
} =
HashIDPreimageContractID.new(
network_id: network_id,
contract_id_preimage: contract_id_preimage
)
|> HashIDPreimageContractID.to_xdr()
end
test "to_xdr/1 with the struct is invalid" do
{:error, :invalid_struct} = HashIDPreimageContractID.to_xdr("invalid_struct")
end
end