Skip to content

Commit

Permalink
test: Update tests to use to field.
Browse files Browse the repository at this point in the history
  • Loading branch information
johngrantuk committed Nov 1, 2024
1 parent 2e5cb11 commit 3bac32c
Show file tree
Hide file tree
Showing 23 changed files with 130 additions and 2 deletions.
1 change: 1 addition & 0 deletions test/cowAmm/addLiquidity.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ describe('add liquidity test', () => {
addLiquidityInput,
addLiquidityOutput,
txInput.slippage,
chainId,
protocolVersion,
);
});
Expand Down
1 change: 1 addition & 0 deletions test/cowAmm/removeLiquidity.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ describe('remove liquidity test', () => {
input,
removeLiquidityOutput,
txInput.slippage,
chainId,
protocolVersion,
);
});
Expand Down
23 changes: 23 additions & 0 deletions test/lib/utils/addLiquidityHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
VAULT,
Permit2Helper,
AddLiquidityKind,
ChainId,
} from 'src';
import { getTokensForBalanceCheck } from './getTokensForBalanceCheck';
import { TxOutput, sendTransactionGetBalances } from './helper';
Expand Down Expand Up @@ -188,6 +189,7 @@ export function assertAddLiquidityUnbalanced(
addLiquidityInput: AddLiquidityUnbalancedInput,
addLiquidityOutput: AddLiquidityOutput,
slippage: Slippage,
chainId: ChainId,
protocolVersion: 2 | 3 = 2,
wethIsEth?: boolean,
) {
Expand All @@ -214,6 +216,7 @@ export function assertAddLiquidityUnbalanced(
> = {
// | Omit<AddLiquidityV2BaseQueryOutput, 'amountsIn' | 'bptIndex'> = {
// Query should use same amountsIn as input
to: protocolVersion === 2 ? VAULT[chainId] : BALANCER_ROUTER[chainId],
amountsIn: expectedAmountsIn,
tokenInIndex: undefined,
// Should match inputs
Expand Down Expand Up @@ -256,6 +259,7 @@ export function assertAddLiquiditySingleToken(
addLiquidityInput: AddLiquiditySingleTokenInput,
addLiquidityOutput: AddLiquidityOutput,
slippage: Slippage,
chainId: ChainId,
protocolVersion: 2 | 3 = 2,
wethIsEth?: boolean,
) {
Expand All @@ -280,6 +284,7 @@ export function assertAddLiquiditySingleToken(
'amountsIn' | 'bptIndex'
> = {
// Query should use same bpt out as user sets
to: protocolVersion === 2 ? VAULT[chainId] : BALANCER_ROUTER[chainId],
bptOut: TokenAmount.fromRawAmount(
bptToken,
addLiquidityInput.bptOut.rawAmount,
Expand Down Expand Up @@ -334,6 +339,7 @@ export function assertAddLiquidityProportional(
addLiquidityInput: AddLiquidityProportionalInput,
addLiquidityOutput: AddLiquidityOutput,
slippage: Slippage,
chainId: ChainId,
protocolVersion: 1 | 2 | 3 = 2,
wethIsEth?: boolean,
) {
Expand All @@ -360,7 +366,24 @@ export function assertAddLiquidityProportional(
: a,
);

let to: Address;

switch (protocolVersion) {
case 1:
to = poolState.address;
break;
case 2:
to = VAULT[chainId];
break;
case 3:
to = BALANCER_ROUTER[chainId];
break;
default:
throw new Error(`Unsupported protocolVersion: ${protocolVersion}`);
}

const expectedQueryOutput: Omit<AddLiquidityQueryOutput, 'bptIndex'> = {
to,
// Query should use same referenceAmount as user sets
bptOut,
amountsIn,
Expand Down
25 changes: 25 additions & 0 deletions test/lib/utils/removeLiquidityHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
TokenAmount,
VAULT,
PermitHelper,
ChainId,
} from 'src';
import { getTokensForBalanceCheck } from './getTokensForBalanceCheck';
import { sendTransactionGetBalances, TxOutput } from './helper';
Expand Down Expand Up @@ -184,6 +185,7 @@ export function assertRemoveLiquidityUnbalanced(
removeLiquidityInput: RemoveLiquidityUnbalancedInput,
removeLiquidityOutput: RemoveLiquidityOutput,
slippage: Slippage,
chainId: ChainId,
wethIsEth?: boolean,
) {
const {
Expand Down Expand Up @@ -211,6 +213,7 @@ export function assertRemoveLiquidityUnbalanced(
'bptIn' | 'bptIndex'
> = {
// Query should use same amountsOut as input
to: VAULT[chainId],
amountsOut: expectedAmountsOut,
tokenOutIndex: undefined,
// Should match inputs
Expand Down Expand Up @@ -249,6 +252,7 @@ export function assertRemoveLiquiditySingleTokenExactOut(
removeLiquidityInput: RemoveLiquiditySingleTokenExactOutInput,
removeLiquidityOutput: RemoveLiquidityOutput,
slippage: Slippage,
chainId: ChainId,
protocolVersion: 2 | 3 = 2,
wethIsEth?: boolean,
) {
Expand Down Expand Up @@ -281,6 +285,7 @@ export function assertRemoveLiquiditySingleTokenExactOut(
'bptIn' | 'bptIndex'
> = {
// Query should use same amountsOut as input
to: protocolVersion === 2 ? VAULT[chainId] : BALANCER_ROUTER[chainId],
amountsOut: expectedAmountsOut,
tokenOutIndex: tokensWithoutBpt.findIndex(
(t) => t.address === removeLiquidityInput.amountOut.address,
Expand Down Expand Up @@ -322,6 +327,7 @@ export function assertRemoveLiquiditySingleTokenExactIn(
removeLiquidityInput: RemoveLiquiditySingleTokenExactInInput,
removeLiquidityOutput: RemoveLiquidityOutput,
slippage: Slippage,
chainId: ChainId,
protocolVersion: 2 | 3 = 2,
wethIsEth?: boolean,
) {
Expand Down Expand Up @@ -349,6 +355,7 @@ export function assertRemoveLiquiditySingleTokenExactIn(
'amountsOut' | 'bptIndex'
> = {
// Query should use same bpt out as user sets
to: protocolVersion === 2 ? VAULT[chainId] : BALANCER_ROUTER[chainId],
bptIn: TokenAmount.fromRawAmount(
bptToken,
removeLiquidityInput.bptIn.rawAmount,
Expand Down Expand Up @@ -406,6 +413,7 @@ export function assertRemoveLiquidityProportional(
removeLiquidityInput: RemoveLiquidityProportionalInput,
removeLiquidityOutput: RemoveLiquidityOutput,
slippage: Slippage,
chainId: ChainId,
protocolVersion: 1 | 2 | 3 = 2,
wethIsEth?: boolean,
) {
Expand All @@ -421,6 +429,22 @@ export function assertRemoveLiquidityProportional(
18,
);

let to: Address;

switch (protocolVersion) {
case 1:
to = poolState.address;
break;
case 2:
to = VAULT[chainId];
break;
case 3:
to = BALANCER_ROUTER[chainId];
break;
default:
throw new Error(`Unsupported protocolVersion: ${protocolVersion}`);
}

const expectedQueryOutput: Omit<
RemoveLiquidityQueryOutput,
'amountsOut' | 'bptIndex'
Expand All @@ -438,6 +462,7 @@ export function assertRemoveLiquidityProportional(
removeLiquidityKind: removeLiquidityInput.kind,
protocolVersion: poolState.protocolVersion,
chainId: removeLiquidityInput.chainId,
to,
};

const queryCheck = getCheck(removeLiquidityQueryOutput, true);
Expand Down
5 changes: 5 additions & 0 deletions test/lib/utils/removeLiquidityRecoveryHelper.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {
BALANCER_ROUTER,
ChainId,
NATIVE_ASSETS,
PoolState,
RemoveLiquidityBuildCallInput,
Expand All @@ -8,6 +10,7 @@ import {
Slippage,
Token,
TokenAmount,
VAULT,
} from 'src';
import { getTokensForBalanceCheck } from './getTokensForBalanceCheck';
import { sendTransactionGetBalances } from './helper';
Expand Down Expand Up @@ -120,6 +123,7 @@ export function assertRemoveLiquidityRecovery(
removeLiquidityRecoveryInput: RemoveLiquidityRecoveryInput,
removeLiquidityOutput: RemoveLiquidityOutput,
slippage: Slippage,
chainId: ChainId,
protocolVersion: 2 | 3 = 2,
wethIsEth?: boolean,
) {
Expand Down Expand Up @@ -152,6 +156,7 @@ export function assertRemoveLiquidityRecovery(
removeLiquidityKind: removeLiquidityRecoveryInput.kind,
protocolVersion: poolState.protocolVersion,
chainId: removeLiquidityRecoveryInput.chainId,
to: protocolVersion === 2 ? VAULT[chainId] : BALANCER_ROUTER[chainId],
};

const queryCheck = getCheck(removeLiquidityQueryOutput, true);
Expand Down
6 changes: 6 additions & 0 deletions test/v2/addLiquidity/composableStable.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ describe('add liquidity composable stable test', () => {
addLiquidityInput,
addLiquidityOutput,
txInput.slippage,
chainId,
);
});

Expand All @@ -140,6 +141,7 @@ describe('add liquidity composable stable test', () => {
addLiquidityInput,
addLiquidityOutput,
txInput.slippage,
chainId,
2,
wethIsEth,
);
Expand Down Expand Up @@ -174,6 +176,7 @@ describe('add liquidity composable stable test', () => {
input,
addLiquidityOutput,
txInput.slippage,
chainId,
);
});

Expand All @@ -193,6 +196,7 @@ describe('add liquidity composable stable test', () => {
addLiquidityInput,
addLiquidityOutput,
txInput.slippage,
chainId,
2,
wethIsEth,
);
Expand Down Expand Up @@ -225,6 +229,7 @@ describe('add liquidity composable stable test', () => {
input,
addLiquidityOutput,
txInput.slippage,
chainId,
);
});
test('with native', async () => {
Expand All @@ -242,6 +247,7 @@ describe('add liquidity composable stable test', () => {
addLiquidityInput,
addLiquidityOutput,
txInput.slippage,
chainId,
2,
wethIsEth,
);
Expand Down
1 change: 1 addition & 0 deletions test/v2/addLiquidity/gyro2.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ describe('Gyro2 add liquidity test', () => {
addLiquidityInput,
addLiquidityOutput,
txInput.slippage,
chainId,
);
});
//Removed test with native, because there are no GyroE V1 pool with wrapped native asset in any network
Expand Down
1 change: 1 addition & 0 deletions test/v2/addLiquidity/gyro3.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ describe('Gyro3 add liquidity test', () => {
addLiquidityInput,
addLiquidityOutput,
txInput.slippage,
chainId,
);
});
//Removed test with native, because there are no GyroE V1 pool with wrapped native asset in any network
Expand Down
1 change: 1 addition & 0 deletions test/v2/addLiquidity/gyroE.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ describe('gyroE V2 add liquidity test', () => {
addLiquidityInput,
addLiquidityOutput,
txInput.slippage,
chainId,
);
});
});
Expand Down
2 changes: 2 additions & 0 deletions test/v2/addLiquidity/gyroEV2.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ describe('GyroE V2 add liquidity test', () => {
addLiquidityInput,
addLiquidityOutput,
txInput.slippage,
chainId,
);
});
test('with native', async () => {
Expand All @@ -130,6 +131,7 @@ describe('GyroE V2 add liquidity test', () => {
addLiquidityInput,
addLiquidityOutput,
txInput.slippage,
chainId,
2,
wethIsEth,
);
Expand Down
4 changes: 4 additions & 0 deletions test/v2/addLiquidity/stable.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ describe('add liquidity stable test', () => {
addLiquidityInput,
addLiquidityOutput,
txInput.slippage,
chainId,
);
});

Expand All @@ -135,6 +136,7 @@ describe('add liquidity stable test', () => {
addLiquidityInput,
addLiquidityOutput,
txInput.slippage,
chainId,
poolState.protocolVersion,
wethIsEth,
);
Expand Down Expand Up @@ -170,6 +172,7 @@ describe('add liquidity stable test', () => {
addLiquidityInput,
addLiquidityOutput,
txInput.slippage,
chainId,
);
});

Expand All @@ -186,6 +189,7 @@ describe('add liquidity stable test', () => {
addLiquidityInput,
addLiquidityOutput,
txInput.slippage,
chainId,
poolState.protocolVersion,
wethIsEth,
);
Expand Down
6 changes: 6 additions & 0 deletions test/v2/addLiquidity/weighted.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ describe('add liquidity weighted test', () => {
addLiquidityInput,
addLiquidityOutput,
txInput.slippage,
chainId,
);
});

Expand All @@ -140,6 +141,7 @@ describe('add liquidity weighted test', () => {
addLiquidityInput,
addLiquidityOutput,
txInput.slippage,
chainId,
2,
wethIsEth,
);
Expand Down Expand Up @@ -175,6 +177,7 @@ describe('add liquidity weighted test', () => {
addLiquidityInput,
addLiquidityOutput,
txInput.slippage,
chainId,
);
});

Expand All @@ -191,6 +194,7 @@ describe('add liquidity weighted test', () => {
addLiquidityInput,
addLiquidityOutput,
txInput.slippage,
chainId,
2,
wethIsEth,
);
Expand Down Expand Up @@ -223,6 +227,7 @@ describe('add liquidity weighted test', () => {
addLiquidityInput,
addLiquidityOutput,
txInput.slippage,
chainId,
);
});
test('with native', async () => {
Expand All @@ -238,6 +243,7 @@ describe('add liquidity weighted test', () => {
addLiquidityInput,
addLiquidityOutput,
txInput.slippage,
chainId,
2,
wethIsEth,
);
Expand Down
Loading

0 comments on commit 3bac32c

Please sign in to comment.