Skip to main content
Glama
faucet.test.ts1.82 kB
import { jest } from '@jest/globals'; import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519'; // Use unstable_mockModule to mock ESM modules const mockGetFaucetHost = jest.fn(); const mockRequestSuiFromFaucetV1 = jest.fn(); jest.unstable_mockModule('@mysten/sui/faucet', () => ({ getFaucetHost: mockGetFaucetHost, requestSuiFromFaucetV1: mockRequestSuiFromFaucetV1, })); // Must dynamically import modules after mocking describe('getFaucet', () => { let getFaucet: any; beforeEach(async () => { jest.clearAllMocks(); console.error = jest.fn(); // Dynamically import the module being tested const faucetModule = await import('../../src/utils/faucet.js'); getFaucet = faucetModule.getFaucet; }); const recipient = Ed25519Keypair.generate().toSuiAddress(); it('should return true if the faucet request is successful', async () => { mockGetFaucetHost.mockReturnValue('http://127.0.0.1:9123'); mockRequestSuiFromFaucetV1.mockResolvedValue({} as never); const result = await getFaucet(recipient, 'testnet'); expect(result).toBe(true); }); it('should return false if the faucet request fails', async () => { mockGetFaucetHost.mockReturnValue('http://127.0.0.1:9123'); // Use generic function to mock throwing an error mockRequestSuiFromFaucetV1.mockImplementation(() => { throw new Error('Faucet error'); }); const result = await getFaucet(recipient, 'testnet'); expect(result).toBe(false); }); it('should return false if the faucet response has an error', async () => { mockGetFaucetHost.mockReturnValue('http://127.0.0.1:9123'); mockRequestSuiFromFaucetV1.mockResolvedValue({ error: 'Some error' } as never); const result = await getFaucet(recipient, 'testnet'); expect(result).toBe(false); }); });

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/0xdwong/sui-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server