Skip to content

Commit

Permalink
Merge pull request #1963 from demergent-labs/caller_property_tests
Browse files Browse the repository at this point in the history
caller and id property tests
  • Loading branch information
lastmjs authored Aug 7, 2024
2 parents 64119c5 + 25d3484 commit e8a2e20
Show file tree
Hide file tree
Showing 24 changed files with 13,139 additions and 9 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,9 @@ jobs:
"tests/end_to_end/http_server/sqlite_drizzle",
"tests/end_to_end/http_server/sqlite_typeorm",
"tests/end_to_end/http_server/tfjs",
"tests/end_to_end/http_server/web_assembly"
"tests/end_to_end/http_server/web_assembly",
"tests/property/ic_api/caller",
"tests/property/ic_api/id"
]
END
)
Expand Down
12 changes: 8 additions & 4 deletions src/lib/stable/execute_with_candid_serde.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { IDL, JsonValue } from '@dfinity/candid';

import { handleUncaughtError } from './error';
import { reply } from './ic_apis';
import { reply, trap } from './ic_apis';

type CanisterMethodMode =
| 'query'
Expand All @@ -20,9 +20,13 @@ export async function executeAndReplyWithCandidSerde(
returnIdlType: IDL.Type | undefined,
manual: boolean
): Promise<void> {
const decodedArgs = decodeArgs(mode, args, paramIdlTypes);
const unencodedResult = await getUnencodedResult(decodedArgs, callback);
encodeResultAndReply(mode, manual, unencodedResult, returnIdlType);
try {
const decodedArgs = decodeArgs(mode, args, paramIdlTypes);
const unencodedResult = await getUnencodedResult(decodedArgs, callback);
encodeResultAndReply(mode, manual, unencodedResult, returnIdlType);
} catch (error: any) {
trap(error.toString());
}
}

function decodeArgs(
Expand Down
4 changes: 2 additions & 2 deletions src/lib/stable/ic_apis/caller.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Principal } from '../';

/**
* Returns the caller of the current call
* @returns the caller of the current call
* Returns the principal of the caller of the current call
* @returns the principal of the caller of the current call
*/
export function caller(): Principal {
if (globalThis._azleIc === undefined) {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/stable/ic_apis/id.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Principal } from '..';

/**
* Gets the id of this canister
* @returns the canister id
* Returns the canister's id as a principal
* @returns the canister's id as a principal
*/
export function id(): Principal {
if (globalThis._azleIc === undefined) {
Expand Down
4 changes: 4 additions & 0 deletions tests/property/ic_api/caller/.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/caller/dfx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"canisters": {
"canister": {
"type": "azle",
"main": "src/index.ts",
"candid_gen": "automatic",
"declarations": {
"output": "test/dfx_generated/canister",
"node_compatibility": true
}
}
}
}
10 changes: 10 additions & 0 deletions tests/property/ic_api/caller/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
transform: {
'^.+\\.ts$': ['ts-jest', { isolatedModules: true }],
'^.+\\.js$': 'ts-jest'
},
transformIgnorePatterns: ['/node_modules/(?!(azle)/)'] // Make sure azle is transformed
};
Loading

0 comments on commit e8a2e20

Please sign in to comment.