Skip to content

Commit c51b689

Browse files
authored
test: fixes e2e tests for compatibility with dfx 0.26.0 (#996)
1 parent ae261e2 commit c51b689

File tree

3 files changed

+41
-19
lines changed

3 files changed

+41
-19
lines changed

docs/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
### Changed
77

8+
- 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
89
- fix: fixes a bug in the Ed25519KeyIdentity verify implementation where the argument order was incorrect
910
- fix: fixes a bug in the `Principal` library where the management canister id util was incorrectly importing using `fromHex`
1011
- feat: change auth-client's default identity provider url

e2e/node/basic/basic.test.ts

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,48 @@ import { Principal } from '@dfinity/principal';
1010
import agent from '../utils/agent';
1111
import { test, expect } from 'vitest';
1212

13+
/**
14+
* Util for determining the default effective canister id, necessary for pocketic
15+
* @returns the default effective canister id
16+
*/
17+
export async function getDefaultEffectiveCanisterId() {
18+
const res = await fetch('http://localhost:4943/_/topology'); //?
19+
const data = await res.json(); //?
20+
const id = data['default_effective_canister_id']['canister_id'];
21+
// decode from base64
22+
const decoded = Buffer.from(id, 'base64').toString('hex');
23+
24+
return Principal.fromHex(decoded);
25+
}
26+
27+
test('createCanister', async () => {
28+
// Make sure this doesn't fail.
29+
await getManagementCanister({
30+
agent: await agent,
31+
}).provisional_create_canister_with_cycles({
32+
amount: [BigInt(1e12)],
33+
settings: [],
34+
specified_id: [],
35+
sender_canister_version: [],
36+
});
37+
});
1338
test('read_state', async () => {
39+
const ecid = await getDefaultEffectiveCanisterId();
1440
const resolvedAgent = await agent;
1541
const now = Date.now() / 1000;
1642
const path = [new TextEncoder().encode('time')];
17-
const canisterId = Principal.fromHex('00000000000000000001');
18-
const response = await resolvedAgent.readState(canisterId, {
43+
const response = await resolvedAgent.readState(ecid, {
1944
paths: [path],
2045
});
2146
if (resolvedAgent.rootKey == null) throw new Error(`The agent doesn't have a root key yet`);
2247
const cert = await Certificate.create({
2348
certificate: response.certificate,
2449
rootKey: resolvedAgent.rootKey,
25-
canisterId: canisterId,
50+
canisterId: ecid,
51+
});
52+
expect(cert.lookup([new TextEncoder().encode('Time')])).toEqual({
53+
status: LookupStatus.Unknown,
2654
});
27-
expect(cert.lookup([new TextEncoder().encode('Time')])).toEqual({ status: LookupStatus.Unknown });
2855

2956
let rawTime = cert.lookup(path);
3057

@@ -51,7 +78,7 @@ test('read_state with passed request', async () => {
5178
const resolvedAgent = await agent;
5279
const now = Date.now() / 1000;
5380
const path = [new TextEncoder().encode('time')];
54-
const canisterId = Principal.fromHex('00000000000000000001');
81+
const canisterId = await getDefaultEffectiveCanisterId();
5582
const request = await resolvedAgent.createReadStateRequest({ paths: [path] });
5683
const response = await resolvedAgent.readState(
5784
canisterId,
@@ -67,7 +94,9 @@ test('read_state with passed request', async () => {
6794
rootKey: resolvedAgent.rootKey,
6895
canisterId: canisterId,
6996
});
70-
expect(cert.lookup([new TextEncoder().encode('Time')])).toEqual({ status: LookupStatus.Unknown });
97+
expect(cert.lookup([new TextEncoder().encode('Time')])).toEqual({
98+
status: LookupStatus.Unknown,
99+
});
71100

72101
let rawTime = cert.lookup(path);
73102

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

93-
test('createCanister', async () => {
94-
// Make sure this doesn't fail.
95-
await getManagementCanister({
96-
agent: await agent,
97-
}).provisional_create_canister_with_cycles({
98-
amount: [BigInt(1e12)],
99-
settings: [],
100-
specified_id: [],
101-
sender_canister_version: [],
102-
});
103-
});
104-
105122
test('withOptions', async () => {
106123
// Make sure this fails.
107124
await expect(

e2e/node/canisters/counter.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { readFileSync } from 'fs';
44
import path from 'path';
55
import agent, { makeAgent } from '../utils/agent';
66
import { _SERVICE } from './declarations/counter';
7+
import { getDefaultEffectiveCanisterId } from '../basic/basic.test';
78

89
let cache: {
910
canisterId: Principal;
@@ -61,7 +62,10 @@ export const createActor = async (options?: HttpAgentOptions, agent?: Agent) =>
6162
//
6263
}
6364

64-
const canisterId = await Actor.createCanister({ agent: effectiveAgent });
65+
const canisterId = await Actor.createCanister({
66+
agent: effectiveAgent,
67+
effectiveCanisterId: await getDefaultEffectiveCanisterId(),
68+
});
6569
await Actor.install({ module }, { canisterId, agent: effectiveAgent });
6670
return Actor.createActor(idl, { canisterId, agent: effectiveAgent }) as ActorSubclass<_SERVICE>;
6771
};

0 commit comments

Comments
 (0)