From 87ca03fcdf92a63b96e01b6b6506d117f1fd25d6 Mon Sep 17 00:00:00 2001 From: neumattock <152253273+newmattock@users.noreply.github.com> Date: Tue, 26 May 2026 04:01:57 -0700 Subject: [PATCH 1/3] fix: honor configured WBGL bridge endpoint --- src/__tests__/WBGLEndpoint.test.ts | 56 ++++++++++++++++++++++++++++++ src/bridge/WBGL.ts | 4 +-- 2 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 src/__tests__/WBGLEndpoint.test.ts diff --git a/src/__tests__/WBGLEndpoint.test.ts b/src/__tests__/WBGLEndpoint.test.ts new file mode 100644 index 0000000..0829b14 --- /dev/null +++ b/src/__tests__/WBGLEndpoint.test.ts @@ -0,0 +1,56 @@ +import fetch from 'node-fetch'; +import { ethers } from 'ethers'; + +import { ChaindIds, ChainNames } from '../chains'; +import { WBGL } from '../bridge/WBGL'; + +jest.mock('node-fetch', () => jest.fn()); + +const mockedFetch = fetch as unknown as jest.Mock; + +describe('WBGL bridge endpoint configuration', () => { + beforeEach(() => { + mockedFetch.mockResolvedValue({ + json: jest.fn().mockResolvedValue({ + address: '0x0000000000000000000000000000000000000001', + }), + }); + }); + + afterEach(() => { + jest.clearAllMocks(); + }); + + it('submits WBGL swaps to the configured bridge endpoint', async () => { + const wbgl = new WBGL({ + evmPrivateKey: `0x${'1'.repeat(64)}`, + provider: new ethers.providers.JsonRpcProvider(), + chainName: ChainNames.BNBSmartChain, + chainId: ChaindIds.BNBSmartChain, + bridgeEndpoint: 'https://bridge.example.test/app/', + bglPrivateKeyOrSeed: 'unused-for-wbgl', + }); + + jest + .spyOn( + wbgl as unknown as { _sendWbgl: () => Promise }, + '_sendWbgl', + ) + .mockResolvedValue({ + transactionHash: '0xabc', + wbglBalance: '10', + balance: '1', + }); + + await wbgl.swapWBGLforBGL({ + bglAddress: 'bgl1qh3tsz3a7l3m49xaq4xcdx8aefthchuqagmspcn', + to: '0x0000000000000000000000000000000000000001', + wbglAmount: 5, + }); + + expect(mockedFetch).toHaveBeenCalledWith( + 'https://bridge.example.test/app/submit/wbgl', + expect.objectContaining({ method: 'POST' }), + ); + }); +}); diff --git a/src/bridge/WBGL.ts b/src/bridge/WBGL.ts index d1223e0..1be9a39 100644 --- a/src/bridge/WBGL.ts +++ b/src/bridge/WBGL.ts @@ -42,13 +42,14 @@ export class WBGL { private readonly provider: Provider private readonly chainId: number | string | ChaindIds private readonly chainName: string - private readonly bridgeEndpoint = 'https://bglswap.com/app/' + private readonly bridgeEndpoint: string private readonly evmPrivateKey: string constructor(config: IBridgeConfig) { this.provider = config.provider this.chainId = config.chainId this.chainName = config.chainName + this.bridgeEndpoint = config.bridgeEndpoint || 'https://bglswap.com/app/' this.evmPrivateKey = config.evmPrivateKey } @@ -177,4 +178,3 @@ export class WBGL { } /// END OF PRIVATE METHODS } - From c44a12e303e0345c51f710605b71850dfe1eed91 Mon Sep 17 00:00:00 2001 From: neumattock <152253273+newmattock@users.noreply.github.com> Date: Wed, 3 Jun 2026 18:48:50 -0700 Subject: [PATCH 2/3] fix: normalize configured WBGL bridge endpoint --- src/__tests__/WBGLEndpoint.test.ts | 7 +++++-- src/bridge/WBGL.ts | 7 ++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/__tests__/WBGLEndpoint.test.ts b/src/__tests__/WBGLEndpoint.test.ts index 0829b14..4e988b6 100644 --- a/src/__tests__/WBGLEndpoint.test.ts +++ b/src/__tests__/WBGLEndpoint.test.ts @@ -21,13 +21,16 @@ describe('WBGL bridge endpoint configuration', () => { jest.clearAllMocks(); }); - it('submits WBGL swaps to the configured bridge endpoint', async () => { + it.each([ + ['https://bridge.example.test/app/'], + ['https://bridge.example.test/app'], + ])('submits WBGL swaps to the configured bridge endpoint %s', async (bridgeEndpoint) => { const wbgl = new WBGL({ evmPrivateKey: `0x${'1'.repeat(64)}`, provider: new ethers.providers.JsonRpcProvider(), chainName: ChainNames.BNBSmartChain, chainId: ChaindIds.BNBSmartChain, - bridgeEndpoint: 'https://bridge.example.test/app/', + bridgeEndpoint, bglPrivateKeyOrSeed: 'unused-for-wbgl', }); diff --git a/src/bridge/WBGL.ts b/src/bridge/WBGL.ts index 1be9a39..70dfea0 100644 --- a/src/bridge/WBGL.ts +++ b/src/bridge/WBGL.ts @@ -33,6 +33,11 @@ export interface WBGLBGLExchangePairResult { } type Provider = ethers.providers.JsonRpcProvider | ethers.providers.Web3Provider +const DEFAULT_BRIDGE_ENDPOINT = 'https://bglswap.com/app/' + +const normalizeBridgeEndpoint = (endpoint: string): string => ( + endpoint.endsWith('/') ? endpoint : `${endpoint}/` +) export class WBGL { @@ -49,7 +54,7 @@ export class WBGL { this.provider = config.provider this.chainId = config.chainId this.chainName = config.chainName - this.bridgeEndpoint = config.bridgeEndpoint || 'https://bglswap.com/app/' + this.bridgeEndpoint = normalizeBridgeEndpoint(config.bridgeEndpoint || DEFAULT_BRIDGE_ENDPOINT) this.evmPrivateKey = config.evmPrivateKey } From 9f0a6aba4bc6ae5609e0d4f3e8e726c27862e1a4 Mon Sep 17 00:00:00 2001 From: neumattock <152253273+newmattock@users.noreply.github.com> Date: Wed, 3 Jun 2026 19:41:09 -0700 Subject: [PATCH 3/3] test: cover empty WBGL bridge endpoint fallback --- src/__tests__/WBGLEndpoint.test.ts | 55 ++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 18 deletions(-) diff --git a/src/__tests__/WBGLEndpoint.test.ts b/src/__tests__/WBGLEndpoint.test.ts index 4e988b6..ac17cf6 100644 --- a/src/__tests__/WBGLEndpoint.test.ts +++ b/src/__tests__/WBGLEndpoint.test.ts @@ -9,22 +9,7 @@ jest.mock('node-fetch', () => jest.fn()); const mockedFetch = fetch as unknown as jest.Mock; describe('WBGL bridge endpoint configuration', () => { - beforeEach(() => { - mockedFetch.mockResolvedValue({ - json: jest.fn().mockResolvedValue({ - address: '0x0000000000000000000000000000000000000001', - }), - }); - }); - - afterEach(() => { - jest.clearAllMocks(); - }); - - it.each([ - ['https://bridge.example.test/app/'], - ['https://bridge.example.test/app'], - ])('submits WBGL swaps to the configured bridge endpoint %s', async (bridgeEndpoint) => { + const createWbgl = (bridgeEndpoint?: string) => { const wbgl = new WBGL({ evmPrivateKey: `0x${'1'.repeat(64)}`, provider: new ethers.providers.JsonRpcProvider(), @@ -45,14 +30,48 @@ describe('WBGL bridge endpoint configuration', () => { balance: '1', }); - await wbgl.swapWBGLforBGL({ + return wbgl; + }; + + const submitSwap = async (wbgl: WBGL) => + wbgl.swapWBGLforBGL({ bglAddress: 'bgl1qh3tsz3a7l3m49xaq4xcdx8aefthchuqagmspcn', to: '0x0000000000000000000000000000000000000001', wbglAmount: 5, }); + beforeEach(() => { + mockedFetch.mockResolvedValue({ + json: jest.fn().mockResolvedValue({ + address: '0x0000000000000000000000000000000000000001', + }), + }); + }); + + afterEach(() => { + jest.clearAllMocks(); + }); + + it.each([ + ['https://bridge.example.test/app/'], + ['https://bridge.example.test/app'], + ])( + 'submits WBGL swaps to the configured bridge endpoint %s', + async (bridgeEndpoint) => { + await submitSwap(createWbgl(bridgeEndpoint)); + + expect(mockedFetch).toHaveBeenCalledWith( + 'https://bridge.example.test/app/submit/wbgl', + expect.objectContaining({ method: 'POST' }), + ); + }, + ); + + it('uses the production default when the bridge endpoint is empty', async () => { + await submitSwap(createWbgl('')); + expect(mockedFetch).toHaveBeenCalledWith( - 'https://bridge.example.test/app/submit/wbgl', + 'https://bglswap.com/app/submit/wbgl', expect.objectContaining({ method: 'POST' }), ); });