|
1 | | -import { Actor, AnonymousIdentity, HttpAgent, Identity } from '@dfinity/agent'; |
| 1 | +import { Actor, AnonymousIdentity, HttpAgent, Identity, CanisterStatus } from '@dfinity/agent'; |
2 | 2 | import { IDL } from '@dfinity/candid'; |
3 | 3 | import { Ed25519KeyIdentity } from '@dfinity/identity'; |
4 | 4 | import { Principal } from '@dfinity/principal'; |
5 | | -import { describe, it, expect, vi } from 'vitest'; |
| 5 | +import { describe, it, expect, test, vi } from 'vitest'; |
6 | 6 | import { makeAgent } from '../utils/agent'; |
7 | 7 |
|
8 | 8 | const createWhoamiActor = async (identity: Identity) => { |
@@ -113,3 +113,50 @@ describe('certified query', () => { |
113 | 113 | `); |
114 | 114 | }); |
115 | 115 | }); |
| 116 | + |
| 117 | +describe('controllers', () => { |
| 118 | + it('should return the controllers of a canister with multiple controllers', async () => { |
| 119 | + const agent = new HttpAgent({ host: 'https://icp-api.io' }); |
| 120 | + const status = await CanisterStatus.request({ |
| 121 | + // Whoami canister |
| 122 | + canisterId: Principal.from('ivcos-eqaaa-aaaab-qablq-cai'), |
| 123 | + agent: agent, |
| 124 | + paths: ['controllers'], |
| 125 | + }); |
| 126 | + expect((status.get('controllers') as Principal[]).map(p => p.toText())).toMatchInlineSnapshot(` |
| 127 | + [ |
| 128 | + "hgfyw-myaaa-aaaab-qaaoa-cai", |
| 129 | + "b73qn-rqaaa-aaaap-aazvq-cai", |
| 130 | + "aux4w-bi6yf-a3bhr-zydhx-qvf2p-ymdeg-ddvg6-gmobi-ct4dk-wf4xd-nae", |
| 131 | + "jhnlf-yu2dz-v7beb-c77gl-76tj7-shaqo-5qfvi-htvel-gzamb-bvzx6-yqe", |
| 132 | + ] |
| 133 | + `); |
| 134 | + }); |
| 135 | + it('should return the controllers of a canister with one controller', async () => { |
| 136 | + const agent = new HttpAgent({ host: 'https://icp-api.io' }); |
| 137 | + const status = await CanisterStatus.request({ |
| 138 | + // NNS Governance Canister |
| 139 | + canisterId: Principal.from('rrkah-fqaaa-aaaaa-aaaaq-cai'), |
| 140 | + agent: agent, |
| 141 | + paths: ['controllers'], |
| 142 | + }); |
| 143 | + // Should be root canister |
| 144 | + expect((status.get('controllers') as Principal[]).map(p => p.toText())).toMatchInlineSnapshot(` |
| 145 | + [ |
| 146 | + "r7inp-6aaaa-aaaaa-aaabq-cai", |
| 147 | + ] |
| 148 | + `); |
| 149 | + }); |
| 150 | + it('should return the controllers of a canister with no controllers', async () => { |
| 151 | + const agent = new HttpAgent({ host: 'https://icp-api.io' }); |
| 152 | + const status = await CanisterStatus.request({ |
| 153 | + // nomeata's capture-the-ic-token canister |
| 154 | + canisterId: Principal.from('fj6bh-taaaa-aaaab-qaacq-cai'), |
| 155 | + agent: agent, |
| 156 | + paths: ['controllers'], |
| 157 | + }); |
| 158 | + expect((status.get('controllers') as Principal[]).map(p => p.toText())).toMatchInlineSnapshot(` |
| 159 | + [] |
| 160 | + `); |
| 161 | + }); |
| 162 | +}); |
0 commit comments