-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathProtocolFactory.t.sol
More file actions
2418 lines (2155 loc) · 102 KB
/
ProtocolFactory.t.sol
File metadata and controls
2418 lines (2155 loc) · 102 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
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.23;
import {Test, console} from "forge-std/Test.sol";
import {AragonTest} from "./helpers/AragonTest.sol";
import {ProtocolFactoryBuilder} from "./helpers/ProtocolFactoryBuilder.sol";
import {ProtocolFactory} from "../src/ProtocolFactory.sol";
import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import {DummySetup} from "./helpers/DummySetup.sol";
// OSx Imports
import {IDAO} from "@aragon/osx-commons-contracts/src/dao/IDAO.sol";
import {DAO, Action} from "@aragon/osx/core/dao/DAO.sol";
import {PermissionLib} from "@aragon/osx-commons-contracts/src/permission/PermissionLib.sol";
import {PermissionManager} from "@aragon/osx/core/permission/PermissionManager.sol";
import {DAOFactory} from "@aragon/osx/framework/dao/DAOFactory.sol";
import {DAORegistry} from "@aragon/osx/framework/dao/DAORegistry.sol";
import {PluginRepoFactory} from "@aragon/osx/framework/plugin/repo/PluginRepoFactory.sol";
import {PluginRepoRegistry} from "@aragon/osx/framework/plugin/repo/PluginRepoRegistry.sol";
import {PluginRepo} from "@aragon/osx/framework/plugin/repo/PluginRepo.sol";
import {
PluginSetupProcessor,
PluginSetupRef,
hashHelpers
} from "@aragon/osx/framework/plugin/setup/PluginSetupProcessor.sol";
import {IPluginSetup} from "@aragon/osx-commons-contracts/src/plugin/setup/IPluginSetup.sol";
import {IPlugin} from "@aragon/osx-commons-contracts/src/plugin/IPlugin.sol";
import {ENSSubdomainRegistrar} from "@aragon/osx/framework/utils/ens/ENSSubdomainRegistrar.sol";
// ENS Imports
import {ENS} from "@ensdomains/ens-contracts/contracts/registry/ENS.sol";
import {PublicResolver} from "@ensdomains/ens-contracts/contracts/resolvers/PublicResolver.sol";
import {ENSHelper} from "../src/helpers/ENSHelper.sol";
// Plugins
import {Admin} from "@aragon/admin-plugin/Admin.sol";
import {Multisig} from "@aragon/multisig-plugin/Multisig.sol";
import {TokenVoting} from "@aragon/token-voting-plugin/TokenVoting.sol";
import {MajorityVotingBase} from "@aragon/token-voting-plugin/base/MajorityVotingBase.sol";
import {IMajorityVoting} from "@aragon/token-voting-plugin/base/IMajorityVoting.sol";
import {StagedProposalProcessor} from "@aragon/staged-proposal-processor-plugin/StagedProposalProcessor.sol";
import {RuledCondition} from "@aragon/osx-commons-contracts/src/permission/condition/extensions/RuledCondition.sol";
import {AdminSetup} from "@aragon/admin-plugin/AdminSetup.sol";
import {MultisigSetup} from "@aragon/multisig-plugin/MultisigSetup.sol";
import {TokenVotingSetup} from "@aragon/token-voting-plugin/TokenVotingSetup.sol";
import {StagedProposalProcessorSetup} from "@aragon/staged-proposal-processor-plugin/StagedProposalProcessorSetup.sol";
import {GovernanceERC20} from "@aragon/token-voting-plugin/erc20/GovernanceERC20.sol";
import {GovernanceWrappedERC20} from "@aragon/token-voting-plugin/erc20/GovernanceWrappedERC20.sol";
import {IERC20Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol";
contract ProtocolFactoryTest is AragonTest {
ProtocolFactoryBuilder builder;
ProtocolFactory factory;
ProtocolFactory.DeploymentParameters deploymentParams;
ProtocolFactory.Deployment deployment;
address[] internal mgmtDaoMembers;
// Namehashes calculated in setUp for reuse
bytes32 ethNode;
bytes32 daoRootNode; // e.g., dao-test.eth
bytes32 pluginRootNode; // e.g., plugin-test.dao-test.eth
bytes32 managementDaoNode; // e.g., management-test.dao-test.eth
function setUp() public {
builder = new ProtocolFactoryBuilder();
// Configure some basic params for testing
mgmtDaoMembers = new address[](3);
mgmtDaoMembers[0] = alice;
mgmtDaoMembers[1] = bob;
mgmtDaoMembers[2] = carol;
builder.withManagementDaoMembers(mgmtDaoMembers).withManagementDaoMinApprovals(2);
// Build the factory (deploys factory contract but doesn't call deployPhase yet)
factory = builder.build();
deploymentParams = builder.getDeploymentParams();
// Pre-calculate namehashes based on params
ethNode = vm.ensNamehash("eth");
daoRootNode = vm.ensNamehash(string.concat(deploymentParams.ensParameters.daoRootDomain, ".eth"));
pluginRootNode = vm.ensNamehash(
string.concat(
deploymentParams.ensParameters.pluginSubdomain,
".",
deploymentParams.ensParameters.daoRootDomain,
".eth"
)
);
managementDaoNode = vm.ensNamehash(
string.concat(
deploymentParams.ensParameters.managementDaoSubdomain,
".",
deploymentParams.ensParameters.daoRootDomain,
".eth"
)
);
vm.label(address(this), "TestRunner");
// To avoid issues with clock modes (e.g., block.timestamp == block.number)
vm.warp(block.timestamp + 1 days);
}
function test_WhenDeployingTheProtocolFactory() external {
// It getParameters should return the exact same parameters as provided to the constructor
ProtocolFactory.DeploymentParameters memory currentParams = factory.getParameters();
// Deep comparison
assertEq(keccak256(abi.encode(currentParams)), keccak256(abi.encode(deploymentParams)));
// It getDeployment should return empty values (zero addresses)
deployment = factory.getDeployment();
assertEq(deployment.daoFactory, address(0));
assertEq(deployment.pluginRepoFactory, address(0));
assertEq(deployment.pluginSetupProcessor, address(0));
assertEq(deployment.globalExecutor, address(0));
assertEq(deployment.placeholderSetup, address(0));
assertEq(deployment.daoRegistry, address(0));
assertEq(deployment.pluginRepoRegistry, address(0));
assertEq(deployment.managementDao, address(0));
assertEq(deployment.managementDaoMultisig, address(0));
assertEq(deployment.ensRegistry, address(0));
assertEq(deployment.daoSubdomainRegistrar, address(0));
assertEq(deployment.pluginSubdomainRegistrar, address(0));
assertEq(deployment.publicResolver, address(0));
assertEq(deployment.adminPluginRepo, address(0));
assertEq(deployment.multisigPluginRepo, address(0));
assertEq(deployment.tokenVotingPluginRepo, address(0));
assertEq(deployment.stagedProposalProcessorPluginRepo, address(0));
}
modifier whenInvokingDeployOnce() {
_;
}
function test_GivenNoPriorDeploymentOnTheFactory() external whenInvokingDeployOnce {
// It Should emit an event with the factory address on final phase
factory.deployPhase(); // Phase 1
factory.deployPhase(); // Phase 2
vm.expectEmit(true, true, true, true);
emit ProtocolFactory.ProtocolDeployed(factory);
factory.deployPhase(); // Phase 3
// It The deployment addresses are filled with the new contracts
deployment = factory.getDeployment();
assertNotEq(deployment.daoFactory, address(0));
assertNotEq(deployment.pluginRepoFactory, address(0));
assertNotEq(deployment.pluginSetupProcessor, address(0));
assertNotEq(deployment.globalExecutor, address(0)); // Should be the base address provided
assertNotEq(deployment.placeholderSetup, address(0)); // Should be the base address provided
assertNotEq(deployment.daoRegistry, address(0));
assertNotEq(deployment.pluginRepoRegistry, address(0));
assertNotEq(deployment.managementDao, address(0));
assertNotEq(deployment.managementDaoMultisig, address(0));
assertNotEq(deployment.ensRegistry, address(0));
assertNotEq(deployment.daoSubdomainRegistrar, address(0));
assertNotEq(deployment.pluginSubdomainRegistrar, address(0));
assertNotEq(deployment.publicResolver, address(0));
assertNotEq(deployment.adminPluginRepo, address(0));
assertNotEq(deployment.multisigPluginRepo, address(0));
assertNotEq(deployment.tokenVotingPluginRepo, address(0));
assertNotEq(deployment.stagedProposalProcessorPluginRepo, address(0));
// Check a few key implementations match the params
assertEq(deployment.globalExecutor, deploymentParams.osxImplementations.globalExecutor);
assertEq(deployment.placeholderSetup, deploymentParams.osxImplementations.placeholderSetup);
// It Parameters should remain immutable after deployment
ProtocolFactory.DeploymentParameters memory currentParams = factory.getParameters();
assertEq(keccak256(abi.encode(currentParams)), keccak256(abi.encode(deploymentParams)));
// It The used ENS setup matches the given parameters
ENS ens = ENS(deployment.ensRegistry);
ENSSubdomainRegistrar daoRegistrar = ENSSubdomainRegistrar(deployment.daoSubdomainRegistrar);
ENSSubdomainRegistrar pluginRegistrar = ENSSubdomainRegistrar(deployment.pluginSubdomainRegistrar);
IResolver resolver = IResolver(deployment.publicResolver); // Assuming PublicResolver implements this basic func
// Owner of the registry contract itself is the Management DAO
assertEq(ens.owner(bytes32(0)), deployment.managementDao, "Registry root owner mismatch");
// 2. Check Root Domain Ownership
assertEq(ens.owner(daoRootNode), deployment.managementDao, "DAO root domain owner mismatch");
assertEq(ens.owner(pluginRootNode), deployment.managementDao, "Plugin root domain owner mismatch");
// 3. Check DAO Registrar State
assertEq(address(daoRegistrar.dao()), deployment.managementDao, "DAO Registrar: DAO mismatch");
assertEq(address(daoRegistrar.ens()), deployment.ensRegistry, "DAO Registrar: ENS mismatch");
assertEq(daoRegistrar.node(), daoRootNode, "DAO Registrar: Root node mismatch");
// 4. Check Plugin Registrar State
assertEq(address(pluginRegistrar.dao()), deployment.managementDao, "Plugin Registrar: DAO mismatch");
assertEq(address(pluginRegistrar.ens()), deployment.ensRegistry, "Plugin Registrar: ENS mismatch");
assertEq(pluginRegistrar.node(), pluginRootNode, "Plugin Registrar: Root node mismatch");
// 5. Check Management DAO ENS Resolution
assertEq(
ens.owner(managementDaoNode), deployment.daoSubdomainRegistrar, "Management DAO ENS node owner mismatch"
);
assertEq(
ens.resolver(managementDaoNode), deployment.publicResolver, "Management DAO ENS node resolver mismatch"
);
// Check resolution via the resolver itself
assertEq(
resolver.addr(managementDaoNode), deployment.managementDao, "Management DAO ENS resolver addr() mismatch"
);
// 6. Check Operator Approvals on ENS Registry granted by Management DAO
// The factory executes actions via the Mgmt DAO to grant these during setup.
assertTrue(
ens.isApprovedForAll(deployment.managementDao, deployment.daoSubdomainRegistrar),
"DAO Registrar not approved operator"
);
assertTrue(
ens.isApprovedForAll(deployment.managementDao, deployment.pluginSubdomainRegistrar),
"Plugin Registrar not approved operator"
);
// Check DAORegistry/PluginRepoRegistry permissions elsewhere if needed
// 7. Check Implementation Address (optional sanity check)
address daoRegImpl = _getImplementation(deployment.daoSubdomainRegistrar);
assertEq(
daoRegImpl, deploymentParams.osxImplementations.ensSubdomainRegistrarBase, "DAO Registrar Impl mismatch"
);
address pluginRegImpl = _getImplementation(deployment.pluginSubdomainRegistrar);
assertEq(
pluginRegImpl,
deploymentParams.osxImplementations.ensSubdomainRegistrarBase,
"Plugin Registrar Impl mismatch"
);
}
function test_GivenTheFactoryAlreadyMadeADeployment_CallingDeployPhaseIsNoop() external whenInvokingDeployOnce {
// Do a first deployment
ProtocolFactory.DeploymentParameters memory params0 = factory.getParameters();
while (!factory.deployPhase()) {}
ProtocolFactory.DeploymentParameters memory params1 = factory.getParameters();
ProtocolFactory.Deployment memory deployment1 = factory.getDeployment();
// Calling deployPhase after completion should be a no-op (not revert)
factory.deployPhase();
// It Parameters should remain unchanged
ProtocolFactory.DeploymentParameters memory params2 = factory.getParameters();
assertEq(keccak256(abi.encode(params0)), keccak256(abi.encode(params1)));
assertEq(keccak256(abi.encode(params1)), keccak256(abi.encode(params2)));
// It Deployment addresses should remain unchanged
ProtocolFactory.Deployment memory deployment2 = factory.getDeployment();
assertEq(keccak256(abi.encode(deployment1)), keccak256(abi.encode(deployment2)));
// Phase should still be Complete
assertEq(uint256(factory.currentPhase()), uint256(ProtocolFactory.DeploymentPhase.Complete));
}
function test_RevertGiven_TheManagementDAOMinApprovalsIsTooSmall() external whenInvokingDeployOnce {
// It Should revert
builder = new ProtocolFactoryBuilder();
// One member, two approvals
mgmtDaoMembers = new address[](1);
mgmtDaoMembers[0] = alice;
builder.withManagementDaoMembers(mgmtDaoMembers).withManagementDaoMinApprovals(2);
factory = builder.build();
// Phase 1 and 2 succeed
factory.deployPhase();
factory.deployPhase();
// Fail on phase 3 (when concludeManagementDao is called)
vm.expectRevert(ProtocolFactory.MemberListIsTooSmall.selector);
factory.deployPhase();
// OK with valid config
mgmtDaoMembers = new address[](2);
mgmtDaoMembers[0] = alice;
mgmtDaoMembers[1] = bob;
builder.withManagementDaoMembers(mgmtDaoMembers).withManagementDaoMinApprovals(2);
factory = builder.build();
}
// PHASED DEPLOYMENT TESTS
modifier whenInvokingPhasedDeployment() {
_;
}
function test_PhasedDeploymentCompletesSuccessfully() external whenInvokingPhasedDeployment {
// Verify initial phase
assertEq(uint256(factory.currentPhase()), uint256(ProtocolFactory.DeploymentPhase.NotStarted));
// Deploy phase 1
factory.deployPhase();
assertEq(uint256(factory.currentPhase()), uint256(ProtocolFactory.DeploymentPhase.Phase1Complete));
// Deploy phase 2
factory.deployPhase();
assertEq(uint256(factory.currentPhase()), uint256(ProtocolFactory.DeploymentPhase.Phase2Complete));
// Deploy phase 3 - expect event
vm.expectEmit(true, true, true, true);
emit ProtocolFactory.ProtocolDeployed(factory);
factory.deployPhase();
assertEq(uint256(factory.currentPhase()), uint256(ProtocolFactory.DeploymentPhase.Complete));
// Verify deployment completed
deployment = factory.getDeployment();
assertNotEq(deployment.daoFactory, address(0));
assertNotEq(deployment.managementDao, address(0));
assertNotEq(deployment.pluginRepoRegistry, address(0));
}
function test_DeployPhaseIsNoopAfterCompletion() external whenInvokingPhasedDeployment {
// Complete all phases
while (!factory.deployPhase()) {}
ProtocolFactory.Deployment memory deployment1 = factory.getDeployment();
// Calling deployPhase after completion should be a no-op
factory.deployPhase();
// Phase should still be Complete
assertEq(uint256(factory.currentPhase()), uint256(ProtocolFactory.DeploymentPhase.Complete));
// Deployment should be unchanged
ProtocolFactory.Deployment memory deployment2 = factory.getDeployment();
assertEq(keccak256(abi.encode(deployment1)), keccak256(abi.encode(deployment2)));
}
modifier givenAProtocolDeployment() {
// Use phased deployment to stay within EIP-7825 gas limits
while (!factory.deployPhase()) {}
deployment = factory.getDeployment();
deploymentParams = builder.getDeploymentParams();
// Ensure deployment actually happened for modifier sanity
assertNotEq(deployment.daoFactory, address(0));
_;
}
function test_WhenCallingGetParameters() external givenAProtocolDeployment {
// It Should return the given values
// 1
factory = builder.build();
bytes32 hash1 = keccak256(abi.encode(factory.getParameters()));
factory = builder.build();
bytes32 hash2 = keccak256(abi.encode(factory.getParameters()));
assertEq(hash1, hash2, "Equal input params should produce equal output values");
// 2
factory = builder.withDaoRootDomain("dao-1").build();
hash2 = keccak256(abi.encode(factory.getParameters()));
assertNotEq(hash1, hash2, "Different input params should produce different values");
assertEq(factory.getParameters().ensParameters.daoRootDomain, "dao-1", "DAO root domain mismatch");
hash1 = hash2;
// 3
factory = builder.withManagementDaoSubdomain("management-1").build();
hash2 = keccak256(abi.encode(factory.getParameters()));
assertNotEq(hash1, hash2, "Different input params should produce different values");
assertEq(
factory.getParameters().ensParameters.managementDaoSubdomain,
"management-1",
"Management DAO subdomain mismatch"
);
hash1 = hash2;
// 4
factory = builder.withPluginSubdomain("plugin-1").build();
hash2 = keccak256(abi.encode(factory.getParameters()));
assertNotEq(hash1, hash2, "Different input params should produce different values");
assertEq(factory.getParameters().ensParameters.pluginSubdomain, "plugin-1", "Plugin subdomain mismatch");
hash1 = hash2;
// 5
factory = builder.withAdminPlugin(1, 5, "releaseMeta", "buildMeta", "admin-1").build();
hash2 = keccak256(abi.encode(factory.getParameters()));
assertNotEq(hash1, hash2, "Different input params should produce different values");
assertEq(factory.getParameters().corePlugins.adminPlugin.release, 1, "Admin plugin release mismatch");
assertEq(factory.getParameters().corePlugins.adminPlugin.build, 5, "Admin plugin build mismatch");
assertEq(
factory.getParameters().corePlugins.adminPlugin.releaseMetadataUri,
"releaseMeta",
"Admin plugin releaseMetadataUri mismatch"
);
assertEq(
factory.getParameters().corePlugins.adminPlugin.buildMetadataUri,
"buildMeta",
"Admin plugin buildMetadataUri mismatch"
);
assertEq(
factory.getParameters().corePlugins.adminPlugin.subdomain, "admin-1", "Admin plugin subdomain mismatch"
);
hash1 = hash2;
// 6
factory = builder.withAdminPlugin(2, 10, "releaseMeta-2", "buildMeta-2", "admin-2").build();
hash2 = keccak256(abi.encode(factory.getParameters()));
assertNotEq(hash1, hash2, "Different input params should produce different values");
assertEq(factory.getParameters().corePlugins.adminPlugin.release, 2, "Admin plugin release mismatch");
assertEq(factory.getParameters().corePlugins.adminPlugin.build, 10, "Admin plugin build mismatch");
assertEq(
factory.getParameters().corePlugins.adminPlugin.releaseMetadataUri,
"releaseMeta-2",
"Admin plugin releaseMetadataUri mismatch"
);
assertEq(
factory.getParameters().corePlugins.adminPlugin.buildMetadataUri,
"buildMeta-2",
"Admin plugin buildMetadataUri mismatch"
);
assertEq(
factory.getParameters().corePlugins.adminPlugin.subdomain, "admin-2", "Admin plugin subdomain mismatch"
);
hash1 = hash2;
// 7
factory = builder.withMultisigPlugin(1, 5, "releaseMeta", "buildMeta", "multisig-1").build();
hash2 = keccak256(abi.encode(factory.getParameters()));
assertNotEq(hash1, hash2, "Different input params should produce different values");
assertEq(factory.getParameters().corePlugins.multisigPlugin.release, 1, "Multisig plugin release mismatch");
assertEq(factory.getParameters().corePlugins.multisigPlugin.build, 5, "Multisig plugin build mismatch");
assertEq(
factory.getParameters().corePlugins.multisigPlugin.releaseMetadataUri,
"releaseMeta",
"Multisig plugin releaseMetadataUri mismatch"
);
assertEq(
factory.getParameters().corePlugins.multisigPlugin.buildMetadataUri,
"buildMeta",
"Multisig plugin buildMetadataUri mismatch"
);
assertEq(
factory.getParameters().corePlugins.multisigPlugin.subdomain,
"multisig-1",
"Multisig plugin subdomain mismatch"
);
hash1 = hash2;
// 8
factory = builder.withMultisigPlugin(2, 10, "releaseMeta-2", "buildMeta-2", "multisig-2").build();
hash2 = keccak256(abi.encode(factory.getParameters()));
assertNotEq(hash1, hash2, "Different input params should produce different values");
assertEq(factory.getParameters().corePlugins.multisigPlugin.release, 2, "Multisig plugin release mismatch");
assertEq(factory.getParameters().corePlugins.multisigPlugin.build, 10, "Multisig plugin build mismatch");
assertEq(
factory.getParameters().corePlugins.multisigPlugin.releaseMetadataUri,
"releaseMeta-2",
"Multisig plugin releaseMetadataUri mismatch"
);
assertEq(
factory.getParameters().corePlugins.multisigPlugin.buildMetadataUri,
"buildMeta-2",
"Multisig plugin buildMetadataUri mismatch"
);
assertEq(
factory.getParameters().corePlugins.multisigPlugin.subdomain,
"multisig-2",
"Multisig plugin subdomain mismatch"
);
hash1 = hash2;
// 9
factory = builder.withTokenVotingPlugin(1, 5, "releaseMeta", "buildMeta", "tokenVoting-1").build();
hash2 = keccak256(abi.encode(factory.getParameters()));
assertNotEq(hash1, hash2, "Different input params should produce different values");
assertEq(
factory.getParameters().corePlugins.tokenVotingPlugin.release, 1, "TokenVoting plugin release mismatch"
);
assertEq(factory.getParameters().corePlugins.tokenVotingPlugin.build, 5, "TokenVoting plugin build mismatch");
assertEq(
factory.getParameters().corePlugins.tokenVotingPlugin.releaseMetadataUri,
"releaseMeta",
"TokenVoting plugin releaseMetadataUri mismatch"
);
assertEq(
factory.getParameters().corePlugins.tokenVotingPlugin.buildMetadataUri,
"buildMeta",
"TokenVoting plugin buildMetadataUri mismatch"
);
assertEq(
factory.getParameters().corePlugins.tokenVotingPlugin.subdomain,
"tokenVoting-1",
"TokenVoting plugin subdomain mismatch"
);
hash1 = hash2;
// 10
factory = builder.withTokenVotingPlugin(2, 10, "releaseMeta-2", "buildMeta-2", "tokenVoting-2").build();
hash2 = keccak256(abi.encode(factory.getParameters()));
assertNotEq(hash1, hash2, "Different input params should produce different values");
assertEq(
factory.getParameters().corePlugins.tokenVotingPlugin.release, 2, "TokenVoting plugin release mismatch"
);
assertEq(factory.getParameters().corePlugins.tokenVotingPlugin.build, 10, "TokenVoting plugin build mismatch");
assertEq(
factory.getParameters().corePlugins.tokenVotingPlugin.releaseMetadataUri,
"releaseMeta-2",
"TokenVoting plugin releaseMetadataUri mismatch"
);
assertEq(
factory.getParameters().corePlugins.tokenVotingPlugin.buildMetadataUri,
"buildMeta-2",
"TokenVoting plugin buildMetadataUri mismatch"
);
assertEq(
factory.getParameters().corePlugins.tokenVotingPlugin.subdomain,
"tokenVoting-2",
"TokenVoting plugin subdomain mismatch"
);
hash1 = hash2;
// 11
factory = builder.withStagedProposalProcessorPlugin(
1, 5, "releaseMeta", "buildMeta", "stagedProposalProcessor-1"
).build();
hash2 = keccak256(abi.encode(factory.getParameters()));
assertNotEq(hash1, hash2, "Different input params should produce different values");
assertEq(
factory.getParameters().corePlugins.stagedProposalProcessorPlugin.release,
1,
"StagedProposalProcessor plugin release mismatch"
);
assertEq(
factory.getParameters().corePlugins.stagedProposalProcessorPlugin.build,
5,
"StagedProposalProcessor plugin build mismatch"
);
assertEq(
factory.getParameters().corePlugins.stagedProposalProcessorPlugin.releaseMetadataUri,
"releaseMeta",
"StagedProposalProcessor plugin releaseMetadataUri mismatch"
);
assertEq(
factory.getParameters().corePlugins.stagedProposalProcessorPlugin.buildMetadataUri,
"buildMeta",
"StagedProposalProcessor plugin buildMetadataUri mismatch"
);
assertEq(
factory.getParameters().corePlugins.stagedProposalProcessorPlugin.subdomain,
"stagedProposalProcessor-1",
"StagedProposalProcessor plugin subdomain mismatch"
);
hash1 = hash2;
// 12
factory = builder.withStagedProposalProcessorPlugin(
2, 10, "releaseMeta-2", "buildMeta-2", "stagedProposalProcessor-2"
).build();
hash2 = keccak256(abi.encode(factory.getParameters()));
assertNotEq(hash1, hash2, "Different input params should produce different values");
assertEq(
factory.getParameters().corePlugins.stagedProposalProcessorPlugin.release,
2,
"StagedProposalProcessor plugin release mismatch"
);
assertEq(
factory.getParameters().corePlugins.stagedProposalProcessorPlugin.build,
10,
"StagedProposalProcessor plugin build mismatch"
);
assertEq(
factory.getParameters().corePlugins.stagedProposalProcessorPlugin.releaseMetadataUri,
"releaseMeta-2",
"StagedProposalProcessor plugin releaseMetadataUri mismatch"
);
assertEq(
factory.getParameters().corePlugins.stagedProposalProcessorPlugin.buildMetadataUri,
"buildMeta-2",
"StagedProposalProcessor plugin buildMetadataUri mismatch"
);
assertEq(
factory.getParameters().corePlugins.stagedProposalProcessorPlugin.subdomain,
"stagedProposalProcessor-2",
"StagedProposalProcessor plugin subdomain mismatch"
);
hash1 = hash2;
// 13
factory = builder.withManagementDaoMetadataUri("meta-1234").build();
hash2 = keccak256(abi.encode(factory.getParameters()));
assertNotEq(hash1, hash2, "Different input params should produce different values");
assertEq(factory.getParameters().managementDao.metadataUri, "meta-1234", "Management DAO metadataUri mismatch");
hash1 = hash2;
// 14
factory = builder.withManagementDaoMembers(new address[](1)).build();
hash2 = keccak256(abi.encode(factory.getParameters()));
assertNotEq(hash1, hash2, "Different input params should produce different values");
assertEq(factory.getParameters().managementDao.members.length, 1, "Management DAO members list mismatch");
hash1 = hash2;
// 15
factory = builder.withManagementDaoMinApprovals(10).build();
hash2 = keccak256(abi.encode(factory.getParameters()));
assertNotEq(hash1, hash2, "Different input params should produce different values");
assertEq(factory.getParameters().managementDao.minApprovals, 10, "Management DAO minApprovals mismatch");
hash1 = hash2;
}
function test_WhenCallingGetDeployment() external givenAProtocolDeployment {
// It Should return the right values
assertEq(
keccak256(abi.encode(deployment)),
keccak256(abi.encode(factory.getDeployment())),
"Deployment addresses mismatch"
);
// Sanity checks
assertNotEq(deployment.daoFactory, address(0));
assertNotEq(deployment.pluginRepoFactory, address(0));
assertNotEq(PluginRepoFactory(deployment.pluginRepoFactory).pluginRepoBase(), address(0));
assertNotEq(deployment.pluginSetupProcessor, address(0));
assertEq(
address(PluginSetupProcessor(deployment.pluginSetupProcessor).repoRegistry()), deployment.pluginRepoRegistry
);
assertEq(deployment.globalExecutor, deploymentParams.osxImplementations.globalExecutor);
assertEq(deployment.placeholderSetup, deploymentParams.osxImplementations.placeholderSetup);
assertNotEq(deployment.daoRegistry, address(0));
assertEq(address(DAORegistry(deployment.daoRegistry).subdomainRegistrar()), deployment.daoSubdomainRegistrar);
assertNotEq(deployment.pluginRepoRegistry, address(0));
assertEq(
address(PluginRepoRegistry(deployment.pluginRepoRegistry).subdomainRegistrar()),
deployment.pluginSubdomainRegistrar
);
assertNotEq(deployment.managementDao, address(0));
assertEq(_getImplementation(deployment.managementDao), deploymentParams.osxImplementations.daoBase);
assertNotEq(deployment.managementDaoMultisig, address(0));
assertNotEq(deployment.ensRegistry, address(0));
assertNotEq(deployment.daoSubdomainRegistrar, address(0));
assertEq(address(ENSSubdomainRegistrar(deployment.daoSubdomainRegistrar).ens()), deployment.ensRegistry);
assertEq(address(ENSSubdomainRegistrar(deployment.daoSubdomainRegistrar).resolver()), deployment.publicResolver);
assertNotEq(deployment.pluginSubdomainRegistrar, address(0));
assertEq(address(ENSSubdomainRegistrar(deployment.pluginSubdomainRegistrar).ens()), deployment.ensRegistry);
assertEq(
address(ENSSubdomainRegistrar(deployment.pluginSubdomainRegistrar).resolver()), deployment.publicResolver
);
assertNotEq(deployment.publicResolver, address(0));
assertNotEq(deployment.adminPluginRepo, address(0));
assertEq(PluginRepo(deployment.adminPluginRepo).latestRelease(), 1);
assertEq(
PluginRepo(deployment.adminPluginRepo).getLatestVersion(1).pluginSetup,
address(deploymentParams.corePlugins.adminPlugin.pluginSetup)
);
assertNotEq(deployment.multisigPluginRepo, address(0));
assertEq(PluginRepo(deployment.multisigPluginRepo).latestRelease(), 1);
assertEq(
PluginRepo(deployment.multisigPluginRepo).getLatestVersion(1).pluginSetup,
address(deploymentParams.corePlugins.multisigPlugin.pluginSetup)
);
assertNotEq(deployment.tokenVotingPluginRepo, address(0));
assertEq(PluginRepo(deployment.tokenVotingPluginRepo).latestRelease(), 1);
assertEq(
PluginRepo(deployment.tokenVotingPluginRepo).getLatestVersion(1).pluginSetup,
address(deploymentParams.corePlugins.tokenVotingPlugin.pluginSetup)
);
assertNotEq(deployment.stagedProposalProcessorPluginRepo, address(0));
assertEq(PluginRepo(deployment.stagedProposalProcessorPluginRepo).latestRelease(), 1);
assertEq(
PluginRepo(deployment.stagedProposalProcessorPluginRepo).getLatestVersion(1).pluginSetup,
address(deploymentParams.corePlugins.stagedProposalProcessorPlugin.pluginSetup)
);
}
function test_WhenUsingTheDAOFactory() external givenAProtocolDeployment {
DAOFactory daoFactory = DAOFactory(deployment.daoFactory);
DAORegistry daoRegistry = DAORegistry(deployment.daoRegistry);
ENS ens = ENS(deployment.ensRegistry);
IResolver resolver = IResolver(deployment.publicResolver);
string memory daoSubdomain = "testdao";
string memory metadataUri = "ipfs://dao-meta";
DAOFactory.DAOSettings memory daoSettings = DAOFactory.DAOSettings({
trustedForwarder: address(0),
daoURI: "ipfs://dao-uri",
metadata: bytes(metadataUri),
subdomain: daoSubdomain
});
DAOFactory.PluginSettings[] memory plugins = new DAOFactory.PluginSettings[](0);
// It Should deploy a valid DAO and register it
(DAO newDao,) = daoFactory.createDao(daoSettings, plugins);
assertNotEq(address(newDao), address(0), "DAO address is zero");
assertTrue(daoRegistry.entries(address(newDao)), "DAO not registered in registry");
// It New DAOs should have the right permissions on themselves
// By default, DAOFactory grants ROOT to the DAO itself
assertTrue(
newDao.hasPermission(address(newDao), address(newDao), newDao.ROOT_PERMISSION_ID(), ""),
"DAO does not have ROOT on itself"
);
// It New DAOs should be resolved from the requested ENS subdomain
string memory fullDomain =
string.concat(daoSubdomain, ".", deploymentParams.ensParameters.daoRootDomain, ".eth");
bytes32 node = vm.ensNamehash(fullDomain);
assertEq(ens.owner(node), deployment.daoSubdomainRegistrar, "ENS owner mismatch");
assertEq(ens.resolver(node), deployment.publicResolver, "ENS resolver mismatch");
assertEq(resolver.addr(node), address(newDao), "Resolver addr mismatch");
}
function test_WhenUsingThePluginRepoFactory() external givenAProtocolDeployment {
PluginRepoFactory repoFactory = PluginRepoFactory(deployment.pluginRepoFactory);
PluginRepoRegistry repoRegistry = PluginRepoRegistry(deployment.pluginRepoRegistry);
ENS ens = ENS(deployment.ensRegistry);
IResolver resolver = IResolver(deployment.publicResolver);
string memory repoSubdomain = "testplugin";
address maintainer = alice; // Let Alice be the maintainer
// It Should deploy a valid PluginRepo and register it
address newRepoAddress = address(repoFactory.createPluginRepo(repoSubdomain, maintainer));
assertTrue(newRepoAddress != address(0), "Repo address is zero");
assertTrue(repoRegistry.entries(newRepoAddress), "Repo not registered in registry");
PluginRepo newRepo = PluginRepo(newRepoAddress);
assertTrue(
newRepo.isGranted(newRepoAddress, maintainer, newRepo.MAINTAINER_PERMISSION_ID(), ""),
"Maintainer does not have MAINTAINER_PERMISSION on the plugin repo"
);
// It The maintainer can publish new versions
DummySetup dummySetup = new DummySetup();
vm.prank(maintainer);
newRepo.createVersion(1, address(dummySetup), bytes("ipfs://build"), bytes("ipfs://release"));
PluginRepo.Version memory latestVersion = newRepo.getLatestVersion(1);
assertEq(latestVersion.pluginSetup, address(dummySetup), "Published version mismatch");
// It The plugin repo should be resolved from the requested ENS subdomain
string memory fullDomain = string.concat(
repoSubdomain,
".",
deploymentParams.ensParameters.pluginSubdomain,
".",
deploymentParams.ensParameters.daoRootDomain,
".eth"
);
bytes32 node = vm.ensNamehash(fullDomain);
assertEq(ens.owner(node), deployment.pluginSubdomainRegistrar, "ENS owner mismatch");
assertEq(ens.resolver(node), deployment.publicResolver, "ENS resolver mismatch");
assertEq(resolver.addr(node), newRepoAddress, "Resolver addr mismatch");
}
function test_WhenUsingTheManagementDAO() external givenAProtocolDeployment {
Multisig multisig = Multisig(deployment.managementDaoMultisig);
PluginRepo adminRepo = PluginRepo(deployment.adminPluginRepo);
// It Should have a multisig with the given members and settings
assertEq(multisig.addresslistLength(), mgmtDaoMembers.length, "Member count mismatch");
for (uint256 i = 0; i < mgmtDaoMembers.length; i++) {
assertTrue(multisig.isListed(mgmtDaoMembers[i]), "Member address mismatch");
}
(bool onlyListed, uint16 minApprovals) = multisig.multisigSettings();
assertTrue(onlyListed, "OnlyListed should be true");
assertEq(minApprovals, uint16(deploymentParams.managementDao.minApprovals), "Min approvals mismatch");
// It Should be able to publish new core plugin versions (via multisig)
DummySetup dummySetup = new DummySetup();
uint8 targetRelease = deploymentParams.corePlugins.adminPlugin.release;
bytes memory buildMeta = bytes("ipfs://new-admin-build");
bytes memory releaseMeta = bytes("ipfs://new-admin-release"); // Usually same for build
bytes memory actionData = abi.encodeCall(
PluginRepo.createVersion,
(
targetRelease, // target release
address(dummySetup), // new setup implementation
buildMeta,
releaseMeta
)
);
Action[] memory actions = new Action[](1);
actions[0] = Action({to: deployment.adminPluginRepo, value: 0, data: actionData});
// Move 1 block forward to avoid ProposalCreationForbidden()
vm.roll(block.number + 1);
// Create proposal (Alice proposes)
vm.prank(alice);
uint256 proposalId = multisig.createProposal(
bytes("ipfs://prop-new-admin-version"),
actions,
0, // startdate
uint64(block.timestamp + 100), // enddate
bytes("")
);
// Move 1 block forward to avoid missing the snapshot block
vm.roll(block.number + 1);
assertTrue(multisig.canApprove(proposalId, alice), "Cannot approve");
vm.prank(alice);
multisig.approve(proposalId, false);
// Approve (Bob approves, reaching minApprovals = 2)
vm.prank(bob);
multisig.approve(proposalId, false);
uint256 buildCountBefore = adminRepo.buildCount(targetRelease);
// Execute (Carol executes)
assertTrue(multisig.canExecute(proposalId), "Proposal should be executable");
vm.prank(carol);
multisig.execute(proposalId);
uint256 buildCountAfter = adminRepo.buildCount(targetRelease);
assertEq(buildCountBefore + 1, buildCountAfter, "Should have increased hte buildCount");
// Verify new version
PluginRepo.Version memory latestVersion = adminRepo.getLatestVersion(targetRelease);
assertEq(latestVersion.pluginSetup, address(dummySetup), "New version setup mismatch");
assertEq(latestVersion.buildMetadata, buildMeta, "New version build meta mismatch");
}
function test_WhenPreparingAnAdminPluginInstallation() external givenAProtocolDeployment {
DAO targetDao = _createTestDao("dao-with-admin-plugin", deployment);
PluginSetupProcessor psp = PluginSetupProcessor(deployment.pluginSetupProcessor);
PluginSetupRef memory pluginSetupRef = PluginSetupRef(
PluginRepo.Tag(
deploymentParams.corePlugins.adminPlugin.release, deploymentParams.corePlugins.adminPlugin.build
),
PluginRepo(deployment.adminPluginRepo)
);
// Custom prepareInstallation params
IPlugin.TargetConfig memory targetConfig =
IPlugin.TargetConfig({target: address(targetDao), operation: IPlugin.Operation.Call});
bytes memory setupData = abi.encode(bob, targetConfig); // Initial admin and target
// It should complete normally
(address pluginAddress, IPluginSetup.PreparedSetupData memory preparedSetupData) = psp.prepareInstallation(
address(targetDao), PluginSetupProcessor.PrepareInstallationParams(pluginSetupRef, setupData)
);
assertNotEq(pluginAddress, address(0));
assertTrue(pluginAddress.code.length > 0, "No code at plugin address");
assertEq(preparedSetupData.permissions.length, 3, "Wrong admin permissions");
}
function test_WhenApplyingAnAdminPluginInstallation() external givenAProtocolDeployment {
DAO targetDao = _createTestDao("dao-with-admin-plugin2", deployment);
PluginSetupRef memory pluginSetupRef = PluginSetupRef(
PluginRepo.Tag(
deploymentParams.corePlugins.adminPlugin.release, deploymentParams.corePlugins.adminPlugin.build
),
PluginRepo(deployment.adminPluginRepo)
);
// Custom prepareInstallation params
address initialAdmin = alice; // Let Alice be the admin
IPlugin.TargetConfig memory targetConfig =
IPlugin.TargetConfig({target: address(targetDao), operation: IPlugin.Operation.Call});
bytes memory setupData = abi.encode(initialAdmin, targetConfig); // Initial admin and target
address pluginAddress = _installPlugin(targetDao, pluginSetupRef, setupData);
// It should allow the admin to execute on the DAO
Admin adminPlugin = Admin(pluginAddress);
string memory newDaoUri = "https://new-uri";
assertNotEq(targetDao.daoURI(), newDaoUri, "Should not have the new value yet");
bytes memory executeCalldata = abi.encodeCall(DAO.setDaoURI, (newDaoUri));
Action[] memory actions = new Action[](1);
actions[0] = Action({to: address(targetDao), value: 0, data: executeCalldata});
// Immediately executed
vm.prank(alice);
adminPlugin.createProposal("ipfs://proposal-meta", actions, 0, 0, bytes(""));
// Verify execution
assertEq(targetDao.daoURI(), newDaoUri, "Execution failed");
}
function test_WhenPreparingAMultisigPluginInstallation() external givenAProtocolDeployment {
DAO targetDao = _createTestDao("dao-with-multisig", deployment);
PluginSetupProcessor psp = PluginSetupProcessor(deployment.pluginSetupProcessor);
PluginSetupRef memory pluginSetupRef = PluginSetupRef(
PluginRepo.Tag(
deploymentParams.corePlugins.multisigPlugin.release, deploymentParams.corePlugins.multisigPlugin.build
),
PluginRepo(deployment.multisigPluginRepo)
);
IPlugin.TargetConfig memory targetConfig =
IPlugin.TargetConfig({target: address(targetDao), operation: IPlugin.Operation.Call});
address[] memory members = new address[](3);
members[0] = bob;
members[1] = carol;
members[2] = david;
bytes memory setupData = abi.encode(
members,
Multisig.MultisigSettings({onlyListed: true, minApprovals: 2}),
targetConfig,
bytes("") // metadata
);
// It should complete normally
(address pluginAddress, IPluginSetup.PreparedSetupData memory preparedSetupData) = psp.prepareInstallation(
address(targetDao), PluginSetupProcessor.PrepareInstallationParams(pluginSetupRef, setupData)
);
assertNotEq(pluginAddress, address(0));
assertTrue(pluginAddress.code.length > 0, "No code at plugin address");
assertEq(preparedSetupData.permissions.length, 6, "Wrong multisig permissions");
}
function test_WhenApplyingAMultisigPluginInstallation() external givenAProtocolDeployment {
DAO targetDao = _createTestDao("dao-with-multisig2", deployment);
PluginSetupRef memory pluginSetupRef = PluginSetupRef(
PluginRepo.Tag(
deploymentParams.corePlugins.multisigPlugin.release, deploymentParams.corePlugins.multisigPlugin.build
),
PluginRepo(deployment.multisigPluginRepo)
);
IPlugin.TargetConfig memory targetConfig =
IPlugin.TargetConfig({target: address(targetDao), operation: IPlugin.Operation.Call});
address[] memory members = new address[](3);
members[0] = bob;
members[1] = carol;
members[2] = david;
bytes memory setupData = abi.encode(
members,
Multisig.MultisigSettings({onlyListed: true, minApprovals: 2}),
targetConfig,
bytes("") // metadata
);
address pluginAddress = _installPlugin(targetDao, pluginSetupRef, setupData);
Multisig multisigPlugin = Multisig(pluginAddress);
// Allow this script to create proposals on the plugin
Action[] memory actions = new Action[](1);
actions[0] = Action({
to: address(targetDao),
value: 0,
data: abi.encodeCall(
PermissionManager.grant, (pluginAddress, address(this), multisigPlugin.CREATE_PROPOSAL_PERMISSION_ID())
)
});
targetDao.execute(bytes32(0), actions, 0);
// Try to change the DAO URI via proposal
string memory newDaoUri = "https://new-uri";
assertNotEq(targetDao.daoURI(), newDaoUri, "Should not have the new value yet");
bytes memory executeCalldata = abi.encodeCall(DAO.setDaoURI, (newDaoUri));
actions[0] = Action({to: address(targetDao), value: 0, data: executeCalldata});
// Create proposal
vm.roll(block.number + 1);
uint256 proposalId = multisigPlugin.createProposal(
"ipfs://proposal-meta", actions, 0, uint64(block.timestamp + 20000), bytes("")
);
// Approve (Bob)
vm.prank(bob);
multisigPlugin.approve(proposalId, false);
// Approve (Carol)
vm.prank(carol);
multisigPlugin.approve(proposalId, false);
// Execute (David)
assertTrue(multisigPlugin.canExecute(proposalId));
vm.prank(david);
multisigPlugin.execute(proposalId);
// Verify execution