forked from algorand/py-algorand-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_unit.py
2254 lines (1969 loc) · 104 KB
/
test_unit.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
import base64
import copy
import unittest
import random
from unittest.mock import Mock
from algosdk.future import transaction
from algosdk import encoding
from algosdk import account
from algosdk import mnemonic
from algosdk import error
from algosdk import constants
from algosdk import util
from algosdk import logic
from algosdk import wordlist
from algosdk.future import template
from algosdk.testing import dryrun
from nacl.signing import SigningKey
class TestPaymentTransaction(unittest.TestCase):
def test_min_txn_fee(self):
address = "7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q"
gh = "JgsgCaCTqIaLeVhyL6XlRu3n7Rfk2FxMeK+wRSaQ7dI="
sp = transaction.SuggestedParams(0, 1, 100, gh)
txn = transaction.PaymentTxn(address, sp, address,
1000, note=b'\x00')
self.assertEqual(constants.min_txn_fee, txn.fee)
def test_note_wrong_type(self):
address = "7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q"
gh = "JgsgCaCTqIaLeVhyL6XlRu3n7Rfk2FxMeK+wRSaQ7dI="
sp = transaction.SuggestedParams(0, 1, 100, gh)
f = lambda: transaction.PaymentTxn(address, sp, address,
1000, note="hello")
self.assertRaises(error.WrongNoteType, f)
def test_note_wrong_length(self):
address = "7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q"
gh = "JgsgCaCTqIaLeVhyL6XlRu3n7Rfk2FxMeK+wRSaQ7dI="
sp = transaction.SuggestedParams(0, 1, 100, gh)
f = lambda: transaction.PaymentTxn(address, sp, address,
1000, note=("0"*1025).encode())
self.assertRaises(error.WrongNoteLength, f)
def test_serialize(self):
address = "7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q"
gh = "JgsgCaCTqIaLeVhyL6XlRu3n7Rfk2FxMeK+wRSaQ7dI="
sp = transaction.SuggestedParams(3, 1, 100, gh)
txn = transaction.PaymentTxn(address, sp, address,
1000, note=bytes([1, 32, 200]))
enc = encoding.msgpack_encode(txn)
re_enc = encoding.msgpack_encode(encoding.msgpack_decode(enc))
self.assertEqual(enc, re_enc)
def test_serialize_with_note_string_encode(self):
address = "7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q"
gh = "JgsgCaCTqIaLeVhyL6XlRu3n7Rfk2FxMeK+wRSaQ7dI="
sp = transaction.SuggestedParams(3, 1, 100, gh)
txn = transaction.PaymentTxn(address, sp, address,
1000, note="hello".encode())
enc = encoding.msgpack_encode(txn)
re_enc = encoding.msgpack_encode(encoding.msgpack_decode(enc))
self.assertEqual(enc, re_enc)
def test_serialize_with_note_max_length(self):
address = "7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q"
gh = "JgsgCaCTqIaLeVhyL6XlRu3n7Rfk2FxMeK+wRSaQ7dI="
sp = transaction.SuggestedParams(3, 1, 100, gh)
txn = transaction.PaymentTxn(address, sp, address,
1000, note=("0"*1024).encode())
enc = encoding.msgpack_encode(txn)
re_enc = encoding.msgpack_encode(encoding.msgpack_decode(enc))
self.assertEqual(enc, re_enc)
def test_serialize_zero_amt(self):
address = "7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q"
gh = "JgsgCaCTqIaLeVhyL6XlRu3n7Rfk2FxMeK+wRSaQ7dI="
sp = transaction.SuggestedParams(3, 1, 100, gh)
txn = transaction.PaymentTxn(address, sp, address,
0, note=bytes([1, 32, 200]))
enc = encoding.msgpack_encode(txn)
re_enc = encoding.msgpack_encode(encoding.msgpack_decode(enc))
self.assertEqual(enc, re_enc)
def test_serialize_gen(self):
address = "7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q"
gh = "JgsgCaCTqIaLeVhyL6XlRu3n7Rfk2FxMeK+wRSaQ7dI="
sp = transaction.SuggestedParams(3, 1, 100, gh, "testnet-v1.0")
txn = transaction.PaymentTxn(address, sp, address,
1000, close_remainder_to=address)
enc = encoding.msgpack_encode(txn)
re_enc = encoding.msgpack_encode(encoding.msgpack_decode(enc))
self.assertEqual(enc, re_enc)
def test_serialize_txgroup(self):
address = "7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q"
gh = "JgsgCaCTqIaLeVhyL6XlRu3n7Rfk2FxMeK+wRSaQ7dI="
sp = transaction.SuggestedParams(3, 1, 100, gh, "testnet-v1.0")
txn = transaction.PaymentTxn(address, sp, address,
1000, close_remainder_to=address)
txid = txn.get_txid().encode()
txid = base64.decodebytes(txid)
txgroup = transaction.TxGroup([txid])
enc = encoding.msgpack_encode(txgroup)
re_enc = encoding.msgpack_encode(encoding.msgpack_decode(enc))
self.assertEqual(enc, re_enc)
txgroup = transaction.TxGroup([txid] * 11)
enc = encoding.msgpack_encode(txgroup)
re_enc = encoding.msgpack_encode(encoding.msgpack_decode(enc))
self.assertEqual(enc, re_enc)
# check group field serialization
gid = transaction.calculate_group_id([txn, txn])
txn.group = gid
enc = encoding.msgpack_encode(txn)
re_enc = encoding.msgpack_encode(encoding.msgpack_decode(enc))
self.assertEqual(enc, re_enc)
def test_sign(self):
mn = (
"advice pudding treat near rule blouse same whisper inner electric"
" quit surface sunny dismiss leader blood seat clown cost exist ho"
"spital century reform able sponsor")
gh = "JgsgCaCTqIaLeVhyL6XlRu3n7Rfk2FxMeK+wRSaQ7dI="
address = "PNWOET7LLOWMBMLE4KOCELCX6X3D3Q4H2Q4QJASYIEOF7YIPPQBG3YQ5YI"
close = "IDUTJEUIEVSMXTU4LGTJWZ2UE2E6TIODUKU6UW3FU3UKIQQ77RLUBBBFLA"
sk = mnemonic.to_private_key(mn)
pk = account.address_from_private_key(sk)
sp = transaction.SuggestedParams(4, 12466, 13466, gh, "devnet-v33.0")
txn = transaction.PaymentTxn(
pk, sp, address, 1000, note=base64.b64decode("6gAVR0Nsv5Y="),
close_remainder_to=close)
stx = txn.sign(sk)
golden = (
"gqNzaWfEQPhUAZ3xkDDcc8FvOVo6UinzmKBCqs0woYSfodlmBMfQvGbeUx3Srxy3d"
"yJDzv7rLm26BRv9FnL2/AuT7NYfiAWjdHhui6NhbXTNA+ilY2xvc2XEIEDpNJKIJW"
"TLzpxZpptnVCaJ6aHDoqnqW2Wm6KRCH/xXo2ZlZc0EmKJmds0wsqNnZW6sZGV2bmV"
"0LXYzMy4womdoxCAmCyAJoJOohot5WHIvpeVG7eftF+TYXEx4r7BFJpDt0qJsds00"
"mqRub3RlxAjqABVHQ2y/lqNyY3bEIHts4k/rW6zAsWTinCIsV/X2PcOH1DkEglhBH"
"F/hD3wCo3NuZMQg5/D4TQaBHfnzHI2HixFV9GcdUaGFwgCQhmf0SVhwaKGkdHlwZa"
"NwYXk=")
self.assertEqual(golden, encoding.msgpack_encode(stx))
txid_golden = "5FJDJD5LMZC3EHUYYJNH5I23U4X6H2KXABNDGPIL557ZMJ33GZHQ"
self.assertEqual(txn.get_txid(), txid_golden)
# check group field serialization
gid = transaction.calculate_group_id([txn])
stx.group = gid
enc = encoding.msgpack_encode(stx)
re_enc = encoding.msgpack_encode(encoding.msgpack_decode(enc))
self.assertEqual(enc, re_enc)
def test_sign_logic_multisig(self):
program = b"\x01\x20\x01\x01\x22"
lsig = transaction.LogicSig(program)
passphrase = "sight garment riot tattoo tortoise identify left talk sea ill walnut leg robot myth toe perfect rifle dizzy spend april build legend brother above hospital"
sk = mnemonic.to_private_key(passphrase)
addr = account.address_from_private_key(sk)
passphrase2 = "sentence spoil search picnic civil quote question express uniform laundry visit wisdom level domain pigeon pattern search animal upper joke fiscal latin they ability stove"
sk2 = mnemonic.to_private_key(passphrase2)
addr2 = account.address_from_private_key(sk2)
msig = transaction.Multisig(1, 2, [addr, addr2])
lsig.sign(sk, msig)
lsig.append_to_multisig(sk2)
receiver = "DOMUC6VGZH7SSY5V332JR5HRLZSOJDWNPBI4OI2IIBU6A3PFLOBOXZ3KFY"
gh = "zNQES/4IqimxRif40xYvzBBIYCZSbYvNSRIzVIh4swo="
params = transaction.SuggestedParams(0, 447, 1447, gh, gen="network-v1")
txn = transaction.PaymentTxn(msig.address(), params, receiver, 1000000)
lstx = transaction.LogicSigTransaction(txn, lsig)
golden = (
"gqRsc2lngqFsxAUBIAEBIqRtc2lng6ZzdWJzaWeSgqJwa8QgeUdQSBmJmLH5xdID"
"nkf+V3AQH6usPifhfJVwnJ7d7nOhc8RAuP0Ms22j1xXTcXYOivDMztXm7vY2uBi8"
"vJCDlpWhVxLoEDKhqmqEbT7SfvCrS2aNXPiJUSZ7cNMyUdytOpFdD4KicGvEILxI"
"bwe4gu5YCR4TLASEBpTJ25cdJZqxMqhkgMHQqr61oXPEQGOeeZZ1FAJjJ65N5Asj"
"i1bK+Q2LZblC77u7NYcw4gPAig8rRUKJYNQtiKVVJQ53A8ufQkn9dZ6uybbaIPxu"
"bQejdGhyAqF2AaN0eG6Jo2FtdM4AD0JAo2ZlZc0D6KJmds0Bv6NnZW6qbmV0d29y"
"ay12MaJnaMQgzNQES/4IqimxRif40xYvzBBIYCZSbYvNSRIzVIh4swqibHbNBaej"
"cmN2xCAbmUF6psn/KWO13vSY9PFeZOSOzXhRxyNIQGngbeVbgqNzbmTEIIytL7Xv"
"2XuuO6mS+3IetwlKVPM0qdKBIiMVdhzAOMPKpHR5cGWjcGF5")
encoded = encoding.msgpack_encode(lstx)
self.assertEqual(encoded, golden)
def test_serialize_zero_receiver(self):
address = "7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q"
receiver = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ"
gh = "JgsgCaCTqIaLeVhyL6XlRu3n7Rfk2FxMeK+wRSaQ7dI="
sp = transaction.SuggestedParams(3, 1, 100, gh)
txn = transaction.PaymentTxn(address, sp, receiver,
1000, note=bytes([1, 32, 200]))
golden = (
"iKNhbXTNA+ijZmVlzQPoomZ2AaJnaMQgJgsgCaCTqIaLeVhyL6XlRu3n7Rfk2FxMe"
"K+wRSaQ7dKibHZkpG5vdGXEAwEgyKNzbmTEIP5oQQPnKvM7kbGuuSOunAVfSbJzHQ"
"tAtCP3Bf2XdDxmpHR5cGWjcGF5")
self.assertEqual(golden, encoding.msgpack_encode(txn))
def test_error_empty_receiver_txn(self):
address = "7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q"
receiver = None
gh = "JgsgCaCTqIaLeVhyL6XlRu3n7Rfk2FxMeK+wRSaQ7dI="
sp = transaction.SuggestedParams(3, 1, 100, gh)
with self.assertRaises(error.ZeroAddressError):
transaction.PaymentTxn(address, sp, receiver, 1000)
def test_error_empty_receiver_asset_txn(self):
address = "7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q"
receiver = None
gh = "JgsgCaCTqIaLeVhyL6XlRu3n7Rfk2FxMeK+wRSaQ7dI="
sp = transaction.SuggestedParams(3, 1, 100, gh)
with self.assertRaises(error.ZeroAddressError):
transaction.AssetTransferTxn(address, sp, receiver, 1000, 24)
def test_serialize_pay(self):
mn = (
"advice pudding treat near rule blouse same whisper inner electric"
" quit surface sunny dismiss leader blood seat clown cost exist ho"
"spital century reform able sponsor")
sk = mnemonic.to_private_key(mn)
pk = mnemonic.to_public_key(mn)
to = "PNWOET7LLOWMBMLE4KOCELCX6X3D3Q4H2Q4QJASYIEOF7YIPPQBG3YQ5YI"
fee = 4
first_round = 12466
last_round = 13466
gh = "JgsgCaCTqIaLeVhyL6XlRu3n7Rfk2FxMeK+wRSaQ7dI="
gen = "devnet-v33.0"
note = base64.b64decode("6gAVR0Nsv5Y=")
close = "IDUTJEUIEVSMXTU4LGTJWZ2UE2E6TIODUKU6UW3FU3UKIQQ77RLUBBBFLA"
amount = 1000
sp = transaction.SuggestedParams(fee, first_round, last_round, gh, gen)
txn = transaction.PaymentTxn(pk, sp, to, amount, close, note)
signed_txn = txn.sign(sk)
golden = (
"gqNzaWfEQPhUAZ3xkDDcc8FvOVo6UinzmKBCqs0woYSfodlmBMfQvGbeUx3Srxy3d"
"yJDzv7rLm26BRv9FnL2/AuT7NYfiAWjdHhui6NhbXTNA+ilY2xvc2XEIEDpNJKIJW"
"TLzpxZpptnVCaJ6aHDoqnqW2Wm6KRCH/xXo2ZlZc0EmKJmds0wsqNnZW6sZGV2bmV"
"0LXYzMy4womdoxCAmCyAJoJOohot5WHIvpeVG7eftF+TYXEx4r7BFJpDt0qJsds00"
"mqRub3RlxAjqABVHQ2y/lqNyY3bEIHts4k/rW6zAsWTinCIsV/X2PcOH1DkEglhBH"
"F/hD3wCo3NuZMQg5/D4TQaBHfnzHI2HixFV9GcdUaGFwgCQhmf0SVhwaKGkdHlwZa"
"NwYXk=")
self.assertEqual(golden, encoding.msgpack_encode(signed_txn))
def test_serialize_pay_lease(self):
mn = (
"advice pudding treat near rule blouse same whisper inner electric"
" quit surface sunny dismiss leader blood seat clown cost exist ho"
"spital century reform able sponsor")
sk = mnemonic.to_private_key(mn)
pk = mnemonic.to_public_key(mn)
to = "PNWOET7LLOWMBMLE4KOCELCX6X3D3Q4H2Q4QJASYIEOF7YIPPQBG3YQ5YI"
fee = 4
first_round = 12466
last_round = 13466
gh = "JgsgCaCTqIaLeVhyL6XlRu3n7Rfk2FxMeK+wRSaQ7dI="
gen = "devnet-v33.0"
note = base64.b64decode("6gAVR0Nsv5Y=")
close = "IDUTJEUIEVSMXTU4LGTJWZ2UE2E6TIODUKU6UW3FU3UKIQQ77RLUBBBFLA"
amount = 1000
lease = bytes([1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3,
4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4])
sp = transaction.SuggestedParams(fee, first_round, last_round, gh, gen)
txn = transaction.PaymentTxn(
pk, sp, to, amount, close_remainder_to=close, note=note,
lease=lease)
signed_txn = txn.sign(sk)
golden = (
"gqNzaWfEQOMmFSIKsZvpW0txwzhmbgQjxv6IyN7BbV5sZ2aNgFbVcrWUnqPpQQxfP"
"hV/wdu9jzEPUU1jAujYtcNCxJ7ONgejdHhujKNhbXTNA+ilY2xvc2XEIEDpNJKIJW"
"TLzpxZpptnVCaJ6aHDoqnqW2Wm6KRCH/xXo2ZlZc0FLKJmds0wsqNnZW6sZGV2bmV"
"0LXYzMy4womdoxCAmCyAJoJOohot5WHIvpeVG7eftF+TYXEx4r7BFJpDt0qJsds00"
"mqJseMQgAQIDBAECAwQBAgMEAQIDBAECAwQBAgMEAQIDBAECAwSkbm90ZcQI6gAVR"
"0Nsv5ajcmN2xCB7bOJP61uswLFk4pwiLFf19j3Dh9Q5BIJYQRxf4Q98AqNzbmTEIO"
"fw+E0GgR358xyNh4sRVfRnHVGhhcIAkIZn9ElYcGihpHR5cGWjcGF5")
self.assertEqual(golden, encoding.msgpack_encode(signed_txn))
def test_serialize_keyreg(self):
mn = (
"awful drop leaf tennis indoor begin mandate discover uncle seven "
"only coil atom any hospital uncover make any climb actor armed me"
"asure need above hundred")
sk = mnemonic.to_private_key(mn)
pk = mnemonic.to_public_key(mn)
fee = 1000
gh = "SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI="
votepk = "Kv7QI7chi1y6axoy+t7wzAVpePqRq/rkjzWh/RMYyLo="
selpk = "bPgrv4YogPcdaUAxrt1QysYZTVyRAuUMD4zQmCu9llc="
votefirst = 10000
votelast = 10111
votedilution = 11
sp = transaction.SuggestedParams(
fee, 322575, 323575, gh, flat_fee=True)
txn = transaction.KeyregTxn(pk, sp, votepk, selpk, votefirst, votelast,
votedilution)
signed_txn = txn.sign(sk)
golden = (
"gqNzaWfEQEA8ANbrvTRxU9c8v6WERcEPw7D/HacRgg4vICa61vEof60Wwtx6KJKDy"
"vBuvViFeacLlngPY6vYCVP0DktTwQ2jdHhui6NmZWXNA+iiZnbOAATsD6JnaMQgSG"
"O1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiKibHbOAATv96ZzZWxrZXnEIGz"
"4K7+GKID3HWlAMa7dUMrGGU1ckQLlDA+M0JgrvZZXo3NuZMQgCfvSdiwI+Gxa5r9t"
"16epAd5mdddQ4H6MXHaYZH224f2kdHlwZaZrZXlyZWendm90ZWZzdM0nEKZ2b3Rla"
"2QLp3ZvdGVrZXnEICr+0CO3IYtcumsaMvre8MwFaXj6kav65I81of0TGMi6p3ZvdG"
"Vsc3TNJ38=")
self.assertEqual(golden, encoding.msgpack_encode(signed_txn))
def test_serialize_asset_create(self):
mn = (
"awful drop leaf tennis indoor begin mandate discover uncle seven "
"only coil atom any hospital uncover make any climb actor armed me"
"asure need above hundred")
sk = mnemonic.to_private_key(mn)
pk = mnemonic.to_public_key(mn)
fee = 10
first_round = 322575
last_round = 323575
gh = "SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI="
total = 100
assetname = "testcoin"
unitname = "tst"
url = "website"
metadata = bytes("fACPO4nRgO55j1ndAK3W6Sgc4APkcyFh", "ascii")
sp = transaction.SuggestedParams(fee, first_round, last_round, gh)
txn = transaction.AssetConfigTxn(
pk, sp, total=total, manager=pk, reserve=pk, freeze=pk,
clawback=pk, unit_name=unitname, asset_name=assetname, url=url,
metadata_hash=metadata, default_frozen=False)
signed_txn = txn.sign(sk)
golden = (
"gqNzaWfEQEDd1OMRoQI/rzNlU4iiF50XQXmup3k5czI9hEsNqHT7K4KsfmA/0DUVk"
"bzOwtJdRsHS8trm3Arjpy9r7AXlbAujdHhuh6RhcGFyiaJhbcQgZkFDUE80blJnTz"
"U1ajFuZEFLM1c2U2djNEFQa2N5RmiiYW6odGVzdGNvaW6iYXWnd2Vic2l0ZaFjxCA"
"J+9J2LAj4bFrmv23Xp6kB3mZ111Dgfoxcdphkfbbh/aFmxCAJ+9J2LAj4bFrmv23X"
"p6kB3mZ111Dgfoxcdphkfbbh/aFtxCAJ+9J2LAj4bFrmv23Xp6kB3mZ111Dgfoxcd"
"phkfbbh/aFyxCAJ+9J2LAj4bFrmv23Xp6kB3mZ111Dgfoxcdphkfbbh/aF0ZKJ1bq"
"N0c3SjZmVlzQ+0omZ2zgAE7A+iZ2jEIEhjtRiks8hOyBDyLU8QgcsPcfBZp6wg3sY"
"vf3DlCToiomx2zgAE7/ejc25kxCAJ+9J2LAj4bFrmv23Xp6kB3mZ111Dgfoxcdphk"
"fbbh/aR0eXBlpGFjZmc=")
self.assertEqual(golden, encoding.msgpack_encode(signed_txn))
def test_serialize_asset_create_decimal(self):
mn = (
"awful drop leaf tennis indoor begin mandate discover uncle seven "
"only coil atom any hospital uncover make any climb actor armed me"
"asure need above hundred")
sk = mnemonic.to_private_key(mn)
pk = mnemonic.to_public_key(mn)
fee = 10
first_round = 322575
last_round = 323575
gh = "SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI="
total = 100
assetname = "testcoin"
unitname = "tst"
url = "website"
metadata = bytes("fACPO4nRgO55j1ndAK3W6Sgc4APkcyFh", "ascii")
sp = transaction.SuggestedParams(fee, first_round, last_round, gh)
txn = transaction.AssetConfigTxn(
pk, sp, total=total, manager=pk, reserve=pk, freeze=pk,
clawback=pk, unit_name=unitname, asset_name=assetname, url=url,
metadata_hash=metadata, default_frozen=False, decimals=1)
signed_txn = txn.sign(sk)
golden = (
"gqNzaWfEQCj5xLqNozR5ahB+LNBlTG+d0gl0vWBrGdAXj1ibsCkvAwOsXs5KHZK1Y"
"dLgkdJecQiWm4oiZ+pm5Yg0m3KFqgqjdHhuh6RhcGFyiqJhbcQgZkFDUE80blJnTz"
"U1ajFuZEFLM1c2U2djNEFQa2N5RmiiYW6odGVzdGNvaW6iYXWnd2Vic2l0ZaFjxCA"
"J+9J2LAj4bFrmv23Xp6kB3mZ111Dgfoxcdphkfbbh/aJkYwGhZsQgCfvSdiwI+Gxa"
"5r9t16epAd5mdddQ4H6MXHaYZH224f2hbcQgCfvSdiwI+Gxa5r9t16epAd5mdddQ4"
"H6MXHaYZH224f2hcsQgCfvSdiwI+Gxa5r9t16epAd5mdddQ4H6MXHaYZH224f2hdG"
"SidW6jdHN0o2ZlZc0P3KJmds4ABOwPomdoxCBIY7UYpLPITsgQ8i1PEIHLD3HwWae"
"sIN7GL39w5Qk6IqJsds4ABO/3o3NuZMQgCfvSdiwI+Gxa5r9t16epAd5mdddQ4H6M"
"XHaYZH224f2kdHlwZaRhY2Zn")
self.assertEqual(golden, encoding.msgpack_encode(signed_txn))
def test_asset_empty_address_error(self):
pk = "DN7MBMCL5JQ3PFUQS7TMX5AH4EEKOBJVDUF4TCV6WERATKFLQF4MQUPZTA"
fee = 10
first_round = 322575
last_round = 323575
gh = "SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI="
index = 1234
sp = transaction.SuggestedParams(fee, first_round, last_round, gh)
self.assertRaises(error.EmptyAddressError, transaction.AssetConfigTxn,
pk, sp, reserve=pk,
freeze=pk, clawback=pk, index=index)
def test_serialize_asset_config(self):
mn = (
"awful drop leaf tennis indoor begin mandate discover uncle seven "
"only coil atom any hospital uncover make any climb actor armed me"
"asure need above hundred")
sk = mnemonic.to_private_key(mn)
pk = mnemonic.to_public_key(mn)
fee = 10
first_round = 322575
last_round = 323575
gh = "SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI="
index = 1234
sp = transaction.SuggestedParams(fee, first_round, last_round, gh)
txn = transaction.AssetConfigTxn(
pk, sp, manager=pk, reserve=pk, freeze=pk, clawback=pk,
index=index)
signed_txn = txn.sign(sk)
golden = (
"gqNzaWfEQBBkfw5n6UevuIMDo2lHyU4dS80JCCQ/vTRUcTx5m0ivX68zTKyuVRrHa"
"TbxbRRc3YpJ4zeVEnC9Fiw3Wf4REwejdHhuiKRhcGFyhKFjxCAJ+9J2LAj4bFrmv2"
"3Xp6kB3mZ111Dgfoxcdphkfbbh/aFmxCAJ+9J2LAj4bFrmv23Xp6kB3mZ111Dgfox"
"cdphkfbbh/aFtxCAJ+9J2LAj4bFrmv23Xp6kB3mZ111Dgfoxcdphkfbbh/aFyxCAJ"
"+9J2LAj4bFrmv23Xp6kB3mZ111Dgfoxcdphkfbbh/aRjYWlkzQTSo2ZlZc0NSKJmd"
"s4ABOwPomdoxCBIY7UYpLPITsgQ8i1PEIHLD3HwWaesIN7GL39w5Qk6IqJsds4ABO"
"/3o3NuZMQgCfvSdiwI+Gxa5r9t16epAd5mdddQ4H6MXHaYZH224f2kdHlwZaRhY2Z"
"n")
self.assertEqual(golden, encoding.msgpack_encode(signed_txn))
def test_serialize_asset_destroy(self):
mn = (
"awful drop leaf tennis indoor begin mandate discover uncle seven "
"only coil atom any hospital uncover make any climb actor armed me"
"asure need above hundred")
sk = mnemonic.to_private_key(mn)
pk = mnemonic.to_public_key(mn)
fee = 10
first_round = 322575
last_round = 323575
gh = "SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI="
index = 1
sp = transaction.SuggestedParams(fee, first_round, last_round, gh)
txn = transaction.AssetConfigTxn(
pk, sp, index=index, strict_empty_address_check=False)
signed_txn = txn.sign(sk)
golden = (
"gqNzaWfEQBSP7HtzD/Lvn4aVvaNpeR4T93dQgo4LvywEwcZgDEoc/WVl3aKsZGcZk"
"cRFoiWk8AidhfOZzZYutckkccB8RgGjdHhuh6RjYWlkAaNmZWXNB1iiZnbOAATsD6"
"JnaMQgSGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiKibHbOAATv96NzbmT"
"EIAn70nYsCPhsWua/bdenqQHeZnXXUOB+jFx2mGR9tuH9pHR5cGWkYWNmZw==")
self.assertEqual(golden, encoding.msgpack_encode(signed_txn))
def test_serialize_asset_freeze(self):
mn = (
"awful drop leaf tennis indoor begin mandate discover uncle seven "
"only coil atom any hospital uncover make any climb actor armed me"
"asure need above hundred")
sk = mnemonic.to_private_key(mn)
pk = mnemonic.to_public_key(mn)
fee = 10
first_round = 322575
last_round = 323576
gh = "SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI="
index = 1
target = "BH55E5RMBD4GYWXGX5W5PJ5JAHPGM5OXKDQH5DC4O2MGI7NW4H6VOE4CP4"
sp = transaction.SuggestedParams(fee, first_round, last_round, gh)
txn = transaction.AssetFreezeTxn(
pk, sp, index=index, target=target, new_freeze_state=True)
signed_txn = txn.sign(sk)
golden = (
"gqNzaWfEQAhru5V2Xvr19s4pGnI0aslqwY4lA2skzpYtDTAN9DKSH5+qsfQQhm4oq"
"+9VHVj7e1rQC49S28vQZmzDTVnYDQGjdHhuiaRhZnJ6w6RmYWRkxCAJ+9J2LAj4bF"
"rmv23Xp6kB3mZ111Dgfoxcdphkfbbh/aRmYWlkAaNmZWXNCRqiZnbOAATsD6JnaMQ"
"gSGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiKibHbOAATv+KNzbmTEIAn7"
"0nYsCPhsWua/bdenqQHeZnXXUOB+jFx2mGR9tuH9pHR5cGWkYWZyeg==")
self.assertEqual(golden, encoding.msgpack_encode(signed_txn))
def test_serialize_asset_transfer(self):
mn = (
"awful drop leaf tennis indoor begin mandate discover uncle seven "
"only coil atom any hospital uncover make any climb actor armed me"
"asure need above hundred")
sk = mnemonic.to_private_key(mn)
pk = mnemonic.to_public_key(mn)
fee = 10
first_round = 322575
last_round = 323576
gh = "SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI="
index = 1
amount = 1
to = "BH55E5RMBD4GYWXGX5W5PJ5JAHPGM5OXKDQH5DC4O2MGI7NW4H6VOE4CP4"
close = "BH55E5RMBD4GYWXGX5W5PJ5JAHPGM5OXKDQH5DC4O2MGI7NW4H6VOE4CP4"
sp = transaction.SuggestedParams(fee, first_round, last_round, gh)
txn = transaction.AssetTransferTxn(
pk, sp, to, amount, index, close)
signed_txn = txn.sign(sk)
golden = (
"gqNzaWfEQNkEs3WdfFq6IQKJdF1n0/hbV9waLsvojy9pM1T4fvwfMNdjGQDy+Lees"
"uQUfQVTneJD4VfMP7zKx4OUlItbrwSjdHhuiqRhYW10AaZhY2xvc2XEIAn70nYsCP"
"hsWua/bdenqQHeZnXXUOB+jFx2mGR9tuH9pGFyY3bEIAn70nYsCPhsWua/bdenqQH"
"eZnXXUOB+jFx2mGR9tuH9o2ZlZc0KvqJmds4ABOwPomdoxCBIY7UYpLPITsgQ8i1P"
"EIHLD3HwWaesIN7GL39w5Qk6IqJsds4ABO/4o3NuZMQgCfvSdiwI+Gxa5r9t16epA"
"d5mdddQ4H6MXHaYZH224f2kdHlwZaVheGZlcqR4YWlkAQ==")
self.assertEqual(golden, encoding.msgpack_encode(signed_txn))
def test_serialize_asset_accept(self):
mn = (
"awful drop leaf tennis indoor begin mandate discover uncle seven "
"only coil atom any hospital uncover make any climb actor armed me"
"asure need above hundred")
sk = mnemonic.to_private_key(mn)
pk = mnemonic.to_public_key(mn)
fee = 10
first_round = 322575
last_round = 323575
gh = "SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI="
index = 1
amount = 0
to = "BH55E5RMBD4GYWXGX5W5PJ5JAHPGM5OXKDQH5DC4O2MGI7NW4H6VOE4CP4"
sp = transaction.SuggestedParams(fee, first_round, last_round, gh)
txn = transaction.AssetTransferTxn(
pk, sp, to, amount, index)
signed_txn = txn.sign(sk)
golden = (
"gqNzaWfEQJ7q2rOT8Sb/wB0F87ld+1zMprxVlYqbUbe+oz0WM63FctIi+K9eYFSqT"
"26XBZ4Rr3+VTJpBE+JLKs8nctl9hgijdHhuiKRhcmN2xCAJ+9J2LAj4bFrmv23Xp6"
"kB3mZ111Dgfoxcdphkfbbh/aNmZWXNCOiiZnbOAATsD6JnaMQgSGO1GKSzyE7IEPI"
"tTxCByw9x8FmnrCDexi9/cOUJOiKibHbOAATv96NzbmTEIAn70nYsCPhsWua/bden"
"qQHeZnXXUOB+jFx2mGR9tuH9pHR5cGWlYXhmZXKkeGFpZAE=")
self.assertEqual(golden, encoding.msgpack_encode(signed_txn))
def test_serialize_asset_revoke(self):
mn = (
"awful drop leaf tennis indoor begin mandate discover uncle seven "
"only coil atom any hospital uncover make any climb actor armed me"
"asure need above hundred")
sk = mnemonic.to_private_key(mn)
pk = mnemonic.to_public_key(mn)
fee = 10
first_round = 322575
last_round = 323575
gh = "SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI="
index = 1
amount = 1
to = "BH55E5RMBD4GYWXGX5W5PJ5JAHPGM5OXKDQH5DC4O2MGI7NW4H6VOE4CP4"
sp = transaction.SuggestedParams(fee, first_round, last_round, gh)
txn = transaction.AssetTransferTxn(
pk, sp, to, amount, index, revocation_target=to)
signed_txn = txn.sign(sk)
golden = (
"gqNzaWfEQHsgfEAmEHUxLLLR9s+Y/yq5WeoGo/jAArCbany+7ZYwExMySzAhmV7M7"
"S8+LBtJalB4EhzEUMKmt3kNKk6+vAWjdHhuiqRhYW10AaRhcmN2xCAJ+9J2LAj4bF"
"rmv23Xp6kB3mZ111Dgfoxcdphkfbbh/aRhc25kxCAJ+9J2LAj4bFrmv23Xp6kB3mZ"
"111Dgfoxcdphkfbbh/aNmZWXNCqqiZnbOAATsD6JnaMQgSGO1GKSzyE7IEPItTxCB"
"yw9x8FmnrCDexi9/cOUJOiKibHbOAATv96NzbmTEIAn70nYsCPhsWua/bdenqQHeZ"
"nXXUOB+jFx2mGR9tuH9pHR5cGWlYXhmZXKkeGFpZAE=")
self.assertEqual(golden, encoding.msgpack_encode(signed_txn))
def test_pay_float_amt(self):
address = "7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q"
gh = "JgsgCaCTqIaLeVhyL6XlRu3n7Rfk2FxMeK+wRSaQ7dI="
sp = transaction.SuggestedParams(3, 1, 100, gh)
f = lambda: transaction.PaymentTxn(address, sp, address,
10., note=bytes([1, 32, 200]))
self.assertRaises(error.WrongAmountType, f)
def test_pay_negative_amt(self):
address = "7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q"
gh = "JgsgCaCTqIaLeVhyL6XlRu3n7Rfk2FxMeK+wRSaQ7dI="
sp = transaction.SuggestedParams(3, 1, 100, gh)
f = lambda: transaction.PaymentTxn(address, sp, address,
-5, note=bytes([1, 32, 200]))
self.assertRaises(error.WrongAmountType, f)
def test_asset_transfer_float_amt(self):
address = "7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q"
fee = 10
first_round = 322575
last_round = 323576
gh = "SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI="
index = 1
amount = 1.
to = "BH55E5RMBD4GYWXGX5W5PJ5JAHPGM5OXKDQH5DC4O2MGI7NW4H6VOE4CP4"
close = "BH55E5RMBD4GYWXGX5W5PJ5JAHPGM5OXKDQH5DC4O2MGI7NW4H6VOE4CP4"
sp = transaction.SuggestedParams(fee, first_round, last_round, gh)
f = lambda: transaction.AssetTransferTxn(
address, sp, to, amount, index, close)
self.assertRaises(error.WrongAmountType, f)
def test_asset_transfer_negative_amt(self):
address = "7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q"
fee = 10
first_round = 322575
last_round = 323576
gh = "SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI="
index = 1
amount = -1
to = "BH55E5RMBD4GYWXGX5W5PJ5JAHPGM5OXKDQH5DC4O2MGI7NW4H6VOE4CP4"
close = "BH55E5RMBD4GYWXGX5W5PJ5JAHPGM5OXKDQH5DC4O2MGI7NW4H6VOE4CP4"
sp = transaction.SuggestedParams(fee, first_round, last_round, gh)
f = lambda: transaction.AssetTransferTxn(
address, sp, to, amount, index, close)
self.assertRaises(error.WrongAmountType, f)
def test_group_id(self):
address = "UPYAFLHSIPMJOHVXU2MPLQ46GXJKSDCEMZ6RLCQ7GWB5PRDKJUWKKXECXI"
fromAddress, toAddress = address, address
fee = 1000
amount = 2000
genesisID = "devnet-v1.0"
genesisHash = "sC3P7e2SdbqKJK0tbiCdK9tdSpbe6XeCGKdoNzmlj0E="
firstRound1 = 710399
note1 = base64.b64decode("wRKw5cJ0CMo=")
sp = transaction.SuggestedParams(
fee, firstRound1, firstRound1+1000, genesisHash, genesisID,
flat_fee=True)
tx1 = transaction.PaymentTxn(
fromAddress, sp, toAddress, amount,
note=note1)
firstRound2 = 710515
note2 = base64.b64decode("dBlHI6BdrIg=")
sp.first = firstRound2
sp.last = firstRound2 + 1000
tx2 = transaction.PaymentTxn(
fromAddress, sp, toAddress, amount,
note=note2)
# goal clerk send dumps unsigned transaction as signed with empty
# signature in order to save tx type
stx1 = transaction.SignedTransaction(tx1, None)
stx2 = transaction.SignedTransaction(tx2, None)
goldenTx1 = (
"gaN0eG6Ko2FtdM0H0KNmZWXNA+iiZnbOAArW/6NnZW6rZGV2bmV0LXYxLjCiZ2jEI"
"LAtz+3tknW6iiStLW4gnSvbXUqW3ul3ghinaDc5pY9Bomx2zgAK2uekbm90ZcQIwR"
"Kw5cJ0CMqjcmN2xCCj8AKs8kPYlx63ppj1w5410qkMRGZ9FYofNYPXxGpNLKNzbmT"
"EIKPwAqzyQ9iXHremmPXDnjXSqQxEZn0Vih81g9fEak0spHR5cGWjcGF5"
)
goldenTx2 = (
"gaN0eG6Ko2FtdM0H0KNmZWXNA+iiZnbOAArXc6NnZW6rZGV2bmV0LXYxLjCiZ2jEI"
"LAtz+3tknW6iiStLW4gnSvbXUqW3ul3ghinaDc5pY9Bomx2zgAK21ukbm90ZcQIdB"
"lHI6BdrIijcmN2xCCj8AKs8kPYlx63ppj1w5410qkMRGZ9FYofNYPXxGpNLKNzbmT"
"EIKPwAqzyQ9iXHremmPXDnjXSqQxEZn0Vih81g9fEak0spHR5cGWjcGF5"
)
self.assertEqual(goldenTx1, encoding.msgpack_encode(stx1))
self.assertEqual(goldenTx2, encoding.msgpack_encode(stx2))
# preserve original tx{1,2} objects
tx1 = copy.deepcopy(tx1)
tx2 = copy.deepcopy(tx2)
gid = transaction.calculate_group_id([tx1, tx2])
stx1.transaction.group = gid
stx2.transaction.group = gid
# goal clerk group sets Group to every transaction and concatenate
# them in output file
# simulating that behavior here
txg = base64.b64encode(
base64.b64decode(encoding.msgpack_encode(stx1)) +
base64.b64decode(encoding.msgpack_encode(stx2))
).decode()
goldenTxg = (
"gaN0eG6Lo2FtdM0H0KNmZWXNA+iiZnbOAArW/6NnZW6rZGV2bmV0LXYxLjCiZ2jEI"
"LAtz+3tknW6iiStLW4gnSvbXUqW3ul3ghinaDc5pY9Bo2dycMQgLiQ9OBup9H/bZL"
"SfQUH2S6iHUM6FQ3PLuv9FNKyt09SibHbOAAra56Rub3RlxAjBErDlwnQIyqNyY3b"
"EIKPwAqzyQ9iXHremmPXDnjXSqQxEZn0Vih81g9fEak0so3NuZMQgo/ACrPJD2Jce"
"t6aY9cOeNdKpDERmfRWKHzWD18RqTSykdHlwZaNwYXmBo3R4boujYW10zQfQo2ZlZ"
"c0D6KJmds4ACtdzo2dlbqtkZXZuZXQtdjEuMKJnaMQgsC3P7e2SdbqKJK0tbiCdK9"
"tdSpbe6XeCGKdoNzmlj0GjZ3JwxCAuJD04G6n0f9tktJ9BQfZLqIdQzoVDc8u6/0U"
"0rK3T1KJsds4ACttbpG5vdGXECHQZRyOgXayIo3JjdsQgo/ACrPJD2Jcet6aY9cOe"
"NdKpDERmfRWKHzWD18RqTSyjc25kxCCj8AKs8kPYlx63ppj1w5410qkMRGZ9FYofN"
"YPXxGpNLKR0eXBlo3BheQ=="
)
self.assertEqual(goldenTxg, txg)
# repeat test above for assign_group_id
txa1 = copy.deepcopy(tx1)
txa2 = copy.deepcopy(tx2)
txns = transaction.assign_group_id([txa1, txa2])
self.assertEqual(len(txns), 2)
stx1 = transaction.SignedTransaction(txns[0], None)
stx2 = transaction.SignedTransaction(txns[1], None)
# goal clerk group sets Group to every transaction and concatenate
# them in output file
# simulating that behavior here
txg = base64.b64encode(
base64.b64decode(encoding.msgpack_encode(stx1)) +
base64.b64decode(encoding.msgpack_encode(stx2))
).decode()
self.assertEqual(goldenTxg, txg)
# check filtering
txns = transaction.assign_group_id([tx1, tx2], address=fromAddress)
self.assertEqual(len(txns), 2)
self.assertEqual(stx1.transaction.group, txns[0].group)
txns = transaction.assign_group_id([tx1, tx2], address="NONEXISTENT")
self.assertEqual(len(txns), 0)
class TestAssetConfigConveniences(unittest.TestCase):
"""Tests that the simplified versions of Config are equivalent to Config"""
sender = "7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q"
genesis = "JgsgCaCTqIaLeVhyL6XlRu3n7Rfk2FxMeK+wRSaQ7dI="
params = transaction.SuggestedParams(0, 1, 100, genesis)
def test_asset_create(self):
create = transaction.AssetCreateTxn(self.sender, self.params,
1000, "2", False,
manager=None,
reserve=None,
freeze=None,
clawback=None,
unit_name="NEWCOIN",
asset_name="A new kind of coin",
url="https://newcoin.co/")
config = transaction.AssetConfigTxn(self.sender, self.params, index=None,
total="1000", decimals=2,
unit_name="NEWCOIN",
asset_name="A new kind of coin",
url="https://newcoin.co/",
strict_empty_address_check=False)
self.assertEqual(create.dictify(), config.dictify())
self.assertEqual(config, create)
self.assertEqual(transaction.AssetCreateTxn.undictify(create.dictify()),
config)
def test_asset_update(self):
update = transaction.AssetUpdateTxn(self.sender, self.params, 6,
manager=None,
reserve=self.sender,
freeze=None,
clawback=None)
config = transaction.AssetConfigTxn(self.sender, self.params, index="6",
reserve=self.sender,
strict_empty_address_check=False)
self.assertEqual(update.dictify(), config.dictify())
self.assertEqual(config, update)
self.assertEqual(transaction.AssetUpdateTxn.undictify(update.dictify()),
config)
def test_asset_destroy(self):
destroy = transaction.AssetDestroyTxn(self.sender, self.params, 23)
config = transaction.AssetConfigTxn(self.sender, self.params, index="23",
strict_empty_address_check=False)
self.assertEqual(destroy.dictify(), config.dictify())
self.assertEqual(config, destroy)
self.assertEqual(transaction.AssetDestroyTxn.undictify(destroy.dictify()),
config)
class TestAssetTransferConveniences(unittest.TestCase):
sender = "7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q"
receiver = "DOMUC6VGZH7SSY5V332JR5HRLZSOJDWNPBI4OI2IIBU6A3PFLOBOXZ3KFY"
genesis = "JgsgCaCTqIaLeVhyL6XlRu3n7Rfk2FxMeK+wRSaQ7dI="
params = transaction.SuggestedParams(0, 1, 100, genesis)
def test_asset_optin(self):
optin = transaction.AssetOptInTxn(self.sender, self.params, "7")
xfer = transaction.AssetTransferTxn(self.sender, self.params, self.sender,
0, index=7)
self.assertEqual(optin.dictify(), xfer.dictify())
self.assertEqual(xfer, optin)
self.assertEqual(transaction.AssetOptInTxn.undictify(optin.dictify()),
xfer)
def test_asset_closeout(self):
closeout = transaction.AssetCloseOutTxn(self.sender, self.params,
self.receiver, "7")
xfer = transaction.AssetTransferTxn(self.sender, self.params, self.receiver,
0, index=7, close_assets_to=self.receiver)
self.assertEqual(closeout.dictify(), xfer.dictify())
self.assertEqual(xfer, closeout)
self.assertEqual(transaction.AssetCloseOutTxn.undictify(closeout.dictify()),
xfer)
class TestApplicationTransactions(unittest.TestCase):
sender = "7ZUECA7HFLZTXENRV24SHLU4AVPUTMTTDUFUBNBD64C73F3UHRTHAIOF6Q"
genesis = "JgsgCaCTqIaLeVhyL6XlRu3n7Rfk2FxMeK+wRSaQ7dI="
lschema = transaction.StateSchema(1, 2)
gschema = transaction.StateSchema(3, 4)
def test_application_call(self):
params = transaction.SuggestedParams(0, 1, 100, self.genesis)
for oc in transaction.OnComplete:
b = transaction.ApplicationCallTxn(self.sender, params, 10, oc,
app_args=[b"hello"])
s = transaction.ApplicationCallTxn(self.sender, params, "10", oc,
app_args=["hello"])
self.assertEqual(b, s) # string is encoded same as corresponding bytes
transaction.ApplicationCallTxn(self.sender, params, 10, oc,
app_args=[2,3,0]) # ints work
with self.assertRaises(AssertionError):
transaction.ApplicationCallTxn(self.sender, params, 10, oc,
app_args=[3.4]) # floats don't
with self.assertRaises(OverflowError):
transaction.ApplicationCallTxn(self.sender, params, 10, oc,
app_args=[-10]) # nor negative
transaction.ApplicationCallTxn(self.sender, params, 10, oc, # maxuint64
app_args=[18446744073709551615])
with self.assertRaises(OverflowError):
transaction.ApplicationCallTxn(self.sender, params, 10, oc, # too big
app_args=[18446744073709551616])
i = transaction.ApplicationCallTxn(self.sender, params, 10, oc,
foreign_apps=[4, 3],
foreign_assets=(2,1))
s = transaction.ApplicationCallTxn(self.sender, params, "10", oc,
foreign_apps=["4", 3],
foreign_assets=[2, "1"])
self.assertEqual(i, s) # string is encoded same as corresponding int
def test_application_create(self):
approve = b"\0"
clear = b"\1"
params = transaction.SuggestedParams(0, 1, 100, self.genesis)
for oc in transaction.OnComplete:
# We will confirm that the Create is just shorthand for
# the Call. But note that the programs come before the
# schemas and the schemas are REVERSED! That's
# unfortunate, and we should consider adding "*" to the
# argument list after on_completion, thereby forcing the
# use of named arguments.
create = transaction.ApplicationCreateTxn(self.sender, params, oc,
approve, clear,
self.lschema, self.gschema)
call = transaction.ApplicationCallTxn(self.sender, params, 0, oc,
self.gschema, self.lschema,
approve, clear)
# Check the dict first, it's important on it's own, and it
# also gives more a meaningful error if they're not equal.
self.assertEqual(create.dictify(), call.dictify())
self.assertEqual(create, call)
self.assertEqual(call, create)
def test_application_update(self):
empty = b""
params = transaction.SuggestedParams(0, 1, 100, self.genesis)
i = transaction.ApplicationUpdateTxn(self.sender, params, 10, empty, empty)
s = transaction.ApplicationUpdateTxn(self.sender, params, "10", empty, empty)
self.assertEqual(i, s) # int and string encoded same
call = transaction.ApplicationCallTxn(self.sender, params, 10,
transaction.OnComplete.UpdateApplicationOC,
None, None,
empty, empty)
self.assertEqual(i.dictify(), call.dictify())
self.assertEqual(i, call)
def test_application_delete(self):
params = transaction.SuggestedParams(0, 1, 100, self.genesis)
i = transaction.ApplicationDeleteTxn(self.sender, params, 10)
s = transaction.ApplicationDeleteTxn(self.sender, params, "10")
self.assertEqual(i, s) # int and string encoded same
call = transaction.ApplicationCallTxn(self.sender, params, 10,
transaction.OnComplete.DeleteApplicationOC)
self.assertEqual(i.dictify(), call.dictify())
self.assertEqual(i, call)
class TestMnemonic(unittest.TestCase):
zero_bytes = bytes([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
def test_mnemonic_private_key(self):
priv_key, _ = account.generate_account()
mn = mnemonic.from_private_key(priv_key)
self.assertEqual(len(mn.split(" ")), constants.mnemonic_len)
self.assertEqual(priv_key, mnemonic.to_private_key(mn))
def test_zero_mnemonic(self):
expected_mnemonic = (
"abandon abandon abandon abandon abandon abandon abandon abandon "
"abandon abandon abandon abandon abandon abandon abandon abandon "
"abandon abandon abandon abandon abandon abandon abandon abandon "
"invest")
result = mnemonic._from_key(self.zero_bytes)
self.assertEqual(expected_mnemonic, result)
result = mnemonic._to_key(result)
self.assertEqual(self.zero_bytes, result)
def test_whitespace_irrelevance(self):
padded = """
abandon abandon abandon abandon abandon abandon abandon abandon
abandon abandon abandon abandon abandon abandon abandon abandon
abandon abandon abandon abandon abandon abandon abandon abandon
invest
"""
result = mnemonic._to_key(padded)
self.assertEqual(self.zero_bytes, result)
def test_case_irrelevance(self):
padded = """
abandon ABANDON abandon abandon abandon abandon abandon abandon
abandon abandon abandon abandon abandon abandon abandon abandon
abandon abandon abandon abandon abandon abandon abandon abandon
invEST
"""
result = mnemonic._to_key(padded)
self.assertEqual(self.zero_bytes, result)
def test_short_words(self):
padded = """
aban abandon abandon abandon abandon abandon abandon abandon
aban abandon abandon abandon abandon abandon abandon abandon
aban abandon abandon abandon abandon abandon abandon abandon
inve
"""
result = mnemonic._to_key(padded)
self.assertEqual(self.zero_bytes, result)
def test_wrong_checksum(self):
mn = (
"abandon abandon abandon abandon abandon abandon abandon abandon "
"abandon abandon abandon abandon abandon abandon abandon abandon "
"abandon abandon abandon abandon abandon abandon abandon abandon "
"abandon")
self.assertRaises(error.WrongChecksumError, mnemonic._to_key, mn)
def test_word_not_in_list(self):
mn = (
"abandon abandon abandon abandon abandon abandon abandon abandon "
"abandon abandon abandon abandon abandon abandon abandon abandon "
"abandon abandon abandon venues abandon abandon abandon abandon "
"invest")
self.assertRaises(ValueError, mnemonic._to_key, mn)
mn = (
"abandon abandon abandon abandon abandon abandon abandon abandon "
"abandon abandon abandon abandon abandon abandon abandon abandon "
"abandon abandon abandon abandon abandon abandon abandon abandon "
"x-ray")
self.assertRaises(ValueError, mnemonic._to_key, mn)
def test_wordlist_integrity(self):
"""This isn't a test of _checksum, it reminds us not to change the
wordlist.
"""
result = mnemonic._checksum(bytes(wordlist.word_list_raw(), "utf-8"))
self.assertEqual(result, 1939)
def test_mnemonic_wrong_len(self):
mn = "abandon abandon abandon"
self.assertRaises(error.WrongMnemonicLengthError, mnemonic._to_key, mn)
def test_bytes_wrong_len(self):
key = bytes([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
self.assertRaises(error.WrongKeyBytesLengthError,
mnemonic._from_key, key)
def test_key_wrong_len(self):
address = "WRONG_LENGTH_TOO_SHORT"
self.assertRaises(error.WrongKeyLengthError,
encoding.decode_address, address)
class TestAddress(unittest.TestCase):
def test_is_valid(self):
valid = "MO2H6ZU47Q36GJ6GVHUKGEBEQINN7ZWVACMWZQGIYUOE3RBSRVYHV4ACJI"
self.assertTrue(encoding.is_valid_address(valid))
invalid = "MO2H6ZU47Q36GJ6GVHUKGEBEQINN7ZWVACMWZQGIYUOE3RBSRVYHV4ACJG"
self.assertFalse(encoding.is_valid_address(invalid))
def test_encode_decode(self):
sk, pk = account.generate_account()
self.assertEqual(pk, encoding.encode_address(
encoding.decode_address(pk)))
self.assertEqual(pk, account.address_from_private_key(sk))
class TestMultisig(unittest.TestCase):
def test_merge(self):
msig = transaction.Multisig(1, 2, [
"DN7MBMCL5JQ3PFUQS7TMX5AH4EEKOBJVDUF4TCV6WERATKFLQF4MQUPZTA",
"BFRTECKTOOE7A5LHCF3TTEOH2A7BW46IYT2SX5VP6ANKEXHZYJY77SJTVM",
"47YPQTIGQEO7T4Y4RWDYWEKV6RTR2UNBQXBABEEGM72ESWDQNCQ52OPASU"
])
mn = (