jaelis-node 1.3.2 → 1.4.1
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.
- package/README.md +62 -1
- package/lib/JAELIS-VM/lib/adapters/evm-adapter.js +454 -0
- package/lib/JAELIS-VM/lib/adapters/index.js +411 -0
- package/lib/JAELIS-VM/lib/adapters/svm-adapter.js +457 -0
- package/lib/JAELIS-VM/lib/compiler/jir-compiler.js +1097 -0
- package/lib/JAELIS-VM/lib/execution/engine.js +1183 -0
- package/lib/JAELIS-VM/lib/index.js +440 -0
- package/lib/JAELIS-VM/lib/integration/jaelis-integration.js +543 -0
- package/lib/JAELIS-VM/lib/serialization/serializer.js +819 -0
- package/lib/JAELIS-VM/lib/state/state-manager.js +1116 -0
- package/lib/JAELIS-VM/lib/translator/bytecode-translator.js +1222 -0
- package/lib/JAELIS-VM/lib/unified/cross-chain-state.js +836 -0
- package/lib/JAELIS-VM/lib/unified/dynamic-contracts.js +1127 -0
- package/lib/JAELIS-VM/lib/unified/index.js +378 -0
- package/lib/JAELIS-VM/lib/unified/jaelis-abi.js +1150 -0
- package/lib/JAELIS-VM/lib/unified/unified-compiler.js +1350 -0
- package/lib/JAELIS-VM/node_modules/.bin/download-cbor-prebuilds +12 -0
- package/lib/JAELIS-VM/node_modules/.bin/download-cbor-prebuilds.cmd +17 -0
- package/lib/JAELIS-VM/node_modules/.bin/download-cbor-prebuilds.ps1 +28 -0
- package/lib/JAELIS-VM/node_modules/.bin/download-msgpackr-prebuilds +12 -0
- package/lib/JAELIS-VM/node_modules/.bin/download-msgpackr-prebuilds.cmd +17 -0
- package/lib/JAELIS-VM/node_modules/.bin/download-msgpackr-prebuilds.ps1 +28 -0
- package/lib/JAELIS-VM/node_modules/.bin/node-gyp-build-optional-packages +12 -0
- package/lib/JAELIS-VM/node_modules/.bin/node-gyp-build-optional-packages-optional +12 -0
- package/lib/JAELIS-VM/node_modules/.bin/node-gyp-build-optional-packages-optional.cmd +17 -0
- package/lib/JAELIS-VM/node_modules/.bin/node-gyp-build-optional-packages-optional.ps1 +28 -0
- package/lib/JAELIS-VM/node_modules/.bin/node-gyp-build-optional-packages-test +12 -0
- package/lib/JAELIS-VM/node_modules/.bin/node-gyp-build-optional-packages-test.cmd +17 -0
- package/lib/JAELIS-VM/node_modules/.bin/node-gyp-build-optional-packages-test.ps1 +28 -0
- package/lib/JAELIS-VM/node_modules/.bin/node-gyp-build-optional-packages.cmd +17 -0
- package/lib/JAELIS-VM/node_modules/.bin/node-gyp-build-optional-packages.ps1 +28 -0
- package/lib/JAELIS-VM/node_modules/.package-lock.json +127 -0
- package/lib/JAELIS-VM/node_modules/@cbor-extract/cbor-extract-win32-x64/README.md +1 -0
- package/lib/JAELIS-VM/node_modules/@cbor-extract/cbor-extract-win32-x64/index.js +0 -0
- package/lib/JAELIS-VM/node_modules/@cbor-extract/cbor-extract-win32-x64/node.abi115.node +0 -0
- package/lib/JAELIS-VM/node_modules/@cbor-extract/cbor-extract-win32-x64/node.napi.node +0 -0
- package/lib/JAELIS-VM/node_modules/@cbor-extract/cbor-extract-win32-x64/package.json +17 -0
- package/lib/JAELIS-VM/node_modules/@msgpackr-extract/msgpackr-extract-win32-x64/README.md +1 -0
- package/lib/JAELIS-VM/node_modules/@msgpackr-extract/msgpackr-extract-win32-x64/index.js +0 -0
- package/lib/JAELIS-VM/node_modules/@msgpackr-extract/msgpackr-extract-win32-x64/node.abi115.node +0 -0
- package/lib/JAELIS-VM/node_modules/@msgpackr-extract/msgpackr-extract-win32-x64/node.napi.node +0 -0
- package/lib/JAELIS-VM/node_modules/@msgpackr-extract/msgpackr-extract-win32-x64/package.json +17 -0
- package/lib/JAELIS-VM/node_modules/cbor-extract/LICENSE +21 -0
- package/lib/JAELIS-VM/node_modules/cbor-extract/README.md +5 -0
- package/lib/JAELIS-VM/node_modules/cbor-extract/bin/download-prebuilds.js +11 -0
- package/lib/JAELIS-VM/node_modules/cbor-extract/binding.gyp +60 -0
- package/lib/JAELIS-VM/node_modules/cbor-extract/index.js +1 -0
- package/lib/JAELIS-VM/node_modules/cbor-extract/package.json +50 -0
- package/lib/JAELIS-VM/node_modules/cbor-extract/src/extract.cpp +198 -0
- package/lib/JAELIS-VM/node_modules/cbor-x/LICENSE +21 -0
- package/lib/JAELIS-VM/node_modules/cbor-x/README.md +380 -0
- package/lib/JAELIS-VM/node_modules/cbor-x/SECURITY.md +11 -0
- package/lib/JAELIS-VM/node_modules/cbor-x/benchmark.md +73 -0
- package/lib/JAELIS-VM/node_modules/cbor-x/browser.js +11 -0
- package/lib/JAELIS-VM/node_modules/cbor-x/decode.d.ts +2 -0
- package/lib/JAELIS-VM/node_modules/cbor-x/decode.js +1300 -0
- package/lib/JAELIS-VM/node_modules/cbor-x/dist/decode-no-eval.cjs +1244 -0
- package/lib/JAELIS-VM/node_modules/cbor-x/dist/decode-no-eval.cjs.map +1 -0
- package/lib/JAELIS-VM/node_modules/cbor-x/dist/index-no-eval.cjs +2509 -0
- package/lib/JAELIS-VM/node_modules/cbor-x/dist/index-no-eval.cjs.map +1 -0
- package/lib/JAELIS-VM/node_modules/cbor-x/dist/index-no-eval.min.js +2 -0
- package/lib/JAELIS-VM/node_modules/cbor-x/dist/index-no-eval.min.js.map +1 -0
- package/lib/JAELIS-VM/node_modules/cbor-x/dist/index.js +2508 -0
- package/lib/JAELIS-VM/node_modules/cbor-x/dist/index.js.map +1 -0
- package/lib/JAELIS-VM/node_modules/cbor-x/dist/index.min.js +2 -0
- package/lib/JAELIS-VM/node_modules/cbor-x/dist/index.min.js.map +1 -0
- package/lib/JAELIS-VM/node_modules/cbor-x/dist/node.cjs +2629 -0
- package/lib/JAELIS-VM/node_modules/cbor-x/dist/node.cjs.map +1 -0
- package/lib/JAELIS-VM/node_modules/cbor-x/dist/test.js +3343 -0
- package/lib/JAELIS-VM/node_modules/cbor-x/dist/test.js.map +1 -0
- package/lib/JAELIS-VM/node_modules/cbor-x/encode.d.ts +1 -0
- package/lib/JAELIS-VM/node_modules/cbor-x/encode.js +1231 -0
- package/lib/JAELIS-VM/node_modules/cbor-x/index.d.ts +79 -0
- package/lib/JAELIS-VM/node_modules/cbor-x/index.js +3 -0
- package/lib/JAELIS-VM/node_modules/cbor-x/iterators.js +85 -0
- package/lib/JAELIS-VM/node_modules/cbor-x/node-index.js +24 -0
- package/lib/JAELIS-VM/node_modules/cbor-x/package.json +94 -0
- package/lib/JAELIS-VM/node_modules/cbor-x/rollup.config.js +88 -0
- package/lib/JAELIS-VM/node_modules/cbor-x/stream.js +61 -0
- package/lib/JAELIS-VM/node_modules/cbor-x/webpack.config.js +19 -0
- package/lib/JAELIS-VM/node_modules/detect-libc/LICENSE +201 -0
- package/lib/JAELIS-VM/node_modules/detect-libc/README.md +163 -0
- package/lib/JAELIS-VM/node_modules/detect-libc/index.d.ts +14 -0
- package/lib/JAELIS-VM/node_modules/detect-libc/lib/detect-libc.js +313 -0
- package/lib/JAELIS-VM/node_modules/detect-libc/lib/elf.js +39 -0
- package/lib/JAELIS-VM/node_modules/detect-libc/lib/filesystem.js +51 -0
- package/lib/JAELIS-VM/node_modules/detect-libc/lib/process.js +24 -0
- package/lib/JAELIS-VM/node_modules/detect-libc/package.json +44 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/LICENSE +21 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/README.md +372 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/SECURITY.md +11 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/benchmark.md +67 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/dist/index-no-eval.cjs +2407 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/dist/index-no-eval.cjs.map +1 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/dist/index-no-eval.min.js +2 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/dist/index-no-eval.min.js.map +1 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/dist/index.js +2406 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/dist/index.js.map +1 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/dist/index.min.js +2 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/dist/index.min.js.map +1 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/dist/node.cjs +3320 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/dist/node.cjs.map +1 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/dist/test.js +4540 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/dist/test.js.map +1 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/dist/unpack-no-eval.cjs +1250 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/dist/unpack-no-eval.cjs.map +1 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/index.d.cts +91 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/index.d.ts +91 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/index.js +5 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/iterators.js +87 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/node-index.js +25 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/pack.d.cts +1 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/pack.d.ts +1 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/pack.js +1141 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/package.json +104 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/rollup.config.js +88 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/stream.js +57 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/struct.js +815 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/test-worker.js +3 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/unpack.d.cts +2 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/unpack.d.ts +2 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/unpack.js +1221 -0
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/LICENSE +21 -0
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/README.md +5 -0
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/bin/download-prebuilds.js +13 -0
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/binding.gyp +63 -0
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/index.js +1 -0
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/.bin/node-gyp-build-optional-packages +12 -0
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/.bin/node-gyp-build-optional-packages-optional +12 -0
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/.bin/node-gyp-build-optional-packages-optional.cmd +17 -0
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/.bin/node-gyp-build-optional-packages-optional.ps1 +28 -0
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/.bin/node-gyp-build-optional-packages-test +12 -0
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/.bin/node-gyp-build-optional-packages-test.cmd +17 -0
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/.bin/node-gyp-build-optional-packages-test.ps1 +28 -0
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/.bin/node-gyp-build-optional-packages.cmd +17 -0
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/.bin/node-gyp-build-optional-packages.ps1 +28 -0
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/node-gyp-build-optional-packages/LICENSE +21 -0
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/node-gyp-build-optional-packages/README.md +58 -0
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/node-gyp-build-optional-packages/bin.js +82 -0
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/node-gyp-build-optional-packages/build-test.js +19 -0
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/node-gyp-build-optional-packages/index.js +6 -0
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/node-gyp-build-optional-packages/node-gyp-build.js +236 -0
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/node-gyp-build-optional-packages/optional.js +7 -0
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/node-gyp-build-optional-packages/package.json +32 -0
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/package.json +50 -0
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/src/extract.cpp +274 -0
- package/lib/JAELIS-VM/node_modules/node-gyp-build-optional-packages/LICENSE +21 -0
- package/lib/JAELIS-VM/node_modules/node-gyp-build-optional-packages/README.md +58 -0
- package/lib/JAELIS-VM/node_modules/node-gyp-build-optional-packages/bin.js +77 -0
- package/lib/JAELIS-VM/node_modules/node-gyp-build-optional-packages/build-test.js +19 -0
- package/lib/JAELIS-VM/node_modules/node-gyp-build-optional-packages/index.js +224 -0
- package/lib/JAELIS-VM/node_modules/node-gyp-build-optional-packages/optional.js +7 -0
- package/lib/JAELIS-VM/node_modules/node-gyp-build-optional-packages/package.json +32 -0
- package/lib/JAELIS-VM/package-lock.json +284 -0
- package/lib/JAELIS-VM/package.json +38 -0
- package/lib/JAELIS-VM/test/comprehensive.test.js +267 -0
- package/lib/JAELIS-VM/test/cross-chain-test.js +470 -0
- package/lib/JAELIS-VM/test/unified-vm-test.js +459 -0
- package/lib/JAELIS-VM/test/unified.test.js +166 -0
- package/lib/JAELIS-VM/test/vm.test.js +599 -0
- package/lib/index.js +240 -4
- package/package.json +2 -2
|
@@ -0,0 +1,470 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JAELIS CROSS-CHAIN STATE - Integration Test Suite
|
|
3
|
+
*
|
|
4
|
+
* Tests all cross-chain settlement features:
|
|
5
|
+
* - Chain-ID namespaced storage slots
|
|
6
|
+
* - Light client verification
|
|
7
|
+
* - Cross-chain state settlement
|
|
8
|
+
* - State diff detection
|
|
9
|
+
* - Cross-chain opcodes
|
|
10
|
+
*
|
|
11
|
+
* Run: node test/cross-chain-test.js
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const {
|
|
15
|
+
UnifiedJaelisVM,
|
|
16
|
+
CrossChainStateStore,
|
|
17
|
+
CrossChainSettlementManager,
|
|
18
|
+
EVMLightClient,
|
|
19
|
+
SVMLightClient,
|
|
20
|
+
CHAIN_REGISTRY,
|
|
21
|
+
CROSS_CHAIN_OPCODES
|
|
22
|
+
} = require('../lib/unified');
|
|
23
|
+
|
|
24
|
+
console.log('═══════════════════════════════════════════════════════════════');
|
|
25
|
+
console.log(' JAELIS CROSS-CHAIN STATE - INTEGRATION TESTS');
|
|
26
|
+
console.log('═══════════════════════════════════════════════════════════════');
|
|
27
|
+
|
|
28
|
+
let passed = 0;
|
|
29
|
+
let failed = 0;
|
|
30
|
+
|
|
31
|
+
function test(name, fn) {
|
|
32
|
+
try {
|
|
33
|
+
fn();
|
|
34
|
+
console.log(`✓ ${name}`);
|
|
35
|
+
passed++;
|
|
36
|
+
} catch (error) {
|
|
37
|
+
console.log(`✗ ${name}`);
|
|
38
|
+
console.log(` Error: ${error.message}`);
|
|
39
|
+
failed++;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async function asyncTest(name, fn) {
|
|
44
|
+
try {
|
|
45
|
+
await fn();
|
|
46
|
+
console.log(`✓ ${name}`);
|
|
47
|
+
passed++;
|
|
48
|
+
} catch (error) {
|
|
49
|
+
console.log(`✗ ${name}`);
|
|
50
|
+
console.log(` Error: ${error.message}`);
|
|
51
|
+
failed++;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function assert(condition, message) {
|
|
56
|
+
if (!condition) {
|
|
57
|
+
throw new Error(message || 'Assertion failed');
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// ═══════════════════════════════════════════════════════════════
|
|
62
|
+
// TEST 1: CHAIN REGISTRY
|
|
63
|
+
// ═══════════════════════════════════════════════════════════════
|
|
64
|
+
|
|
65
|
+
console.log('\n--- Chain Registry Tests ---');
|
|
66
|
+
|
|
67
|
+
test('ChainRegistry: JAELIS Testnet defined (LIVE)', () => {
|
|
68
|
+
assert(CHAIN_REGISTRY.JAELIS_TESTNET, 'JAELIS_TESTNET should be defined');
|
|
69
|
+
assert(CHAIN_REGISTRY.JAELIS_TESTNET.id === 4545, `Expected 4545, got ${CHAIN_REGISTRY.JAELIS_TESTNET.id}`);
|
|
70
|
+
assert(CHAIN_REGISTRY.JAELIS_TESTNET.type === 'native', 'JAELIS should be native type');
|
|
71
|
+
assert(CHAIN_REGISTRY.JAELIS_TESTNET.status === 'live', 'JAELIS Testnet should be live');
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test('ChainRegistry: JAELIS Mainnet defined (upcoming)', () => {
|
|
75
|
+
assert(CHAIN_REGISTRY.JAELIS_MAINNET, 'JAELIS_MAINNET should be defined');
|
|
76
|
+
assert(CHAIN_REGISTRY.JAELIS_MAINNET.id === 4547, `Expected 4547, got ${CHAIN_REGISTRY.JAELIS_MAINNET.id}`);
|
|
77
|
+
assert(CHAIN_REGISTRY.JAELIS_MAINNET.status === 'upcoming', 'JAELIS Mainnet should be upcoming');
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test('ChainRegistry: Ethereum mainnet defined', () => {
|
|
81
|
+
assert(CHAIN_REGISTRY.ETH_MAINNET, 'ETH_MAINNET should be defined');
|
|
82
|
+
assert(CHAIN_REGISTRY.ETH_MAINNET.id === 1, `Expected 1, got ${CHAIN_REGISTRY.ETH_MAINNET.id}`);
|
|
83
|
+
assert(CHAIN_REGISTRY.ETH_MAINNET.type === 'evm', 'ETH should be EVM type');
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test('ChainRegistry: Solana defined', () => {
|
|
87
|
+
assert(CHAIN_REGISTRY.SOLANA_MAINNET, 'SOLANA_MAINNET should be defined');
|
|
88
|
+
assert(CHAIN_REGISTRY.SOLANA_MAINNET.id === 101, `Expected 101, got ${CHAIN_REGISTRY.SOLANA_MAINNET.id}`);
|
|
89
|
+
assert(CHAIN_REGISTRY.SOLANA_MAINNET.type === 'svm', 'Solana should be SVM type');
|
|
90
|
+
assert(CHAIN_REGISTRY.SOLANA_MAINNET.cluster === 'mainnet-beta', 'Should have correct cluster');
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test('ChainRegistry: All major chains present', () => {
|
|
94
|
+
const requiredChains = ['JAELIS_TESTNET', 'JAELIS_MAINNET', 'ETH_MAINNET', 'POLYGON', 'ARBITRUM_ONE', 'SOLANA_MAINNET', 'APTOS_MAINNET', 'TON_MAINNET'];
|
|
95
|
+
for (const chain of requiredChains) {
|
|
96
|
+
assert(CHAIN_REGISTRY[chain], `${chain} should be defined`);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
// ═══════════════════════════════════════════════════════════════
|
|
101
|
+
// TEST 2: CHAIN-ID NAMESPACED STORAGE SLOTS
|
|
102
|
+
// ═══════════════════════════════════════════════════════════════
|
|
103
|
+
|
|
104
|
+
console.log('\n--- Storage Slot Computation Tests ---');
|
|
105
|
+
|
|
106
|
+
test('StorageSlot: Same contract, different chains = different slots', () => {
|
|
107
|
+
const store = new CrossChainStateStore();
|
|
108
|
+
|
|
109
|
+
const contractAddr = '0x1234567890abcdef1234567890abcdef12345678';
|
|
110
|
+
const varName = 'balances';
|
|
111
|
+
|
|
112
|
+
const ethSlot = store.computeSlot(1, contractAddr, varName); // Ethereum (chain ID 1)
|
|
113
|
+
const jaelisSlot = store.computeSlot(4545, contractAddr, varName); // JAELIS Testnet (chain ID 4545)
|
|
114
|
+
const solSlot = store.computeSlot(101, contractAddr, varName); // Solana (chain ID 101)
|
|
115
|
+
|
|
116
|
+
assert(!ethSlot.equals(jaelisSlot), 'ETH and JAELIS slots should be different');
|
|
117
|
+
assert(!ethSlot.equals(solSlot), 'ETH and SOL slots should be different');
|
|
118
|
+
assert(!jaelisSlot.equals(solSlot), 'JAELIS and SOL slots should be different');
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
test('StorageSlot: Same chain, same contract, different vars = different slots', () => {
|
|
122
|
+
const store = new CrossChainStateStore();
|
|
123
|
+
|
|
124
|
+
const contractAddr = '0x1234567890abcdef1234567890abcdef12345678';
|
|
125
|
+
|
|
126
|
+
const balanceSlot = store.computeSlot(1, contractAddr, 'balances');
|
|
127
|
+
const ownerSlot = store.computeSlot(1, contractAddr, 'owner');
|
|
128
|
+
const supplySlot = store.computeSlot(1, contractAddr, 'totalSupply');
|
|
129
|
+
|
|
130
|
+
assert(!balanceSlot.equals(ownerSlot), 'balance and owner slots should be different');
|
|
131
|
+
assert(!balanceSlot.equals(supplySlot), 'balance and supply slots should be different');
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
test('StorageSlot: Deterministic - same inputs = same output', () => {
|
|
135
|
+
const store = new CrossChainStateStore();
|
|
136
|
+
|
|
137
|
+
const contractAddr = '0x1234567890abcdef1234567890abcdef12345678';
|
|
138
|
+
|
|
139
|
+
const slot1 = store.computeSlot(1, contractAddr, 'test');
|
|
140
|
+
const slot2 = store.computeSlot(1, contractAddr, 'test');
|
|
141
|
+
|
|
142
|
+
assert(slot1.equals(slot2), 'Same inputs should produce same slot');
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
test('StorageSlot: Mapping slot computation', () => {
|
|
146
|
+
const store = new CrossChainStateStore();
|
|
147
|
+
|
|
148
|
+
const contractAddr = '0x1234567890abcdef1234567890abcdef12345678';
|
|
149
|
+
const userAddr = '0xaabbccdd00112233aabbccdd00112233aabbccdd';
|
|
150
|
+
|
|
151
|
+
const slot = store.computeMappingSlot(1, contractAddr, 'balances', userAddr);
|
|
152
|
+
assert(Buffer.isBuffer(slot), 'Mapping slot should be a buffer');
|
|
153
|
+
assert(slot.length === 32, 'Slot should be 32 bytes');
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
// ═══════════════════════════════════════════════════════════════
|
|
157
|
+
// TEST 3: CROSS-CHAIN STATE READ/WRITE
|
|
158
|
+
// ═══════════════════════════════════════════════════════════════
|
|
159
|
+
|
|
160
|
+
console.log('\n--- Cross-Chain State Read/Write Tests ---');
|
|
161
|
+
|
|
162
|
+
test('StateRW: Write and read native chain state', () => {
|
|
163
|
+
const store = new CrossChainStateStore(4545); // JAELIS Testnet (live)
|
|
164
|
+
|
|
165
|
+
const contractAddr = '0x1234567890abcdef1234567890abcdef12345678';
|
|
166
|
+
const value = Buffer.alloc(32);
|
|
167
|
+
value.writeBigUInt64LE(1000000n, 0);
|
|
168
|
+
|
|
169
|
+
// Write
|
|
170
|
+
store.writeChainState(4545, contractAddr, 'balance', value);
|
|
171
|
+
|
|
172
|
+
// Read
|
|
173
|
+
const readValue = store.readChainState(4545, contractAddr, 'balance');
|
|
174
|
+
assert(readValue.readBigUInt64LE(0) === 1000000n, 'Value should match');
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
test('StateRW: Cannot directly write to external chain', () => {
|
|
178
|
+
const store = new CrossChainStateStore(4545); // JAELIS Testnet
|
|
179
|
+
|
|
180
|
+
const contractAddr = '0x1234567890abcdef1234567890abcdef12345678';
|
|
181
|
+
const value = Buffer.alloc(32);
|
|
182
|
+
|
|
183
|
+
try {
|
|
184
|
+
store.writeChainState(1, contractAddr, 'balance', value); // Try to write to ETH
|
|
185
|
+
assert(false, 'Should have thrown');
|
|
186
|
+
} catch (error) {
|
|
187
|
+
assert(error.message.includes('Cannot directly write'), 'Should get access error');
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
test('StateRW: Read returns zero for unset state', () => {
|
|
192
|
+
const store = new CrossChainStateStore(4545);
|
|
193
|
+
|
|
194
|
+
const value = store.readChainState(1, '0xdeadbeef', 'nonexistent');
|
|
195
|
+
assert(value.every(b => b === 0), 'Unset state should be zero');
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
// ═══════════════════════════════════════════════════════════════
|
|
199
|
+
// TEST 4: LIGHT CLIENT VERIFICATION
|
|
200
|
+
// ═══════════════════════════════════════════════════════════════
|
|
201
|
+
|
|
202
|
+
console.log('\n--- Light Client Tests ---');
|
|
203
|
+
|
|
204
|
+
asyncTest('LightClient: EVM light client setup', async () => {
|
|
205
|
+
const client = new EVMLightClient(1); // Ethereum mainnet
|
|
206
|
+
|
|
207
|
+
assert(client.chainId === 1, 'Chain ID should be 1');
|
|
208
|
+
assert(client.lastVerifiedBlock === 0, 'Initial block should be 0');
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
asyncTest('LightClient: Update headers', async () => {
|
|
212
|
+
const client = new EVMLightClient(1);
|
|
213
|
+
|
|
214
|
+
const headers = [
|
|
215
|
+
{
|
|
216
|
+
number: 1000,
|
|
217
|
+
hash: Buffer.alloc(32, 1),
|
|
218
|
+
parentHash: Buffer.alloc(32, 0),
|
|
219
|
+
stateRoot: Buffer.alloc(32, 2),
|
|
220
|
+
timestamp: Date.now()
|
|
221
|
+
}
|
|
222
|
+
];
|
|
223
|
+
|
|
224
|
+
await client.updateHeaders(headers);
|
|
225
|
+
assert(client.lastVerifiedBlock === 1000, 'Block should be updated');
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
asyncTest('LightClient: Verify state proof structure', async () => {
|
|
229
|
+
const client = new EVMLightClient(1);
|
|
230
|
+
|
|
231
|
+
// Add a header first
|
|
232
|
+
const stateRoot = Buffer.alloc(32, 0xab);
|
|
233
|
+
await client.updateHeaders([{
|
|
234
|
+
number: 1000,
|
|
235
|
+
hash: Buffer.alloc(32, 1),
|
|
236
|
+
parentHash: Buffer.alloc(32, 0),
|
|
237
|
+
stateRoot: stateRoot,
|
|
238
|
+
timestamp: Date.now()
|
|
239
|
+
}]);
|
|
240
|
+
|
|
241
|
+
// Create a proof
|
|
242
|
+
const proof = Buffer.alloc(100);
|
|
243
|
+
proof.writeBigUInt64LE(1000n, 0); // Block number
|
|
244
|
+
stateRoot.copy(proof, 8); // State root
|
|
245
|
+
|
|
246
|
+
const slot = Buffer.alloc(32);
|
|
247
|
+
const value = Buffer.alloc(32);
|
|
248
|
+
|
|
249
|
+
const isValid = await client.verifyStateProof(proof, slot, value);
|
|
250
|
+
assert(isValid === true, 'Valid proof structure should verify');
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
// ═══════════════════════════════════════════════════════════════
|
|
254
|
+
// TEST 5: CROSS-CHAIN SETTLEMENT
|
|
255
|
+
// ═══════════════════════════════════════════════════════════════
|
|
256
|
+
|
|
257
|
+
console.log('\n--- Cross-Chain Settlement Tests ---');
|
|
258
|
+
|
|
259
|
+
asyncTest('Settlement: Settle external state with proof', async () => {
|
|
260
|
+
const manager = new CrossChainSettlementManager({ nativeChainId: 4545 });
|
|
261
|
+
|
|
262
|
+
// Get the light client and update it
|
|
263
|
+
const ethClient = manager.stateStore.lightClients.get(1);
|
|
264
|
+
const stateRoot = Buffer.alloc(32, 0xab);
|
|
265
|
+
await ethClient.updateHeaders([{
|
|
266
|
+
number: 1000,
|
|
267
|
+
hash: Buffer.alloc(32, 1),
|
|
268
|
+
parentHash: Buffer.alloc(32, 0),
|
|
269
|
+
stateRoot: stateRoot,
|
|
270
|
+
timestamp: Date.now()
|
|
271
|
+
}]);
|
|
272
|
+
|
|
273
|
+
// Create proof
|
|
274
|
+
const proof = Buffer.alloc(100);
|
|
275
|
+
proof.writeBigUInt64LE(1000n, 0);
|
|
276
|
+
stateRoot.copy(proof, 8);
|
|
277
|
+
|
|
278
|
+
// Settle state
|
|
279
|
+
const contractAddr = '0x1234567890abcdef1234567890abcdef12345678';
|
|
280
|
+
const value = Buffer.alloc(32);
|
|
281
|
+
value.writeBigUInt64LE(5000n, 0);
|
|
282
|
+
|
|
283
|
+
const result = await manager.settle(1, contractAddr, 'balance', value, proof);
|
|
284
|
+
assert(result.settlement, 'Should have settlement record');
|
|
285
|
+
assert(result.settlement.chainId === 1, 'Chain ID should be 1');
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
asyncTest('Settlement: Read settled state', async () => {
|
|
289
|
+
const manager = new CrossChainSettlementManager({ nativeChainId: 4545 });
|
|
290
|
+
|
|
291
|
+
// Setup and settle
|
|
292
|
+
const ethClient = manager.stateStore.lightClients.get(1);
|
|
293
|
+
const stateRoot = Buffer.alloc(32, 0xcd);
|
|
294
|
+
await ethClient.updateHeaders([{
|
|
295
|
+
number: 2000,
|
|
296
|
+
hash: Buffer.alloc(32, 2),
|
|
297
|
+
parentHash: Buffer.alloc(32, 1),
|
|
298
|
+
stateRoot: stateRoot,
|
|
299
|
+
timestamp: Date.now()
|
|
300
|
+
}]);
|
|
301
|
+
|
|
302
|
+
const proof = Buffer.alloc(100);
|
|
303
|
+
proof.writeBigUInt64LE(2000n, 0);
|
|
304
|
+
stateRoot.copy(proof, 8);
|
|
305
|
+
|
|
306
|
+
const contractAddr = '0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef';
|
|
307
|
+
const value = Buffer.alloc(32);
|
|
308
|
+
value.writeBigUInt64LE(99999n, 0);
|
|
309
|
+
|
|
310
|
+
await manager.settle(1, contractAddr, 'totalSupply', value, proof);
|
|
311
|
+
|
|
312
|
+
// Read it back
|
|
313
|
+
const readValue = manager.readState(1, contractAddr, 'totalSupply');
|
|
314
|
+
assert(readValue.readBigUInt64LE(0) === 99999n, 'Settled value should be readable');
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
// ═══════════════════════════════════════════════════════════════
|
|
318
|
+
// TEST 6: UNIFIED VM INTEGRATION
|
|
319
|
+
// ═══════════════════════════════════════════════════════════════
|
|
320
|
+
|
|
321
|
+
console.log('\n--- Unified VM Cross-Chain Integration Tests ---');
|
|
322
|
+
|
|
323
|
+
asyncTest('UnifiedVM: Has cross-chain manager', async () => {
|
|
324
|
+
const vm = new UnifiedJaelisVM({ chainId: 4545 });
|
|
325
|
+
|
|
326
|
+
assert(vm.crossChainManager, 'Should have cross-chain manager');
|
|
327
|
+
assert(vm.chainId === 4545, 'Chain ID should be 4545 (testnet)');
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
asyncTest('UnifiedVM: Compute cross-chain slots', async () => {
|
|
331
|
+
const vm = new UnifiedJaelisVM({ chainId: 4545 });
|
|
332
|
+
|
|
333
|
+
const ethSlot = vm.computeCrossChainSlot(1, '0x1234', 'balance');
|
|
334
|
+
const jaelisSlot = vm.computeCrossChainSlot(4545, '0x1234', 'balance');
|
|
335
|
+
|
|
336
|
+
assert(!ethSlot.equals(jaelisSlot), 'Different chains = different slots');
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
asyncTest('UnifiedVM: Get chain info', async () => {
|
|
340
|
+
const vm = new UnifiedJaelisVM();
|
|
341
|
+
|
|
342
|
+
const ethInfo = vm.getChainInfo(1);
|
|
343
|
+
assert(ethInfo.name === 'Ethereum Mainnet', 'Should get ETH info');
|
|
344
|
+
|
|
345
|
+
const solInfo = vm.getChainInfo(101);
|
|
346
|
+
assert(solInfo.name === 'Solana Mainnet', 'Should get SOL info');
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
asyncTest('UnifiedVM: Get all chains', async () => {
|
|
350
|
+
const vm = new UnifiedJaelisVM();
|
|
351
|
+
|
|
352
|
+
const chains = vm.getAllChains();
|
|
353
|
+
assert(Object.keys(chains).length > 20, 'Should have many chains');
|
|
354
|
+
assert(chains.JAELIS_TESTNET, 'Should have JAELIS Testnet');
|
|
355
|
+
assert(chains.JAELIS_MAINNET, 'Should have JAELIS Mainnet');
|
|
356
|
+
assert(chains.ETH_MAINNET, 'Should have ETH');
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
asyncTest('UnifiedVM: Stats include cross-chain', async () => {
|
|
360
|
+
const vm = new UnifiedJaelisVM();
|
|
361
|
+
|
|
362
|
+
const stats = vm.getStats();
|
|
363
|
+
assert(stats.crossChain, 'Should have crossChain stats');
|
|
364
|
+
assert(stats.crossChainSettlements === 0, 'Should start at 0 settlements');
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
// ═══════════════════════════════════════════════════════════════
|
|
368
|
+
// TEST 7: CROSS-CHAIN OPCODES
|
|
369
|
+
// ═══════════════════════════════════════════════════════════════
|
|
370
|
+
|
|
371
|
+
console.log('\n--- Cross-Chain Opcode Tests ---');
|
|
372
|
+
|
|
373
|
+
test('Opcodes: All cross-chain opcodes defined', () => {
|
|
374
|
+
const requiredOpcodes = [
|
|
375
|
+
'XCHAIN_SLOAD', 'XCHAIN_SSTORE', 'XCHAIN_SETTLE',
|
|
376
|
+
'XCHAIN_ID', 'XCHAIN_EXISTS', 'XCHAIN_TYPE',
|
|
377
|
+
'XCHAIN_VERIFY', 'XCHAIN_QUEUE', 'XCHAIN_FLUSH',
|
|
378
|
+
'XCHAIN_DIFF', 'XCHAIN_UPDATE', 'XCHAIN_HEIGHT'
|
|
379
|
+
];
|
|
380
|
+
|
|
381
|
+
for (const op of requiredOpcodes) {
|
|
382
|
+
assert(CROSS_CHAIN_OPCODES[op] !== undefined, `${op} should be defined`);
|
|
383
|
+
}
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
test('Opcodes: Opcodes are in extended range (0xE0-0xEF)', () => {
|
|
387
|
+
for (const [name, code] of Object.entries(CROSS_CHAIN_OPCODES)) {
|
|
388
|
+
assert(code >= 0xE0 && code <= 0xEF, `${name} (0x${code.toString(16)}) should be in 0xE0-0xEF range`);
|
|
389
|
+
}
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
test('Opcodes: No duplicate opcode values', () => {
|
|
393
|
+
const values = Object.values(CROSS_CHAIN_OPCODES);
|
|
394
|
+
const unique = new Set(values);
|
|
395
|
+
assert(values.length === unique.size, 'All opcode values should be unique');
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
// ═══════════════════════════════════════════════════════════════
|
|
399
|
+
// TEST 8: STATE DIFF DETECTION
|
|
400
|
+
// ═══════════════════════════════════════════════════════════════
|
|
401
|
+
|
|
402
|
+
console.log('\n--- State Diff Detection Tests ---');
|
|
403
|
+
|
|
404
|
+
test('StateDiff: Detect differences between chains', () => {
|
|
405
|
+
const store = new CrossChainStateStore(4545);
|
|
406
|
+
|
|
407
|
+
const contractAddr = '0x1234567890abcdef1234567890abcdef12345678';
|
|
408
|
+
|
|
409
|
+
// Write different values for same var on two chains (simulating settled state)
|
|
410
|
+
const ethSlot = store.computeSlot(1, contractAddr, 'price');
|
|
411
|
+
const solSlot = store.computeSlot(101, contractAddr, 'price');
|
|
412
|
+
|
|
413
|
+
const ethValue = Buffer.alloc(32);
|
|
414
|
+
ethValue.writeBigUInt64LE(100n, 0);
|
|
415
|
+
store.write(ethSlot, ethValue);
|
|
416
|
+
|
|
417
|
+
const solValue = Buffer.alloc(32);
|
|
418
|
+
solValue.writeBigUInt64LE(105n, 0);
|
|
419
|
+
store.write(solSlot, solValue);
|
|
420
|
+
|
|
421
|
+
// Check diff
|
|
422
|
+
const diff = store.getStateDiff(1, 101, contractAddr, ['price']);
|
|
423
|
+
assert(diff.length === 1, 'Should find 1 difference');
|
|
424
|
+
assert(diff[0].variableName === 'price', 'Diff should be for price');
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
test('StateDiff: No diff when values match', () => {
|
|
428
|
+
const store = new CrossChainStateStore(4545);
|
|
429
|
+
|
|
430
|
+
const contractAddr = '0x1234567890abcdef1234567890abcdef12345678';
|
|
431
|
+
|
|
432
|
+
// Write same value on both chains
|
|
433
|
+
const ethSlot = store.computeSlot(1, contractAddr, 'constant');
|
|
434
|
+
const solSlot = store.computeSlot(101, contractAddr, 'constant');
|
|
435
|
+
|
|
436
|
+
const sameValue = Buffer.alloc(32);
|
|
437
|
+
sameValue.writeBigUInt64LE(42n, 0);
|
|
438
|
+
store.write(ethSlot, sameValue);
|
|
439
|
+
store.write(solSlot, Buffer.from(sameValue)); // Copy
|
|
440
|
+
|
|
441
|
+
// Check diff
|
|
442
|
+
const diff = store.getStateDiff(1, 101, contractAddr, ['constant']);
|
|
443
|
+
assert(diff.length === 0, 'Should find no differences');
|
|
444
|
+
});
|
|
445
|
+
|
|
446
|
+
// ═══════════════════════════════════════════════════════════════
|
|
447
|
+
// SUMMARY
|
|
448
|
+
// ═══════════════════════════════════════════════════════════════
|
|
449
|
+
|
|
450
|
+
(async () => {
|
|
451
|
+
// Wait for all async tests
|
|
452
|
+
await new Promise(resolve => setTimeout(resolve, 3000));
|
|
453
|
+
|
|
454
|
+
console.log('\n═══════════════════════════════════════════════════════════════');
|
|
455
|
+
console.log(` RESULTS: ${passed} passed, ${failed} failed`);
|
|
456
|
+
console.log('═══════════════════════════════════════════════════════════════');
|
|
457
|
+
|
|
458
|
+
if (failed === 0) {
|
|
459
|
+
console.log('\n ✓ ALL CROSS-CHAIN TESTS PASSED!');
|
|
460
|
+
console.log(' ✓ Chain-ID namespaced storage: OPERATIONAL');
|
|
461
|
+
console.log(' ✓ Light client verification: OPERATIONAL');
|
|
462
|
+
console.log(' ✓ Cross-chain settlement: OPERATIONAL');
|
|
463
|
+
console.log(' ✓ State diff detection: OPERATIONAL');
|
|
464
|
+
console.log(' ✓ JAELIS is now a UNIVERSAL SETTLEMENT LAYER!');
|
|
465
|
+
} else {
|
|
466
|
+
console.log('\n ✗ Some tests failed. Review output above.');
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
console.log('\n');
|
|
470
|
+
})();
|