Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 39 additions & 0 deletions src/__tests__/datakey-sync.test.ts
Original file line number Diff line number Diff line change
@@ -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.);

Check failure on line 29 in src/__tests__/datakey-sync.test.ts

View workflow job for this annotation

GitHub Actions / Typecheck, lint, test, build (20.x)

Identifier expected.

Check failure on line 29 in src/__tests__/datakey-sync.test.ts

View workflow job for this annotation

GitHub Actions / Typecheck, lint, test, build (20.x)

',' expected.

Check failure on line 29 in src/__tests__/datakey-sync.test.ts

View workflow job for this annotation

GitHub Actions / Typecheck, lint, test, build (20.x)

',' expected.

Check failure on line 29 in src/__tests__/datakey-sync.test.ts

View workflow job for this annotation

GitHub Actions / Typecheck, lint, test, build (20.x)

Expression expected.

Check failure on line 29 in src/__tests__/datakey-sync.test.ts

View workflow job for this annotation

GitHub Actions / Typecheck, lint, test, build (20.x)

',' expected.

Check failure on line 29 in src/__tests__/datakey-sync.test.ts

View workflow job for this annotation

GitHub Actions / Typecheck, lint, test, build (20.x)

',' expected.

Check failure on line 29 in src/__tests__/datakey-sync.test.ts

View workflow job for this annotation

GitHub Actions / Typecheck, lint, test, build (20.x)

',' expected.

Check failure on line 29 in src/__tests__/datakey-sync.test.ts

View workflow job for this annotation

GitHub Actions / Typecheck, lint, test, build (22.x)

Identifier expected.

Check failure on line 29 in src/__tests__/datakey-sync.test.ts

View workflow job for this annotation

GitHub Actions / Typecheck, lint, test, build (22.x)

',' expected.

Check failure on line 29 in src/__tests__/datakey-sync.test.ts

View workflow job for this annotation

GitHub Actions / Typecheck, lint, test, build (22.x)

',' expected.

Check failure on line 29 in src/__tests__/datakey-sync.test.ts

View workflow job for this annotation

GitHub Actions / Typecheck, lint, test, build (22.x)

Expression expected.

Check failure on line 29 in src/__tests__/datakey-sync.test.ts

View workflow job for this annotation

GitHub Actions / Typecheck, lint, test, build (22.x)

',' expected.

Check failure on line 29 in src/__tests__/datakey-sync.test.ts

View workflow job for this annotation

GitHub Actions / Typecheck, lint, test, build (22.x)

',' expected.

Check failure on line 29 in src/__tests__/datakey-sync.test.ts

View workflow job for this annotation

GitHub Actions / Typecheck, lint, test, build (22.x)

',' expected.
return;
}

const rustContent = fs.readFileSync(storageLayoutPath, 'utf8');

expect(rustContent).toContain('"task_"');
expect(rustContent).toContain('"vote_"');
expect(rustContent).toContain('"vero_reputation"');
});
});
2 changes: 2 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
Expand Down
Loading