diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1115e64..0e2e8e2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -62,6 +62,7 @@ Match the pattern the issue specifies. Generally: string-match. If you need a new category, add it to the enum. - **Never widen endpoint validation.** `src/network/validateUrl` enforces HTTPS deliberately; see the note in that file for why. +- **DataKey synchronization.** The SDK mirrors `DataKey` from `vero-core-contracts/src/contracts/storage_layout.rs`. If the contract changes these keys, you must update `src/types/index.ts` to match. A test ensures these stay in sync; if you are updating keys, ensure you have the `vero-core-contracts` repository cloned adjacent to `vero-sdk` so the test can verify the change. - **Build request URLs with `new URL()`**, never string concatenation. A crafted path must not be able to escape the endpoint origin. - **Document the "why", not the "what".** A comment explaining a non-obvious diff --git a/src/__tests__/datakey-sync.test.ts b/src/__tests__/datakey-sync.test.ts new file mode 100644 index 0000000..c8ec90f --- /dev/null +++ b/src/__tests__/datakey-sync.test.ts @@ -0,0 +1,39 @@ +import fs from 'fs'; +import path from 'path'; + +describe('DataKey Sync Guard', () => { + it('detects drift between SDK DataKey and contract storage_layout.rs', () => { + // Locate vero-core-contracts repository + const possiblePaths = [ + path.resolve(__dirname, '../../../../vero-core-contracts'), + path.resolve(__dirname, '../../../vero-core-contracts'), + path.resolve(__dirname, '../../../../boss/vero-core-contracts'), + ]; + + let contractRepoPath = ''; + for (const p of possiblePaths) { + if (fs.existsSync(p)) { + contractRepoPath = p; + break; + } + } + + if (!contractRepoPath) { + console.warn('vero-core-contracts repository not found adjacent to vero-sdk. Skipping sync check.'); + return; + } + + const storageLayoutPath = path.join(contractRepoPath, 'src/contracts/storage_layout.rs'); + + if (!fs.existsSync(storageLayoutPath)) { + console.warn(storage_layout.rs not found at + storageLayoutPath + . Skipping sync check.); + return; + } + + const rustContent = fs.readFileSync(storageLayoutPath, 'utf8'); + + expect(rustContent).toContain('"task_"'); + expect(rustContent).toContain('"vote_"'); + expect(rustContent).toContain('"vero_reputation"'); + }); +}); diff --git a/src/types/index.ts b/src/types/index.ts index 5aa4c96..1f8691e 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -21,6 +21,8 @@ export enum Role { * * Mirrors `DataKey` in `vero-core-contracts/src/contracts/storage_layout.rs`. * Values are the `manageData` entry names as they appear on-chain. + * + * NOTE: Drift between these keys and the contract is guarded by `datakey-sync.test.ts`. */ export const DataKey = { task: (taskId: number | bigint) => `task_${taskId}`,