-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
wsg eth test finished #21
Closed
Closed
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
bc514dc
wsg eth test finished
devlancer412 293aa63
reentrant bugfix on wsgEth contract
devlancer412 7626c67
Merge branch 'main' into test/wsgEth
devlancer412 f90f060
redeem rate test
devlancer412 753c1ff
removed console log
devlancer412 6e79583
added comment
devlancer412 3638424
removed manual syncReward call
devlancer412 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,122 @@ | ||
const {ethers} = require("hardhat"); | ||
const {expect} = require("chai"); | ||
const {parseEther} = require("ethers/lib/utils"); | ||
|
||
describe.only("WsgETH.sol", () => { | ||
let sgEth, wsgEth, deployer, alice; | ||
let MINTER_ROLE; | ||
|
||
beforeEach(async () => { | ||
const [owner, addr1] = await ethers.getSigners(); | ||
|
||
const SgETH = await ethers.getContractFactory("SgETH"); | ||
sgEth = await SgETH.deploy([]); | ||
await sgEth.deployed(); | ||
|
||
deployer = owner; | ||
alice = addr1; | ||
|
||
MINTER_ROLE = await sgEth.MINTER(); | ||
|
||
// deploy wsgeth | ||
const WSGETH = await ethers.getContractFactory("WSGETH"); | ||
wsgEth = await WSGETH.deploy(sgEth.address, 24 * 60 * 60); | ||
await wsgEth.deployed(); | ||
|
||
// mint tokens for test | ||
await sgEth.addMinter(deployer.address); | ||
await sgEth.mint(deployer.address, parseEther("1000")); | ||
}); | ||
|
||
it("deposit", async () => { | ||
await expect(wsgEth.connect(alice).deposit(parseEther("1"), alice.address)).to.be.revertedWith( | ||
"TRANSFER_FROM_FAILED", | ||
); | ||
await expect(wsgEth.deposit(parseEther("1"), alice.address)).to.be.revertedWith("TRANSFER_FROM_FAILED"); | ||
|
||
await sgEth.approve(wsgEth.address, parseEther("1")); | ||
await expect(wsgEth.deposit(parseEther("1"), alice.address)) | ||
.to.be.emit(wsgEth, "Transfer") | ||
.withArgs(ethers.constants.AddressZero, alice.address, parseEther("1")); | ||
}); | ||
|
||
it("mint", async () => { | ||
await expect(wsgEth.connect(alice).mint(parseEther("1"), alice.address)).to.be.revertedWith("TRANSFER_FROM_FAILED"); | ||
await expect(wsgEth.mint(parseEther("1"), alice.address)).to.be.revertedWith("TRANSFER_FROM_FAILED"); | ||
|
||
await sgEth.approve(wsgEth.address, parseEther("1")); | ||
await expect(wsgEth.mint(parseEther("1"), alice.address)) | ||
.to.be.emit(wsgEth, "Transfer") | ||
.withArgs(ethers.constants.AddressZero, alice.address, parseEther("1")); | ||
}); | ||
|
||
it("withdraw", async () => { | ||
await expect(wsgEth.withdraw(parseEther("1"), alice.address, alice.address)).to.be.revertedWith(""); // panic revert by insufficient allowance | ||
await wsgEth.connect(alice).approve(deployer.address, parseEther("1000")); | ||
|
||
await expect(wsgEth.withdraw(parseEther("1"), alice.address, alice.address)).to.be.revertedWith(""); // panic revert by insufficient balance | ||
|
||
// mint wsgEth to alice | ||
await sgEth.approve(wsgEth.address, parseEther("1")); | ||
await wsgEth.deposit(parseEther("1"), alice.address); | ||
|
||
await expect(wsgEth.withdraw(parseEther("1"), alice.address, alice.address)) | ||
.to.be.emit(wsgEth, "Withdraw") | ||
.withArgs(deployer.address, alice.address, alice.address, parseEther("1"), parseEther("1")); | ||
}); | ||
|
||
it("redeem", async () => { | ||
await expect(wsgEth.redeem(parseEther("1"), alice.address, alice.address)).to.be.revertedWith(""); // panic revert by insufficient allowance | ||
await wsgEth.connect(alice).approve(deployer.address, parseEther("1000")); | ||
|
||
await expect(wsgEth.redeem(parseEther("1"), alice.address, alice.address)).to.be.revertedWith(""); // panic revert by insufficient balance | ||
|
||
// mint wsgEth to alice | ||
await sgEth.approve(wsgEth.address, parseEther("1")); | ||
await wsgEth.deposit(parseEther("1"), alice.address); | ||
|
||
await expect(wsgEth.redeem(parseEther("1"), alice.address, alice.address)) | ||
.to.be.emit(wsgEth, "Withdraw") | ||
.withArgs(deployer.address, alice.address, alice.address, parseEther("1"), parseEther("1")); | ||
}); | ||
|
||
it("depositWithSignature", async () => { | ||
await sgEth.transfer(alice.address, parseEther("1")); | ||
const nonce = await sgEth.nonces(alice.address); | ||
const deadline = Math.floor(Date.now() / 1000) + 1000; | ||
const approveData = { | ||
owner: alice.address, | ||
spender: wsgEth.address, | ||
value: parseEther("1"), | ||
nonce, | ||
deadline: deadline, | ||
}; | ||
|
||
const domain = await sgEth.eip712Domain(); | ||
|
||
const signature = await alice._signTypedData( | ||
{ | ||
name: domain.name, | ||
version: domain.version, | ||
chainId: domain.chainId, | ||
verifyingContract: domain.verifyingContract, | ||
}, | ||
{ | ||
Permit: [ | ||
{name: "owner", type: "address"}, | ||
{name: "spender", type: "address"}, | ||
{name: "value", type: "uint256"}, | ||
{name: "nonce", type: "uint256"}, | ||
{name: "deadline", type: "uint256"}, | ||
], | ||
}, | ||
approveData, | ||
); | ||
|
||
const {r, s, v} = ethers.utils.splitSignature(signature); | ||
|
||
// await expect(wsgEth.connect(alice).depositWithSignature(parseEther("1"), alice.address, deadline, false, v, r, s)) | ||
// .to.be.emit(wsgEth, "Transfer") | ||
// .withArgs(ethers.constants.AddressZero, alice.address, parseEther("1")); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this not work as expected?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. You can check this issue.
#19