New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@avalabs/bridge-unified

Package Overview
Dependencies
Maintainers
1
Versions
188
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@avalabs/bridge-unified - npm Package Compare versions

Comparing version 0.0.0-feat-unified-api-interface-20231127184154 to 0.0.0-feat-unified-api-interface-20231127184908

2

CHANGELOG.md
# @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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc