generated from NomicFoundation/hardhat-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from traderjoe-xyz/launch-event-phase-one-testing
Launch event phase one testing
- Loading branch information
Showing
6 changed files
with
274 additions
and
31 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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
compile: | ||
yarn run hardhat compile | ||
|
||
.PHONY: test | ||
test: | ||
yarn run hardhat test | ||
|
||
clean: | ||
yarn run hardhat clean | ||
|
||
coverage: | ||
yarn run hardhat coverage | ||
|
||
console: | ||
yarn run hardhat console |
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
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
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
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
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,245 @@ | ||
const { ethers, network } = require("hardhat"); | ||
const { expect } = require("chai"); | ||
|
||
describe("Launch event contract phase one", function () { | ||
before(async function () { | ||
this.signers = await ethers.getSigners(); | ||
this.dev = this.signers[0]; | ||
this.alice = this.signers[1]; | ||
this.bob = this.signers[2]; | ||
this.carol = this.signers[3]; | ||
|
||
await network.provider.request({ | ||
method: "hardhat_reset", | ||
params: [ | ||
{ | ||
forking: { | ||
jsonRpcUrl: "https://api.avax.network/ext/bc/C/rpc", | ||
// blockNumber: 8465376, | ||
}, | ||
live: false, | ||
saveDeployments: true, | ||
tags: ["test", "local"], | ||
}, | ||
], | ||
}); | ||
}); | ||
|
||
beforeEach(async function () { | ||
// We want to setup | ||
// The Rocket factory contract | ||
// A new ERC20 for the auction | ||
// rocket-joe token | ||
this.WAVAX = "0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7"; | ||
this.wavax = ethers.getContractAt("IWAVAX", this.WAVAX); | ||
this.PENALTY_COLLECTOR = this.carol.address; | ||
this.ROUTER = "0x60aE616a2155Ee3d9A68541Ba4544862310933d4"; | ||
this.FACTORY = "0x9Ad6C38BE94206cA50bb0d90783181662f0Cfa10"; | ||
|
||
this.RocketJoeTokenCF = await ethers.getContractFactory("RocketJoeToken"); | ||
this.rJOE = await this.RocketJoeTokenCF.deploy(); | ||
this.AUCTOK = await this.RocketJoeTokenCF.deploy(); | ||
// Send rJOE to dev address | ||
await this.rJOE | ||
.connect(this.dev) | ||
.mint(this.dev.address, "1000000000000000000000000"); | ||
|
||
await this.rJOE | ||
.connect(this.dev) | ||
.mint(this.bob.address, ethers.utils.parseEther("10.0")); | ||
|
||
// Send auction token to the dev. | ||
await this.AUCTOK.connect(this.dev).mint( | ||
this.dev.address, | ||
"1000000000000000000000000" | ||
); | ||
|
||
this.LaunchEventCF = await ethers.getContractFactory("LaunchEvent"); | ||
this.RocketFactoryCF = await ethers.getContractFactory("RocketJoeFactory"); | ||
this.RocketFactory = await this.RocketFactoryCF.deploy( | ||
this.rJOE.address, | ||
this.WAVAX, | ||
this.PENALTY_COLLECTOR, | ||
this.ROUTER, | ||
this.FACTORY | ||
); | ||
await this.AUCTOK.connect(this.dev).approve( | ||
this.RocketFactory.address, | ||
"1000000000000000000000000" | ||
); | ||
|
||
// Deploy the launch event contract | ||
block = await ethers.provider.getBlock(); | ||
await this.RocketFactory.createRJLaunchEvent( | ||
this.alice.address, // Issuer | ||
block.timestamp + 60, // Start time (60 seconds from now) | ||
this.AUCTOK.address, // Address of the token being auctioned | ||
100, // Floor price (100 Wei) | ||
1000, // Amount of tokens for auction | ||
2893517, // Withdraw penalty gradient | ||
4e11, // Fixed withdraw penalty | ||
5000, // min allocation | ||
ethers.utils.parseEther("5.0"), // max allocation | ||
60 * 60 * 24 * 7 - 1, // User timelock | ||
60 * 60 * 24 * 8 // Issuer timelock | ||
); | ||
|
||
// Get a reference to the acutal launch event contract. | ||
this.LaunchEvent = await ethers.getContractAt( | ||
"LaunchEvent", | ||
this.RocketFactory.getRJLaunchEvent(this.AUCTOK.address) | ||
); | ||
}); | ||
|
||
describe("Interacting with phase one", function () { | ||
it("It should revert if sale has not started yet", async function () { | ||
expect( | ||
this.LaunchEvent.connect(this.bob).depositAVAX({ | ||
value: ethers.utils.parseEther("1.0"), | ||
}) | ||
).to.be.revertedWith("LaunchEvent: Not in phase one"); | ||
}); | ||
|
||
it("It should revert if rJOE not approved", async function () { | ||
await network.provider.send("evm_increaseTime", [120]); | ||
await network.provider.send("evm_mine"); | ||
expect( | ||
this.LaunchEvent.connect(this.bob).depositAVAX({ | ||
value: ethers.utils.parseEther("1.0"), | ||
}) | ||
).to.be.revertedWith("ERC20: transfer amount exceeds allowance"); | ||
}); | ||
|
||
it("should be payable with AVAX", async function () { | ||
await network.provider.send("evm_increaseTime", [120]); | ||
await network.provider.send("evm_mine"); | ||
await this.rJOE | ||
.connect(this.bob) | ||
.approve(this.LaunchEvent.address, ethers.utils.parseEther("1.0")); | ||
await this.LaunchEvent.connect(this.bob).depositAVAX({ | ||
value: ethers.utils.parseEther("1.0"), | ||
}); | ||
expect(this.LaunchEvent.users(this.bob.address).amount).to.equal( | ||
ethers.utils.parseEther("1.0").number | ||
); | ||
}); | ||
|
||
it("should revert if AVAX sent less than min allocation", async function () { | ||
await network.provider.send("evm_increaseTime", [120]); | ||
await network.provider.send("evm_mine"); | ||
await this.rJOE.connect(this.bob).approve(this.LaunchEvent.address, 4999); | ||
expect( | ||
this.LaunchEvent.connect(this.bob).depositAVAX({ value: 4999 }) | ||
).to.be.revertedWith( | ||
"LaunchEvent: Not enough AVAX sent to meet the min allocation" | ||
); | ||
}); | ||
|
||
it("Should only be pausable by owner", async function () { | ||
expect(this.LaunchEvent.connect(this.dev).pause()).to.be.revertedWith( | ||
"Ownable: caller is not the owner" | ||
); | ||
}); | ||
|
||
it("should revert if paused", async function () { | ||
await network.provider.send("evm_increaseTime", [120]); | ||
await network.provider.send("evm_mine"); | ||
await this.rJOE.connect(this.bob).approve(this.LaunchEvent.address, 4999); | ||
await this.LaunchEvent.connect(this.alice).pause(); | ||
expect( | ||
this.LaunchEvent.connect(this.bob).depositAVAX({ value: 4999 }) | ||
).to.be.revertedWith("LaunchEvent: Contract is paused"); | ||
}); | ||
|
||
it("should revert if AVAX sent more than max allocation", async function () { | ||
await network.provider.send("evm_increaseTime", [120]); | ||
await network.provider.send("evm_mine"); | ||
await this.rJOE | ||
.connect(this.bob) | ||
.approve(this.LaunchEvent.address, ethers.utils.parseEther("6")); | ||
expect( | ||
this.LaunchEvent.connect(this.bob).depositAVAX({ | ||
value: ethers.utils.parseEther("6"), | ||
}) | ||
).to.be.revertedWith( | ||
"LaunchEvent: Too much AVAX sent to meet the max allocation" | ||
); | ||
}); | ||
|
||
it("should burn rJOE on succesful deposit", async function () { | ||
let rJOEBefore = await this.rJOE.totalSupply(); | ||
|
||
await network.provider.send("evm_increaseTime", [120]); | ||
await network.provider.send("evm_mine"); | ||
await this.rJOE | ||
.connect(this.bob) | ||
.approve(this.LaunchEvent.address, ethers.utils.parseEther("1.0")); | ||
|
||
await this.LaunchEvent.connect(this.bob).depositAVAX({ | ||
value: ethers.utils.parseEther("1.0"), | ||
}); | ||
|
||
expect(await this.rJOE.totalSupply()).to.be.equal( | ||
rJOEBefore.sub(ethers.utils.parseEther("1.0")) | ||
); | ||
}); | ||
|
||
it("should apply no fee if withdraw in first day", async function () { | ||
await network.provider.send("evm_increaseTime", [120]); | ||
await network.provider.send("evm_mine"); | ||
await this.rJOE | ||
.connect(this.bob) | ||
.approve(this.LaunchEvent.address, ethers.utils.parseEther("1.0")); | ||
|
||
await this.LaunchEvent.connect(this.bob).depositAVAX({ | ||
value: ethers.utils.parseEther("1.0"), | ||
}); | ||
|
||
// Test the amount received | ||
const balanceBefore = await this.bob.getBalance(); | ||
await this.LaunchEvent.connect(this.bob).withdrawWAVAX( | ||
ethers.utils.parseEther("1.0") | ||
); | ||
expect(await this.bob.getBalance()).to.be.above(balanceBefore); | ||
// Check the balance of penalty collecter. | ||
expect(await this.carol.getBalance()).to.equal("10000000000000000000000"); | ||
}); | ||
|
||
it("should apply gradient fee if withdraw in second day", async function () { | ||
await network.provider.send("evm_increaseTime", [120]); | ||
await network.provider.send("evm_mine"); | ||
await this.rJOE | ||
.connect(this.bob) | ||
.approve(this.LaunchEvent.address, ethers.utils.parseEther("1.0")); | ||
|
||
await this.LaunchEvent.connect(this.bob).depositAVAX({ | ||
value: ethers.utils.parseEther("1.0"), | ||
}); | ||
await network.provider.send("evm_increaseTime", [60 * 60 * 36]); // 1.5 days | ||
await network.provider.send("evm_mine"); | ||
await this.LaunchEvent.connect(this.bob).withdrawWAVAX( | ||
ethers.utils.parseEther("1.0") | ||
); | ||
|
||
// Check the balance of penalty collecter. | ||
expect(await this.carol.getBalance()).to.be.above( | ||
"10000000000000000000000" | ||
); | ||
}); | ||
|
||
it("should revert try to create pool during phase one", async function () { | ||
await network.provider.send("evm_increaseTime", [120]); | ||
await network.provider.send("evm_mine"); | ||
expect( | ||
this.LaunchEvent.connect(this.dev).createPair() | ||
).to.be.revertedWith("LaunchEvent: Not in phase three"); | ||
}); | ||
}); | ||
|
||
after(async function () { | ||
await network.provider.request({ | ||
method: "hardhat_reset", | ||
params: [], | ||
}); | ||
}); | ||
}); |