difftreelog
Merge pull request #82 from usetech-llc/feature/transferFromExpectSuccess_helper_fix
in: master
Fix transferFrom implementation/test
2 files changed
pallets/nft/src/lib.rsdiffbeforeafterboth112211221123 // Check approval1123 // Check approval1124 let mut approval: u128 = 0;1124 let mut approval: u128 = 0;1125 if <Allowances<T>>::contains_key(collection_id, (item_id, &from, &recipient)) {1125 if <Allowances<T>>::contains_key(collection_id, (item_id, &from, &sender)) {1126 approval = <Allowances<T>>::get(collection_id, (item_id, &from, &recipient));1126 approval = <Allowances<T>>::get(collection_id, (item_id, &from, &sender));1127 ensure!(approval >= value, Error::<T>::TokenValueNotEnough);1127 ensure!(approval >= value, Error::<T>::TokenValueNotEnough);1128 appoved_transfer = true;1128 appoved_transfer = true;1129 }1129 }114411441145 // Reduce approval by transferred amount or remove if remaining approval drops to 01145 // Reduce approval by transferred amount or remove if remaining approval drops to 01146 if approval.checked_sub(value).unwrap_or(0) > 0 {1146 if approval.checked_sub(value).unwrap_or(0) > 0 {1147 <Allowances<T>>::insert(collection_id, (item_id, &from, &recipient), approval - value);1147 <Allowances<T>>::insert(collection_id, (item_id, &from, &sender), approval - value);1148 }1148 }1149 else {1149 else {1150 <Allowances<T>>::remove(collection_id, (item_id, &from, &recipient));1150 <Allowances<T>>::remove(collection_id, (item_id, &from, &sender));1151 }1151 }115211521153 match target_collection.mode1153 match target_collection.modetests/src/util/helpers.tsdiffbeforeafterboth462 }462 }463 const transferFromTx = await api.tx.nft.transferFrom(463 const transferFromTx = await api.tx.nft.transferFrom(464 accountFrom.address, accountTo.address, collectionId, tokenId, value);464 accountFrom.address, accountTo.address, collectionId, tokenId, value);465 const events = await submitTransactionAsync(accountFrom, transferFromTx);465 const events = await submitTransactionAsync(accountApproved, transferFromTx);466 const result = getCreateItemResult(events);466 const result = getCreateItemResult(events);467 // tslint:disable-next-line:no-unused-expression467 // tslint:disable-next-line:no-unused-expression468 expect(result.success).to.be.true;468 expect(result.success).to.be.true;