Smoke test for uni-info-watcher (#184)

* Smoke test for uni-info-watcher and refactor token deployment code.

* Test for Token entity after PoolCreated event.

* Test for Pool entity after PoolCreated event.

* Tests for entities after InitializeEvent.

Co-authored-by: prathamesh0 <prathamesh.musale0@gmail.com>
This commit is contained in:
Ashwin Phatak
2021-08-04 18:57:44 +05:30
committed by GitHub
co-authored by prathamesh
parent 73e0475dfa
commit a9d411c6df
17 changed files with 395 additions and 63 deletions
+34
View File
@@ -0,0 +1,34 @@
import { ethers, Contract, ContractTransaction, Signer, BigNumber } from 'ethers';
import {
abi as TESTERC20_ABI,
bytecode as TESTERC20_BYTECODE
} from '../artifacts/test/contracts/TestERC20.sol/TestERC20.json';
export { abi as TESTERC20_ABI } from '../artifacts/test/contracts/TestERC20.sol/TestERC20.json';
export const deployTokens = async (signer: Signer): Promise<{token0Address: string, token1Address: string}> => {
const Token = new ethers.ContractFactory(TESTERC20_ABI, TESTERC20_BYTECODE, signer);
const token0 = await Token.deploy(ethers.BigNumber.from(2).pow(255));
const token0Address = token0.address;
const token1 = await Token.deploy(ethers.BigNumber.from(2).pow(255));
const token1Address = token1.address;
return { token0Address, token1Address };
};
export const createPool = async (
factory: Contract,
token0Address: string,
token1Address: string,
fee: number): Promise<void> => {
const transaction: ContractTransaction = await factory.createPool(token0Address, token1Address, fee);
await transaction.wait();
};
export const initializePool = async (pool: Contract, sqrtPrice: string): Promise<void> => {
const transaction: ContractTransaction = await pool.initialize(BigNumber.from(sqrtPrice));
await transaction.wait();
};
@@ -0,0 +1,60 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.7.6;
import '@uniswap/v3-core/contracts/interfaces/IERC20Minimal.sol';
contract TestERC20 is IERC20Minimal {
mapping(address => uint256) public override balanceOf;
mapping(address => mapping(address => uint256)) public override allowance;
constructor(uint256 amountToMint) {
mint(msg.sender, amountToMint);
}
function mint(address to, uint256 amount) public {
uint256 balanceNext = balanceOf[to] + amount;
require(balanceNext >= amount, 'overflow balance');
balanceOf[to] = balanceNext;
}
function transfer(address recipient, uint256 amount) external override returns (bool) {
uint256 balanceBefore = balanceOf[msg.sender];
require(balanceBefore >= amount, 'insufficient balance');
balanceOf[msg.sender] = balanceBefore - amount;
uint256 balanceRecipient = balanceOf[recipient];
require(balanceRecipient + amount >= balanceRecipient, 'recipient balance overflow');
balanceOf[recipient] = balanceRecipient + amount;
emit Transfer(msg.sender, recipient, amount);
return true;
}
function approve(address spender, uint256 amount) external override returns (bool) {
allowance[msg.sender][spender] = amount;
emit Approval(msg.sender, spender, amount);
return true;
}
function transferFrom(
address sender,
address recipient,
uint256 amount
) external override returns (bool) {
uint256 allowanceBefore = allowance[sender][msg.sender];
require(allowanceBefore >= amount, 'allowance insufficient');
allowance[sender][msg.sender] = allowanceBefore - amount;
uint256 balanceRecipient = balanceOf[recipient];
require(balanceRecipient + amount >= balanceRecipient, 'overflow balance recipient');
balanceOf[recipient] = balanceRecipient + amount;
uint256 balanceSender = balanceOf[sender];
require(balanceSender >= amount, 'underflow balance sender');
balanceOf[sender] = balanceSender - amount;
emit Transfer(sender, recipient, amount);
return true;
}
}