Skip to content

Commit 0e24138

Browse files
authored
Merge branch 'LayerZero-Labs:main' into krak/deepwiki-json
2 parents c0a96a8 + ab9b083 commit 0e24138

File tree

247 files changed

+47699
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

247 files changed

+47699
-1
lines changed

.github/workflows/lint-build-test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
name: Lint, Build & Test
1616
runs-on: ubuntu-latest
1717
container:
18-
image: ghcr.io/layerzero-labs/devcon:1.1.9-bookworm
18+
image: ghcr.io/layerzero-labs/devcon:1.1.11-bookworm
1919
env:
2020
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
2121
GH_TOKEN: ${{ secrets.GH_TOKEN }}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# LayerZero EndpointV2 IOTA Contracts
Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
#!/bin/sh
2+
':'; // ; cat "$0" | node --input-type=module - $@ ; exit $?
3+
4+
/****
5+
* Usage:
6+
* ./build_and_test.mjs compile [contract_name] - to compile a specific contract, if no contract name is provided, all contracts will be compiled
7+
* ./build_and_test.mjs test [contract_name] - to test a specific contract, if no contract name is provided, all contracts will be tested
8+
*/
9+
import { fileURLToPath } from 'url';
10+
import { $, fs } from 'zx';
11+
import path from 'node:path';
12+
import { globSync } from 'glob';
13+
14+
let workdir = path.dirname(fileURLToPath(import.meta.url).replace('[eval1]', '')) + '/';
15+
const allModuleDir = {};
16+
17+
// Global variable to track current backups for emergency revert
18+
let currentBackups = null;
19+
20+
function applyTestToml(contractsDir) {
21+
const backupFiles = [];
22+
const testTomlFiles = globSync(contractsDir + '**/Move.test.toml');
23+
24+
if (testTomlFiles.length === 0) {
25+
return backupFiles;
26+
}
27+
28+
console.log('🔄 Applying Move.test.toml configurations...');
29+
30+
for (const testTomlFile of testTomlFiles) {
31+
try {
32+
const moveTomlFile = testTomlFile.replace('Move.test.toml', 'Move.toml');
33+
const backupFile = moveTomlFile + '.backup';
34+
35+
if (fs.existsSync(moveTomlFile)) {
36+
// Create backup file
37+
fs.copyFileSync(moveTomlFile, backupFile);
38+
backupFiles.push({ original: moveTomlFile, backup: backupFile });
39+
40+
// Replace with Move.test.toml content
41+
const testContent = fs.readFileSync(testTomlFile, 'utf8');
42+
fs.writeFileSync(moveTomlFile, testContent);
43+
44+
console.log(
45+
` ✓ Applied ${path.relative(contractsDir, testTomlFile)}${path.relative(contractsDir, moveTomlFile)}`
46+
);
47+
console.log(` ✓ Backup saved: ${path.relative(contractsDir, backupFile)}`);
48+
}
49+
} catch (error) {
50+
console.error(` ❌ Failed to apply ${testTomlFile}:`, error.message);
51+
}
52+
}
53+
54+
console.log(`✅ Applied ${backupFiles.length} Move.test.toml configurations`);
55+
return backupFiles;
56+
}
57+
58+
function revertToml(backupFiles, contractsDir) {
59+
console.log('🔄 Reverting Move.toml files back to original...');
60+
61+
for (const { original, backup } of backupFiles) {
62+
try {
63+
if (fs.existsSync(backup)) {
64+
// Restore from backup file
65+
fs.copyFileSync(backup, original);
66+
// Remove backup file
67+
fs.unlinkSync(backup);
68+
console.log(` ✓ Reverted ${path.relative(contractsDir, original)}`);
69+
}
70+
} catch (error) {
71+
console.error(` ❌ Failed to revert ${original}:`, error.message);
72+
}
73+
}
74+
75+
console.log(`✅ Reverted ${backupFiles.length} files to original Move.toml`);
76+
}
77+
78+
// Emergency revert function for when process is interrupted
79+
function emergencyRevert() {
80+
if (currentBackups && currentBackups.length > 0) {
81+
console.log('\n🚨 Process interrupted! Emergency reverting Move.toml files...');
82+
try {
83+
const contractsDir = path.dirname(fileURLToPath(import.meta.url)) + '/';
84+
revertToml(currentBackups, contractsDir);
85+
console.log('✅ Emergency revert completed successfully');
86+
} catch (error) {
87+
console.error('❌ Emergency revert failed:', error.message);
88+
console.error(
89+
'⚠️ WARNING: Some files may still have Move.test.toml content instead of original Move.toml!'
90+
);
91+
}
92+
}
93+
process.exit(1);
94+
}
95+
96+
// Set up signal handlers for graceful cleanup on abort
97+
process.on('SIGINT', emergencyRevert); // Ctrl+C
98+
process.on('SIGTERM', emergencyRevert); // Termination signal
99+
process.on('SIGHUP', emergencyRevert); // Hangup signal
100+
101+
function parseModule(moveFile) {
102+
const rawData = fs.readFileSync(moveFile, { recursive: true });
103+
const moveContent = rawData.toString();
104+
105+
// Extract module name from Move.toml
106+
const moduleNameMatch = moveContent.match(/name\s*=\s*"([^"]+)"/);
107+
if (!moduleNameMatch) {
108+
throw new Error(`Could not find module name in ${moveFile}`);
109+
}
110+
const moduleName = moduleNameMatch[1];
111+
112+
allModuleDir[moduleName] = {
113+
dir: path.dirname(moveFile),
114+
};
115+
return moduleName;
116+
}
117+
118+
async function compile(moduleName) {
119+
let workdir = allModuleDir[moduleName].dir;
120+
console.log(`Building ${moduleName} in ${workdir}`);
121+
try {
122+
await $({
123+
cwd: workdir,
124+
verbose: true,
125+
stdio: ['inherit', process.stdout, process.stderr],
126+
})`iota move build --skip-fetch-latest-git-deps`;
127+
} catch (e) {
128+
console.error(`Failed to build ${moduleName} in ${workdir}`);
129+
process.exit(1);
130+
}
131+
}
132+
133+
async function test(moduleName) {
134+
const moduleWorkdir = allModuleDir[moduleName].dir;
135+
console.log(`Testing ${moduleName} in ${moduleWorkdir}`);
136+
137+
// Apply Move.test.toml configurations before running tests
138+
// const contractsDir = path.dirname(fileURLToPath(import.meta.url)) + '/';
139+
// const backupFiles = applyTestToml(contractsDir);
140+
141+
// Store backups globally for emergency revert
142+
// currentBackups = backupFiles;
143+
144+
try {
145+
await $({
146+
cwd: moduleWorkdir,
147+
verbose: true,
148+
stdio: ['inherit', process.stdout, process.stderr],
149+
})`iota move test --skip-fetch-latest-git-deps -d`;
150+
151+
console.log(`${moduleName} tests passed`);
152+
} catch (error) {
153+
console.log(`${moduleName} tests failed`);
154+
throw error;
155+
} finally {
156+
// Always revert Move.toml files back, even if tests fail
157+
// revertToml(backupFiles, contractsDir);
158+
// Clear global backups after successful revert
159+
// currentBackups = null;
160+
}
161+
}
162+
163+
const args = process.argv.slice(2);
164+
if (args.length === 0) {
165+
throw new Error("please provide a task type: 'test' or 'compile'");
166+
}
167+
const taskType = args[0];
168+
const moduleNames = args[1] !== undefined ? args[1].split(',') : [];
169+
170+
async function main() {
171+
// workdir already points to the contracts directory
172+
let contracts = globSync(workdir + '**/Move.toml');
173+
174+
const modules = new Set();
175+
for (const contract of contracts) {
176+
const moduleName = parseModule(contract);
177+
if (args.length === 2) {
178+
// Flexible matching: handle kebab-case vs camelCase
179+
const normalizeModuleName = (name) => name.toLowerCase().replace(/[-_]/g, '');
180+
const normalizedModuleName = normalizeModuleName(moduleName);
181+
182+
if (moduleNames.some((name) => normalizeModuleName(name) === normalizedModuleName)) {
183+
modules.add(moduleName);
184+
}
185+
} else {
186+
modules.add(moduleName);
187+
}
188+
}
189+
190+
console.time(taskType);
191+
const compiles = [];
192+
console.log(`modules: ${Array.from(modules).join(', ')}`);
193+
194+
for (const module of modules) {
195+
if (taskType === 'test') {
196+
await test(module);
197+
} else {
198+
compiles.push(compile(module));
199+
}
200+
}
201+
202+
await Promise.all(compiles);
203+
console.timeEnd(taskType);
204+
}
205+
206+
(async () => {
207+
await main();
208+
})();

0 commit comments

Comments
 (0)