Skip to content

Commit 8073a52

Browse files
authored
fix(contracts): optimize test fixture deployment speed (#697)
Signed-off-by: Miguel_LZPF <miguel.carpena@io.builders> Signed-off-by: Axel-IoBuilders <108282711+Axel-IoBuilders@users.noreply.github.com>
1 parent 3249a59 commit 8073a52

File tree

21 files changed

+331
-81
lines changed

21 files changed

+331
-81
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@hashgraph/asset-tokenization-contracts": patch
3+
---
4+
5+
- Optimize test fixture deployment speed (96% improvement). Improved contract test performance from 47 seconds to 2 seconds per fixture by fixing inefficient batch processing and removing unnecessary network delays on instant-mining networks (Hardhat/local).
6+
- Remove duplicated contract interface fragments in test files (ERC3643, clearing, protectedPartitions tests).

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
"clean:full": "npm run clean:workspaces && npm run clean:deps:full && npm run clean:root && echo '\\n✅ Complete cleanup finished — workspaces, dependencies, and root junk removed'",
3737
"lint:staged:js": "eslint --cache",
3838
"lint:staged:sol": "solhint --config packages/ats/contracts/.solhint.json",
39-
"format:staged": "prettier --check",
39+
"format:staged": "prettier --write",
40+
"format:staged:check": "prettier --check",
4041
"pre-commit": "lint-staged",
4142
"commitlint": "commitlint --edit",
4243
"prepare": "husky",

packages/ats/contracts/scripts/cli/hardhat.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ async function main() {
8080
console.log(` Equity Config Version: ${output.configurations.equity.version}`);
8181
console.log(` Bond Config Version: ${output.configurations.bond.version}`);
8282
console.log(` Total Contracts: ${output.summary.totalContracts}`);
83-
console.log(` Deployment Time: ${output.summary.deploymentTime}ms`);
8483

8584
process.exit(0);
8685
} catch (error) {

packages/ats/contracts/scripts/cli/standalone.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ async function main() {
9090
console.log(` Equity Config Version: ${output.configurations.equity.version}`);
9191
console.log(` Bond Config Version: ${output.configurations.bond.version}`);
9292
console.log(` Total Contracts: ${output.summary.totalContracts}`);
93-
console.log(` Deployment Time: ${output.summary.deploymentTime}ms`);
9493

9594
process.exit(0);
9695
} catch (error) {

packages/ats/contracts/scripts/domain/bond/createConfiguration.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ const BOND_FACETS = [
105105
* @param blrContract - BusinessLogicResolver contract instance
106106
* @param facetAddresses - Map of facet names to their deployed addresses
107107
* @param useTimeTravel - Whether to use TimeTravel variants (default: false)
108+
* @param partialBatchDeploy - Whether this is a partial batch deployment (default: false)
109+
* @param batchSize - Number of facets per batch (default: DEFAULT_BATCH_SIZE)
110+
* @param confirmations - Number of confirmations to wait for (default: 0 for test environments)
108111
* @returns Promise resolving to operation result
109112
*
110113
* @example
@@ -122,7 +125,10 @@ const BOND_FACETS = [
122125
* 'BondUSAFacet': '0xdef...',
123126
* // ... more facets
124127
* },
125-
* false
128+
* false,
129+
* false,
130+
* 15,
131+
* 0
126132
* )
127133
*
128134
* if (result.success) {
@@ -139,6 +145,7 @@ export async function createBondConfiguration(
139145
useTimeTravel: boolean = false,
140146
partialBatchDeploy: boolean = false,
141147
batchSize: number = DEFAULT_BATCH_SIZE,
148+
confirmations: number = 0,
142149
): Promise<OperationResult<ConfigurationData, ConfigurationError>> {
143150
// Get facet names based on time travel mode
144151
// Include TimeTravelFacet when useTimeTravel=true to provide time manipulation functions
@@ -169,5 +176,6 @@ export async function createBondConfiguration(
169176
facets,
170177
partialBatchDeploy,
171178
batchSize,
179+
confirmations,
172180
});
173181
}

packages/ats/contracts/scripts/domain/equity/createConfiguration.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ const EQUITY_FACETS = [
104104
* @param blrContract - BusinessLogicResolver contract instance
105105
* @param facetAddresses - Map of facet names to their deployed addresses
106106
* @param useTimeTravel - Whether to use TimeTravel variants (default: false)
107+
* @param partialBatchDeploy - Whether this is a partial batch deployment (default: false)
108+
* @param batchSize - Number of facets per batch (default: DEFAULT_BATCH_SIZE)
109+
* @param confirmations - Number of confirmations to wait for (default: 0 for test environments)
107110
* @returns Promise resolving to operation result
108111
*
109112
* @example
@@ -122,7 +125,10 @@ const EQUITY_FACETS = [
122125
* 'EquityUSAFacet': '0x123...',
123126
* // ... more facets
124127
* },
125-
* false
128+
* false,
129+
* false,
130+
* 15,
131+
* 0
126132
* )
127133
*
128134
* if (result.success) {
@@ -139,6 +145,7 @@ export async function createEquityConfiguration(
139145
useTimeTravel: boolean = false,
140146
partialBatchDeploy: boolean = false,
141147
batchSize: number = DEFAULT_BATCH_SIZE,
148+
confirmations: number = 0,
142149
): Promise<OperationResult<ConfigurationData, ConfigurationError>> {
143150
// Get facet names based on time travel mode
144151
// Include TimeTravelFacet when useTimeTravel=true to provide time manipulation functions
@@ -169,5 +176,6 @@ export async function createEquityConfiguration(
169176
facets,
170177
partialBatchDeploy,
171178
batchSize,
179+
confirmations,
172180
});
173181
}

packages/ats/contracts/scripts/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export type {
7070
ResumeOptions,
7171
} from "./infrastructure/types/checkpoint";
7272
export { CheckpointManager } from "./infrastructure/checkpoint/CheckpointManager";
73+
export { NullCheckpointManager } from "./infrastructure/checkpoint/NullCheckpointManager";
7374
export type { CreateCheckpointParams } from "./infrastructure/checkpoint/CheckpointManager";
7475
export {
7576
checkpointToDeploymentOutput,
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
3+
/**
4+
* Null checkpoint manager for test environments.
5+
*
6+
* Provides no-op implementations of checkpoint operations to eliminate
7+
* filesystem I/O overhead during test execution. All checkpoint state is
8+
* maintained in memory only.
9+
*
10+
* Use this manager when `ignoreCheckpoint: true` is specified in deployment
11+
* options to prevent unnecessary disk writes and improve test performance.
12+
*
13+
* @module infrastructure/checkpoint/NullCheckpointManager
14+
*/
15+
16+
import type { DeploymentCheckpoint, CheckpointStatus } from "../types/checkpoint";
17+
import { CheckpointManager } from "./CheckpointManager";
18+
19+
/**
20+
* No-op checkpoint manager for test environments.
21+
*
22+
* Extends CheckpointManager but overrides all filesystem operations to be
23+
* no-ops. Checkpoints are created in memory but never persisted to disk.
24+
*
25+
* **Performance Benefits:**
26+
* - Eliminates filesystem I/O during test execution
27+
* - Prevents checkpoint file accumulation
28+
* - Avoids race conditions in parallel test execution
29+
* - Reduces test initialization overhead by ~500-1000ms per test
30+
*
31+
* @example
32+
* ```typescript
33+
* // In deployment workflow
34+
* const checkpointManager = ignoreCheckpoint
35+
* ? new NullCheckpointManager()
36+
* : new CheckpointManager(checkpointDir);
37+
*
38+
* // Checkpoint operations work but don't touch filesystem
39+
* const checkpoint = checkpointManager.createCheckpoint({ ... });
40+
* await checkpointManager.saveCheckpoint(checkpoint); // No-op
41+
* ```
42+
*/
43+
export class NullCheckpointManager extends CheckpointManager {
44+
/**
45+
* Create a null checkpoint manager.
46+
*
47+
* Directory parameter is accepted for API compatibility but ignored.
48+
*/
49+
constructor(checkpointsDir?: string) {
50+
super(checkpointsDir);
51+
}
52+
53+
/**
54+
* No-op save operation.
55+
*
56+
* Checkpoint is not written to disk. This eliminates filesystem I/O
57+
* overhead during test execution while maintaining API compatibility.
58+
*
59+
* @param checkpoint - Checkpoint to save (ignored)
60+
*/
61+
async saveCheckpoint(checkpoint: DeploymentCheckpoint): Promise<void> {
62+
// No-op - don't write to disk
63+
// Update lastUpdate for consistency with in-memory state
64+
checkpoint.lastUpdate = new Date().toISOString();
65+
}
66+
67+
/**
68+
* Always returns null (no checkpoints exist on disk).
69+
*
70+
* @param _checkpointId - Checkpoint ID to load (ignored)
71+
* @returns null (checkpoints are never persisted)
72+
*/
73+
async loadCheckpoint(_checkpointId: string): Promise<DeploymentCheckpoint | null> {
74+
return null; // No checkpoints exist
75+
}
76+
77+
/**
78+
* Always returns empty array (no checkpoints exist on disk).
79+
*
80+
* @param _network - Network name (ignored)
81+
* @param _status - Status filter (ignored)
82+
* @returns Empty array (no checkpoints to find)
83+
*/
84+
async findCheckpoints(_network: string, _status?: CheckpointStatus): Promise<DeploymentCheckpoint[]> {
85+
return []; // No checkpoints exist
86+
}
87+
88+
/**
89+
* No-op delete operation.
90+
*
91+
* @param _checkpointId - Checkpoint ID to delete (ignored)
92+
*/
93+
async deleteCheckpoint(_checkpointId: string): Promise<void> {
94+
// No-op - nothing to delete
95+
}
96+
97+
/**
98+
* No-op cleanup operation.
99+
*
100+
* @param _network - Network name (ignored)
101+
* @param _daysToKeep - Days to keep (ignored)
102+
* @returns 0 (no checkpoints to clean up)
103+
*/
104+
async cleanupOldCheckpoints(_network: string, _daysToKeep?: number): Promise<number> {
105+
return 0; // No checkpoints to clean up
106+
}
107+
}

packages/ats/contracts/scripts/infrastructure/checkpoint/utils.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ export function checkpointToDeploymentOutput(checkpoint: DeploymentCheckpoint):
6060
// Calculate deployment time
6161
const endTime = new Date(checkpoint.lastUpdate).getTime();
6262
const start = new Date(startTime).getTime();
63-
const deploymentTime = endTime - start;
6463

6564
// Calculate total gas used (sum from all deployments)
6665
let totalGasUsed = 0;
@@ -114,7 +113,7 @@ export function checkpointToDeploymentOutput(checkpoint: DeploymentCheckpoint):
114113
totalContracts: 3 + steps.facets.size, // ProxyAdmin + BLR + Factory + facets
115114
totalFacets: steps.facets.size,
116115
totalConfigurations: 2,
117-
deploymentTime,
116+
deploymentTime: endTime - start,
118117
gasUsed: totalGasUsed.toString(),
119118
success: checkpoint.status === "completed",
120119
},

packages/ats/contracts/scripts/infrastructure/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export {
9999

100100
export { getNetworkConfig, getAllNetworks } from "./config";
101101

102-
export { getDeploymentConfig, isLocalNetwork, DEPLOYMENT_CONFIGS } from "./networkConfig";
102+
export { getDeploymentConfig, isLocalNetwork, isInstantMiningNetwork, DEPLOYMENT_CONFIGS } from "./networkConfig";
103103
export type { DeploymentConfig } from "./networkConfig";
104104

105105
// ============================================================================
@@ -207,6 +207,7 @@ export { getSelector } from "./utils/selector";
207207
// ============================================================================
208208

209209
export { CheckpointManager } from "./checkpoint/CheckpointManager";
210+
export { NullCheckpointManager } from "./checkpoint/NullCheckpointManager";
210211
export type { CreateCheckpointParams } from "./checkpoint/CheckpointManager";
211212

212213
export {

0 commit comments

Comments
 (0)