-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest-1.0.1.html
More file actions
2194 lines (1795 loc) · 76.3 KB
/
test-1.0.1.html
File metadata and controls
2194 lines (1795 loc) · 76.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
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
<!doctype html>
<html lang="ja">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jasmine/3.3.0/jasmine.min.css">
</head>
<body>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/3.3.0/jasmine.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/3.3.0/jasmine-html.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/3.3.0/boot.min.js"></script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://xembook.github.io/nem2-browserify/symbol-sdk-1.0.1.js"></script>
<script>
jasmine.DEFAULT_TIMEOUT_INTERVAL =240000;
describe('symbol-sdk.1.0.1',() => {
let networkType;
let minFeeMultiplier;
let medianFeeMultiplier;
let clog;
let createCompleteAggregateTx;
let createTx;
let getRandMessage;
let getSinedTx;
let bob;
let getCarolAccounts;
let getCarolAggregate;
beforeEach(async()=>{
await listener.open();
bob = nem.Account.generateNewAccount(networkType);
});
beforeAll(async()=>{
NODE = "https://sym-test-01.opening-line.jp:3001";
nem = require("/node_modules/symbol-sdk");
sha3_256 = require('/node_modules/js-sha3').sha3_256;
repo = new nem.RepositoryFactoryHttp(NODE);
nsRepo = repo.createNamespaceRepository();
txRepo = repo.createTransactionRepository();
nwRepo = repo.createNetworkRepository();
blockRepo = repo.createBlockRepository();
receiptRepo = repo.createReceiptRepository();
accountRepo = repo.createAccountRepository();
nodeRepo = repo.createNodeRepository();
tsRepo = repo.createTransactionStatusRepository();
chainRepo = repo.createChainRepository();
finRepo = repo.createFinalizationRepository();
hlRepo = repo.createHashLockRepository();
metaRepo = repo.createMetadataRepository();
mosaicRepo = repo.createMosaicRepository();
msigRepo = repo.createMultisigRepository();
resAccountRepo = repo.createRestrictionAccountRepository();
resMosaicRepo = repo.createRestrictionMosaicRepository();
slRepo = repo.createSecretLockRepository();
transactionService = new nem.TransactionService(txRepo, receiptRepo);
stateProofService = new nem.StateProofService(repo);
metaService = new nem.MetadataTransactionService(metaRepo);
mosaicResService = new nem.MosaicRestrictionTransactionService(resMosaicRepo,nsRepo)
//listener
wsEndpoint = NODE.replace('http', 'ws') + "/ws";
listener = new nem.Listener(wsEndpoint,nsRepo,WebSocket);
listener.open();
//parameter
epochAdjustment = await repo.getEpochAdjustment().toPromise();
generationHash = await repo.getGenerationHash().toPromise();
networkType = await repo.getNetworkType().toPromise();
transactionFees = await nwRepo.getTransactionFees().toPromise();
medianFeeMultiplier = transactionFees.medianFeeMultiplier;
minFeeMultiplier = transactionFees.minFeeMultiplier;
// feeAdjustment = minFeeMultiplier * 2 + medianFeeMultiplier * 2;
feeAdjustment = 100;
console.log(medianFeeMultiplier);
console.log(minFeeMultiplier);
networkCurrency = (await repo.getCurrencies().toPromise()).currency;
alice = nem.Account.createFromPrivateKey("803F16C54119EA888C2E7DDB1F5B9672ED93D44801D08DE68374A1125625B486",networkType);
clog = function(signedTx){
console.log(NODE + "/transactionStatus/" + signedTx.hash);
console.log(NODE + "/transactions/confirmed/" + signedTx.hash);
console.log("http://explorer.testnet.symboldev.network/transactions/" + signedTx.hash);
}
createTx = function(publicAccount,amount){
return nem.TransferTransaction.create(
nem.Deadline.create(epochAdjustment),
publicAccount.address,
[networkCurrency.createRelative(amount)],
nem.PlainMessage.create(""),
networkType
);
}
createTxByNamespace = function(publicAccount,amount){
const mosaicId = new nem.NamespaceId('symbol.xym');
return nem.TransferTransaction.create(
nem.Deadline.create(epochAdjustment),
publicAccount.address,
[new nem.Mosaic(mosaicId, nem.UInt64.fromUint(amount * 1000000))],
nem.PlainMessage.create(""),
networkType
);
}
createAggregateTx = function(alice,aliceAmount,bob,bobAmount){
const aggregateArray =
[createTx(bob.publicAccount,aliceAmount).toAggregate(alice.publicAccount)]
.concat([createTx(alice.publicAccount,bobAmount).toAggregate(bob.publicAccount)]);
return nem.AggregateTransaction.createComplete(
nem.Deadline.create(epochAdjustment),aggregateArray,networkType,[]
).setMaxFeeForAggregate(feeAdjustment,1);
}
getSignedTx = function(aggregateArray,cosigners){
compTx = nem.AggregateTransaction.createComplete(
nem.Deadline.create(epochAdjustment),
aggregateArray,
networkType,[]
)
.setMaxFeeForAggregate(feeAdjustment,cosigners.length)
//console.log(compTx);
return compTx.signTransactionWithCosignatories(alice,cosigners,generationHash);
}
getRandMessage = function(N){
S="abcdefghijklmnopqrstuvwxyz"
return Array.from(Array(N)).map(()=>S[Math.floor(Math.random()*S.length)]).join('')
}
getCarolAccounts = function(cnt){
carols = Array();
carolAddresses = Array();
for(let i = 0; i <= cnt; i++){
carol = nem.Account.generateNewAccount(networkType)
carolAddresses.push(carol.address);
carols.push(carol);
}
return {accounts:carols,addresses:carolAddresses}
}
getCarolAggregate = function(account,cnt){
carols = Array();
carolMultisigs = Array();
for(let i = 0; i <= cnt; i++){
carol = nem.Account.generateNewAccount(networkType)
msigTx = nem.MultisigAccountModificationTransaction.create(
nem.Deadline.create(epochAdjustment),
1,1,[account.address],[],nem.NetworkType.TEST_NET
);
carols.push(carol);
carolMultisigs.push(msigTx.toAggregate(carol.publicAccount));
}
return {aggTx:carolMultisigs,cosigs:carols};
}
});
describe('network properties', () => {
it('resolves to epochAdjustment', async () => {
expect(await repo.getEpochAdjustment().toPromise())
.toBe(1616694977)
})
it('resolves to networkType', async () => {
expect(await repo.getNetworkType().toPromise())
.toBe(152)
})
it('resolves to generationHash', async () => {
expect(await repo.getGenerationHash().toPromise())
.toBe("3B5E1FA6445653C971A50687E75E6D09FB30481055E3990C84B25E9222DC1155")
})
});
describe('Lock',() => {
it('catches Failure_LockHash_Invalid_Mosaic_Id', async () => {});
it('catches Failure_LockHash_Hash_Already_Exists', async () => {});
it('catches Failure_LockHash_Unknown_Hash', async () => {});
it('catches Failure_LockHash_Inactive_Hash', async () => {});
it('catches Failure_LockSecret_Invalid_Hash_Algorithm', async () => {});
it('catches Failure_LockSecret_Hash_Already_Exists', async () => {});
it('catches Failure_LockSecret_Proof_Size_Out_Of_Bounds', async () => {});
it('catches Failure_LockSecret_Secret_Mismatch', async () => {});
it('catches Failure_LockSecret_Unknown_Composite_Key', async () => {});
it('catches Failure_LockSecret_Inactive_Secret', async () => {});
it('catches Failure_LockSecret_Hash_Algorithm_Mismatch', async () => {});
it('catches Failure_LockHash_Invalid_Mosaic_Amount', async () => {
aggregateArray =
[createTx(bob.publicAccount,2).toAggregate(alice.publicAccount)]
.concat([createTx(alice.publicAccount,1).toAggregate(bob.publicAccount)]);
aggTx = nem.AggregateTransaction.createBonded(
nem.Deadline.create(epochAdjustment),aggregateArray,networkType,[]
).setMaxFeeForAggregate(feeAdjustment,1);
signedTx = alice.sign(aggTx, generationHash);
hashLockTx = nem.HashLockTransaction.create(
nem.Deadline.create(epochAdjustment),
networkCurrency.createRelative(9),
nem.UInt64.fromUint(480),
signedTx,
networkType,
nem.UInt64.fromUint(1000000)
);
signedLockTx = alice.sign(hashLockTx, generationHash);
await expectAsync( transactionService.announce(signedLockTx,listener).toPromise())
.toBeRejectedWith(new Error('Failure_LockHash_Invalid_Mosaic_Amount'))
});
it('catches Failure_LockHash_Invalid_Duration', async () => {
aggregateArray =
[createTx(bob.publicAccount,2).toAggregate(alice.publicAccount)]
.concat([createTx(alice.publicAccount,1).toAggregate(bob.publicAccount)]);
aggTx = nem.AggregateTransaction.createBonded(
nem.Deadline.create(epochAdjustment),aggregateArray,networkType,[]
).setMaxFeeForAggregate(feeAdjustment,1);
signedTx = alice.sign(aggTx, generationHash);
hashLockTx = nem.HashLockTransaction.create(
nem.Deadline.create(epochAdjustment),
networkCurrency.createRelative(10),
nem.UInt64.fromUint(2 * 24 * 60 * 60 / 30 + 1),
signedTx,
networkType,
nem.UInt64.fromUint(1000000)
);
signedLockTx = alice.sign(hashLockTx, generationHash);
await expectAsync( transactionService.announce(signedLockTx,listener).toPromise())
.toBeRejectedWith(new Error('Failure_LockHash_Invalid_Duration'))
});
it('catches Failure_LockSecret_Invalid_Duration', async () => {
carol = nem.Account.generateNewAccount(networkType);
random = nem.Crypto.randomBytes(20);
proof = random.toString('hex'); //秘密の合言葉
hash = sha3_256.create();
secret = hash.update(random).hex().toUpperCase();//ダイジェスト
tx = nem.SecretLockTransaction.create(
nem.Deadline.create(epochAdjustment),
networkCurrency.createRelative(1),
nem.UInt64.fromUint(365 * 24 * 3600 / 30 + 1),
nem.LockHashAlgorithm.Op_Sha3_256,
secret,
carol.address,
networkType
);
const aggregateArray =
[createTx(bob.publicAccount,2).toAggregate(alice.publicAccount)]
.concat([tx.toAggregate(bob.publicAccount)]);
const signedTx = nem.AggregateTransaction.createComplete(
nem.Deadline.create(epochAdjustment),aggregateArray,networkType,[]
).setMaxFeeForAggregate(feeAdjustment,1)
.signTransactionWithCosignatories(alice,[bob],generationHash);
await expectAsync( transactionService.announce(signedTx,listener).toPromise())
.toBeRejectedWith(new Error('Failure_LockSecret_Invalid_Duration'))
});
});
describe('Transaction',() => {
it('catches Failure_Core_Nemesis_Account_Signed_After_Nemesis_Block', async () => {});
it('catches Failure_Core_Invalid_Version', async () => {});
it('catches Failure_Core_Invalid_Transaction_Fee', async () => {});
it('catches Failure_Core_Block_Harvester_Ineligible', async () => {});
it('catches Failure_Core_Zero_Address', async () => {});
it('catches Failure_Core_Zero_Public_Key', async () => {});
it('catches Failure_Core_Nonzero_Internal_Padding', async () => {});
it('catches Failure_Core_Address_Collision', async () => {});
it('catches Failure_Core_Invalid_Link_Action', async () => {});
it('catches Failure_Core_Link_Already_Exists', async () => {});
it('catches Failure_Core_Inconsistent_Unlink_Data', async () => {});
it('catches Failure_Core_Invalid_Link_Range', async () => {});
it('catches Failure_Core_Too_Many_Links', async () => {});
it('catches Failure_Aggregate_No_Transactions', async () => {});
it('catches Failure_Aggregate_Transactions_Hash_Mismatch', async () => {});
it('catches Failure_Core_Insufficient_Balance', async () => {
const signedTx = createAggregateTx(alice,1,bob,2)
.signTransactionWithCosignatories(alice,[bob],generationHash);
await expectAsync( transactionService.announce(signedTx,listener).toPromise())
.toBeRejectedWith(new Error('Failure_Core_Insufficient_Balance'))
});
it('catches Failure_Aggregate_Missing_Cosignatures', async () => {
const signedTx = createAggregateTx(alice,2,bob,1)
.signTransactionWithCosignatories(alice,[],generationHash);
await expectAsync( transactionService.announce(signedTx,listener).toPromise())
.toBeRejectedWith(new Error('Failure_Aggregate_Missing_Cosignatures'))
});
it('catches Failure_Aggregate_Redundant_Cosignatures', async () => {
const signedTx = createAggregateTx(alice,2,bob,1)
.signTransactionWithCosignatories(alice,[bob,bob],generationHash);
await expectAsync( transactionService.announce(signedTx,listener).toPromise())
.toBeRejectedWith(new Error('Failure_Aggregate_Redundant_Cosignatures'))
});
it('catches Failure_Core_Invalid_Address', async () => {
carol = nem.Account.generateNewAccount(networkType + 1);
const signedTx = createAggregateTx(alice,2,carol,1)
.signTransactionWithCosignatories(alice,[carol],generationHash);
await expectAsync( transactionService.announce(signedTx,listener).toPromise())
.toBeRejectedWith(new Error('Failure_Core_Invalid_Address'));
});
it('catches Failure_Core_Future_Deadline', async () => {
const aggregateArray =
[createTx(bob.publicAccount,2).toAggregate(alice.publicAccount)]
.concat([createTx(alice.publicAccount,1).toAggregate(bob.publicAccount)]);
const aggregateTx = nem.AggregateTransaction.createComplete(
nem.Deadline.create(0),aggregateArray,networkType,[]
).setMaxFeeForAggregate(feeAdjustment,1);
const signedTx = aggregateTx.signTransactionWithCosignatories(alice,[bob],generationHash);
await expectAsync( transactionService.announce(signedTx,listener).toPromise())
.toBeRejectedWith(new Error('Failure_Core_Future_Deadline'))
});
it('catches Failure_Core_Past_Deadline', async () => {
const aggregateArray =
[createTx(bob.publicAccount,2).toAggregate(alice.publicAccount)]
.concat([createTx(alice.publicAccount,1).toAggregate(bob.publicAccount)]);
const aggregateTx = nem.AggregateTransaction.createComplete(
nem.Deadline.create(epochAdjustment + 7200),aggregateArray,networkType,[]
).setMaxFeeForAggregate(feeAdjustment,1);
const signedTx = aggregateTx.signTransactionWithCosignatories(alice,[bob],generationHash);
await expectAsync( transactionService.announce(signedTx,listener).toPromise())
.toBeRejectedWith(new Error('Failure_Core_Past_Deadline'))
});
it('catches Failure_Core_Wrong_Network', async () => {
const aggregateArray =
[createTx(bob.publicAccount,2).toAggregate(alice.publicAccount)]
.concat(createTx(alice.publicAccount,1).toAggregate(bob.publicAccount));
const aggregateTx = nem.AggregateTransaction.createComplete(
nem.Deadline.create(epochAdjustment),aggregateArray,networkType + 1,[]
).setMaxFeeForAggregate(feeAdjustment,1);
const signedTx = aggregateTx.signTransactionWithCosignatories(alice,[bob],generationHash);
await expectAsync( transactionService.announce(signedTx,listener).toPromise())
.toBeRejectedWith(new Error('Failure_Core_Wrong_Network'));
});
it('catches Failure_Aggregate_Too_Many_Transactions', async () => {
let aggregateArray = Array();
for(let i=0;i<=100;i++){
aggregateArray.push(createTx(bob.publicAccount,0).toAggregate(alice.publicAccount));
}
const aggregateTx = nem.AggregateTransaction.createComplete(
nem.Deadline.create(epochAdjustment),aggregateArray,networkType,[]
).setMaxFeeForAggregate(feeAdjustment,0);
const signedTx = aggregateTx.signTransactionWithCosignatories(alice,[],generationHash);
await expectAsync( transactionService.announce(signedTx,listener).toPromise())
.toBeRejectedWith(new Error('Failure_Aggregate_Too_Many_Transactions'));
});
it('catches Failure_Aggregate_Too_Many_Cosignatures', async () => {
carols = Array();
carolAddresses = Array();
for(let i=0;i<=25;i++){
carol = nem.Account.generateNewAccount(networkType)
carolAddresses.push(carol.address);
carols.push(carol);
}
msigTx = nem.MultisigAccountModificationTransaction.create(
nem.Deadline.create(epochAdjustment),
1,1,carolAddresses,[],nem.NetworkType.TEST_NET
);
const aggregateArray =
[createTx(bob.publicAccount,2,epochAdjustment).toAggregate(alice.publicAccount)]
.concat(msigTx.toAggregate(bob.publicAccount));
const aggregateTx = nem.AggregateTransaction.createComplete(
nem.Deadline.create(epochAdjustment),aggregateArray,networkType,[]
).setMaxFeeForAggregate(feeAdjustment,carolAddresses.length + 1);
cosigns = [bob].concat(carols);
const signedTx = aggregateTx.signTransactionWithCosignatories(alice,cosigns,generationHash);
await expectAsync( transactionService.announce(signedTx,listener).toPromise())
.toBeRejectedWith(new Error('Failure_Aggregate_Too_Many_Cosignatures'));
});
it('catches Failure_Aggregate_Ineligible_Cosignatories', async () => {
carol = nem.Account.generateNewAccount(networkType)
carol1 = nem.Account.generateNewAccount(networkType)
msigTx = nem.MultisigAccountModificationTransaction.create(
nem.Deadline.create(epochAdjustment),
1,1,[carol.address],[],nem.NetworkType.TEST_NET
);
const aggregateArray =
[createTx(bob.publicAccount,6).toAggregate(alice.publicAccount)]
.concat(msigTx.toAggregate(bob.publicAccount))
signedTx = getSignedTx(aggregateArray,[bob,carol1].concat(carol));
await expectAsync( transactionService.announce(signedTx,listener).toPromise())
.toBeRejectedWith(new Error('Failure_Aggregate_Ineligible_Cosignatories'));
});
it('catches Failure_Transfer_Message_Too_Large', async () => {
const signedTx = nem.TransferTransaction.create(
nem.Deadline.create(epochAdjustment),
alice.address,
[networkCurrency.createRelative(0)],
nem.PlainMessage.create(getRandMessage(1024)),
networkType
).setMaxFee(feeAdjustment)
.signWith(alice,generationHash);
await expectAsync( transactionService.announce(signedTx,listener).toPromise())
.toBeRejectedWith(new Error('Failure_Transfer_Message_Too_Large'));
});
it('catches Failure_Transfer_Out_Of_Order_Mosaics', async () => {
tx = nem.TransferTransaction.create(
nem.Deadline.create(epochAdjustment),
bob.address,
[
networkCurrency.createRelative(1),
networkCurrency.createRelative(1)
],
nem.PlainMessage.create(""),
networkType
).setMaxFee(feeAdjustment);
const signedTx = tx.signWith(alice,generationHash);
await expectAsync( transactionService.announce(signedTx,listener).toPromise())
.toBeRejectedWith(new Error('Failure_Transfer_Out_Of_Order_Mosaics'))
});
});
describe('Multisig',() => {
it('catches Failure_Multisig_Redundant_Modification', async () => {});
it('catches Failure_Multisig_Unknown_Multisig_Account', async () => {});
it('catches Failure_Multisig_Not_A_Cosignatory', async () => {});
it('catches Failure_Multisig_Max_Multisig_Depth', async () => {
carol = nem.Account.generateNewAccount(networkType)
carol1 = nem.Account.generateNewAccount(networkType)
carol2 = nem.Account.generateNewAccount(networkType)
carol3 = nem.Account.generateNewAccount(networkType)
msigTx = nem.MultisigAccountModificationTransaction.create(
nem.Deadline.create(epochAdjustment),
1,1,[carol.address],[],networkType
);
msigTx1 = nem.MultisigAccountModificationTransaction.create(
nem.Deadline.create(epochAdjustment),
1,1,[carol1.address],[],networkType
);
msigTx2 = nem.MultisigAccountModificationTransaction.create(
nem.Deadline.create(epochAdjustment),
1,1,[carol2.address],[],networkType
);
msigTx3 = nem.MultisigAccountModificationTransaction.create(
nem.Deadline.create(epochAdjustment),
1,1,[carol3.address],[],networkType
);
const aggregateArray =
[createTx(bob.publicAccount,0).toAggregate(alice.publicAccount)]
.concat(msigTx.toAggregate(bob.publicAccount))
.concat(msigTx1.toAggregate(carol.publicAccount))
.concat(msigTx2.toAggregate(carol1.publicAccount))
.concat(msigTx3.toAggregate(carol2.publicAccount))
signedTx = getSignedTx(aggregateArray,[bob,carol,carol1,carol2,carol3]);
await expectAsync( transactionService.announce(signedTx,listener).toPromise())
.toBeRejectedWith(new Error('Failure_Multisig_Max_Multisig_Depth'));
});
it('catches Failure_Multisig_Min_Setting_Out_Of_Range', async () => {
carol = nem.Account.generateNewAccount(networkType)
msigTx = nem.MultisigAccountModificationTransaction.create(
nem.Deadline.create(epochAdjustment),
200,1,[carol.address],[],nem.NetworkType.TEST_NET
);
const aggregateArray =
[createTx(bob.publicAccount,0).toAggregate(alice.publicAccount)]
.concat(msigTx.toAggregate(bob.publicAccount))
signedTx = getSignedTx(aggregateArray,[bob,carol]);
await expectAsync( transactionService.announce(signedTx,listener).toPromise())
.toBeRejectedWith(new Error('Failure_Multisig_Min_Setting_Out_Of_Range'));
});
it('catches Failure_Multisig_Min_Setting_Out_Of_Range minus', async () => {
carol = nem.Account.generateNewAccount(networkType)
msigTx = nem.MultisigAccountModificationTransaction.create(
nem.Deadline.create(epochAdjustment),
-1,1,[carol.address],[],nem.NetworkType.TEST_NET
);
const aggregateArray =
[createTx(bob.publicAccount,0).toAggregate(alice.publicAccount)]
.concat(msigTx.toAggregate(bob.publicAccount))
signedTx = getSignedTx(aggregateArray,[bob,carol]);
await expectAsync( transactionService.announce(signedTx,listener).toPromise())
.toBeRejectedWith(new Error('Failure_Multisig_Min_Setting_Out_Of_Range'));
});
it('catches Failure_Multisig_Min_Setting_Larger_Than_Num_Cosignatories', async () => {
carol = nem.Account.generateNewAccount(networkType)
msigTx = nem.MultisigAccountModificationTransaction.create(
nem.Deadline.create(epochAdjustment),
2,1,[carol.address],[],nem.NetworkType.TEST_NET
);
const aggregateArray =
[createTx(bob.publicAccount,0).toAggregate(alice.publicAccount)]
.concat(msigTx.toAggregate(bob.publicAccount))
signedTx = getSignedTx(aggregateArray,[bob,carol]);
await expectAsync( transactionService.announce(signedTx,listener).toPromise())
.toBeRejectedWith(new Error('Failure_Multisig_Min_Setting_Larger_Than_Num_Cosignatories'));
});
it('catches Failure_Multisig_Max_Cosigned_Accounts', async () => {
carolsAggTxs = getCarolAggregate(bob,20);
const aggregateArray =
[createTx(bob.publicAccount,10).toAggregate(alice.publicAccount)]
.concat(carolsAggTxs.aggTx)
signedTx = getSignedTx(aggregateArray,[bob].concat(carolsAggTxs.cosigs));
res = await transactionService.announce(
signedTx
,listener).toPromise()
console.log(res);
carolsAggTxs2 = getCarolAggregate(bob,20);
const aggregateArray2 =
[createTx(bob.publicAccount,10).toAggregate(alice.publicAccount)]
.concat(carolsAggTxs2.aggTx)
signedTx2 = getSignedTx(aggregateArray2,[bob].concat(carolsAggTxs2.cosigs));
await expectAsync( transactionService.announce(signedTx2,listener).toPromise())
.toBeRejectedWith(new Error('Failure_Multisig_Max_Cosigned_Accounts'));
});
it('catches Failure_Multisig_Max_Cosignatories', async () => {
dave = nem.Account.generateNewAccount(networkType);
carols = getCarolAccounts(20);
msigTx = nem.MultisigAccountModificationTransaction.create(
nem.Deadline.create(epochAdjustment),
1,1,[dave.address].concat(carols.addresses),[],nem.NetworkType.TEST_NET
);
const aggregateArray =
[createTx(bob.publicAccount,10).toAggregate(alice.publicAccount)]
.concat(createTx(dave.publicAccount,5).toAggregate(alice.publicAccount))
.concat(msigTx.toAggregate(bob.publicAccount));
signedTx = getSignedTx(aggregateArray,[bob].concat(carols.accounts).concat(dave));
res = await transactionService.announce(
signedTx
,listener).toPromise()
console.log(res);
carols2 = getCarolAccounts(20);
const signedTx2 = nem.AggregateTransaction.createComplete(
nem.Deadline.create(epochAdjustment),
[
nem.MultisigAccountModificationTransaction.create(
nem.Deadline.create(epochAdjustment),
1,1,carols2.addresses,[],nem.NetworkType.TEST_NET)
.toAggregate(bob.publicAccount)
],
networkType,[]
).setMaxFeeForAggregate(feeAdjustment,carols2.addresses.length)
.signTransactionWithCosignatories(dave,carols2.accounts,generationHash);
await expectAsync( transactionService.announce(signedTx2,listener).toPromise())
.toBeRejectedWith(new Error('Failure_Multisig_Max_Cosignatories'));
});
it('catches Failure_Multisig_Multiple_Deletes', async () => {
carols = getCarolAccounts(20);
msigTx = nem.MultisigAccountModificationTransaction.create(
nem.Deadline.create(epochAdjustment),
1,1,[],carols.addresses,nem.NetworkType.TEST_NET
);
const aggregateArray =
[createTx(bob.publicAccount,0).toAggregate(alice.publicAccount)]
.concat(msigTx.toAggregate(bob.publicAccount));
await expectAsync( transactionService.announce(
getSignedTx(aggregateArray,[bob].concat(carols.accounts))
,listener).toPromise())
.toBeRejectedWith(new Error('Failure_Multisig_Multiple_Deletes'));
});
it('catches Failure_Multisig_Already_A_Cosignatory', async () => {
dave = nem.Account.generateNewAccount(networkType);
carols = getCarolAccounts(5);
msigTx = nem.MultisigAccountModificationTransaction.create(
nem.Deadline.create(epochAdjustment),
1,1,[dave.address].concat(carols.addresses),[],nem.NetworkType.TEST_NET
);
msigTx2 = nem.MultisigAccountModificationTransaction.create(
nem.Deadline.create(epochAdjustment),
1,1,carols.addresses,[],nem.NetworkType.TEST_NET
);
const aggregateArray =
[createTx(bob.publicAccount,0).toAggregate(alice.publicAccount)]
.concat(createTx(dave.publicAccount,0).toAggregate(alice.publicAccount))
.concat(msigTx.toAggregate(bob.publicAccount))
.concat(msigTx2.toAggregate(bob.publicAccount));
await expectAsync( transactionService.announce(
getSignedTx(aggregateArray,[bob].concat(carols.accounts).concat(dave))
,listener).toPromise())
.toBeRejectedWith(new Error('Failure_Multisig_Already_A_Cosignatory'));
});
it('catches Failure_Multisig_Operation_Prohibited_By_Account', async () => {
carols = getCarolAccounts(1);
msigTx = nem.MultisigAccountModificationTransaction.create(
nem.Deadline.create(epochAdjustment),
1,1,carols.addresses,[],nem.NetworkType.TEST_NET
);
const aggregateArray =
[createTx(bob.publicAccount,4).toAggregate(alice.publicAccount)]
.concat(msigTx.toAggregate(bob.publicAccount))
.concat(createTx(alice.publicAccount,0).toAggregate(bob.publicAccount))
res = await expectAsync( transactionService.announce(
getSignedTx(aggregateArray,[bob].concat(carols.accounts))
,listener).toPromise())
await expectAsync( transactionService.announce(
createTx(alice.publicAccount,0)
.setMaxFee(feeAdjustment).signWith(bob,generationHash)
,listener).toPromise())
.toBeRejectedWith(new Error('Failure_Multisig_Operation_Prohibited_By_Account'));
});
it('catches Failure_Multisig_Loop', async () => {
carol = nem.Account.generateNewAccount(networkType)
carol1 = nem.Account.generateNewAccount(networkType)
msigTx = nem.MultisigAccountModificationTransaction.create(
nem.Deadline.create(epochAdjustment),
1,1,[carol.address],[],nem.NetworkType.TEST_NET
);
msigTx1 = nem.MultisigAccountModificationTransaction.create(
nem.Deadline.create(epochAdjustment),
1,1,[carol1.address],[],nem.NetworkType.TEST_NET
);
const aggregateArray =
[createTx(bob.publicAccount,6).toAggregate(alice.publicAccount)]
.concat(msigTx.toAggregate(carol.publicAccount))
.concat(msigTx1.toAggregate(bob.publicAccount))
signedTx = getSignedTx(aggregateArray,[bob,carol]);
await listener.open();
await expectAsync( transactionService.announce(signedTx,listener).toPromise())
.toBeRejectedWith(new Error('Failure_Multisig_Loop'));
});
it('catches Failure_Multisig_Account_In_Both_Sets', async () => {
carol = nem.Account.generateNewAccount(networkType)
msigTx = nem.MultisigAccountModificationTransaction.create(
nem.Deadline.create(epochAdjustment),
1,1,[carol.address],[carol.address],nem.NetworkType.TEST_NET
);
const aggregateArray =
[createTx(bob.publicAccount,0).toAggregate(alice.publicAccount)]
.concat(msigTx.toAggregate(carol.publicAccount))
signedTx = getSignedTx(aggregateArray,[bob,carol]);
await expectAsync( transactionService.announce(signedTx,listener).toPromise())
.toBeRejectedWith(new Error('Failure_Multisig_Account_In_Both_Sets'));
});
});
describe('Metadata',() => {
it('catches Failure_Metadata_Value_Too_Small', async () => {});
it('catches Failure_Metadata_Value_Size_Delta_Too_Large', async () => {});
it('catches Failure_Metadata_Value_Size_Delta_Mismatch', async () => {});
it('catches Failure_Metadata_Value_Change_Irreversible', async () => {});
it('catches Failure_Metadata_Value_Too_Large', async () => {
accountKey = nem.KeyGenerator.generateUInt64Key("key_account");
createAccountMetaTx = await metaService.createAccountMetadataTransaction(
nem.Deadline.create(epochAdjustment),
networkType,
bob.address,//target
accountKey,
getRandMessage(1025),
bob.address // sender
).toPromise();
const aggregateArray =
[createTx(bob.publicAccount,0).toAggregate(alice.publicAccount)]
.concat(createAccountMetaTx.toAggregate(bob.publicAccount));
await expectAsync( transactionService.announce(
getSignedTx(aggregateArray,[bob])
,listener).toPromise())
.toBeRejectedWith(new Error('Failure_Metadata_Value_Too_Large'));
});
it('catches Failure_Metadata_Value_Too_Large', async () => {
randomId = getRandMessage(56).toLowerCase();
mosaicId = new nem.NamespaceId( "mosaic__" + randomId);
mosaicKey = nem.KeyGenerator.generateUInt64Key("key_mosaic");
createMosaicMetaTx = await metaService.createMosaicMetadataTransaction(
nem.Deadline.create(epochAdjustment),
networkType,
bob.address,
mosaicId,
mosaicKey,
getRandMessage(1025),
bob.address
).toPromise();
const aggregateArray =
[createTx(bob.publicAccount,0).toAggregate(alice.publicAccount)]
.concat(createMosaicMetaTx.toAggregate(bob.publicAccount));
await expectAsync( transactionService.announce(
getSignedTx(aggregateArray,[bob])
,listener).toPromise())
.toBeRejectedWith(new Error('Failure_Metadata_Value_Too_Large'));
});
it('catches Failure_Metadata_Value_Too_Large', async () => {
randomId = getRandMessage(56).toLowerCase();
accountId = new nem.NamespaceId("account_" + randomId);
namespaceKey = nem.KeyGenerator.generateUInt64Key("key_namespace");
createNamespaceMetaTx = await metaService.createNamespaceMetadataTransaction(
nem.Deadline.create(epochAdjustment),
networkType,
bob.address,
accountId,
namespaceKey,
getRandMessage(1025),
bob.address
).toPromise();
const aggregateArray =
[createTx(bob.publicAccount,0).toAggregate(alice.publicAccount)]
.concat(createNamespaceMetaTx.toAggregate(bob.publicAccount));
await expectAsync( transactionService.announce(
getSignedTx(aggregateArray,[bob])
,listener).toPromise())
.toBeRejectedWith(new Error('Failure_Metadata_Value_Too_Large'));
});
});
describe('Restriction',() => {
beforeAll(async()=>{
mosaicAddressResTx = function(account,mosaicId,value){
resKey = nem.KeyGenerator.generateUInt64Key("KYC".toLowerCase());
return nem.MosaicAddressRestrictionTransaction.create(
nem.Deadline.create(epochAdjustment),
mosaicId, // mosaicId
resKey, // restrictionKey
account.address, // address
nem.UInt64.fromUint(value), // newRestrictionValue
networkType,
);
}
})
it('catches Failure_RestrictionAccount_Invalid_Restriction_Flags', async () => {});
// it('catches Failure_RestrictionAccount_Invalid_Modification_Action', async () => {});
it('catches Failure_RestrictionAccount_Invalid_Modification_Address', async () => {});
// it('catches Failure_RestrictionAccount_Modification_Operation_Type_Incompatible', async () => {});
it('catches Failure_RestrictionAccount_Redundant_Modification', async () => {});
it('catches Failure_RestrictionAccount_Invalid_Modification', async () => {});
it('catches Failure_RestrictionAccount_Modification_Count_Exceeded', async () => {});
it('catches Failure_RestrictionAccount_No_Modifications', async () => {});
it('catches Failure_RestrictionAccount_Values_Count_Exceeded', async () => {});
it('catches Failure_RestrictionAccount_Invalid_Value', async () => {});
it('catches Failure_RestrictionAccount_Operation_Type_Prohibited', async () => {});
it('catches Failure_RestrictionMosaic_Invalid_Restriction_Type', async () => {});
it('catches Failure_RestrictionMosaic_Previous_Value_Mismatch', async () => {});
it('catches Failure_RestrictionMosaic_Previous_Value_Must_Be_Zero', async () => {});
it('catches Failure_RestrictionMosaic_Max_Restrictions_Exceeded', async () => {});
it('catches Failure_RestrictionMosaic_Cannot_Delete_Nonexistent_Restriction', async () => {});
it('catches Failure_RestrictionMosaic_Unknown_Global_Restriction', async () => {});
it('catches Failure_RestrictionMosaic_Invalid_Global_Restriction', async () => {});
it('catches Failure_RestrictionMosaic_Account_Unauthorized', async () => {
carol1 = nem.Account.generateNewAccount(networkType);
nonce = nem.MosaicNonce.createRandom();
mosaicId = nem.MosaicId.createFromNonce(nonce, bob.address)
//モザイク作成
mosaicDefTx = nem.MosaicDefinitionTransaction.create(
nem.Deadline.create(epochAdjustment),
nonce,
mosaicId,
nem.MosaicFlags.create(true, true, true),
0,
nem.UInt64.fromUint(0),
networkType
);
//モザイク変更
mosaicChangeTx = nem.MosaicSupplyChangeTransaction.create(
nem.Deadline.create(epochAdjustment),
mosaicDefTx.mosaicId,
nem.MosaicSupplyChangeAction.Increase,
nem.UInt64.fromUint(1000000),
networkType
);
resKey = nem.KeyGenerator.generateUInt64Key("KYC".toLowerCase());
creatreMosaicGlobalResTx = nem.MosaicGlobalRestrictionTransaction.create(
nem.Deadline.create(epochAdjustment),
mosaicId, // mosaicId
resKey, // restrictionKey
nem.UInt64.fromUint(0), // previousRestrictionValue
nem.MosaicRestrictionType.NONE, // previousRestrictionType
nem.UInt64.fromUint(1), // newRestrictionValue
nem.MosaicRestrictionType.EQ, // newRestrictionType
networkType,
undefined
);
distMosaicTx = function(publicAccount,mosaicId){
message = getRandMessage(1023);
return nem.TransferTransaction.create(
nem.Deadline.create(epochAdjustment),
publicAccount.address,
[new nem.Mosaic(mosaicId, nem.UInt64.fromUint(1))],
nem.PlainMessage.create(message),
networkType
);
}
const aggregateArray =
[createTx(bob.publicAccount,100).toAggregate(alice.publicAccount)]
.concat(mosaicDefTx.toAggregate(bob.publicAccount))
.concat(mosaicChangeTx.toAggregate(bob.publicAccount))
.concat(creatreMosaicGlobalResTx.toAggregate(bob.publicAccount))
.concat(mosaicAddressResTx(bob,mosaicId,1).toAggregate(bob.publicAccount))
.concat(mosaicAddressResTx(carol1,mosaicId,0).toAggregate(bob.publicAccount))
.concat(distMosaicTx(carol1.publicAccount,mosaicId).toAggregate(bob.publicAccount));
await expectAsync( transactionService.announce(
getSignedTx(aggregateArray,[bob])
,listener).toPromise())
.toBeRejectedWith(new Error('Failure_RestrictionMosaic_Account_Unauthorized'));
});
it('catches Failure_RestrictionAccount_Address_Interaction_Prohibited AllowIncomingAddress', async () => {
carol1 = nem.Account.generateNewAccount(networkType);
nonce = nem.MosaicNonce.createRandom();
mosaicId = nem.MosaicId.createFromNonce(nonce, bob.address)
addressResTx = nem.AccountRestrictionTransaction.createAddressRestrictionModificationTransaction(
nem.Deadline.create(epochAdjustment),
nem.AddressRestrictionFlag.AllowIncomingAddress,
[carol1.address],
[],
networkType
);
const aggregateArray =
[addressResTx.toAggregate(bob.publicAccount)]
.concat(createTx(bob.publicAccount,1).toAggregate(alice.publicAccount))
await expectAsync( transactionService.announce(
getSignedTx(aggregateArray,[bob])
,listener).toPromise())
.toBeRejectedWith(new Error('Failure_RestrictionAccount_Address_Interaction_Prohibited'));
});
it('catches Failure_RestrictionAccount_Address_Interaction_Prohibited BlockIncomingAddress', async () => {
carol1 = nem.Account.generateNewAccount(networkType);
nonce = nem.MosaicNonce.createRandom();
mosaicId = nem.MosaicId.createFromNonce(nonce, bob.address)
addressResTx = nem.AccountRestrictionTransaction.createAddressRestrictionModificationTransaction(
nem.Deadline.create(epochAdjustment),
nem.AddressRestrictionFlag.BlockIncomingAddress,
[alice.address],
[],
networkType
);
const aggregateArray =
[addressResTx.toAggregate(bob.publicAccount)]
.concat(createTx(bob.publicAccount,1).toAggregate(alice.publicAccount))
await expectAsync( transactionService.announce(
getSignedTx(aggregateArray,[bob])
,listener).toPromise())
.toBeRejectedWith(new Error('Failure_RestrictionAccount_Address_Interaction_Prohibited'));
});
it('catches Failure_RestrictionAccount_Address_Interaction_Prohibited AllowOutgoingAddress', async () => {
carol1 = nem.Account.generateNewAccount(networkType);
nonce = nem.MosaicNonce.createRandom();
mosaicId = nem.MosaicId.createFromNonce(nonce, bob.address)
addressResTx = nem.AccountRestrictionTransaction.createAddressRestrictionModificationTransaction(
nem.Deadline.create(epochAdjustment),
nem.AddressRestrictionFlag.AllowOutgoingAddress,
[alice.address],
[],
networkType
);
const aggregateArray =
[addressResTx.toAggregate(bob.publicAccount)]
.concat(createTx(bob.publicAccount,2).toAggregate(alice.publicAccount))
.concat(createTx(carol1.publicAccount,1).toAggregate(bob.publicAccount))
await expectAsync( transactionService.announce(
getSignedTx(aggregateArray,[bob])
,listener).toPromise())
.toBeRejectedWith(new Error('Failure_RestrictionAccount_Address_Interaction_Prohibited'));
});
it('catches Failure_RestrictionAccount_Address_Interaction_Prohibited BlockOutgoingAddress', async () => {