difftreelog
feat add collection sponsoring for rft
in: master
4 files changed
runtime/common/config/pallets/app_promotion.rsdiffbeforeafterboth--- a/runtime/common/config/pallets/app_promotion.rs
+++ b/runtime/common/config/pallets/app_promotion.rs
@@ -22,7 +22,7 @@
use frame_support::{parameter_types, PalletId};
use sp_arithmetic::Perbill;
use up_common::{
- constants::{UNIQUE, RELAY_DAYS, DAYS},
+ constants::{UNIQUE, RELAY_DAYS},
types::Balance,
};
runtime/common/ethereum/sponsoring.rsdiffbeforeafterboth--- a/runtime/common/ethereum/sponsoring.rs
+++ b/runtime/common/ethereum/sponsoring.rs
@@ -32,14 +32,22 @@
Config as FungibleConfig,
erc::{UniqueFungibleCall, ERC20Call},
};
-use pallet_refungible::Config as RefungibleConfig;
+use pallet_refungible::{
+ Config as RefungibleConfig,
+ erc::UniqueRefungibleCall,
+ erc_token::{RefungibleTokenHandle, UniqueRefungibleTokenCall},
+ RefungibleHandle,
+};
use pallet_unique::Config as UniqueConfig;
use sp_std::prelude::*;
-use up_data_structs::{CollectionMode, CreateItemData, CreateNftData, TokenId};
+use up_data_structs::{
+ CollectionMode, CreateItemData, CreateNftData, mapping::TokenAddressMapping, TokenId,
+};
use up_sponsorship::SponsorshipHandler;
-
use crate::{Runtime, runtime_common::sponsoring::*};
+mod refungible;
+
pub type EvmSponsorshipHandler = (
UniqueEthSponsorshipHandler<Runtime>,
pallet_evm_contract_helpers::HelpersContractSponsoring<Runtime>,
@@ -53,80 +61,155 @@
who: &T::CrossAccountId,
call_context: &CallContext,
) -> Option<T::CrossAccountId> {
- let collection_id = map_eth_to_id(&call_context.contract_address)?;
- let collection = <CollectionHandle<T>>::new(collection_id)?;
- let sponsor = collection.sponsorship.sponsor()?.clone();
- let (method_id, mut reader) = AbiReader::new_call(&call_context.input).ok()?;
- Some(T::CrossAccountId::from_sub(match &collection.mode {
- CollectionMode::NFT => {
- let call = <UniqueNFTCall<T>>::parse(method_id, &mut reader).ok()??;
- match call {
- UniqueNFTCall::TokenProperties(TokenPropertiesCall::SetProperty {
- token_id,
- key,
- value,
- ..
- }) => {
- let token_id: TokenId = token_id.try_into().ok()?;
- withdraw_set_token_property::<T>(
+ if let Some(collection_id) = map_eth_to_id(&call_context.contract_address) {
+ let collection = <CollectionHandle<T>>::new(collection_id)?;
+ let sponsor = collection.sponsorship.sponsor()?.clone();
+ let (method_id, mut reader) = AbiReader::new_call(&call_context.input).ok()?;
+ Some(T::CrossAccountId::from_sub(match &collection.mode {
+ CollectionMode::NFT => {
+ let call = <UniqueNFTCall<T>>::parse(method_id, &mut reader).ok()??;
+ match call {
+ UniqueNFTCall::TokenProperties(TokenPropertiesCall::SetProperty {
+ token_id,
+ key,
+ value,
+ ..
+ }) => {
+ let token_id: TokenId = token_id.try_into().ok()?;
+ withdraw_set_token_property::<T>(
+ &collection,
+ &who,
+ &token_id,
+ key.len() + value.len(),
+ )
+ .map(|()| sponsor)
+ }
+ UniqueNFTCall::ERC721UniqueExtensions(
+ ERC721UniqueExtensionsCall::Transfer { token_id, .. },
+ ) => {
+ let token_id: TokenId = token_id.try_into().ok()?;
+ withdraw_transfer::<T>(&collection, &who, &token_id).map(|()| sponsor)
+ }
+ UniqueNFTCall::ERC721UniqueMintable(
+ ERC721UniqueMintableCall::Mint { .. }
+ | ERC721UniqueMintableCall::MintCheckId { .. }
+ | ERC721UniqueMintableCall::MintWithTokenUri { .. }
+ | ERC721UniqueMintableCall::MintWithTokenUriCheckId { .. },
+ ) => withdraw_create_item::<T>(
&collection,
&who,
- &token_id,
- key.len() + value.len(),
+ &CreateItemData::NFT(CreateNftData::default()),
)
- .map(|()| sponsor)
- }
- UniqueNFTCall::ERC721UniqueExtensions(
- ERC721UniqueExtensionsCall::Transfer { token_id, .. },
- ) => {
- let token_id: TokenId = token_id.try_into().ok()?;
- withdraw_transfer::<T>(&collection, &who, &token_id).map(|()| sponsor)
- }
- UniqueNFTCall::ERC721UniqueMintable(
- ERC721UniqueMintableCall::Mint { .. }
- | ERC721UniqueMintableCall::MintCheckId { .. }
- | ERC721UniqueMintableCall::MintWithTokenUri { .. }
- | ERC721UniqueMintableCall::MintWithTokenUriCheckId { .. },
- ) => withdraw_create_item::<T>(
- &collection,
- &who,
- &CreateItemData::NFT(CreateNftData::default()),
- )
- .map(|()| sponsor),
- UniqueNFTCall::ERC721(ERC721Call::TransferFrom { token_id, from, .. }) => {
- let token_id: TokenId = token_id.try_into().ok()?;
- let from = T::CrossAccountId::from_eth(from);
- withdraw_transfer::<T>(&collection, &from, &token_id).map(|()| sponsor)
- }
- UniqueNFTCall::ERC721(ERC721Call::Approve { token_id, .. }) => {
- let token_id: TokenId = token_id.try_into().ok()?;
- withdraw_approve::<T>(&collection, who.as_sub(), &token_id)
- .map(|()| sponsor)
+ .map(|()| sponsor),
+ UniqueNFTCall::ERC721(ERC721Call::TransferFrom {
+ token_id, from, ..
+ }) => {
+ let token_id: TokenId = token_id.try_into().ok()?;
+ let from = T::CrossAccountId::from_eth(from);
+ withdraw_transfer::<T>(&collection, &from, &token_id).map(|()| sponsor)
+ }
+ UniqueNFTCall::ERC721(ERC721Call::Approve { token_id, .. }) => {
+ let token_id: TokenId = token_id.try_into().ok()?;
+ withdraw_approve::<T>(&collection, who.as_sub(), &token_id)
+ .map(|()| sponsor)
+ }
+ _ => None,
}
- _ => None,
}
- }
- CollectionMode::Fungible(_) => {
- let call = <UniqueFungibleCall<T>>::parse(method_id, &mut reader).ok()??;
- #[allow(clippy::single_match)]
- match call {
- UniqueFungibleCall::ERC20(ERC20Call::Transfer { .. }) => {
- withdraw_transfer::<T>(&collection, who, &TokenId::default())
- .map(|()| sponsor)
- }
- UniqueFungibleCall::ERC20(ERC20Call::TransferFrom { from, .. }) => {
- let from = T::CrossAccountId::from_eth(from);
- withdraw_transfer::<T>(&collection, &from, &TokenId::default())
- .map(|()| sponsor)
- }
- UniqueFungibleCall::ERC20(ERC20Call::Approve { .. }) => {
- withdraw_approve::<T>(&collection, who.as_sub(), &TokenId::default())
- .map(|()| sponsor)
+ CollectionMode::ReFungible => {
+ let call = <UniqueRefungibleCall<T>>::parse(method_id, &mut reader).ok()??;
+ refungible::call_sponsor(call, collection, who).map(|()| sponsor)
+ }
+ CollectionMode::Fungible(_) => {
+ let call = <UniqueFungibleCall<T>>::parse(method_id, &mut reader).ok()??;
+ match call {
+ UniqueFungibleCall::ERC20(ERC20Call::Transfer { .. }) => {
+ withdraw_transfer::<T>(&collection, who, &TokenId::default())
+ .map(|()| sponsor)
+ }
+ UniqueFungibleCall::ERC20(ERC20Call::TransferFrom { from, .. }) => {
+ let from = T::CrossAccountId::from_eth(from);
+ withdraw_transfer::<T>(&collection, &from, &TokenId::default())
+ .map(|()| sponsor)
+ }
+ UniqueFungibleCall::ERC20(ERC20Call::Approve { .. }) => {
+ withdraw_approve::<T>(&collection, who.as_sub(), &TokenId::default())
+ .map(|()| sponsor)
+ }
+ _ => None,
}
- _ => None,
}
- }
- _ => None,
- }?))
+ }?))
+ } else {
+ let (collection_id, token_id) =
+ T::EvmTokenAddressMapping::address_to_token(&call_context.contract_address)?;
+ let collection = <CollectionHandle<T>>::new(collection_id)?;
+ let sponsor = collection.sponsorship.sponsor()?.clone();
+ let rft_collection = RefungibleHandle::cast(collection);
+ let token = RefungibleTokenHandle(rft_collection, token_id);
+ let (method_id, mut reader) = AbiReader::new_call(&call_context.input).ok()?;
+ let call = <UniqueRefungibleTokenCall<T>>::parse(method_id, &mut reader).ok()??;
+ Some(T::CrossAccountId::from_sub(
+ refungible::token_call_sponsor(call, token, who).map(|()| sponsor)?,
+ ))
+ }
+ }
+}
+
+mod common {
+ use super::*;
+
+ use pallet_common::erc::{CollectionCall};
+
+ pub fn collection_call_sponsor<T>(
+ call: CollectionCall<T>,
+ _collection: CollectionHandle<T>,
+ _who: &T::CrossAccountId,
+ ) -> Option<()>
+ where
+ T: UniqueConfig + FungibleConfig + NonfungibleConfig + RefungibleConfig,
+ {
+ use CollectionCall::*;
+
+ match call {
+ // Readonly
+ ERC165Call(_, _)
+ | CollectionProperty { .. }
+ | CollectionProperties { .. }
+ | HasCollectionPendingSponsor
+ | CollectionSponsor
+ | ContractAddress
+ | AllowlistedCross { .. }
+ | IsOwnerOrAdminEth { .. }
+ | IsOwnerOrAdminCross { .. }
+ | CollectionOwner
+ | CollectionAdmins
+ | UniqueCollectionType => None,
+
+ // Not sponsored
+ AddToCollectionAllowList { .. }
+ | AddToCollectionAllowListCross { .. }
+ | RemoveFromCollectionAllowList { .. }
+ | RemoveFromCollectionAllowListCross { .. }
+ | AddCollectionAdminCross { .. }
+ | RemoveCollectionAdminCross { .. }
+ | AddCollectionAdmin { .. }
+ | RemoveCollectionAdmin { .. }
+ | SetNestingBool { .. }
+ | SetNesting { .. }
+ | SetCollectionAccess { .. }
+ | SetCollectionMintMode { .. }
+ | SetOwner { .. }
+ | ChangeCollectionOwnerCross { .. }
+ | SetCollectionProperty { .. }
+ | SetCollectionProperties { .. }
+ | DeleteCollectionProperty { .. }
+ | DeleteCollectionProperties { .. }
+ | SetCollectionSponsor { .. }
+ | SetCollectionSponsorCross { .. }
+ | ConfirmCollectionSponsorship
+ | RemoveCollectionSponsor
+ | SetIntLimit { .. } => None,
+ }
}
}
runtime/common/ethereum/sponsoring/refungible.rsdiffbeforeafterboth1// 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/>.1617//! Implements EVM sponsoring logic via TransactionValidityHack1819use core::convert::TryInto;20use pallet_common::CollectionHandle;21use pallet_evm::account::CrossAccountId;22use pallet_fungible::Config as FungibleConfig;23use pallet_refungible::Config as RefungibleConfig;24use pallet_nonfungible::Config as NonfungibleConfig;25use pallet_unique::Config as UniqueConfig;26use up_data_structs::{CreateItemData, CreateNftData, TokenId};2728use super::common;29use crate::runtime_common::sponsoring::*;3031use pallet_refungible::{32 erc::{33 ERC721BurnableCall, ERC721Call, ERC721EnumerableCall, ERC721MetadataCall,34 ERC721UniqueExtensionsCall, ERC721UniqueMintableCall, TokenPropertiesCall,35 UniqueRefungibleCall,36 },37 erc_token::{38 ERC1633Call, ERC20Call, ERC20UniqueExtensionsCall, RefungibleTokenHandle,39 UniqueRefungibleTokenCall,40 },41};4243pub fn call_sponsor<T>(44 call: UniqueRefungibleCall<T>,45 collection: CollectionHandle<T>,46 who: &T::CrossAccountId,47) -> Option<()>48where49 T: UniqueConfig + FungibleConfig + NonfungibleConfig + RefungibleConfig,50{51 use UniqueRefungibleCall::*;5253 match call {54 // Readonly55 ERC165Call(_, _) => None,5657 ERC721Enumerable(call) => erc721::enumerable_call_sponsor(call, collection, who),58 ERC721Burnable(call) => erc721::burnable_call_sponsor(call, collection, who),59 ERC721Metadata(call) => erc721::metadata_call_sponsor(call, collection, who),60 Collection(call) => common::collection_call_sponsor(call, collection, who),61 ERC721(call) => erc721::call_sponsor(call, collection, who),62 ERC721UniqueExtensions(call) => {63 erc721::unique_extensions_call_sponsor(call, collection, who)64 }65 ERC721UniqueMintable(call) => erc721::unique_mintable_call_sponsor(call, collection, who),66 TokenProperties(call) => token_properties_call_sponsor(call, collection, who),67 }68}6970pub fn token_properties_call_sponsor<T>(71 call: TokenPropertiesCall<T>,72 collection: CollectionHandle<T>,73 who: &T::CrossAccountId,74) -> Option<()>75where76 T: UniqueConfig + FungibleConfig + NonfungibleConfig + RefungibleConfig,77{78 use TokenPropertiesCall::*;7980 match call {81 // Readonly82 ERC165Call(_, _) | Property { .. } => None,8384 // Not sponsored85 SetTokenPropertyPermission { .. }86 | SetProperties { .. }87 | DeleteProperty { .. }88 | DeleteProperties { .. } => None,8990 SetProperty {91 token_id,92 key,93 value,94 ..95 } => {96 let token_id: TokenId = token_id.try_into().ok()?;97 withdraw_set_token_property::<T>(&collection, &who, &token_id, key.len() + value.len())98 }99 }100}101102pub fn token_call_sponsor<T>(103 call: UniqueRefungibleTokenCall<T>,104 token: RefungibleTokenHandle<T>,105 who: &T::CrossAccountId,106) -> Option<()>107where108 T: UniqueConfig + FungibleConfig + NonfungibleConfig + RefungibleConfig,109{110 use UniqueRefungibleTokenCall::*;111112 match call {113 // Readonly114 ERC165Call(_, _) => None,115116 ERC20(call) => erc20::call_sponsor(call, token, who),117 ERC20UniqueExtensions(call) => erc20::unique_extensions_call_sponsor(call, token, who),118 ERC1633(call) => erc1633::call_sponsor(call, token, who),119 }120}121122mod erc721 {123 use super::*;124125 pub fn call_sponsor<T>(126 call: ERC721Call<T>,127 collection: CollectionHandle<T>,128 who: &T::CrossAccountId,129 ) -> Option<()>130 where131 T: UniqueConfig + FungibleConfig + NonfungibleConfig + RefungibleConfig,132 {133 use ERC721Call::*;134135 match call {136 // Readonly137 ERC165Call(_, _)138 | BalanceOf { .. }139 | OwnerOf { .. }140 | GetApproved { .. }141 | IsApprovedForAll { .. }142 | CollectionHelperAddress => None,143144 // Not sponsored145 SafeTransferFromWithData { .. }146 | SafeTransferFrom { .. }147 | SetApprovalForAll { .. } => None,148149 TransferFrom { token_id, from, .. } => {150 let token_id: TokenId = token_id.try_into().ok()?;151 let from = T::CrossAccountId::from_eth(from);152 withdraw_transfer::<T>(&collection, &from, &token_id)153 }154 Approve { _token_id, .. } => {155 let token_id: TokenId = _token_id.try_into().ok()?;156 withdraw_approve::<T>(&collection, who.as_sub(), &token_id)157 }158 }159 }160161 pub fn enumerable_call_sponsor<T>(162 call: ERC721EnumerableCall<T>,163 _collection: CollectionHandle<T>,164 _who: &T::CrossAccountId,165 ) -> Option<()>166 where167 T: UniqueConfig + FungibleConfig + NonfungibleConfig + RefungibleConfig,168 {169 use ERC721EnumerableCall::*;170171 match call {172 // Readonly173 ERC165Call(_, _) | TokenByIndex { .. } | TokenOfOwnerByIndex { .. } | TotalSupply => {174 None175 }176 }177 }178179 pub fn burnable_call_sponsor<T>(180 call: ERC721BurnableCall<T>,181 _collection: CollectionHandle<T>,182 _who: &T::CrossAccountId,183 ) -> Option<()>184 where185 T: UniqueConfig + FungibleConfig + NonfungibleConfig + RefungibleConfig,186 {187 use ERC721BurnableCall::*;188189 match call {190 // Readonly191 ERC165Call(_, _) => None,192193 // Not sponsored194 Burn { .. } => None,195 }196 }197198 pub fn metadata_call_sponsor<T>(199 call: ERC721MetadataCall<T>,200 _collection: CollectionHandle<T>,201 _who: &T::CrossAccountId,202 ) -> Option<()>203 where204 T: UniqueConfig + FungibleConfig + NonfungibleConfig + RefungibleConfig,205 {206 use ERC721MetadataCall::*;207208 match call {209 // Readonly210 ERC165Call(_, _) | NameProxy | SymbolProxy | TokenUri { .. } => None,211 }212 }213214 pub fn unique_extensions_call_sponsor<T>(215 call: ERC721UniqueExtensionsCall<T>,216 collection: CollectionHandle<T>,217 who: &T::CrossAccountId,218 ) -> Option<()>219 where220 T: UniqueConfig + FungibleConfig + NonfungibleConfig + RefungibleConfig,221 {222 use ERC721UniqueExtensionsCall::*;223224 match call {225 // Readonly226 ERC165Call(_, _)227 | Name228 | Symbol229 | Description230 | CrossOwnerOf { .. }231 | Properties { .. }232 | NextTokenId233 | TokenContractAddress { .. } => None,234235 // Not sponsored236 TransferCross { .. }237 | TransferFromCross { .. }238 | BurnFrom { .. }239 | BurnFromCross { .. }240 | MintBulk { .. }241 | MintBulkWithTokenUri { .. } => None,242243 Transfer { token_id, .. } => {244 let token_id: TokenId = token_id.try_into().ok()?;245 withdraw_transfer::<T>(&collection, &who, &token_id)246 }247 }248 }249250 pub fn unique_mintable_call_sponsor<T>(251 call: ERC721UniqueMintableCall<T>,252 collection: CollectionHandle<T>,253 who: &T::CrossAccountId,254 ) -> Option<()>255 where256 T: UniqueConfig + FungibleConfig + NonfungibleConfig + RefungibleConfig,257 {258 use ERC721UniqueMintableCall::*;259260 match call {261 // Readonly262 ERC165Call(_, _) | MintingFinished => None,263264 // Not sponsored265 FinishMinting => None,266267 Mint { .. }268 | MintCheckId { .. }269 | MintWithTokenUri { .. }270 | MintWithTokenUriCheckId { .. } => withdraw_create_item::<T>(271 &collection,272 &who,273 &CreateItemData::NFT(CreateNftData::default()),274 ),275 }276 }277}278279mod erc20 {280 use super::*;281282 pub fn call_sponsor<T>(283 call: ERC20Call<T>,284 token: RefungibleTokenHandle<T>,285 who: &T::CrossAccountId,286 ) -> Option<()>287 where288 T: UniqueConfig + FungibleConfig + NonfungibleConfig + RefungibleConfig,289 {290 use ERC20Call::*;291292 match call {293 // Readonly294 ERC165Call(_, _)295 | Name296 | Symbol297 | TotalSupply298 | Decimals299 | BalanceOf { .. }300 | Allowance { .. } => None,301302 Transfer { .. } => {303 let RefungibleTokenHandle(handle, token_id) = token;304 let token_id = token_id.try_into().ok()?;305 withdraw_transfer::<T>(&handle, &who, &token_id)306 }307 TransferFrom { from, .. } => {308 let RefungibleTokenHandle(handle, token_id) = token;309 let token_id = token_id.try_into().ok()?;310 let from = T::CrossAccountId::from_eth(from);311 withdraw_transfer::<T>(&handle, &from, &token_id)312 }313 Approve { .. } => {314 let RefungibleTokenHandle(handle, token_id) = token;315 let token_id = token_id.try_into().ok()?;316 withdraw_approve::<T>(&handle, who.as_sub(), &token_id)317 }318 }319 }320321 pub fn unique_extensions_call_sponsor<T>(322 call: ERC20UniqueExtensionsCall<T>,323 _token: RefungibleTokenHandle<T>,324 _who: &T::CrossAccountId,325 ) -> Option<()>326 where327 T: UniqueConfig + FungibleConfig + NonfungibleConfig + RefungibleConfig,328 {329 use ERC20UniqueExtensionsCall::*;330331 match call {332 // Readonly333 ERC165Call(_, _) => None,334335 // Not sponsored336 BurnFrom { .. } | Repartition { .. } => None,337 }338 }339}340341mod erc1633 {342 use super::*;343344 pub fn call_sponsor<T>(345 call: ERC1633Call<T>,346 _token: RefungibleTokenHandle<T>,347 _who: &T::CrossAccountId,348 ) -> Option<()>349 where350 T: UniqueConfig + FungibleConfig + NonfungibleConfig + RefungibleConfig,351 {352 use ERC1633Call::*;353354 match call {355 // Readonly356 ERC165Call(_, _) | ParentToken | ParentTokenId => None,357 }358 }359}tests/src/eth/collectionSponsoring.test.tsdiffbeforeafterboth--- a/tests/src/eth/collectionSponsoring.test.ts
+++ b/tests/src/eth/collectionSponsoring.test.ts
@@ -15,10 +15,10 @@
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
import {IKeyringPair} from '@polkadot/types/types';
-import {usingPlaygrounds} from '../util/index';
+import {Pallets, requirePalletsOrSkip, usingPlaygrounds} from '../util/index';
import {itEth, expect} from './util';
-describe('evm collection sponsoring', () => {
+describe('evm nft collection sponsoring', () => {
let donor: IKeyringPair;
let alice: IKeyringPair;
let nominal: bigint;
@@ -317,3 +317,529 @@
expect(collectionSponsor).to.deep.eq({Unconfirmed: sponsorSub.address});
});
});
+
+describe('evm RFT collection sponsoring', () => {
+ let donor: IKeyringPair;
+ let alice: IKeyringPair;
+ let nominal: bigint;
+
+ before(async function() {
+ await usingPlaygrounds(async (helper, privateKey) => {
+ requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
+ donor = await privateKey({filename: __filename});
+ [alice] = await helper.arrange.createAccounts([100n], donor);
+ nominal = helper.balance.getOneTokenNominal();
+ });
+ });
+
+ itEth('sponsors mint transactions', async ({helper}) => {
+ const collection = await helper.rft.mintCollection(alice, {tokenPrefix: 'spnr', permissions: {mintMode: true}});
+ await collection.setSponsor(alice, alice.address);
+ await collection.confirmSponsorship(alice);
+
+ const minter = helper.eth.createAccount();
+ expect(await helper.balance.getEthereum(minter)).to.equal(0n);
+
+ const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
+ const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', minter);
+
+ await collection.addToAllowList(alice, {Ethereum: minter});
+
+ const result = await contract.methods.mint(minter).send();
+
+ const events = helper.eth.normalizeEvents(result.events);
+ expect(events).to.deep.include({
+ address: collectionAddress,
+ event: 'Transfer',
+ args: {
+ from: '0x0000000000000000000000000000000000000000',
+ to: minter,
+ tokenId: '1',
+ },
+ });
+ });
+
+ // TODO: Temprorary off. Need refactor
+ // itWeb3('Set substrate sponsor', async ({api, web3, privateKeyWrapper}) => {
+ // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
+ // const collectionHelpers = evmCollectionHelpers(web3, owner);
+ // let result = await collectionHelpers.methods.createRFTCollection('Sponsor collection', '1', '1').send();
+ // const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
+ // const sponsor = privateKeyWrapper('//Alice');
+ // const collectionEvm = evmCollection(web3, owner, collectionIdAddress);
+
+ // expect(await collectionEvm.methods.hasCollectionPendingSponsor().call({from: owner})).to.be.false;
+ // result = await collectionEvm.methods.setCollectionSponsorSubstrate(sponsor.addressRaw).send({from: owner});
+ // expect(await collectionEvm.methods.hasCollectionPendingSponsor().call({from: owner})).to.be.true;
+
+ // const confirmTx = await api.tx.unique.confirmSponsorship(collectionId);
+ // await submitTransactionAsync(sponsor, confirmTx);
+ // expect(await collectionEvm.methods.hasCollectionPendingSponsor().call({from: owner})).to.be.false;
+
+ // const sponsorTuple = await collectionEvm.methods.collectionSponsor().call({from: owner});
+ // expect(bigIntToSub(api, BigInt(sponsorTuple[1]))).to.be.eq(sponsor.address);
+ // });
+
+ // Soft-deprecated
+ itEth('[eth] Remove sponsor', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const collectionHelpers = helper.ethNativeContract.collectionHelpers(owner);
+
+ let result = await collectionHelpers.methods.createRFTCollection('Sponsor collection', '1', '1').send({value: Number(2n * nominal)});
+ const collectionIdAddress = helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);
+ const sponsor = await helper.eth.createAccountWithBalance(donor);
+ const collectionEvm = helper.ethNativeContract.collection(collectionIdAddress, 'rft', owner, true);
+
+ expect(await collectionEvm.methods.hasCollectionPendingSponsor().call({from: owner})).to.be.false;
+ result = await collectionEvm.methods.setCollectionSponsor(sponsor).send({from: owner});
+ expect(await collectionEvm.methods.hasCollectionPendingSponsor().call({from: owner})).to.be.true;
+
+ await collectionEvm.methods.confirmCollectionSponsorship().send({from: sponsor});
+ expect(await collectionEvm.methods.hasCollectionPendingSponsor().call({from: owner})).to.be.false;
+
+ await collectionEvm.methods.removeCollectionSponsor().send({from: owner});
+
+ const sponsorTuple = await collectionEvm.methods.collectionSponsor().call({from: owner});
+ expect(sponsorTuple.field_0).to.be.eq('0x0000000000000000000000000000000000000000');
+ });
+
+ itEth('[cross] Remove sponsor', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const collectionHelpers = helper.ethNativeContract.collectionHelpers(owner);
+
+ let result = await collectionHelpers.methods.createRFTCollection('Sponsor collection', '1', '1').send({value: Number(2n * nominal)});
+ const collectionIdAddress = helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);
+ const sponsor = await helper.eth.createAccountWithBalance(donor);
+ const sponsorCross = helper.ethCrossAccount.fromAddress(sponsor);
+ const collectionEvm = helper.ethNativeContract.collection(collectionIdAddress, 'rft', owner);
+
+ expect(await collectionEvm.methods.hasCollectionPendingSponsor().call({from: owner})).to.be.false;
+ result = await collectionEvm.methods.setCollectionSponsorCross(sponsorCross).send({from: owner});
+ expect(await collectionEvm.methods.hasCollectionPendingSponsor().call({from: owner})).to.be.true;
+
+ await collectionEvm.methods.confirmCollectionSponsorship().send({from: sponsor});
+ expect(await collectionEvm.methods.hasCollectionPendingSponsor().call({from: owner})).to.be.false;
+
+ await collectionEvm.methods.removeCollectionSponsor().send({from: owner});
+
+ const sponsorTuple = await collectionEvm.methods.collectionSponsor().call({from: owner});
+ expect(sponsorTuple.field_0).to.be.eq('0x0000000000000000000000000000000000000000');
+ });
+
+ // Soft-deprecated
+ itEth('[eth] Sponsoring collection from evm address via access list', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+
+ const {collectionId, collectionAddress} = await helper.eth.createERC721MetadataCompatibleRFTCollection(owner, 'Sponsor collection', '1', '1', '');
+
+ const collection = helper.rft.getCollectionObject(collectionId);
+ const sponsor = await helper.eth.createAccountWithBalance(donor);
+ const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'rft', owner, true);
+
+ await collectionEvm.methods.setCollectionSponsor(sponsor).send({from: owner});
+ let collectionData = (await collection.getData())!;
+ expect(collectionData.raw.sponsorship.Unconfirmed).to.be.eq(helper.address.ethToSubstrate(sponsor, true));
+ await expect(collectionEvm.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('caller is not set as sponsor');
+
+ await collectionEvm.methods.confirmCollectionSponsorship().send({from: sponsor});
+ collectionData = (await collection.getData())!;
+ expect(collectionData.raw.sponsorship.Confirmed).to.be.eq(helper.address.ethToSubstrate(sponsor, true));
+
+ const user = helper.eth.createAccount();
+ const nextTokenId = await collectionEvm.methods.nextTokenId().call();
+ expect(nextTokenId).to.be.equal('1');
+
+ const oldPermissions = (await collection.getData())!.raw.permissions; // (await getDetailedCollectionInfo(api, collectionId))!.permissions.toHuman();
+ expect(oldPermissions.mintMode).to.be.false;
+ expect(oldPermissions.access).to.be.equal('Normal');
+
+ await collectionEvm.methods.setCollectionAccess(1 /*'AllowList'*/).send({from: owner});
+ await collectionEvm.methods.addToCollectionAllowList(user).send({from: owner});
+ await collectionEvm.methods.setCollectionMintMode(true).send({from: owner});
+
+ const newPermissions = (await collection.getData())!.raw.permissions; // (await getDetailedCollectionInfo(api, collectionId))!.permissions.toHuman();
+ expect(newPermissions.mintMode).to.be.true;
+ expect(newPermissions.access).to.be.equal('AllowList');
+
+ const ownerBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(owner));
+ const sponsorBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(sponsor));
+
+ {
+ const result = await collectionEvm.methods.mintWithTokenURI(user, 'Test URI').send({from: user});
+ const events = helper.eth.normalizeEvents(result.events);
+
+ expect(events).to.deep.include({
+ address: collectionAddress,
+ event: 'Transfer',
+ args: {
+ from: '0x0000000000000000000000000000000000000000',
+ to: user,
+ tokenId: '1',
+ },
+ });
+
+ const ownerBalanceAfter = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(owner));
+ const sponsorBalanceAfter = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(sponsor));
+
+ expect(await collectionEvm.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');
+ expect(ownerBalanceBefore).to.be.eq(ownerBalanceAfter);
+ expect(sponsorBalanceBefore > sponsorBalanceAfter).to.be.true;
+ }
+ });
+
+ itEth('[cross] Sponsoring collection from evm address via access list', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+
+ const {collectionId, collectionAddress} = await helper.eth.createERC721MetadataCompatibleRFTCollection(owner, 'Sponsor collection', '1', '1', '');
+
+ const collection = helper.rft.getCollectionObject(collectionId);
+ const sponsor = await helper.eth.createAccountWithBalance(donor);
+ const sponsorCross = helper.ethCrossAccount.fromAddress(sponsor);
+ const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);
+
+ await collectionEvm.methods.setCollectionSponsorCross(sponsorCross).send({from: owner});
+ let collectionData = (await collection.getData())!;
+ expect(collectionData.raw.sponsorship.Unconfirmed).to.be.eq(helper.address.ethToSubstrate(sponsor, true));
+ await expect(collectionEvm.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('caller is not set as sponsor');
+
+ await collectionEvm.methods.confirmCollectionSponsorship().send({from: sponsor});
+ collectionData = (await collection.getData())!;
+ expect(collectionData.raw.sponsorship.Confirmed).to.be.eq(helper.address.ethToSubstrate(sponsor, true));
+
+ const user = helper.eth.createAccount();
+ const userCross = helper.ethCrossAccount.fromAddress(user);
+ const nextTokenId = await collectionEvm.methods.nextTokenId().call();
+ expect(nextTokenId).to.be.equal('1');
+
+ const oldPermissions = (await collection.getData())!.raw.permissions; // (await getDetailedCollectionInfo(api, collectionId))!.permissions.toHuman();
+ expect(oldPermissions.mintMode).to.be.false;
+ expect(oldPermissions.access).to.be.equal('Normal');
+
+ await collectionEvm.methods.setCollectionAccess(1 /*'AllowList'*/).send({from: owner});
+ await collectionEvm.methods.addToCollectionAllowListCross(userCross).send({from: owner});
+ await collectionEvm.methods.setCollectionMintMode(true).send({from: owner});
+
+ const newPermissions = (await collection.getData())!.raw.permissions; // (await getDetailedCollectionInfo(api, collectionId))!.permissions.toHuman();
+ expect(newPermissions.mintMode).to.be.true;
+ expect(newPermissions.access).to.be.equal('AllowList');
+
+ const ownerBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(owner));
+ const sponsorBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(sponsor));
+
+ {
+ const result = await collectionEvm.methods.mintWithTokenURI(user, 'Test URI').send({from: user});
+ const events = helper.eth.normalizeEvents(result.events);
+
+ expect(events).to.deep.include({
+ address: collectionAddress,
+ event: 'Transfer',
+ args: {
+ from: '0x0000000000000000000000000000000000000000',
+ to: user,
+ tokenId: '1',
+ },
+ });
+
+ const ownerBalanceAfter = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(owner));
+ const sponsorBalanceAfter = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(sponsor));
+
+ expect(await collectionEvm.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');
+ expect(ownerBalanceBefore).to.be.eq(ownerBalanceAfter);
+ expect(sponsorBalanceBefore > sponsorBalanceAfter).to.be.true;
+ }
+ });
+
+ // TODO: Temprorary off. Need refactor
+ // itWeb3('Sponsoring collection from substrate address via access list', async ({api, web3, privateKeyWrapper}) => {
+ // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
+ // const collectionHelpers = evmCollectionHelpers(web3, owner);
+ // const result = await collectionHelpers.methods.createERC721MetadataCompatibleRFTCollection('Sponsor collection', '1', '1', '').send();
+ // const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
+ // const sponsor = privateKeyWrapper('//Alice');
+ // const collectionEvm = evmCollection(web3, owner, collectionIdAddress);
+
+ // await collectionEvm.methods.setCollectionSponsorSubstrate(sponsor.addressRaw).send({from: owner});
+
+ // const confirmTx = await api.tx.unique.confirmSponsorship(collectionId);
+ // await submitTransactionAsync(sponsor, confirmTx);
+
+ // const user = createEthAccount(web3);
+ // const nextTokenId = await collectionEvm.methods.nextTokenId().call();
+ // expect(nextTokenId).to.be.equal('1');
+
+ // await collectionEvm.methods.setCollectionAccess(1 /*'AllowList'*/).send({from: owner});
+ // await collectionEvm.methods.addToCollectionAllowList(user).send({from: owner});
+ // await collectionEvm.methods.setCollectionMintMode(true).send({from: owner});
+
+ // const ownerBalanceBefore = await ethBalanceViaSub(api, owner);
+ // const sponsorBalanceBefore = (await getBalance(api, [sponsor.address]))[0];
+
+ // {
+ // const nextTokenId = await collectionEvm.methods.nextTokenId().call();
+ // expect(nextTokenId).to.be.equal('1');
+ // const result = await collectionEvm.methods.mintWithTokenURI(
+ // user,
+ // nextTokenId,
+ // 'Test URI',
+ // ).send({from: user});
+ // const events = normalizeEvents(result.events);
+
+ // expect(events).to.be.deep.equal([
+ // {
+ // address: collectionIdAddress,
+ // event: 'Transfer',
+ // args: {
+ // from: '0x0000000000000000000000000000000000000000',
+ // to: user,
+ // tokenId: nextTokenId,
+ // },
+ // },
+ // ]);
+
+ // const ownerBalanceAfter = await ethBalanceViaSub(api, owner);
+ // const sponsorBalanceAfter = (await getBalance(api, [sponsor.address]))[0];
+
+ // expect(await collectionEvm.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');
+ // expect(ownerBalanceBefore).to.be.eq(ownerBalanceAfter);
+ // expect(sponsorBalanceBefore > sponsorBalanceAfter).to.be.true;
+ // }
+ // });
+
+ // Soft-deprecated
+ itEth('[eth] Check that transaction via EVM spend money from sponsor address', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+
+ const {collectionAddress, collectionId} = await helper.eth.createERC721MetadataCompatibleRFTCollection(owner,'Sponsor collection', '1', '1', '');
+ const collection = helper.rft.getCollectionObject(collectionId);
+ const sponsor = await helper.eth.createAccountWithBalance(donor);
+ const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'rft', owner, true);
+
+ await collectionEvm.methods.setCollectionSponsor(sponsor).send();
+ let collectionData = (await collection.getData())!;
+ expect(collectionData.raw.sponsorship.Unconfirmed).to.be.eq(helper.address.ethToSubstrate(sponsor, true));
+ await expect(collectionEvm.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('caller is not set as sponsor');
+
+ const sponsorCollection = helper.ethNativeContract.collection(collectionAddress, 'rft', sponsor, true);
+ await sponsorCollection.methods.confirmCollectionSponsorship().send();
+ collectionData = (await collection.getData())!;
+ expect(collectionData.raw.sponsorship.Confirmed).to.be.eq(helper.address.ethToSubstrate(sponsor, true));
+
+ const user = helper.eth.createAccount();
+ await collectionEvm.methods.addCollectionAdmin(user).send();
+
+ const ownerBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(owner));
+ const sponsorBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(sponsor));
+
+ const userCollectionEvm = helper.ethNativeContract.collection(collectionAddress, 'rft', user, true);
+
+ const result = await userCollectionEvm.methods.mintWithTokenURI(user, 'Test URI').send();
+ const tokenId = result.events.Transfer.returnValues.tokenId;
+
+ const events = helper.eth.normalizeEvents(result.events);
+ const address = helper.ethAddress.fromCollectionId(collectionId);
+
+ expect(events).to.deep.include({
+ address,
+ event: 'Transfer',
+ args: {
+ from: '0x0000000000000000000000000000000000000000',
+ to: user,
+ tokenId: '1',
+ },
+ });
+ expect(await userCollectionEvm.methods.tokenURI(tokenId).call()).to.be.equal('Test URI');
+
+ const ownerBalanceAfter = await helper.balance.getSubstrate(helper.address.ethToSubstrate(owner));
+ expect(ownerBalanceAfter).to.be.eq(ownerBalanceBefore);
+ const sponsorBalanceAfter = await helper.balance.getSubstrate(helper.address.ethToSubstrate(sponsor));
+ expect(sponsorBalanceAfter < sponsorBalanceBefore).to.be.true;
+ });
+
+ itEth('[cross] Check that transaction via EVM spend money from sponsor address', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+
+ const {collectionAddress, collectionId} = await helper.eth.createERC721MetadataCompatibleRFTCollection(owner,'Sponsor collection', '1', '1', '');
+ const collection = helper.rft.getCollectionObject(collectionId);
+ const sponsor = await helper.eth.createAccountWithBalance(donor);
+ const sponsorCross = helper.ethCrossAccount.fromAddress(sponsor);
+ const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);
+
+ await collectionEvm.methods.setCollectionSponsorCross(sponsorCross).send();
+ let collectionData = (await collection.getData())!;
+ expect(collectionData.raw.sponsorship.Unconfirmed).to.be.eq(helper.address.ethToSubstrate(sponsor, true));
+ await expect(collectionEvm.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('caller is not set as sponsor');
+
+ const sponsorCollection = helper.ethNativeContract.collection(collectionAddress, 'rft', sponsor);
+ await sponsorCollection.methods.confirmCollectionSponsorship().send();
+ collectionData = (await collection.getData())!;
+ expect(collectionData.raw.sponsorship.Confirmed).to.be.eq(helper.address.ethToSubstrate(sponsor, true));
+
+ const user = helper.eth.createAccount();
+ const userCross = helper.ethCrossAccount.fromAddress(user);
+ await collectionEvm.methods.addCollectionAdminCross(userCross).send();
+
+ const ownerBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(owner));
+ const sponsorBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(sponsor));
+
+ const userCollectionEvm = helper.ethNativeContract.collection(collectionAddress, 'rft', user);
+
+ const result = await userCollectionEvm.methods.mintWithTokenURI(user, 'Test URI').send();
+ const tokenId = result.events.Transfer.returnValues.tokenId;
+
+ const events = helper.eth.normalizeEvents(result.events);
+ const address = helper.ethAddress.fromCollectionId(collectionId);
+
+ expect(events).to.deep.include({
+ address,
+ event: 'Transfer',
+ args: {
+ from: '0x0000000000000000000000000000000000000000',
+ to: user,
+ tokenId: '1',
+ },
+ });
+ expect(await userCollectionEvm.methods.tokenURI(tokenId).call()).to.be.equal('Test URI');
+
+ const ownerBalanceAfter = await helper.balance.getSubstrate(helper.address.ethToSubstrate(owner));
+ expect(ownerBalanceAfter).to.be.eq(ownerBalanceBefore);
+ const sponsorBalanceAfter = await helper.balance.getSubstrate(helper.address.ethToSubstrate(sponsor));
+ expect(sponsorBalanceAfter < sponsorBalanceBefore).to.be.true;
+ });
+});
+
+describe('evm RFT token sponsoring', () => {
+ let donor: IKeyringPair;
+
+ before(async function() {
+ await usingPlaygrounds(async (helper, privateKey) => {
+ requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
+ donor = await privateKey({filename: __filename});
+ });
+ });
+
+ itEth('[cross] Check that transfer via EVM spend money from sponsor address', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+
+ const {collectionAddress, collectionId} = await helper.eth.createERC721MetadataCompatibleRFTCollection(owner,'Sponsor collection', '1', '1', '');
+ const sponsor = await helper.eth.createAccountWithBalance(donor);
+ const sponsorCross = helper.ethCrossAccount.fromAddress(sponsor);
+ const receiver = await helper.eth.createAccountWithBalance(donor);
+ const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);
+
+ await collectionEvm.methods.setCollectionSponsorCross(sponsorCross).send();
+
+ const sponsorCollection = helper.ethNativeContract.collection(collectionAddress, 'rft', sponsor);
+ await sponsorCollection.methods.confirmCollectionSponsorship().send();
+
+ const user = await helper.eth.createAccountWithBalance(donor);
+ const userCross = helper.ethCrossAccount.fromAddress(user);
+ await collectionEvm.methods.addCollectionAdminCross(userCross).send();
+
+ const userCollectionEvm = helper.ethNativeContract.collection(collectionAddress, 'rft', user);
+
+ const result = await userCollectionEvm.methods.mintWithTokenURI(user, 'Test URI').send();
+ const tokenId = result.events.Transfer.returnValues.tokenId;
+
+ const tokenContract = helper.ethNativeContract.rftTokenById(collectionId, tokenId, user);
+ await tokenContract.methods.repartition(2).send();
+
+ const ownerBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(owner));
+ const sponsorBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(sponsor));
+ const userBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(user));
+
+ await tokenContract.methods.transfer(receiver, 1).send();
+
+ const ownerBalanceAfter = await helper.balance.getSubstrate(helper.address.ethToSubstrate(owner));
+ expect(ownerBalanceAfter).to.be.eq(ownerBalanceBefore);
+ const sponsorBalanceAfter = await helper.balance.getSubstrate(helper.address.ethToSubstrate(sponsor));
+ expect(sponsorBalanceAfter < sponsorBalanceBefore).to.be.true;
+ const userBalanceAfter = await helper.balance.getSubstrate(helper.address.ethToSubstrate(user));
+ expect(userBalanceAfter).to.be.eq(userBalanceBefore);
+ });
+
+ itEth('[cross] Check that approve via EVM spend money from sponsor address', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+
+ const {collectionAddress, collectionId} = await helper.eth.createERC721MetadataCompatibleRFTCollection(owner,'Sponsor collection', '1', '1', '');
+ const sponsor = await helper.eth.createAccountWithBalance(donor);
+ const sponsorCross = helper.ethCrossAccount.fromAddress(sponsor);
+ const receiver = await helper.eth.createAccountWithBalance(donor);
+ const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);
+
+ await collectionEvm.methods.setCollectionSponsorCross(sponsorCross).send();
+
+ const sponsorCollection = helper.ethNativeContract.collection(collectionAddress, 'rft', sponsor);
+ await sponsorCollection.methods.confirmCollectionSponsorship().send();
+
+ const user = await helper.eth.createAccountWithBalance(donor);
+ const userCross = helper.ethCrossAccount.fromAddress(user);
+ await collectionEvm.methods.addCollectionAdminCross(userCross).send();
+
+ const userCollectionEvm = helper.ethNativeContract.collection(collectionAddress, 'rft', user);
+
+ const result = await userCollectionEvm.methods.mintWithTokenURI(user, 'Test URI').send();
+ const tokenId = result.events.Transfer.returnValues.tokenId;
+
+ const tokenContract = helper.ethNativeContract.rftTokenById(collectionId, tokenId, user);
+ await tokenContract.methods.repartition(2).send();
+
+ const ownerBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(owner));
+ const sponsorBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(sponsor));
+ const userBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(user));
+
+ await tokenContract.methods.approve(receiver, 1).send();
+
+ const ownerBalanceAfter = await helper.balance.getSubstrate(helper.address.ethToSubstrate(owner));
+ expect(ownerBalanceAfter).to.be.eq(ownerBalanceBefore);
+ const sponsorBalanceAfter = await helper.balance.getSubstrate(helper.address.ethToSubstrate(sponsor));
+ expect(sponsorBalanceAfter < sponsorBalanceBefore).to.be.true;
+ const userBalanceAfter = await helper.balance.getSubstrate(helper.address.ethToSubstrate(user));
+ expect(userBalanceAfter).to.be.eq(userBalanceBefore);
+ });
+
+
+ itEth('[cross] Check that transferFrom via EVM spend money from sponsor address', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+
+ const {collectionAddress, collectionId} = await helper.eth.createERC721MetadataCompatibleRFTCollection(owner,'Sponsor collection', '1', '1', '');
+ const sponsor = await helper.eth.createAccountWithBalance(donor);
+ const sponsorCross = helper.ethCrossAccount.fromAddress(sponsor);
+ const receiver = await helper.eth.createAccountWithBalance(donor);
+ const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);
+
+ await collectionEvm.methods.setCollectionSponsorCross(sponsorCross).send();
+
+ const sponsorCollection = helper.ethNativeContract.collection(collectionAddress, 'rft', sponsor);
+ await sponsorCollection.methods.confirmCollectionSponsorship().send();
+
+ const user = await helper.eth.createAccountWithBalance(donor);
+ const userCross = helper.ethCrossAccount.fromAddress(user);
+ await collectionEvm.methods.addCollectionAdminCross(userCross).send();
+
+ const userCollectionEvm = helper.ethNativeContract.collection(collectionAddress, 'rft', user);
+
+ const result = await userCollectionEvm.methods.mintWithTokenURI(user, 'Test URI').send();
+ const tokenId = result.events.Transfer.returnValues.tokenId;
+
+ const tokenContract = helper.ethNativeContract.rftTokenById(collectionId, tokenId, user);
+ await tokenContract.methods.repartition(2).send();
+ await tokenContract.methods.approve(receiver, 1).send();
+
+ const ownerBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(owner));
+ const sponsorBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(sponsor));
+ const userBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(user));
+ const receiverBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(receiver));
+
+ const receiverTokenContract = helper.ethNativeContract.rftTokenById(collectionId, tokenId, receiver);
+ await receiverTokenContract.methods.transferFrom(user, receiver, 1).send();
+
+ const receiverBalanceAfter = await helper.balance.getSubstrate(helper.address.ethToSubstrate(receiver));
+ expect(receiverBalanceAfter).to.be.eq(receiverBalanceBefore);
+ const ownerBalanceAfter = await helper.balance.getSubstrate(helper.address.ethToSubstrate(owner));
+ expect(ownerBalanceAfter).to.be.eq(ownerBalanceBefore);
+ const sponsorBalanceAfter = await helper.balance.getSubstrate(helper.address.ethToSubstrate(sponsor));
+ expect(sponsorBalanceAfter < sponsorBalanceBefore).to.be.true;
+ const userBalanceAfter = await helper.balance.getSubstrate(helper.address.ethToSubstrate(user));
+ expect(userBalanceAfter).to.be.eq(userBalanceBefore);
+ });
+});