Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
🚨 Add more unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sameersubudhi committed Nov 17, 2023
1 parent 81c0734 commit 08c7cb6
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -496,10 +496,12 @@ module.exports = {
estimateTransactionFees,

// Export for the unit tests
getCcmBuffer,
calcDynamicFeeEstimates,
mockTransaction,
calcAdditionalFees,
filterOptionalProps,
getNumberOfSignatures,
validateTransactionParams,
validateUserHasTokenAccount,
};
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,42 @@ jest.mock('../../../../../shared/dataService/business/token', () => ({
},
}));

describe('getCcmBuffer', () => {
it('should return null if the transaction is not token transferCrossChain', () => {
const { getCcmBuffer } = require(mockedTransactionFeeEstimatesFilePath);
expect(getCcmBuffer(mockRegisterValidatorTxRequestConnector.transaction)).resolves.toBeNull();
});

it.todo("Add test cases for 'if (!ccmSendSuccess)' scenarios");
});

describe('validateUserHasTokenAccount', () => {
it.todo('Fix the mocks for validateUserHasTokenAccount dependencies and enable the tests');

it('should return undefined if user has token account initialized', () => {
const { validateUserHasTokenAccount } = require(mockedTransactionFeeEstimatesFilePath);
const { tokenID, recipientAddress } = mockTransferCrossChainTxRequest.transaction.params;

expect(validateUserHasTokenAccount(tokenID, recipientAddress)).resolves.toBeUndefined();
});

xit("should throw an error if user doesn't have token account initialized", async () => {
jest.mock('../../../../../shared/dataService/business/token', () => ({
async tokenHasUserAccount() {
return {
data: { isExists: false },
meta: {},
};
},
}));

const { validateUserHasTokenAccount } = require(mockedTransactionFeeEstimatesFilePath);
const { tokenID, recipientAddress } = mockTransferCrossChainTxRequest.transaction.params;

await expect(validateUserHasTokenAccount(tokenID, recipientAddress)).rejects.toThrow();
});
});

describe('validateTransactionParams', () => {
it('should validate a valid token and register validator transaction', () => {
const { validateTransactionParams } = require(mockedTransactionFeeEstimatesFilePath);
Expand Down Expand Up @@ -298,6 +334,23 @@ describe('validateTransactionParams', () => {
}),
).rejects.toThrow();
});

it('should throw an error if user has insufficient balance transaction', () => {
const { sendingChainID, ...remParams } =
mockInteroperabilitySubmitMainchainCrossChainUpdateTxRequest.transaction.params;

const { validateTransactionParams } = require(mockedTransactionFeeEstimatesFilePath);

expect(() =>
validateTransactionParams({
...mockInteroperabilitySubmitMainchainCrossChainUpdateTxRequest.transaction,
params: {
...remParams,
amount: Number.MAX_SAFE_INTEGER.toString(),
},
}),
).rejects.toThrow();
});
});

describe('Test transaction fees estimates', () => {
Expand Down

0 comments on commit 08c7cb6

Please sign in to comment.