-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into kai/SDK-1828-call-and-poll
- Loading branch information
Showing
9 changed files
with
147 additions
and
21 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
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,49 @@ | ||
import { describe, it, expect } from 'vitest'; | ||
import { ActorMethod, Actor, HttpAgent } from '@dfinity/agent'; | ||
import util from 'util'; | ||
import exec from 'child_process'; | ||
const execAsync = util.promisify(exec.exec); | ||
|
||
const { stdout } = await execAsync('dfx canister id trap'); | ||
|
||
export const idlFactory = ({ IDL }) => { | ||
return IDL.Service({ | ||
Throw: IDL.Func([], [], []), | ||
test: IDL.Func([], [], []), | ||
}); | ||
}; | ||
|
||
export interface _SERVICE { | ||
Throw: ActorMethod<[], undefined>; | ||
test: ActorMethod<[], undefined>; | ||
} | ||
|
||
describe('trap', () => { | ||
it('should trap', async () => { | ||
const canisterId = stdout.trim(); | ||
const agent = await HttpAgent.create({ | ||
host: 'http://localhost:4943', | ||
shouldFetchRootKey: true, | ||
}); | ||
const actor = Actor.createActor<_SERVICE>(idlFactory, { canisterId, agent }); | ||
try { | ||
await actor.Throw(); | ||
} catch (error) { | ||
console.log(error); | ||
expect(error.reject_message).toBe('foo'); | ||
} | ||
}); | ||
it('should trap', async () => { | ||
const canisterId = stdout.trim(); | ||
const agent = await HttpAgent.create({ | ||
host: 'http://localhost:4943', | ||
shouldFetchRootKey: true, | ||
}); | ||
const actor = Actor.createActor<_SERVICE>(idlFactory, { canisterId, agent }); | ||
try { | ||
await actor.test(); | ||
} catch (error) { | ||
expect(error.reject_message).toContain('Canister called `ic0.trap` with message: trapping'); | ||
} | ||
}); | ||
}); |
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,23 @@ | ||
import Debug "mo:base/Debug"; | ||
import Error "mo:base/Error"; | ||
|
||
actor { | ||
|
||
func doTrap (n:Nat) { | ||
if (n <= 0) | ||
{ Debug.trap("trapping") } | ||
else { | ||
doTrap (n - 1); | ||
}; | ||
Debug.print (debug_show {doTrap = n}); // prevent TCO | ||
}; | ||
|
||
public func test() : async () { | ||
doTrap(10); | ||
}; | ||
|
||
public func Throw() : async () { | ||
throw Error.reject("foo"); | ||
} | ||
|
||
}; |
Binary file not shown.
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