forked from TrueFiEng/Waffle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Called-on-contract example (TrueFiEng#288)
Fix contracts
- Loading branch information
1 parent
adf8d24
commit 617e519
Showing
10 changed files
with
8,166 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const baseConfig = require('../../.eslintrc.json') | ||
|
||
module.exports = { | ||
...baseConfig, | ||
} |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
build |
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"name": "example-basic", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"license": "MIT", | ||
"scripts": { | ||
"test": "export NODE_ENV=test && mocha", | ||
"build": "waffle waffle.json", | ||
"lint": "eslint '{src,test}/**/*.ts'", | ||
"lint:fix": "eslint --fix '{src,test}/**/*.ts'" | ||
}, | ||
"devDependencies": { | ||
"@types/chai": "^4.2.3", | ||
"@types/mocha": "^5.2.7", | ||
"@typescript-eslint/eslint-plugin": "^2.30.0", | ||
"@typescript-eslint/parser": "^2.30.0", | ||
"chai": "^4.2.0", | ||
"eslint": "^6.8.0", | ||
"eslint-plugin-import": "^2.20.2", | ||
"ethereum-waffle": "2.5.0", | ||
"ethers": "4.0.47", | ||
"mocha": "^7.1.2", | ||
"ts-node": "^8.9.1", | ||
"typescript": "^3.8.3", | ||
"@openzeppelin/contracts": "^3.0.1" | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
pragma solidity ^0.6.2; | ||
|
||
import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; | ||
|
||
contract BasicToken is ERC20 { | ||
constructor(uint256 initialBalance) ERC20("Basic", "BSC") public { | ||
_mint(msg.sender, initialBalance); | ||
} | ||
} | ||
|
||
contract AmIRichAlready { | ||
BasicToken private tokenContract; | ||
uint private constant RICHNESS = 1000000 * 10 ** 18; | ||
constructor (BasicToken _tokenContract) public { | ||
tokenContract = _tokenContract; | ||
} | ||
|
||
function check() public view returns (bool) { | ||
uint balance = tokenContract.balanceOf(msg.sender); | ||
return balance > RICHNESS; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import {expect, use} from 'chai'; | ||
import {Contract, utils} from 'ethers'; | ||
import {deployContract, MockProvider, solidity} from 'ethereum-waffle'; | ||
|
||
import BasicToken from '../build/BasicToken.json'; | ||
import AmIRichAlready from '../build/AmIRichAlready.json'; | ||
|
||
use(solidity); | ||
|
||
describe('Am I Rich Already', () => { | ||
let ERC20: Contract; | ||
let contract: Contract; | ||
const [wallet] = new MockProvider().getWallets(); | ||
|
||
it('returns false if the wallet has less then 1000000 coins', async () => { | ||
ERC20 = await deployContract(wallet, BasicToken, [utils.parseEther('999999')]); | ||
contract = await deployContract(wallet, AmIRichAlready, [ERC20.address]); | ||
expect(await contract.check()).to.be.equal(false); | ||
expect('balanceOf').to.be.calledOnContract(ERC20); | ||
}); | ||
|
||
it('returns true if the wallet has at least 1000000 coins', async () => { | ||
ERC20 = await deployContract(wallet, BasicToken, [utils.parseEther('1000001')]); | ||
contract = await deployContract(wallet, AmIRichAlready, [ERC20.address]); | ||
expect(await contract.check()).to.equal(true); | ||
expect('balanceOf').to.be.calledOnContractWith(ERC20, [wallet.address]); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
-r ts-node/register/transpile-only | ||
--timeout 50000 | ||
--no-warnings | ||
test/**/*.test.{js,ts} |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "../../tsconfig.json" | ||
} |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"compilerType": "solcjs", | ||
"compilerVersion": "0.6.2", | ||
"sourceDirectory": "./src", | ||
"outputDirectory": "./build" | ||
} |
Oops, something went wrong.