Files
trezor-suite/packages/connect/e2e/tests/api/init.test.ts
2026-02-06 10:07:34 +01:00

77 lines
2.4 KiB
TypeScript

// eslint-disable-next-line import/no-extraneous-dependencies
import TrezorConnect from '@trezor/connect';
// error thrown by .init()
const INIT_ERROR = { code: 'Init_ManifestMissing' };
describe('TrezorConnect.init', () => {
afterEach(() => {
TrezorConnect.dispose();
});
it('calling method before .init()', async () => {
const { payload } = await TrezorConnect.getCoinInfo({ coin: 'btc' });
expect(payload).toMatchObject(INIT_ERROR);
});
it('missing manifest in TrezorConnect.init', async () => {
try {
// @ts-expect-error
await TrezorConnect.init();
throw new Error('Should not be resolved');
} catch (error) {
expect(error).toMatchObject(INIT_ERROR);
}
});
it('invalid manifest in TrezorConnect.init', async () => {
try {
// @ts-expect-error
await TrezorConnect.init({ manifest: {} });
throw new Error('Should not be resolved');
} catch (error) {
expect(error).toMatchObject(INIT_ERROR);
}
});
it('calling .init() multiple times', async () => {
await TrezorConnect.init({
manifest: { appName: 'a', appUrl: 'a', email: 'b' },
});
try {
await TrezorConnect.init({
manifest: { appName: 'a', appUrl: 'a', email: 'b' },
});
throw new Error('Should not be resolved');
} catch (error) {
expect(error).toMatchObject({ code: 'Init_AlreadyInitialized' });
}
});
it('calling multiple methods synchronously', async () => {
await TrezorConnect.init({
manifest: { appName: 'a', appUrl: 'a', email: 'b' },
});
const result = await Promise.all([
TrezorConnect.getCoinInfo({ coin: 'btc' }),
TrezorConnect.blockchainEstimateFee({ request: { blocks: [1] }, coin: 'test' }),
]);
// success, success
expect(result.map(r => r.success)).toEqual([true, true]);
});
it('init success', async () => {
await TrezorConnect.init({
manifest: { appName: 'a', appUrl: 'a', email: 'b' },
});
const resp = await TrezorConnect.getCoinInfo({ coin: 'btc' });
expect(resp).toMatchObject({
payload: { type: 'bitcoin', shortcut: 'BTC' },
});
});
});