difftreelog
tests(refungible-pallet): add negative tests for fractionalizer contract
in: master
1 file changed
tests/src/eth/fractionalizer/fractionalizer.test.tsdiffbeforeafterboth177178179180describe('Negative Integration Tests for fractionalizer', () => {181 itWeb3('call setRFTCollection twice', async ({api, web3, privateKeyWrapper}) => {182 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);183 const fractionalizer = await deployFractionalizer(api, web3, owner);184 const {collectionIdAddress} = await createRefungibleCollection(api, web3, owner);185 const refungibleContract = uniqueRefungible(web3, collectionIdAddress, owner);186 await refungibleContract.methods.addCollectionAdmin(fractionalizer.options.address).send();187 await fractionalizer.methods.setRFTCollection(collectionIdAddress).send();188189 await expect(fractionalizer.methods.setRFTCollection(collectionIdAddress).send()).to.be.eventually.rejected;190 });191192 itWeb3('call setRFTCollection with NFT collection', async ({api, web3, privateKeyWrapper}) => {193 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);194 const fractionalizer = await deployFractionalizer(api, web3, owner);195 const {collectionIdAddress} = await createNonfungibleCollection(api, web3, owner);196197 await expect(fractionalizer.methods.setRFTCollection(collectionIdAddress).send()).to.be.eventually.rejected;198 });199200 itWeb3('call setRFTCollection while not collection admin', async ({api, web3, privateKeyWrapper}) => {201 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);202 const fractionalizer = await deployFractionalizer(api, web3, owner);203 const {collectionIdAddress} = await createRefungibleCollection(api, web3, owner);204205 await expect(fractionalizer.methods.setRFTCollection(collectionIdAddress).send()).to.be.eventually.rejected;206 });207208 itWeb3('call setRFTCollection after mintRFTCollection', async ({api, web3, privateKeyWrapper}) => {209 const alice = privateKeyWrapper('//Alice');210 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);211 const fractionalizer = await deployFractionalizer(api, web3, owner);212 const tx = api.tx.balances.transfer(evmToAddress(fractionalizer.options.address), 10n * UNIQUE);213 await submitTransactionAsync(alice, tx);214215 const result = await fractionalizer.methods.mintRFTCollection('A', 'B', 'C').send({from: owner});216 const collectionIdAddress = result.events.RFTCollectionSet.returnValues._collection;217218 await expect(fractionalizer.methods.setRFTCollection(collectionIdAddress).send()).to.be.eventually.rejected;219 });220221 itWeb3('call nft2rft without setting RFT collection for contract', async ({api, web3, privateKeyWrapper}) => {222 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);223224 const {collectionIdAddress: nftCollectionAddress} = await createNonfungibleCollection(api, web3, owner);225 const nftContract = uniqueNFT(web3, nftCollectionAddress, owner);226 const nftTokenId = await nftContract.methods.nextTokenId().call();227 await nftContract.methods.mint(owner, nftTokenId).send();228229 const fractionalizer = await deployFractionalizer(api, web3, owner);230231 await expect(fractionalizer.methods.nft2rft(nftCollectionAddress, nftTokenId, 100).send()).to.be.eventually.rejected;232 });233234 itWeb3('call nft2rft while not owner of NFT token', async ({api, web3, privateKeyWrapper}) => {235 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);236 const nftOwner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);237238 const {collectionIdAddress: nftCollectionAddress} = await createNonfungibleCollection(api, web3, owner);239 const nftContract = uniqueNFT(web3, nftCollectionAddress, owner);240 const nftTokenId = await nftContract.methods.nextTokenId().call();241 await nftContract.methods.mint(owner, nftTokenId).send();242 await nftContract.methods.transfer(nftOwner, 1).send();243244245 const {fractionalizer} = await initFractionalizer(api, web3, privateKeyWrapper, owner);246247 await expect(fractionalizer.methods.nft2rft(nftCollectionAddress, nftTokenId, 100).send()).to.be.eventually.rejected;248 });249250 itWeb3('call nft2rft while not in list of allowed accounts', async ({api, web3, privateKeyWrapper}) => {251 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);252253 const {collectionIdAddress: nftCollectionAddress} = await createNonfungibleCollection(api, web3, owner);254 const nftContract = uniqueNFT(web3, nftCollectionAddress, owner);255 const nftTokenId = await nftContract.methods.nextTokenId().call();256 await nftContract.methods.mint(owner, nftTokenId).send();257258 const {fractionalizer} = await initFractionalizer(api, web3, privateKeyWrapper, owner);259260 await nftContract.methods.approve(fractionalizer.options.address, nftTokenId).send();261 await expect(fractionalizer.methods.nft2rft(nftCollectionAddress, nftTokenId, 100).send()).to.be.eventually.rejected;262 });263264 itWeb3('call nft2rft while fractionalizer doesnt have approval for nft token', async ({api, web3, privateKeyWrapper}) => {265 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);266267 const {collectionIdAddress: nftCollectionAddress} = await createNonfungibleCollection(api, web3, owner);268 const nftContract = uniqueNFT(web3, nftCollectionAddress, owner);269 const nftTokenId = await nftContract.methods.nextTokenId().call();270 await nftContract.methods.mint(owner, nftTokenId).send();271272 const {fractionalizer} = await initFractionalizer(api, web3, privateKeyWrapper, owner);273274 await fractionalizer.methods.setAllowlist(nftCollectionAddress, true).send();275 await expect(fractionalizer.methods.nft2rft(nftCollectionAddress, nftTokenId, 100).send()).to.be.eventually.rejected;276 });277278 itWeb3('call rft2nft without setting RFT collection for contract', async ({api, web3, privateKeyWrapper}) => {279 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);280281 const fractionalizer = await deployFractionalizer(api, web3, owner);282 const {collectionIdAddress: rftCollectionAddress} = await createRefungibleCollection(api, web3, owner);283 const refungibleContract = uniqueRefungible(web3, rftCollectionAddress, owner);284 const rftTokenId = await refungibleContract.methods.nextTokenId().call();285 await refungibleContract.methods.mint(owner, rftTokenId).send();286 287 await expect(fractionalizer.methods.rft2nft(rftCollectionAddress, rftTokenId).send()).to.be.eventually.rejected;288 });289290 itWeb3('call rft2nft for RFT token that is not from configured RFT collection', async ({api, web3, privateKeyWrapper}) => {291 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);292293 const {fractionalizer} = await initFractionalizer(api, web3, privateKeyWrapper, owner);294 const {collectionIdAddress: rftCollectionAddress} = await createRefungibleCollection(api, web3, owner);295 const refungibleContract = uniqueRefungible(web3, rftCollectionAddress, owner);296 const rftTokenId = await refungibleContract.methods.nextTokenId().call();297 await refungibleContract.methods.mint(owner, rftTokenId).send();298 299 await expect(fractionalizer.methods.rft2nft(rftCollectionAddress, rftTokenId).send()).to.be.eventually.rejected;300 });301302 itWeb3('call rft2nft without owning all RFT pieces', async ({api, web3, privateKeyWrapper}) => {303 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);304 const receiver = await createEthAccountWithBalance(api, web3, privateKeyWrapper);305306 const {fractionalizer, rftCollectionAddress} = await initFractionalizer(api, web3, privateKeyWrapper, owner);307 const {rftTokenAddress} = await createRFTToken(api, web3, owner, fractionalizer, 100n);308 309 const {tokenId} = tokenIdFromAddress(rftTokenAddress);310 const refungibleTokenContract = uniqueRefungibleToken(web3, rftTokenAddress, owner);311 await refungibleTokenContract.methods.transfer(receiver, 50).send();312 await refungibleTokenContract.methods.approve(fractionalizer.options.address, 50).send();313 await expect(fractionalizer.methods.rft2nft(rftCollectionAddress, tokenId).send()).to.be.eventually.rejected;314 });315});