Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

### Changed

- test: fixes e2e tests for compatibility with dfx 0.26.0 and `pocket-ic` by querying for the `default_effective_canister_id` before calling the management canister
- fix: fixes a bug in the Ed25519KeyIdentity verify implementation where the argument order was incorrect
- fix: fixes a bug in the `Principal` library where the management canister id util was incorrectly importing using `fromHex`
- feat: change auth-client's default identity provider url
Expand Down
53 changes: 35 additions & 18 deletions e2e/node/basic/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,48 @@ import { Principal } from '@dfinity/principal';
import agent from '../utils/agent';
import { test, expect } from 'vitest';

/**
* Util for determining the default effective canister id, necessary for pocketic
* @returns the default effective canister id
*/
export async function getDefaultEffectiveCanisterId() {
const res = await fetch('http://localhost:4943/_/topology'); //?
const data = await res.json(); //?
const id = data['default_effective_canister_id']['canister_id'];
// decode from base64
const decoded = Buffer.from(id, 'base64').toString('hex');

return Principal.fromHex(decoded);
}

test('createCanister', async () => {
// Make sure this doesn't fail.
await getManagementCanister({
agent: await agent,
}).provisional_create_canister_with_cycles({
amount: [BigInt(1e12)],
settings: [],
specified_id: [],
sender_canister_version: [],
});
});
test('read_state', async () => {
const ecid = await getDefaultEffectiveCanisterId();
const resolvedAgent = await agent;
const now = Date.now() / 1000;
const path = [new TextEncoder().encode('time')];
const canisterId = Principal.fromHex('00000000000000000001');
const response = await resolvedAgent.readState(canisterId, {
const response = await resolvedAgent.readState(ecid, {
paths: [path],
});
if (resolvedAgent.rootKey == null) throw new Error(`The agent doesn't have a root key yet`);
const cert = await Certificate.create({
certificate: response.certificate,
rootKey: resolvedAgent.rootKey,
canisterId: canisterId,
canisterId: ecid,
});
expect(cert.lookup([new TextEncoder().encode('Time')])).toEqual({
status: LookupStatus.Unknown,
});
expect(cert.lookup([new TextEncoder().encode('Time')])).toEqual({ status: LookupStatus.Unknown });

let rawTime = cert.lookup(path);

Expand All @@ -51,7 +78,7 @@ test('read_state with passed request', async () => {
const resolvedAgent = await agent;
const now = Date.now() / 1000;
const path = [new TextEncoder().encode('time')];
const canisterId = Principal.fromHex('00000000000000000001');
const canisterId = await getDefaultEffectiveCanisterId();
const request = await resolvedAgent.createReadStateRequest({ paths: [path] });
const response = await resolvedAgent.readState(
canisterId,
Expand All @@ -67,7 +94,9 @@ test('read_state with passed request', async () => {
rootKey: resolvedAgent.rootKey,
canisterId: canisterId,
});
expect(cert.lookup([new TextEncoder().encode('Time')])).toEqual({ status: LookupStatus.Unknown });
expect(cert.lookup([new TextEncoder().encode('Time')])).toEqual({
status: LookupStatus.Unknown,
});

let rawTime = cert.lookup(path);

Expand All @@ -90,18 +119,6 @@ test('read_state with passed request', async () => {
expect(Math.abs(time - now) < 5).toBe(true);
});

test('createCanister', async () => {
// Make sure this doesn't fail.
await getManagementCanister({
agent: await agent,
}).provisional_create_canister_with_cycles({
amount: [BigInt(1e12)],
settings: [],
specified_id: [],
sender_canister_version: [],
});
});

test('withOptions', async () => {
// Make sure this fails.
await expect(
Expand Down
6 changes: 5 additions & 1 deletion e2e/node/canisters/counter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { readFileSync } from 'fs';
import path from 'path';
import agent, { makeAgent } from '../utils/agent';
import { _SERVICE } from './declarations/counter';
import { getDefaultEffectiveCanisterId } from '../basic/basic.test';

let cache: {
canisterId: Principal;
Expand Down Expand Up @@ -61,7 +62,10 @@ export const createActor = async (options?: HttpAgentOptions, agent?: Agent) =>
//
}

const canisterId = await Actor.createCanister({ agent: effectiveAgent });
const canisterId = await Actor.createCanister({
agent: effectiveAgent,
effectiveCanisterId: await getDefaultEffectiveCanisterId(),
});
await Actor.install({ module }, { canisterId, agent: effectiveAgent });
return Actor.createActor(idl, { canisterId, agent: effectiveAgent }) as ActorSubclass<_SERVICE>;
};
Loading