Skip to content

Commit

Permalink
add e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aburkut committed Oct 18, 2023
1 parent 7f4d34e commit 1fc9138
Show file tree
Hide file tree
Showing 6 changed files with 203 additions and 121 deletions.
1 change: 1 addition & 0 deletions src/dex/wombat/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ function swapQuoteFunc(
return 0n;
}
// int256 D = Ax + Ay - A.wmul((Lx * Lx) / Ax + (Ly * Ly) / Ay); // flattened _invariantFunc

const d =
assetX +
assetY -
Expand Down
293 changes: 184 additions & 109 deletions src/dex/wombat/wombat-e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,128 +11,203 @@ import { Network, ContractMethod, SwapSide } from '../../constants';
import { StaticJsonRpcProvider } from '@ethersproject/providers';
import { generateConfig } from '../../config';

// function testForNetwork(
// network: Network,
// dexKey: string,
// tokenASymbol: string,
// tokenBSymbol: string,
// tokenAAmount: string,
// tokenBAmount: string,
// nativeTokenAmount: string,
// ) {
// const provider = new StaticJsonRpcProvider(
// generateConfig(network).privateHttpProvider,
// network,
// );
// const tokens = Tokens[network];
// const holders = Holders[network];
// const nativeTokenSymbol = NativeTokenSymbols[network];
//
// const sideToContractMethods = new Map([
// [
// SwapSide.SELL,
// [
// ContractMethod.simpleSwap,
// // ContractMethod.multiSwap,
// // ContractMethod.megaSwap,
// ],
// ],
// ]);
//
// describe(`${network}`, () => {
// sideToContractMethods.forEach((contractMethods, side) =>
// describe(`${side}`, () => {
// contractMethods.forEach((contractMethod: ContractMethod) => {
// describe(`${contractMethod}`, () => {
// it(`${nativeTokenSymbol} -> ${tokenASymbol}`, async () => {
// await testE2E(
// tokens[nativeTokenSymbol],
// tokens[tokenASymbol],
// holders[nativeTokenSymbol],
// side === SwapSide.SELL ? nativeTokenAmount : tokenAAmount,
// side,
// dexKey,
// contractMethod,
// network,
// provider,
// );
// });
// it(`${tokenASymbol} -> ${nativeTokenSymbol}`, async () => {
// await testE2E(
// tokens[tokenASymbol],
// tokens[nativeTokenSymbol],
// holders[tokenASymbol],
// side === SwapSide.SELL ? tokenAAmount : nativeTokenAmount,
// side,
// dexKey,
// contractMethod,
// network,
// provider,
// );
// });
// it(`${tokenASymbol} -> ${tokenBSymbol}`, async () => {
// await testE2E(
// tokens[tokenASymbol],
// tokens[tokenBSymbol],
// holders[tokenASymbol],
// side === SwapSide.SELL ? tokenAAmount : tokenBAmount,
// side,
// dexKey,
// contractMethod,
// network,
// provider,
// );
// });
// });
// });
// }),
// );
// });
// }

function testForNetwork(
network: Network,
dexKey: string,
tokenASymbol: string,
tokenBSymbol: string,
tokenAAmount: string,
tokenBAmount: string,
nativeTokenAmount: string,
) {
const provider = new StaticJsonRpcProvider(
generateConfig(network).privateHttpProvider,
network,
);
const tokens = Tokens[network];
const holders = Holders[network];
const nativeTokenSymbol = NativeTokenSymbols[network];
describe('Wombat E2E', () => {
const dexKey = 'Wombat';

describe('BSC', () => {
const network = Network.BSC;
const tokens = Tokens[network];
const holders = Holders[network];
const provider = new StaticJsonRpcProvider(
generateConfig(network).privateHttpProvider,
network,
);

const sideToContractMethods = new Map([
[
SwapSide.SELL,
const sideToContractMethods = new Map([
[
SwapSide.SELL,
[
ContractMethod.simpleSwap,
// ContractMethod.multiSwap,
// ContractMethod.megaSwap,
],
],
[
ContractMethod.simpleSwap,
// ContractMethod.multiSwap,
// ContractMethod.megaSwap,
SwapSide.BUY,
[
ContractMethod.simpleBuy,
// ContractMethod.buy,
],
],
],
]);
]);

const pairs: { name: string; sellAmount: string; buyAmount: string }[][] =
[
[
{
name: 'USDC',
sellAmount: '100000000000000000000',
buyAmount: '100000000000000000000',
},
{
name: 'USDT',
sellAmount: '100000000000000000000',
buyAmount: '100000000000000000000',
},
],
[
{
name: 'BNB',
sellAmount: '1000000000000000000',
buyAmount: '1000000000',
},
{
name: 'BNBx',
sellAmount: '1000000000',
buyAmount: '1000000000000000000',
},
],
];

describe(`${network}`, () => {
sideToContractMethods.forEach((contractMethods, side) =>
describe(`${side}`, () => {
contractMethods.forEach((contractMethod: ContractMethod) => {
describe(`${contractMethod}`, () => {
it(`${nativeTokenSymbol} -> ${tokenASymbol}`, async () => {
await testE2E(
tokens[nativeTokenSymbol],
tokens[tokenASymbol],
holders[nativeTokenSymbol],
side === SwapSide.SELL ? nativeTokenAmount : tokenAAmount,
side,
dexKey,
contractMethod,
network,
provider,
);
});
it(`${tokenASymbol} -> ${nativeTokenSymbol}`, async () => {
await testE2E(
tokens[tokenASymbol],
tokens[nativeTokenSymbol],
holders[tokenASymbol],
side === SwapSide.SELL ? tokenAAmount : nativeTokenAmount,
side,
dexKey,
contractMethod,
network,
provider,
);
});
it(`${tokenASymbol} -> ${tokenBSymbol}`, async () => {
await testE2E(
tokens[tokenASymbol],
tokens[tokenBSymbol],
holders[tokenASymbol],
side === SwapSide.SELL ? tokenAAmount : tokenBAmount,
side,
dexKey,
contractMethod,
network,
provider,
);
pairs.forEach(pair => {
describe(`${contractMethod}`, () => {
it(`${pair[0].name} -> ${pair[1].name}`, async () => {
await testE2E(
tokens[pair[0].name],
tokens[pair[1].name],
holders[pair[0].name],
side === SwapSide.SELL
? pair[0].sellAmount
: pair[0].buyAmount,
side,
dexKey,
contractMethod,
network,
provider,
);
});
it(`${pair[1].name} -> ${pair[0].name}`, async () => {
await testE2E(
tokens[pair[1].name],
tokens[pair[0].name],
holders[pair[1].name],
side === SwapSide.SELL
? pair[1].sellAmount
: pair[1].buyAmount,
side,
dexKey,
contractMethod,
network,
provider,
);
});
});
});
});
}),
);
});
}

describe('Wombat E2E', () => {
const dexKey = 'Wombat';

describe('BSC', () => {
const network = Network.BSC;

const tokenASymbol: string = 'USDC';
const tokenBSymbol: string = 'USDT';

const tokenAAmount: string = '100000000';
const tokenBAmount: string = '100000000';
const nativeTokenAmount = '1000000000000000000';

testForNetwork(
network,
dexKey,
tokenASymbol,
tokenBSymbol,
tokenAAmount,
tokenBAmount,
nativeTokenAmount,
);
});

describe('Arbitrum', () => {
const network = Network.ARBITRUM;

const tokenASymbol: string = 'USDC';
const tokenBSymbol: string = 'USDT';

const tokenAAmount: string = '100000000';
const tokenBAmount: string = '100000000';
const nativeTokenAmount = '1000000000000000000';

testForNetwork(
network,
dexKey,
tokenASymbol,
tokenBSymbol,
tokenAAmount,
tokenBAmount,
nativeTokenAmount,
);
});
// describe('Arbitrum', () => {
// const network = Network.ARBITRUM;
//
// const tokenASymbol: string = 'USDC';
// const tokenBSymbol: string = 'USDT';
//
// const tokenAAmount: string = '100000000';
// const tokenBAmount: string = '100000000';
// const nativeTokenAmount = '1000000000000000000';
//
// testForNetwork(
// network,
// dexKey,
// tokenASymbol,
// tokenBSymbol,
// tokenAAmount,
// tokenBAmount,
// nativeTokenAmount,
// );
// });
});
8 changes: 4 additions & 4 deletions src/dex/wombat/wombat-integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,16 @@ describe('Wombat', function () {
let blockNumber: number;
let wombat: Wombat;

describe('Mainnet', () => {
const network = Network.MAINNET;
describe('BSC', () => {
const network = Network.BSC;
const dexHelper = new DummyDexHelper(network);

const tokens = Tokens[network];

// TODO: Put here token Symbol to check against
// Don't forget to update relevant tokens in constant-e2e.ts
const srcTokenSymbol = 'srcTokenSymbol';
const destTokenSymbol = 'destTokenSymbol';
const srcTokenSymbol = 'USDC';
const destTokenSymbol = 'USDT';

const amountsForSell = [
0n,
Expand Down
16 changes: 8 additions & 8 deletions src/dex/wombat/wombat-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,14 @@ export class WombatEventPool extends StatefulEventSubscriber<PoolState> {

let i = 0;
// 2 A. decode pool params
const ampFactor = WombatEventPool.poolInterface.decodeFunctionResult(
const ampFactor = BigInt(WombatEventPool.poolInterface.decodeFunctionResult(
'ampFactor',
returnData[i++],
)[0];
const haircutRate = WombatEventPool.poolInterface.decodeFunctionResult(
)[0]);
const haircutRate = BigInt(WombatEventPool.poolInterface.decodeFunctionResult(
'haircutRate',
returnData[i++],
)[0];
)[0]);
const poolState: PoolState = {
params: {
ampFactor,
Expand All @@ -165,14 +165,14 @@ export class WombatEventPool extends StatefulEventSubscriber<PoolState> {
for (const [tokenAddress, tokenInfo] of Object.entries(
this.poolCfg.tokens,
)) {
const cash = WombatEventPool.assetInterface.decodeFunctionResult(
const cash = BigInt(WombatEventPool.assetInterface.decodeFunctionResult(
'cash',
returnData[i++],
)[0];
const liability = WombatEventPool.assetInterface.decodeFunctionResult(
)[0]);
const liability = BigInt(WombatEventPool.assetInterface.decodeFunctionResult(
'liability',
returnData[i++],
)[0];
)[0]);
poolState.underlyingAddresses.push(tokenAddress);
poolState.asset[tokenAddress] = {
cash,
Expand Down
4 changes: 4 additions & 0 deletions tests/constants-e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,10 @@ export const Tokens: {
address: '0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c',
decimals: 18,
},
BNBx: {
address: '0xab824b47806fea52276fef231e5e2d5fb3d4cf4e',
decimals: 9,
},
BUSD: {
address: '0xe9e7cea3dedca5984780bafc599bd69add087d56',
decimals: 18,
Expand Down
Loading

0 comments on commit 1fc9138

Please sign in to comment.