Skip to content

Commit

Permalink
fix: canisterStatus returns full list of controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
krpeacock committed Nov 13, 2023
1 parent 963ef63 commit 6b4e939
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
1 change: 1 addition & 0 deletions docs/generated/changelog.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ <h1>Agent-JS Changelog</h1>
<section>
<h2>Version x.x.x</h2>
<ul>
<li>fix: canisterStatus returns full list of controllers</li>
<ul>
<strong>feat!: node signature verification</strong
><br />
Expand Down
36 changes: 34 additions & 2 deletions e2e/node/basic/mainnet.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Actor, AnonymousIdentity, HttpAgent, Identity } from '@dfinity/agent';
import { Actor, AnonymousIdentity, HttpAgent, Identity, CanisterStatus } from '@dfinity/agent';
import { IDL } from '@dfinity/candid';
import { Ed25519KeyIdentity } from '@dfinity/identity';
import { Principal } from '@dfinity/principal';
import { describe, it, expect, vi } from 'vitest';
import { describe, it, expect, test, vi } from 'vitest';
import { makeAgent } from '../utils/agent';

const createWhoamiActor = async (identity: Identity) => {
Expand Down Expand Up @@ -113,3 +113,35 @@ describe('certified query', () => {
`);
});
});

describe('controllers', () => {
it('should return the controllers of a canister with multiple controllers', async () => {
const agent = new HttpAgent({ host: 'https://icp-api.io' });
const status = await CanisterStatus.request({
canisterId: Principal.from('ivcos-eqaaa-aaaab-qablq-cai'),
agent: agent,
paths: ['controllers'],
});
expect((status.get('controllers') as Principal[]).map(p => p.toText())).toMatchInlineSnapshot(`
[
"hgfyw-myaaa-aaaab-qaaoa-cai",
"b73qn-rqaaa-aaaap-aazvq-cai",
"aux4w-bi6yf-a3bhr-zydhx-qvf2p-ymdeg-ddvg6-gmobi-ct4dk-wf4xd-nae",
"jhnlf-yu2dz-v7beb-c77gl-76tj7-shaqo-5qfvi-htvel-gzamb-bvzx6-yqe",
]
`);
});
it('should return the controllers of a canister with one controller', async () => {
const agent = new HttpAgent({ host: 'https://icp-api.io' });
const status = await CanisterStatus.request({
canisterId: Principal.from('rrkah-fqaaa-aaaaa-aaaaq-cai'),
agent: agent,
paths: ['controllers'],
});
expect((status.get('controllers') as Principal[]).map(p => p.toText())).toMatchInlineSnapshot(`
[
"r7inp-6aaaa-aaaaa-aaabq-cai",
]
`);
});
});
4 changes: 2 additions & 2 deletions packages/agent/src/canisterStatus/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,10 +349,10 @@ const decodeUtf8 = (buf: ArrayBuffer): string => {
return new TextDecoder().decode(buf);
};

// Controllers are CBOR-encoded buffers, starting with a Tag we don't need
// Controllers are CBOR-encoded buffers
const decodeControllers = (buf: ArrayBuffer): Principal[] => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [tag, ...controllersRaw] = decodeCbor(buf);
const controllersRaw = decodeCbor(buf);
return controllersRaw.map((buf: ArrayBuffer) => {
return Principal.fromUint8Array(new Uint8Array(buf));
});
Expand Down

0 comments on commit 6b4e939

Please sign in to comment.