Skip to content

Commit

Permalink
feat: adding legacy cases validateCommitmentId
Browse files Browse the repository at this point in the history
  • Loading branch information
EDUARDO MELO DE SIQUEIRA authored and EDUARDO MELO DE SIQUEIRA committed Jul 12, 2024
1 parent b2ef8a9 commit e2a6a65
Showing 1 changed file with 115 additions and 0 deletions.
115 changes: 115 additions & 0 deletions test/OriumSftMarketplace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,45 @@ describe('OriumSftMarketplace', () => {
'OriumSftMarketplace: expected grantor does not match the grantor of the commitmentId',
)
})
it("Should NOT create a LEGACY rental offer if commitmentId grantor and offer lender's address are different", async () => {
await marketplaceRoyalties
.connect(operator)
.setRolesRegistry(
await wearableToken.getAddress(),
await SftRolesRegistrySingleRoleLegacy.getAddress(),
)

await wearableToken.mint(creator.address, tokenId, tokenAmount, '0x')
await wearableToken
.connect(creator)
.setApprovalForAll(await SftRolesRegistrySingleRoleLegacy.getAddress(), true)

const rentalOfferLegacy = {
nonce: `0x${randomBytes(32).toString('hex')}`,
commitmentId: BigInt(0),
lender: lender.address,
borrower: AddressZero,
tokenAddress: wearableAddress,
tokenId,
tokenAmount,
feeTokenAddress: await mockERC20.getAddress(),
feeAmountPerSecond: toWei('0.0000001'),
deadline: Number((await ethers.provider.getBlock('latest'))?.timestamp) + ONE_DAY,
minDuration: 1,
roles: [UNIQUE_ROLE],
rolesData: [EMPTY_BYTES],
}
await SftRolesRegistrySingleRoleLegacy.connect(creator).commitTokens(
creator.address,
rentalOfferLegacy.tokenAddress,
rentalOfferLegacy.tokenId,
rentalOfferLegacy.tokenAmount,
)
rentalOfferLegacy.commitmentId = BigInt(2)
await expect(marketplace.connect(lender).createRentalOffer(rentalOfferLegacy)).to.be.revertedWith(
'OriumSftMarketplace: expected grantor does not match the grantor of the commitmentId',
)
})
it('Should NOT create a rental offer if commitmentId token address and offer token address are different', async () => {
const AnotherMockERC1155 = await ethers.getContractFactory('MockERC1155')
const anotherMockERC1155 = await AnotherMockERC1155.deploy()
Expand Down Expand Up @@ -442,6 +481,53 @@ describe('OriumSftMarketplace', () => {
"OriumSftMarketplace: tokenId provided does not match commitment's tokenId",
)
})
it('Should NOT create a LEGACY rental offer if commitmentId token id and offer token id are different', async () => {
const rentalOfferLegacy = {
nonce: `0x${randomBytes(32).toString('hex')}`,
commitmentId: BigInt(0),
lender: lender.address,
borrower: AddressZero,
tokenAddress: wearableAddress,
tokenId,
tokenAmount,
feeTokenAddress: await mockERC20.getAddress(),
feeAmountPerSecond: toWei('0.0000001'),
deadline: Number((await ethers.provider.getBlock('latest'))?.timestamp) + ONE_DAY,
minDuration: 1,
roles: [UNIQUE_ROLE],
rolesData: [EMPTY_BYTES],
}

await marketplaceRoyalties
.connect(operator)
.setRolesRegistry(
await wearableToken.getAddress(),
await SftRolesRegistrySingleRoleLegacy.getAddress(),
)

await marketplace.connect(lender).createRentalOffer(rentalOfferLegacy)
await time.increase(ONE_DAY)
rentalOfferLegacy.commitmentId = BigInt(1)
rentalOfferLegacy.nonce = `0x${randomBytes(32).toString('hex')}`
rentalOfferLegacy.deadline = (await time.latest()) + ONE_DAY

const newTokenId = 2
await wearableToken.mint(lender.address, newTokenId, rentalOfferLegacy.tokenAmount, '0x')
await wearableToken
.connect(lender)
.setApprovalForAll(await SftRolesRegistrySingleRoleLegacy.getAddress(), true)

await SftRolesRegistrySingleRoleLegacy.connect(lender).commitTokens(
lender.address,
rentalOfferLegacy.tokenAddress,
newTokenId,
rentalOfferLegacy.tokenAmount,
)
rentalOfferLegacy.commitmentId = BigInt(2)
await expect(marketplace.connect(lender).createRentalOffer(rentalOfferLegacy)).to.be.revertedWith(
"OriumSftMarketplace: tokenId provided does not match commitment's tokenId",
)
})
it('Should NOT create a rental offer if commitmentId token amount and offer token amount are different', async () => {
rentalOffer.commitmentId = BigInt(2)
rentalOffer.tokenAmount = BigInt(3)
Expand Down Expand Up @@ -1098,6 +1184,35 @@ describe('OriumSftMarketplace', () => {
marketplace.connect(lender).batchCommitTokensAndGrantRole(commitAndGrantRoleParams),
).to.revertedWith("OriumSftMarketplace: tokenAmount provided does not match commitment's tokenAmount")
})

it('Should NOT commit LEGACY tokens and grant role if tokenAmount does not match the commitment', async () => {
await marketplaceRoyalties
.connect(operator)
.setRolesRegistry(await wearableToken.getAddress(), await SftRolesRegistrySingleRoleLegacy.getAddress())
await wearableToken.setApprovalForAll(await SftRolesRegistrySingleRoleLegacy.getAddress(), true)
commitAndGrantRoleParams[0].tokenAddress = await wearableToken.getAddress()

await SftRolesRegistrySingleRoleLegacy.connect(lender).setRoleApprovalForAll(
await wearableToken.getAddress(),
await marketplace.getAddress(),
true,
)
await wearableToken
.connect(lender)
.setApprovalForAll(await SftRolesRegistrySingleRoleLegacy.getAddress(), true)

commitAndGrantRoleParams[0].commitmentId = BigInt(1)
commitAndGrantRoleParams[0].tokenAmount = BigInt(0)
await SftRolesRegistrySingleRoleLegacy.connect(lender).commitTokens(
lender.address,
await wearableToken.getAddress(),
tokenId,
tokenAmount,
)
await expect(
marketplace.connect(lender).batchCommitTokensAndGrantRole(commitAndGrantRoleParams),
).to.revertedWith("OriumSftMarketplace: tokenAmount provided does not match commitment's tokenAmount")
})
})
})

Expand Down

0 comments on commit e2a6a65

Please sign in to comment.