Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: canisterStatus throws if root key is not fetched (#600)
- Loading branch information
Showing
5 changed files
with
60 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { CanisterStatus, HttpAgent } from '@dfinity/agent'; | ||
import { Principal } from '@dfinity/principal'; | ||
import counter from '../canisters/counter'; | ||
|
||
jest.setTimeout(30_000); | ||
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(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters