Files
uniswap-v2/test/ERC20.ts
Noah Zinsmeister d48b5f5a44 run everything on constantinople
turn on compiler optimization

don't hardcode 18 decimals

add create2

name return values in factory
2019-10-24 18:03:15 -04:00

71 lines
2.4 KiB
TypeScript

import chai from 'chai'
import { solidity, createMockProvider, getWallets, deployContract } from 'ethereum-waffle'
import { Contract } from 'ethers'
import { BigNumber, bigNumberify } from 'ethers/utils'
import ERC20 from '../build/ERC20.json'
chai.use(solidity)
const { expect } = chai
const decimalize = (n: number): BigNumber => bigNumberify(n).mul(bigNumberify(10).pow(18))
const name = 'Mock ERC20'
const symbol = 'MOCK'
const decimals = 18
const totalSupply = decimalize(1000)
describe('ERC20', () => {
const provider = createMockProvider()
const [wallet, walletTo] = getWallets(provider)
let token: Contract
beforeEach(async () => {
token = await deployContract(wallet, ERC20, [name, symbol, decimals, totalSupply])
})
it('name, symbol, decimals, totalSupply, balanceOf', async () => {
expect(await token.name()).to.eq(name)
expect(await token.symbol()).to.eq(symbol)
expect(await token.decimals()).to.eq(18)
expect(await token.totalSupply()).to.eq(totalSupply)
expect(await token.balanceOf(wallet.address)).to.eq(totalSupply)
})
it('transfer', async () => {
const transferAmount = decimalize(10)
await expect(token.transfer(walletTo.address, transferAmount))
.to.emit(token, 'Transfer')
.withArgs(wallet.address, walletTo.address, transferAmount)
expect(await token.balanceOf(wallet.address)).to.eq(totalSupply.sub(transferAmount))
expect(await token.balanceOf(walletTo.address)).to.eq(transferAmount)
})
it('transferFrom', async () => {
const transferAmount = decimalize(10)
await expect(token.approve(walletTo.address, transferAmount))
.to.emit(token, 'Approval')
.withArgs(wallet.address, walletTo.address, transferAmount)
await expect(token.connect(walletTo).transferFrom(wallet.address, walletTo.address, transferAmount))
.to.emit(token, 'Transfer')
.withArgs(wallet.address, walletTo.address, transferAmount)
expect(await token.balanceOf(wallet.address)).to.eq(totalSupply.sub(transferAmount))
expect(await token.balanceOf(walletTo.address)).to.eq(transferAmount)
})
it('transfer fails', async () => {
await expect(token.transfer(walletTo.address, totalSupply.add(1))).to.be.revertedWith(
'SafeMath: subtraction overflow'
)
await expect(token.connect(walletTo).transfer(walletTo.address, 1)).to.be.revertedWith(
'SafeMath: subtraction overflow'
)
})
})