Skip to content
707 changes: 707 additions & 0 deletions e2e/synpress/pr1330-manual-qa.spec.ts

Large diffs are not rendered by default.

1,980 changes: 1 addition & 1,979 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
"url": "^0.11.1",
"viem": "^2.13.3",
"web-vitals": "^2.1.4",
"web3": "^1.8.1",
"webln": "^0.3.2"
},
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions playwright.synpress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default defineConfig({
'sepolia-real-tx.spec.ts',
'sell-complete.spec.ts',
'sepolia-sell-e2e.spec.ts', // New complete E2E test
'pr1330-manual-qa.spec.ts', // PR #1330 metamask/web3 viem-port manual-QA evidence
],
snapshotDir: './e2e/screenshots',
snapshotPathTemplate: '{snapshotDir}/{testFileName}-{arg}-{projectName}-{platform}{ext}',
Expand Down
30 changes: 0 additions & 30 deletions src/__tests__/eip5792-real-hooks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,36 +74,6 @@ jest.mock('../hooks/web3.hook', () => ({
}),
}));

// Mock Web3 - simplified, no window access
jest.mock('web3', () => {
const mockAccount = '0x1234567890123456789012345678901234567890';
const MockWeb3: any = function (this: any) {
this.eth = {
getAccounts: jest.fn().mockResolvedValue([mockAccount]),
getChainId: jest.fn().mockResolvedValue(1),
requestAccounts: jest.fn().mockResolvedValue([mockAccount]),
getBalance: jest.fn().mockResolvedValue('1000000000000000000'),
personal: { sign: jest.fn() },
sendTransaction: jest.fn(),
Contract: jest.fn().mockReturnValue({ methods: {} }),
};
this.utils = {
toChecksumAddress: (addr: string) => addr,
toHex: (val: number) => `0x${val.toString(16)}`,
toWei: (val: string) => val,
fromWei: (val: string) => val,
};
};
MockWeb3.givenProvider = {};
MockWeb3.utils = {
toChecksumAddress: (addr: string) => addr,
toHex: (val: number) => `0x${val.toString(16)}`,
toWei: (val: string) => val,
fromWei: (val: string) => val,
};
return MockWeb3;
});

// Mock react-device-detect
jest.mock('react-device-detect', () => ({
isMobile: false,
Expand Down
103 changes: 103 additions & 0 deletions src/hooks/__tests__/web3.hook.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import { renderHook } from '@testing-library/react';

// Mock @dfx.swiss/react (ships untransformed ESM); values mirror the real Blockchain enum
jest.mock('@dfx.swiss/react', () => ({
Blockchain: {
BITCOIN: 'Bitcoin',
ETHEREUM: 'Ethereum',
SEPOLIA: 'Sepolia',
BINANCE_SMART_CHAIN: 'BinanceSmartChain',
OPTIMISM: 'Optimism',
ARBITRUM: 'Arbitrum',
POLYGON: 'Polygon',
BASE: 'Base',
GNOSIS: 'Gnosis',
HAQQ: 'Haqq',
CITREA: 'Citrea',
CITREA_TESTNET: 'CitreaTestnet',
},
}));

import { Blockchain } from '@dfx.swiss/react';
import { useWeb3 } from '../web3.hook';

function setup() {
const { result } = renderHook(() => useWeb3());
return result.current;
}

describe('useWeb3', () => {
describe('toBlockchain', () => {
it('maps a numeric chain id', () => {
expect(setup().toBlockchain(1)).toBe(Blockchain.ETHEREUM);
});

it('maps a decimal string chain id', () => {
expect(setup().toBlockchain('137')).toBe(Blockchain.POLYGON);
});

it('maps a hex string chain id', () => {
expect(setup().toBlockchain('0x38')).toBe(Blockchain.BINANCE_SMART_CHAIN);
});

it('returns undefined for an unknown chain id', () => {
expect(setup().toBlockchain(999)).toBeUndefined();
});
});

describe('toChainId', () => {
it('returns the chain id of a mapped blockchain', () => {
expect(setup().toChainId(Blockchain.ETHEREUM)).toBe('1');
});

it('returns undefined for an unmapped blockchain', () => {
expect(setup().toChainId(Blockchain.BITCOIN)).toBeUndefined();
});
});

describe('toChainHex', () => {
it('returns the chain id as hex', () => {
expect(setup().toChainHex(Blockchain.ARBITRUM)).toBe('0xa4b1');
});

it('returns undefined for an unmapped blockchain', () => {
expect(setup().toChainHex(Blockchain.BITCOIN)).toBeUndefined();
});
});

describe('toChainObject', () => {
it('returns the full MetaMask chain parameters', () => {
expect(setup().toChainObject(Blockchain.BINANCE_SMART_CHAIN)).toEqual({
chainId: '0x38',
chainName: 'BNB Smart Chain Mainnet',
nativeCurrency: {
name: 'BNB',
symbol: 'BNB',
decimals: 18,
},
rpcUrls: ['https://bsc-dataseed.binance.org/'],
blockExplorerUrls: ['https://bscscan.com/'],
});
});

it.each([
[Blockchain.ETHEREUM, '0x1', 'Ethereum Mainnet'],
[Blockchain.SEPOLIA, '0xaa36a7', 'Ethereum Sepolia'],
[Blockchain.BINANCE_SMART_CHAIN, '0x38', 'BNB Smart Chain Mainnet'],
[Blockchain.ARBITRUM, '0xa4b1', 'Arbitrum One'],
[Blockchain.OPTIMISM, '0xa', 'OP Mainnet'],
[Blockchain.POLYGON, '0x89', 'Polygon Mainnet'],
[Blockchain.BASE, '0x2105', 'Base'],
[Blockchain.GNOSIS, '0x64', 'Gnosis'],
[Blockchain.HAQQ, '0x2be3', 'Haqq Network'],
[Blockchain.CITREA, '0x1012', 'Citrea'],
[Blockchain.CITREA_TESTNET, '0x13fb', 'Citrea Testnet'],
])('describes %s with chain id %s', (blockchain, chainId, chainName) => {
expect(setup().toChainObject(blockchain)).toMatchObject({ chainId, chainName });
});

it('returns undefined for an unmapped blockchain', () => {
expect(setup().toChainObject(Blockchain.BITCOIN)).toBeUndefined();
});
});
});
Loading
Loading