Skip to content

Commit

Permalink
chore: add tests for bridge controller
Browse files Browse the repository at this point in the history
  • Loading branch information
infiniteflower committed Oct 9, 2024
1 parent beb3cea commit 6de5ea4
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion app/scripts/controllers/bridge/bridge-controller.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Provider } from '@metamask/network-controller';
import nock from 'nock';
import { BRIDGE_API_BASE_URL } from '../../../../shared/constants/bridge';
import { CHAIN_IDS } from '../../../../shared/constants/network';
Expand All @@ -17,11 +18,30 @@ const messengerMock = {
publish: jest.fn(),
} as unknown as jest.Mocked<BridgeControllerMessenger>;

const providerMock = {} as Provider;

jest.mock('@ethersproject/contracts', () => {
return {
Contract: jest.fn(() => ({
allowance: jest.fn(() => '100000000000000000000'),
})),
};
});

jest.mock('@ethersproject/providers', () => {
return {
Web3Provider: jest.fn(),
};
});

describe('BridgeController', function () {
let bridgeController: BridgeController;

beforeAll(function () {
bridgeController = new BridgeController({ messenger: messengerMock });
bridgeController = new BridgeController({
messenger: messengerMock,
provider: providerMock,
});
});

beforeEach(() => {
Expand Down Expand Up @@ -143,4 +163,15 @@ describe('BridgeController', function () {
},
]);
});

describe('getBridgeERC20Allowance', () => {
it('should return the atomic allowance of the ERC20 token contract', async () => {
const allowance = await bridgeController.getBridgeERC20Allowance(
'0x1f9840a85d5af5bf1d1762f925bdaddc4201f984',
'0x0000000000000000000000000000000000000000',
'0xa',
);
expect(allowance).toBe('100000000000000000000');
});
});
});

0 comments on commit 6de5ea4

Please sign in to comment.