git.delta.rocks / unique-network / refs/commits / e256f7e1e4e2

difftreelog

tests(refungible-pallet): add negative tests for fractionalizer contract

Grigoriy Simonov2022-08-11parent: #34ddd36.patch.diff
in: master

1 file changed

modifiedtests/src/eth/fractionalizer/fractionalizer.test.tsdiffbeforeafterboth
177
178
179
180describe('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();
188
189 await expect(fractionalizer.methods.setRFTCollection(collectionIdAddress).send()).to.be.eventually.rejected;
190 });
191
192 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);
196
197 await expect(fractionalizer.methods.setRFTCollection(collectionIdAddress).send()).to.be.eventually.rejected;
198 });
199
200 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);
204
205 await expect(fractionalizer.methods.setRFTCollection(collectionIdAddress).send()).to.be.eventually.rejected;
206 });
207
208 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);
214
215 const result = await fractionalizer.methods.mintRFTCollection('A', 'B', 'C').send({from: owner});
216 const collectionIdAddress = result.events.RFTCollectionSet.returnValues._collection;
217
218 await expect(fractionalizer.methods.setRFTCollection(collectionIdAddress).send()).to.be.eventually.rejected;
219 });
220
221 itWeb3('call nft2rft without setting RFT collection for contract', async ({api, web3, privateKeyWrapper}) => {
222 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
223
224 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();
228
229 const fractionalizer = await deployFractionalizer(api, web3, owner);
230
231 await expect(fractionalizer.methods.nft2rft(nftCollectionAddress, nftTokenId, 100).send()).to.be.eventually.rejected;
232 });
233
234 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);
237
238 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();
243
244
245 const {fractionalizer} = await initFractionalizer(api, web3, privateKeyWrapper, owner);
246
247 await expect(fractionalizer.methods.nft2rft(nftCollectionAddress, nftTokenId, 100).send()).to.be.eventually.rejected;
248 });
249
250 itWeb3('call nft2rft while not in list of allowed accounts', async ({api, web3, privateKeyWrapper}) => {
251 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
252
253 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();
257
258 const {fractionalizer} = await initFractionalizer(api, web3, privateKeyWrapper, owner);
259
260 await nftContract.methods.approve(fractionalizer.options.address, nftTokenId).send();
261 await expect(fractionalizer.methods.nft2rft(nftCollectionAddress, nftTokenId, 100).send()).to.be.eventually.rejected;
262 });
263
264 itWeb3('call nft2rft while fractionalizer doesnt have approval for nft token', async ({api, web3, privateKeyWrapper}) => {
265 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
266
267 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();
271
272 const {fractionalizer} = await initFractionalizer(api, web3, privateKeyWrapper, owner);
273
274 await fractionalizer.methods.setAllowlist(nftCollectionAddress, true).send();
275 await expect(fractionalizer.methods.nft2rft(nftCollectionAddress, nftTokenId, 100).send()).to.be.eventually.rejected;
276 });
277
278 itWeb3('call rft2nft without setting RFT collection for contract', async ({api, web3, privateKeyWrapper}) => {
279 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
280
281 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 });
289
290 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);
292
293 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 });
301
302 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);
305
306 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});