-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
77 additions
and
3 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
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,76 @@ | ||
const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers'); | ||
const { expect } = require('@1inch/solidity-utils'); | ||
const { signOrder, buildOrder } = require('./helpers/orderUtils'); | ||
const { ethers } = require('hardhat'); | ||
const { deploySwap, deployUSDC, deployUSDT } = require('./helpers/fixtures'); | ||
|
||
describe('OrderRegistrator', function () { | ||
let addr; | ||
|
||
before(async function () { | ||
[addr] = await ethers.getSigners(); | ||
}); | ||
|
||
async function deployAndInit () { | ||
const { swap } = await deploySwap(); | ||
const { usdc } = await deployUSDC(); | ||
const { usdt } = await deployUSDT(); | ||
const OrderRegistrator = await ethers.getContractFactory('OrderRegistrator'); | ||
const registrator = await OrderRegistrator.deploy(swap); | ||
await registrator.waitForDeployment(); | ||
const chainId = (await ethers.provider.getNetwork()).chainId; | ||
return { swap, usdc, usdt, registrator, chainId }; | ||
}; | ||
|
||
it('should emit OrderRegistered event', async function () { | ||
const { usdc, usdt, swap, registrator, chainId } = await loadFixture(deployAndInit); | ||
|
||
const order = buildOrder({ | ||
makerAsset: await usdc.getAddress(), | ||
takerAsset: await usdt.getAddress(), | ||
makingAmount: 1, | ||
takingAmount: 2, | ||
maker: addr.address, | ||
}); | ||
|
||
const orderTuple = [order.salt, order.maker, order.receiver, order.makerAsset, order.takerAsset, order.makingAmount, order.takingAmount, order.makerTraits]; | ||
|
||
const signature = ethers.Signature.from(await signOrder(order, chainId, await swap.getAddress(), addr)).compactSerialized; | ||
|
||
const tx = registrator.registerOrder(order, order.extension, signature); | ||
await expect(tx).to.emit(registrator, 'OrderRegistered').withArgs(orderTuple, order.extension, signature); | ||
}); | ||
|
||
it('should revert with wrong signature', async function () { | ||
const { usdc, usdt, swap, registrator, chainId } = await loadFixture(deployAndInit); | ||
|
||
const order = buildOrder({ | ||
makerAsset: await usdc.getAddress(), | ||
takerAsset: await usdt.getAddress(), | ||
makingAmount: 1, | ||
takingAmount: 2, | ||
maker: addr.address, | ||
}); | ||
const signature = ethers.Signature.from(await signOrder(order, chainId + 1n, await swap.getAddress(), addr)).compactSerialized; | ||
|
||
const tx = registrator.registerOrder(order, order.extension, signature); | ||
await expect(tx).to.be.revertedWithCustomError(swap, 'BadSignature'); | ||
}); | ||
|
||
it('should revert with wrong extension', async function () { | ||
const { usdc, usdt, swap, registrator, chainId } = await loadFixture(deployAndInit); | ||
|
||
const order = buildOrder({ | ||
makerAsset: await usdc.getAddress(), | ||
takerAsset: await usdt.getAddress(), | ||
makingAmount: 1, | ||
takingAmount: 2, | ||
maker: addr.address, | ||
}); | ||
const orderLibFactory = await ethers.getContractFactory('OrderLib'); | ||
|
||
const signature = ethers.Signature.from(await signOrder(order, chainId, await swap.getAddress(), addr)).compactSerialized; | ||
const tx = registrator.registerOrder(order, order.extension + '00', signature); | ||
await expect(tx).to.be.revertedWithCustomError(orderLibFactory, 'UnexpectedOrderExtension'); | ||
}); | ||
}); |