git.delta.rocks / unique-network / refs/commits / 7efe1bc1a770

difftreelog

Merge pull request #82 from usetech-llc/feature/transferFromExpectSuccess_helper_fix

Greg Zaitsev2021-02-02parents: #037be4d #91ad8d6.patch.diff
in: master
Fix transferFrom implementation/test

2 files changed

modifiedpallets/nft/src/lib.rsdiffbeforeafterboth
11221122
1123 // Check approval1123 // Check approval
1124 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 }
11441144
1145 // 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 0
1146 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 }
11521152
1153 match target_collection.mode1153 match target_collection.mode
modifiedtests/src/util/helpers.tsdiffbeforeafterboth
--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -462,7 +462,7 @@
     }
     const transferFromTx = await api.tx.nft.transferFrom(
       accountFrom.address, accountTo.address, collectionId, tokenId, value);
-    const events = await submitTransactionAsync(accountFrom, transferFromTx);
+    const events = await submitTransactionAsync(accountApproved, transferFromTx);
     const result = getCreateItemResult(events);
     // tslint:disable-next-line:no-unused-expression
     expect(result.success).to.be.true;