git.delta.rocks / unique-network / refs/commits / cdd6fac1acc1

difftreelog

misk: Documentation, test fixes, refactor

Trubnikov Sergey2022-10-27parent: #6afd9fe.patch.diff
in: master

12 files changed

modifiedCargo.lockdiffbeforeafterboth
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1096,26 +1096,6 @@
 checksum = "e4c78c047431fee22c1a7bb92e00ad095a02a983affe4d8a72e2a2c62c1b94f3"
 
 [[package]]
-name = "const_format"
-version = "0.2.30"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7309d9b4d3d2c0641e018d449232f2e28f1b22933c137f157d3dbc14228b8c0e"
-dependencies = [
- "const_format_proc_macros",
-]
-
-[[package]]
-name = "const_format_proc_macros"
-version = "0.2.29"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d897f47bf7270cf70d370f8f98c1abb6d2d4cf60a6845d30e05bfb90c6568650"
-dependencies = [
- "proc-macro2",
- "quote",
- "unicode-xid",
-]
-
-[[package]]
 name = "constant_time_eq"
 version = "0.1.5"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2373,7 +2353,6 @@
 version = "0.1.3"
 dependencies = [
  "concat-idents",
- "const_format",
  "ethereum",
  "evm-coder-procedural",
  "evm-core 0.35.0 (git+https://github.com/uniquenetwork/evm?branch=unique-polkadot-v0.9.30)",
modifiedcrates/evm-coder/Cargo.tomldiffbeforeafterboth
--- a/crates/evm-coder/Cargo.toml
+++ b/crates/evm-coder/Cargo.toml
@@ -5,7 +5,6 @@
 edition = "2021"
 
 [dependencies]
-const_format = { version = "0.2.26", default-features = false }
 sha3-const = { version = "0.1.1", default-features = false }
 # Ethereum uses keccak (=sha3) for selectors
 # sha3 = "0.10.1"
modifiedcrates/evm-coder/procedural/src/solidity_interface.rsdiffbeforeafterboth
--- a/crates/evm-coder/procedural/src/solidity_interface.rs
+++ b/crates/evm-coder/procedural/src/solidity_interface.rs
@@ -20,7 +20,7 @@
 // about Procedural Macros in Rust book:
 // https://doc.rust-lang.org/reference/procedural-macros.html
 
-use proc_macro2::{TokenStream, token_stream};
+use proc_macro2::TokenStream;
 use quote::{quote, ToTokens, format_ident};
 use inflector::cases;
 use std::fmt::Write;
modifiedcrates/evm-coder/src/custom_signature.rsdiffbeforeafterboth
--- a/crates/evm-coder/src/custom_signature.rs
+++ b/crates/evm-coder/src/custom_signature.rs
@@ -1,23 +1,140 @@
+//! # A module for custom signature support.
+//!
+//! ## Overview
+//! This module allows you to create arbitrary signatures for types and functions in compile time.
+//!
+//! ### Type signatures
+//! To create the desired type signature, you need to create your own trait with the `SIGNATURE` constant.
+//! Then in the implementation, for the required type, use the macro [`make_signature`]
+//! #### Example
+//! ```
+//! use std::str::from_utf8;
+//! use evm_coder::make_signature;
+//! use evm_coder::custom_signature::{
+//! 	SignatureUnit,
+//! 	SIGNATURE_SIZE_LIMIT
+//! };
+//!
+//! // Create trait for our signature
+//! trait SoliditySignature {
+//!		const SIGNATURE: SignatureUnit;
+//!
+//!		fn name() -> &'static str {
+//!			from_utf8(&Self::SIGNATURE.data[..Self::SIGNATURE.len]).expect("bad utf-8")
+//!		}
+//!	}
+//!
+//! // Make signatures for some types
+//!	impl SoliditySignature for u8 {
+//!		make_signature!(new fixed("uint8"));
+//!	}
+//!	impl SoliditySignature for u32 {
+//!		make_signature!(new fixed("uint32"));
+//!	}
+//!	impl<T: SoliditySignature> SoliditySignature for Vec<T> {
+//!		make_signature!(new nameof(T) fixed("[]"));
+//!	}
+//!	impl<A: SoliditySignature, B: SoliditySignature> SoliditySignature for (A, B) {
+//!		make_signature!(new fixed("(") nameof(A) fixed(",") nameof(B) fixed(")"));
+//!	}
+//!	impl<A: SoliditySignature> SoliditySignature for (A,) {
+//!		make_signature!(new fixed("(") nameof(A) fixed(",") shift_left(1) fixed(")"));
+//!	}
+//!
+//! assert_eq!(u8::name(), "uint8");
+//! assert_eq!(<Vec<u8>>::name(), "uint8[]");
+//! assert_eq!(<(u32, u8)>::name(), "(uint32,uint8)");
+//! ```
+//!
+//! ### Function signatures
+//! To create a function signature, the macro [`make_signature`] is also used, which accepts
+//! settings for the function format [`SignaturePreferences`] and function parameters [`SignatureUnit`]
+//! #### Example
+//! ```
+//! use core::str::from_utf8;
+//! use evm_coder::{
+//!		make_signature,
+//!		custom_signature::{
+//!			SIGNATURE_SIZE_LIMIT, SignatureUnit, SignaturePreferences, FunctionSignature,
+//!		},
+//!	};
+//! // Trait for our signature
+//! trait SoliditySignature {
+//!		const SIGNATURE: SignatureUnit;
+//!
+//!		fn name() -> &'static str {
+//!			from_utf8(&Self::SIGNATURE.data[..Self::SIGNATURE.len]).expect("bad utf-8")
+//!		}
+//!	}
+//!
+//! // Make signatures for some types
+//!	impl SoliditySignature for u8 {
+//!		make_signature!(new fixed("uint8"));
+//!	}
+//!	impl<T: SoliditySignature> SoliditySignature for Vec<T> {
+//!		make_signature!(new nameof(T) fixed("[]"));
+//!	}
+//!
+//! // Function signature settings
+//! const SIGNATURE_PREFERENCES: SignaturePreferences = SignaturePreferences {
+//!		open_name: Some(SignatureUnit::new("some_funk")),
+//!		open_delimiter: Some(SignatureUnit::new("(")),
+//!		param_delimiter: Some(SignatureUnit::new(",")),
+//!		close_delimiter: Some(SignatureUnit::new(")")),
+//!		close_name: None,
+//!	};
+//!
+//! // Create functions signatures
+//! fn make_func_without_args() {
+//!		const SIG: FunctionSignature = make_signature!(
+//!			new fn(SIGNATURE_PREFERENCES),
+//!		);
+//!		let name = SIG.as_str();
+//!		similar_asserts::assert_eq!(name, "some_funk()");
+//!	}
+//!
+//! fn make_func_with_3_args() {
+//!		const SIG: FunctionSignature = make_signature!(
+//!			new fn(SIGNATURE_PREFERENCES),
+//!			(<u8>::SIGNATURE),
+//!			(<u8>::SIGNATURE),
+//!			(<Vec<u8>>::SIGNATURE),
+//!		);
+//!		let name = SIG.as_str();
+//!		similar_asserts::assert_eq!(name, "some_funk(uint8,uint8,uint8[])");
+//!	}
+//! ```
 use core::str::from_utf8;
 
+/// The maximum length of the signature.
 pub const SIGNATURE_SIZE_LIMIT: usize = 256;
 
+/// Function signature formatting preferences.
 #[derive(Debug)]
 pub struct SignaturePreferences {
+	/// The name of the function before the list of parameters: `*some*(param1,param2)func`
 	pub open_name: Option<SignatureUnit>,
+	/// Opening separator: `some*(*param1,param2)func`
 	pub open_delimiter: Option<SignatureUnit>,
+	/// Parameters separator: `some(param1*,*param2)func`
 	pub param_delimiter: Option<SignatureUnit>,
+	/// Closinging separator: `some(param1,param2*)*func`
 	pub close_delimiter: Option<SignatureUnit>,
+	/// The name of the function after the list of parameters: `some(param1,param2)*func*`
 	pub close_name: Option<SignatureUnit>,
 }
 
+/// Constructs and stores the signature of the function.
 #[derive(Debug)]
 pub struct FunctionSignature {
+	/// Storage for function signature.
 	pub unit: SignatureUnit,
 	preferences: SignaturePreferences,
 }
 
 impl FunctionSignature {
+	/// Start constructing the signature. It is written to the storage
+	/// [`SignaturePreferences::open_name`] and [`SignaturePreferences::open_delimiter`].
 	pub const fn new(preferences: SignaturePreferences) -> FunctionSignature {
 		let mut dst = [0_u8; SIGNATURE_SIZE_LIMIT];
 		let mut dst_offset = 0;
@@ -36,6 +153,8 @@
 		}
 	}
 
+	/// Add a function parameter to the signature. It is written to the storage
+	/// `param` [`SignatureUnit`] and [`SignaturePreferences::param_delimiter`].
 	pub const fn add_param(
 		signature: FunctionSignature,
 		param: SignatureUnit,
@@ -55,6 +174,8 @@
 		}
 	}
 
+	/// Complete signature construction. It is written to the storage
+	/// [`SignaturePreferences::close_delimiter`] and [`SignaturePreferences::close_name`].
 	pub const fn done(signature: FunctionSignature, owerride: bool) -> FunctionSignature {
 		let mut dst = signature.unit.data;
 		let mut dst_offset = signature.unit.len - if owerride { 1 } else { 0 };
@@ -73,18 +194,23 @@
 		}
 	}
 
+	/// Represent the signature as `&str'.
 	pub fn as_str(&self) -> &str {
 		from_utf8(&self.unit.data[..self.unit.len]).expect("bad utf-8")
 	}
 }
 
+/// Storage for the signature or its elements.
 #[derive(Debug)]
 pub struct SignatureUnit {
+	/// Signature data.
 	pub data: [u8; SIGNATURE_SIZE_LIMIT],
+	/// The actual size of the data.
 	pub len: usize,
 }
 
 impl SignatureUnit {
+	/// Create a signature from `&str'.
 	pub const fn new(name: &'static str) -> SignatureUnit {
 		let mut signature = [0_u8; SIGNATURE_SIZE_LIMIT];
 		let name = name.as_bytes();
@@ -98,9 +224,23 @@
 	}
 }
 
+/// ### Macro to create signatures of types and functions.
+///
+/// Format for creating a type of signature:
+/// ```ignore
+/// make_signature!(new fixed("uint8")); // Simple type
+/// make_signature!(new fixed("(") nameof(u8) fixed(",") nameof(u8) fixed(")")); // Composite type
+/// ```
+/// Format for creating a function of the function:
+/// ```ignore
+/// const SIG: FunctionSignature = make_signature!(
+///		new fn(SIGNATURE_PREFERENCES),
+///		(u8::SIGNATURE),
+///		(<(u8,u8)>::SIGNATURE),
+///	);
+/// ```
 #[macro_export]
-#[allow(missing_docs)]
-macro_rules! make_signature { // May be "define_signature"?
+macro_rules! make_signature {
 	(new fn($func:expr)$(,)+) => {
 		{
 			let fs = FunctionSignature::new($func);
@@ -283,10 +423,13 @@
 		assert_eq!(<MaxSize>::name(), "!".repeat(SIGNATURE_SIZE_LIMIT));
 	}
 
-	// This test must NOT compile!
+	// This test must NOT compile with "index out of bounds"!
 	// #[test]
 	// fn over_max_size() {
-	// 	assert_eq!(<Vec<MaxSize>>::name(), "!".repeat(SIZE_LIMIT) + "[]");
+	// 	assert_eq!(
+	// 		<Vec<MaxSize>>::name(),
+	// 		"!".repeat(SIGNATURE_SIZE_LIMIT) + "[]"
+	// 	);
 	// }
 
 	#[test]
modifiedcrates/evm-coder/src/lib.rsdiffbeforeafterboth
--- a/crates/evm-coder/src/lib.rs
+++ b/crates/evm-coder/src/lib.rs
@@ -15,8 +15,7 @@
 // along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
 
 #![doc = include_str!("../README.md")]
-// #![deny(missing_docs)]
-#![warn(missing_docs)]
+#![deny(missing_docs)]
 #![macro_use]
 #![cfg_attr(not(feature = "std"), no_std)]
 #[cfg(not(feature = "std"))]
@@ -94,7 +93,6 @@
 pub use evm_coder_procedural::solidity;
 /// See [`solidity_interface`]
 pub use evm_coder_procedural::weight;
-pub use const_format;
 pub use sha3_const;
 
 /// Derives [`ToLog`] for enum
@@ -384,18 +382,6 @@
 	fn function_selector_generation() {
 		assert_eq!(fn_selector!(transfer(address, uint256)), 0xa9059cbb);
 	}
-
-	// #[test]
-	// fn function_selector_generation_1() {
-	// 	assert_eq!(
-	// 		fn_selector!(transferFromCrossAccountToCrossAccount(
-	// 			EthCrossAccount,
-	// 			EthCrossAccount,
-	// 			uint256
-	// 		)),
-	// 		2543295963
-	// 	);
-	// }
 
 	#[test]
 	fn event_topic_generation() {
modifiedcrates/evm-coder/tests/conditional_is.rsdiffbeforeafterboth
--- a/crates/evm-coder/tests/conditional_is.rs
+++ b/crates/evm-coder/tests/conditional_is.rs
@@ -1,4 +1,11 @@
 use evm_coder::{types::*, solidity_interface, execution::Result};
+use evm_coder::{
+	make_signature,
+	custom_signature::{
+		SIGNATURE_SIZE_LIMIT, SignatureUnit, SignaturePreferences, FunctionSignature,
+	},
+	types::Signature,
+};
 
 pub struct Contract(bool);
 
modifiedcrates/evm-coder/tests/generics.rsdiffbeforeafterboth
--- a/crates/evm-coder/tests/generics.rs
+++ b/crates/evm-coder/tests/generics.rs
@@ -16,6 +16,12 @@
 
 use std::marker::PhantomData;
 use evm_coder::{execution::Result, generate_stubgen, solidity_interface, types::*};
+use evm_coder::{
+	make_signature,
+	custom_signature::{
+		SIGNATURE_SIZE_LIMIT, SignatureUnit, SignaturePreferences, FunctionSignature,
+	},
+};
 
 pub struct Generic<T>(PhantomData<T>);
 
modifiedcrates/evm-coder/tests/random.rsdiffbeforeafterboth
--- a/crates/evm-coder/tests/random.rs
+++ b/crates/evm-coder/tests/random.rs
@@ -17,6 +17,13 @@
 #![allow(dead_code)] // This test only checks that macros is not panicking
 
 use evm_coder::{ToLog, execution::Result, solidity_interface, types::*, solidity, weight};
+use evm_coder::{
+	make_signature,
+	custom_signature::{
+		SIGNATURE_SIZE_LIMIT, SignatureUnit, SignaturePreferences, FunctionSignature,
+	},
+	types::Signature,
+};
 
 pub struct Impls;
 
modifiedcrates/evm-coder/tests/solidity_generation.rsdiffbeforeafterboth
--- a/crates/evm-coder/tests/solidity_generation.rs
+++ b/crates/evm-coder/tests/solidity_generation.rs
@@ -15,6 +15,13 @@
 // along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
 
 use evm_coder::{execution::Result, generate_stubgen, solidity_interface, types::*};
+use evm_coder::{
+	make_signature,
+	custom_signature::{
+		SIGNATURE_SIZE_LIMIT, SignatureUnit, SignaturePreferences, FunctionSignature,
+	},
+	types::Signature,
+};
 
 pub struct ERC20;
 
modifiedtests/src/eth/base.test.tsdiffbeforeafterboth
--- a/tests/src/eth/base.test.ts
+++ b/tests/src/eth/base.test.ts
@@ -116,8 +116,8 @@
     await checkInterface(helper, '0x780e9d63', true, true);
   });
 
-  itEth('ERC721UniqueExtensions - 0x244543ee - support', async ({helper}) => {
-    await checkInterface(helper, '0x244543ee', true, true);
+  itEth('ERC721UniqueExtensions support', async ({helper}) => {
+    expect(await contract(helper).methods.supportsInterface('0xb76006ac').call()).to.be.true;
   });
 
   itEth('ERC721Burnable - 0x42966c68 - support', async ({helper}) => {
modifiedtests/src/eth/nonFungible.test.tsdiffbeforeafterboth
--- a/tests/src/eth/nonFungible.test.ts
+++ b/tests/src/eth/nonFungible.test.ts
@@ -410,14 +410,13 @@
   });
 
   itEth('Can perform transferFromCross()', async ({helper, privateKey}) => {
-    const alice = privateKey('//Alice');
-    const collection = await helper.nft.mintCollection(alice, {name: 'A', description: 'B', tokenPrefix: 'C'});
+    const collection = await helper.nft.mintCollection(donor, {name: 'A', description: 'B', tokenPrefix: 'C'});
 
     const owner = privateKey('//Bob');
-    const spender = await helper.eth.createAccountWithBalance(alice, 100n);
+    const spender = await helper.eth.createAccountWithBalance(donor, 100n);
     const receiver = privateKey('//Charlie');
 
-    const token = await collection.mintToken(alice, {Substrate: owner.address});
+    const token = await collection.mintToken(donor, {Substrate: owner.address});
 
     const address = helper.ethAddress.fromCollectionId(collection.collectionId);
     const contract = helper.ethNativeContract.collection(address, 'nft');
modifiedtests/src/eth/reFungible.test.tsdiffbeforeafterboth
before · tests/src/eth/reFungible.test.ts
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {Pallets, requirePalletsOrSkip} from '../util';18import {expect, itEth, usingEthPlaygrounds} from './util';19import {IKeyringPair} from '@polkadot/types/types';2021describe('Refungible: Information getting', () => {22  let donor: IKeyringPair;2324  before(async function() {25    await usingEthPlaygrounds(async (helper, privateKey) => {26      requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);2728      donor = await privateKey({filename: __filename});29    });30  });3132  itEth('totalSupply', async ({helper}) => {33    const caller = await helper.eth.createAccountWithBalance(donor);34    const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'TotalSupply', '6', '6');35    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);3637    await contract.methods.mint(caller).send();3839    const totalSupply = await contract.methods.totalSupply().call();40    expect(totalSupply).to.equal('1');41  });4243  itEth('balanceOf', async ({helper}) => {44    const caller = await helper.eth.createAccountWithBalance(donor);45    const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'BalanceOf', '6', '6');46    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);4748    await contract.methods.mint(caller).send();49    await contract.methods.mint(caller).send();50    await contract.methods.mint(caller).send();5152    const balance = await contract.methods.balanceOf(caller).call();53    expect(balance).to.equal('3');54  });5556  itEth('ownerOf', async ({helper}) => {57    const caller = await helper.eth.createAccountWithBalance(donor);58    const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'OwnerOf', '6', '6');59    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);6061    const result = await contract.methods.mint(caller).send();62    const tokenId = result.events.Transfer.returnValues.tokenId;6364    const owner = await contract.methods.ownerOf(tokenId).call();65    expect(owner).to.equal(caller);66  });6768  itEth('ownerOf after burn', async ({helper}) => {69    const caller = await helper.eth.createAccountWithBalance(donor);70    const receiver = helper.eth.createAccount();71    const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(caller, 'OwnerOf-AfterBurn', '6', '6');72    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);7374    const result = await contract.methods.mint(caller).send();75    const tokenId = result.events.Transfer.returnValues.tokenId;76    const tokenContract = helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller);7778    await tokenContract.methods.repartition(2).send();79    await tokenContract.methods.transfer(receiver, 1).send();8081    await tokenContract.methods.burnFrom(caller, 1).send();8283    const owner = await contract.methods.ownerOf(tokenId).call();84    expect(owner).to.equal(receiver);85  });8687  itEth('ownerOf for partial ownership', async ({helper}) => {88    const caller = await helper.eth.createAccountWithBalance(donor);89    const receiver = helper.eth.createAccount();90    const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(caller, 'Partial-OwnerOf', '6', '6');91    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);9293    const result = await contract.methods.mint(caller).send();94    const tokenId = result.events.Transfer.returnValues.tokenId;95    const tokenContract = helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller);9697    await tokenContract.methods.repartition(2).send();98    await tokenContract.methods.transfer(receiver, 1).send();99100    const owner = await contract.methods.ownerOf(tokenId).call();101    expect(owner).to.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');102  });103});104105describe('Refungible: Plain calls', () => {106  let donor: IKeyringPair;107108  before(async function() {109    await usingEthPlaygrounds(async (helper, privateKey) => {110      requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);111112      donor = await privateKey({filename: __filename});113    });114  });115116  itEth('Can perform mint()', async ({helper}) => {117    const owner = await helper.eth.createAccountWithBalance(donor);118    const receiver = helper.eth.createAccount();119    const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleRFTCollection(owner, 'Minty', '6', '6', '');120    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);121122    const result = await contract.methods.mintWithTokenURI(receiver, 'Test URI').send();123124    const event = result.events.Transfer;125    expect(event.address).to.equal(collectionAddress);126    expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');127    expect(event.returnValues.to).to.equal(receiver);128    const tokenId = event.returnValues.tokenId;129    expect(tokenId).to.be.equal('1');130131    expect(await contract.methods.tokenURI(tokenId).call()).to.be.equal('Test URI');132  });133134  itEth.skip('Can perform mintBulk()', async ({helper}) => {135    const owner = await helper.eth.createAccountWithBalance(donor);136    const receiver = helper.eth.createAccount();137    const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleRFTCollection(owner, 'MintBulky', '6', '6', '');138    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);139140    {141      const nextTokenId = await contract.methods.nextTokenId().call();142      expect(nextTokenId).to.be.equal('1');143      const result = await contract.methods.mintBulkWithTokenURI(144        receiver,145        [146          [nextTokenId, 'Test URI 0'],147          [+nextTokenId + 1, 'Test URI 1'],148          [+nextTokenId + 2, 'Test URI 2'],149        ],150      ).send();151152      const events = result.events.Transfer;153      for (let i = 0; i < 2; i++) {154        const event = events[i];155        expect(event.address).to.equal(collectionAddress);156        expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');157        expect(event.returnValues.to).to.equal(receiver);158        expect(event.returnValues.tokenId).to.equal(String(+nextTokenId + i));159      }160161      expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI 0');162      expect(await contract.methods.tokenURI(+nextTokenId + 1).call()).to.be.equal('Test URI 1');163      expect(await contract.methods.tokenURI(+nextTokenId + 2).call()).to.be.equal('Test URI 2');164    }165  });166167  itEth('Can perform burn()', async ({helper}) => {168    const caller = await helper.eth.createAccountWithBalance(donor);169    const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'Burny', '6', '6');170    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);171172    const result = await contract.methods.mint(caller).send();173    const tokenId = result.events.Transfer.returnValues.tokenId;174    {175      const result = await contract.methods.burn(tokenId).send();176      const event = result.events.Transfer;177      expect(event.address).to.equal(collectionAddress);178      expect(event.returnValues.from).to.equal(caller);179      expect(event.returnValues.to).to.equal('0x0000000000000000000000000000000000000000');180      expect(event.returnValues.tokenId).to.equal(tokenId.toString());181    }182  });183184  itEth('Can perform transferFrom()', async ({helper}) => {185    const caller = await helper.eth.createAccountWithBalance(donor);186    const receiver = helper.eth.createAccount();187    const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(caller, 'TransferFromy', '6', '6');188    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);189190    const result = await contract.methods.mint(caller).send();191    const tokenId = result.events.Transfer.returnValues.tokenId;192193    const tokenAddress = helper.ethAddress.fromTokenId(collectionId, tokenId);194195    const tokenContract = helper.ethNativeContract.rftToken(tokenAddress, caller);196    await tokenContract.methods.repartition(15).send();197198    {199      const tokenEvents: any = [];200      tokenContract.events.allEvents((_: any, event: any) => {201        tokenEvents.push(event);202      });203      const result = await contract.methods.transferFrom(caller, receiver, tokenId).send();204      if (tokenEvents.length == 0) await helper.wait.newBlocks(1);205206      let event = result.events.Transfer;207      expect(event.address).to.equal(collectionAddress);208      expect(event.returnValues.from).to.equal(caller);209      expect(event.returnValues.to).to.equal(receiver);210      expect(event.returnValues.tokenId).to.equal(tokenId.toString());211212      event = tokenEvents[0];213      expect(event.address).to.equal(tokenAddress);214      expect(event.returnValues.from).to.equal(caller);215      expect(event.returnValues.to).to.equal(receiver);216      expect(event.returnValues.value).to.equal('15');217    }218219    {220      const balance = await contract.methods.balanceOf(receiver).call();221      expect(+balance).to.equal(1);222    }223224    {225      const balance = await contract.methods.balanceOf(caller).call();226      expect(+balance).to.equal(0);227    }228  });229230  itEth('Can perform burnFrom()', async ({helper, privateKey}) => {231    const alice = privateKey('//Alice');232    const collection = await helper.rft.mintCollection(alice, {name: 'A', description: 'B', tokenPrefix: 'C'});233234    const owner = await helper.eth.createAccountWithBalance(alice, 100n);235    const spender = await helper.eth.createAccountWithBalance(alice, 100n);236237    const token = await collection.mintToken(alice, 100n, {Ethereum: owner});238239    const address = helper.ethAddress.fromCollectionId(collection.collectionId);240    const contract = helper.ethNativeContract.collection(address, 'rft');241242    const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, token.tokenId);243    const tokenContract = helper.ethNativeContract.rftToken(tokenAddress, owner);244    await tokenContract.methods.repartition(15).send();245    await tokenContract.methods.approve(spender, 15).send();246247    {248      const result = await contract.methods.burnFrom(owner, token.tokenId).send({from: spender});249      const event = result.events.Transfer;250      expect(event).to.be.like({251        address: helper.ethAddress.fromCollectionId(collection.collectionId),252        event: 'Transfer',253        returnValues: {254          from: owner,255          to: '0x0000000000000000000000000000000000000000',256          tokenId: token.tokenId.toString(),257        },258      });259    }260261    expect(await collection.getTokenBalance(token.tokenId, {Ethereum: owner})).to.be.eq(0n);262  });263264  itEth('Can perform burnFromCross()', async ({helper, privateKey}) => {265    const alice = privateKey('//Alice');266    const collection = await helper.rft.mintCollection(alice, {name: 'A', description: 'B', tokenPrefix: 'C'});267268    const owner = privateKey('//Bob');269    const spender = await helper.eth.createAccountWithBalance(alice, 100n);270271    const token = await collection.mintToken(alice, 100n, {Substrate: owner.address});272273    const address = helper.ethAddress.fromCollectionId(collection.collectionId);274    const contract = helper.ethNativeContract.collection(address, 'rft');275276    await token.repartition(owner, 15n);277    await token.approve(owner, {Ethereum: spender}, 15n);278279    {280      const ownerCross = helper.ethCrossAccount.fromKeyringPair(owner);281      const result = await contract.methods.burnFromCross(ownerCross, token.tokenId).send({from: spender});282      const event = result.events.Transfer;283      expect(event).to.be.like({284        address: helper.ethAddress.fromCollectionId(collection.collectionId),285        event: 'Transfer',286        returnValues: {287          from: helper.address.substrateToEth(owner.address),288          to: '0x0000000000000000000000000000000000000000',289          tokenId: token.tokenId.toString(),290        },291      });292    }293294    expect(await collection.getTokenBalance(token.tokenId, {Substrate: owner.address})).to.be.eq(0n);295  });296297  itEth('Can perform transferFromCross()', async ({helper, privateKey}) => {298    const alice = privateKey('//Alice');299    const collection = await helper.rft.mintCollection(alice, {name: 'A', description: 'B', tokenPrefix: 'C'});300301    const owner = privateKey('//Bob');302    const spender = await helper.eth.createAccountWithBalance(alice, 100n);303    const receiver = privateKey('//Charlie');304305    const token = await collection.mintToken(alice, 100n, {Substrate: owner.address});306307    const address = helper.ethAddress.fromCollectionId(collection.collectionId);308    const contract = helper.ethNativeContract.collection(address, 'rft');309310    await token.repartition(owner, 15n);311    await token.approve(owner, {Ethereum: spender}, 15n);312313    {314      const ownerCross = helper.ethCrossAccount.fromKeyringPair(owner);315      const recieverCross = helper.ethCrossAccount.fromKeyringPair(receiver);316      const result = await contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: spender});317      const event = result.events.Transfer;318      expect(event).to.be.like({319        address: helper.ethAddress.fromCollectionId(collection.collectionId),320        event: 'Transfer',321        returnValues: {322          from: helper.address.substrateToEth(owner.address),323          to: helper.address.substrateToEth(receiver.address),324          tokenId: token.tokenId.toString(),325        },326      });327    }328329    expect(await token.getTop10Owners()).to.be.like([{Substrate: receiver.address}]);330  });331332  itEth('Can perform transfer()', async ({helper}) => {333    const caller = await helper.eth.createAccountWithBalance(donor);334    const receiver = helper.eth.createAccount();335    const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'Transferry', '6', '6');336    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);337338    const result = await contract.methods.mint(caller).send();339    const tokenId = result.events.Transfer.returnValues.tokenId;340341    {342      const result = await contract.methods.transfer(receiver, tokenId).send();343344      const event = result.events.Transfer;345      expect(event.address).to.equal(collectionAddress);346      expect(event.returnValues.from).to.equal(caller);347      expect(event.returnValues.to).to.equal(receiver);348      expect(event.returnValues.tokenId).to.equal(tokenId.toString());349    }350351    {352      const balance = await contract.methods.balanceOf(caller).call();353      expect(+balance).to.equal(0);354    }355356    {357      const balance = await contract.methods.balanceOf(receiver).call();358      expect(+balance).to.equal(1);359    }360  });361362  itEth('transfer event on transfer from partial ownership to full ownership', async ({helper}) => {363    const caller = await helper.eth.createAccountWithBalance(donor);364    const receiver = helper.eth.createAccount();365    const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(caller, 'Transferry-Partial-to-Full', '6', '6');366    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);367368    const result = await contract.methods.mint(caller).send();369    const tokenId = result.events.Transfer.returnValues.tokenId;370371    const tokenContract = helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller);372373    await tokenContract.methods.repartition(2).send();374    await tokenContract.methods.transfer(receiver, 1).send();375376    const events: any = [];377    contract.events.allEvents((_: any, event: any) => {378      events.push(event);379    });380381    await tokenContract.methods.transfer(receiver, 1).send();382    if (events.length == 0) await helper.wait.newBlocks(1);383    const event = events[0];384385    expect(event.address).to.equal(collectionAddress);386    expect(event.returnValues.from).to.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');387    expect(event.returnValues.to).to.equal(receiver);388    expect(event.returnValues.tokenId).to.equal(tokenId.toString());389  });390391  itEth('transfer event on transfer from full ownership to partial ownership', async ({helper}) => {392    const caller = await helper.eth.createAccountWithBalance(donor);393    const receiver = helper.eth.createAccount();394    const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(caller, 'Transferry-Full-to-Partial', '6', '6');395    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);396397    const result = await contract.methods.mint(caller).send();398    const tokenId = result.events.Transfer.returnValues.tokenId;399400    const tokenContract = helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller);401402    await tokenContract.methods.repartition(2).send();403404    const events: any = [];405    contract.events.allEvents((_: any, event: any) => {406      events.push(event);407    });408409    await tokenContract.methods.transfer(receiver, 1).send();410    if (events.length == 0) await helper.wait.newBlocks(1);411    const event = events[0];412413    expect(event.address).to.equal(collectionAddress);414    expect(event.returnValues.from).to.equal(caller);415    expect(event.returnValues.to).to.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');416    expect(event.returnValues.tokenId).to.equal(tokenId.toString());417  });418});419420describe('RFT: Fees', () => {421  let donor: IKeyringPair;422423  before(async function() {424    await usingEthPlaygrounds(async (helper, privateKey) => {425      requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);426427      donor = await privateKey({filename: __filename});428    });429  });430431  itEth('transferFrom() call fee is less than 0.2UNQ', async ({helper}) => {432    const caller = await helper.eth.createAccountWithBalance(donor);433    const receiver = helper.eth.createAccount();434    const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'Feeful-Transfer-From', '6', '6');435    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);436437    const result = await contract.methods.mint(caller).send();438    const tokenId = result.events.Transfer.returnValues.tokenId;439440    const cost = await helper.eth.recordCallFee(caller, () => contract.methods.transferFrom(caller, receiver, tokenId).send());441    expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));442    expect(cost > 0n);443  });444445  itEth('transfer() call fee is less than 0.2UNQ', async ({helper}) => {446    const caller = await helper.eth.createAccountWithBalance(donor);447    const receiver = helper.eth.createAccount();448    const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'Feeful-Transfer', '6', '6');449    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);450451    const result = await contract.methods.mint(caller).send();452    const tokenId = result.events.Transfer.returnValues.tokenId;453454    const cost = await helper.eth.recordCallFee(caller, () => contract.methods.transfer(receiver, tokenId).send());455    expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));456    expect(cost > 0n);457  });458});459460describe('Common metadata', () => {461  let donor: IKeyringPair;462  let alice: IKeyringPair;463464  before(async function() {465    await usingEthPlaygrounds(async (helper, privateKey) => {466      requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);467468      donor = await privateKey({filename: __filename});469      [alice] = await helper.arrange.createAccounts([20n], donor);470    });471  });472473  itEth('Returns collection name', async ({helper}) => {474    const caller = helper.eth.createAccount();475    const tokenPropertyPermissions = [{476      key: 'URI',477      permission: {478        mutable: true,479        collectionAdmin: true,480        tokenOwner: false,481      },482    }];483    const collection = await helper.rft.mintCollection(484      alice,485      {486        name: 'Leviathan',487        tokenPrefix: '11',488        properties: [{key: 'ERC721Metadata', value: '1'}],489        tokenPropertyPermissions,490      },491    );492493    const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'rft', caller);494    const name = await contract.methods.name().call();495    expect(name).to.equal('Leviathan');496  });497498  itEth('Returns symbol name', async ({helper}) => {499    const caller = await helper.eth.createAccountWithBalance(donor);500    const tokenPropertyPermissions = [{501      key: 'URI',502      permission: {503        mutable: true,504        collectionAdmin: true,505        tokenOwner: false,506      },507    }];508    const {collectionId} = await helper.rft.mintCollection(509      alice,510      {511        name: 'Leviathan',512        tokenPrefix: '12',513        properties: [{key: 'ERC721Metadata', value: '1'}],514        tokenPropertyPermissions,515      },516    );517518    const contract = helper.ethNativeContract.collectionById(collectionId, 'rft', caller);519    const symbol = await contract.methods.symbol().call();520    expect(symbol).to.equal('12');521  });522});
after · tests/src/eth/reFungible.test.ts
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {Pallets, requirePalletsOrSkip} from '../util';18import {expect, itEth, usingEthPlaygrounds} from './util';19import {IKeyringPair} from '@polkadot/types/types';2021describe('Refungible: Information getting', () => {22  let donor: IKeyringPair;2324  before(async function() {25    await usingEthPlaygrounds(async (helper, privateKey) => {26      requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);2728      donor = await privateKey({filename: __filename});29    });30  });3132  itEth('totalSupply', async ({helper}) => {33    const caller = await helper.eth.createAccountWithBalance(donor);34    const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'TotalSupply', '6', '6');35    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);3637    await contract.methods.mint(caller).send();3839    const totalSupply = await contract.methods.totalSupply().call();40    expect(totalSupply).to.equal('1');41  });4243  itEth('balanceOf', async ({helper}) => {44    const caller = await helper.eth.createAccountWithBalance(donor);45    const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'BalanceOf', '6', '6');46    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);4748    await contract.methods.mint(caller).send();49    await contract.methods.mint(caller).send();50    await contract.methods.mint(caller).send();5152    const balance = await contract.methods.balanceOf(caller).call();53    expect(balance).to.equal('3');54  });5556  itEth('ownerOf', async ({helper}) => {57    const caller = await helper.eth.createAccountWithBalance(donor);58    const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'OwnerOf', '6', '6');59    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);6061    const result = await contract.methods.mint(caller).send();62    const tokenId = result.events.Transfer.returnValues.tokenId;6364    const owner = await contract.methods.ownerOf(tokenId).call();65    expect(owner).to.equal(caller);66  });6768  itEth('ownerOf after burn', async ({helper}) => {69    const caller = await helper.eth.createAccountWithBalance(donor);70    const receiver = helper.eth.createAccount();71    const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(caller, 'OwnerOf-AfterBurn', '6', '6');72    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);7374    const result = await contract.methods.mint(caller).send();75    const tokenId = result.events.Transfer.returnValues.tokenId;76    const tokenContract = helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller);7778    await tokenContract.methods.repartition(2).send();79    await tokenContract.methods.transfer(receiver, 1).send();8081    await tokenContract.methods.burnFrom(caller, 1).send();8283    const owner = await contract.methods.ownerOf(tokenId).call();84    expect(owner).to.equal(receiver);85  });8687  itEth('ownerOf for partial ownership', async ({helper}) => {88    const caller = await helper.eth.createAccountWithBalance(donor);89    const receiver = helper.eth.createAccount();90    const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(caller, 'Partial-OwnerOf', '6', '6');91    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);9293    const result = await contract.methods.mint(caller).send();94    const tokenId = result.events.Transfer.returnValues.tokenId;95    const tokenContract = helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller);9697    await tokenContract.methods.repartition(2).send();98    await tokenContract.methods.transfer(receiver, 1).send();99100    const owner = await contract.methods.ownerOf(tokenId).call();101    expect(owner).to.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');102  });103});104105describe('Refungible: Plain calls', () => {106  let donor: IKeyringPair;107108  before(async function() {109    await usingEthPlaygrounds(async (helper, privateKey) => {110      requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);111112      donor = await privateKey({filename: __filename});113    });114  });115116  itEth('Can perform mint()', async ({helper}) => {117    const owner = await helper.eth.createAccountWithBalance(donor);118    const receiver = helper.eth.createAccount();119    const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleRFTCollection(owner, 'Minty', '6', '6', '');120    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);121122    const result = await contract.methods.mintWithTokenURI(receiver, 'Test URI').send();123124    const event = result.events.Transfer;125    expect(event.address).to.equal(collectionAddress);126    expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');127    expect(event.returnValues.to).to.equal(receiver);128    const tokenId = event.returnValues.tokenId;129    expect(tokenId).to.be.equal('1');130131    expect(await contract.methods.tokenURI(tokenId).call()).to.be.equal('Test URI');132  });133134  itEth.skip('Can perform mintBulk()', async ({helper}) => {135    const owner = await helper.eth.createAccountWithBalance(donor);136    const receiver = helper.eth.createAccount();137    const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleRFTCollection(owner, 'MintBulky', '6', '6', '');138    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);139140    {141      const nextTokenId = await contract.methods.nextTokenId().call();142      expect(nextTokenId).to.be.equal('1');143      const result = await contract.methods.mintBulkWithTokenURI(144        receiver,145        [146          [nextTokenId, 'Test URI 0'],147          [+nextTokenId + 1, 'Test URI 1'],148          [+nextTokenId + 2, 'Test URI 2'],149        ],150      ).send();151152      const events = result.events.Transfer;153      for (let i = 0; i < 2; i++) {154        const event = events[i];155        expect(event.address).to.equal(collectionAddress);156        expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');157        expect(event.returnValues.to).to.equal(receiver);158        expect(event.returnValues.tokenId).to.equal(String(+nextTokenId + i));159      }160161      expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI 0');162      expect(await contract.methods.tokenURI(+nextTokenId + 1).call()).to.be.equal('Test URI 1');163      expect(await contract.methods.tokenURI(+nextTokenId + 2).call()).to.be.equal('Test URI 2');164    }165  });166167  itEth('Can perform burn()', async ({helper}) => {168    const caller = await helper.eth.createAccountWithBalance(donor);169    const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'Burny', '6', '6');170    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);171172    const result = await contract.methods.mint(caller).send();173    const tokenId = result.events.Transfer.returnValues.tokenId;174    {175      const result = await contract.methods.burn(tokenId).send();176      const event = result.events.Transfer;177      expect(event.address).to.equal(collectionAddress);178      expect(event.returnValues.from).to.equal(caller);179      expect(event.returnValues.to).to.equal('0x0000000000000000000000000000000000000000');180      expect(event.returnValues.tokenId).to.equal(tokenId.toString());181    }182  });183184  itEth('Can perform transferFrom()', async ({helper}) => {185    const caller = await helper.eth.createAccountWithBalance(donor);186    const receiver = helper.eth.createAccount();187    const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(caller, 'TransferFromy', '6', '6');188    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);189190    const result = await contract.methods.mint(caller).send();191    const tokenId = result.events.Transfer.returnValues.tokenId;192193    const tokenAddress = helper.ethAddress.fromTokenId(collectionId, tokenId);194195    const tokenContract = helper.ethNativeContract.rftToken(tokenAddress, caller);196    await tokenContract.methods.repartition(15).send();197198    {199      const tokenEvents: any = [];200      tokenContract.events.allEvents((_: any, event: any) => {201        tokenEvents.push(event);202      });203      const result = await contract.methods.transferFrom(caller, receiver, tokenId).send();204      if (tokenEvents.length == 0) await helper.wait.newBlocks(1);205206      let event = result.events.Transfer;207      expect(event.address).to.equal(collectionAddress);208      expect(event.returnValues.from).to.equal(caller);209      expect(event.returnValues.to).to.equal(receiver);210      expect(event.returnValues.tokenId).to.equal(tokenId.toString());211212      event = tokenEvents[0];213      expect(event.address).to.equal(tokenAddress);214      expect(event.returnValues.from).to.equal(caller);215      expect(event.returnValues.to).to.equal(receiver);216      expect(event.returnValues.value).to.equal('15');217    }218219    {220      const balance = await contract.methods.balanceOf(receiver).call();221      expect(+balance).to.equal(1);222    }223224    {225      const balance = await contract.methods.balanceOf(caller).call();226      expect(+balance).to.equal(0);227    }228  });229230  itEth('Can perform burnFrom()', async ({helper, privateKey}) => {231    const alice = privateKey('//Alice');232    const collection = await helper.rft.mintCollection(alice, {name: 'A', description: 'B', tokenPrefix: 'C'});233234    const owner = await helper.eth.createAccountWithBalance(alice, 100n);235    const spender = await helper.eth.createAccountWithBalance(alice, 100n);236237    const token = await collection.mintToken(alice, 100n, {Ethereum: owner});238239    const address = helper.ethAddress.fromCollectionId(collection.collectionId);240    const contract = helper.ethNativeContract.collection(address, 'rft');241242    const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, token.tokenId);243    const tokenContract = helper.ethNativeContract.rftToken(tokenAddress, owner);244    await tokenContract.methods.repartition(15).send();245    await tokenContract.methods.approve(spender, 15).send();246247    {248      const result = await contract.methods.burnFrom(owner, token.tokenId).send({from: spender});249      const event = result.events.Transfer;250      expect(event).to.be.like({251        address: helper.ethAddress.fromCollectionId(collection.collectionId),252        event: 'Transfer',253        returnValues: {254          from: owner,255          to: '0x0000000000000000000000000000000000000000',256          tokenId: token.tokenId.toString(),257        },258      });259    }260261    expect(await collection.getTokenBalance(token.tokenId, {Ethereum: owner})).to.be.eq(0n);262  });263264  itEth('Can perform burnFromCross()', async ({helper, privateKey}) => {265    const alice = privateKey('//Alice');266    const collection = await helper.rft.mintCollection(alice, {name: 'A', description: 'B', tokenPrefix: 'C'});267268    const owner = privateKey('//Bob');269    const spender = await helper.eth.createAccountWithBalance(alice, 100n);270271    const token = await collection.mintToken(alice, 100n, {Substrate: owner.address});272273    const address = helper.ethAddress.fromCollectionId(collection.collectionId);274    const contract = helper.ethNativeContract.collection(address, 'rft');275276    await token.repartition(owner, 15n);277    await token.approve(owner, {Ethereum: spender}, 15n);278279    {280      const ownerCross = helper.ethCrossAccount.fromKeyringPair(owner);281      const result = await contract.methods.burnFromCross(ownerCross, token.tokenId).send({from: spender});282      const event = result.events.Transfer;283      expect(event).to.be.like({284        address: helper.ethAddress.fromCollectionId(collection.collectionId),285        event: 'Transfer',286        returnValues: {287          from: helper.address.substrateToEth(owner.address),288          to: '0x0000000000000000000000000000000000000000',289          tokenId: token.tokenId.toString(),290        },291      });292    }293294    expect(await collection.getTokenBalance(token.tokenId, {Substrate: owner.address})).to.be.eq(0n);295  });296297  itEth('Can perform transferFromCross()', async ({helper, privateKey}) => {298    const collection = await helper.rft.mintCollection(donor, {name: 'A', description: 'B', tokenPrefix: 'C'});299300    const owner = privateKey('//Bob');301    const spender = await helper.eth.createAccountWithBalance(donor, 100n);302    const receiver = privateKey('//Charlie');303304    const token = await collection.mintToken(donor, 100n, {Substrate: owner.address});305306    const address = helper.ethAddress.fromCollectionId(collection.collectionId);307    const contract = helper.ethNativeContract.collection(address, 'rft');308309    await token.repartition(owner, 15n);310    await token.approve(owner, {Ethereum: spender}, 15n);311312    {313      const ownerCross = helper.ethCrossAccount.fromKeyringPair(owner);314      const recieverCross = helper.ethCrossAccount.fromKeyringPair(receiver);315      const result = await contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: spender});316      const event = result.events.Transfer;317      expect(event).to.be.like({318        address: helper.ethAddress.fromCollectionId(collection.collectionId),319        event: 'Transfer',320        returnValues: {321          from: helper.address.substrateToEth(owner.address),322          to: helper.address.substrateToEth(receiver.address),323          tokenId: token.tokenId.toString(),324        },325      });326    }327328    expect(await token.getTop10Owners()).to.be.like([{Substrate: receiver.address}]);329  });330331  itEth('Can perform transfer()', async ({helper}) => {332    const caller = await helper.eth.createAccountWithBalance(donor);333    const receiver = helper.eth.createAccount();334    const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'Transferry', '6', '6');335    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);336337    const result = await contract.methods.mint(caller).send();338    const tokenId = result.events.Transfer.returnValues.tokenId;339340    {341      const result = await contract.methods.transfer(receiver, tokenId).send();342343      const event = result.events.Transfer;344      expect(event.address).to.equal(collectionAddress);345      expect(event.returnValues.from).to.equal(caller);346      expect(event.returnValues.to).to.equal(receiver);347      expect(event.returnValues.tokenId).to.equal(tokenId.toString());348    }349350    {351      const balance = await contract.methods.balanceOf(caller).call();352      expect(+balance).to.equal(0);353    }354355    {356      const balance = await contract.methods.balanceOf(receiver).call();357      expect(+balance).to.equal(1);358    }359  });360361  itEth('transfer event on transfer from partial ownership to full ownership', async ({helper}) => {362    const caller = await helper.eth.createAccountWithBalance(donor);363    const receiver = helper.eth.createAccount();364    const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(caller, 'Transferry-Partial-to-Full', '6', '6');365    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);366367    const result = await contract.methods.mint(caller).send();368    const tokenId = result.events.Transfer.returnValues.tokenId;369370    const tokenContract = helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller);371372    await tokenContract.methods.repartition(2).send();373    await tokenContract.methods.transfer(receiver, 1).send();374375    const events: any = [];376    contract.events.allEvents((_: any, event: any) => {377      events.push(event);378    });379380    await tokenContract.methods.transfer(receiver, 1).send();381    if (events.length == 0) await helper.wait.newBlocks(1);382    const event = events[0];383384    expect(event.address).to.equal(collectionAddress);385    expect(event.returnValues.from).to.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');386    expect(event.returnValues.to).to.equal(receiver);387    expect(event.returnValues.tokenId).to.equal(tokenId.toString());388  });389390  itEth('transfer event on transfer from full ownership to partial ownership', async ({helper}) => {391    const caller = await helper.eth.createAccountWithBalance(donor);392    const receiver = helper.eth.createAccount();393    const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(caller, 'Transferry-Full-to-Partial', '6', '6');394    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);395396    const result = await contract.methods.mint(caller).send();397    const tokenId = result.events.Transfer.returnValues.tokenId;398399    const tokenContract = helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller);400401    await tokenContract.methods.repartition(2).send();402403    const events: any = [];404    contract.events.allEvents((_: any, event: any) => {405      events.push(event);406    });407408    await tokenContract.methods.transfer(receiver, 1).send();409    if (events.length == 0) await helper.wait.newBlocks(1);410    const event = events[0];411412    expect(event.address).to.equal(collectionAddress);413    expect(event.returnValues.from).to.equal(caller);414    expect(event.returnValues.to).to.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');415    expect(event.returnValues.tokenId).to.equal(tokenId.toString());416  });417});418419describe('RFT: Fees', () => {420  let donor: IKeyringPair;421422  before(async function() {423    await usingEthPlaygrounds(async (helper, privateKey) => {424      requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);425426      donor = await privateKey({filename: __filename});427    });428  });429430  itEth('transferFrom() call fee is less than 0.2UNQ', async ({helper}) => {431    const caller = await helper.eth.createAccountWithBalance(donor);432    const receiver = helper.eth.createAccount();433    const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'Feeful-Transfer-From', '6', '6');434    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);435436    const result = await contract.methods.mint(caller).send();437    const tokenId = result.events.Transfer.returnValues.tokenId;438439    const cost = await helper.eth.recordCallFee(caller, () => contract.methods.transferFrom(caller, receiver, tokenId).send());440    expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));441    expect(cost > 0n);442  });443444  itEth('transfer() call fee is less than 0.2UNQ', async ({helper}) => {445    const caller = await helper.eth.createAccountWithBalance(donor);446    const receiver = helper.eth.createAccount();447    const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'Feeful-Transfer', '6', '6');448    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);449450    const result = await contract.methods.mint(caller).send();451    const tokenId = result.events.Transfer.returnValues.tokenId;452453    const cost = await helper.eth.recordCallFee(caller, () => contract.methods.transfer(receiver, tokenId).send());454    expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));455    expect(cost > 0n);456  });457});458459describe('Common metadata', () => {460  let donor: IKeyringPair;461  let alice: IKeyringPair;462463  before(async function() {464    await usingEthPlaygrounds(async (helper, privateKey) => {465      requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);466467      donor = await privateKey({filename: __filename});468      [alice] = await helper.arrange.createAccounts([20n], donor);469    });470  });471472  itEth('Returns collection name', async ({helper}) => {473    const caller = helper.eth.createAccount();474    const tokenPropertyPermissions = [{475      key: 'URI',476      permission: {477        mutable: true,478        collectionAdmin: true,479        tokenOwner: false,480      },481    }];482    const collection = await helper.rft.mintCollection(483      alice,484      {485        name: 'Leviathan',486        tokenPrefix: '11',487        properties: [{key: 'ERC721Metadata', value: '1'}],488        tokenPropertyPermissions,489      },490    );491492    const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'rft', caller);493    const name = await contract.methods.name().call();494    expect(name).to.equal('Leviathan');495  });496497  itEth('Returns symbol name', async ({helper}) => {498    const caller = await helper.eth.createAccountWithBalance(donor);499    const tokenPropertyPermissions = [{500      key: 'URI',501      permission: {502        mutable: true,503        collectionAdmin: true,504        tokenOwner: false,505      },506    }];507    const {collectionId} = await helper.rft.mintCollection(508      alice,509      {510        name: 'Leviathan',511        tokenPrefix: '12',512        properties: [{key: 'ERC721Metadata', value: '1'}],513        tokenPropertyPermissions,514      },515    );516517    const contract = helper.ethNativeContract.collectionById(collectionId, 'rft', caller);518    const symbol = await contract.methods.symbol().call();519    expect(symbol).to.equal('12');520  });521});