/** * @jest-environment jsdom */ import Hypernative from '.' import Mpc from '../../../mpc' import portalMock from '../../../__mocks/portal/portal' import { mockHost, mockScanAddressesRequest, mockScanAddressesResponse, mockScanEVMTxRequest, mockScanEVMTxResponse, mockScanEip712TxRequest, mockScanEip712TxResponse, mockScanSolanaTxRequest, mockScanSolanaTxResponse, mockScanNftRequest, mockScanNftResponse, mockScanTokenRequest, mockScanTokenResponse, mockScanUrlRequest, mockScanUrlResponse, } from '../../../__mocks/constants' describe('Hypernative', () => { let hypernative: Hypernative let mpc: Mpc beforeEach(() => { jest.clearAllMocks() portalMock.host = mockHost mpc = new Mpc({ portal: portalMock, }) hypernative = new Hypernative({ mpc }) }) describe('scanEVMTx', () => { it('should call mpc.scanEVMTx with the correct arguments', async () => { const spy = jest .spyOn(mpc, 'scanEVMTx') .mockResolvedValue(mockScanEVMTxResponse) const result = await hypernative.scanEVMTx(mockScanEVMTxRequest) expect(spy).toHaveBeenCalledWith(mockScanEVMTxRequest) expect(result).toEqual(mockScanEVMTxResponse) }) it('should propagate errors from mpc.scanEVMTx', async () => { const error = new Error('Test error') jest.spyOn(mpc, 'scanEVMTx').mockRejectedValue(error) await expect( hypernative.scanEVMTx(mockScanEVMTxRequest), ).rejects.toThrow('Test error') }) }) describe('scanEip712Tx', () => { it('should call mpc.scanEip712Tx with the correct arguments', async () => { const spy = jest .spyOn(mpc, 'scanEip712Tx') .mockResolvedValue(mockScanEip712TxResponse) const result = await hypernative.scanEip712Tx(mockScanEip712TxRequest) expect(spy).toHaveBeenCalledWith(mockScanEip712TxRequest) expect(result).toEqual(mockScanEip712TxResponse) }) it('should propagate errors from mpc.scanEip712Tx', async () => { const error = new Error('Test error') jest.spyOn(mpc, 'scanEip712Tx').mockRejectedValue(error) await expect( hypernative.scanEip712Tx(mockScanEip712TxRequest), ).rejects.toThrow('Test error') }) }) describe('scanSolanaTx', () => { it('should call mpc.scanSolanaTx with the correct arguments', async () => { const spy = jest .spyOn(mpc, 'scanSolanaTx') .mockResolvedValue(mockScanSolanaTxResponse) const result = await hypernative.scanSolanaTx(mockScanSolanaTxRequest) expect(spy).toHaveBeenCalledWith(mockScanSolanaTxRequest) expect(result).toEqual(mockScanSolanaTxResponse) }) it('should propagate errors from mpc.scanSolanaTx', async () => { const error = new Error('Test error') jest.spyOn(mpc, 'scanSolanaTx').mockRejectedValue(error) await expect( hypernative.scanSolanaTx(mockScanSolanaTxRequest), ).rejects.toThrow('Test error') }) }) describe('scanAddresses', () => { it('should call mpc.scanAddresses with the correct arguments', async () => { const spy = jest .spyOn(mpc, 'scanAddresses') .mockResolvedValue(mockScanAddressesResponse) const { addresses, ...options } = mockScanAddressesRequest const result = await hypernative.scanAddresses(addresses, options) expect(spy).toHaveBeenCalledWith(mockScanAddressesRequest) expect(result).toEqual(mockScanAddressesResponse) }) it('should propagate errors from mpc.scanAddresses', async () => { const error = new Error('Test error') jest.spyOn(mpc, 'scanAddresses').mockRejectedValue(error) const { addresses, ...options } = mockScanAddressesRequest await expect( hypernative.scanAddresses(addresses, options), ).rejects.toThrow('Test error') }) }) describe('scanNFTs', () => { it('should call mpc.scanNFTs with the correct arguments', async () => { const spy = jest .spyOn(mpc, 'scanNFTs') .mockResolvedValue(mockScanNftResponse) const result = await hypernative.scanNFTs(mockScanNftRequest) expect(spy).toHaveBeenCalledWith(mockScanNftRequest) expect(result).toEqual(mockScanNftResponse) }) it('should propagate errors from mpc.scanNFTs', async () => { const error = new Error('Test error') jest.spyOn(mpc, 'scanNFTs').mockRejectedValue(error) await expect(hypernative.scanNFTs(mockScanNftRequest)).rejects.toThrow( 'Test error', ) }) }) describe('scanTokens', () => { it('should call mpc.scanTokens with the correct arguments', async () => { const spy = jest .spyOn(mpc, 'scanTokens') .mockResolvedValue(mockScanTokenResponse) const result = await hypernative.scanTokens(mockScanTokenRequest) expect(spy).toHaveBeenCalledWith(mockScanTokenRequest) expect(result).toEqual(mockScanTokenResponse) }) it('should propagate errors from mpc.scanTokens', async () => { const error = new Error('Test error') jest.spyOn(mpc, 'scanTokens').mockRejectedValue(error) await expect( hypernative.scanTokens(mockScanTokenRequest), ).rejects.toThrow('Test error') }) }) describe('scanURL', () => { it('should call mpc.scanUrl with the correct arguments', async () => { const spy = jest .spyOn(mpc, 'scanUrl') .mockResolvedValue(mockScanUrlResponse) const result = await hypernative.scanURL(mockScanUrlRequest) expect(spy).toHaveBeenCalledWith(mockScanUrlRequest) expect(result).toEqual(mockScanUrlResponse) }) it('should propagate errors from mpc.scanUrl', async () => { const error = new Error('Test error') jest.spyOn(mpc, 'scanUrl').mockRejectedValue(error) await expect(hypernative.scanURL(mockScanUrlRequest)).rejects.toThrow( 'Test error', ) }) }) })