Skip to content

Commit

Permalink
feat: improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
marcomariscal committed Apr 4, 2024
1 parent cb12486 commit 1a770c0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/lib/actions/prepareRegisterKeys/prepareRegisterKeys.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import setupTestEnv from '../../helpers/test/setupTestEnv';
import setupTestWallet from '../../helpers/test/setupTestWallet';
import { VALID_SCHEME_ID, parseStealthMetaAddressURI } from '../../..';
import setupTestStealthKeys from '../../helpers/test/setupTestStealthKeys';
import { PrepareError } from '../types';

describe('prepareRegisterKeys', async () => {
const { stealthClient, ERC6538Address } = await setupTestEnv();
Expand All @@ -15,12 +16,14 @@ describe('prepareRegisterKeys', async () => {
});
const account = walletClient.account?.address!;

const prepared = await stealthClient.prepareRegisterKeys({
const prepareArgs = {
account,
ERC6538Address,
schemeId,
stealthMetaAddress: stealthMetaAddressToRegister,
});
};

const prepared = await stealthClient.prepareRegisterKeys(prepareArgs);

// Prepare tx using viem and the prepared payload
const request = await walletClient.prepareTransactionRequest({
Expand All @@ -36,6 +39,16 @@ describe('prepareRegisterKeys', async () => {

const res = await walletClient.waitForTransactionReceipt({ hash });

test('should throw PrepareError when given invalid contract address', () => {
const invalidERC6538Address = '0xinvalid';
expect(
stealthClient.prepareRegisterKeys({
...prepareArgs,
ERC6538Address: invalidERC6538Address,
})
).rejects.toBeInstanceOf(PrepareError);
});

test('should successfully register a stealth meta-address using the prepare payload', () => {
expect(res.status).toEqual('success');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from '../../..';
import setupTestStealthKeys from '../../helpers/test/setupTestStealthKeys';
import type { RegisterKeysOnBehalfArgs } from './types';
import { PrepareError } from '../types';

describe('prepareRegisterKeysOnBehalf', async () => {
const { stealthClient, ERC6538Address, chainId } = await setupTestEnv();
Expand Down Expand Up @@ -93,6 +94,17 @@ describe('prepareRegisterKeysOnBehalf', async () => {

const res = await walletClient.waitForTransactionReceipt({ hash });

test('should throw PrepareError when given invalid contract address', () => {
const invalidERC6538Address = '0xinvalid';
expect(
stealthClient.prepareRegisterKeysOnBehalf({
account,
ERC6538Address: invalidERC6538Address,
args,
})
).rejects.toBeInstanceOf(PrepareError);
});

test('should successfully register a stealth meta-address on behalf using the prepare payload', () => {
expect(res.status).toEqual('success');
});
Expand Down

0 comments on commit 1a770c0

Please sign in to comment.