-
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.
- Loading branch information
Showing
9 changed files
with
1,256 additions
and
1 deletion.
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
77 changes: 77 additions & 0 deletions
77
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,77 @@ | ||
import fc from 'fast-check'; | ||
|
||
import { UniqueIdentifierArb } from '../unique_identifier_arb'; | ||
import { | ||
BodyGenerator, | ||
TestsGenerator, | ||
CallbackLocation, | ||
generateCallback, | ||
CallbackLocationArb | ||
} from '.'; | ||
import { Test } from '../../../test'; | ||
import { VoidArb } from '../candid/primitive/void'; | ||
|
||
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('canisterMethod'), | ||
VoidArb(), | ||
CallbackLocationArb, | ||
UniqueIdentifierArb('typeDeclaration') | ||
// TODO: This unique id would be better named globalScope or something | ||
// But needs to match the same scope as typeDeclarations so I'm using | ||
// that for now. | ||
) | ||
.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 | ||
}; | ||
} | ||
); | ||
} |
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.