git.delta.rocks / unique-network / refs/commits / 88ef7226e031

difftreelog

Test all collection for total_pieces

Trubnikov Sergey2022-06-30parent: #2d796da.patch.diff
in: master

10 files changed

modifiedclient/rpc/src/lib.rsdiffbeforeafterboth
198 collection_id: CollectionId,198 collection_id: CollectionId,
199 token_id: TokenId,199 token_id: TokenId,
200 at: Option<BlockHash>,200 at: Option<BlockHash>,
201 ) -> Result<u128>;201 ) -> Result<Option<u128>>;
202}202}
203203
204mod rmrk_unique_rpc {204mod rmrk_unique_rpc {
472 pass_method!(collection_stats() -> CollectionStats, unique_api);472 pass_method!(collection_stats() -> CollectionStats, unique_api);
473 pass_method!(next_sponsored(collection: CollectionId, account: CrossAccountId, token: TokenId) -> Option<u64>, unique_api);473 pass_method!(next_sponsored(collection: CollectionId, account: CrossAccountId, token: TokenId) -> Option<u64>, unique_api);
474 pass_method!(effective_collection_limits(collection_id: CollectionId) -> Option<CollectionLimits>, unique_api);474 pass_method!(effective_collection_limits(collection_id: CollectionId) -> Option<CollectionLimits>, unique_api);
475 pass_method!(total_pieces(collection_id: CollectionId, token_id: TokenId) -> u128, unique_api);475 pass_method!(total_pieces(collection_id: CollectionId, token_id: TokenId) -> Option<u128>, unique_api);
476}476}
477477
478#[allow(deprecated)]478#[allow(deprecated)]
modifiedpallets/common/src/lib.rsdiffbeforeafterboth
1383 /// Amount of specific token account have (Applicable to fungible/refungible)1383 /// Amount of specific token account have (Applicable to fungible/refungible)
1384 fn balance(&self, account: T::CrossAccountId, token: TokenId) -> u128;1384 fn balance(&self, account: T::CrossAccountId, token: TokenId) -> u128;
1385 /// Amount of token pieces1385 /// Amount of token pieces
1386 fn total_pieces(&self, token: TokenId) -> u128;1386 fn total_pieces(&self, token: TokenId) -> Option<u128>;
1387 fn allowance(1387 fn allowance(
1388 &self,1388 &self,
1389 sender: T::CrossAccountId,1389 sender: T::CrossAccountId,
modifiedpallets/fungible/src/common.rsdiffbeforeafterboth
25use up_data_structs::{Property, PropertyKey, PropertyValue, PropertyKeyPermission};25use up_data_structs::{Property, PropertyKey, PropertyValue, PropertyKeyPermission};
2626
27use crate::{27use crate::{
28 Allowance, Balance, Config, Error, FungibleHandle, Pallet, SelfWeightOf, weights::WeightInfo,28 Allowance, TotalSupply, Balance, Config, Error, FungibleHandle, Pallet, SelfWeightOf,
29 weights::WeightInfo,
29};30};
3031
404 None405 None
405 }406 }
406407
407 fn total_pieces(&self, _token: TokenId) -> u128 {408 fn total_pieces(&self, token: TokenId) -> Option<u128> {
408 0409 if token != TokenId::default() {
410 return None;
411 }
412 <TotalSupply<T>>::try_get(self.id).ok()
409 }413 }
410}414}
411415
modifiedpallets/nonfungible/src/common.rsdiffbeforeafterboth
473 None473 None
474 }474 }
475475
476 fn total_pieces(&self, _token: TokenId) -> u128 {476 fn total_pieces(&self, _token: TokenId) -> Option<u128> {
477 1477 Some(1)
478 }478 }
479}479}
480480
modifiedpallets/refungible/src/common.rsdiffbeforeafterboth
410 Some(self)410 Some(self)
411 }411 }
412412
413 fn total_pieces(&self, token: TokenId) -> u128 {413 fn total_pieces(&self, token: TokenId) -> Option<u128> {
414 <Pallet<T>>::total_pieces(self.id, token)414 <Pallet<T>>::total_pieces(self.id, token)
415 }415 }
416}416}
modifiedpallets/refungible/src/lib.rsdiffbeforeafterboth
711 Ok(())711 Ok(())
712 }712 }
713713
714 fn total_pieces(collection_id: CollectionId, token_id: TokenId) -> u128 {714 fn total_pieces(collection_id: CollectionId, token_id: TokenId) -> Option<u128> {
715 <TotalSupply<T>>::get((collection_id, token_id))715 <TotalSupply<T>>::try_get((collection_id, token_id)).ok()
716 }716 }
717}717}
718718
modifiedprimitives/rpc/src/lib.rsdiffbeforeafterboth
80 fn collection_stats() -> Result<CollectionStats>;80 fn collection_stats() -> Result<CollectionStats>;
81 fn next_sponsored(collection: CollectionId, account: CrossAccountId, token: TokenId) -> Result<Option<u64>>;81 fn next_sponsored(collection: CollectionId, account: CrossAccountId, token: TokenId) -> Result<Option<u64>>;
82 fn effective_collection_limits(collection_id: CollectionId) -> Result<Option<CollectionLimits>>;82 fn effective_collection_limits(collection_id: CollectionId) -> Result<Option<CollectionLimits>>;
83 fn total_pieces(collection_id: CollectionId, token_id: TokenId) -> Result<u128>;83 fn total_pieces(collection_id: CollectionId, token_id: TokenId) -> Result<Option<u128>>;
84 }84 }
85}85}
8686
modifiedruntime/common/src/runtime_apis.rsdiffbeforeafterboth
143 Ok(<pallet_common::Pallet<Runtime>>::effective_collection_limits(collection))143 Ok(<pallet_common::Pallet<Runtime>>::effective_collection_limits(collection))
144 }144 }
145145
146 fn total_pieces(collection: CollectionId, token_id: TokenId) -> Result<u128, DispatchError> {146 fn total_pieces(collection: CollectionId, token_id: TokenId) -> Result<Option<u128>, DispatchError> {
147 dispatch_unique_runtime!(collection.total_pieces(token_id))147 dispatch_unique_runtime!(collection.total_pieces(token_id))
148 }148 }
149 }149 }
modifiedtests/src/createItem.test.tsdiffbeforeafterboth
24 createCollectionWithPropsExpectSuccess,24 createCollectionWithPropsExpectSuccess,
25 createItemWithPropsExpectSuccess,25 createItemWithPropsExpectSuccess,
26 createItemWithPropsExpectFailure,26 createItemWithPropsExpectFailure,
27 createCollection,
28 transferExpectSuccess,
27} from './util/helpers';29} from './util/helpers';
2830
29const expect = chai.expect;31const expect = chai.expect;
96 await createItemWithPropsExpectSuccess(alice, newCollectionID, createMode, [{key: 'key1', value: 'val1'}]);98 await createItemWithPropsExpectSuccess(alice, newCollectionID, createMode, [{key: 'key1', value: 'val1'}]);
97 });99 });
100
101 it.only('Check total pieces of Fungible token', async () => {
102 await usingApi(async api => {
103 const createMode = 'Fungible';
104 const collectionId = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});
105 const tokenId = await createItemExpectSuccess(alice, collectionId, createMode, bob.address);
106 {
107 const totalPieces = await api.rpc.unique.totalPieces(collectionId, tokenId);
108 expect(totalPieces.isSome).to.be.true;
109 expect(totalPieces.unwrap().toBigInt()).to.be.eq(10n);
110 }
111
112 await transferExpectSuccess(collectionId, tokenId, bob, alice, 1, createMode);
113 {
114 const totalPieces = await api.rpc.unique.totalPieces(collectionId, tokenId);
115 expect(totalPieces.isSome).to.be.true;
116 expect(totalPieces.unwrap().toBigInt()).to.be.eq(10n);
117 }
118 });
119 });
120
121 it.only('Check total pieces of NFT token', async () => {
122 await usingApi(async api => {
123 const createMode = 'NFT';
124 const collectionId = await createCollectionExpectSuccess({mode: {type: createMode}});
125 const tokenId = await createItemExpectSuccess(alice, collectionId, createMode, bob.address);
126 {
127 const totalPieces = await api.rpc.unique.totalPieces(collectionId, tokenId);
128 expect(totalPieces.isSome).to.be.true;
129 expect(totalPieces.unwrap().toBigInt()).to.be.eq(1n);
130 }
131
132 await transferExpectSuccess(collectionId, tokenId, bob, alice, 1, createMode);
133 {
134 const totalPieces = await api.rpc.unique.totalPieces(collectionId, tokenId);
135 expect(totalPieces.isSome).to.be.true;
136 expect(totalPieces.unwrap().toBigInt()).to.be.eq(1n);
137 }
138 });
139 });
140
141 it.only('Check total pieces of ReFungible token', async () => {
142 await usingApi(async api => {
143 const createMode = 'ReFungible';
144 const createCollectionResult = await createCollection(api, alice, {mode: {type: createMode}});
145 const collectionId = createCollectionResult.collectionId;
146 const amountPieces = 100n;
147 const tokenId = await createItemExpectSuccess(alice, collectionId, createMode, bob.address);
148 {
149 const totalPieces = await api.rpc.unique.totalPieces(collectionId, tokenId);
150 expect(totalPieces.isSome).to.be.true;
151 expect(totalPieces.unwrap().toBigInt()).to.be.eq(amountPieces);
152 }
153
154 await transferExpectSuccess(collectionId, tokenId, bob, alice, 60n, createMode);
155 {
156 const totalPieces = await api.rpc.unique.totalPieces(collectionId, tokenId);
157 expect(totalPieces.isSome).to.be.true;
158 expect(totalPieces.unwrap().toBigInt()).to.be.eq(amountPieces);
159 }
160 });
161 });
98});162});
99163
100describe('Negative integration test: ext. createItem():', () => {164describe('Negative integration test: ext. createItem():', () => {
modifiedtests/src/refungible.test.tsdiffbeforeafterboth
68 });68 });
69 });69 });
70
71 it.only('Check total pieces of token', async () => {
72 await usingApi(async api => {
73 const createCollectionResult = await createCollection(api, alice, {mode: {type: 'ReFungible'}});
74 expect(createCollectionResult.success).to.be.true;
75 const collectionId = createCollectionResult.collectionId;
76 const amountPieces = 100n;
77 const result = await createRefungibleToken(api, alice, collectionId, amountPieces);
78 expect(result.success).to.be.true;
79 {
80 const totalPieces = await api.rpc.unique.totalPieces(collectionId, result.itemId);
81 expect(totalPieces.toBigInt()).to.be.eq(amountPieces);
82 }
83
84 await transfer(api, collectionId, result.itemId, alice, bob, 60n);
85 {
86 const totalPieces = await api.rpc.unique.totalPieces(collectionId, result.itemId);
87 expect(totalPieces.toBigInt()).to.be.eq(amountPieces);
88 }
89 });
90 });
9170
92 it('Transfer token pieces', async () => {71 it('Transfer token pieces', async () => {
93 await usingApi(async api => {72 await usingApi(async api => {