@avalabs/bridge-unified
Advanced tools
Comparing version 0.0.0-feat-unified-api-interface-20231127184154 to 0.0.0-feat-unified-api-interface-20231127184908
# @avalabs/unified-bridge | ||
## 0.0.0-feat-unified-api-interface-20231127184154 | ||
## 0.0.0-feat-unified-api-interface-20231127184908 | ||
@@ -5,0 +5,0 @@ ### Major Changes |
{ | ||
"name": "@avalabs/bridge-unified", | ||
"version": "0.0.0-feat-unified-api-interface-20231127184154", | ||
"version": "0.0.0-feat-unified-api-interface-20231127184908", | ||
"main": "dist/index.js", | ||
@@ -18,3 +18,3 @@ "type": "module", | ||
"@internal/tsup-config": "0.0.1", | ||
"eslint-config-custom": "0.0.0-feat-unified-api-interface-20231127184154" | ||
"eslint-config-custom": "0.0.0-feat-unified-api-interface-20231127184908" | ||
}, | ||
@@ -21,0 +21,0 @@ "scripts": { |
@@ -237,2 +237,129 @@ import { encodeFunctionData } from 'viem'; | ||
}); | ||
describe('does not need additional approval', () => { | ||
it('works with a provided signer', async () => { | ||
const start = 1000; | ||
const dateSpy = jest.spyOn(Date, 'now'); | ||
dateSpy.mockReturnValue(start); | ||
const bridgeSignedHex = '0x3'; | ||
const bridgeTxHash = '0x4'; | ||
const bridgeTxData = 'bridge-tx-data'; | ||
const providerWithSigner = { | ||
request: jest.fn(), | ||
sign: jest.fn().mockResolvedValueOnce(bridgeSignedHex), | ||
}; | ||
const params = getTransferParams({ sourceProvider: providerWithSigner }); | ||
sourceClientMock.readContract.mockResolvedValue(params.amount); | ||
sourceClientMock.sendRawTransaction.mockResolvedValueOnce(bridgeTxHash); | ||
(encodeFunctionData as jest.Mock).mockReturnValueOnce(bridgeTxData); | ||
const bridgeTransfer = await transferAsset(bridgeMock, params, environment); | ||
expect(bridgeTransfer).toStrictEqual( | ||
getBridgeTransferMock({ | ||
amount: params.amount, | ||
addressC: params.addressC, | ||
addressBtc: params.addressBtc, | ||
sourceTxHash: bridgeTxHash, | ||
startBlockNumber: targetBlockNumber, | ||
sourceStartedAt: start, | ||
}), | ||
); | ||
expect(getClientForChain).toHaveBeenCalledTimes(2); | ||
expect(getClientForChain).toHaveBeenNthCalledWith(1, { | ||
chain: params.sourceChain, | ||
provider: providerWithSigner, | ||
}); | ||
expect(getClientForChain).toHaveBeenNthCalledWith(2, { | ||
chain: params.targetChain, | ||
provider: targetProviderMock, | ||
}); | ||
expect(sourceClientMock.readContract).toHaveBeenCalledWith({ | ||
address: BRIDGE_ASSET.address, | ||
abi: ERC20_ABI, | ||
functionName: 'allowance', | ||
args: [params.addressC, SOURCE_ROUTER_ADDRESS], | ||
}); | ||
expect(encodeFunctionData).toHaveBeenCalledTimes(1); | ||
expect(encodeFunctionData).toHaveBeenCalledWith({ | ||
abi: TOKEN_ROUTER_ABI, | ||
functionName: 'transferTokens', | ||
args: [params.amount, 1, params.addressC, BRIDGE_ASSET.address], | ||
}); | ||
expect(providerWithSigner.sign).toHaveBeenCalledTimes(1); | ||
expect(providerWithSigner.sign).toHaveBeenCalledWith({ | ||
from: params.addressC, | ||
to: SOURCE_ROUTER_ADDRESS, | ||
data: bridgeTxData, | ||
}); | ||
expect(sourceClientMock.sendRawTransaction).toHaveBeenCalledTimes(1); | ||
expect(sourceClientMock.sendRawTransaction).toHaveBeenCalledWith({ | ||
serializedTransaction: bridgeSignedHex, | ||
}); | ||
}); | ||
it('works without provided signer', async () => { | ||
const start = 1000; | ||
const dateSpy = jest.spyOn(Date, 'now'); | ||
dateSpy.mockReturnValue(start); | ||
const bridgeTxHash = '0x2'; | ||
const bridgeTxRequest = 'bridge-tx-request'; | ||
const params = getTransferParams({ sourceProvider: sourceProviderMock }); | ||
sourceClientMock.readContract.mockResolvedValue(params.amount); | ||
sourceClientMock.simulateContract.mockResolvedValueOnce({ request: bridgeTxRequest }); | ||
sourceClientMock.writeContract.mockResolvedValueOnce(bridgeTxHash); | ||
const bridgeTransfer = await transferAsset(bridgeMock, params, environment); | ||
expect(bridgeTransfer).toStrictEqual( | ||
getBridgeTransferMock({ | ||
amount: params.amount, | ||
addressC: params.addressC, | ||
addressBtc: params.addressBtc, | ||
sourceTxHash: bridgeTxHash, | ||
startBlockNumber: targetBlockNumber, | ||
sourceStartedAt: start, | ||
}), | ||
); | ||
expect(getClientForChain).toHaveBeenCalledTimes(2); | ||
expect(getClientForChain).toHaveBeenNthCalledWith(1, { | ||
chain: params.sourceChain, | ||
provider: sourceProviderMock, | ||
}); | ||
expect(getClientForChain).toHaveBeenNthCalledWith(2, { | ||
chain: params.targetChain, | ||
provider: targetProviderMock, | ||
}); | ||
expect(sourceClientMock.readContract).toHaveBeenCalledWith({ | ||
address: BRIDGE_ASSET.address, | ||
abi: ERC20_ABI, | ||
functionName: 'allowance', | ||
args: [params.addressC, SOURCE_ROUTER_ADDRESS], | ||
}); | ||
expect(sourceClientMock.simulateContract).toHaveBeenCalledTimes(1); | ||
expect(sourceClientMock.simulateContract).toHaveBeenCalledWith({ | ||
account: params.addressC, | ||
address: SOURCE_ROUTER_ADDRESS, | ||
abi: TOKEN_ROUTER_ABI, | ||
functionName: 'transferTokens', | ||
args: [params.amount, 1, params.addressC, BRIDGE_ASSET.address], | ||
}); | ||
expect(sourceClientMock.writeContract).toHaveBeenCalledTimes(1); | ||
expect(sourceClientMock.writeContract).toHaveBeenCalledWith(bridgeTxRequest); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
275001
3017