difftreelog
Merge branch 'develop' into feature/token_owners
in: master
15 files changed
Cargo.lockdiffbeforeafterboth632063206321[[package]]6321[[package]]6322name = "pallet-refungible"6322name = "pallet-refungible"6323version = "0.1.1"6323version = "0.1.2"6324dependencies = [6324dependencies = [6325 "ethereum",6326 "evm-coder",6325 "frame-benchmarking",6327 "frame-benchmarking",6326 "frame-support",6328 "frame-support",6327 "frame-system",6329 "frame-system",6328 "pallet-common",6330 "pallet-common",6329 "pallet-evm",6331 "pallet-evm",6332 "pallet-evm-coder-substrate",6330 "pallet-structure",6333 "pallet-structure",6331 "parity-scale-codec 3.1.5",6334 "parity-scale-codec 3.1.5",6332 "scale-info",6335 "scale-info",Makefilediffbeforeafterboth12NONFUNGIBLE_EVM_STUBS=./pallets/nonfungible/src/stubs12NONFUNGIBLE_EVM_STUBS=./pallets/nonfungible/src/stubs13NONFUNGIBLE_EVM_ABI=./tests/src/eth/nonFungibleAbi.json13NONFUNGIBLE_EVM_ABI=./tests/src/eth/nonFungibleAbi.json1415REFUNGIBLE_EVM_STUBS=./pallets/refungible/src/stubs16RENFUNGIBLE_EVM_ABI=./tests/src/eth/reFungibleAbi.json17RENFUNGIBLE_TOKEN_EVM_ABI=./tests/src/eth/reFungibleTokenAbi.json141815CONTRACT_HELPERS_STUBS=./pallets/evm-contract-helpers/src/stubs/19CONTRACT_HELPERS_STUBS=./pallets/evm-contract-helpers/src/stubs/16CONTRACT_HELPERS_ABI=./tests/src/eth/util/contractHelpersAbi.json20CONTRACT_HELPERS_ABI=./tests/src/eth/util/contractHelpersAbi.json21TESTS_API=./tests/src/eth/api/25TESTS_API=./tests/src/eth/api/222623.PHONY: regenerate_solidity27.PHONY: regenerate_solidity24regenerate_solidity: UniqueFungible.sol UniqueNFT.sol ContractHelpers.sol CollectionHelpers.sol28regenerate_solidity: UniqueFungible.sol UniqueNFT.sol UniqueRefungibleToken.sol ContractHelpers.sol CollectionHelpers.sol252926UniqueFungible.sol:30UniqueFungible.sol:27 PACKAGE=pallet-fungible NAME=erc::gen_iface OUTPUT=$(TESTS_API)/$@ ./.maintain/scripts/generate_sol.sh31 PACKAGE=pallet-fungible NAME=erc::gen_iface OUTPUT=$(TESTS_API)/$@ ./.maintain/scripts/generate_sol.sh30UniqueNFT.sol:34UniqueNFT.sol:31 PACKAGE=pallet-nonfungible NAME=erc::gen_iface OUTPUT=$(TESTS_API)/$@ ./.maintain/scripts/generate_sol.sh35 PACKAGE=pallet-nonfungible NAME=erc::gen_iface OUTPUT=$(TESTS_API)/$@ ./.maintain/scripts/generate_sol.sh32 PACKAGE=pallet-nonfungible NAME=erc::gen_impl OUTPUT=$(NONFUNGIBLE_EVM_STUBS)/$@ ./.maintain/scripts/generate_sol.sh36 PACKAGE=pallet-nonfungible NAME=erc::gen_impl OUTPUT=$(NONFUNGIBLE_EVM_STUBS)/$@ ./.maintain/scripts/generate_sol.sh37 38UniqueRefungibleToken.sol:39 PACKAGE=pallet-refungible NAME=erc_token::gen_iface OUTPUT=$(TESTS_API)/$@ ./.maintain/scripts/generate_sol.sh40 PACKAGE=pallet-refungible NAME=erc_token::gen_impl OUTPUT=$(REFUNGIBLE_EVM_STUBS)/$@ ./.maintain/scripts/generate_sol.sh334134ContractHelpers.sol:42ContractHelpers.sol:35 PACKAGE=pallet-evm-contract-helpers NAME=eth::contract_helpers_iface OUTPUT=$(TESTS_API)/$@ ./.maintain/scripts/generate_sol.sh43 PACKAGE=pallet-evm-contract-helpers NAME=eth::contract_helpers_iface OUTPUT=$(TESTS_API)/$@ ./.maintain/scripts/generate_sol.sh47 INPUT=$(NONFUNGIBLE_EVM_STUBS)/$< OUTPUT=$(NONFUNGIBLE_EVM_STUBS)/UniqueNFT.raw ./.maintain/scripts/compile_stub.sh55 INPUT=$(NONFUNGIBLE_EVM_STUBS)/$< OUTPUT=$(NONFUNGIBLE_EVM_STUBS)/UniqueNFT.raw ./.maintain/scripts/compile_stub.sh48 INPUT=$(NONFUNGIBLE_EVM_STUBS)/$< OUTPUT=$(NONFUNGIBLE_EVM_ABI) ./.maintain/scripts/generate_abi.sh56 INPUT=$(NONFUNGIBLE_EVM_STUBS)/$< OUTPUT=$(NONFUNGIBLE_EVM_ABI) ./.maintain/scripts/generate_abi.sh5758UniqueRefungibleToken: UniqueRefungibleToken.sol59 INPUT=$(REFUNGIBLE_EVM_STUBS)/$< OUTPUT=$(REFUNGIBLE_EVM_STUBS)/UniqueRefungibleToken.raw ./.maintain/scripts/compile_stub.sh60 INPUT=$(REFUNGIBLE_EVM_STUBS)/$< OUTPUT=$(RENFUNGIBLE_TOKEN_EVM_ABI) ./.maintain/scripts/generate_abi.sh496150ContractHelpers: ContractHelpers.sol62ContractHelpers: ContractHelpers.sol51 INPUT=$(CONTRACT_HELPERS_STUBS)/$< OUTPUT=$(CONTRACT_HELPERS_STUBS)/ContractHelpers.raw ./.maintain/scripts/compile_stub.sh63 INPUT=$(CONTRACT_HELPERS_STUBS)/$< OUTPUT=$(CONTRACT_HELPERS_STUBS)/ContractHelpers.raw ./.maintain/scripts/compile_stub.sh55 INPUT=$(COLLECTION_HELPER_STUBS)/$< OUTPUT=$(COLLECTION_HELPER_STUBS)/CollectionHelpers.raw ./.maintain/scripts/compile_stub.sh67 INPUT=$(COLLECTION_HELPER_STUBS)/$< OUTPUT=$(COLLECTION_HELPER_STUBS)/CollectionHelpers.raw ./.maintain/scripts/compile_stub.sh56 INPUT=$(COLLECTION_HELPER_STUBS)/$< OUTPUT=$(COLLECTION_HELPER_ABI) ./.maintain/scripts/generate_abi.sh68 INPUT=$(COLLECTION_HELPER_STUBS)/$< OUTPUT=$(COLLECTION_HELPER_ABI) ./.maintain/scripts/generate_abi.sh576958evm_stubs: UniqueFungible UniqueNFT ContractHelpers CollectionHelpers70evm_stubs: UniqueFungible UniqueNFT UniqueRefungibleToken ContractHelpers CollectionHelpers597160.PHONY: _bench72.PHONY: _bench61_bench:73_bench:pallets/refungible/CHANGELOG.mddiffbeforeafterboth223All notable changes to this project will be documented in this file.3All notable changes to this project will be documented in this file.445## [0.1.1] - 2022-07-145## [v0.1.2] - 2022-07-14667### Added7### Other changes889 - Implementation of RPC method `token_owners` returning 10 owners in no particular order.9feat(refungible-pallet): add ERC-20 EVM API for RFT token pieces ([#413](https://github.com/UniqueNetwork/unique-chain/pull/413))10 This was an internal request to improve the web interface and support fractionalization event. 10test(refungible-pallet): add tests for ERC-20 EVM API for RFT token pieces ([#413](https://github.com/UniqueNetwork/unique-chain/pull/413))111112 12## [v0.1.1] - 2022-07-141313 14### Other changes1516- feat: RPC method `token_owners` returning 10 owners in no particular order.1718This was an internal request to improve the web interface and support fractionalization event. 19pallets/refungible/Cargo.tomldiffbeforeafterboth1[package]1[package]2name = "pallet-refungible"2name = "pallet-refungible"3version = "0.1.1"3version = "0.1.2"4license = "GPLv3"4license = "GPLv3"5edition = "2021"5edition = "2021"6611version = '3.1.2'11version = '3.1.2'121213[dependencies]13[dependencies]14evm-coder = { default-features = false, path = '../../crates/evm-coder' }15pallet-evm-coder-substrate = { default-features = false, path = '../../pallets/evm-coder-substrate' }16pallet-common = { default-features = false, path = '../common' }17pallet-structure = { default-features = false, path = '../structure' }18struct-versioning = { path = "../../crates/struct-versioning" }19up-data-structs = { default-features = false, path = '../../primitives/data-structs' }2021ethereum = { version = "0.12.0", default-features = false }22scale-info = { version = "2.0.1", default-features = false, features = ["derive",] }2324frame-benchmarking = { default-features = false, optional = true, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }14frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }25frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }15frame-system = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }26frame-system = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }27pallet-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier", branch = "unique-polkadot-v0.9.24" }28sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }16sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }29sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }17sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }30sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }18sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }19pallet-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier", branch = "unique-polkadot-v0.9.24" }20pallet-common = { default-features = false, path = '../common' }21pallet-structure = { default-features = false, path = '../structure' }22up-data-structs = { default-features = false, path = '../../primitives/data-structs' }23frame-benchmarking = { default-features = false, optional = true, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }24scale-info = { version = "2.0.1", default-features = false, features = [25 "derive",26] }27struct-versioning = { path = "../../crates/struct-versioning" }283129[features]32[features]30default = ["std"]33default = ["std"]31std = [34std = [35 "ethereum/std",36 "evm-coder/std",37 'frame-benchmarking/std',32 "frame-support/std",38 "frame-support/std",33 "frame-system/std",39 "frame-system/std",34 "sp-runtime/std",40 "pallet-common/std",35 "sp-std/std",41 "pallet-evm/std",36 "up-data-structs/std",37 "pallet-common/std",42 "pallet-evm-coder-substrate/std",38 "pallet-structure/std",43 "pallet-structure/std",39 'frame-benchmarking/std',44 "sp-runtime/std",40 "pallet-evm/std",45 "sp-std/std",46 "up-data-structs/std",41]47]42runtime-benchmarks = [48runtime-benchmarks = [43 'frame-benchmarking',49 'frame-benchmarking',44 'frame-support/runtime-benchmarks',50 'frame-support/runtime-benchmarks',45 'frame-system/runtime-benchmarks',51 'frame-system/runtime-benchmarks',52 'up-data-structs/runtime-benchmarks',46]53]4754pallets/refungible/src/erc.rsdiffbeforeafterboth14// You should have received a copy of the GNU General Public License14// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.161617extern crate alloc;17use up_data_structs::TokenId;18use evm_coder::{generate_stubgen, solidity_interface, types::*};1918use pallet_common::erc::CommonEvmHandler;20use pallet_common::{CollectionHandle, erc::CollectionCall, erc::CommonEvmHandler};2119use pallet_evm::PrecompileHandle;22use pallet_evm::PrecompileHandle;23use pallet_evm_coder_substrate::call;202421use crate::{Config, RefungibleHandle};25use crate::{Config, RefungibleHandle};222627#[solidity_interface(28 name = "UniqueRFT",29 is(via("CollectionHandle<T>", common_mut, Collection),)30)]23impl<T: Config> CommonEvmHandler for RefungibleHandle<T> {31impl<T: Config> RefungibleHandle<T> where T::AccountId: From<[u8; 32]> {}24 const CODE: &'static [u8] = include_bytes!("./stubs/UniqueRefungible.raw");322533// Not a tests, but code generators26 fn call(34generate_stubgen!(gen_impl, UniqueRFTCall<()>, true);27 self,28 _handle: &mut impl PrecompileHandle,29 ) -> Option<pallet_common::erc::PrecompileResult> {30 // TODO: Implement RFT variant of ERC72131 None32 }33}3435pub struct RefungibleTokenHandle<T: Config>(pub RefungibleHandle<T>, pub TokenId);35generate_stubgen!(gen_iface, UniqueRFTCall<()>, false);363637impl<T: Config> CommonEvmHandler for RefungibleTokenHandle<T> {37impl<T: Config> CommonEvmHandler for RefungibleHandle<T>38where39 T::AccountId: From<[u8; 32]>,40{38 const CODE: &'static [u8] = include_bytes!("./stubs/UniqueRefungibleToken.raw");41 const CODE: &'static [u8] = include_bytes!("./stubs/UniqueRefungible.raw");3940 fn call(42 fn call(41 self,43 self,42 _handle: &mut impl PrecompileHandle,44 handle: &mut impl PrecompileHandle,43 ) -> Option<pallet_common::erc::PrecompileResult> {45 ) -> Option<pallet_common::erc::PrecompileResult> {44 // TODO: Implement RFT variant of ERC2046 call::<T, UniqueRFTCall<T>, _, _>(handle, self)45 None46 }47 }47}48}4849pallets/refungible/src/erc_token.rsdiffbeforeafterbothno changes
pallets/refungible/src/lib.rsdiffbeforeafterboth878788#![cfg_attr(not(feature = "std"), no_std)]88#![cfg_attr(not(feature = "std"), no_std)]898990use crate::erc_token::ERC20Events;9192use codec::{Encode, Decode, MaxEncodedLen};93use core::ops::Deref;94use evm_coder::ToLog;90use frame_support::{ensure, fail, BoundedVec, transactional, storage::with_transaction};95use frame_support::{BoundedVec, ensure, fail, storage::with_transaction, transactional};91use up_data_structs::{96use pallet_evm::{account::CrossAccountId, Pallet as PalletEvm};92 AccessMode, CollectionId, CustomDataLimit, MAX_REFUNGIBLE_PIECES, TokenId,93 CreateCollectionData, CreateRefungibleExData, mapping::TokenAddressMapping, budget::Budget,94 Property, PropertyScope, TrySetProperty, PropertyKey, PropertyValue, PropertyPermission,95 PropertyKeyPermission,96};97use pallet_evm::account::CrossAccountId;97use pallet_evm_coder_substrate::WithRecorder;98use pallet_common::{98use pallet_common::{99 Error as CommonError, Event as CommonEvent, Pallet as PalletCommon,99 CommonCollectionOperations, Error as CommonError, Event as CommonEvent, Pallet as PalletCommon,100 CommonCollectionOperations as _,101};100};102use pallet_structure::Pallet as PalletStructure;101use pallet_structure::Pallet as PalletStructure;102use scale_info::TypeInfo;103use sp_core::H160;103use sp_runtime::{ArithmeticError, DispatchError, DispatchResult, TransactionOutcome};104use sp_runtime::{ArithmeticError, DispatchError, DispatchResult, TransactionOutcome};104use sp_std::{vec::Vec, vec, collections::btree_map::BTreeMap};105use sp_std::{vec::Vec, vec, collections::btree_map::BTreeMap};105use core::ops::Deref;106use codec::{Encode, Decode, MaxEncodedLen};106use up_data_structs::{107use scale_info::TypeInfo;107 AccessMode, budget::Budget, CollectionId, CreateCollectionData, CreateRefungibleExData,108 CustomDataLimit, mapping::TokenAddressMapping, MAX_REFUNGIBLE_PIECES, TokenId, Property,109 PropertyKey, PropertyKeyPermission, PropertyPermission, PropertyScope, PropertyValue,110 TrySetProperty,111};108112109pub use pallet::*;113pub use pallet::*;110#[cfg(feature = "runtime-benchmarks")]114#[cfg(feature = "runtime-benchmarks")]111pub mod benchmarking;115pub mod benchmarking;112pub mod common;116pub mod common;113pub mod erc;117pub mod erc;118pub mod erc_token;114pub mod weights;119pub mod weights;115pub(crate) type SelfWeightOf<T> = <T as Config>::WeightInfo;120pub(crate) type SelfWeightOf<T> = <T as Config>::WeightInfo;116121271 pub fn into_inner(self) -> pallet_common::CollectionHandle<T> {276 pub fn into_inner(self) -> pallet_common::CollectionHandle<T> {272 self.0277 self.0273 }278 }279 pub fn common_mut(&mut self) -> &mut pallet_common::CollectionHandle<T> {280 &mut self.0281 }274}282}283275impl<T: Config> Deref for RefungibleHandle<T> {284impl<T: Config> Deref for RefungibleHandle<T> {280 }289 }281}290}291292impl<T: Config> WithRecorder<T> for RefungibleHandle<T> {293 fn recorder(&self) -> &pallet_evm_coder_substrate::SubstrateRecorder<T> {294 self.0.recorder()295 }296 fn into_recorder(self) -> pallet_evm_coder_substrate::SubstrateRecorder<T> {297 self.0.into_recorder()298 }299}282300283impl<T: Config> Pallet<T> {301impl<T: Config> Pallet<T> {284 /// Get number of RFT tokens in collection302 /// Get number of RFT tokens in collection460 <Balance<T>>::insert((collection.id, token, owner), balance);478 <Balance<T>>::insert((collection.id, token, owner), balance);461 }479 }462 <TotalSupply<T>>::insert((collection.id, token), total_supply);480 <TotalSupply<T>>::insert((collection.id, token), total_supply);463 // TODO: ERC20 transfer event481482 <PalletEvm<T>>::deposit_log(483 ERC20Events::Transfer {484 from: *owner.as_eth(),485 to: H160::default(),486 value: amount.into(),487 }488 .to_log(T::EvmTokenAddressMapping::token_to_address(489 collection.id,490 token,491 )),492 );464 <PalletCommon<T>>::deposit_event(CommonEvent::ItemDestroyed(493 <PalletCommon<T>>::deposit_event(CommonEvent::ItemDestroyed(465 collection.id,494 collection.id,466 token,495 token,736 }765 }737 }766 }738767739 // TODO: ERC20 transfer event768 <PalletEvm<T>>::deposit_log(769 ERC20Events::Transfer {770 from: *from.as_eth(),771 to: *to.as_eth(),772 value: amount.into(),773 }774 .to_log(T::EvmTokenAddressMapping::token_to_address(775 collection.id,776 token,777 )),778 );740 <PalletCommon<T>>::deposit_event(CommonEvent::Transfer(779 <PalletCommon<T>>::deposit_event(CommonEvent::Transfer(741 collection.id,780 collection.id,742 token,781 token,889 continue;928 continue;890 }929 }891930892 // TODO: ERC20 transfer event931 <PalletEvm<T>>::deposit_log(932 ERC20Events::Transfer {933 from: H160::default(),934 to: *user.as_eth(),935 value: amount.into(),936 }937 .to_log(T::EvmTokenAddressMapping::token_to_address(938 collection.id,939 TokenId(token_id),940 )),941 );893 <PalletCommon<T>>::deposit_event(CommonEvent::ItemCreated(942 <PalletCommon<T>>::deposit_event(CommonEvent::ItemCreated(894 collection.id,943 collection.id,895 TokenId(token_id),944 TokenId(token_id),913 } else {962 } else {914 <Allowance<T>>::insert((collection.id, token, sender, spender), amount);963 <Allowance<T>>::insert((collection.id, token, sender, spender), amount);915 }964 }916 // TODO: ERC20 approval event965966 <PalletEvm<T>>::deposit_log(967 ERC20Events::Approval {968 owner: *sender.as_eth(),969 spender: *spender.as_eth(),970 value: amount.into(),971 }972 .to_log(T::EvmTokenAddressMapping::token_to_address(973 collection.id,974 token,975 )),976 );917 <PalletCommon<T>>::deposit_event(CommonEvent::Approved(977 <PalletCommon<T>>::deposit_event(CommonEvent::Approved(918 collection.id,978 collection.id,919 token,979 token,1092 <Balance<T>>::insert((collection.id, token, owner), amount);1152 <Balance<T>>::insert((collection.id, token, owner), amount);1093 <TotalSupply<T>>::insert((collection.id, token), amount);1153 <TotalSupply<T>>::insert((collection.id, token), amount);11541155 if amount > total_pieces {1156 let mint_amount = amount - total_pieces;1157 <PalletEvm<T>>::deposit_log(1158 ERC20Events::Transfer {1159 from: H160::default(),1160 to: *owner.as_eth(),1161 value: mint_amount.into(),1162 }1163 .to_log(T::EvmTokenAddressMapping::token_to_address(1164 collection.id,1165 token,1166 )),1167 );1168 <PalletCommon<T>>::deposit_event(CommonEvent::ItemCreated(1169 collection.id,1170 token,1171 owner.clone(),1172 mint_amount,1173 ));1174 } else if total_pieces > amount {1175 let burn_amount = total_pieces - amount;1176 <PalletEvm<T>>::deposit_log(1177 ERC20Events::Transfer {1178 from: *owner.as_eth(),1179 to: H160::default(),1180 value: burn_amount.into(),1181 }1182 .to_log(T::EvmTokenAddressMapping::token_to_address(1183 collection.id,1184 token,1185 )),1186 );1187 <PalletCommon<T>>::deposit_event(CommonEvent::ItemDestroyed(1188 collection.id,1189 token,1190 owner.clone(),1191 burn_amount,1192 ));1193 }11941094 Ok(())1195 Ok(())1095 }1196 }pallets/refungible/src/stubs/UniqueRefungibleToken.rawdiffbeforeafterbothbinary blob — no preview
pallets/refungible/src/stubs/UniqueRefungibleToken.soldiffbeforeafterbothno changes
runtime/common/src/dispatch.rsdiffbeforeafterboth25pub use pallet_common::dispatch::CollectionDispatch;25pub use pallet_common::dispatch::CollectionDispatch;26use pallet_fungible::{Pallet as PalletFungible, FungibleHandle};26use pallet_fungible::{Pallet as PalletFungible, FungibleHandle};27use pallet_nonfungible::{Pallet as PalletNonfungible, NonfungibleHandle};27use pallet_nonfungible::{Pallet as PalletNonfungible, NonfungibleHandle};28use pallet_refungible::{Pallet as PalletRefungible, RefungibleHandle, erc::RefungibleTokenHandle};28use pallet_refungible::{29 Pallet as PalletRefungible, RefungibleHandle, erc_token::RefungibleTokenHandle,30};29use up_data_structs::{31use up_data_structs::{30 CollectionMode, CreateCollectionData, MAX_DECIMAL_POINTS, mapping::TokenAddressMapping,32 CollectionMode, CreateCollectionData, MAX_DECIMAL_POINTS, mapping::TokenAddressMapping,tests/src/eth/api/UniqueRefungibleToken.soldiffbeforeafterbothno changes
tests/src/eth/reFungibleToken.test.tsdiffbeforeafterbothno changes
tests/src/eth/reFungibleTokenAbi.jsondiffbeforeafterbothno changes
tests/src/refungible.test.tsdiffbeforeafterboth14// You should have received a copy of the GNU General Public License14// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.161617import {default as usingApi, executeTransaction} from './substrate/substrate-api';17import {default as usingApi, submitTransactionAsync} from './substrate/substrate-api';18import {IKeyringPair} from '@polkadot/types/types';18import {IKeyringPair} from '@polkadot/types/types';19import {19import {20 createCollectionExpectSuccess,20 createCollectionExpectSuccess,34 getDetailedCollectionInfo,34 getDetailedCollectionInfo,35 normalizeAccountId,35 normalizeAccountId,36 CrossAccountId,36 CrossAccountId,37 getCreateItemsResult,38 getDestroyItemsResult,37} from './util/helpers';39} from './util/helpers';384039import chai from 'chai';41import chai from 'chai';227 });229 });228 });230 });231232 it('Repartition with increased amount', async () => {233 await usingApi(async api => {234 const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;235 const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n)).itemId;236237 const tx = api.tx.unique.repartition(collectionId, tokenId, 200n);238 const events = await submitTransactionAsync(alice, tx);239 const substrateEvents = getCreateItemsResult(events);240 expect(substrateEvents).to.include.deep.members([241 {242 success: true,243 collectionId,244 itemId: tokenId,245 recipient: {Substrate: alice.address},246 amount: 100,247 },248 ]);249 });250 });251252 it('Repartition with decreased amount', async () => {253 await usingApi(async api => {254 const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;255 const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n)).itemId;256257 const tx = api.tx.unique.repartition(collectionId, tokenId, 50n);258 const events = await submitTransactionAsync(alice, tx);259 const substrateEvents = getDestroyItemsResult(events);260 expect(substrateEvents).to.include.deep.members([261 {262 success: true,263 collectionId,264 itemId: tokenId,265 owner: {Substrate: alice.address},266 amount: 50,267 },268 ]);269 });270 });229});271});230272231describe('Test Refungible properties:', () => {273describe('Test Refungible properties:', () => {tests/src/util/helpers.tsdiffbeforeafterboth103 collectionId: number;103 collectionId: number;104 itemId: number;104 itemId: number;105 recipient?: CrossAccountId;105 recipient?: CrossAccountId;106 amount?: number;106}107}108109interface DestroyItemResult {110 success: boolean;111 collectionId: number;112 itemId: number;113 owner: CrossAccountId;114 amount: number;115}107116108interface TransferResult {117interface TransferResult {109 collectionId: number;118 collectionId: number;220 const collectionId = parseInt(data[0].toString(), 10);229 const collectionId = parseInt(data[0].toString(), 10);221 const itemId = parseInt(data[1].toString(), 10);230 const itemId = parseInt(data[1].toString(), 10);222 const recipient = normalizeAccountId(data[2].toJSON() as any);231 const recipient = normalizeAccountId(data[2].toJSON() as any);232 const amount = parseInt(data[3].toString(), 10);223233224 const itemRes: CreateItemResult = {234 const itemRes: CreateItemResult = {225 success: true,235 success: true,226 collectionId,236 collectionId,227 itemId,237 itemId,228 recipient,238 recipient,239 amount,229 };240 };230241231 results.push(itemRes);242 results.push(itemRes);255 return result;266 return result;256}267}268269export function getDestroyItemsResult(events: EventRecord[]): DestroyItemResult[] {270 const results: DestroyItemResult[] = [];271 272 const genericResult = getGenericResult<DestroyItemResult[]>(events, 'common', 'ItemDestroyed', (data) => {273 const collectionId = parseInt(data[0].toString(), 10);274 const itemId = parseInt(data[1].toString(), 10);275 const owner = normalizeAccountId(data[2].toJSON() as any);276 const amount = parseInt(data[3].toString(), 10);277278 const itemRes: DestroyItemResult = {279 success: true,280 collectionId,281 itemId,282 owner,283 amount,284 };285286 results.push(itemRes);287 return results;288 });289290 if (!genericResult.success) return [];291 return results;292}257293258export function getTransferResult(api: ApiPromise, events: EventRecord[]): TransferResult {294export function getTransferResult(api: ApiPromise, events: EventRecord[]): TransferResult {259 for (const {event} of events) {295 for (const {event} of events) {