Skip to content

Commit

Permalink
Init tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Sluder committed Nov 30, 2023
1 parent c4a298d commit a5da781
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<img src="https://raw.githubusercontent.com/IndigoProtocol/dexter/master/src/dex/logo/muesliswap.png" width="30" />
<img src="https://raw.githubusercontent.com/IndigoProtocol/dexter/master/src/dex/logo/wingriders.png" width="30" />
<img src="https://raw.githubusercontent.com/IndigoProtocol/dexter/master/src/dex/logo/vyfinance.png" width="30" />
<img src="https://raw.githubusercontent.com/IndigoProtocol/dexter/master/src/dex/logo/teddyswap.png" width="30" />
</div>

### What You Can Do
Expand Down
Binary file added src/dex/logo/teddyswap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
100 changes: 100 additions & 0 deletions tests/teddyswap.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import {
Asset,
Dexter,
LiquidityPool,
MockDataProvider,
SwapRequest,
MockWalletProvider,
DatumParameters,
DatumParameterKey,
PayToAddress,
AddressType,
TeddySwap,
} from '../src';

describe('TeddySwap', () => {

const walletProvider: MockWalletProvider = new MockWalletProvider();
walletProvider.loadWalletFromSeedPhrase(['']);
const dexter: Dexter = (new Dexter())
.withDataProvider(new MockDataProvider())
.withWalletProvider(walletProvider);
const asset: Asset = new Asset('f66d78b4a3cb3d37afa0ec36461e51ecbde00f26c8f0a68f94b69880', '69555344', 6);

describe('Set Swap In', () => {

const liquidityPool: LiquidityPool = new LiquidityPool(
TeddySwap.identifier,
'lovelace',
asset,
127343265n,
7635989630n,
'addr1',
);
liquidityPool.poolFeePercent = 0.3;


const swapRequest: SwapRequest = dexter.newSwapRequest()
.forLiquidityPool(liquidityPool)
.withSwapInToken('lovelace')
.withSwapInAmount(10_000_000000n)
.withSlippagePercent(1.0);

it('Can calculate swap parameters', () => {
expect(+swapRequest.getPriceImpactPercent().toFixed(2)).toEqual(2.86);
expect(swapRequest.getEstimatedReceive()).toEqual(7_111_424026n);
expect(swapRequest.getMinimumReceive()).toEqual(7_042_999195n);
});

// it('Can build swap order', () => {
// const teddyswap: TeddySwap = new TeddySwap();
// const defaultSwapParameters: DatumParameters = {
// [DatumParameterKey.PoolIdentifier]: '1234',
// [DatumParameterKey.SenderPubKeyHash]: walletProvider.publicKeyHash(),
// [DatumParameterKey.SenderStakingKeyHash]: walletProvider.stakingKeyHash(),
// [DatumParameterKey.ReceiverPubKeyHash]: walletProvider.publicKeyHash(),
// [DatumParameterKey.ReceiverStakingKeyHash]: walletProvider.stakingKeyHash(),
// [DatumParameterKey.SwapInAmount]: swapRequest.swapInAmount,
// [DatumParameterKey.MinReceive]: swapRequest.getMinimumReceive(),
// [DatumParameterKey.SwapInTokenPolicyId]: '',
// [DatumParameterKey.SwapInTokenAssetName]: '',
// [DatumParameterKey.SwapOutTokenPolicyId]: asset.policyId,
// [DatumParameterKey.SwapOutTokenAssetName]: asset.nameHex,
// };
//
// return teddyswap.buildSwapOrder(liquidityPool, defaultSwapParameters)
// .then((payments: PayToAddress[]) => {
// expect(() => { teddyswap.buildSwapOrder(liquidityPool, defaultSwapParameters); }).not.toThrowError();
// expect(payments[0].addressType).toBe(AddressType.Contract);
// expect(payments[0].assetBalances[0].quantity).toEqual(10004500000n);
// expect(payments[0].datum).toBe('d8799f421234d8799fd8799fd8799fd8799f42ed56ffd8799fd8799fd8799f42bac6ffffffffd87a80ffd87a80ff1a002625a0d8799fd879801b00000002540be400d8799f1b000000309173774fffffff');
// });
// });

});

describe('Set Swap Out', () => {

const liquidityPool: LiquidityPool = new LiquidityPool(
TeddySwap.identifier,
'lovelace',
asset,
127343265n,
7635989630n,
'addr1',
);
liquidityPool.poolFeePercent = 0.3;

const swapRequest: SwapRequest = dexter.newSwapRequest()
.forLiquidityPool(liquidityPool)
.withSwapInToken('lovelace')
.withSwapOutAmount(10_000_000000n)
.withSlippagePercent(1.0);

it('Can calculate swap parameters', () => {
expect(swapRequest.swapInAmount).toEqual(14_231_278551);
});

});

});

0 comments on commit a5da781

Please sign in to comment.