Skip to content

Commit

Permalink
add test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
alissacrane-cb committed Oct 29, 2024
1 parent 15b4ee1 commit f296883
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/transaction/utils/sendBatchedTransactions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,16 @@ describe('sendBatchedTransactions', () => {
calls: [{ to: '0x123', abi: '123' }],
});
});

it('should transform not transform call', async () => {
await sendBatchedTransactions({
capabilities: mockCapabilities,
sendCallsAsync: mockSendCallsAsync,
transactions: [{ to: '0x123', data: '123' }],
});
expect(mockSendCallsAsync).toHaveBeenCalled({
Capabilities: mockCapabilities,
calls: [{ to: '0x123', data: '123' }],
});
});
});
19 changes: 18 additions & 1 deletion src/transaction/utils/sendSingleTransactions.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { encodeFunctionData } from 'viem';
import { type Mock, beforeEach, describe, expect, it, vi } from 'vitest';
import type { Call } from '../types';
import { sendSingleTransactions } from './sendSingleTransactions';

vi.mock('viem', () => ({
encodeFunctionData: vi.fn(),
}));

describe('sendSingleTransactions', () => {
const mockSendCallAsync = vi.fn();
const transactions: Call[] = [
Expand All @@ -11,6 +16,7 @@ describe('sendSingleTransactions', () => {

beforeEach(() => {
vi.clearAllMocks();
(encodeFunctionData as Mock).mockReturnValue('123');
});

it('should call sendCallAsync for each transaction when type is TRANSACTION_TYPE_CALLS', async () => {
Expand Down Expand Up @@ -50,4 +56,15 @@ describe('sendSingleTransactions', () => {
});
expect(mockSendCallAsync).toHaveBeenCalledTimes(4);
});

it('should transform contracts to calls', async () => {
await sendSingleTransactions({
sendCallAsync: mockSendCallAsync,
transactions: [{ abi: '123', address: '0x123' }],
});
expect(mockSendCallAsync).toHaveBeenCalledWith({
data: '123',
to: '0x123',
});
});
});

0 comments on commit f296883

Please sign in to comment.