Skip to content

Commit

Permalink
feat: estimateAmountReceiving() works with new bridge
Browse files Browse the repository at this point in the history
  • Loading branch information
sbp-rib committed Mar 23, 2021
1 parent 4121794 commit 5b1bf96
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 33 deletions.
50 changes: 19 additions & 31 deletions src/modules/generic-fees/estimateAmountReceiving/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { PromiseValue } from 'type-fest';

import type { SkybridgeCoin } from '../../coins';
import { buildContext } from '../../context';
import type { SkybridgeMode } from '../../modes';
Expand All @@ -14,48 +16,28 @@ it.each<
currencyDeposit: SkybridgeCoin<SkybridgeResource, 'test', 'in'>;
currencyReceiving: SkybridgeCoin<SkybridgeResource, 'test', 'out'>;
},
any,
Pick<PromiseValue<ReturnType<typeof estimateAmountReceiving>>, 'feeCurrency'>,
]
>([
[
{ amountDesired: '3', currencyDeposit: 'BTC', currencyReceiving: 'WBTC' },
{
amountReceiving: '2.99385',
feeBridgeFraction: '0.002',
feeMiner: '0.00015',
feeCurrency: 'WBTC',
feeTotal: '0.00615',
},
{ feeCurrency: 'WBTC' },
],
[
{ amountDesired: '156', currencyDeposit: 'WBTC', currencyReceiving: 'BTC' },
{
amountReceiving: '155.6877',
feeBridgeFraction: '0.002',
feeMiner: '0.0003',
feeCurrency: 'BTC',
feeTotal: '0.3123',
},
{ feeCurrency: 'BTC' },
],
[
{ amountDesired: '156', currencyDeposit: 'sbBTC', currencyReceiving: 'WBTC' },
{
amountReceiving: '156',
feeBridgeFraction: '0.002',
feeMiner: '0.00015',
feeCurrency: 'WBTC',
feeTotal: '0.31215',
},
{ feeCurrency: 'WBTC' },
],
[
{ amountDesired: '156', currencyDeposit: 'BTC', currencyReceiving: 'sbBTC' },
{
amountReceiving: '155.68785',
feeBridgeFraction: '0.005',
feeMiner: '0',
feeCurrency: 'sbBTC',
feeTotal: '0.31215',
},
{ feeCurrency: 'sbBTC' },
],
[
{ amountDesired: '156', currencyDeposit: 'BTCB.BEP20', currencyReceiving: 'sbBTC.BEP20' },
{ feeCurrency: 'sbBTC.BEP20' },
],
])('works for %O', async ({ amountDesired, currencyDeposit, currencyReceiving }, expected) => {
expect.assertions(1);
Expand All @@ -68,7 +50,13 @@ it.each<
amountDesired,
});

expect(result).toMatchObject(expected);
expect(result).toMatchObject({
...expected,
amountReceiving: expect.stringMatching(/\d+(\.\d+)?/),
feeBridgeFraction: expect.stringMatching(/\d+(\.\d+)?/),
feeMiner: expect.stringMatching(/\d+(\.\d+)?/),
feeTotal: expect.stringMatching(/\d+(\.\d+)?/),
});
});

it.each<{ currencyDeposit: any; mode: SkybridgeMode; currencyReceiving: any }>([
Expand All @@ -87,6 +75,6 @@ it.each<{ currencyDeposit: any; mode: SkybridgeMode; currencyReceiving: any }>([
amountDesired: '1',
});
} catch (e) {
expect(e.message).toMatch(/must be one of/);
expect(e.message).toMatch(/(Could not find (test|production) bridge)|(must be one of)/);
}
});
4 changes: 2 additions & 2 deletions src/modules/generic-fees/estimateAmountReceiving/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { SkybridgeMode } from '../../modes';
import type { SkybridgeParams } from '../../common-params';
import { SkybridgeResource } from '../../resources';
import type { SkybridgeResource } from '../../resources';
import type { SkybridgeCoin } from '../../coins';
import { fetch } from '../../fetch';
import { SkybridgeCoin } from '../../coins';

export const estimateAmountReceiving = async <M extends SkybridgeMode>({
context,
Expand Down

0 comments on commit 5b1bf96

Please sign in to comment.