-
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
2 changed files
with
63 additions
and
48 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,63 @@ | ||
import { | ||
CallResult, | ||
ic, | ||
Principal, | ||
RejectionCode, | ||
Service, | ||
serviceUpdate, | ||
$update | ||
text, | ||
update, | ||
Void | ||
} from 'azle'; | ||
import { someService } from '../some_service'; | ||
import { default as SomeService } from '../some_service'; | ||
|
||
class Nonexistent extends Service { | ||
@serviceUpdate | ||
method: () => CallResult<void>; | ||
@update([], Void) | ||
method: () => Void; | ||
} | ||
|
||
export const nonexistentCanister = new Nonexistent( | ||
Principal.fromText('rkp4c-7iaaa-aaaaa-aaaca-cai') | ||
); | ||
export default class extends Service { | ||
nonexistentCanister = new Nonexistent( | ||
Principal.fromText('rkp4c-7iaaa-aaaaa-aaaca-cai') | ||
); | ||
|
||
$update; | ||
export async function getRejectionCodeNoError(): Promise<RejectionCode> { | ||
await someService.accept().call(); | ||
return ic.rejectCode(); | ||
} | ||
someService = new SomeService( | ||
Principal.fromText( | ||
process.env.SOME_SERVICE_PRINCIPAL ?? | ||
ic.trap('process.env.SOME_SERVICE_PRINCIPAL is undefined') | ||
) | ||
); | ||
|
||
$update; | ||
export async function getRejectionCodeDestinationInvalid(): Promise<RejectionCode> { | ||
await nonexistentCanister.method().call(); | ||
return ic.rejectCode(); | ||
} | ||
@update([], RejectionCode) | ||
async getRejectionCodeNoError(): Promise<RejectionCode> { | ||
await ic.call(this.someService.accept); | ||
|
||
$update; | ||
export async function getRejectionCodeCanisterReject(): Promise<RejectionCode> { | ||
await someService.reject('reject').call(); | ||
return ic.rejectCode(); | ||
} | ||
return ic.rejectCode(); | ||
} | ||
|
||
$update; | ||
export async function getRejectionCodeCanisterError(): Promise<RejectionCode> { | ||
await someService.error().call(); | ||
return ic.rejectCode(); | ||
} | ||
@update([], RejectionCode) | ||
async getRejectionCodeDestinationInvalid(): Promise<RejectionCode> { | ||
await ic.call(this.nonexistentCanister.method); | ||
|
||
return ic.rejectCode(); | ||
} | ||
|
||
@update([], RejectionCode) | ||
async getRejectionCodeCanisterReject(): Promise<RejectionCode> { | ||
await ic.call(this.someService.reject, { args: ['reject'] }); | ||
|
||
return ic.rejectCode(); | ||
} | ||
|
||
@update([], RejectionCode) | ||
async getRejectionCodeCanisterError(): Promise<RejectionCode> { | ||
await ic.call(this.someService.error); | ||
|
||
return ic.rejectCode(); | ||
} | ||
|
||
@update([text], text) | ||
async getRejectionMessage(message: text): Promise<text> { | ||
await ic.call(this.someService.reject, { args: [message] }); | ||
|
||
$update; | ||
export async function getRejectionMessage(message: string): Promise<string> { | ||
await someService.reject(message).call(); | ||
return ic.rejectMessage(); | ||
return ic.rejectMessage(); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,19 +1,20 @@ | ||
import { CallResult, empty, ic, Principal, Service, serviceQuery } from 'azle'; | ||
import { bool, empty, ic, query, Service, text } from 'azle'; | ||
|
||
export class SomeService extends Service { | ||
@serviceQuery | ||
reject: (message: string) => CallResult<empty>; | ||
type Manual<T> = void; | ||
|
||
@serviceQuery | ||
accept: () => CallResult<boolean>; | ||
export default class extends Service { | ||
@query([text], empty, { manual: true }) | ||
reject(message: text): Manual<empty> { | ||
ic.reject(message); | ||
} | ||
|
||
@serviceQuery | ||
error: () => CallResult<empty>; | ||
} | ||
@query([], bool) | ||
accept(): bool { | ||
return true; | ||
} | ||
|
||
export const someService = new SomeService( | ||
Principal.fromText( | ||
process.env.SOME_SERVICE_PRINCIPAL ?? | ||
ic.trap('process.env.SOME_SERVICE_PRINCIPAL is undefined') | ||
) | ||
); | ||
@query([], empty, { manual: true }) | ||
error(): Manual<empty> { | ||
// This errors because neither ic.reject nor ic.reply were called | ||
} | ||
} |