-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1520 from demergent-labs/1517_inspect_message
Test: Added InspectMessageMethodArb
- Loading branch information
Showing
13 changed files
with
1,340 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
property_tests/arbitraries/canister_methods/inspect_message_method_arb.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import fc from 'fast-check'; | ||
|
||
import { Test } from '../../../test'; | ||
import { VoidArb } from '../candid/primitive/void'; | ||
import { UniqueIdentifierArb } from '../unique_identifier_arb'; | ||
import { | ||
BodyGenerator, | ||
CallbackLocation, | ||
CallbackLocationArb, | ||
generateCallback, | ||
TestsGenerator | ||
} from '.'; | ||
|
||
export type InspectMessageMethod = { | ||
imports: Set<string>; | ||
globalDeclarations: string[]; | ||
sourceCode: string; | ||
tests: Test[][]; | ||
}; | ||
|
||
export function InspectMessageMethodArb(constraints: { | ||
generateBody: BodyGenerator; | ||
generateTests: TestsGenerator; | ||
callbackLocation?: CallbackLocation; | ||
}) { | ||
return fc | ||
.tuple( | ||
UniqueIdentifierArb('canisterProperties'), | ||
VoidArb(), | ||
CallbackLocationArb, | ||
UniqueIdentifierArb('globalNames') | ||
) | ||
.map( | ||
([ | ||
functionName, | ||
returnType, | ||
defaultCallbackLocation, | ||
callbackName | ||
]): InspectMessageMethod => { | ||
const callbackLocation = | ||
constraints.callbackLocation ?? defaultCallbackLocation; | ||
|
||
const imports = new Set(['inspectMessage', 'ic']); | ||
|
||
const callback = generateCallback( | ||
[], | ||
returnType, | ||
constraints.generateBody, | ||
callbackLocation, | ||
callbackName | ||
); | ||
|
||
const globalDeclarations = | ||
callbackLocation === 'STANDALONE' ? [callback] : []; | ||
|
||
const sourceCode = `${functionName}: inspectMessage(${ | ||
callbackLocation === 'STANDALONE' ? callbackName : callback | ||
})`; | ||
|
||
const tests = constraints.generateTests( | ||
functionName, | ||
[], | ||
returnType | ||
); | ||
|
||
return { | ||
imports, | ||
globalDeclarations, | ||
sourceCode, | ||
tests | ||
}; | ||
} | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
property_tests/tests/canister_methods/inspect_message/dfx.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"canisters": { | ||
"canister": { | ||
"type": "custom", | ||
"main": "src/index.ts", | ||
"candid": "src/index.did", | ||
"build": "npx azle canister", | ||
"wasm": ".azle/canister/canister.wasm", | ||
"gzip": true, | ||
"declarations": { | ||
"output": "test/dfx_generated/canister", | ||
"node_compatibility": true | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.