-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
set_trustline_flags_test.exs
95 lines (84 loc) · 2.25 KB
/
set_trustline_flags_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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
defmodule Stellar.TxBuild.SetTrustlineFlagsTest do
use ExUnit.Case
alias Stellar.Test.Fixtures.XDR, as: XDRFixtures
alias Stellar.TxBuild.{AccountID, Asset, SetTrustlineFlags, TrustlineFlags}
setup do
trustor = "GD726E62G6G4ANHWHIQTH5LNMFVF2EQSEXITB6DZCCTKVU6EQRRE2SJS"
asset_code = "BTCN"
asset_issuer = "GBTG2POJVVSRBQSZVA3IYJEZJQLPTIVVYOYRLTZEAEFBMVP72ZTQYA2V"
clear_flags = []
set_flags = [:authorized, :maintain_liabilities]
%{
trustor: trustor,
asset: {asset_code, asset_issuer},
clear_flags: clear_flags,
set_flags: set_flags,
xdr:
XDRFixtures.set_trustline_flags(
trustor,
{asset_code, asset_issuer},
set_flags,
clear_flags
)
}
end
test "new/2", %{
trustor: trustor,
asset: asset,
set_flags: set_flags
} do
trustor_str = AccountID.new(trustor)
asset_str = Asset.new(asset)
set_flags_str = set_flags |> TrustlineFlags.new()
%SetTrustlineFlags{
trustor: ^trustor_str,
asset: ^asset_str,
set_flags: ^set_flags_str
} =
SetTrustlineFlags.new(
trustor: trustor,
asset: asset,
set_flags: set_flags
)
end
test "new/2 invalid_flags", %{
trustor: trustor,
asset: asset
} do
{:error, [set_flags: :invalid_flags]} =
SetTrustlineFlags.new(
trustor: trustor,
asset: asset,
set_flags: :test
)
end
test "new/2 with_invalid_trustor" do
{:error, [trustor: :invalid_ed25519_public_key]} =
SetTrustlineFlags.new(
asset: :native,
trustor: "ABC"
)
end
test "new/2 with_invalid_asset", %{trustor: trustor} do
{:error, [asset: :invalid_asset_issuer]} =
SetTrustlineFlags.new(
asset: {"BTCN", "ABC"},
trustor: trustor
)
end
test "new/2 with_invalid_attributes" do
{:error, :invalid_operation_attributes} = SetTrustlineFlags.new("ABC", "123")
end
test "to_xdr/1", %{
xdr: xdr,
trustor: trustor,
asset: asset,
set_flags: set_flags,
clear_flags: clear_flags
} do
^xdr =
[trustor: trustor, asset: asset, set_flags: set_flags, clear_flags: clear_flags]
|> SetTrustlineFlags.new()
|> SetTrustlineFlags.to_xdr()
end
end