-
Notifications
You must be signed in to change notification settings - Fork 86
/
canisterStatus.test.ts
43 lines (40 loc) · 1.39 KB
/
canisterStatus.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { CanisterStatus, HttpAgent } from '@dfinity/agent';
import { Principal } from '@dfinity/principal';
import counter from '../canisters/counter';
jest.setTimeout(30_000);
afterEach(async () => {
await Promise.resolve();
});
describe.only('canister status', () => {
it('should fetch successfully', async () => {
const counterObj = await (await counter)();
const agent = new HttpAgent({ host: `http://localhost:${process.env.REPLICA_PORT}` });
await agent.fetchRootKey();
const request = await CanisterStatus.request({
canisterId: Principal.from(counterObj.canisterId),
agent,
paths: ['controllers'],
});
expect(Array.isArray(request.get('controllers'))).toBe(true);
});
it('should throw an error if fetchRootKey has not been called', async () => {
const counterObj = await (await counter)();
const agent = new HttpAgent({ host: `http://localhost:${process.env.REPLICA_PORT}` });
const shouldThrow = async () => {
// eslint-disable-next-line no-useless-catch
try {
const request = await CanisterStatus.request({
canisterId: Principal.from(counterObj.canisterId),
agent,
paths: ['controllers'],
}).catch(error => {
throw error;
});
console.log(request);
} catch (error) {
throw error;
}
};
expect(shouldThrow).rejects.toThrow();
});
});