-
Notifications
You must be signed in to change notification settings - Fork 66
Test/ Refactor of swap operator tests #486
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
Conversation
54b532b
to
9ee07fc
Compare
// Executing as non-controller should succeed | ||
await setNextBlockTime(deadline + 1); | ||
await swapOperator.connect(governance).closeOrder(contractOrder); | ||
// Executing as non-controller should succeed |
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.
let's make this address some random address not governance so the test is accurate
test/unit/SwapOperator/closeOrder.js
Outdated
.to.emit(swapOperator, 'OrderClosed') | ||
.withArgs(makeOrderTuple(contractOrder), order.sellAmount.div(2)); | ||
}); | ||
it('emitting OrderClosed event when order was partially filled', async function () { |
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.
emits OrderClosed event when order was partially filled
test/unit/SwapOperator/closeOrder.js
Outdated
|
||
it('when order was fully filled', async function () { | ||
await cowSettlement.fill(contractOrder, orderUID, order.sellAmount, order.feeAmount, order.buyAmount); | ||
it('emitting OrderClosed event when order was fully filled', async function () { |
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.
emits OrderClosed event when order was fully filled
test/unit/SwapOperator/closeOrder.js
Outdated
expect(await weth.allowance(swapOperator.address, cowVaultRelayer.address)).to.eq( | ||
order.sellAmount.add(order.feeAmount), | ||
); | ||
it('canceling the presignature and allowance: does so if the order was not filled at all', async function () { |
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.
'presignature is false and allowance is 0 when order was not filled at all'
test/unit/SwapOperator/closeOrder.js
Outdated
order.feeAmount.div(2), | ||
order.buyAmount.div(2), | ||
); | ||
it('canceling the presignature and allowance: does so if the order is partially filled', async function () { |
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.
'cancels presignature and allowance when the order is partially filled'
test/unit/SwapOperator/closeOrder.js
Outdated
); | ||
expect(await dai.balanceOf(swapOperator.address)).to.eq(0); | ||
expect(await weth.balanceOf(swapOperator.address)).to.gt(0); | ||
it('canceling the presignature and allowance: does so if the order was fully filled', async function () { |
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.
'cancels presignature and allowance when the order is fully filled'
test/unit/SwapOperator/closeOrder.js
Outdated
it('withdraws and unwraps ether if buyToken is weth', async function () { | ||
// Cancel current order | ||
await swapOperator.closeOrder(contractOrder); | ||
it('withdrawing buyToken to pool withdraws and unwraps ether if buyToken is weth', async function () { |
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.
withdraws buyToken to pool and unwraps ether if buyToken is weth
test/unit/SwapOperator/closeOrder.js
Outdated
it('transfer the erc20 token if its not weth', async function () { | ||
expect(await dai.balanceOf(swapOperator.address)).to.eq(0); | ||
expect(await dai.balanceOf(pool.address)).to.eq(0); | ||
it('withdrawing buyToken to pool transfer the erc20 token if its not weth', async function () { |
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.
withdraws buyToken to pool when buyToken is an erc20 token
test/unit/SwapOperator/closeOrder.js
Outdated
it('withdraws and unwraps ether if sellToken is weth', async function () { | ||
const initialPoolEth = await ethers.provider.getBalance(pool.address); | ||
const initialOperatorWeth = await weth.balanceOf(swapOperator.address); | ||
it('returning sellToken to pool withdraws and unwraps ether if sellToken is weth', async function () { |
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.
returns sellToken to pool and unwraps ether if sellToken is weth
test/unit/SwapOperator/closeOrder.js
Outdated
it('transfers the erc20 token to pool if its not weth', async function () { | ||
// Cancel current order | ||
await swapOperator.closeOrder(contractOrder); | ||
it('returning sellToken to pool transfers the erc20 token to pool if its not weth', async function () { |
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.
returns sellToken to pool when sellToken is an erc20 token
test/unit/SwapOperator/closeOrder.js
Outdated
.to.emit(swapOperator, 'OrderClosed') | ||
.withArgs(makeOrderTuple(contractOrder), 0); | ||
}); | ||
it('when order was not filled', async function () { |
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.
emits OrderClosed event when order was not filled
test/unit/SwapOperator/placeOrder.js
Outdated
it('performs the validation when buyToken is not WETH', async function () { | ||
// Since DAI was already registered on setup, set its details to 0 | ||
await pool.connect(governance).setSwapDetails(dai.address, 0, 0, 0, true); // otherSigner is governant | ||
it('performs the validation assets details when buyToken is not WETH', async function () { |
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.
validates asset details when buyToken is not WETH
test/unit/SwapOperator/placeOrder.js
Outdated
lastSwapTime = (await pool.getAssetSwapDetails(dai.address)).lastSwapTime; | ||
expect(lastSwapTime).to.eq(await lastBlockTimestamp()); | ||
}); | ||
it('setting lastSwapDate: sets it on buyAsset when selling ETH', async function () { |
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.
sets lastSwapDate on buyAsset when selling ETH
test/unit/SwapOperator/placeOrder.js
Outdated
describe('setting pools swapValue', function () { | ||
it('works when selling eth', async function () { | ||
expect(await pool.swapValue()).to.eq(0); | ||
it('setting lastSwapDate: sets it on sellAsset when buying ETH', async function () { |
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.
sets lastSwapDate on sellAsset when buying ETH
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.
Test description renames required
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.
LGTM
3772821
to
f7a00c6
Compare
Context
Closes #390
Changes proposed in this pull request
Refactored out some common constants between
placeOrder
andcloseOrder
. Also tried to flatten the nesting ofdescribe
blocks without losing too much context for each unit test.Checklist
Review
When reviewing a PR, please indicate intention in comments using the following emojis: