-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathtest.js
9570 lines (8713 loc) · 256 KB
/
test.js
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
var assert = require("assert");
var fs = require("fs");
var util = require("ethereumjs-util");
const constants = require("./constants.js");
const { web3 } = require("./web3");
const { Tester, longer } = require("./testHelpers");
const {
testAccountRecoveryManager
} = require("./contracts/account-recovery/testAccountRecoveryManager");
const {
testUpgradeBeaconController
} = require("./contracts/upgradeability/testUpgradeBeaconController");
const {
testUpgradeBeaconControllerManagerPartOne,
testUpgradeBeaconControllerManagerPartTwo
} = require("./contracts/upgradeability/testUpgradeBeaconControllerManager");
const {
testKeyRegistryV2
} = require("./contracts/registries/testKeyRegistryV2");
const {
testPerformingUpgrade
} = require("./contracts/upgradeability/testPerformingUpgrade");
const AdharmaSmartWalletImplementationArtifact = require("../../build/contracts/AdharmaSmartWalletImplementation.json");
const AdharmaKeyRingImplementationArtifact = require("../../build/contracts/AdharmaKeyRingImplementation.json");
const DharmaSmartWalletImplementationV6Artifact = require("../../build/contracts/DharmaSmartWalletImplementationV6.json");
const DharmaSmartWalletImplementationV7Artifact = require("../../build/contracts/DharmaSmartWalletImplementationV7.json");
const DharmaKeyRingImplementationV1Artifact = require("../../build/contracts/DharmaKeyRingImplementationV1.json");
const contractNames = Object.assign({}, constants.CONTRACT_NAMES);
const ONE = web3.utils.toBN("1");
const ZERO = web3.utils.toBN("0");
async function test(testingContext) {
const tester = new Tester(testingContext);
await tester.init();
console.log("running tests...");
await tester.runTest(
`DharmaUpgradeBeaconController can transfer owner`,
tester.DharmaUpgradeBeaconController,
"transferOwnership",
"send",
[tester.address]
);
await tester.runTest(
"Dharma Key Registry V2 gets the initial global key correctly",
tester.DharmaKeyRegistryV2,
"getGlobalKey",
"call",
[],
true,
value => {
assert.strictEqual(value, tester.address);
}
);
const messageV2 =
tester.DharmaKeyRegistryV2.options.address +
tester.address.slice(2) +
web3.utils
.asciiToHex(
"This signature demonstrates that the supplied signing key is valid."
)
.slice(2);
const v2KeySignature = tester.signHashedPrefixedHashedHexString(
messageV2,
tester.address
);
await tester.runTest(
"Dharma Key Registry V2 cannot set a previously used global key",
tester.DharmaKeyRegistryV2,
"setGlobalKey",
"send",
[tester.address, v2KeySignature],
false
);
const BadBeacon = await tester.runTest(
`Mock Bad Beacon contract deployment`,
tester.BadBeaconDeployer,
"",
"deploy"
);
const BadBeaconTwo = await tester.runTest(
`Mock Bad Beacon Two contract deployment`,
tester.BadBeaconTwoDeployer,
"",
"deploy"
);
const DharmaSmartWalletImplementationV6 = await tester.runTest(
`DharmaSmartWalletImplementationV6 contract deployment`,
tester.DharmaSmartWalletImplementationV6Deployer,
"",
"deploy"
);
const DharmaSmartWalletImplementationV7 = await tester.runTest(
`DharmaSmartWalletImplementationV7 contract deployment`,
tester.DharmaSmartWalletImplementationV7Deployer,
"",
"deploy"
);
const DharmaKeyRingImplementationV1 = await tester.runTest(
`DharmaKeyRingImplementationV1 contract deployment`,
tester.DharmaKeyRingImplementationV1Deployer,
"",
"deploy"
);
await tester.runTest(
"Dharma Upgrade Beacon Controller cannot set null address as implementation",
tester.DharmaUpgradeBeaconController,
"upgrade",
"send",
[tester.DharmaUpgradeBeacon.options.address, constants.NULL_ADDRESS],
false
);
await tester.runTest(
"Dharma Upgrade Beacon Controller cannot set non-contract as implementation",
tester.DharmaUpgradeBeaconController,
"upgrade",
"send",
[tester.DharmaUpgradeBeacon.options.address, tester.address],
false
);
await tester.runTest(
'Dharma Upgrade Beacon Controller cannot support a "bad" beacon that throws',
tester.DharmaUpgradeBeaconController,
"upgrade",
"send",
[
BadBeacon.options.address,
DharmaSmartWalletImplementationV6.options.address
],
false
);
await tester.runTest(
"Dharma Upgrade Beacon Controller cannot upgrade a non-upgradeable beacon",
tester.DharmaUpgradeBeaconController,
"upgrade",
"send",
[
BadBeaconTwo.options.address,
DharmaSmartWalletImplementationV6.options.address
],
false
);
await tester.runTest(
"Dharma Upgrade Beacon Controller is inaccessible from a non-owner",
tester.DharmaUpgradeBeaconController,
"upgrade",
"send",
[
tester.DharmaUpgradeBeacon.options.address,
DharmaSmartWalletImplementationV6.options.address
],
false,
receipt => {},
tester.originalAddress
);
await tester.runTest(
"Dharma Upgrade Beacon Controller can set initial upgrade beacon implementation",
tester.DharmaUpgradeBeaconController,
"upgrade",
"send",
[
tester.DharmaUpgradeBeacon.options.address,
DharmaSmartWalletImplementationV6.options.address
],
true,
receipt => {
if (testingContext !== "coverage") {
assert.strictEqual(
receipt.events.Upgraded.returnValues.upgradeBeacon,
tester.DharmaUpgradeBeacon.options.address
);
assert.strictEqual(
receipt.events.Upgraded.returnValues.oldImplementation,
constants.NULL_ADDRESS
);
assert.strictEqual(
receipt.events.Upgraded.returnValues
.oldImplementationCodeHash,
constants.EMPTY_HASH
);
assert.strictEqual(
receipt.events.Upgraded.returnValues.newImplementation,
DharmaSmartWalletImplementationV6.options.address
);
/* TODO
assert.strictEqual(
receipt.events.Upgraded.returnValues.newImplementationCodeHash,
...
)
*/
}
}
);
await tester.runTest(
"Dharma Upgrade Beacon Controller cannot clear upgrade beacon implementation",
tester.DharmaUpgradeBeaconController,
"upgrade",
"send",
[tester.DharmaUpgradeBeacon.options.address, constants.NULL_ADDRESS],
false
);
await tester.runTest(
"Dharma Upgrade Beacon Controller can reset upgrade beacon implementation",
tester.DharmaUpgradeBeaconController,
"upgrade",
"send",
[
tester.DharmaUpgradeBeacon.options.address,
DharmaSmartWalletImplementationV6.options.address
],
true,
receipt => {
if (testingContext !== "coverage") {
assert.strictEqual(
receipt.events.Upgraded.returnValues.upgradeBeacon,
tester.DharmaUpgradeBeacon.options.address
);
assert.strictEqual(
receipt.events.Upgraded.returnValues.oldImplementation,
DharmaSmartWalletImplementationV6.options.address
);
/* TODO
assert.strictEqual(
receipt.events.Upgraded.returnValues.oldImplementationCodeHash,
constants.EMPTY_HASH
)
*/
assert.strictEqual(
receipt.events.Upgraded.returnValues.newImplementation,
DharmaSmartWalletImplementationV6.options.address
);
/* TODO
assert.strictEqual(
receipt.events.Upgraded.returnValues.newImplementationCodeHash,
...
)
*/
}
}
);
const UpgradeBeaconImplementationCheck = await tester.runTest(
`UpgradeBeaconImplementationCheck deployment`,
tester.UpgradeBeaconImplementationCheckDeployer,
"",
"deploy",
[
tester.DharmaUpgradeBeacon.options.address,
DharmaSmartWalletImplementationV6.options.address
]
);
await tester.runTest(
"DharmaUpgradeBeacon has the implementation set",
tester.DharmaUpgradeBeaconController,
"getImplementation",
"call",
[tester.DharmaUpgradeBeacon.options.address],
true,
value => {
assert.strictEqual(
value,
DharmaSmartWalletImplementationV6.options.address
);
}
);
await tester.runTest(
"Dharma Key Ring Upgrade Beacon Controller can set initial key ring upgrade beacon implementation",
tester.DharmaKeyRingUpgradeBeaconController,
"upgrade",
"send",
[
tester.DharmaKeyRingUpgradeBeacon.options.address,
DharmaKeyRingImplementationV1.options.address
],
true,
receipt => {
if (testingContext !== "coverage") {
assert.strictEqual(
receipt.events.Upgraded.returnValues.upgradeBeacon,
tester.DharmaKeyRingUpgradeBeacon.options.address
);
assert.strictEqual(
receipt.events.Upgraded.returnValues.oldImplementation,
constants.NULL_ADDRESS
);
assert.strictEqual(
receipt.events.Upgraded.returnValues
.oldImplementationCodeHash,
constants.EMPTY_HASH
);
assert.strictEqual(
receipt.events.Upgraded.returnValues.newImplementation,
DharmaKeyRingImplementationV1.options.address
);
/* TODO
assert.strictEqual(
receipt.events.Upgraded.returnValues.newImplementationCodeHash,
...
)
*/
}
}
);
const KeyRingUpgradeBeaconImplementationCheck = await tester.runTest(
`KeyRingUpgradeBeaconImplementationCheck deployment`,
tester.UpgradeBeaconImplementationCheckDeployer,
"",
"deploy",
[
tester.DharmaKeyRingUpgradeBeacon.options.address,
DharmaKeyRingImplementationV1.options.address
]
);
await tester.runTest(
"DharmaKeyRingUpgradeBeacon has the implementation set",
tester.DharmaKeyRingUpgradeBeaconController,
"getImplementation",
"call",
[tester.DharmaKeyRingUpgradeBeacon.options.address],
true,
value => {
assert.strictEqual(
value,
DharmaKeyRingImplementationV1.options.address
);
}
);
const DharmaSmartWalletNoFactoryNoConstructorDeployer = new web3.eth.Contract(
[]
);
DharmaSmartWalletNoFactoryNoConstructorDeployer.options.data =
"0x600b5981380380925939f359595959365960205959596e" +
tester.DharmaUpgradeBeacon.options.address.slice(12).toLowerCase() +
"5afa1551368280375af43d3d93803e602e57fd5bf3";
const DharmaSmartWalletNoFactoryNoConstructor = await tester.runTest(
`DharmaSmartWallet minimal upgradeable proxy deployment - no factory or constructor`,
DharmaSmartWalletNoFactoryNoConstructorDeployer,
"",
"deploy"
);
const DharmaSmartWalletImplementationTest = new web3.eth.Contract(
DharmaSmartWalletImplementationV6Artifact.abi,
DharmaSmartWalletNoFactoryNoConstructor.options.address
);
await tester.runTest(
"test passes",
DharmaSmartWalletImplementationTest,
"getVersion",
"call",
[],
true,
value => {
assert.ok(value.length > 0);
}
);
let currentSaiCode;
await tester.runTest(
"Checking for required external contracts...",
tester.MockCodeCheck,
"code",
"call",
[constants.SAI_MAINNET_ADDRESS],
true,
value => {
currentSaiCode = value;
}
);
if (!currentSaiCode) {
console.log(
`completed ${tester.passed + tester.failed} test${
tester.passed + tester.failed === 1 ? "" : "s"
} ` +
`with ${tester.failed} failure${
tester.failed === 1 ? "" : "s"
}.`
);
console.log(
"Note that the full test suite cannot be executed locally - instead, " +
"run against a fork of mainnet using `yarn forkStart` and `yarn test`."
);
if (tester.failed > 0) {
process.exit(1);
}
// exit.
return 0;
}
const DharmaSmartWalletNoFactoryDeployer = new web3.eth.Contract([]);
DharmaSmartWalletNoFactoryDeployer.options.data =
"0x595959596076380359602059595973" +
tester.DharmaUpgradeBeacon.options.address.slice(2).toLowerCase() +
"5afa155182607683395af46038573d903d81803efd5b60356041819339f3595959593659602059595973" +
tester.DharmaUpgradeBeacon.options.address.slice(2).toLowerCase() +
"5afa1551368280375af43d3d93803e603357fd5bf3" +
"c4d66de80000000000000000000000009999999999999999999999999999999999999999";
const DharmaSmartWalletNoFactory = await tester.runTest(
`DharmaSmartWallet minimal upgradeable proxy deployment - no factory but with constructor`,
DharmaSmartWalletNoFactoryDeployer,
"",
"deploy"
);
const DharmaSmartWalletImplementationTestWithConstructor = new web3.eth.Contract(
DharmaSmartWalletImplementationV6Artifact.abi,
DharmaSmartWalletNoFactory.options.address
);
await tester.runTest(
"test passes",
DharmaSmartWalletImplementationTestWithConstructor,
"getVersion",
"call",
[],
true,
value => {
assert.ok(value.length > 0);
}
);
await tester.runTest(
"new user smart wallet can be called and has the correct dharma key set",
DharmaSmartWalletImplementationTestWithConstructor,
"getUserSigningKey",
"call",
[],
true,
value => {
assert.strictEqual(
value,
"0x9999999999999999999999999999999999999999"
);
}
);
const DharmaSmartWalletFactoryV1 = await tester.runTest(
`DharmaSmartWalletFactoryV1 contract deployment`,
tester.DharmaSmartWalletFactoryV1Deployer,
"",
"deploy",
[]
);
let targetWalletAddress;
await tester.runTest(
"DharmaSmartWalletFactoryV1 can get a new smart wallet address ahead of time",
DharmaSmartWalletFactoryV1,
"getNextSmartWallet",
"call",
[tester.address],
true,
value => {
// TODO: verify against expected value
targetWalletAddress = value;
}
);
const UserSmartWalletV6 = new web3.eth.Contract(
DharmaSmartWalletImplementationV6Artifact.abi,
targetWalletAddress
);
const UserSmartWalletV7 = new web3.eth.Contract(
DharmaSmartWalletImplementationV7Artifact.abi,
targetWalletAddress
);
await testPerformingUpgrade(
tester,
DharmaSmartWalletImplementationV6, // new implementation
UserSmartWalletV6,
tester.DharmaUpgradeBeaconController,
tester.DharmaUpgradeBeacon.options.address,
6,
true
);
contractNames[DharmaSmartWalletFactoryV1.options.address] =
"Smart Wallet Factory";
contractNames[targetWalletAddress] = "Smart Wallet";
const ethWhaleBalance = await web3.eth.getBalance(
constants.ETH_WHALE_ADDRESS
);
const saiWhaleBalance = await web3.eth.getBalance(
constants.SAI_WHALE_ADDRESS
);
const daiWhaleBalance = await web3.eth.getBalance(
constants.DAI_WHALE_ADDRESS
);
const usdcWhaleBalance = await web3.eth.getBalance(
constants.USDC_WHALE_ADDRESS
);
if (ethWhaleBalance === "0") {
await web3.eth.sendTransaction({
from: tester.address,
to: constants.ETH_WHALE_ADDRESS,
value: web3.utils.toWei(".2", "ether"),
gas: testingContext !== "coverage" ? "0x5208" : tester.gasLimit - 1,
gasPrice: 1
});
console.log(" ✓ Eth Whale can receive eth if needed");
}
if (saiWhaleBalance === "0") {
await web3.eth.sendTransaction({
from: tester.address,
to: constants.SAI_WHALE_ADDRESS,
value: web3.utils.toWei(".1", "ether"),
gas: testingContext !== "coverage" ? "0x5208" : tester.gasLimit - 1,
gasPrice: 1
});
console.log(" ✓ Sai Whale can receive eth if needed");
}
if (daiWhaleBalance === "0") {
await web3.eth.sendTransaction({
from: tester.address,
to: constants.DAI_WHALE_ADDRESS,
value: web3.utils.toWei(".1", "ether"),
gas: testingContext !== "coverage" ? "0x5208" : tester.gasLimit - 1,
gasPrice: 1
});
console.log(" ✓ Dai Whale can receive eth if needed");
}
if (usdcWhaleBalance === "0") {
await web3.eth.sendTransaction({
from: tester.address,
to: constants.USDC_WHALE_ADDRESS,
value: web3.utils.toWei(".1", "ether"),
gas: testingContext !== "coverage" ? "0x5208" : tester.gasLimit - 1,
gasPrice: 1
});
console.log(" ✓ USDC Whale can receive eth if needed");
}
await web3.eth.sendTransaction({
from: constants.ETH_WHALE_ADDRESS,
to: targetWalletAddress,
value: web3.utils.toWei(".1", "ether"),
gas: testingContext !== "coverage" ? "0x5208" : tester.gasLimit - 1,
gasPrice: 1
});
console.log(
" ✓ Eth Whale can deposit eth into the yet-to-be-deployed smart wallet"
);
await tester.runTest(
"Dai Whale can deposit dai into the yet-to-be-deployed smart wallet",
tester.DAI,
"transfer",
"send",
[targetWalletAddress, web3.utils.toWei("100", "ether")],
true,
receipt => {
if (testingContext !== "coverage") {
assert.strictEqual(
receipt.events.Transfer.returnValues.from,
constants.DAI_WHALE_ADDRESS
);
assert.strictEqual(
receipt.events.Transfer.returnValues.to,
targetWalletAddress
);
assert.strictEqual(
receipt.events.Transfer.returnValues.value,
web3.utils.toWei("100", "ether")
);
}
},
constants.DAI_WHALE_ADDRESS
);
await tester.runTest(
"USDC Whale can deposit usdc into the yet-to-be-deployed smart wallet",
tester.USDC,
"transfer",
"send",
[targetWalletAddress, web3.utils.toWei("100", "lovelace")], // six decimals
true,
receipt => {
if (testingContext !== "coverage") {
assert.strictEqual(
receipt.events.Transfer.returnValues.from,
constants.USDC_WHALE_ADDRESS
);
assert.strictEqual(
receipt.events.Transfer.returnValues.to,
targetWalletAddress
);
assert.strictEqual(
receipt.events.Transfer.returnValues.value,
web3.utils.toWei("100", "lovelace")
);
}
},
constants.USDC_WHALE_ADDRESS
);
await tester.runTest(
"DharmaSmartWalletFactoryV1 cannot deploy a new smart wallet with no key",
DharmaSmartWalletFactoryV1,
"newSmartWallet",
"send",
[constants.NULL_ADDRESS],
false
);
await tester.runTest(
"DharmaSmartWalletFactoryV1 can deploy a new smart wallet using a Dharma Key",
DharmaSmartWalletFactoryV1,
"newSmartWallet",
"send",
[tester.address],
true,
receipt => {
//console.log(receipt.status, receipt.gasUsed)
if (testingContext !== "coverage") {
let events = [];
Object.values(receipt.events).forEach(value => {
const log = constants.EVENT_DETAILS[value.raw.topics[0]];
if (typeof log === "undefined") {
console.log(value);
}
const decoded = web3.eth.abi.decodeLog(
log.abi,
value.raw.data,
value.raw.topics
);
events.push({
address: contractNames[value.address],
eventName: log.name,
returnValues: decoded
});
});
assert.strictEqual(events[0].address, "Smart Wallet");
assert.strictEqual(events[0].eventName, "NewUserSigningKey");
assert.strictEqual(
events[0].returnValues.userSigningKey,
tester.address
);
assert.strictEqual(events[1].address, "DAI");
assert.strictEqual(events[1].eventName, "Approval");
assert.strictEqual(
events[1].returnValues.value,
constants.FULL_APPROVAL
);
assert.strictEqual(events[2].address, "CDAI");
assert.strictEqual(events[2].eventName, "AccrueInterest");
assert.strictEqual(events[3].address, "DAI");
assert.strictEqual(events[3].eventName, "Transfer");
assert.strictEqual(
events[3].returnValues.value,
web3.utils.toWei("100", "ether")
);
assert.strictEqual(events[4].address, "CDAI");
assert.strictEqual(events[4].eventName, "Mint");
assert.strictEqual(
events[4].returnValues.mintTokens,
web3.utils.toWei("100", "ether")
);
assert.strictEqual(events[5].address, "CDAI");
assert.strictEqual(events[5].eventName, "Transfer");
assert.strictEqual(events[6].address, "USDC");
assert.strictEqual(events[6].eventName, "Approval");
assert.strictEqual(
events[6].returnValues.value,
constants.FULL_APPROVAL
);
assert.strictEqual(events[7].address, "CUSDC");
assert.strictEqual(events[7].eventName, "AccrueInterest");
assert.strictEqual(events[8].address, "USDC");
assert.strictEqual(events[8].eventName, "Transfer");
assert.strictEqual(
events[8].returnValues.value,
web3.utils.toWei("100", "lovelace")
);
assert.strictEqual(events[9].address, "CUSDC");
assert.strictEqual(events[9].eventName, "Mint");
assert.strictEqual(
events[9].returnValues.mintTokens,
web3.utils.toWei("100", "lovelace")
);
assert.strictEqual(events[10].address, "CUSDC");
assert.strictEqual(events[10].eventName, "Transfer");
}
}
);
await tester.runTest(
"DharmaSmartWalletFactoryV1 gets a new smart wallet address with same key",
DharmaSmartWalletFactoryV1,
"getNextSmartWallet",
"call",
[tester.address],
true,
value => {
// TODO: verify against expected value
assert.ok(targetWalletAddress !== value);
}
);
let originalNonce = 0;
await tester.runTest(
"UserSmartWalletV6 nonce can be retrieved and starts at zero",
UserSmartWalletV6,
"getNonce",
"call",
[],
true,
value => {
assert.strictEqual(value, originalNonce.toString());
}
);
await tester.runTest(
"V6 UserSmartWallet can get balances",
UserSmartWalletV6,
"getBalances",
"call",
[],
true,
value => {
//console.log(value)
}
);
await tester.runTest(
"V6 UserSmartWallet secondary can call to cancel",
UserSmartWalletV6,
"cancel",
"send",
[0, "0x"]
);
await tester.runTest(
"V6 UserSmartWallet nonce is now set to original + 1",
UserSmartWalletV6,
"getNonce",
"call",
[],
true,
value => {
assert.strictEqual(value, (parseInt(originalNonce) + 1).toString());
}
);
await tester.runTest(
"V6 UserSmartWallet can get next custom action ID to set a user signing key",
UserSmartWalletV6,
"getNextCustomActionID",
"call",
[
1, // SetUserSigningKey,
constants.FULL_APPROVAL, // This value shouldn't matter
tester.addressTwo,
0
],
true,
value => {
customActionId = value;
}
);
setUserSigningKeyDharmaSignature = tester.signHashedPrefixedHexString(
customActionId,
tester.address
);
await tester.runTest(
"V6 UserSmartWallet can set a new user signing key with signatures",
UserSmartWalletV6,
"setUserSigningKey",
"send",
[tester.addressTwo, 0, "0x", setUserSigningKeyDharmaSignature]
);
await tester.runTest(
"V6 UserSmartWallet has the new user signing key set",
UserSmartWalletV6,
"getUserSigningKey",
"call",
[],
true,
value => {
assert.strictEqual(value, tester.addressTwo);
}
);
await tester.runTest(
"cSai can be sent to V6 UserSmartWallet",
tester.CSAI,
"transfer",
"send",
[UserSmartWalletV6.options.address, web3.utils.toWei("0.5", "mwei")]
);
await tester.runTest(
"V6 UserSmartWallet can get next custom action ID",
UserSmartWalletV6,
"getNextCustomActionID",
"call",
[
0, // DAIWithdrawal
constants.FULL_APPROVAL,
tester.address,
0
],
true,
value => {
customActionId = value;
}
);
await tester.runTest(
"V6 UserSmartWallet can get custom action ID and it matches next action ID",
UserSmartWalletV6,
"getCustomActionID",
"call",
[
0, // DAIWithdrawal
constants.FULL_APPROVAL,
tester.address,
parseInt(originalNonce) + 2,
0
],
true,
value => {
assert.strictEqual(value, customActionId);
}
);
await tester.runTest(
"V6 UserSmartWallet can get next generic action ID",
UserSmartWalletV6,
"getNextGenericActionID",
"call",
[tester.address, "0x", 0],
true,
value => {
genericActionID = value;
}
);
await tester.runTest(
"V6 UserSmartWallet can get generic action ID and it matches next action ID",
UserSmartWalletV6,
"getGenericActionID",
"call",
[tester.address, "0x", parseInt(originalNonce) + 2, 0],
true,
value => {
assert.strictEqual(value, genericActionID);
}
);
await tester.runTest(
"UserSmartWallet calls to atomic methods revert",
UserSmartWalletV6,
"_withdrawDaiAtomic",
"send",
["1", tester.address],
false
);
// Give the Dai Whale some ETH so it can make transactions
await web3.eth.sendTransaction({
from: tester.address,
to: constants.DAI_WHALE_ADDRESS,
value: web3.utils.toWei("1", "ether"),
gas: testingContext !== "coverage" ? "0xffff" : tester.gasLimit - 1,
gasPrice: 1
});
await tester.runTest(
"Dai Whale can deposit Dai into the V6 smart wallet",
tester.DAI,
"transfer",
"send",
[targetWalletAddress, web3.utils.toWei("100", "ether")],
true,
receipt => {
if (testingContext !== "coverage") {
assert.strictEqual(
receipt.events.Transfer.returnValues.from,
constants.DAI_WHALE_ADDRESS
);
assert.strictEqual(
receipt.events.Transfer.returnValues.to,
targetWalletAddress
);
assert.strictEqual(
receipt.events.Transfer.returnValues.value,
web3.utils.toWei("100", "ether")
);
}
},
constants.DAI_WHALE_ADDRESS
);
await tester.runTest(
"USDC Whale can deposit usdc into the V6 smart wallet",
tester.USDC,
"transfer",
"send",
[targetWalletAddress, web3.utils.toWei("100", "lovelace")], // six decimals
true,
receipt => {
if (testingContext !== "coverage") {
assert.strictEqual(
receipt.events.Transfer.returnValues.from,
constants.USDC_WHALE_ADDRESS
);
assert.strictEqual(
receipt.events.Transfer.returnValues.to,
targetWalletAddress
);
assert.strictEqual(
receipt.events.Transfer.returnValues.value,
web3.utils.toWei("100", "lovelace")
);
}
},
constants.USDC_WHALE_ADDRESS
);
await tester.runTest(
"V6 UserSmartWallet can get a generic action ID",
UserSmartWalletV6,
"getNextGenericActionID",
"call",
[
tester.DAI.options.address,
tester.DAI.methods
.approve(tester.CDAI.options.address, 0)
.encodeABI(),
0
],
true,
value => {
customActionId = value;
}
);
executeActionSignature = tester.signHashedPrefixedHexString(
customActionId,
tester.address
);
executeActionUserSignature = tester.signHashedPrefixedHexString(
customActionId,