Skip to content

Commit

Permalink
fix: reentrancy only
Browse files Browse the repository at this point in the history
  • Loading branch information
EduardoMelo00 committed Aug 14, 2024
1 parent c2c882e commit 6ed60f2
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion test/OriumSftMarketplace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ describe('OriumSftMarketplace', () => {
).to.be.revertedWith('OriumSftMarketplace: Insufficient native token amount')
})

it.only('should detect reentrancy attack during fee transfer', async () => {
it('should detect reentrancy attack during fee transfer', async () => {
const AttackContract = await ethers.getContractFactory('ReentrancyAttack')
attackContract = (await AttackContract.deploy(marketplace)) as ReentrancyAttack
await attackContract.waitForDeployment()
Expand Down Expand Up @@ -752,6 +752,41 @@ describe('OriumSftMarketplace', () => {
).to.be.revertedWith('OriumSftMarketplace: This offer has an ongoing rental')
})

it('should revert when accept offer is called from Attack contract after a offer be accepeted by borrower', async () => {
const AttackContract = await ethers.getContractFactory('ReentrancyAttack')
attackContract = (await AttackContract.deploy(marketplace)) as ReentrancyAttack
await attackContract.waitForDeployment()

await marketplaceRoyalties
.connect(operator)
.setTrustedFeeTokenForToken([rentalOffer.tokenAddress], [AddressZero], [true])
rentalOffer.minDuration = duration
rentalOffer.feeTokenAddress = AddressZero
rentalOffer.feeAmountPerSecond = toWei('0.0000001')
const totalFeeAmount = rentalOffer.feeAmountPerSecond * BigInt(duration)

rentalOffer.nonce = `0x${randomBytes(32).toString('hex')}`
await marketplace.connect(lender).createRentalOffer({ ...rentalOffer, commitmentId: BigInt(0) })
rentalOffer.commitmentId = BigInt(2)

const blockTimestamp = (await ethers.provider.getBlock('latest'))?.timestamp
const expirationDate = Number(blockTimestamp) + duration + 1

await expect(
marketplace.connect(borrower).acceptRentalOffer(rentalOffer, duration, {
value: totalFeeAmount.toString(),
}),
)
.to.emit(marketplace, 'RentalStarted')
.withArgs(rentalOffer.lender, rentalOffer.nonce, borrower.address, expirationDate)

await expect(
attackContract.connect(lender).attack(rentalOffer, duration, {
value: totalFeeAmount,
}),
).to.be.revertedWith('OriumSftMarketplace: This offer has an ongoing rental')
})

describe('Fees', async function () {
const feeAmountPerSecond = toWei('1')
const feeAmount = feeAmountPerSecond * BigInt(duration)
Expand Down

0 comments on commit 6ed60f2

Please sign in to comment.