Skip to content

Commit

Permalink
tests() add tests on createInstance rejection
Browse files Browse the repository at this point in the history
  • Loading branch information
immortal-tofu committed Jul 15, 2023
1 parent 69ab0d7 commit 3c53cc8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/sdk/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ describe('token', () => {
expect(instance.hasKeypair).toBeDefined();
});

it('fails to create an instance', async () => {
await expect(createInstance({ chainId: BigInt(1234) as any, publicKey: tfhePublicKey })).rejects.toThrow(
'chainId must be a number'
);

await expect(createInstance({ chainId: 9000, publicKey: 43 as any })).rejects.toThrow('publicKey must be a string');
});

it('creates an instance with keypairs', async () => {
const keypair = sodium.crypto_box_keypair('hex');

Expand Down
4 changes: 2 additions & 2 deletions src/sdk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ export type FhevmInstanceParams = {
export const createInstance = async (params: FhevmInstanceParams): Promise<FhevmInstance> => {
await sodium.ready;
const { chainId, publicKey, keypairs } = params;
if (typeof chainId !== 'number') throw new Error('chainId must be a number.');
if (typeof publicKey !== 'string') throw new Error('publicKey must be a string.');
if (typeof chainId !== 'number') throw new Error('chainId must be a number');
if (typeof publicKey !== 'string') throw new Error('publicKey must be a string');
const buff = fromHexString(publicKey);
const tfheCompactPublicKey = TfheCompactPublicKey.deserialize(buff);

Expand Down

0 comments on commit 3c53cc8

Please sign in to comment.