Files
smom-dbis-138/metamask-sdk/src/addNetwork.test.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

76 lines
1.9 KiB
TypeScript

/**
* Unit tests for addNetwork functionality
*/
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
import { addNetwork, isNetworkAdded, addOrSwitchNetwork, getEthereumProvider } from './addNetwork';
// Mock window.ethereum
const mockEthereum = {
isMetaMask: true,
request: vi.fn(),
on: vi.fn(),
removeListener: vi.fn(),
};
describe('addNetwork', () => {
beforeEach(() => {
vi.clearAllMocks();
if (typeof window !== 'undefined') {
(window as any).ethereum = mockEthereum;
}
});
afterEach(() => {
if (typeof window !== 'undefined') {
delete (window as any).ethereum;
}
});
it('should get Ethereum provider', () => {
const provider = getEthereumProvider();
expect(provider).toBe(mockEthereum);
});
it('should throw error if MetaMask not installed', () => {
if (typeof window !== 'undefined') {
delete (window as any).ethereum;
}
expect(() => getEthereumProvider()).toThrow('MetaMask is not installed');
});
it('should add network successfully', async () => {
mockEthereum.request.mockResolvedValue(null);
await addNetwork();
expect(mockEthereum.request).toHaveBeenCalledWith({
method: 'wallet_addEthereumChain',
params: [expect.objectContaining({
chainId: '0x8a',
chainName: 'DeFi Oracle Meta Mainnet',
})],
});
});
it('should check if network is added', async () => {
mockEthereum.request.mockResolvedValue('0x8a');
const isAdded = await isNetworkAdded();
expect(isAdded).toBe(true);
});
it('should add or switch network', async () => {
mockEthereum.request.mockResolvedValueOnce('0x1'); // Current chain
mockEthereum.request.mockResolvedValueOnce(null); // Switch network
await addOrSwitchNetwork();
expect(mockEthereum.request).toHaveBeenCalledWith({
method: 'wallet_switchEthereumChain',
params: [{ chainId: '0x8a' }],
});
});
});