@diamondslab/diamonds 1.4.0 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (174) hide show
  1. package/CHANGELOG.md +67 -0
  2. package/README.md +32 -6
  3. package/dist/cli/diamond-abi-cli.d.ts +0 -1
  4. package/dist/cli/diamond-abi-cli.js +2 -1
  5. package/dist/core/CallbackManager.d.ts +0 -1
  6. package/dist/core/CallbackManager.js +0 -1
  7. package/dist/core/DeploymentManager.d.ts +0 -1
  8. package/dist/core/DeploymentManager.js +0 -1
  9. package/dist/core/Diamond.d.ts +0 -1
  10. package/dist/core/Diamond.js +0 -1
  11. package/dist/core/DiamondDeployer.d.ts +0 -1
  12. package/dist/core/DiamondDeployer.js +0 -1
  13. package/dist/core/index.d.ts +0 -1
  14. package/dist/core/index.js +0 -1
  15. package/dist/index.d.ts +0 -1
  16. package/dist/index.js +0 -1
  17. package/dist/repositories/DBDeploymentRepository.d.ts +0 -1
  18. package/dist/repositories/DBDeploymentRepository.js +0 -1
  19. package/dist/repositories/DeploymentRepository.d.ts +0 -1
  20. package/dist/repositories/DeploymentRepository.js +0 -1
  21. package/dist/repositories/FileDeploymentRepository.d.ts +0 -1
  22. package/dist/repositories/FileDeploymentRepository.js +0 -1
  23. package/dist/repositories/databaseHandler.d.ts +0 -1
  24. package/dist/repositories/databaseHandler.js +0 -1
  25. package/dist/repositories/index.d.ts +0 -1
  26. package/dist/repositories/index.js +0 -1
  27. package/dist/repositories/jsonFileHandler.d.ts +0 -1
  28. package/dist/repositories/jsonFileHandler.js +0 -1
  29. package/dist/repositories/prismaDBHandler.d.ts +0 -1
  30. package/dist/repositories/prismaDBHandler.js +0 -1
  31. package/dist/resolution/index.d.ts +0 -1
  32. package/dist/resolution/index.js +0 -1
  33. package/dist/resolution/selectorResolution.d.ts +0 -1
  34. package/dist/resolution/selectorResolution.js +0 -1
  35. package/dist/schemas/DeploymentSchema.d.ts +0 -1
  36. package/dist/schemas/DeploymentSchema.js +0 -1
  37. package/dist/schemas/index.d.ts +0 -1
  38. package/dist/schemas/index.js +0 -1
  39. package/dist/strategies/BaseDeploymentStrategy.d.ts +0 -1
  40. package/dist/strategies/BaseDeploymentStrategy.js +0 -1
  41. package/dist/strategies/DeploymentStrategy.d.ts +0 -1
  42. package/dist/strategies/DeploymentStrategy.js +0 -1
  43. package/dist/strategies/LocalDeploymentStrategy.d.ts +0 -1
  44. package/dist/strategies/LocalDeploymentStrategy.js +0 -1
  45. package/dist/strategies/OZDefenderDeploymentStrategy.d.ts +2 -3
  46. package/dist/strategies/OZDefenderDeploymentStrategy.js +12 -3
  47. package/dist/strategies/RPCDeploymentStrategy.d.ts +0 -1
  48. package/dist/strategies/RPCDeploymentStrategy.js +0 -1
  49. package/dist/strategies/index.d.ts +0 -1
  50. package/dist/strategies/index.js +0 -1
  51. package/dist/types/config.d.ts +0 -1
  52. package/dist/types/config.js +0 -1
  53. package/dist/types/defender.d.ts +0 -1
  54. package/dist/types/defender.js +0 -1
  55. package/dist/types/deployments.d.ts +0 -1
  56. package/dist/types/deployments.js +0 -1
  57. package/dist/types/index.d.ts +0 -1
  58. package/dist/types/index.js +0 -1
  59. package/dist/types/rpc.d.ts +0 -1
  60. package/dist/types/rpc.js +0 -1
  61. package/dist/utils/common.d.ts +1 -2
  62. package/dist/utils/common.js +0 -1
  63. package/dist/utils/configurationResolver.d.ts +0 -1
  64. package/dist/utils/configurationResolver.js +0 -1
  65. package/dist/utils/contractMapping.d.ts +0 -1
  66. package/dist/utils/contractMapping.js +0 -1
  67. package/dist/utils/defenderClients.d.ts +2 -5
  68. package/dist/utils/defenderClients.js +36 -16
  69. package/dist/utils/defenderStore.d.ts +0 -1
  70. package/dist/utils/defenderStore.js +0 -1
  71. package/dist/utils/diamondAbiGenerator.d.ts +0 -1
  72. package/dist/utils/diamondAbiGenerator.js +0 -1
  73. package/dist/utils/diffDeployedFacets.d.ts +0 -1
  74. package/dist/utils/diffDeployedFacets.js +0 -1
  75. package/dist/utils/index.d.ts +0 -1
  76. package/dist/utils/index.js +0 -1
  77. package/dist/utils/loupe.d.ts +0 -1
  78. package/dist/utils/loupe.js +0 -1
  79. package/dist/utils/rpcStore.d.ts +0 -1
  80. package/dist/utils/rpcStore.js +0 -1
  81. package/dist/utils/signer.d.ts +0 -1
  82. package/dist/utils/signer.js +0 -1
  83. package/dist/utils/txlogging.d.ts +0 -1
  84. package/dist/utils/txlogging.js +0 -1
  85. package/dist/utils/workspaceSetup.d.ts +0 -1
  86. package/dist/utils/workspaceSetup.js +0 -1
  87. package/package.json +29 -18
  88. package/diamonds/README.md +0 -3
  89. package/dist/cli/diamond-abi-cli.d.ts.map +0 -1
  90. package/dist/cli/diamond-abi-cli.js.map +0 -1
  91. package/dist/core/CallbackManager.d.ts.map +0 -1
  92. package/dist/core/CallbackManager.js.map +0 -1
  93. package/dist/core/DeploymentManager.d.ts.map +0 -1
  94. package/dist/core/DeploymentManager.js.map +0 -1
  95. package/dist/core/Diamond.d.ts.map +0 -1
  96. package/dist/core/Diamond.js.map +0 -1
  97. package/dist/core/DiamondDeployer.d.ts.map +0 -1
  98. package/dist/core/DiamondDeployer.js.map +0 -1
  99. package/dist/core/index.d.ts.map +0 -1
  100. package/dist/core/index.js.map +0 -1
  101. package/dist/index.d.ts.map +0 -1
  102. package/dist/index.js.map +0 -1
  103. package/dist/repositories/DBDeploymentRepository.d.ts.map +0 -1
  104. package/dist/repositories/DBDeploymentRepository.js.map +0 -1
  105. package/dist/repositories/DeploymentRepository.d.ts.map +0 -1
  106. package/dist/repositories/DeploymentRepository.js.map +0 -1
  107. package/dist/repositories/FileDeploymentRepository.d.ts.map +0 -1
  108. package/dist/repositories/FileDeploymentRepository.js.map +0 -1
  109. package/dist/repositories/databaseHandler.d.ts.map +0 -1
  110. package/dist/repositories/databaseHandler.js.map +0 -1
  111. package/dist/repositories/index.d.ts.map +0 -1
  112. package/dist/repositories/index.js.map +0 -1
  113. package/dist/repositories/jsonFileHandler.d.ts.map +0 -1
  114. package/dist/repositories/jsonFileHandler.js.map +0 -1
  115. package/dist/repositories/prismaDBHandler.d.ts.map +0 -1
  116. package/dist/repositories/prismaDBHandler.js.map +0 -1
  117. package/dist/resolution/index.d.ts.map +0 -1
  118. package/dist/resolution/index.js.map +0 -1
  119. package/dist/resolution/selectorResolution.d.ts.map +0 -1
  120. package/dist/resolution/selectorResolution.js.map +0 -1
  121. package/dist/schemas/DeploymentSchema.d.ts.map +0 -1
  122. package/dist/schemas/DeploymentSchema.js.map +0 -1
  123. package/dist/schemas/index.d.ts.map +0 -1
  124. package/dist/schemas/index.js.map +0 -1
  125. package/dist/strategies/BaseDeploymentStrategy.d.ts.map +0 -1
  126. package/dist/strategies/BaseDeploymentStrategy.js.map +0 -1
  127. package/dist/strategies/DeploymentStrategy.d.ts.map +0 -1
  128. package/dist/strategies/DeploymentStrategy.js.map +0 -1
  129. package/dist/strategies/LocalDeploymentStrategy.d.ts.map +0 -1
  130. package/dist/strategies/LocalDeploymentStrategy.js.map +0 -1
  131. package/dist/strategies/OZDefenderDeploymentStrategy.d.ts.map +0 -1
  132. package/dist/strategies/OZDefenderDeploymentStrategy.js.map +0 -1
  133. package/dist/strategies/RPCDeploymentStrategy.d.ts.map +0 -1
  134. package/dist/strategies/RPCDeploymentStrategy.js.map +0 -1
  135. package/dist/strategies/index.d.ts.map +0 -1
  136. package/dist/strategies/index.js.map +0 -1
  137. package/dist/types/config.d.ts.map +0 -1
  138. package/dist/types/config.js.map +0 -1
  139. package/dist/types/defender.d.ts.map +0 -1
  140. package/dist/types/defender.js.map +0 -1
  141. package/dist/types/deployments.d.ts.map +0 -1
  142. package/dist/types/deployments.js.map +0 -1
  143. package/dist/types/index.d.ts.map +0 -1
  144. package/dist/types/index.js.map +0 -1
  145. package/dist/types/rpc.d.ts.map +0 -1
  146. package/dist/types/rpc.js.map +0 -1
  147. package/dist/utils/common.d.ts.map +0 -1
  148. package/dist/utils/common.js.map +0 -1
  149. package/dist/utils/configurationResolver.d.ts.map +0 -1
  150. package/dist/utils/configurationResolver.js.map +0 -1
  151. package/dist/utils/contractMapping.d.ts.map +0 -1
  152. package/dist/utils/contractMapping.js.map +0 -1
  153. package/dist/utils/defenderClients.d.ts.map +0 -1
  154. package/dist/utils/defenderClients.js.map +0 -1
  155. package/dist/utils/defenderStore.d.ts.map +0 -1
  156. package/dist/utils/defenderStore.js.map +0 -1
  157. package/dist/utils/diamondAbiGenerator.d.ts.map +0 -1
  158. package/dist/utils/diamondAbiGenerator.js.map +0 -1
  159. package/dist/utils/diffDeployedFacets.d.ts.map +0 -1
  160. package/dist/utils/diffDeployedFacets.js.map +0 -1
  161. package/dist/utils/index.d.ts.map +0 -1
  162. package/dist/utils/index.js.map +0 -1
  163. package/dist/utils/loupe.d.ts.map +0 -1
  164. package/dist/utils/loupe.js.map +0 -1
  165. package/dist/utils/rpcStore.d.ts.map +0 -1
  166. package/dist/utils/rpcStore.js.map +0 -1
  167. package/dist/utils/signer.d.ts.map +0 -1
  168. package/dist/utils/signer.js.map +0 -1
  169. package/dist/utils/txlogging.d.ts.map +0 -1
  170. package/dist/utils/txlogging.js.map +0 -1
  171. package/dist/utils/workspaceSetup.d.ts.map +0 -1
  172. package/dist/utils/workspaceSetup.js.map +0 -1
  173. package/examples/defender-deployment/README.md +0 -415
  174. package/test/README.md +0 -136
@@ -1,415 +0,0 @@
1
- # Defender Deployment Example
2
-
3
- This example demonstrates how to deploy and upgrade a Diamond proxy contract using OpenZeppelin Defender.
4
-
5
- ## Overview
6
-
7
- This example includes:
8
-
9
- - A complete Diamond implementation with multiple facets
10
- - Configuration for Defender deployment
11
- - Deployment and upgrade scripts
12
- - Step-by-step instructions
13
-
14
- ## Prerequisites
15
-
16
- 1. OpenZeppelin Defender account with API credentials
17
- 2. Testnet ETH for gas fees
18
- 3. Node.js 16+ and npm
19
-
20
- ## Setup
21
-
22
- 1. **Clone and Install Dependencies**
23
-
24
- ```bash
25
- cd examples/defender-deployment
26
- npm install
27
- ```
28
-
29
- 2. **Configure Environment**
30
-
31
- ```bash
32
- cp .env.example .env
33
- # Edit .env with your Defender credentials
34
- ```
35
-
36
- 3. **Review Diamond Configuration**
37
-
38
- ```bash
39
- cat diamond-config.json
40
- ```
41
-
42
- ## Diamond Structure
43
-
44
- ### Contracts
45
-
46
- - `ExampleDiamond.sol`: Main diamond contract
47
- - `ExampleFacet1.sol`: Basic functionality facet
48
- - `ExampleFacet2.sol`: Advanced functionality facet
49
- - `UpgradeFacet.sol`: New facet for upgrade demonstration
50
-
51
- ### Configuration
52
-
53
- ```json
54
- {
55
- "protocolVersion": 0.0,
56
- "protocolInitFacet": "ExampleFacet1",
57
- "facets": {
58
- "DiamondCutFacet": {
59
- "priority": 10,
60
- "versions": { "0.0": {} }
61
- },
62
- "DiamondLoupeFacet": {
63
- "priority": 20,
64
- "versions": { "0.0": {} }
65
- },
66
- "ExampleFacet1": {
67
- "priority": 30,
68
- "versions": {
69
- "0.0": {
70
- "deployInit": "initialize()",
71
- "callbacks": ["logDeployment"]
72
- }
73
- }
74
- },
75
- "ExampleFacet2": {
76
- "priority": 40,
77
- "versions": {
78
- "0.0": {
79
- "deployInit": "setup()",
80
- "callbacks": ["validateSetup"]
81
- }
82
- }
83
- }
84
- }
85
- }
86
- ```
87
-
88
- ## Deployment Steps
89
-
90
- ### 1. Initial Deployment
91
-
92
- ```bash
93
- # Deploy to Sepolia testnet
94
- npm run deploy:sepolia
95
-
96
- # Or deploy to local hardhat network
97
- npm run deploy:local
98
- ```
99
-
100
- This will:
101
-
102
- 1. Deploy DiamondCutFacet through Defender
103
- 2. Deploy the main Diamond contract
104
- 3. Deploy all configured facets
105
- 4. Create a Defender proposal for the diamond cut
106
- 5. Execute the proposal (if auto-approval is enabled)
107
-
108
- ### 2. Verify Deployment
109
-
110
- ```bash
111
- # Check deployment status
112
- npm run status
113
-
114
- # Verify on block explorer
115
- npm run verify
116
- ```
117
-
118
- ### 3. Upgrade Example
119
-
120
- ```bash
121
- # This adds UpgradeFacet and upgrades ExampleFacet1 to v1.0
122
- npm run upgrade
123
- ```
124
-
125
- ## Script Explanations
126
-
127
- ### deploy-script.ts
128
-
129
- ```typescript
130
- import { ethers } from 'hardhat';
131
- import { Diamond, DiamondDeployer, FileDeploymentRepository } from '@diamonds/core';
132
- import { OZDefenderDeploymentStrategy } from '@diamonds/strategies';
133
-
134
- async function main() {
135
- console.log('🚀 Starting Defender deployment...');
136
-
137
- // Load configuration
138
- const config = {
139
- diamondName: 'ExampleDiamond',
140
- networkName: 'sepolia',
141
- chainId: 11155111,
142
- deploymentsPath: './deployments',
143
- contractsPath: './contracts',
144
- callbacksPath: './callbacks',
145
- configFilePath: './diamond-config.json',
146
- deployedDiamondDataFilePath: './deployments/exampledianmond-sepolia-11155111.json'
147
- };
148
-
149
- // Create diamond instance
150
- const repository = new FileDeploymentRepository(config);
151
- const diamond = new Diamond(config, repository);
152
-
153
- // Setup provider and signer
154
- diamond.setProvider(ethers.provider);
155
- diamond.setSigner(await ethers.getSigners()[0]);
156
-
157
- // Create Defender strategy
158
- const strategy = new OZDefenderDeploymentStrategy(
159
- process.env.DEFENDER_API_KEY!,
160
- process.env.DEFENDER_API_SECRET!,
161
- process.env.DEFENDER_RELAYER_ADDRESS!,
162
- process.env.AUTO_APPROVE === 'true',
163
- process.env.DEFENDER_SAFE_ADDRESS!,
164
- 'Safe',
165
- true // verbose logging
166
- );
167
-
168
- // Execute deployment
169
- const deployer = new DiamondDeployer(diamond, strategy);
170
- await deployer.deployDiamond();
171
-
172
- console.log('✅ Deployment completed!');
173
-
174
- // Output deployment information
175
- const deployedData = diamond.getDeployedDiamondData();
176
- console.log('\n📊 Deployment Summary:');
177
- console.log(`Diamond Address: ${deployedData.DiamondAddress}`);
178
- console.log(`Deployer Address: ${deployedData.DeployerAddress}`);
179
- console.log('\n📋 Deployed Facets:');
180
-
181
- Object.entries(deployedData.DeployedFacets || {}).forEach(([name, facet]) => {
182
- console.log(` ${name}: ${facet.address} (v${facet.version})`);
183
- });
184
- }
185
-
186
- main()
187
- .then(() => process.exit(0))
188
- .catch((error) => {
189
- console.error('❌ Deployment failed:', error);
190
- process.exit(1);
191
- });
192
- ```
193
-
194
- ### upgrade-script.ts
195
-
196
- ```typescript
197
- import { ethers } from 'hardhat';
198
- import { Diamond, DiamondDeployer, FileDeploymentRepository } from '@diamonds/core';
199
- import { OZDefenderDeploymentStrategy } from '@diamonds/strategies';
200
- import * as fs from 'fs-extra';
201
-
202
- async function main() {
203
- console.log('♻️ Starting upgrade process...');
204
-
205
- // Load and update configuration
206
- const configPath = './diamond-config.json';
207
- const config = await fs.readJson(configPath);
208
-
209
- // Add new facet for upgrade
210
- config.protocolVersion = 1.0;
211
- config.facets['UpgradeFacet'] = {
212
- priority: 50,
213
- versions: {
214
- "1.0": {
215
- deployInit: "initialize()",
216
- callbacks: ["logUpgrade"]
217
- }
218
- }
219
- };
220
-
221
- // Upgrade existing facet
222
- config.facets['ExampleFacet1'].versions["1.0"] = {
223
- upgradeInit: "upgradeToV1()",
224
- callbacks: ["validateUpgrade"]
225
- };
226
-
227
- // Save updated configuration
228
- await fs.writeJson(configPath, config, { spaces: 2 });
229
-
230
- // Setup diamond with existing deployment data
231
- const diamondConfig = {
232
- diamondName: 'ExampleDiamond',
233
- networkName: 'sepolia',
234
- chainId: 11155111,
235
- deploymentsPath: './deployments',
236
- contractsPath: './contracts',
237
- callbacksPath: './callbacks',
238
- configFilePath: configPath,
239
- deployedDiamondDataFilePath: './deployments/exampledianmond-sepolia-11155111.json'
240
- };
241
-
242
- const repository = new FileDeploymentRepository(diamondConfig);
243
- const diamond = new Diamond(diamondConfig, repository);
244
-
245
- diamond.setProvider(ethers.provider);
246
- diamond.setSigner(await ethers.getSigners()[0]);
247
-
248
- // Create strategy and execute upgrade
249
- const strategy = new OZDefenderDeploymentStrategy(
250
- process.env.DEFENDER_API_KEY!,
251
- process.env.DEFENDER_API_SECRET!,
252
- process.env.DEFENDER_RELAYER_ADDRESS!,
253
- process.env.AUTO_APPROVE === 'true',
254
- process.env.DEFENDER_SAFE_ADDRESS!,
255
- 'Safe',
256
- true
257
- );
258
-
259
- const deployer = new DiamondDeployer(diamond, strategy);
260
- await deployer.deployDiamond(); // Automatically detects upgrade scenario
261
-
262
- console.log('✅ Upgrade completed!');
263
- }
264
-
265
- main()
266
- .then(() => process.exit(0))
267
- .catch((error) => {
268
- console.error('❌ Upgrade failed:', error);
269
- process.exit(1);
270
- });
271
- ```
272
-
273
- ## Callback Examples
274
-
275
- ### callbacks/logDeployment.ts
276
-
277
- ```typescript
278
- export async function logDeployment(args: any) {
279
- console.log('📝 Deployment callback executed');
280
- console.log('Diamond Address:', args.diamondAddress);
281
- console.log('Facet Address:', args.facetAddress);
282
- console.log('Timestamp:', new Date().toISOString());
283
- }
284
- ```
285
-
286
- ### callbacks/validateSetup.ts
287
-
288
- ```typescript
289
- import { ethers } from 'hardhat';
290
-
291
- export async function validateSetup(args: any) {
292
- console.log('🔍 Validating setup...');
293
-
294
- // Connect to deployed diamond
295
- const diamond = await ethers.getContractAt('ExampleFacet2', args.diamondAddress);
296
-
297
- // Validate initialization
298
- const isSetup = await diamond.isSetupComplete();
299
- if (!isSetup) {
300
- throw new Error('Setup validation failed');
301
- }
302
-
303
- console.log('✅ Setup validation passed');
304
- }
305
- ```
306
-
307
- ## Expected Output
308
-
309
- ### Successful Deployment
310
-
311
- ```bash
312
- 🚀 Starting Defender deployment...
313
-
314
- 🪓 Pre-deploy diamond tasks for ExampleDiamond from OZDefenderDeploymentStrategy...
315
- 📡 Submitted DiamondCutFacet deploy to Defender: defender-deploy-id-1
316
- ✅ Deployment succeeded for deploy-diamondcutfacet.
317
- 📡 Submitted Diamond deploy to Defender: defender-deploy-id-2
318
- ✅ Deployment succeeded for deploy-diamond.
319
-
320
- 🚀 Deploying facet: DiamondLoupeFacet to version 0
321
- 📡 Submitted deployment for facet DiamondLoupeFacet: defender-deploy-id-3
322
- ✅ Deployment succeeded for deploy-DiamondLoupeFacet.
323
-
324
- 🚀 Deploying facet: ExampleFacet1 to version 0
325
- 📡 Submitted deployment for facet ExampleFacet1: defender-deploy-id-4
326
- ✅ Deployment succeeded for deploy-ExampleFacet1.
327
-
328
- 🚀 Deploying facet: ExampleFacet2 to version 0
329
- 📡 Submitted deployment for facet ExampleFacet2: defender-deploy-id-5
330
- ✅ Deployment succeeded for deploy-ExampleFacet2.
331
-
332
- 🪓 Performing DiamondCut with 3 cut(s):
333
- - Add for facet DiamondLoupeFacet at 0x3456789012345678901234567890123456789012
334
- - Add for facet ExampleFacet1 at 0x4567890123456789012345678901234567890123
335
- - Add for facet ExampleFacet2 at 0x5678901234567890123456789012345678901234
336
-
337
- 📡 Defender Proposal created: https://defender.openzeppelin.com/proposal/test-proposal-123
338
- ⏳ Auto-approval enabled. Waiting for proposal to be ready for execution...
339
- ✅ Proposal executed successfully.
340
-
341
- 📝 Deployment callback executed
342
- 🔍 Validating setup...
343
- ✅ Setup validation passed
344
-
345
- ✅ Deployment completed!
346
-
347
- 📊 Deployment Summary:
348
- Diamond Address: 0x1234567890123456789012345678901234567890
349
- Deployer Address: 0x742d35Cc6634C0532925a3b8D50d97e7
350
-
351
- 📋 Deployed Facets:
352
- DiamondCutFacet: 0x2345678901234567890123456789012345678901 (v0)
353
- DiamondLoupeFacet: 0x3456789012345678901234567890123456789012 (v0)
354
- ExampleFacet1: 0x4567890123456789012345678901234567890123 (v0)
355
- ExampleFacet2: 0x5678901234567890123456789012345678901234 (v0)
356
- ```
357
-
358
- ## Troubleshooting
359
-
360
- ### Common Issues
361
-
362
- 1. **API Authentication Error**
363
-
364
- ```bash
365
- Error: Invalid API credentials
366
- ```
367
-
368
- **Solution**: Verify your `DEFENDER_API_KEY` and `DEFENDER_API_SECRET` in `.env`
369
-
370
- 2. **Insufficient Balance**
371
-
372
- ```bash
373
- Error: insufficient funds for gas
374
- ```
375
-
376
- **Solution**: Add testnet ETH to your deployer address
377
-
378
- 3. **Network Configuration**
379
-
380
- ```bash
381
- Error: could not detect network
382
- ```
383
-
384
- **Solution**: Verify your RPC URL and network settings
385
-
386
- 4. **Multi-sig Approval Required**
387
-
388
- ```bash
389
- Warning: Proposal awaiting approval
390
- ```
391
-
392
- **Solution**: Check Defender dashboard for pending proposals
393
-
394
- ### Debug Mode
395
-
396
- Enable verbose logging:
397
-
398
- ```bash
399
- DEBUG=diamonds:* npm run deploy:sepolia
400
- ```
401
-
402
- ## Next Steps
403
-
404
- 1. **Customize Facets**: Modify the example facets for your use case
405
- 2. **Add More Facets**: Extend the diamond with additional functionality
406
- 3. **Production Deployment**: Configure for mainnet deployment
407
- 4. **Monitoring**: Set up monitoring and alerting through Defender
408
- 5. **Automation**: Create automated deployment pipelines
409
-
410
- ## Resources
411
-
412
- - [OpenZeppelin Defender Documentation](https://docs.openzeppelin.com/defender/)
413
- - [ERC-2535 Diamond Standard](https://eips.ethereum.org/EIPS/eip-2535)
414
- - [Hardhat Documentation](https://hardhat.org/docs)
415
- - [Diamonds Module Documentation](../../docs/defender-integration.md)
package/test/README.md DELETED
@@ -1,136 +0,0 @@
1
- # Test Setup and Execution Guide
2
-
3
- This guide walks through setting up and running the test suite for the `diamonds` module.
4
-
5
- ## Prerequisites
6
-
7
- - Node.js (v14+)
8
- - Yarn or npm
9
-
10
- ## Installation
11
-
12
- 1. Clone the repository:
13
- ```bash
14
- git clone https://github.com/your-org/diamonds.git
15
- cd diamonds
16
- ```
17
-
18
- 2. Install dependencies:
19
- ```bash
20
- yarn install
21
- ```
22
-
23
- ## Test Configuration
24
-
25
- The test suite uses Hardhat for smart contract testing and includes mock implementations of:
26
-
27
- - Diamond contracts and facets
28
- - OpenZeppelin Defender API
29
- - File system repositories
30
-
31
- All test configuration is in `hardhat.config.ts`. The mock contracts are located in `test/mocks/contracts`.
32
-
33
- ## Running Tests
34
-
35
- ### All Tests
36
-
37
- ```bash
38
- npm test
39
- ```
40
-
41
- ### Unit Tests Only
42
-
43
- ```bash
44
- npm run test:unit
45
- ```
46
-
47
- ### Integration Tests Only
48
-
49
- ```bash
50
- npm run test:integration
51
- ```
52
-
53
- ### Test Coverage
54
-
55
- ```bash
56
- npm run test:coverage
57
- ```
58
-
59
- ## Test Structure
60
-
61
- - **Unit Tests**: Test individual components in isolation
62
- - Core classes (Diamond, DiamondDeployer, etc.)
63
- - Strategy implementations
64
- - Repository implementations
65
-
66
- - **Integration Tests**: Test end-to-end workflows
67
- - Local deployment
68
- - OZ Defender deployment
69
- - Facet upgrades
70
-
71
- ## Mock Contracts
72
-
73
- The test suite includes mock implementations of:
74
-
75
- - `MockDiamond.sol`: A simplified diamond contract
76
- - `MockDiamondCutFacet.sol`: Diamond cut facet
77
- - `MockDiamondLoupeFacet.sol`: Diamond loupe facet
78
- - `MockTestFacet.sol`: Test facet with various functions
79
-
80
- ## Test Helpers
81
-
82
- The `setup.ts` file provides helper functions for:
83
-
84
- - Setting up the test environment
85
- - Creating temporary configuration files
86
- - Deploying mock contracts
87
- - Cleaning up after tests
88
-
89
- ## Debugging Tests
90
-
91
- When tests fail, check:
92
-
93
- 1. Console output for error messages
94
- 2. Temporary files in `.tmp-test*` directories
95
- 3. Hardhat error traces
96
-
97
- You can add `console.log` statements in test files for debugging.
98
-
99
- ## Cleaning Up
100
-
101
- To clean up temporary test files:
102
-
103
- ```bash
104
- npm run clean
105
- ```
106
-
107
- ## Adding New Tests
108
-
109
- 1. Create a new test file in the appropriate directory
110
- 2. Import needed components and test helpers
111
- 3. Use the setup helper to initialize the environment
112
- 4. Write your tests using Mocha/Chai syntax
113
- 5. Clean up after tests using the cleanup helper
114
-
115
- ## Mocking External Services
116
-
117
- The OZ Defender tests use sinon to mock the API:
118
-
119
- ```typescript
120
- // Example mock setup
121
- mockDeployClient.deployContract.resolves({
122
- deploymentId: 'defender-deploy-id',
123
- status: 'pending'
124
- });
125
- ```
126
-
127
- ## Environment Variables
128
-
129
- Set these environment variables for local testing:
130
-
131
- ```
132
- DEFENDER_API_KEY=test-api-key
133
- DEFENDER_API_SECRET=test-api-secret
134
- DEFENDER_RELAYER_ADDRESS=0x1234...
135
- DEFENDER_SAFE_ADDRESS=0x5678...
136
- ```