difftreelog
Merge pull request #66 from usetech-llc/feature/NFTPAR-280
in: master
Feature/nftpar 280
3 files changed
pallets/nft/src/lib.rsdiffbeforeafterboth419 pub AddressTokens get(fn address_tokens): double_map hasher(identity) CollectionId, hasher(twox_64_concat) T::AccountId => Vec<TokenId>;419 pub AddressTokens get(fn address_tokens): double_map hasher(identity) CollectionId, hasher(twox_64_concat) T::AccountId => Vec<TokenId>;420420421 /// Tokens transfer baskets421 /// Tokens transfer baskets422 pub CreateItemBasket get(fn create_item_basket): map hasher(twox_64_concat) (CollectionId, T::AccountId) => T::BlockNumber;422 pub NftTransferBasket get(fn nft_transfer_basket): double_map hasher(identity) CollectionId, hasher(identity) TokenId => T::BlockNumber;423 pub NftTransferBasket get(fn nft_transfer_basket): double_map hasher(identity) CollectionId, hasher(identity) TokenId => T::BlockNumber;423 pub FungibleTransferBasket get(fn fungible_transfer_basket): double_map hasher(identity) CollectionId, hasher(twox_64_concat) T::AccountId => T::BlockNumber;424 pub FungibleTransferBasket get(fn fungible_transfer_basket): double_map hasher(identity) CollectionId, hasher(twox_64_concat) T::AccountId => T::BlockNumber;424 pub ReFungibleTransferBasket get(fn refungible_transfer_basket): double_map hasher(identity) CollectionId, hasher(identity) TokenId => T::BlockNumber;425 pub ReFungibleTransferBasket get(fn refungible_transfer_basket): double_map hasher(identity) CollectionId, hasher(identity) TokenId => T::BlockNumber;2297 let mut sponsor: T::AccountId = match IsSubType::<Call<T>>::is_sub_type(call) {2298 let mut sponsor: T::AccountId = match IsSubType::<Call<T>>::is_sub_type(call) {2298 Some(Call::create_item(collection_id, _owner, _properties)) => {2299 Some(Call::create_item(collection_id, _owner, _properties)) => {23002301 // sponsor timeout2302 let block_number = <system::Module<T>>::block_number() as T::BlockNumber;23032304 let limit = <Collection<T>>::get(collection_id).limits.sponsor_transfer_timeout;2305 let mut sponsored = true;2306 if <CreateItemBasket<T>>::contains_key((collection_id, &who)) {2307 let last_tx_block = <CreateItemBasket<T>>::get((collection_id, &who));2308 let limit_time = last_tx_block + limit.into();2309 if block_number <= limit_time {2310 sponsored = false;2311 }2312 }2313 if sponsored {2314 <CreateItemBasket<T>>::insert((collection_id, who.clone()), block_number);2315 }229923162300 // check free create limit2317 // check free create limit2301 if (<Collection<T>>::get(collection_id).limits.sponsored_data_size >= (_properties.len() as u32)) &&2318 if (<Collection<T>>::get(collection_id).limits.sponsored_data_size >= (_properties.len() as u32)) &&2302 (<Collection<T>>::get(collection_id).sponsor_confirmed)2319 (<Collection<T>>::get(collection_id).sponsor_confirmed) &&2320 (sponsored)2303 {2321 {2304 <Collection<T>>::get(collection_id).sponsor2322 <Collection<T>>::get(collection_id).sponsor2305 } else {2323 } else {runtime/src/lib.rsdiffbeforeafterboth143 spec_name: create_runtime_str!("nft"),143 spec_name: create_runtime_str!("nft"),144 impl_name: create_runtime_str!("nft"),144 impl_name: create_runtime_str!("nft"),145 authoring_version: 1,145 authoring_version: 1,146 spec_version: 2,146 spec_version: 3,147 impl_version: 1,147 impl_version: 1,148 apis: RUNTIME_API_VERSIONS,148 apis: RUNTIME_API_VERSIONS,149 transaction_version: 1,149 transaction_version: 1,tests/src/confirmSponsorship.test.tsdiffbeforeafterboth170 });170 });171 });171 });172172173 it('NFT: Sponsoring is rate limited', async () => {173 it('NFT: Sponsoring of transfers is rate limited', async () => {174 const collectionId = await createCollectionExpectSuccess();174 const collectionId = await createCollectionExpectSuccess();175 await setCollectionSponsorExpectSuccess(collectionId, bob.address);175 await setCollectionSponsorExpectSuccess(collectionId, bob.address);176 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');176 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');285 });285 });286 });286 });287288 it('NFT: Sponsoring of createItem is rate limited', async () => {289 const collectionId = await createCollectionExpectSuccess();290 await setCollectionSponsorExpectSuccess(collectionId, bob.address);291 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');292293 // Enable collection white list 294 await enableWhiteListExpectSuccess(alice, collectionId);295296 // Enable public minting297 await enablePublicMintingExpectSuccess(alice, collectionId);298299 await usingApi(async (api) => {300 // Find unused address301 const zeroBalance = await findUnusedAddress(api);302303 // Add zeroBalance address to white list304 await addToWhiteListExpectSuccess(alice, collectionId, zeroBalance.address);305306 // Mint token using unused address as signer - gets sponsored307 await createItemExpectSuccess(zeroBalance, collectionId, 'NFT', zeroBalance.address);308309 // Second mint should fail310 const AsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());311 312 const consoleError = console.error;313 const consoleLog = console.log;314 console.error = () => {};315 console.log = () => {};316 const badTransaction = async function () { 317 await createItemExpectSuccess(zeroBalance, collectionId, 'NFT', zeroBalance.address);318 };319 await expect(badTransaction()).to.be.rejectedWith("Inability to pay some fees");320 console.error = consoleError;321 console.log = consoleLog;322 const BsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());323324 // Try again after Zero gets some balance - now it should succeed325 const balancetx = api.tx.balances.transfer(zeroBalance.address, 1e15);326 await submitTransactionAsync(alice, balancetx);327 await createItemExpectSuccess(zeroBalance, collectionId, 'NFT', zeroBalance.address);328329 expect(BsponsorBalance.isEqualTo(AsponsorBalance)).to.be.true;330 });331 });287332288});333});289334