Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
Lykhoyda committed Aug 21, 2024
1 parent ccf0ff5 commit e2e9358
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 53 deletions.
56 changes: 6 additions & 50 deletions packages/substrate/src/__test__/fungible.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,80 +166,36 @@ describe('SubstrateFungibleAssetTransfer', () => {
'Insufficient asset balance to perform the Transaction',
);
});

test('should throw ERROR - when native balance is not sufficient', async () => {
(getFeeHandler as jest.Mock).mockResolvedValue(FeeHandlerType.BASIC);
(getBasicFee as jest.Mock).mockResolvedValue({
fee: new BN(2000),
type: FeeHandlerType.BASIC,
});
(getAssetBalance as jest.Mock).mockResolvedValue({ balance: BigInt(1) });

const insufficientBalanceRequest = {
...transferRequest,
amount: BigInt(1000), // Amount set to trigger insufficient balance
};

const transfer = await createSubstrateFungibleAssetTransfer(insufficientBalanceRequest);
await expect(transfer.getTransferTransaction()).rejects.toThrow(
'Insufficient balance to perform the Transaction',
);
});

test('should throw ERROR - Transferable Token is not sufficient - basic', async () => {
(getFeeHandler as jest.Mock).mockResolvedValue(FeeHandlerType.BASIC);
(getBasicFee as jest.Mock).mockResolvedValue({
fee: new BN(2000),
type: FeeHandlerType.PERCENTAGE,
});
(getAssetBalance as jest.Mock).mockResolvedValue({ balance: BigInt(0) });

const transfer = await createSubstrateFungibleAssetTransfer(transferRequest);
await expect(transfer.getTransferTransaction()).rejects.toThrow(
'Insufficient asset balance to perform the Transaction',
);
});

test('should throw ERROR - Transferable Token is not sufficient - Percentage', async () => {
(getFeeHandler as jest.Mock).mockResolvedValue(FeeHandlerType.PERCENTAGE);
(getPercentageFee as jest.Mock).mockResolvedValue({
fee: new BN(100),
type: FeeHandlerType.PERCENTAGE,
});
(getAssetBalance as jest.Mock).mockResolvedValue({ balance: BigInt(0) });

const transfer = await createSubstrateFungibleAssetTransfer(transferRequest);
await expect(transfer.getTransferTransaction()).rejects.toThrow(
'Insufficient asset balance to perform the Transaction',
);
});
});

describe('verifyBalance', () => {
test('should pass balance verification when balance is sufficient', async () => {
(getFeeHandler as jest.Mock).mockResolvedValue(FeeHandlerType.BASIC);
(getBasicFee as jest.Mock).mockResolvedValue({
fee: new BN(100),
fee: new BN(500),
type: FeeHandlerType.BASIC,
});
(getNativeTokenBalance as jest.Mock).mockResolvedValue({ free: BigInt(500) });

const sufficientBalanceRequest = {
...transferRequest,
amount: BigInt(200),
amount: BigInt(1),
};

const transfer = await createSubstrateFungibleAssetTransfer(sufficientBalanceRequest);
await expect(transfer.verifyBalance()).resolves.not.toThrow();
});

test('should throw ERROR - when sender address is invalid', async () => {
(getFeeHandler as jest.Mock).mockResolvedValue(FeeHandlerType.PERCENTAGE);
(getPercentageFee as jest.Mock).mockResolvedValue({
fee: new BN(50),
type: FeeHandlerType.PERCENTAGE,
});

const invalidSenderRequest = {
...transferRequest,
senderAddress: 'invalidAddress',
sourceAddress: 'invalidAddress',
};

const transfer = await createSubstrateFungibleAssetTransfer(invalidSenderRequest);
Expand Down
3 changes: 0 additions & 3 deletions packages/substrate/src/fungible.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export interface SubstrateAssetTransferRequest extends BaseTransferParams {
sourceNetworkProvider: ApiPromise;
amount: bigint;
destinationAddress: string;
senderAddress: string;
}

export async function createSubstrateFungibleAssetTransfer(
Expand All @@ -42,12 +41,10 @@ class SubstrateFungibleAssetTransfer extends BaseTransfer {
amount: bigint;
destinationAddress: string = '';
sourceNetworkProvider: ApiPromise;
senderAddress: string;

constructor(transfer: SubstrateAssetTransferRequest, config: Config) {
super(transfer, config);
this.amount = transfer.amount;
this.senderAddress = transfer.senderAddress;
this.sourceNetworkProvider = transfer.sourceNetworkProvider;

if (isValidAddressForNetwork(transfer.destinationAddress, this.destination.type))
Expand Down

0 comments on commit e2e9358

Please sign in to comment.