forked from XRPLF/rippled
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfreeze-test.coffee
More file actions
851 lines (646 loc) · 27.3 KB
/
freeze-test.coffee
File metadata and controls
851 lines (646 loc) · 27.3 KB
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
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
################################### REQUIRES ###################################
extend = require 'extend'
fs = require 'fs'
assert = require 'assert'
async = require 'async'
{
Remote
UInt160
Transaction
Amount
} = require 'ripple-lib'
testutils = require './testutils'
{
LedgerState
LedgerVerifier
TestAccount
} = require './ledger-state'
{
pretty_json
server_setup_teardown
skip_or_only
submit_for_final
suite_test_bailer
} = require './batmans-belt'
################################ FREEZE OVERVIEW ###############################
'''
Freeze Feature Overview
=======================
A frozen line prevents funds from being transferred to anyone except back to the
issuer, yet does not prohibit acquisition of more of the issuer's assets, via
receipt of a Payment or placing offers to buy them.
A trust line's Flags now assigns two bits, for toggling the freeze status of
each side of a trustline.
GlobalFreeze
------------
There is also, a global freeze, toggled by a bit in the AccountRoot Flags, which
freezes ALL trust lines for an account.
Offers can not be created to buy or sell assets issued by an account with
GlobalFreeze set.
Use cases (via (David (JoelKatz) Schwartz)):
There are two basic cases. One is a case where some kind of bug or flaw causes
a large amount of an asset to somehow be created and the gateway hasn't yet
decided how it's going to handle it.
The other is a reissue where one asset is replaced by another. In a community
credit case, say someone tricks you into issuing a huge amount of an asset,
but you set the no freeze flag. You can still set global freeze to protect
others from trading valuable assets for assets you issued that are now,
unfortunately, worthless. And if you're an honest guy, you can set up a new
account and re-issue to people who are legitimate holders
NoFreeze
--------
NoFreeze, is a set only flag bit in the account root.
When this bit is set:
An account may not freeze it's side of a trustline
The NoFreeze bit can not be cleared
The GlobalFreeze flag bit can not cleared
GlobalFreeze can be used as a matter of last resort
Flag Definitions
================
LedgerEntry flags
-----------------
RippleState
LowFreeze 0x00400000
HighFreeze 0x00800000
AccountRoot
NoFreeze 0x00200000
GlobalFeeze 0x00400000
Transaction flags
-----------------
TrustSet (used with Flags)
SetFreeze 0x00100000
ClearFreeze 0x00200000
AccountSet (used with SetFlag/ClearFlag)
NoFreeze 6
GlobalFreeze 7
API Implications
================
transaction.Payment
-------------------
Any offers containing frozen funds found in the process of a tesSUCCESS will be
removed from the books.
transaction.OfferCreate
-----------------------
Selling an asset from a globally frozen issuer fails with tecFROZEN
Selling an asset from a frozen line fails with tecUNFUNDED_OFFER
Any offers containing frozen funds found in the process of a tesSUCCESS will be
removed from the books.
request.book_offers
-------------------
All offers selling assets from a frozen line/acount (offers created before a
freeze) will be filtered, except where in a global freeze situation where:
TakerGets.issuer == Account ($frozen_account)
request.path_find & transaction.Payment
---------------------------------------
No Path may contain frozen trustlines, or offers (placed, prior to freezing) of
assets from frozen lines.
request.account_offers
-----------------------
These offers are unfiltered, merely walking the owner directory and reporting
all offers.
'''
################################################################################
Flags =
sle:
AccountRoot:
PasswordSpent: 0x00010000
RequireDestTag: 0x00020000
RequireAuth: 0x00040000
DisallowXRP: 0x00080000
NoFreeze: 0x00200000
GlobalFreeze: 0x00400000
RippleState:
LowFreeze: 0x00400000
HighFreeze: 0x00800000
tx:
SetFlag:
AccountRoot:
NoFreeze: 6
GlobalFreeze: 7
TrustSet:
# New Flags
SetFreeze: 0x00100000
ClearFreeze: 0x00200000
Transaction.flags.TrustSet ||= {};
# Monkey Patch SetFreeze and ClearFreeze into old version of ripple-lib
Transaction.flags.TrustSet.SetFreeze = Flags.tx.TrustSet.SetFreeze
Transaction.flags.TrustSet.ClearFreeze = Flags.tx.TrustSet.ClearFreeze
GlobalFreeze = Flags.tx.SetFlag.AccountRoot.GlobalFreeze
NoFreeze = Flags.tx.SetFlag.AccountRoot.NoFreeze
#################################### CONFIG ####################################
config = testutils.init_config()
#################################### HELPERS ###################################
get_lines = (remote, acc, done) ->
args = {account: acc, ledger: 'validated'}
remote.request_account_lines args, (err, lines) ->
done(lines)
account_set_factory = (remote, ledger, alias_for) ->
(acc, fields, done) ->
tx = remote.transaction()
tx.account_set(acc)
extend tx.tx_json, fields
tx.on 'error', (err) ->
assert !err, ("Unexpected error #{ledger.pretty_json err}\n" +
"don't use this helper if expecting an error")
submit_for_final tx, (m) ->
assert.equal m.metadata?.TransactionResult, 'tesSUCCESS'
affected_root = m.metadata.AffectedNodes[0].ModifiedNode
assert.equal alias_for(affected_root.FinalFields.Account), acc
done(affected_root)
make_payment_factory = (remote, ledger) ->
(src, dst, amount, path, on_final) ->
if typeof path == 'function'
on_final = path
path = undefined
src_account = UInt160.json_rewrite src
dst_account = UInt160.json_rewrite dst
dst_amount = Amount.from_json amount
tx = remote.transaction().payment(src_account, dst_account, dst_amount)
if not path?
tx.build_path(true)
else
tx.path_add path.path
tx.send_max path.send_max
tx.on 'error', (err) ->
if err.engine_result?.slice(0,3) == 'tec'
# We can handle this in the `final`
return
assert !err, ("Unexpected error #{ledger.pretty_json err}\n" +
"don't use this helper if expecting an error")
submit_for_final tx, (m) ->
on_final m
create_offer_factory = (remote, ledger) ->
(acc, pays, gets, on_final) ->
tx = remote.transaction().offer_create(acc, pays, gets)
tx.on 'error', (err) ->
if err.engine_result?.slice(0,3) == 'tec'
# We can handle this in the `final`
return
assert !err, ("Unexpected error #{ledger.pretty_json err}\n" +
"don't use this helper if expecting an error")
submit_for_final tx, (m) ->
on_final m
ledger_state_setup = (pre_ledger) ->
post_setup = (context, done) ->
context.ledger = new LedgerState(pre_ledger,
assert,
context.remote,
config)
context.ledger.setup(
#-> # noop logging function
->
->
context.ledger.verifier().do_verify (errors) ->
assert Object.keys(errors).length == 0,
"pre_ledger errors:\n"+ pretty_json errors
done()
)
verify_ledger_state = (ledger, remote, pre_state, done) ->
{config, assert, am} = ledger
verifier = new LedgerVerifier(pre_state, remote, config, assert, am)
verifier.do_verify (errors) ->
assert Object.keys(errors).length == 0,
"ledger_state errors:\n"+ pretty_json errors
done()
book_offers_factory = (remote) ->
(pays, gets, on_book) ->
asset = (a) ->
if typeof a == 'string'
ret = {}
[ret['currency'], ret['issuer']] = a.split('/')
ret
else
a
book=
pays: asset(pays)
gets: asset(gets)
remote.request_book_offers book, (err, book) ->
if err
assert !err, "error with request_book_offers #{err}"
on_book(book)
suite_setup = (state) ->
'''
@state
The ledger state to setup, after starting the server
'''
opts =
setup_func: suiteSetup
teardown_func: suiteTeardown
post_setup: ledger_state_setup(state)
get_context = server_setup_teardown(opts)
helpers = null
helpers_factory = ->
context = {ledger, remote} = get_context()
alog = (obj) -> console.log ledger.pretty_json obj
lines_for = (acc) -> get_lines(remote, arguments...)
alias_for = (acc) -> ledger.am.lookup_alias(acc)
verify_ledger_state_before_suite = (pre) ->
suiteSetup (done) -> verify_ledger_state(ledger, remote, pre, done)
{
context: context
remote: remote
ledger: ledger
lines_for: lines_for
alog: alog
alias_for: alias_for
book_offers: book_offers_factory(remote)
create_offer: create_offer_factory(remote, ledger, alias_for)
account_set: account_set_factory(remote, ledger, alias_for)
make_payment: make_payment_factory(remote, ledger, alias_for)
verify_ledger_state_before_suite: verify_ledger_state_before_suite
}
get_helpers = -> (helpers = helpers ? helpers_factory())
{
get_context: get_context
get_helpers: get_helpers
}
##################################### TESTS ####################################
execute_if_enabled = (fn) ->
enforced = true # freeze tests enforced
fn(global.suite, enforced)
conditional_test_factory = ->
test = suite_test_bailer()
test_if = (b, args...) ->
if b
test(args...)
else
test.skip(args...)
[test, test_if]
execute_if_enabled (suite, enforced) ->
suite 'Freeze Feature', ->
suite 'RippleState Freeze', ->
# test = suite_test_bailer()
[test, test_if] = conditional_test_factory()
h = null
{get_helpers} = suite_setup
accounts:
G1: balance: ['1000.0']
bob:
balance: ['1000.0', '10-100/USD/G1']
alice:
balance: ['1000.0', '100/USD/G1']
offers: [['500.0', '100/USD/G1']]
suite 'Account with line unfrozen (proving operations normally work)', ->
test 'can make Payment on that line', (done) ->
{remote} = h = get_helpers()
h.make_payment 'alice', 'bob', '1/USD/G1', (m) ->
assert.equal m.metadata?.TransactionResult, 'tesSUCCESS'
done()
test 'can receive Payment on that line', (done) ->
h.make_payment 'bob', 'alice', '1/USD/G1', (m) ->
assert.equal m.metadata?.TransactionResult, 'tesSUCCESS'
done()
suite 'Is created via a TrustSet with SetFreeze flag', ->
test 'sets LowFreeze | HighFreeze flags', (done) ->
{remote} = h
tx = remote.transaction()
tx.ripple_line_set('G1', '0/USD/bob')
tx.set_flags('SetFreeze')
submit_for_final tx, (m) ->
assert.equal m.metadata?.TransactionResult, 'tesSUCCESS'
affected = m.metadata.AffectedNodes
assert affected.length > 1, "only one affected node implies a noop"
ripple_state = affected[1].ModifiedNode
final = ripple_state.FinalFields
assert.equal h.alias_for(final.LowLimit.issuer), 'G1'
assert final.Flags & Flags.sle.RippleState.LowFreeze
assert !(final.Flags & Flags.sle.RippleState.HighFreeze)
done()
suite 'Account with line frozen by issuer', ->
test 'can buy more assets on that line', (done) ->
h.create_offer 'bob', '5/USD/G1', '25.0', (m) ->
meta = m.metadata
assert.equal meta.TransactionResult, 'tesSUCCESS'
line = meta.AffectedNodes[3]['ModifiedNode'].FinalFields
assert.equal h.alias_for(line.HighLimit.issuer), 'bob'
assert.equal line.Balance.value, '-15' # HighLimit means balance inverted
done()
test_if enforced, 'can not sell assets from that line', (done) ->
h.create_offer 'bob', '1.0', '5/USD/G1', (m) ->
assert.equal m.engine_result, 'tecUNFUNDED_OFFER'
done()
test 'can receive Payment on that line', (done) ->
h.make_payment 'alice', 'bob', '1/USD/G1', (m) ->
assert.equal m.metadata?.TransactionResult, 'tesSUCCESS'
done()
test_if enforced, 'can not make Payment from that line', (done) ->
h.make_payment 'bob', 'alice', '1/USD/G1', (m) ->
assert.equal m.engine_result, 'tecPATH_DRY'
done()
suite 'request_account_lines', ->
test 'shows `freeze_peer` and `freeze` respectively', (done) ->
async.parallel [
(next) ->
h.lines_for 'G1', (lines) ->
for line in lines.lines
if h.alias_for(line.account) == 'bob'
assert.equal line.freeze, true
assert.equal line.balance, '-16'
# unless we get here, the test will hang alerting us to
# something amiss
next() # setImmediate ;)
break
(next) ->
h.lines_for 'bob', (lines) ->
for line in lines.lines
if h.alias_for(line.account) == 'G1'
assert.equal line.freeze_peer, true
assert.equal line.balance, '16'
next()
break
], ->
done()
suite 'Is cleared via a TrustSet with ClearFreeze flag', ->
test 'sets LowFreeze | HighFreeze flags', (done) ->
{remote} = h
tx = remote.transaction()
tx.ripple_line_set('G1', '0/USD/bob')
tx.set_flags('ClearFreeze')
submit_for_final tx, (m) ->
assert.equal m.metadata?.TransactionResult, 'tesSUCCESS'
affected = m.metadata.AffectedNodes
ripple_state = affected[1].ModifiedNode
final = ripple_state.FinalFields
assert.equal h.alias_for(final.LowLimit.issuer), 'G1'
assert !(final.Flags & Flags.sle.RippleState.LowFreeze)
assert !(final.Flags & Flags.sle.RippleState.HighFreeze)
done()
suite 'Global (AccountRoot) Freeze', ->
# NoFreeze: 0x00200000
# GlobalFreeze: 0x00400000
# test = suite_test_bailer()
[test, test_if] = conditional_test_factory()
h = null
{get_helpers} = suite_setup
accounts:
G1:
balance: ['12000.0']
offers: [['10000.0', '100/USD/G1'], ['100/USD/G1', '10000.0']]
A1:
balance: ['1000.0', '1000/USD/G1']
offers: [['10000.0', '100/USD/G1']]
trusts: ['1200/USD/G1']
A2:
balance: ['20000.0', '100/USD/G1']
trusts: ['200/USD/G1']
offers: [['100/USD/G1', '10000.0']]
A3:
balance: ['20000.0', '100/BTC/G1']
A4:
balance: ['20000.0', '100/BTC/G1']
suite 'Is toggled via AccountSet using SetFlag and ClearFlag', ->
test 'SetFlag GlobalFreeze should set 0x00400000 in Flags', (done) ->
{remote} = h = get_helpers()
h.account_set 'G1', SetFlag: GlobalFreeze, (root) ->
new_flags = root.FinalFields.Flags
assert !(new_flags & Flags.sle.AccountRoot.NoFreeze)
assert (new_flags & Flags.sle.AccountRoot.GlobalFreeze)
done()
test 'ClearFlag GlobalFreeze should clear 0x00400000 in Flags', (done) ->
{remote} = h = get_helpers()
h.account_set 'G1', ClearFlag: GlobalFreeze, (root) ->
new_flags = root.FinalFields.Flags
assert !(new_flags & Flags.sle.AccountRoot.NoFreeze)
assert !(new_flags & Flags.sle.AccountRoot.GlobalFreeze)
done()
suite 'Account without GlobalFreeze (proving operations normally work)', ->
suite 'have visible offers', ->
test 'where taker_gets is $unfrozen_issuer', (done) ->
{remote} = h = get_helpers()
h.book_offers 'XRP', 'USD/G1', (book) ->
assert.equal book.offers.length, 2
aliases = (h.alias_for(o.Account) for o in book.offers).sort()
assert.equal aliases[0], 'A1'
assert.equal aliases[1], 'G1'
done()
test 'where taker_pays is $unfrozen_issuer', (done) ->
h.book_offers 'USD/G1', 'XRP', (book) ->
assert.equal book.offers.length, 2
aliases = (h.alias_for(o.Account) for o in book.offers).sort()
assert.equal aliases[0], 'A2'
assert.equal aliases[1], 'G1'
done()
suite 'it\'s assets can be', ->
test 'bought on the market', (next) ->
h.create_offer 'A3', '1/BTC/G1', '1.0', (m) ->
assert.equal m.metadata?.TransactionResult, 'tesSUCCESS'
next()
test 'sold on the market', (next) ->
h.create_offer 'A4', '1.0', '1/BTC/G1', (m) ->
assert.equal m.metadata?.TransactionResult, 'tesSUCCESS'
next()
suite 'Payments', ->
test 'direct issues can be sent', (done) ->
{remote} = h = get_helpers()
h.make_payment 'G1', 'A2', '1/USD/G1', (m) ->
assert.equal m.metadata?.TransactionResult, 'tesSUCCESS'
done()
test 'direct redemptions can be sent', (done) ->
h.make_payment 'A2', 'G1', '1/USD/G1', (m) ->
assert.equal m.metadata?.TransactionResult, 'tesSUCCESS'
done()
test 'via rippling can be sent', (done) ->
h.make_payment 'A2', 'A1', '1/USD/G1', (m) ->
assert.equal m.metadata?.TransactionResult, 'tesSUCCESS'
done()
test 'via rippling can be sent back', (done) ->
h.make_payment 'A2', 'A1', '1/USD/G1', (m) ->
assert.equal m.metadata?.TransactionResult, 'tesSUCCESS'
done()
suite 'Account with GlobalFreeze', ->
suite 'Needs to set GlobalFreeze first', ->
test 'SetFlag GlobalFreeze will toggle back to freeze', (done) ->
h.account_set 'G1', SetFlag: GlobalFreeze, (root) ->
new_flags = root.FinalFields.Flags
assert !(new_flags & Flags.sle.AccountRoot.NoFreeze)
assert (new_flags & Flags.sle.AccountRoot.GlobalFreeze)
done()
suite 'it\'s assets can\'t be', ->
test_if enforced, 'bought on the market', (next) ->
h.create_offer 'A3', '1/BTC/G1', '1.0', (m) ->
assert.equal m.engine_result, 'tecFROZEN'
next()
test_if enforced, 'sold on the market', (next) ->
h.create_offer 'A4', '1.0', '1/BTC/G1', (m) ->
assert.equal m.engine_result, 'tecFROZEN'
next()
suite 'it\'s offers are filtered', ->
test_if enforced, 'account_offers always '+
'shows their own offers', (done) ->
{remote} = h = get_helpers()
args = { account: 'G1', ledger: 'validated' }
remote.request_account_offers args, (err, res) ->
assert.equal res.offers.length, 2
done()
test.skip 'books_offers(*, $frozen_account/*) shows offers '+
'owned by $frozen_account only', (done) ->
h.book_offers 'XRP', 'USD/G1', (book) ->
# h.alog book.offers
assert.equal book.offers.length, 1
done()
test.skip 'books_offers($frozen_account/*, *) shows '+
'no offers', (done) ->
h.book_offers 'USD/G1', 'XRP', (book) ->
assert.equal book.offers.length, 0
done()
test_if enforced, 'books_offers(*, $frozen_account/*) shows offers '+
'owned by $frozen_account only (broken) ', (done) ->
h.book_offers 'XRP', 'USD/G1', (book) ->
# h.alog book.offers
assert.equal book.offers.length, 2
done()
test_if enforced, 'books_offers($frozen_account/*, *) '+
'shows no offers (broken)', (done) ->
h.book_offers 'USD/G1', 'XRP', (book) ->
assert.equal book.offers.length, 2
done()
suite 'Payments', ->
test 'direct issues can be sent', (done) ->
{remote} = h = get_helpers()
h.make_payment 'G1', 'A2', '1/USD/G1', (m) ->
assert.equal m.metadata?.TransactionResult, 'tesSUCCESS'
done()
test 'direct redemptions can be sent', (done) ->
h.make_payment 'A2', 'G1', '1/USD/G1', (m) ->
assert.equal m.metadata?.TransactionResult, 'tesSUCCESS'
done()
test_if enforced, 'via rippling cant be sent', (done) ->
h.make_payment 'A2', 'A1', '1/USD/G1', (m) ->
assert.equal m.engine_result, 'tecPATH_DRY'
done()
suite 'Accounts with NoFreeze', ->
test = suite_test_bailer()
h = null
{get_helpers} = suite_setup
accounts:
G1: balance: ['12000.0']
A1: balance: ['1000.0', '1000/USD/G1']
suite 'TrustSet NoFreeze', ->
test 'should set 0x00200000 in Flags', (done) ->
h = get_helpers()
h.account_set 'G1', SetFlag: NoFreeze, (root) ->
new_flags = root.FinalFields.Flags
assert (new_flags & Flags.sle.AccountRoot.NoFreeze)
assert !(new_flags & Flags.sle.AccountRoot.GlobalFreeze)
done()
test 'can not be cleared', (done) ->
h.account_set 'G1', ClearFlag: NoFreeze, (root) ->
new_flags = root.FinalFields.Flags
assert (new_flags & Flags.sle.AccountRoot.NoFreeze)
assert !(new_flags & Flags.sle.AccountRoot.GlobalFreeze)
done()
suite 'GlobalFreeze', ->
test 'can set GlobalFreeze', (done) ->
h.account_set 'G1', SetFlag: GlobalFreeze, (root) ->
new_flags = root.FinalFields.Flags
assert (new_flags & Flags.sle.AccountRoot.NoFreeze)
assert (new_flags & Flags.sle.AccountRoot.GlobalFreeze)
done()
test 'can not unset GlobalFreeze', (done) ->
h.account_set 'G1', ClearFlag: GlobalFreeze, (root) ->
new_flags = root.FinalFields.Flags
assert (new_flags & Flags.sle.AccountRoot.NoFreeze)
assert (new_flags & Flags.sle.AccountRoot.GlobalFreeze)
done()
suite 'their trustlines', ->
test 'can\'t be frozen', (done) ->
{remote} = h = get_helpers()
tx = remote.transaction()
tx.ripple_line_set('G1', '0/USD/A1')
tx.set_flags('SetFreeze')
submit_for_final tx, (m) ->
assert.equal m.metadata?.TransactionResult, 'tesSUCCESS'
affected = m.metadata.AffectedNodes
assert.equal affected.length, 1
affected_type = affected[0]['ModifiedNode'].LedgerEntryType
assert.equal affected_type, 'AccountRoot'
done()
suite 'Offers for frozen trustlines (not GlobalFreeze)', ->
# test = suite_test_bailer()
[test, test_if] = conditional_test_factory()
remote = h = null
{get_helpers} = suite_setup
accounts:
G1:
balance: ['1000.0']
A2:
balance: ['2000.0']
trusts: ['1000/USD/G1']
A3:
balance: ['1000.0', '2000/USD/G1']
offers: [['1000.0', '1000/USD/G1']]
A4:
balance: ['1000.0', '2000/USD/G1']
suite 'will be removed by Payment with tesSUCCESS', ->
test 'can normally make a payment partially consuming offer', (done) ->
{remote} = h = get_helpers()
path =
path: [{"currency": "USD", "issuer": "G1"}]
send_max: '1.0'
h.make_payment 'A2', 'G1', '1/USD/G1', path, (m) ->
assert.equal m.metadata?.TransactionResult, 'tesSUCCESS'
done()
test 'offer was only partially consumed', (done) ->
args = { account: 'A3', ledger: 'validated' }
remote.request_account_offers args, (err, res) ->
assert res.offers.length == 1
assert res.offers[0].taker_gets.value, '999'
done()
test 'someone else creates an offer providing liquidity', (done) ->
h.create_offer 'A4', '999.0', '999/USD/G1', (m) ->
assert.equal m.metadata?.TransactionResult, 'tesSUCCESS'
affected = m.metadata.AffectedNodes
done()
test 'owner of partially consumed offer\'s line is frozen', (done) ->
tx = remote.transaction()
tx.ripple_line_set('G1', '0/USD/A3')
tx.set_flags('SetFreeze')
submit_for_final tx, (m) ->
assert.equal m.metadata?.TransactionResult, 'tesSUCCESS'
affected = m.metadata.AffectedNodes
ripple_state = affected[1].ModifiedNode
final = ripple_state.FinalFields
assert.equal h.alias_for(final.HighLimit.issuer), 'G1'
assert !(final.Flags & Flags.sle.RippleState.LowFreeze)
assert (final.Flags & Flags.sle.RippleState.HighFreeze)
done()
test 'Can make a payment via the new offer', (done) ->
path =
path: [{"currency": "USD", "issuer": "G1"}]
send_max: '1.0'
h.make_payment 'A2', 'G1', '1/USD/G1', path, (m) ->
# assert.equal m.engine_result, 'tecPATH_PARTIAL' # tecPATH_DRY
assert.equal m.metadata.TransactionResult, 'tesSUCCESS' # tecPATH_DRY
done()
test_if enforced, 'Partially consumed offer was removed by tes* payment', (done) ->
args = { account: 'A3', ledger: 'validated' }
remote.request_account_offers args, (err, res) ->
assert res.offers.length == 0
done()
suite 'will be removed by OfferCreate with tesSUCCESS', ->
test_if enforced, 'freeze the new offer', (done) ->
tx = remote.transaction()
tx.ripple_line_set('G1', '0/USD/A4')
tx.set_flags('SetFreeze')
submit_for_final tx, (m) ->
assert.equal m.metadata?.TransactionResult, 'tesSUCCESS'
affected = m.metadata.AffectedNodes
ripple_state = affected[0].ModifiedNode
final = ripple_state.FinalFields
assert.equal h.alias_for(final.LowLimit.issuer), 'G1'
assert (final.Flags & Flags.sle.RippleState.LowFreeze)
assert !(final.Flags & Flags.sle.RippleState.HighFreeze)
done()
test_if enforced, 'can no longer create a crossing offer', (done) ->
h.create_offer 'A2', '999/USD/G1', '999.0', (m) ->
assert.equal m.metadata?.TransactionResult, 'tesSUCCESS'
affected = m.metadata.AffectedNodes
created = affected[5].CreatedNode
new_fields = created.NewFields
assert.equal h.alias_for(new_fields.Account), 'A2'
done()
test_if enforced, 'offer was removed by offer_create', (done) ->
args = { account: 'A4', ledger: 'validated' }
remote.request_account_offers args, (err, res) ->
assert res.offers.length == 0
done()