-
Notifications
You must be signed in to change notification settings - Fork 18
/
Addresses.hs
239 lines (222 loc) · 6.99 KB
/
Addresses.hs
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
{-# LANGUAGE NumericUnderscores #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskell #-}
module Cardano.Addresses
where
import Data.Aeson (decode, eitherDecode, encode, object, (.=))
import Data.Text (Text)
import qualified Money
import Test.Hspec
import Test.Tasty.Hspec
import Text.RawString.QQ
import Blockfrost.Types
spec_sample :: Spec
spec_sample = do
it "parses address info sample" $ do
eitherDecode addressInfoSample
`shouldBe`
Right addressInfoExpected
it "parses address info sample" $ do
eitherDecode addressInfoSample
`shouldBe`
Right addressInfoExpected
it "parses address details sample" $ do
eitherDecode addressDetailsSample
`shouldBe`
Right addressDetailsExpected
it "parses address utxos sample" $ do
eitherDecode addressUtxosSample
`shouldBe`
Right addressUtxosExpected
it "parses address transactions sample" $ do
eitherDecode addressTransactionsSample
`shouldBe`
Right addressTransactionsExpected
addressInfoSample = [r|
{
"address": "addr1qxqs59lphg8g6qndelq8xwqn60ag3aeyfcp33c2kdp46a09re5df3pzwwmyq946axfcejy5n4x0y99wqpgtp2gd0k09qsgy6pz",
"amount": [
{
"unit": "lovelace",
"quantity": "42000000"
},
{
"unit": "b0d07d45fe9514f80213f4020e5a61241458be626841cde717cb38a76e7574636f696e",
"quantity": "12"
}
],
"stake_address": "stake1ux3g2c9dx2nhhehyrezyxpkstartcqmu9hk63qgfkccw5rqttygt7",
"type": "shelley",
"script": false
}
|]
addressInfoExpected =
AddressInfo
{ _addressInfoAddress = "addr1qxqs59lphg8g6qndelq8xwqn60ag3aeyfcp33c2kdp46a09re5df3pzwwmyq946axfcejy5n4x0y99wqpgtp2gd0k09qsgy6pz"
, _addressInfoAmount =
[ AdaAmount 42000000
, AssetAmount
$ Money.mkSomeDiscrete
"b0d07d45fe9514f80213f4020e5a61241458be626841cde717cb38a76e7574636f696e"
unitScale
12
]
, _addressInfoStakeAddress = pure "stake1ux3g2c9dx2nhhehyrezyxpkstartcqmu9hk63qgfkccw5rqttygt7"
, _addressInfoType = Shelley
, _addressInfoScript = False
}
addressDetailsSample = [r|
{
"address": "addr1qxqs59lphg8g6qndelq8xwqn60ag3aeyfcp33c2kdp46a09re5df3pzwwmyq946axfcejy5n4x0y99wqpgtp2gd0k09qsgy6pz",
"received_sum": [
{
"unit": "lovelace",
"quantity": "42000000"
},
{
"unit": "b0d07d45fe9514f80213f4020e5a61241458be626841cde717cb38a76e7574636f696e",
"quantity": "12"
}
],
"sent_sum": [
{
"unit": "lovelace",
"quantity": "42000000"
},
{
"unit": "b0d07d45fe9514f80213f4020e5a61241458be626841cde717cb38a76e7574636f696e",
"quantity": "12"
}
],
"tx_count": 12
}
|]
addressDetailsExpected =
AddressDetails
{ _addressDetailsAddress = "addr1qxqs59lphg8g6qndelq8xwqn60ag3aeyfcp33c2kdp46a09re5df3pzwwmyq946axfcejy5n4x0y99wqpgtp2gd0k09qsgy6pz"
, _addressDetailsReceivedSum = amounts
, _addressDetailsSentSum = amounts
, _addressDetailsTxCount = 12
}
where amounts =
[ AdaAmount 42000000
, AssetAmount
$ Money.mkSomeDiscrete
"b0d07d45fe9514f80213f4020e5a61241458be626841cde717cb38a76e7574636f696e"
unitScale
12
]
addressUtxosSample = [r|
[
{
"tx_hash": "39a7a284c2a0948189dc45dec670211cd4d72f7b66c5726c08d9b3df11e44d58",
"output_index": 0,
"amount":
[
{
"unit": "lovelace",
"quantity": "42000000"
}
],
"block": "7eb8e27d18686c7db9a18f8bbcfe34e3fed6e047afaa2d969904d15e934847e6",
"data_hash": "9e478573ab81ea7a8e31891ce0648b81229f408d596a3483e6f4f9b92d3cf710"
},
{
"tx_hash": "4c4e67bafa15e742c13c592b65c8f74c769cd7d9af04c848099672d1ba391b49",
"output_index": 0,
"amount":
[
{
"unit": "lovelace",
"quantity": "729235000"
}
],
"block": "953f1b80eb7c11a7ffcd67cbd4fde66e824a451aca5a4065725e5174b81685b7",
"data_hash": null
},
{
"tx_hash": "768c63e27a1c816a83dc7b07e78af673b2400de8849ea7e7b734ae1333d100d2",
"output_index": 1,
"amount":
[
{
"unit": "lovelace",
"quantity": "42000000"
},
{
"unit": "b0d07d45fe9514f80213f4020e5a61241458be626841cde717cb38a76e7574636f696e",
"quantity": "12"
}
],
"block": "5c571f83fe6c784d3fbc223792627ccf0eea96773100f9aedecf8b1eda4544d7",
"data_hash": null
}
]
|]
addressUtxosExpected =
[ AddressUtxo
{ _addressUtxoTxHash = "39a7a284c2a0948189dc45dec670211cd4d72f7b66c5726c08d9b3df11e44d58"
, _addressUtxoOutputIndex = 0
, _addressUtxoAmount = [ AdaAmount 42000000 ]
, _addressUtxoBlock = "7eb8e27d18686c7db9a18f8bbcfe34e3fed6e047afaa2d969904d15e934847e6"
, _addressUtxoDataHash = Just "9e478573ab81ea7a8e31891ce0648b81229f408d596a3483e6f4f9b92d3cf710"
}
, AddressUtxo
{ _addressUtxoTxHash = "4c4e67bafa15e742c13c592b65c8f74c769cd7d9af04c848099672d1ba391b49"
, _addressUtxoOutputIndex = 0
, _addressUtxoAmount = [ AdaAmount 729235000 ]
, _addressUtxoBlock = "953f1b80eb7c11a7ffcd67cbd4fde66e824a451aca5a4065725e5174b81685b7"
, _addressUtxoDataHash = Nothing
}
, AddressUtxo
{ _addressUtxoTxHash = "768c63e27a1c816a83dc7b07e78af673b2400de8849ea7e7b734ae1333d100d2"
, _addressUtxoOutputIndex = 1
, _addressUtxoAmount =
[ AdaAmount 42000000
, AssetAmount
$ Money.mkSomeDiscrete
"b0d07d45fe9514f80213f4020e5a61241458be626841cde717cb38a76e7574636f696e"
unitScale
12
]
, _addressUtxoBlock = "5c571f83fe6c784d3fbc223792627ccf0eea96773100f9aedecf8b1eda4544d7"
, _addressUtxoDataHash = Nothing
}
]
addressTransactionsSample = [r|
[
{
"tx_hash": "8788591983aa73981fc92d6cddbbe643959f5a784e84b8bee0db15823f575a5b",
"tx_index": 6,
"block_height": 69
},
{
"tx_hash": "52e748c4dec58b687b90b0b40d383b9fe1f24c1a833b7395cdf07dd67859f46f",
"tx_index": 9,
"block_height": 4547
},
{
"tx_hash": "e8073fd5318ff43eca18a852527166aa8008bee9ee9e891f585612b7e4ba700b",
"tx_index": 0,
"block_height": 564654
}
]
|]
addressTransactionsExpected =
[ AddressTransaction
{ _addressTransactionTxHash = "8788591983aa73981fc92d6cddbbe643959f5a784e84b8bee0db15823f575a5b"
, _addressTransactionTxIndex = 6
, _addressTransactionBlockHeight = 69
}
, AddressTransaction
{ _addressTransactionTxHash = "52e748c4dec58b687b90b0b40d383b9fe1f24c1a833b7395cdf07dd67859f46f"
, _addressTransactionTxIndex = 9
, _addressTransactionBlockHeight = 4547
}
, AddressTransaction
{ _addressTransactionTxHash = "e8073fd5318ff43eca18a852527166aa8008bee9ee9e891f585612b7e4ba700b"
, _addressTransactionTxIndex = 0
, _addressTransactionBlockHeight = 564654
}
]