Files
smom-dbis-138/tests/e2e/metamask.spec.ts
defiQUG 1fb7266469 Add Oracle Aggregator and CCIP Integration
- Introduced Aggregator.sol for Chainlink-compatible oracle functionality, including round-based updates and access control.
- Added OracleWithCCIP.sol to extend Aggregator with CCIP cross-chain messaging capabilities.
- Created .gitmodules to include OpenZeppelin contracts as a submodule.
- Developed a comprehensive deployment guide in NEXT_STEPS_COMPLETE_GUIDE.md for Phase 2 and smart contract deployment.
- Implemented Vite configuration for the orchestration portal, supporting both Vue and React frameworks.
- Added server-side logic for the Multi-Cloud Orchestration Portal, including API endpoints for environment management and monitoring.
- Created scripts for resource import and usage validation across non-US regions.
- Added tests for CCIP error handling and integration to ensure robust functionality.
- Included various new files and directories for the orchestration portal and deployment scripts.
2025-12-12 14:57:48 -08:00

143 lines
3.9 KiB
TypeScript

/**
* MetaMask E2E Tests
*
* End-to-end tests for MetaMask integration using Playwright
*/
import { test, expect } from '@playwright/test';
const CHAIN_ID = '0x8a';
const NETWORK_NAME = 'DeFi Oracle Meta Mainnet';
test.describe('MetaMask Integration', () => {
test.beforeEach(async ({ page }) => {
// Navigate to test page
await page.goto('http://localhost:3000');
});
test('should add network to MetaMask', async ({ page, context }) => {
// Mock window.ethereum
await page.addInitScript(() => {
(window as any).ethereum = {
isMetaMask: true,
request: async (args: { method: string; params?: unknown[] }) => {
if (args.method === 'wallet_addEthereumChain') {
return null;
}
if (args.method === 'eth_chainId') {
return CHAIN_ID;
}
return null;
},
on: () => {},
removeListener: () => {},
};
});
// Click add network button
await page.click('button:has-text("Add ChainID 138")');
// Wait for network addition
await page.waitForTimeout(1000);
// Verify network was added
const status = await page.textContent('#status');
expect(status).toContain('Network added successfully');
});
test('should switch to ChainID 138', async ({ page }) => {
// Mock window.ethereum
await page.addInitScript(() => {
(window as any).ethereum = {
isMetaMask: true,
request: async (args: { method: string; params?: unknown[] }) => {
if (args.method === 'wallet_switchEthereumChain') {
return null;
}
if (args.method === 'eth_chainId') {
return CHAIN_ID;
}
return null;
},
on: () => {},
removeListener: () => {},
};
});
// Click switch network button
await page.click('button:has-text("Switch to ChainID 138")');
// Wait for network switch
await page.waitForTimeout(1000);
// Verify network was switched
const status = await page.textContent('#status');
expect(status).toContain('Switched to ChainID 138');
});
test('should add token to MetaMask', async ({ page }) => {
// Mock window.ethereum
await page.addInitScript(() => {
(window as any).ethereum = {
isMetaMask: true,
request: async (args: { method: string; params?: unknown[] }) => {
if (args.method === 'wallet_watchAsset') {
return null;
}
return null;
},
on: () => {},
removeListener: () => {},
};
});
// Click add token button
await page.click('button:has-text("Add WETH Token")');
// Wait for token addition
await page.waitForTimeout(1000);
// Verify token was added
const status = await page.textContent('#status');
expect(status).toContain('Token added successfully');
});
test('should handle MetaMask not installed', async ({ page }) => {
// Don't mock window.ethereum
// Click add network button
await page.click('button:has-text("Add ChainID 138")');
// Verify error message
const status = await page.textContent('#status');
expect(status).toContain('MetaMask is not installed');
});
test('should handle user rejection', async ({ page }) => {
// Mock window.ethereum with user rejection
await page.addInitScript(() => {
(window as any).ethereum = {
isMetaMask: true,
request: async () => {
const error = new Error('User rejected');
(error as any).code = 4001;
throw error;
},
on: () => {},
removeListener: () => {},
};
});
// Click add network button
await page.click('button:has-text("Add ChainID 138")');
// Wait for error
await page.waitForTimeout(1000);
// Verify error message
const status = await page.textContent('#status');
expect(status).toContain('User rejected');
});
});