/
shelley_spec.rb
404 lines (335 loc) · 13.5 KB
/
shelley_spec.rb
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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
RSpec.describe CardanoWallet::Shelley do
describe CardanoWallet::Shelley::Wallets do
after(:each) do
teardown
end
it "I can list wallets" do
l = SHELLEY.wallets.list
expect(l).to be_correct_and_respond 200
expect(l.size).to eq 0
create_shelley_wallet
l = SHELLEY.wallets.list
expect(l).to be_correct_and_respond 200
expect(l.size).to eq 1
end
it "When wallet does not exist it gives 404" do
wid = create_shelley_wallet
SHELLEY.wallets.delete wid
g = SHELLEY.wallets.get wid
expect(g).to be_correct_and_respond 404
d = SHELLEY.wallets.delete wid
expect(d).to be_correct_and_respond 404
end
describe "Create wallets" do
it "I can create, get and delete wallet from mnemonics" do
w = SHELLEY.wallets
wallet = w.create({ name: "Wallet from mnemonic_sentence",
passphrase: "Secure Passphrase",
mnemonic_sentence: mnemonic_sentence(15),
})
expect(wallet).to be_correct_and_respond 201
wid = wallet['id']
g = w.get(wid)
expect(g).to be_correct_and_respond 200
expect(w.delete(wid)).to be_correct_and_respond 204
end
it "I can create, get and delete wallet from mnemonics / second factor" do
w = SHELLEY.wallets
wallet = w.create({ name: "Wallet from mnemonic_sentence",
passphrase: "Secure Passphrase",
mnemonic_sentence: mnemonic_sentence(15),
mnemonic_second_factor: mnemonic_sentence(12)
})
expect(wallet).to be_correct_and_respond 201
wid = wallet['id']
g = w.get(wid)
expect(g).to be_correct_and_respond 200
expect(w.delete(wid)).to be_correct_and_respond 204
end
it "I can set address pool gap" do
pool_gap = 55
w = SHELLEY.wallets
wallet = w.create({ name: "Wallet from mnemonic_sentence",
passphrase: "Secure Passphrase",
mnemonic_sentence: mnemonic_sentence(15),
address_pool_gap: pool_gap
})
expect(wallet).to be_correct_and_respond 201
addr = SHELLEY.addresses.list(wallet['id'])
expect(addr).to be_correct_and_respond 200
expect(addr.size).to eq pool_gap
end
it "I can create, get and delete wallet from pub key" do
w = SHELLEY.wallets
wallet = w.create({ name: "Wallet from pub key",
account_public_key: "b47546e661b6c1791452d003d375756dde6cac2250093ce4630f16b9b9c0ac87411337bda4d5bc0216462480b809824ffb48f17e08d95ab9f1b91d391e48e66b",
address_pool_gap: 20,
})
expect(wallet).to be_correct_and_respond 201
wid = wallet['id']
g = w.get(wid)
expect(g).to be_correct_and_respond 200
expect(w.delete(wid)).to be_correct_and_respond 204
end
end
describe "Update wallet" do
it "Can update_metadata" do
new_name = "New wallet name"
w = SHELLEY.wallets
id = create_shelley_wallet
u = w.update_metadata(id, { name: new_name })
expect(u).to be_correct_and_respond 200
expect(w.get(id)['name']).to eq new_name
end
it "Can update_passphrase" do
w = SHELLEY.wallets
id = create_shelley_wallet
upd = w.update_passphrase(id, { old_passphrase: "Secure Passphrase",
new_passphrase: "Securer Passphrase" })
expect(upd).to be_correct_and_respond 204
end
end
it "Can see utxo" do
id = create_shelley_wallet
utxo = SHELLEY.wallets.utxo(id)
expect(utxo).to be_correct_and_respond 200
end
end
describe CardanoWallet::Shelley::Addresses do
after(:each) do
teardown
end
it "Can list addresses" do
id = create_shelley_wallet
shelley_addr = CardanoWallet.new.shelley.addresses
addresses = shelley_addr.list id
expect(addresses).to be_correct_and_respond 200
expect(addresses.size).to eq 20
addresses.each_with_index do |a, i|
expect(a['derivation_path']).to eq ['1852H', '1815H', '0H', '0', i.to_s]
end
addresses_unused = shelley_addr.list id, { state: "used" }
expect(addresses_unused).to be_correct_and_respond 200
expect(addresses_unused.size).to eq 0
addresses_unused = shelley_addr.list id, { state: "unused" }
expect(addresses_unused).to be_correct_and_respond 200
expect(addresses_unused.size).to eq 20
addresses_unused.each_with_index do |a, i|
expect(a['derivation_path']).to eq ['1852H', '1815H', '0H', '0', i.to_s]
end
end
end
describe CardanoWallet::Shelley::CoinSelections do
after(:each) do
teardown
end
it "I could trigger random coin selection - if had money" do
wid = create_shelley_wallet
addresses = SHELLEY.addresses.list(wid)
addr_amount = [
{ addresses[0]['id'] => 123 },
{ addresses[1]['id'] => 456 }
]
rnd = SHELLEY.coin_selections.random wid, addr_amount
expect(rnd).to be_correct_and_respond 403
expect(rnd.to_s).to include "not_enough_money"
end
end
describe CardanoWallet::Shelley::Transactions do
after(:each) do
teardown
end
it "I could get a tx if I had proper id" do
wid = create_shelley_wallet
txs = SHELLEY.transactions
g = txs.get(wid, TXID)
expect(g).to be_correct_and_respond 404
expect(g.to_s).to include "no_such_transaction"
end
it "Can list transactions" do
id = create_shelley_wallet
txs = SHELLEY.transactions
l = txs.list(id)
l_ext = txs.list(id, { start: "2012-09-25T10:15:00Z",
end: "2016-11-21T10:15:00Z",
order: "ascending" })
l_bad = txs.list(id, { order: "bad_order" })
expect(l).to be_correct_and_respond 200
expect(l_ext).to be_correct_and_respond 200
expect(l_bad).to be_correct_and_respond 400
end
it "I could create transaction - if I had money" do
id = create_shelley_wallet
target_id = create_shelley_wallet
address = SHELLEY.addresses.list(target_id)[0]['id']
txs = SHELLEY.transactions
amt = [{ address => 1000000 }]
tx_sent = txs.create(id, PASS, amt)
expect(tx_sent).to be_correct_and_respond 403
expect(tx_sent.to_s).to include "not_enough_money"
end
it "I could create transaction using rewards - if I had money" do
id = create_shelley_wallet
target_id = create_shelley_wallet
address = SHELLEY.addresses.list(target_id)[0]['id']
txs = SHELLEY.transactions
amt = [{ address => 1000000 }]
tx_sent = txs.create(id, PASS, amt, 'self')
expect(tx_sent).to be_correct_and_respond 403
expect(tx_sent.to_s).to include "not_enough_money"
end
it "I could estimate transaction fee - if I had money" do
id = create_shelley_wallet
target_id = create_shelley_wallet
address = SHELLEY.addresses.list(target_id)[0]['id']
amt = [{ address => 1000000 }]
txs = SHELLEY.transactions
fees = txs.payment_fees(id, amt)
expect(fees).to be_correct_and_respond 403
expect(fees.to_s).to include "not_enough_money"
fees = txs.payment_fees(id, amt, 'self')
expect(fees).to be_correct_and_respond 403
expect(fees.to_s).to include "not_enough_money"
metadata = { "0" => { "string" => "cardano" },
"1" => { "int" => 14 },
"2" => { "bytes" => "2512a00e9653fe49a44a5886202e24d77eeb998f" },
"3" => { "list" => [ { "int" => 14 }, { "int" => 42 }, { "string" => "1337" } ] },
"4" => { "map" => [ { "k" => { "string" => "key" }, "v" => { "string" => "value" } },
{ "k" => { "int" => 14 }, "v" => { "int" => 42 } } ] } }
fees = txs.payment_fees(id, amt, 'self', metadata)
expect(fees).to be_correct_and_respond 403
expect(fees.to_s).to include "not_enough_money"
end
it "I could forget transaction" do
id = create_shelley_wallet
txs = SHELLEY.transactions
res = txs.forget(id, TXID)
expect(res).to be_correct_and_respond 404
end
end
describe CardanoWallet::Shelley::StakePools do
after(:each) do
settings = CardanoWallet.new.misc.settings
s = settings.update({ :pool_metadata_source => "none" })
teardown
end
it "ADP-634 - Pool metadata is updated when settings are updated" do
settings = CardanoWallet.new.misc.settings
pools = SHELLEY.stake_pools
s = settings.update({ :pool_metadata_source => "direct" })
expect(s).to be_correct_and_respond 204
eventually "Pools have metadata when 'pool_metadata_source' => 'direct'" do
sps = pools.list({ stake: 1000 })
sps.select { |p| p['metadata'] }.size > 0
end
s = settings.update({ :pool_metadata_source => "none" })
expect(s).to be_correct_and_respond 204
eventually "Pools have no metadata when 'pool_metadata_source' => 'none'" do
sps = pools.list({ stake: 1000 })
sps.select { |p| p['metadata'] }.size == 0
end
s = settings.update({ :pool_metadata_source => ENV['TESTS_E2E_SMASH'] })
expect(s).to be_correct_and_respond 204
eventually "Pools have metadata when 'pool_metadata_source' => '#{ENV['TESTS_E2E_SMASH']}'" do
sps = pools.list({ stake: 1000 })
sps.select { |p| p['metadata'] }.size > 0
end
s = settings.update({ :pool_metadata_source => "none" })
expect(s).to be_correct_and_respond 204
eventually "Pools have no metadata when 'pool_metadata_source' => 'none'" do
sps = pools.list({ stake: 1000 })
sps.select { |p| p['metadata'] }.size == 0
end
end
describe "Stake Pools GC Maintenance" do
matrix = [{ "direct" => "not_applicable" },
{ "none" => "not_applicable" },
{ "https://smash.cardano-testnet.iohkdev.io" => "has_run" }]
matrix.each do |tc|
it "GC metadata maintenance action on metadata source #{tc}" do
settings = CardanoWallet.new.misc.settings
pools = SHELLEY.stake_pools
s = settings.update({ :pool_metadata_source => tc.keys.first })
expect(s).to be_correct_and_respond 204
t = pools.trigger_maintenance_actions({ maintenance_action: "gc_stake_pools" })
expect(t).to be_correct_and_respond 204
eventually "Maintenance action has status = #{tc.values.first}" do
r = pools.view_maintenance_actions
(r.code == 200) && (r.to_s.include? tc.values.first)
end
end
end
end
it "I could quit stake pool - if I was delegating" do
id = create_shelley_wallet
pools = SHELLEY.stake_pools
quit = pools.quit(id, PASS)
expect(quit).to be_correct_and_respond 403
expect(quit.to_s).to include "not_delegating_to"
end
end
describe CardanoWallet::Shelley::Migrations do
after(:each) do
teardown
end
it "I could create migration plan" do
id = create_shelley_wallet
target_id = create_shelley_wallet
addrs = SHELLEY.addresses.list(target_id).map { |a| a['id'] }
plan = SHELLEY.migrations.plan(id, addrs)
expect(plan).to be_correct_and_respond 501
expect(plan.to_s).to include "not_implemented"
end
it "I could migrate all my funds" do
id = create_shelley_wallet
target_id = create_shelley_wallet
addrs = SHELLEY.addresses.list(target_id).map { |a| a['id'] }
migr = SHELLEY.migrations.migrate(id, PASS, addrs)
expect(migr).to be_correct_and_respond 501
expect(migr.to_s).to include "not_implemented"
end
end
describe CardanoWallet::Shelley::Keys do
after(:each) do
teardown
end
it "Get signed metadata" do
wid = create_shelley_wallet
["utxo_internal", "utxo_external", "mutable_account", "multisig_script"].each do |role|
id = [*0..100000].sample
res = SHELLEY.keys.sign_metadata(wid,
role,
id,
"Secure Passphrase",
{ "0" => { "string" => "cardano" } })
puts "#{wid}/#{role}/#{id}"
expect(res).to respond_with 200
end
end
it "Get public key" do
wid = create_shelley_wallet
["utxo_internal", "utxo_external", "mutable_account", "multisig_script"].each do |role|
id = [*0..100000].sample
res = SHELLEY.keys.get_public_key(wid, role, id)
puts "#{wid}/#{role}/#{id}"
expect(res).to be_correct_and_respond 200
end
end
it "Create account public key - extended = true" do
wid = create_shelley_wallet
["0H", "1H", "2147483647H", "44H"].each do |index|
res = SHELLEY.keys.create_acc_public_key(wid, index, PASS, extended = true)
expect(res).to be_correct_and_respond 202
expect(res.to_s).to include "acc"
end
end
it "Create account public key - extended = false" do
wid = create_shelley_wallet
["0H", "1H", "2147483647H", "44H"].each do |index|
res = SHELLEY.keys.create_acc_public_key(wid, index, PASS, extended = false)
expect(res).to be_correct_and_respond 202
expect(res.to_s).to include "acc"
end
end
end
end