Skip to content
This repository was archived by the owner on Oct 12, 2021. It is now read-only.

Commit 8c2ce92

Browse files
authored
Merge pull request #2 from XIO-Network/dev
flashmit unit test added
2 parents 79becc3 + 24c0c6a commit 8c2ce92

File tree

11 files changed

+187
-232
lines changed

11 files changed

+187
-232
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ coverage.json
1919
npm-debug.log*
2020
yarn-debug.log*
2121
yarn-error.log*
22+
pre-commit.sh

.huskyrc

Lines changed: 0 additions & 1 deletion
This file was deleted.

LICENSE.md

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
1-
# WTFPL
1+
MIT License
22

3-
by Paul Razvan Berg (@PaulRBerg)
3+
Copyright (c) 2020 Xord
44

5-
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
611

7-
0. You just DO WHAT THE FUCK YOU WANT TO.
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
File renamed without changes.

contracts/interfaces/IFlashMinter.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-License-Identifier: GPL-3.0
1+
// SPDX-License-Identifier: MIT
22
pragma solidity 0.6.12;
33

44
interface IFlashMinter {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity 0.6.12;
3+
4+
interface IFlashMint {
5+
function flashMint(uint256 value,bytes calldata data) external;
6+
}

contracts/tests/FlashMinter.sol

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity 0.6.12;
3+
4+
import "../interfaces/tests/IFlashMint.sol";
5+
import "../interfaces/IFlashMinter.sol";
6+
import "../interfaces/IERC20.sol";
7+
8+
contract FlashMinter is IFlashMinter {
9+
10+
address FLASH_CONTRACT;
11+
12+
constructor(address _token) public{
13+
FLASH_CONTRACT = _token;
14+
}
15+
16+
function flashMint(uint256 _value, bytes calldata _data) public {
17+
IFlashMint(FLASH_CONTRACT).flashMint(_value,_data);
18+
}
19+
20+
function executeOnFlashMint(bytes calldata data) public override {
21+
(bool flag, uint256 value,address sender) = abi.decode(data, (bool, uint256,address));
22+
23+
if(flag){
24+
IERC20(FLASH_CONTRACT).transfer(sender,value);
25+
}
26+
}
27+
}

hardhat.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ const config: HardhatUserConfig = {
6464
paths: {
6565
artifacts: "./artifacts",
6666
cache: "./cache",
67-
sources: "./contracts",
67+
sources: "./contracts/",
6868
tests: "./test",
6969
},
7070
solidity: {

package.json

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
{
2-
"name": "@XORD-one/xio-flash-token",
2+
"name": "@XIO-Network/xio-flash-token",
33
"description": "xio flash token smart contract repo",
44
"version": "1.0.0",
5-
"author": {
6-
"name": "XORD.ONE",
7-
"url": "https://xord.com"
8-
},
95
"devDependencies": {
106
"@commitlint/config-conventional": "^9.1.2",
117
"@ethersproject/abstract-signer": "^5.0.6",
@@ -53,10 +49,17 @@
5349
"smart-contracts",
5450
"solidity"
5551
],
56-
"license": "WTFPL",
52+
"license": "MIT",
5753
"publishConfig": {
5854
"access": "public"
5955
},
56+
"husky": {
57+
"hooks": {
58+
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
59+
"pre-commit": "sh ./pre-commit.sh",
60+
"pre-push": "yarn test"
61+
}
62+
},
6063
"scripts": {
6164
"clean": "hardhat clean",
6265
"commit": "git-cz",
@@ -69,9 +72,10 @@
6972
"prettier:list-different": "prettier --config .prettierrc --list-different \"**/*.{js,json,md,sol,ts}\"",
7073
"test": "hardhat test",
7174
"typechain": "hardhat typechain",
72-
"deploy":"hardhat run ./scripts/deploy.ts"
75+
"deploy": "hardhat run ./scripts/deploy.ts"
7376
},
7477
"dependencies": {
78+
"@commitlint/cli": "^11.0.0",
7579
"ethereumjs-util": "^7.0.7"
7680
}
7781
}

test/FlashToken.test.ts

Lines changed: 43 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ import {
55
toUtf8Bytes,
66
solidityPack
77
} from "ethers/lib/utils";
8-
import { expect, use} from "chai";
8+
import { expect, use } from "chai";
99
import { deployContract, MockProvider, solidity } from "ethereum-waffle";
10-
import BasicToken from "../artifacts/contracts/FlashToken.sol/FlashToken.json";
11-
import { constants } from "ethers";
10+
import FlashTokenArtifact from "../artifacts/contracts/FlashToken.sol/FlashToken.json";
11+
import MinterContractArtifact from "../artifacts/contracts/tests/FlashMinter.sol/FlashMinter.json";
12+
import { constants, ethers } from "ethers";
1213
import { ecsign } from "ethereumjs-util";
1314
import { mintTokens } from './utils/functions'
1415

@@ -27,33 +28,33 @@ describe("Flash token", async () => {
2728
"0xc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc6";
2829

2930
beforeEach(async () => {
30-
FlashToken = await deployContract(wallet, BasicToken, [wallet.address, wallet.address]);
31+
FlashToken = await deployContract(wallet, FlashTokenArtifact, [wallet.address, wallet.address]);
3132
});
32-
33+
3334

3435
it("name", async () => {
3536
const name = await FlashToken.name();
3637
expect(name).to.be.equal("Flash Token");
3738
});
38-
39-
39+
40+
4041
it("symbol", async () => {
4142
expect(await FlashToken.symbol()).to.be.equal("FLASH");
4243
});
4344

44-
45+
4546
it("decimals", async () => {
4647
expect(await FlashToken.decimals()).to.be.equal(18);
4748
});
4849

49-
50+
5051
it("name hash", async () => {
5152
expect(keccak256(toUtf8Bytes("FLASH"))).to.be.equal(
5253
"0x345b72c36b14f1cee01efb8ac4b299dc7b8d873e28b4796034548a3d371a4d2f"
5354
);
5455
});
5556

56-
57+
5758
it("version hash", async () => {
5859
expect(keccak256(toUtf8Bytes("1"))).to.be.equal(
5960
"0xc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc6"
@@ -91,7 +92,7 @@ describe("Flash token", async () => {
9192

9293
it("transfer", async () => {
9394

94-
let AMOUNT = await mintTokens(FlashToken,wallet.address);
95+
let AMOUNT = await mintTokens(FlashToken, wallet.address);
9596

9697
await expect(FlashToken.transfer(walletTo.address, AMOUNT))
9798
.to.emit(FlashToken, "Transfer")
@@ -104,11 +105,11 @@ describe("Flash token", async () => {
104105

105106
it("transfer fail -> this token address", async () => {
106107

107-
let AMOUNT = await mintTokens(FlashToken,wallet.address);
108+
let AMOUNT = await mintTokens(FlashToken, wallet.address);
108109

109110
await expect(FlashToken.transfer(FlashToken.address, AMOUNT))
110111
.to.be.revertedWith("FlashToken:: RECEIVER_IS_TOKEN_OR_ZERO");
111-
112+
112113
});
113114

114115

@@ -120,39 +121,39 @@ describe("Flash token", async () => {
120121

121122
it("transfer fail -> zero address", async () => {
122123

123-
let AMOUNT = await mintTokens(FlashToken,wallet.address);
124-
124+
let AMOUNT = await mintTokens(FlashToken, wallet.address);
125+
125126
await expect(FlashToken.transfer(constants.AddressZero, AMOUNT))
126-
.to.be.revertedWith("FlashToken:: RECEIVER_IS_TOKEN_OR_ZERO");
127-
127+
.to.be.revertedWith("FlashToken:: RECEIVER_IS_TOKEN_OR_ZERO");
128+
128129
});
129130

130131

131132
it("transferFrom", async () => {
132133

133-
let AMOUNT = await mintTokens(FlashToken,wallet.address);
134-
134+
let AMOUNT = await mintTokens(FlashToken, wallet.address);
135+
135136
await FlashToken.approve(walletTo.address, AMOUNT);
136137
const Another = FlashToken.connect(walletTo);
137-
138+
138139
await expect(Another.transferFrom(wallet.address, walletTo.address, AMOUNT))
139140
.to.emit(FlashToken, "Transfer")
140141
.withArgs(wallet.address, walletTo.address, AMOUNT);
141-
142-
expect(
142+
143+
expect(
143144
await FlashToken.allowance(wallet.address, walletTo.address)
144145
).to.equal(0);
145-
146+
146147
expect(await FlashToken.balanceOf(wallet.address)).to.equal(0);
147-
148+
148149
expect(await FlashToken.balanceOf(walletTo.address)).to.equal(AMOUNT);
149150
});
150151

151152

152153
it("permit", async () => {
153154

154-
let AMOUNT = await mintTokens(FlashToken,wallet.address);
155-
155+
let AMOUNT = await mintTokens(FlashToken, wallet.address);
156+
156157
const deadline: any = constants.MaxUint256;
157158
const nonces = await FlashToken.nonces(wallet.address);
158159

@@ -193,12 +194,21 @@ describe("Flash token", async () => {
193194
hexlify(s)
194195
)
195196
).to.emit(FlashToken, "Approval");
196-
197-
expect(
198-
await FlashToken.allowance(wallet.address, walletTo.address)
199-
).to.equal(AMOUNT);
200-
201-
expect(await FlashToken.nonces(wallet.address)).to.equal(1);
202-
197+
203198
});
199+
200+
it("flashmint", async () => {
201+
let MinterContract: any = await deployContract(wallet, MinterContractArtifact, [FlashToken.address]);
202+
let encode = ethers.utils.defaultAbiCoder.encode(['bool', 'uint256', 'address'], [false, '1000000000000000000', wallet.address]);
203+
await expect(MinterContract.flashMint("1000000000000000000", encode)
204+
).to.emit(FlashToken, "Transfer");
205+
expect(await FlashToken.flashSupply()).to.equal(0);
206+
})
207+
208+
it("flashmint fail", async () => {
209+
let MinterContract: any = await deployContract(wallet, MinterContractArtifact, [FlashToken.address]);
210+
let encode = ethers.utils.defaultAbiCoder.encode(['bool', 'uint256', 'address'], [true, '1000000000000000000', wallet.address]);
211+
await expect(MinterContract.flashMint("1000000000000000000", encode))
212+
.to.be.revertedWith("FlashToken:: TRANSFER_EXCEED_BALANCE");
213+
})
204214
});

0 commit comments

Comments
 (0)