Skip to content

Commit

Permalink
ON-489: Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Lima committed Sep 29, 2023
1 parent f71d9d7 commit dc06c93
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
4 changes: 2 additions & 2 deletions contracts/OriumMarketplace.sol
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,8 @@ contract OriumMarketplace is Initializable, OwnableUpgradeable, PausableUpgradea
function _validateEndRental(RentalOffer memory _offer, bytes32 _offerHash) internal view {
require(isCreated[_offerHash], "OriumMarketplace: Offer not created");
require(msg.sender == rentals[_offerHash].borrower, "OriumMarketplace: Only borrower can end a rental");
require(nonceDeadline[_offer.lender][_offer.nonce] > block.timestamp, "OriumMarketplace: Rental expired");
require(rentals[_offerHash].expirationDate > block.timestamp, "OriumMarketplace: Rental already ended");
require(nonceDeadline[_offer.lender][_offer.nonce] > block.timestamp, "OriumMarketplace: Rental Offer expired");
require(rentals[_offerHash].expirationDate > block.timestamp, "OriumMarketplace: Rental ended");
}

/**
Expand Down
21 changes: 12 additions & 9 deletions test/OriumMarketplace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { deployMarketplaceContracts } from './fixtures/OriumMarketplaceFixture'
import { expect } from 'chai'
import { toWei } from '../utils/bignumber'
import { FeeInfo, RentalOffer, RoyaltyInfo } from '../utils/types'
import { EMPTY_BYTES, ONE_DAY, ONE_HOUR } from '../utils/constants'
import { AddressZero, EMPTY_BYTES, ONE_DAY, ONE_HOUR } from '../utils/constants'
import { randomBytes } from 'crypto'
import { USER_ROLE } from '../utils/roles'

Expand Down Expand Up @@ -58,7 +58,7 @@ describe('OriumMarketplace', () => {
rentalOffer = {
nonce: `0x${randomBytes(32).toString('hex')}`,
lender: lender.address,
borrower: borrower.address,
borrower: AddressZero,
tokenAddress: mockERC721.address,
tokenId,
feeTokenAddress: mockERC20.address,
Expand Down Expand Up @@ -159,7 +159,7 @@ describe('OriumMarketplace', () => {
rentalOffer.tokenAddress,
rentalOffer.tokenId,
rentalOffer.lender,
rentalOffer.borrower,
borrower.address,
expirationDate,
)
})
Expand All @@ -173,7 +173,7 @@ describe('OriumMarketplace', () => {
rentalOffer.tokenAddress,
rentalOffer.tokenId,
rentalOffer.lender,
rentalOffer.borrower,
borrower.address,
rentalExpirationDate1,
)

Expand All @@ -186,7 +186,7 @@ describe('OriumMarketplace', () => {
rentalOffer.tokenAddress,
rentalOffer.tokenId,
rentalOffer.lender,
rentalOffer.borrower,
borrower.address,
rentalExpirationDate1 + duration + 1,
)
})
Expand All @@ -208,6 +208,9 @@ describe('OriumMarketplace', () => {
)
})
it('Should NOT accept a rental offer if caller is not the borrower', async () => {
rentalOffer.nonce = `0x${randomBytes(32).toString('hex')}`
rentalOffer.borrower = borrower.address
await marketplace.connect(lender).createRentalOffer(rentalOffer)
await expect(
marketplace.connect(notOperator).acceptRentalOffer(rentalOffer, duration),
).to.be.revertedWith('OriumMarketplace: Sender is not allowed to rent this NFT')
Expand Down Expand Up @@ -261,7 +264,7 @@ describe('OriumMarketplace', () => {
rentalOffer.tokenAddress,
rentalOffer.tokenId,
rentalOffer.lender,
rentalOffer.borrower,
borrower.address,
expirationDate,
)
.to.emit(mockERC20, 'Transfer')
Expand Down Expand Up @@ -371,7 +374,7 @@ describe('OriumMarketplace', () => {
await ethers.provider.send('evm_increaseTime', [timeToMove])

await expect(marketplace.connect(borrower).endRental(rentalOffer)).to.be.revertedWith(
'OriumMarketplace: Rental expired',
'OriumMarketplace: Rental Offer expired',
)
})
it('Should end a rental if the role was revoked by borrower directly in registry', async () => {
Expand All @@ -383,7 +386,7 @@ describe('OriumMarketplace', () => {
rentalOffer.tokenAddress,
rentalOffer.tokenId,
rentalOffer.lender,
rentalOffer.borrower,
borrower.address,
)
await expect(marketplace.connect(borrower).endRental(rentalOffer))
.to.emit(marketplace, 'RentalEnded')
Expand All @@ -398,7 +401,7 @@ describe('OriumMarketplace', () => {
it('Should NOT end rental twice', async () => {
await marketplace.connect(borrower).endRental(rentalOffer)
await expect(marketplace.connect(borrower).endRental(rentalOffer)).to.be.revertedWith(
'OriumMarketplace: Rental already ended',
'OriumMarketplace: Rental ended',
)
})
})
Expand Down

0 comments on commit dc06c93

Please sign in to comment.