Skip to content
This repository was archived by the owner on Oct 24, 2025. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions contracts/test/TestUniswapV2Library.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity =0.7.6;

import '../libraries/UniswapV2Library.sol';

contract TestUniswapV2Library {
function testEqualityAmountIn(
uint256 amountIn,
uint256 reserveIn,
uint256 reserveOut
) external pure {
uint256 amountOut = UniswapV2Library.getAmountOut(amountIn, reserveIn, reserveOut);
uint256 amountInComputed = UniswapV2Library.getAmountIn(amountOut, reserveIn, reserveOut);
require(amountIn == amountInComputed);
}

function testEqualityAmountOut(
uint256 amountOut,
uint256 reserveIn,
uint256 reserveOut
) external pure {
uint256 amountIn = UniswapV2Library.getAmountIn(amountOut, reserveIn, reserveOut);
uint256 amountOutComputed = UniswapV2Library.getAmountOut(amountIn, reserveIn, reserveOut);
require(amountOut == amountOutComputed);
}
}
27 changes: 27 additions & 0 deletions test/UniswapV2Library.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { ethers } from 'hardhat'
import { TestUniswapV2Library } from '../typechain'

describe('V2Library', function () {
let uniswapLibrary: TestUniswapV2Library

before(async function () {
const factory = await ethers.getContractFactory('TestUniswapV2Library')
uniswapLibrary = (await factory.deploy()) as TestUniswapV2Library
})

it('exact in', async () => {
await uniswapLibrary.testEqualityAmountIn(
'10000000000000000000000',
'6060121762013965246271',
'1845639706596254478341383'
)
})

it('exact out', async () => {
await uniswapLibrary.testEqualityAmountOut(
'10000000000000000000000',
'6060121762013965246271',
'1845639706596254478341383'
)
})
})