-
-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: drptbl <jakub.mucha@icloud.com> Co-authored-by: drptbl <jakub.mucha@icloud.com>
- Loading branch information
Showing
7 changed files
with
139 additions
and
11 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
export { default as mockEthereum } from './mockEthereum' | ||
export * from './mockTransaction' | ||
export * from './sendTransaction' | ||
export * from '../constants' |
23 changes: 23 additions & 0 deletions
23
wallets/ethereum-wallet-mock/src/playwright/utils/mockTransaction.ts
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,23 @@ | ||
import type { Page } from '@playwright/test' | ||
|
||
/** | ||
* Mocks an Ethereum transaction using Web3Mock | ||
* @param page - Playwright page instance | ||
* @param params - Array of transaction parameters [to, from, value] | ||
* @returns Promise that resolves to the Web3Mock mock result | ||
*/ | ||
export const mockTransaction = async (page: Page, params: [string, string, string]) => { | ||
return page.evaluate( | ||
([params]) => { | ||
return Web3Mock.mock({ | ||
blockchain: 'ethereum', | ||
transaction: { | ||
to: params?.[0], | ||
from: params?.[1], | ||
value: params?.[2] | ||
} | ||
}) | ||
}, | ||
[params] | ||
) | ||
} |
17 changes: 17 additions & 0 deletions
17
wallets/ethereum-wallet-mock/src/playwright/utils/sendTransaction.ts
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,17 @@ | ||
interface SendTransactionParams { | ||
to: string | ||
from: string | ||
value: string | ||
} | ||
|
||
/** | ||
* Sends an Ethereum transaction using Web3Mock | ||
* @param params - Transaction parameters {to: string, from: string, value: string} | ||
* @returns Promise that resolves to the transaction hash | ||
*/ | ||
export const sendTransaction = (params: SendTransactionParams): Promise<string> => { | ||
return window.ethereum.request({ | ||
method: 'eth_sendTransaction', | ||
params: [params] | ||
}) | ||
} |
57 changes: 57 additions & 0 deletions
57
wallets/ethereum-wallet-mock/test/playwright/mock/sendTransaction.spec.ts
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,57 @@ | ||
import { ACCOUNT_MOCK } from '../../../src/constants' | ||
import test from '../../../src/playwright/synpress' | ||
|
||
const { expect } = test | ||
|
||
const TO_ADDRESS = '0x5Af489c8786A018EC4814194dC8048be1007e390' | ||
const VALUE = '2000000000000000000' // 2 ETH | ||
|
||
test('should mock and send transaction', async ({ ethereumWalletMock }) => { | ||
// Connect wallet first | ||
await ethereumWalletMock.connectToDapp() | ||
|
||
// Send the transaction | ||
const txHash = await ethereumWalletMock.sendTransaction(TO_ADDRESS, VALUE) | ||
|
||
// Verify transaction hash format | ||
expect(txHash).toMatch(/^0x[a-fA-F0-9]{64}$/) | ||
}) | ||
|
||
test('should mock and send transaction with zero value', async ({ ethereumWalletMock }) => { | ||
await ethereumWalletMock.connectToDapp() | ||
|
||
const txHash = await ethereumWalletMock.sendTransaction(TO_ADDRESS, '0') | ||
|
||
expect(txHash).toMatch(/^0x[a-fA-F0-9]{64}$/) | ||
}) | ||
|
||
test('should mock and send transaction to same address', async ({ ethereumWalletMock }) => { | ||
await ethereumWalletMock.connectToDapp() | ||
|
||
const txHash = await ethereumWalletMock.sendTransaction(ACCOUNT_MOCK, VALUE) | ||
|
||
expect(txHash).toMatch(/^0x[a-fA-F0-9]{64}$/) | ||
}) | ||
|
||
test('should mock and send multiple transactions', async ({ ethereumWalletMock }) => { | ||
await ethereumWalletMock.connectToDapp() | ||
|
||
const transactions = [ | ||
{ to: TO_ADDRESS, value: '1000000000000000000' }, // 1 ETH | ||
{ to: TO_ADDRESS, value: '3000000000000000000' }, // 3 ETH | ||
{ to: TO_ADDRESS, value: '500000000000000000' } // 0.5 ETH | ||
] | ||
|
||
for (const tx of transactions) { | ||
const txHash = await ethereumWalletMock.sendTransaction(tx.to, tx.value) | ||
expect(txHash).toMatch(/^0x[a-fA-F0-9]{64}$/) | ||
} | ||
}) | ||
|
||
test('should fail with invalid value', async ({ ethereumWalletMock }) => { | ||
await ethereumWalletMock.connectToDapp() | ||
|
||
const invalidValue = 'invalid' | ||
|
||
await expect(ethereumWalletMock.sendTransaction(TO_ADDRESS, invalidValue)).rejects.toThrow() | ||
}) |