-
Notifications
You must be signed in to change notification settings - Fork 382
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
Remove salt from veboost domain separator and expose version #2085
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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,131 @@ | ||
import { expect } from 'chai'; | ||
import { ethers } from 'hardhat'; | ||
import { BigNumber, Contract } from 'ethers'; | ||
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/dist/src/signer-with-address'; | ||
|
||
import * as expectEvent from '@balancer-labs/v2-helpers/src/test/expectEvent'; | ||
import { deploy } from '@balancer-labs/v2-helpers/src/contract'; | ||
import { MAX_UINT256 as MAX_DEADLINE, ZERO_ADDRESS } from '@balancer-labs/v2-helpers/src/constants'; | ||
import { bn } from '@balancer-labs/v2-helpers/src/numbers'; | ||
import { signPermit } from '@balancer-labs/balancer-js'; | ||
import { currentTimestamp } from '@balancer-labs/v2-helpers/src/time'; | ||
|
||
describe('BoostV2', () => { | ||
let boost: Contract; | ||
let holder: SignerWithAddress, spender: SignerWithAddress; | ||
|
||
before('setup signers', async () => { | ||
[, holder, spender] = await ethers.getSigners(); | ||
}); | ||
|
||
sharedBeforeEach('deploy veBoostV2', async () => { | ||
boost = await deploy('BoostV2', { args: [ZERO_ADDRESS, ZERO_ADDRESS] }); | ||
}); | ||
|
||
describe('info', () => { | ||
it('sets up the name properly', async () => { | ||
expect(await boost.name()).to.be.equal('Vote-Escrowed Boost'); | ||
}); | ||
|
||
it('sets up the symbol properly', async () => { | ||
expect(await boost.symbol()).to.be.equal('veBoost'); | ||
}); | ||
|
||
it('sets up the version properly', async () => { | ||
expect(await boost.version()).to.be.equal('v2.0.0'); | ||
}); | ||
}); | ||
|
||
describe('permit', () => { | ||
it('initial nonce is zero', async () => { | ||
expect(await boost.nonces(holder.address)).to.equal(0); | ||
}); | ||
|
||
const amount = bn(42); | ||
|
||
it('accepts holder signature', async function () { | ||
const previousNonce = await boost.nonces(holder.address); | ||
const { v, r, s } = await signPermit(boost, holder, spender, amount); | ||
|
||
const receipt = await (await boost.permit(holder.address, spender.address, amount, MAX_DEADLINE, v, r, s)).wait(); | ||
expectEvent.inReceipt(receipt, 'Approval', { _owner: holder.address, _spender: spender.address, _value: amount }); | ||
|
||
expect(await boost.nonces(holder.address)).to.equal(previousNonce.add(1)); | ||
expect(await boost.allowance(holder.address, spender.address)).to.equal(amount); | ||
}); | ||
|
||
context('with invalid signature', () => { | ||
let v: number, r: string, s: string, deadline: BigNumber; | ||
|
||
context('with reused signature', () => { | ||
beforeEach(async () => { | ||
({ v, r, s, deadline } = await signPermit(boost, holder, spender, amount)); | ||
await boost.permit(holder.address, spender.address, amount, deadline, v, r, s); | ||
}); | ||
|
||
itRevertsWithInvalidSignature(); | ||
}); | ||
|
||
context('with signature for other holder', () => { | ||
beforeEach(async () => { | ||
({ v, r, s, deadline } = await signPermit(boost, spender, spender, amount)); | ||
}); | ||
|
||
itRevertsWithInvalidSignature(); | ||
}); | ||
|
||
context('with signature for other spender', () => { | ||
beforeEach(async () => { | ||
({ v, r, s, deadline } = await signPermit(boost, holder, holder, amount)); | ||
}); | ||
|
||
itRevertsWithInvalidSignature(); | ||
}); | ||
|
||
context('with signature for other amount', () => { | ||
beforeEach(async () => { | ||
({ v, r, s, deadline } = await signPermit(boost, holder, spender, amount.add(1))); | ||
}); | ||
|
||
itRevertsWithInvalidSignature(); | ||
}); | ||
|
||
context('with signature for other token', () => { | ||
beforeEach(async () => { | ||
const otherToken = await deploy('v2-solidity-utils/ERC20PermitMock', { args: ['Token', 'TKN'] }); | ||
|
||
({ v, r, s, deadline } = await signPermit(otherToken, holder, spender, amount)); | ||
}); | ||
|
||
itRevertsWithInvalidSignature(); | ||
}); | ||
|
||
context('with signature with invalid nonce', () => { | ||
beforeEach(async () => { | ||
const currentNonce = await boost.nonces(holder.address); | ||
({ v, r, s, deadline } = await signPermit(boost, holder, spender, amount, MAX_DEADLINE, currentNonce.add(1))); | ||
}); | ||
|
||
itRevertsWithInvalidSignature(); | ||
}); | ||
|
||
context('with expired deadline', () => { | ||
beforeEach(async () => { | ||
const now = await currentTimestamp(); | ||
|
||
({ v, r, s, deadline } = await signPermit(boost, holder, spender, amount, now.sub(1))); | ||
}); | ||
|
||
itRevertsWithInvalidSignature('EXPIRED_SIGNATURE'); | ||
}); | ||
|
||
function itRevertsWithInvalidSignature(reason?: string) { | ||
it('reverts', async () => { | ||
await expect(boost.permit(holder.address, spender.address, amount, deadline, v, r, s)).to.be.revertedWith( | ||
reason ?? 'INVALID_SIGNATURE' | ||
); | ||
}); | ||
} | ||
}); | ||
}); | ||
}); |
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.
Good call