Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Certified data prop test #2181

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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
16 changes: 7 additions & 9 deletions src/lib/stable/ic_apis/data_certificate.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
/**
* When called from a query call, returns the data certificate
* authenticating `certifiedData` set by this canister. Otherwise returns
* `None`.
* @returns the data certificate or None
* `undefined`.
* @returns the data certificate or undefined
*/
export function dataCertificate(): [Uint8Array] | [] {
if (globalThis._azleIc === undefined) {
return [];
export function dataCertificate(): Uint8Array | undefined {
const certificate = globalThis._azleIc?.dataCertificate();
if (certificate instanceof ArrayBuffer) {
return new Uint8Array(certificate);
}

const rawRustValue = globalThis._azleIc.dataCertificate();

return rawRustValue === undefined ? [] : [new Uint8Array(rawRustValue)];
return undefined;
}
4 changes: 4 additions & 0 deletions tests/property/ic_api/certified_data/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.azle
.dfx
dfx_generated
node_modules
13 changes: 13 additions & 0 deletions tests/property/ic_api/certified_data/dfx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"canisters": {
"canister": {
"type": "azle",
"main": "src/index.ts",
"init_arg": "(false)",
"declarations": {
"output": "test/dfx_generated/canister",
"node_compatibility": true
}
}
}
}
12 changes: 12 additions & 0 deletions tests/property/ic_api/certified_data/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
bail: true,
testTimeout: 100_000_000,
transform: {
'^.+\\.ts$': ['ts-jest', { isolatedModules: true }],
'^.+\\.js$': 'ts-jest'
},
transformIgnorePatterns: ['/node_modules/(?!(azle)/)'] // Make sure azle is transformed
};
Loading
Loading