-
Notifications
You must be signed in to change notification settings - Fork 5
/
feature_rewards.py
executable file
·1270 lines (1040 loc) · 60 KB
/
feature_rewards.py
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
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
# Copyright (c) 2017 The Bitcoin Core developers
# Copyright (c) 2017-2020 The Raven Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Testing rewards use cases"""
from test_framework.test_framework import RavenTestFramework
from test_framework.util import assert_equal, assert_raises_rpc_error, assert_contains, Decimal
# noinspection PyAttributeOutsideInit
class RewardsTest(RavenTestFramework):
def set_test_params(self):
self.setup_clean_chain = True
self.num_nodes = 4
self.extra_args = [["-assetindex", "-debug=rewards"], ["-assetindex", "-minrewardheight=15"], ["-assetindex"],
["-assetindex"]]
def activate_assets(self):
self.log.info("Generating RVN for node[0] and activating assets...")
n0, n1, n2 = self.nodes[0], self.nodes[1], self.nodes[2]
n0.generate(1)
self.sync_all()
n0.generate(431)
self.sync_all()
assert_equal("active", n0.getblockchaininfo()["bip9_softforks"]["assets"]["status"])
# Basic functionality test - RVN reward
# - create the main owner address
# - mine blocks to have enough RVN for the reward payments, plus purchasing the asset
# - issue the STOCK1 asset to the owner
# - create 5 shareholder addresses
# - distribute different amounts of the STOCK1 asset to each of the shareholder addresses
# - mine some blocks
# - retrieve the current chain height
# - distribute an RVN reward amongst the shareholders
# - verify that each one receives the expected amount of reward RVN
def basic_test_rvn(self):
self.log.info("Running basic RVN reward test!")
n0, n1, n2 = self.nodes[0], self.nodes[1], self.nodes[2]
self.log.info("Creating owner address")
owner_addr0 = n0.getnewaddress()
# self.log.info(f"Owner address: {owner_addr0}")
self.log.info("Creating distributor address")
dist_addr0 = n0.getnewaddress()
# self.log.info(f"Distributor address: {dist_addr0}")
self.log.info("Providing funding")
self.nodes[0].sendtoaddress(owner_addr0, 1000)
n0.generate(10)
self.sync_all()
self.log.info("Issuing STOCK1 asset")
n0.issue(asset_name="STOCK1", qty=10000, to_address=owner_addr0, change_address="", units=4, reissuable=True, has_ipfs=False)
n0.generate(10)
self.sync_all()
self.log.info("Checking listassetbalancesbyaddress()...")
assert_equal(n0.listassetbalancesbyaddress(owner_addr0)["STOCK1"], 10000)
self.log.info("Transferring all assets to a single address for tracking")
n0.transfer(asset_name="STOCK1", qty=10000, to_address=dist_addr0)
n0.generate(10)
self.sync_all()
assert_equal(n0.listassetbalancesbyaddress(dist_addr0)["STOCK1"], 10000)
self.log.info("Creating shareholder addresses")
shareholder_addr0 = n0.getnewaddress()
shareholder_addr1 = n1.getnewaddress()
shareholder_addr2 = n2.getnewaddress()
shareholder_addr3 = n1.getnewaddress()
shareholder_addr4 = n0.getnewaddress()
self.log.info("Distributing shares")
n0.transfer(asset_name="STOCK1", qty=200, to_address=shareholder_addr0, message="", expire_time=0, change_address="", asset_change_address=dist_addr0)
n0.transfer(asset_name="STOCK1", qty=300, to_address=shareholder_addr1, message="", expire_time=0, change_address="", asset_change_address=dist_addr0)
n0.transfer(asset_name="STOCK1", qty=400, to_address=shareholder_addr2, message="", expire_time=0, change_address="", asset_change_address=dist_addr0)
n0.transfer(asset_name="STOCK1", qty=500, to_address=shareholder_addr3, message="", expire_time=0, change_address="", asset_change_address=dist_addr0)
n0.transfer(asset_name="STOCK1", qty=600, to_address=shareholder_addr4, message="", expire_time=0, change_address="", asset_change_address=dist_addr0)
n0.generate(10)
self.sync_all()
self.log.info("Verifying share distribution")
# ownerDetails = n0.listmyassets("STOCK1", True)
# self.log.info(f"Owner: {ownerDetails}")
# distDetails = n0.listassetbalancesbyaddress(dist_addr0)
# self.log.info(f"Change: {distDetails}")
assert_equal(n1.listassetbalancesbyaddress(shareholder_addr0)["STOCK1"], 200)
assert_equal(n1.listassetbalancesbyaddress(shareholder_addr1)["STOCK1"], 300)
assert_equal(n0.listassetbalancesbyaddress(shareholder_addr2)["STOCK1"], 400)
assert_equal(n2.listassetbalancesbyaddress(shareholder_addr3)["STOCK1"], 500)
assert_equal(n2.listassetbalancesbyaddress(shareholder_addr4)["STOCK1"], 600)
assert_equal(n0.listassetbalancesbyaddress(dist_addr0)["STOCK1"], 8000)
self.log.info("Mining blocks")
n0.generate(200)
self.sync_all()
self.log.info("Providing additional funding")
self.nodes[0].sendtoaddress(owner_addr0, 2000)
n0.generate(100)
self.sync_all()
self.log.info("Retrieving chain height")
tgt_block_height = n0.getblockchaininfo()["blocks"] + 100
self.log.info("Requesting snapshot of STOCK1 ownership in 100 blocks")
n0.requestsnapshot(asset_name="STOCK1", block_height=tgt_block_height)
n0.generate(61)
self.log.info("Retrieving snapshot request")
snap_shot_req = n0.getsnapshotrequest(asset_name="STOCK1", block_height=tgt_block_height)
assert_equal(snap_shot_req["asset_name"], "STOCK1")
assert_equal(snap_shot_req["block_height"], tgt_block_height)
self.log.info("Skipping forward to allow snapshot to process")
n0.generate(100)
self.sync_all()
self.log.info("Retrieving snapshot for ownership validation")
snap_shot = n0.getsnapshot(asset_name="STOCK1", block_height=tgt_block_height)
assert_equal(snap_shot["name"], "STOCK1")
assert_equal(snap_shot["height"], tgt_block_height)
owner0 = False
owner1 = False
owner2 = False
owner3 = False
owner4 = False
owner5 = False
for ownerAddr in snap_shot["owners"]:
# self.log.info(f"Found owner {ownerAddr}")
if ownerAddr["address"] == shareholder_addr0:
assert_equal(ownerAddr["amount_owned"], 200)
owner0 = True
elif ownerAddr["address"] == shareholder_addr1:
assert_equal(ownerAddr["amount_owned"], 300)
owner1 = True
elif ownerAddr["address"] == shareholder_addr2:
assert_equal(ownerAddr["amount_owned"], 400)
owner2 = True
elif ownerAddr["address"] == shareholder_addr3:
assert_equal(ownerAddr["amount_owned"], 500)
owner3 = True
elif ownerAddr["address"] == shareholder_addr4:
assert_equal(ownerAddr["amount_owned"], 600)
owner4 = True
elif ownerAddr["address"] == dist_addr0:
assert_equal(ownerAddr["amount_owned"], 8000)
owner5 = True
assert_equal(owner0, True)
assert_equal(owner1, True)
assert_equal(owner2, True)
assert_equal(owner3, True)
assert_equal(owner4, True)
assert_equal(owner5, True)
# listassetbalancesbyaddress only lists the most recently delivered amount
# for the address, which I believe is a bug, since there can only be one
# key in the result object with the asset name.
# self.log.info("Moving shares after snapshot")
# n0.transfer(asset_name="STOCK1", qty=100, to_address=shareholder_addr0, message="", expire_time=0, change_address="", asset_change_address=dist_addr0)
# n0.transfer(asset_name="STOCK1", qty=100, to_address=shareholder_addr1, message="", expire_time=0, change_address="", asset_change_address=dist_addr0)
# n0.transfer(asset_name="STOCK1", qty=100, to_address=shareholder_addr2, message="", expire_time=0, change_address="", asset_change_address=dist_addr0)
# n0.transfer(asset_name="STOCK1", qty=100, to_address=shareholder_addr3, message="", expire_time=0, change_address="", asset_change_address=dist_addr0)
# n0.transfer(asset_name="STOCK1", qty=100, to_address=shareholder_addr4, message="", expire_time=0, change_address="", asset_change_address=dist_addr0)
# n0.generate(100)
# self.sync_all()
# self.log.info("Verifying share distribution after snapshot")
# assert_equal(n2.listassetbalancesbyaddress(shareholder_addr0)["STOCK1"], 300)
# assert_equal(n2.listassetbalancesbyaddress(shareholder_addr1)["STOCK1"], 400)
# assert_equal(n1.listassetbalancesbyaddress(shareholder_addr2)["STOCK1"], 500)
# assert_equal(n0.listassetbalancesbyaddress(shareholder_addr3)["STOCK1"], 600)
# assert_equal(n0.listassetbalancesbyaddress(shareholder_addr4)["STOCK1"], 700)
self.log.info("Initiating reward payout")
n0.distributereward(asset_name="STOCK1", snapshot_height=tgt_block_height, distribution_asset_name="RVN",
gross_distribution_amount=2000, exception_addresses=dist_addr0)
n0.generate(10)
self.sync_all()
# Inexplicably, order matters here. We need to verify the amount
# using the node that created the address (?!)
self.log.info("Verifying RVN holdings after payout")
assert_equal(n0.getreceivedbyaddress(shareholder_addr0, 0), 200)
assert_equal(n1.getreceivedbyaddress(shareholder_addr1, 0), 300)
assert_equal(n2.getreceivedbyaddress(shareholder_addr2, 0), 400)
assert_equal(n1.getreceivedbyaddress(shareholder_addr3, 0), 500)
assert_equal(n0.getreceivedbyaddress(shareholder_addr4, 0), 600)
# Basic functionality test - ASSET reward
# - create the main owner address
# - mine blocks to have enough RVN for the reward fees, plus purchasing the asset
# - issue the STOCK2 asset to the owner
# - create 5 shareholder addresses
# - issue the PAYOUT1 asset to the owner
# - distribute different amounts of the PAYOUT1 asset to each of the shareholder addresses
# - mine some blocks
# - retrieve the current chain height
# - distribute reward of PAYOUT1 asset units amongst the shareholders
# - verify that each one receives the expected amount of PAYOUT1
def basic_test_asset(self):
self.log.info("Running basic ASSET reward test!")
n0, n1, n2 = self.nodes[0], self.nodes[1], self.nodes[2]
self.log.info("Creating owner address")
owner_addr0 = n0.getnewaddress()
# self.log.info(f"Owner address: {owner_addr0}")
self.log.info("Creating distributor address")
dist_addr0 = n0.getnewaddress()
# self.log.info(f"Distributor address: {dist_addr0}")
self.log.info("Providing funding")
self.nodes[0].sendtoaddress(owner_addr0, 1000)
n0.generate(10)
self.sync_all()
self.log.info("Issuing STOCK2 asset")
n0.issue(asset_name="STOCK2", qty=10000, to_address=owner_addr0, change_address="", units=4, reissuable=True, has_ipfs=False)
n0.generate(10)
self.sync_all()
self.log.info("Creating shareholder addresses")
shareholder_addr0 = n0.getnewaddress()
shareholder_addr1 = n1.getnewaddress()
shareholder_addr2 = n2.getnewaddress()
shareholder_addr3 = n1.getnewaddress()
shareholder_addr4 = n0.getnewaddress()
self.log.info("Distributing shares")
n0.transfer(asset_name="STOCK2", qty=200, to_address=shareholder_addr0, message="", expire_time=0, change_address="", asset_change_address=dist_addr0)
n0.transfer(asset_name="STOCK2", qty=300, to_address=shareholder_addr1, message="", expire_time=0, change_address="", asset_change_address=dist_addr0)
n0.transfer(asset_name="STOCK2", qty=400, to_address=shareholder_addr2, message="", expire_time=0, change_address="", asset_change_address=dist_addr0)
n0.transfer(asset_name="STOCK2", qty=500, to_address=shareholder_addr3, message="", expire_time=0, change_address="", asset_change_address=dist_addr0)
n0.transfer(asset_name="STOCK2", qty=600, to_address=shareholder_addr4, message="", expire_time=0, change_address="", asset_change_address=dist_addr0)
n0.generate(10)
self.sync_all()
self.log.info("Verifying share distribution")
assert_equal(n1.listassetbalancesbyaddress(shareholder_addr0)["STOCK2"], 200)
assert_equal(n1.listassetbalancesbyaddress(shareholder_addr1)["STOCK2"], 300)
assert_equal(n0.listassetbalancesbyaddress(shareholder_addr2)["STOCK2"], 400)
assert_equal(n2.listassetbalancesbyaddress(shareholder_addr3)["STOCK2"], 500)
assert_equal(n2.listassetbalancesbyaddress(shareholder_addr4)["STOCK2"], 600)
self.log.info("Mining blocks")
n0.generate(200)
self.sync_all()
self.log.info("Issuing PAYOUT1 asset")
n0.issue(asset_name="PAYOUT1", qty=10000, to_address=owner_addr0, change_address="", units=8, reissuable=True, has_ipfs=False)
n0.generate(10)
self.sync_all()
self.log.info("Retrieving chain height")
tgt_block_height = n0.getblockchaininfo()["blocks"] + 100
self.log.info("Requesting snapshot of STOCK2 ownership in 100 blocks")
n0.requestsnapshot(asset_name="STOCK2", block_height=tgt_block_height)
# Mine 60 blocks to make sure the -minrewardsheight is met
n0.generate(61)
self.log.info("Retrieving snapshot request")
snap_shot_req = n0.getsnapshotrequest(asset_name="STOCK2", block_height=tgt_block_height)
assert_equal(snap_shot_req["asset_name"], "STOCK2")
assert_equal(snap_shot_req["block_height"], tgt_block_height)
self.log.info("Skipping forward to allow snapshot to process")
n0.generate(100)
self.sync_all()
self.log.info("Retrieving snapshot for ownership validation")
snap_shot = n0.getsnapshot(asset_name="STOCK2", block_height=tgt_block_height)
assert_equal(snap_shot["name"], "STOCK2")
assert_equal(snap_shot["height"], tgt_block_height)
owner0 = False
owner1 = False
owner2 = False
owner3 = False
owner4 = False
for ownerAddr in snap_shot["owners"]:
if ownerAddr["address"] == shareholder_addr0:
assert_equal(ownerAddr["amount_owned"], 200)
owner0 = True
elif ownerAddr["address"] == shareholder_addr1:
assert_equal(ownerAddr["amount_owned"], 300)
owner1 = True
elif ownerAddr["address"] == shareholder_addr2:
assert_equal(ownerAddr["amount_owned"], 400)
owner2 = True
elif ownerAddr["address"] == shareholder_addr3:
assert_equal(ownerAddr["amount_owned"], 500)
owner3 = True
elif ownerAddr["address"] == shareholder_addr4:
assert_equal(ownerAddr["amount_owned"], 600)
owner4 = True
assert_equal(owner0, True)
assert_equal(owner1, True)
assert_equal(owner2, True)
assert_equal(owner3, True)
assert_equal(owner4, True)
# listassetbalancesbyaddress only lists the most recently delivered amount
# for the address, which I believe is a bug, since there can only be one
# key in the result object with the asset name.
# self.log.info("Moving shares after snapshot")
# n0.transfer(asset_name="STOCK2", qty=100, to_address=shareholder_addr0, message="", expire_time=0, change_address="", asset_change_address=dist_addr0)
# n0.transfer(asset_name="STOCK2", qty=100, to_address=shareholder_addr1, message="", expire_time=0, change_address="", asset_change_address=dist_addr0)
# n0.transfer(asset_name="STOCK2", qty=100, to_address=shareholder_addr2, message="", expire_time=0, change_address="", asset_change_address=dist_addr0)
# n0.transfer(asset_name="STOCK2", qty=100, to_address=shareholder_addr3, message="", expire_time=0, change_address="", asset_change_address=dist_addr0)
# n0.transfer(asset_name="STOCK2", qty=100, to_address=shareholder_addr4, message="", expire_time=0, change_address="", asset_change_address=dist_addr0)
# n0.generate(100)
# self.sync_all()
# self.log.info("Verifying share distribution after snapshot")
# assert_equal(n2.listassetbalancesbyaddress(shareholder_addr0)["STOCK2"], 300)
# assert_equal(n2.listassetbalancesbyaddress(shareholder_addr1)["STOCK2"], 400)
# assert_equal(n1.listassetbalancesbyaddress(shareholder_addr2)["STOCK2"], 500)
# assert_equal(n0.listassetbalancesbyaddress(shareholder_addr3)["STOCK2"], 600)
# assert_equal(n0.listassetbalancesbyaddress(shareholder_addr4)["STOCK2"], 700)
self.log.info("Initiating reward payout")
n0.distributereward(asset_name="STOCK2", snapshot_height=tgt_block_height, distribution_asset_name="PAYOUT1",
gross_distribution_amount=2000, exception_addresses=dist_addr0)
n0.generate(10)
self.sync_all()
# Inexplicably, order matters here. We need to verify the amount
# using the node that created the address (?!)
self.log.info("Verifying PAYOUT1 holdings after payout")
assert_equal(n1.listassetbalancesbyaddress(shareholder_addr0)["PAYOUT1"], 200)
assert_equal(n1.listassetbalancesbyaddress(shareholder_addr1)["PAYOUT1"], 300)
assert_equal(n0.listassetbalancesbyaddress(shareholder_addr2)["PAYOUT1"], 400)
assert_equal(n2.listassetbalancesbyaddress(shareholder_addr3)["PAYOUT1"], 500)
assert_equal(n2.listassetbalancesbyaddress(shareholder_addr4)["PAYOUT1"], 600)
# Attempts a payout without an asset snapshot
def payout_without_snapshot(self):
self.log.info("Running payout without snapshot test!")
n0, n1, n2 = self.nodes[0], self.nodes[1], self.nodes[2]
self.log.info("Creating owner address")
owner_addr0 = n0.getnewaddress()
self.log.info("Providing funding")
self.nodes[0].sendtoaddress(owner_addr0, 1000)
n0.generate(10)
self.sync_all()
self.log.info("Issuing STOCK3 asset")
n0.issue(asset_name="STOCK3", qty=10000, to_address=owner_addr0, change_address="", units=4, reissuable=True, has_ipfs=False)
n0.generate(10)
self.sync_all()
self.log.info("Retrieving chain height")
tgt_block_height = n0.getblockchaininfo()["blocks"] + 100
self.log.info("Skipping forward so that we're beyond the expected snapshot height")
n0.generate(161)
self.sync_all()
self.log.info("Initiating failing reward payout")
assert_raises_rpc_error(-32600, "Snapshot request not found",
n0.distributereward, "STOCK3", tgt_block_height, "RVN", 2000, owner_addr0)
# Attempts a payout for an invalid ownership asset
def payout_with_invalid_ownership_asset(self):
self.log.info("Running payout with invalid ownership asset test!")
n0, n1, n2 = self.nodes[0], self.nodes[1], self.nodes[2]
self.log.info("Creating owner address")
owner_addr0 = n0.getnewaddress()
self.log.info("Providing funding")
self.nodes[0].sendtoaddress(owner_addr0, 1000)
n0.generate(10)
self.sync_all()
self.log.info("Retrieving chain height")
tgt_block_height = n0.getblockchaininfo()["blocks"] + 100
self.log.info("Skipping forward so that we're beyond the expected snapshot height")
n0.generate(161)
self.sync_all()
self.log.info("Initiating failing reward payout")
assert_raises_rpc_error(-32600, "The asset hasn't been created: STOCK4",
n0.distributereward, "STOCK4", tgt_block_height, "RVN", 2000, owner_addr0)
# Attempts a payout for an invalid payout asset
def payout_with_invalid_payout_asset(self):
self.log.info("Running payout with invalid payout asset test!")
n0, n1, n2 = self.nodes[0], self.nodes[1], self.nodes[2]
self.log.info("Creating owner address")
owner_addr0 = n0.getnewaddress()
self.log.info("Providing funding")
self.nodes[0].sendtoaddress(owner_addr0, 1000)
n0.generate(10)
self.sync_all()
self.log.info("Issuing STOCK5 asset")
n0.issue(asset_name="STOCK5", qty=10000, to_address=owner_addr0, change_address="", units=4, reissuable=True, has_ipfs=False)
n0.generate(10)
self.sync_all()
self.log.info("Retrieving chain height")
tgt_block_height = n0.getblockchaininfo()["blocks"] + 100
self.log.info("Skipping forward so that we're beyond the expected snapshot height")
n0.generate(161)
self.sync_all()
self.log.info("Initiating failing reward payout")
assert_raises_rpc_error(-32600, "Wallet doesn't have the ownership token(!) for the distribution asset",
n0.distributereward, "STOCK5", tgt_block_height, "PAYOUT2", 2000, owner_addr0)
# Attempts a payout for an invalid payout asset
def payout_before_minimum_height_is_reached(self):
self.log.info("Running payout before minimum rewards height is reached!")
n0, n1, n2 = self.nodes[0], self.nodes[1], self.nodes[2]
self.log.info("Creating owner address")
owner_addr0 = n0.getnewaddress()
self.log.info("Providing funding")
self.nodes[0].sendtoaddress(owner_addr0, 1000)
n0.generate(10)
self.sync_all()
self.log.info("Issuing STOCK6 asset")
n0.issue(asset_name="STOCK6", qty=10000, to_address=owner_addr0, change_address="", units=4, reissuable=True, has_ipfs=False)
n0.generate(10)
self.sync_all()
self.log.info("Retrieving chain height")
tgt_block_height = n0.getblockchaininfo()["blocks"] + 1
self.log.info("Requesting snapshot of STOCK6 ownership in 1 blocks")
n0.requestsnapshot(asset_name="STOCK6", block_height=tgt_block_height)
self.log.info("Skipping forward so that we're 15 blocks ahead of the snapshot height")
n0.generate(16)
self.sync_all()
self.log.info(
"Initiating failing reward payout because we are only 15 block ahead of the snapshot instead of 60")
assert_raises_rpc_error(-32600,
"For security of the rewards payout, it is recommended to wait until chain is 60 blocks ahead of the snapshot height. You can modify this by using the -minrewardsheight.",
n0.distributereward, "STOCK6", tgt_block_height, "RVN", 2000, owner_addr0)
# Attempts a payout using a custom rewards height of 15, and they have low rvn balance
def payout_custom_height_set_with_low_funds(self):
self.log.info("Running payout before minimum rewards height is reached with custom min height value set!")
n0, n1, n2 = self.nodes[0], self.nodes[1], self.nodes[2]
self.log.info("Creating owner address")
owner_addr0 = n1.getnewaddress()
self.log.info("Providing funding")
self.nodes[0].sendtoaddress(owner_addr0, 1000)
n0.generate(5)
self.sync_all()
n1.generate(10)
self.sync_all()
self.log.info("Issuing STOCK7 asset")
n1.issue(asset_name="STOCK7", qty=10000, to_address=owner_addr0, change_address="", units=4, reissuable=True, has_ipfs=False)
n1.generate(10)
self.sync_all()
shareholder_addr0 = n2.getnewaddress()
n1.transfer(asset_name="STOCK7", qty=200, to_address=shareholder_addr0, message="", expire_time=0, change_address="", asset_change_address=owner_addr0)
n1.generate(10)
self.sync_all()
self.log.info("Retrieving chain height")
tgt_block_height = n1.getblockchaininfo()["blocks"] + 1
self.log.info("Requesting snapshot of STOCK7 ownership in 1 blocks")
n1.requestsnapshot(asset_name="STOCK7", block_height=tgt_block_height)
self.log.info("Skipping forward so that we're 30 blocks ahead of the snapshot height")
n1.generate(31)
self.sync_all()
self.log.info("Initiating reward payout should succeed because -minrewardheight=15 on node1")
n1.distributereward("STOCK7", tgt_block_height, "RVN", 2000, owner_addr0)
n1.generate(2)
self.sync_all()
assert_equal(n1.getdistributestatus("STOCK7", tgt_block_height, "RVN", 2000, owner_addr0)['Status'], 3)
n0.sendtoaddress(n1.getnewaddress(), 3000)
n0.generate(5)
self.sync_all()
n1.generate(10)
self.sync_all()
assert_equal(n2.getreceivedbyaddress(shareholder_addr0, 1), 2000)
# Attempts a payout using a custom rewards height of 15, and they have low rvn balance
def payout_with_insufficient_asset_amount(self):
self.log.info("Running payout before minimum rewards height is reached with custom min height value set!")
n0, n1, n2 = self.nodes[0], self.nodes[1], self.nodes[2]
self.log.info("Creating owner address")
owner_addr0 = n1.getnewaddress()
self.log.info("Providing funding")
self.nodes[0].sendtoaddress(owner_addr0, 2000)
n0.generate(5)
self.sync_all()
n1.generate(10)
self.sync_all()
n1.issue(asset_name="STOCK_7.1", qty=10000, to_address=owner_addr0, change_address="", units=4, reissuable=True, has_ipfs=False)
self.log.info("Issuing LOW_ASSET_AMOUNT asset")
n1.issue(asset_name="LOW_ASSET_AMOUNT", qty=10000, to_address=owner_addr0, change_address="", units=4, reissuable=True, has_ipfs=False)
n1.generate(10)
self.sync_all()
# Send the majority of the assets to node0
asset_holder_address = n0.getnewaddress()
n1.transfer(asset_name="LOW_ASSET_AMOUNT", qty=9000, to_address=asset_holder_address, message="", expire_time=0, change_address="", asset_change_address=owner_addr0)
shareholder_addr0 = n2.getnewaddress()
n1.transfer(asset_name="STOCK_7.1", qty=200, to_address=shareholder_addr0, message="", expire_time=0, change_address="", asset_change_address=owner_addr0)
n1.generate(10)
self.sync_all()
self.log.info("Retrieving chain height")
tgt_block_height = n1.getblockchaininfo()["blocks"] + 1
self.log.info("Requesting snapshot of STOCK_7.1 ownership in 1 blocks")
n1.requestsnapshot(asset_name="STOCK_7.1", block_height=tgt_block_height)
self.log.info("Skipping forward so that we're 30 blocks ahead of the snapshot height")
n1.generate(61)
self.sync_all()
self.log.info("Initiating reward payout")
n1.distributereward("STOCK_7.1", tgt_block_height, "LOW_ASSET_AMOUNT", 2000, owner_addr0)
n1.generate(2)
self.sync_all()
assert_equal(
n1.getdistributestatus("STOCK_7.1", tgt_block_height, "LOW_ASSET_AMOUNT", 2000, owner_addr0)['Status'], 5)
# node0 transfer back the assets to node1, now the distribution transaction should get created successfully. when the next block is mined
n0.transfer(asset_name="LOW_ASSET_AMOUNT", qty=9000, to_address=owner_addr0, message="", expire_time=0, change_address="")
n0.generate(5)
self.sync_all()
n1.generate(10)
self.sync_all()
assert_equal(n2.listassetbalancesbyaddress(shareholder_addr0)["LOW_ASSET_AMOUNT"], 2000)
def list_snapshot_requests(self):
self.log.info("Testing listsnapshotrequests()...")
n0, n1 = self.nodes[0], self.nodes[1]
self.log.info("Providing funding")
self.nodes[0].sendtoaddress(n1.getnewaddress(), 1000)
n0.generate(5)
self.sync_all()
srl = n1.listsnapshotrequests()
assert_equal(0, len(srl))
asset_name1 = "LISTME"
block_height1 = n1.getblockcount() + 100
asset_name2 = "LISTME2"
block_height2 = n1.getblockcount() + 200
# make sure a snapshot can't be created for a non-existent
assert_raises_rpc_error(-8, "asset does not exist", n1.requestsnapshot, asset_name1, block_height1)
n1.issue(asset_name1)
n1.issue(asset_name2)
n1.generate(1)
n1.requestsnapshot(asset_name=asset_name1, block_height=block_height1)
n1.requestsnapshot(asset_name=asset_name1, block_height=block_height2)
n1.requestsnapshot(asset_name=asset_name2, block_height=block_height2)
n1.generate(1)
srl = n1.listsnapshotrequests()
assert_equal(3, len(srl))
assert_contains({'asset_name': asset_name1, 'block_height': block_height1}, srl)
assert_contains({'asset_name': asset_name1, 'block_height': block_height2}, srl)
assert_contains({'asset_name': asset_name2, 'block_height': block_height2}, srl)
srl = n1.listsnapshotrequests(asset_name1)
assert_equal(2, len(srl))
assert_contains({'asset_name': asset_name1, 'block_height': block_height1}, srl)
assert_contains({'asset_name': asset_name1, 'block_height': block_height2}, srl)
srl = n1.listsnapshotrequests(asset_name2)
assert_equal(1, len(srl))
assert_contains({'asset_name': asset_name2, 'block_height': block_height2}, srl)
def basic_test_asset_uneven_distribution(self):
self.log.info("Running ASSET reward test (units = 0)!")
n0, n1, n2 = self.nodes[0], self.nodes[1], self.nodes[2]
self.log.info("Creating owner address")
owner_addr0 = n0.getnewaddress()
# self.log.info(f"Owner address: {owner_addr0}")
self.log.info("Creating distributor address")
dist_addr0 = n0.getnewaddress()
# self.log.info(f"Distributor address: {dist_addr0}")
self.log.info("Providing funding")
self.nodes[0].sendtoaddress(owner_addr0, 1000)
n0.generate(10)
self.sync_all()
self.log.info("Issuing STOCK8 asset")
n0.issue(asset_name="STOCK8", qty=10000, to_address=dist_addr0, change_address="", units=0, reissuable=True, has_ipfs=False)
n0.generate(10)
self.sync_all()
self.log.info("Creating shareholder addresses")
shareholder_addr0 = n0.getnewaddress()
shareholder_addr1 = n1.getnewaddress()
shareholder_addr2 = n2.getnewaddress()
self.log.info("Distributing shares")
n0.transferfromaddress(asset_name="STOCK8", from_address=dist_addr0, qty=300, to_address=shareholder_addr0,
message="", expire_time=0, rvn_change_address="", asset_change_address=dist_addr0)
n0.transferfromaddress(asset_name="STOCK8", from_address=dist_addr0, qty=300, to_address=shareholder_addr1,
message="", expire_time=0, rvn_change_address="", asset_change_address=dist_addr0)
n0.transferfromaddress(asset_name="STOCK8", from_address=dist_addr0, qty=300, to_address=shareholder_addr2,
message="", expire_time=0, rvn_change_address="", asset_change_address=dist_addr0)
n0.generate(150)
self.sync_all()
self.log.info("Verifying share distribution")
assert_equal(n1.listassetbalancesbyaddress(shareholder_addr0)['STOCK8'], 300)
assert_equal(n1.listassetbalancesbyaddress(shareholder_addr1)["STOCK8"], 300)
assert_equal(n0.listassetbalancesbyaddress(shareholder_addr2)["STOCK8"], 300)
self.log.info("Mining blocks")
n0.generate(10)
self.sync_all()
self.log.info("Issuing PAYOUT8 asset")
n0.issue(asset_name="PAYOUT8", qty=10, to_address=owner_addr0, change_address="", units=0, reissuable=True, has_ipfs=False)
n0.generate(10)
self.sync_all()
self.log.info("Retrieving chain height")
tgt_block_height = n0.getblockchaininfo()["blocks"] + 5
self.log.info("Requesting snapshot of STOCK8 ownership in 5 blocks")
n0.requestsnapshot(asset_name="STOCK8", block_height=tgt_block_height)
# Mine 10 blocks to make sure snapshot is created
n0.generate(10)
self.log.info("Retrieving snapshot request")
snap_shot_req = n0.getsnapshotrequest(asset_name="STOCK8", block_height=tgt_block_height)
assert_equal(snap_shot_req["asset_name"], "STOCK8")
assert_equal(snap_shot_req["block_height"], tgt_block_height)
self.log.info("Skipping forward to allow snapshot to process")
n0.generate(61)
self.sync_all()
self.log.info("Retrieving snapshot for ownership validation")
snap_shot = n0.getsnapshot(asset_name="STOCK8", block_height=tgt_block_height)
assert_equal(snap_shot["name"], "STOCK8")
assert_equal(snap_shot["height"], tgt_block_height)
owner0 = False
owner1 = False
owner2 = False
for ownerAddr in snap_shot["owners"]:
if ownerAddr["address"] == shareholder_addr0:
assert_equal(ownerAddr["amount_owned"], 300)
owner0 = True
elif ownerAddr["address"] == shareholder_addr1:
assert_equal(ownerAddr["amount_owned"], 300)
owner1 = True
elif ownerAddr["address"] == shareholder_addr2:
assert_equal(ownerAddr["amount_owned"], 300)
owner2 = True
assert_equal(owner0, True)
assert_equal(owner1, True)
assert_equal(owner2, True)
self.log.info("Initiating reward payout")
n0.distributereward(asset_name="STOCK8", snapshot_height=tgt_block_height, distribution_asset_name="PAYOUT8",
gross_distribution_amount=10, exception_addresses=dist_addr0)
n0.generate(10)
self.sync_all()
# Inexplicably, order matters here. We need to verify the amount
# using the node that created the address (?!)
self.log.info("Verifying PAYOUT8 holdings after payout")
assert_equal(n1.listassetbalancesbyaddress(shareholder_addr0)["PAYOUT8"], 3)
assert_equal(n1.listassetbalancesbyaddress(shareholder_addr1)["PAYOUT8"], 3)
assert_equal(n0.listassetbalancesbyaddress(shareholder_addr2)["PAYOUT8"], 3)
def basic_test_asset_even_distribution(self):
self.log.info("Running ASSET reward test (units = 0)!")
n0, n1, n2 = self.nodes[0], self.nodes[1], self.nodes[2]
self.log.info("Creating owner address")
owner_addr0 = n0.getnewaddress()
# self.log.info(f"Owner address: {owner_addr0}")
self.log.info("Creating distributor address")
dist_addr0 = n0.getnewaddress()
# self.log.info(f"Distributor address: {dist_addr0}")
self.log.info("Providing funding")
self.nodes[0].sendtoaddress(owner_addr0, 1000)
n0.generate(10)
self.sync_all()
self.log.info("Issuing STOCK9 asset")
n0.issue(asset_name="STOCK9", qty=10000, to_address=dist_addr0, change_address="", units=0, reissuable=True, has_ipfs=False)
n0.generate(10)
self.sync_all()
self.log.info("Creating shareholder addresses")
shareholder_addr0 = n0.getnewaddress()
shareholder_addr1 = n1.getnewaddress()
shareholder_addr2 = n2.getnewaddress()
self.log.info("Distributing shares")
n0.transferfromaddress(asset_name="STOCK9", from_address=dist_addr0, qty=300, to_address=shareholder_addr0,
message="", expire_time=0, rvn_change_address="", asset_change_address=dist_addr0)
n0.transferfromaddress(asset_name="STOCK9", from_address=dist_addr0, qty=300, to_address=shareholder_addr1,
message="", expire_time=0, rvn_change_address="", asset_change_address=dist_addr0)
n0.transferfromaddress(asset_name="STOCK9", from_address=dist_addr0, qty=400, to_address=shareholder_addr2,
message="", expire_time=0, rvn_change_address="", asset_change_address=dist_addr0)
n0.generate(150)
self.sync_all()
self.log.info("Verifying share distribution")
assert_equal(n1.listassetbalancesbyaddress(shareholder_addr0)['STOCK9'], 300)
assert_equal(n1.listassetbalancesbyaddress(shareholder_addr1)["STOCK9"], 300)
assert_equal(n0.listassetbalancesbyaddress(shareholder_addr2)["STOCK9"], 400)
self.log.info("Mining blocks")
n0.generate(10)
self.sync_all()
self.log.info("Issuing PAYOUT9 asset")
n0.issue(asset_name="PAYOUT9", qty=10, to_address=owner_addr0, change_address="", units=0, reissuable=True, has_ipfs=False)
n0.generate(10)
self.sync_all()
self.log.info("Retrieving chain height")
tgt_block_height = n0.getblockchaininfo()["blocks"] + 5
self.log.info("Requesting snapshot of STOCK9 ownership in 5 blocks")
n0.requestsnapshot(asset_name="STOCK9", block_height=tgt_block_height)
# Mine 10 blocks to make sure snapshot is created
n0.generate(10)
self.log.info("Retrieving snapshot request")
snap_shot_req = n0.getsnapshotrequest(asset_name="STOCK9", block_height=tgt_block_height)
assert_equal(snap_shot_req["asset_name"], "STOCK9")
assert_equal(snap_shot_req["block_height"], tgt_block_height)
self.log.info("Skipping forward to allow snapshot to process")
n0.generate(61)
self.sync_all()
self.log.info("Retrieving snapshot for ownership validation")
snap_shot = n0.getsnapshot(asset_name="STOCK9", block_height=tgt_block_height)
assert_equal(snap_shot["name"], "STOCK9")
assert_equal(snap_shot["height"], tgt_block_height)
owner0 = False
owner1 = False
owner2 = False
for ownerAddr in snap_shot["owners"]:
if ownerAddr["address"] == shareholder_addr0:
assert_equal(ownerAddr["amount_owned"], 300)
owner0 = True
elif ownerAddr["address"] == shareholder_addr1:
assert_equal(ownerAddr["amount_owned"], 300)
owner1 = True
elif ownerAddr["address"] == shareholder_addr2:
assert_equal(ownerAddr["amount_owned"], 400)
owner2 = True
assert_equal(owner0, True)
assert_equal(owner1, True)
assert_equal(owner2, True)
self.log.info("Initiating reward payout")
n0.distributereward(asset_name="STOCK9", snapshot_height=tgt_block_height, distribution_asset_name="PAYOUT9",
gross_distribution_amount=10, exception_addresses=dist_addr0)
n0.generate(10)
self.sync_all()
# Inexplicably, order matters here. We need to verify the amount
# using the node that created the address (?!)
self.log.info("Verifying PAYOUT9 holdings after payout")
assert_equal(n1.listassetbalancesbyaddress(shareholder_addr0)["PAYOUT9"], 3)
assert_equal(n1.listassetbalancesbyaddress(shareholder_addr1)["PAYOUT9"], 3)
assert_equal(n0.listassetbalancesbyaddress(shareholder_addr2)["PAYOUT9"], 4)
def basic_test_asset_round_down_uneven_distribution(self):
self.log.info("Running ASSET reward test with uneven distribution (units = 0)!")
n0, n1, n2 = self.nodes[0], self.nodes[1], self.nodes[2]
self.log.info("Creating owner address")
owner_addr0 = n0.getnewaddress()
# self.log.info(f"Owner address: {owner_addr0}")
self.log.info("Creating distributor address")
dist_addr0 = n0.getnewaddress()
# self.log.info(f"Distributor address: {dist_addr0}")
self.log.info("Providing funding")
self.nodes[0].sendtoaddress(owner_addr0, 1000)
n0.generate(10)
self.sync_all()
self.log.info("Issuing STOCK10 asset")
n0.issue(asset_name="STOCK10", qty=10000, to_address=dist_addr0, change_address="", units=0, reissuable=True, has_ipfs=False)
n0.generate(10)
self.sync_all()
self.log.info("Creating shareholder addresses")
shareholder_addr0 = n0.getnewaddress()
shareholder_addr1 = n1.getnewaddress()
shareholder_addr2 = n2.getnewaddress()
self.log.info("Distributing shares")
n0.transferfromaddress(asset_name="STOCK10", from_address=dist_addr0, qty=300, to_address=shareholder_addr0,
message="", expire_time=0, rvn_change_address="", asset_change_address=dist_addr0)
n0.transferfromaddress(asset_name="STOCK10", from_address=dist_addr0, qty=300, to_address=shareholder_addr1,
message="", expire_time=0, rvn_change_address="", asset_change_address=dist_addr0)
n0.transferfromaddress(asset_name="STOCK10", from_address=dist_addr0, qty=500, to_address=shareholder_addr2,
message="", expire_time=0, rvn_change_address="", asset_change_address=dist_addr0)
n0.generate(150)
self.sync_all()
self.log.info("Verifying share distribution")
assert_equal(n1.listassetbalancesbyaddress(shareholder_addr0)['STOCK10'], 300)
assert_equal(n1.listassetbalancesbyaddress(shareholder_addr1)["STOCK10"], 300)
assert_equal(n0.listassetbalancesbyaddress(shareholder_addr2)["STOCK10"], 500)
self.log.info("Mining blocks")
n0.generate(10)
self.sync_all()
self.log.info("Issuing PAYOUT10 asset")
n0.issue(asset_name="PAYOUT10", qty=10, to_address=owner_addr0, change_address="", units=0, reissuable=True,
has_ipfs=False)
n0.generate(10)
self.sync_all()
self.log.info("Retrieving chain height")
tgt_block_height = n0.getblockchaininfo()["blocks"] + 5
self.log.info("Requesting snapshot of STOCK10 ownership in 5 blocks")
n0.requestsnapshot(asset_name="STOCK10", block_height=tgt_block_height)
# Mine 10 blocks to make sure snapshot is created
n0.generate(10)
self.log.info("Retrieving snapshot request")
snap_shot_req = n0.getsnapshotrequest(asset_name="STOCK10", block_height=tgt_block_height)
assert_equal(snap_shot_req["asset_name"], "STOCK10")
assert_equal(snap_shot_req["block_height"], tgt_block_height)
self.log.info("Skipping forward to allow snapshot to process")
n0.generate(61)
self.sync_all()
self.log.info("Retrieving snapshot for ownership validation")
snap_shot = n0.getsnapshot(asset_name="STOCK10", block_height=tgt_block_height)
assert_equal(snap_shot["name"], "STOCK10")
assert_equal(snap_shot["height"], tgt_block_height)
owner0 = False
owner1 = False
owner2 = False
for ownerAddr in snap_shot["owners"]:
if ownerAddr["address"] == shareholder_addr0:
assert_equal(ownerAddr["amount_owned"], 300)
owner0 = True
elif ownerAddr["address"] == shareholder_addr1:
assert_equal(ownerAddr["amount_owned"], 300)
owner1 = True
elif ownerAddr["address"] == shareholder_addr2:
assert_equal(ownerAddr["amount_owned"], 500)
owner2 = True
assert_equal(owner0, True)
assert_equal(owner1, True)
assert_equal(owner2, True)
self.log.info("Initiating reward payout")
n0.distributereward(asset_name="STOCK10", snapshot_height=tgt_block_height, distribution_asset_name="PAYOUT10",
gross_distribution_amount=10, exception_addresses=dist_addr0)
n0.generate(10)
self.sync_all()
# Inexplicably, order matters here. We need to verify the amount
# using the node that created the address (?!)
self.log.info("Verifying PAYOUT10 holdings after payout")
assert_equal(n1.listassetbalancesbyaddress(shareholder_addr0)["PAYOUT10"], 2)
assert_equal(n1.listassetbalancesbyaddress(shareholder_addr1)["PAYOUT10"], 2)
assert_equal(n0.listassetbalancesbyaddress(shareholder_addr2)["PAYOUT10"], 4)
def basic_test_asset_round_down_uneven_distribution_2(self):
self.log.info("Running ASSET reward test with uneven distribution (units = 0)!")
n0, n1, n2 = self.nodes[0], self.nodes[1], self.nodes[2]
self.log.info("Creating owner address")
owner_addr0 = n0.getnewaddress()
# self.log.info(f"Owner address: {owner_addr0}")
self.log.info("Creating distributor address")
dist_addr0 = n0.getnewaddress()
# self.log.info(f"Distributor address: {dist_addr0}")
self.log.info("Providing funding")
self.nodes[0].sendtoaddress(owner_addr0, 1000)
n0.generate(10)
self.sync_all()
self.log.info("Issuing STOCK11 asset")
n0.issue(asset_name="STOCK11", qty=10000, to_address=dist_addr0, change_address="", units=0, reissuable=True, has_ipfs=False)
n0.generate(10)
self.sync_all()
self.log.info("Creating shareholder addresses")
shareholder_addr0 = n0.getnewaddress()
shareholder_addr1 = n1.getnewaddress()
shareholder_addr2 = n2.getnewaddress()
shareholder_addr3 = n2.getnewaddress()
self.log.info("Distributing shares")
n0.transferfromaddress(asset_name="STOCK11", from_address=dist_addr0, qty=9, to_address=shareholder_addr0,
message="", expire_time=0, rvn_change_address="", asset_change_address=dist_addr0)
n0.transferfromaddress(asset_name="STOCK11", from_address=dist_addr0, qty=3, to_address=shareholder_addr1,
message="", expire_time=0, rvn_change_address="", asset_change_address=dist_addr0)
n0.transferfromaddress(asset_name="STOCK11", from_address=dist_addr0, qty=2, to_address=shareholder_addr2,
message="", expire_time=0, rvn_change_address="", asset_change_address=dist_addr0)
n0.transferfromaddress(asset_name="STOCK11", from_address=dist_addr0, qty=1, to_address=shareholder_addr3,
message="", expire_time=0, rvn_change_address="", asset_change_address=dist_addr0)
n0.generate(150)
self.sync_all()
self.log.info("Verifying share distribution")
assert_equal(n1.listassetbalancesbyaddress(shareholder_addr0)['STOCK11'], 9)
assert_equal(n1.listassetbalancesbyaddress(shareholder_addr1)["STOCK11"], 3)
assert_equal(n0.listassetbalancesbyaddress(shareholder_addr2)["STOCK11"], 2)
assert_equal(n0.listassetbalancesbyaddress(shareholder_addr3)["STOCK11"], 1)
self.log.info("Mining blocks")
n0.generate(10)
self.sync_all()
self.log.info("Issuing PAYOUT11 asset")
n0.issue(asset_name="PAYOUT11", qty=10, to_address=owner_addr0, change_address="", units=0, reissuable=True, has_ipfs=False)
n0.generate(10)
self.sync_all()
self.log.info("Retrieving chain height")
tgt_block_height = n0.getblockchaininfo()["blocks"] + 5
self.log.info("Requesting snapshot of STOCK11 ownership in 5 blocks")
n0.requestsnapshot(asset_name="STOCK11", block_height=tgt_block_height)
# Mine 10 blocks to make sure snapshot is created
n0.generate(10)
self.log.info("Retrieving snapshot request")
snap_shot_req = n0.getsnapshotrequest(asset_name="STOCK11", block_height=tgt_block_height)
assert_equal(snap_shot_req["asset_name"], "STOCK11")
assert_equal(snap_shot_req["block_height"], tgt_block_height)
self.log.info("Skipping forward to allow snapshot to process")
n0.generate(61)
self.sync_all()
self.log.info("Retrieving snapshot for ownership validation")