-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
db73128
commit b51cdfe
Showing
2 changed files
with
13 additions
and
16 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,42 @@ | ||
import {use, expect} from 'chai'; | ||
import {ContractFactory, utils} from 'ethers'; | ||
import {deployMockContract, MockProvider, solidity} from 'ethereum-waffle'; | ||
import {utils, Contract} from 'ethers'; | ||
import {deployMockContract, MockProvider, solidity, deployContract} from 'ethereum-waffle'; | ||
|
||
import IERC20 from '../build/IERC20.json'; | ||
import AmIRichAlready from '../build/AmIRichAlready.json'; | ||
|
||
use(solidity); | ||
|
||
describe('Am I Rich Already', () => { | ||
async function setup() { | ||
const [sender, receiver] = new MockProvider().getWallets(); | ||
const mockERC20 = await deployMockContract(sender, IERC20.abi); | ||
const contractFactory = new ContractFactory(AmIRichAlready.abi, AmIRichAlready.bytecode, sender); | ||
const contract = await contractFactory.deploy(mockERC20.address); | ||
return {sender, receiver, contract, mockERC20}; | ||
} | ||
let mockERC20: Contract; | ||
let contract: Contract; | ||
const [wallet, otherWallet] = new MockProvider().getWallets(); | ||
|
||
beforeEach(async () => { | ||
mockERC20 = await deployMockContract(wallet, IERC20.abi); | ||
contract = await deployContract(wallet, AmIRichAlready, [mockERC20.address]); | ||
}); | ||
|
||
it('returns false if the wallet has less then 1000000 coins', async () => { | ||
const {contract, mockERC20} = await setup(); | ||
await mockERC20.mock.balanceOf.returns(utils.parseEther('999999')); | ||
expect(await contract.check()).to.be.equal(false); | ||
}); | ||
|
||
it('returns true if the wallet has at least 1000000 coins', async () => { | ||
const {contract, mockERC20} = await setup(); | ||
await mockERC20.mock.balanceOf.returns(utils.parseEther('1000001')); | ||
expect(await contract.check()).to.equal(true); | ||
}); | ||
|
||
it('reverts if the ERC20 reverts', async () => { | ||
const {contract, mockERC20} = await setup(); | ||
await mockERC20.mock.balanceOf.reverts(); | ||
await expect(contract.check()).to.be.revertedWith('Mock revert'); | ||
}); | ||
|
||
it('returns 1000001 coins for my address and 0 otherwise', async () => { | ||
const {contract, mockERC20, sender, receiver} = await setup(); | ||
await mockERC20.mock.balanceOf.returns('0'); | ||
await mockERC20.mock.balanceOf.withArgs(sender.address).returns(utils.parseEther('1000001')); | ||
await mockERC20.mock.balanceOf.withArgs(wallet.address).returns(utils.parseEther('1000001')); | ||
|
||
expect(await contract.check()).to.equal(true); | ||
expect(await contract.connect(receiver.address).check()).to.equal(false); | ||
expect(await contract.connect(otherWallet.address).check()).to.equal(false); | ||
}); | ||
}); |
This file contains 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