Created
November 16, 2018 16:22
-
-
Save marekkirejczyk/dd9ff4e34117b24d8f9b4966ab56c86e to your computer and use it in GitHub Desktop.
Waffle example test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import chai from 'chai'; | |
import {createMockProvider, deployContract, getWallets, solidity} from 'ethereum-waffle'; | |
import BasicTokenMock from './build/BasicTokenMock'; | |
chai.use(solidity); | |
const {expect} = chai; | |
describe('Example', () => { | |
let provider; | |
let token; | |
let wallet; | |
let walletTo; | |
beforeEach(async () => { | |
provider = createMockProvider(); | |
[wallet, walletTo] = await getWallets(provider); | |
token = await deployContract(wallet, BasicTokenMock, [wallet.address, 1000]); | |
}); | |
it('Assigns initial balance', async () => { | |
expect(await token.balanceOf(wallet.address)).to.eq(1000); | |
}); | |
it('Transfer adds amount to destination account', async () => { | |
await token.transfer(walletTo.address, 7); | |
expect(await token.balanceOf(wallet.address)).to.eq(993); | |
expect(await token.balanceOf(walletTo.address)).to.eq(7); | |
}); | |
it('Transfer emits event', async () => { | |
await expect(token.transfer(walletTo.address, 7)) | |
.to.emit(token, 'Transfer') | |
.withArgs(wallet.address, walletTo.address, 7); | |
}); | |
it('Can not transfer from empty account', async () => { | |
const tokenFromOtherWallet = contractWithWallet(token, walletTo); | |
await expect(tokenFromOtherWallet.transfer(wallet.address, 1)) | |
.to.be.revertedWith('Not enough balance on sender account'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment