-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support for management canister logging (#863)
* feat: updates for canister logging feature from management canister * feat: support and tests for fetch_canister_logs * changelog * test for bitcoin query * bitcoin query tests
- Loading branch information
Showing
15 changed files
with
1,057 additions
and
420 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { bufFromBufLike, getManagementCanister } from '@dfinity/agent'; | ||
import { describe, it, expect } from 'vitest'; | ||
import logsActor from '../canisters/logs'; | ||
import { makeAgent } from '../utils/agent'; | ||
|
||
describe('canister logs', () => { | ||
it('should make requests to the management canister', async () => { | ||
const { canisterId } = await logsActor(); | ||
|
||
const management = await getManagementCanister({ agent: await makeAgent() }); | ||
const logs = await management.fetch_canister_logs({ canister_id: canisterId }); | ||
|
||
expect(logs.canister_log_records.length).toBe(1); | ||
const content = bufFromBufLike(logs.canister_log_records[0].content); | ||
|
||
expect(new TextDecoder().decode(content).trim()).toBe('Hello, first call!'); | ||
}); | ||
it('should show additional logs', async () => { | ||
const { canisterId, actor } = await logsActor(); | ||
|
||
await actor.hello('second call'); | ||
|
||
const management = await getManagementCanister({ agent: await makeAgent() }); | ||
const logs = await management.fetch_canister_logs({ canister_id: canisterId }); | ||
|
||
expect(logs.canister_log_records.length).toBe(2); | ||
const content = bufFromBufLike(logs.canister_log_records[1].content); | ||
|
||
expect(new TextDecoder().decode(content).trim()).toBe('Hello, second call!'); | ||
}); | ||
}, 10_000); |
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,52 @@ | ||
import { Principal } from '@dfinity/principal'; | ||
import agent from '../utils/agent'; | ||
import { readFileSync } from 'fs'; | ||
import path from 'path'; | ||
import { Actor, ActorMethod, ActorSubclass } from '@dfinity/agent'; | ||
import { IDL } from '@dfinity/candid'; | ||
|
||
export interface _SERVICE { | ||
hello: ActorMethod<[string], undefined>; | ||
} | ||
export declare const init: (args: { IDL: typeof IDL }) => IDL.Type[]; | ||
|
||
export const idlFactory = ({ IDL }) => { | ||
return IDL.Service({ hello: IDL.Func([IDL.Text], [], []) }); | ||
}; | ||
|
||
let cache: { | ||
canisterId: Principal; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
actor: any; | ||
} | null = null; | ||
|
||
/** | ||
* Create a counter Actor + canisterId | ||
*/ | ||
export default async function (): Promise<{ | ||
canisterId: Principal; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
actor: any; | ||
}> { | ||
if (!cache) { | ||
const module = readFileSync(path.join(__dirname, 'logs.wasm')); | ||
|
||
const canisterId = await Actor.createCanister({ agent: await agent }); | ||
await Actor.install({ module }, { canisterId, agent: await agent }); | ||
|
||
const actor = Actor.createActor(idlFactory, { | ||
canisterId, | ||
agent: await agent, | ||
}) as ActorSubclass<_SERVICE>; | ||
|
||
await actor.hello('first call'); | ||
|
||
cache = { | ||
canisterId, | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
actor, | ||
}; | ||
} | ||
|
||
return cache; | ||
} |
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
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
Oops, something went wrong.