-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
soroba_tarsaction_data_test.exs
106 lines (91 loc) · 3.51 KB
/
soroba_tarsaction_data_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
96
97
98
99
100
101
102
103
104
105
106
defmodule Stellar.TxBuild.SorobanTransactionDataTest do
use ExUnit.Case
alias Stellar.TxBuild.{LedgerFootprint, LedgerKey}
alias Stellar.TxBuild.{SorobanResources, SorobanTransactionData}
setup do
hash = "ABC123"
contract_code_args = [hash: hash]
read_only = [LedgerKey.new({:contract_code, contract_code_args})]
read_write = [
LedgerKey.new({:contract_code, contract_code_args}),
LedgerKey.new({:contract_code, contract_code_args})
]
footprint = LedgerFootprint.new(read_only: read_only, read_write: read_write)
instructions = 1000
read_bytes = 1024
write_bytes = 512
resources =
SorobanResources.new(
footprint: footprint,
instructions: instructions,
read_bytes: read_bytes,
write_bytes: write_bytes
)
resource_fee = 100
soroban_transaction_data =
SorobanTransactionData.new(resources: resources, resource_fee: resource_fee)
xdr = %StellarBase.XDR.SorobanTransactionData{
ext: %StellarBase.XDR.ExtensionPoint{
extension_point: %StellarBase.XDR.Void{value: nil},
type: 0
},
resources: %StellarBase.XDR.SorobanResources{
footprint: %StellarBase.XDR.LedgerFootprint{
read_only: %StellarBase.XDR.LedgerKeyList{
ledger_keys: [
%StellarBase.XDR.LedgerKey{
entry: %StellarBase.XDR.LedgerKeyContractCode{
hash: %StellarBase.XDR.Hash{value: "ABC123"}
},
type: %StellarBase.XDR.LedgerEntryType{identifier: :CONTRACT_CODE}
}
]
},
read_write: %StellarBase.XDR.LedgerKeyList{
ledger_keys: [
%StellarBase.XDR.LedgerKey{
entry: %StellarBase.XDR.LedgerKeyContractCode{
hash: %StellarBase.XDR.Hash{value: "ABC123"}
},
type: %StellarBase.XDR.LedgerEntryType{identifier: :CONTRACT_CODE}
},
%StellarBase.XDR.LedgerKey{
entry: %StellarBase.XDR.LedgerKeyContractCode{
hash: %StellarBase.XDR.Hash{value: "ABC123"}
},
type: %StellarBase.XDR.LedgerEntryType{identifier: :CONTRACT_CODE}
}
]
}
},
instructions: %StellarBase.XDR.UInt32{datum: 1000},
read_bytes: %StellarBase.XDR.UInt32{datum: 1024},
write_bytes: %StellarBase.XDR.UInt32{datum: 512}
},
resource_fee: %StellarBase.XDR.Int64{datum: 100}
}
%{
resources: resources,
resource_fee: resource_fee,
soroban_transaction_data: soroban_transaction_data,
xdr: xdr
}
end
test "new/1", %{resources: resources, resource_fee: resource_fee} do
%SorobanTransactionData{resources: ^resources, resource_fee: ^resource_fee} =
SorobanTransactionData.new(resources: resources, resource_fee: resource_fee)
end
test "new/1 with invalid soroban transaction args" do
{:error, :invalid_soroban_transaction_data} = SorobanTransactionData.new(:invalid)
end
test "new/1 with invalid resources", %{resource_fee: resource_fee} do
{:error, :invalid_resources} =
SorobanTransactionData.new(resources: :invalid, resource_fee: resource_fee)
end
test "to_xdr/1", %{soroban_transaction_data: soroban_transaction_data, xdr: xdr} do
^xdr = SorobanTransactionData.to_xdr(soroban_transaction_data)
end
test "to_xdr/1 with invalid struct" do
{:error, :invalid_struct} = SorobanTransactionData.to_xdr(%{})
end
end