difftreelog
feat prevent ouroboros creation during nest
in: master
11 files changed
client/rpc/src/lib.rsdiffbeforeafterboth--- a/client/rpc/src/lib.rs
+++ b/client/rpc/src/lib.rs
@@ -77,11 +77,7 @@
) -> Result<Vec<u8>>;
#[rpc(name = "unique_totalSupply")]
- fn total_supply(
- &self,
- collection: CollectionId,
- at: Option<BlockHash>,
- ) -> Result<u32>;
+ fn total_supply(&self, collection: CollectionId, at: Option<BlockHash>) -> Result<u32>;
#[rpc(name = "unique_accountBalance")]
fn account_balance(
&self,
pallets/common/src/lib.rsdiffbeforeafterboth--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -918,7 +918,7 @@
fn check_nesting(
&self,
sender: T::CrossAccountId,
- from: CollectionId,
+ from: (CollectionId, TokenId),
under: TokenId,
budget: &dyn Budget,
) -> DispatchResult;
pallets/fungible/src/common.rsdiffbeforeafterboth--- a/pallets/fungible/src/common.rs
+++ b/pallets/fungible/src/common.rs
@@ -237,7 +237,7 @@
fn check_nesting(
&self,
_sender: <T>::CrossAccountId,
- _from: CollectionId,
+ _from: (CollectionId, TokenId),
_under: TokenId,
_budget: &dyn Budget,
) -> sp_runtime::DispatchResult {
pallets/fungible/src/lib.rsdiffbeforeafterboth--- a/pallets/fungible/src/lib.rs
+++ b/pallets/fungible/src/lib.rs
@@ -224,7 +224,12 @@
let dispatch = T::CollectionDispatch::dispatch(handle);
let dispatch = dispatch.as_dyn();
- dispatch.check_nesting(from.clone(), collection.id, target.1, nesting_budget)?;
+ dispatch.check_nesting(
+ from.clone(),
+ (collection.id, TokenId::default()),
+ target.1,
+ nesting_budget,
+ )?;
}
// =========
@@ -293,7 +298,12 @@
let dispatch = T::CollectionDispatch::dispatch(handle);
let dispatch = dispatch.as_dyn();
- dispatch.check_nesting(sender.clone(), collection.id, target.1, nesting_budget)?;
+ dispatch.check_nesting(
+ sender.clone(),
+ (collection.id, TokenId::default()),
+ target.1,
+ nesting_budget,
+ )?;
}
}
@@ -386,10 +396,11 @@
if let Some(source) = T::CrossTokenAddressMapping::address_to_token(from) {
// TODO: should collection owner be allowed to perform this transfer?
ensure!(
- <PalletStructure<T>>::indirectly_owned(
+ <PalletStructure<T>>::check_indirectly_owned(
spender.clone(),
source.0,
source.1,
+ None,
nesting_budget
)?,
<CommonError<T>>::ApprovedValueTooLow,
pallets/nonfungible/src/common.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/>.1617use core::marker::PhantomData;1819use frame_support::{dispatch::DispatchResultWithPostInfo, ensure, fail, weights::Weight, BoundedVec};20use up_data_structs::{TokenId, CustomDataLimit, CreateItemExData, CollectionId, budget::Budget};21use pallet_common::{CommonCollectionOperations, CommonWeightInfo, with_weight};22use sp_runtime::DispatchError;23use sp_std::vec::Vec;2425use crate::{26 AccountBalance, Allowance, Config, CreateItemData, Error, NonfungibleHandle, Owned, Pallet,27 SelfWeightOf, TokenData, weights::WeightInfo, TokensMinted,28};2930pub struct CommonWeights<T: Config>(PhantomData<T>);31impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {32 fn create_item() -> Weight {33 <SelfWeightOf<T>>::create_item()34 }3536 fn create_multiple_items_ex(data: &CreateItemExData<T::CrossAccountId>) -> Weight {37 match data {38 CreateItemExData::NFT(t) => <SelfWeightOf<T>>::create_multiple_items_ex(t.len() as u32),39 _ => 0,40 }41 }4243 fn create_multiple_items(amount: u32) -> Weight {44 <SelfWeightOf<T>>::create_multiple_items(amount)45 }4647 fn burn_item() -> Weight {48 <SelfWeightOf<T>>::burn_item()49 }5051 fn transfer() -> Weight {52 <SelfWeightOf<T>>::transfer()53 }5455 fn approve() -> Weight {56 <SelfWeightOf<T>>::approve()57 }5859 fn transfer_from() -> Weight {60 <SelfWeightOf<T>>::transfer_from()61 }6263 fn burn_from() -> Weight {64 <SelfWeightOf<T>>::burn_from()65 }6667 fn set_variable_metadata(bytes: u32) -> Weight {68 <SelfWeightOf<T>>::set_variable_metadata(bytes)69 }70}7172fn map_create_data<T: Config>(73 data: up_data_structs::CreateItemData,74 to: &T::CrossAccountId,75) -> Result<CreateItemData<T>, DispatchError> {76 match data {77 up_data_structs::CreateItemData::NFT(data) => Ok(CreateItemData::<T> {78 const_data: data.const_data,79 variable_data: data.variable_data,80 owner: to.clone(),81 }),82 _ => fail!(<Error<T>>::NotNonfungibleDataUsedToMintFungibleCollectionToken),83 }84}8586impl<T: Config> CommonCollectionOperations<T> for NonfungibleHandle<T> {87 fn create_item(88 &self,89 sender: T::CrossAccountId,90 to: T::CrossAccountId,91 data: up_data_structs::CreateItemData,92 nesting_budget: &dyn Budget,93 ) -> DispatchResultWithPostInfo {94 with_weight(95 <Pallet<T>>::create_item(96 self,97 &sender,98 map_create_data::<T>(data, &to)?,99 nesting_budget,100 ),101 <CommonWeights<T>>::create_item(),102 )103 }104105 fn create_multiple_items(106 &self,107 sender: T::CrossAccountId,108 to: T::CrossAccountId,109 data: Vec<up_data_structs::CreateItemData>,110 nesting_budget: &dyn Budget,111 ) -> DispatchResultWithPostInfo {112 let data = data113 .into_iter()114 .map(|d| map_create_data::<T>(d, &to))115 .collect::<Result<Vec<_>, DispatchError>>()?;116117 let amount = data.len();118 with_weight(119 <Pallet<T>>::create_multiple_items(self, &sender, data, nesting_budget),120 <CommonWeights<T>>::create_multiple_items(amount as u32),121 )122 }123124 fn create_multiple_items_ex(125 &self,126 sender: <T>::CrossAccountId,127 data: up_data_structs::CreateItemExData<<T>::CrossAccountId>,128 nesting_budget: &dyn Budget,129 ) -> DispatchResultWithPostInfo {130 let weight = <CommonWeights<T>>::create_multiple_items_ex(&data);131 let data = match data {132 up_data_structs::CreateItemExData::NFT(nft) => nft,133 _ => fail!(Error::<T>::NotNonfungibleDataUsedToMintFungibleCollectionToken),134 };135136 with_weight(137 <Pallet<T>>::create_multiple_items(self, &sender, data.into_inner(), nesting_budget),138 weight,139 )140 }141142 fn burn_item(143 &self,144 sender: T::CrossAccountId,145 token: TokenId,146 amount: u128,147 ) -> DispatchResultWithPostInfo {148 ensure!(amount <= 1, <Error<T>>::NonfungibleItemsHaveNoAmount);149 if amount == 1 {150 with_weight(151 <Pallet<T>>::burn(self, &sender, token),152 <CommonWeights<T>>::burn_item(),153 )154 } else {155 Ok(().into())156 }157 }158159 fn transfer(160 &self,161 from: T::CrossAccountId,162 to: T::CrossAccountId,163 token: TokenId,164 amount: u128,165 nesting_budget: &dyn Budget,166 ) -> DispatchResultWithPostInfo {167 ensure!(amount <= 1, <Error<T>>::NonfungibleItemsHaveNoAmount);168 if amount == 1 {169 with_weight(170 <Pallet<T>>::transfer(self, &from, &to, token, nesting_budget),171 <CommonWeights<T>>::transfer(),172 )173 } else {174 Ok(().into())175 }176 }177178 fn approve(179 &self,180 sender: T::CrossAccountId,181 spender: T::CrossAccountId,182 token: TokenId,183 amount: u128,184 ) -> DispatchResultWithPostInfo {185 ensure!(amount <= 1, <Error<T>>::NonfungibleItemsHaveNoAmount);186187 with_weight(188 if amount == 1 {189 <Pallet<T>>::set_allowance(self, &sender, token, Some(&spender))190 } else {191 <Pallet<T>>::set_allowance(self, &sender, token, None)192 },193 <CommonWeights<T>>::approve(),194 )195 }196197 fn transfer_from(198 &self,199 sender: T::CrossAccountId,200 from: T::CrossAccountId,201 to: T::CrossAccountId,202 token: TokenId,203 amount: u128,204 nesting_budget: &dyn Budget,205 ) -> DispatchResultWithPostInfo {206 ensure!(amount <= 1, <Error<T>>::NonfungibleItemsHaveNoAmount);207208 if amount == 1 {209 with_weight(210 <Pallet<T>>::transfer_from(self, &sender, &from, &to, token, nesting_budget),211 <CommonWeights<T>>::transfer_from(),212 )213 } else {214 Ok(().into())215 }216 }217218 fn burn_from(219 &self,220 sender: T::CrossAccountId,221 from: T::CrossAccountId,222 token: TokenId,223 amount: u128,224 nesting_budget: &dyn Budget,225 ) -> DispatchResultWithPostInfo {226 ensure!(amount <= 1, <Error<T>>::NonfungibleItemsHaveNoAmount);227228 if amount == 1 {229 with_weight(230 <Pallet<T>>::burn_from(self, &sender, &from, token, nesting_budget),231 <CommonWeights<T>>::burn_from(),232 )233 } else {234 Ok(().into())235 }236 }237238 fn set_variable_metadata(239 &self,240 sender: T::CrossAccountId,241 token: TokenId,242 data: BoundedVec<u8, CustomDataLimit>,243 ) -> DispatchResultWithPostInfo {244 let len = data.len();245 with_weight(246 <Pallet<T>>::set_variable_metadata(self, &sender, token, data),247 <CommonWeights<T>>::set_variable_metadata(len as u32),248 )249 }250251 fn check_nesting(252 &self,253 sender: T::CrossAccountId,254 from: CollectionId,255 under: TokenId,256 budget: &dyn Budget,257 ) -> sp_runtime::DispatchResult {258 <Pallet<T>>::check_nesting(self, sender, from, under, budget)259 }260261 fn account_tokens(&self, account: T::CrossAccountId) -> Vec<TokenId> {262 <Owned<T>>::iter_prefix((self.id, account))263 .map(|(id, _)| id)264 .collect()265 }266267 fn collection_tokens(&self) -> Vec<TokenId> {268 <TokenData<T>>::iter_prefix((self.id,))269 .map(|(id, _)| id)270 .collect()271 }272273 fn token_exists(&self, token: TokenId) -> bool {274 <Pallet<T>>::token_exists(self, token)275 }276277 fn last_token_id(&self) -> TokenId {278 TokenId(<TokensMinted<T>>::get(self.id))279 }280281 fn token_owner(&self, token: TokenId) -> Option<T::CrossAccountId> {282 <TokenData<T>>::get((self.id, token)).map(|t| t.owner)283 }284 fn const_metadata(&self, token: TokenId) -> Vec<u8> {285 <TokenData<T>>::get((self.id, token))286 .map(|t| t.const_data)287 .unwrap_or_default()288 .into_inner()289 }290 fn variable_metadata(&self, token: TokenId) -> Vec<u8> {291 <TokenData<T>>::get((self.id, token))292 .map(|t| t.variable_data)293 .unwrap_or_default()294 .into_inner()295 }296297 fn total_supply(&self) -> u32 {298 <Pallet<T>>::total_supply(self)299 }300301 fn account_balance(&self, account: T::CrossAccountId) -> u32 {302 <AccountBalance<T>>::get((self.id, account))303 }304305 fn balance(&self, account: T::CrossAccountId, token: TokenId) -> u128 {306 if <TokenData<T>>::get((self.id, token))307 .map(|a| a.owner == account)308 .unwrap_or(false)309 {310 1311 } else {312 0313 }314 }315316 fn allowance(317 &self,318 sender: T::CrossAccountId,319 spender: T::CrossAccountId,320 token: TokenId,321 ) -> u128 {322 if <TokenData<T>>::get((self.id, token))323 .map(|a| a.owner != sender)324 .unwrap_or(true)325 {326 0327 } else if <Allowance<T>>::get((self.id, token)) == Some(spender) {328 1329 } else {330 0331 }332 }333}pallets/nonfungible/src/lib.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/lib.rs
+++ b/pallets/nonfungible/src/lib.rs
@@ -296,7 +296,12 @@
let dispatch = T::CollectionDispatch::dispatch(handle);
let dispatch = dispatch.as_dyn();
- dispatch.check_nesting(from.clone(), collection.id, target.1, nesting_budget)?;
+ dispatch.check_nesting(
+ from.clone(),
+ (collection.id, token),
+ target.1,
+ nesting_budget,
+ )?;
}
// =========
@@ -381,13 +386,18 @@
);
}
- for (to, _) in balances.iter() {
- if let Some(target) = T::CrossTokenAddressMapping::address_to_token(to) {
+ for (i, data) in data.iter().enumerate() {
+ let token = TokenId(first_token + i as u32 + 1);
+ if let Some(target) = T::CrossTokenAddressMapping::address_to_token(&data.owner) {
let handle = <CollectionHandle<T>>::try_get(target.0)?;
let dispatch = T::CollectionDispatch::dispatch(handle);
let dispatch = dispatch.as_dyn();
-
- dispatch.check_nesting(sender.clone(), collection.id, target.1, nesting_budget)?;
+ dispatch.check_nesting(
+ sender.clone(),
+ (collection.id, token),
+ target.1,
+ nesting_budget,
+ )?;
}
}
@@ -535,10 +545,11 @@
if let Some(source) = T::CrossTokenAddressMapping::address_to_token(from) {
// TODO: should collection owner be allowed to perform this transfer?
ensure!(
- <PalletStructure<T>>::indirectly_owned(
+ <PalletStructure<T>>::check_indirectly_owned(
spender.clone(),
source.0,
source.1,
+ None,
nesting_budget
)?,
<CommonError<T>>::ApprovedValueTooLow,
@@ -610,31 +621,40 @@
pub fn check_nesting(
handle: &NonfungibleHandle<T>,
sender: T::CrossAccountId,
- from: CollectionId,
+ from: (CollectionId, TokenId),
under: TokenId,
nesting_budget: &dyn Budget,
) -> DispatchResult {
fn ensure_sender_allowed<T: Config>(
collection: CollectionId,
token: TokenId,
+ for_nest: (CollectionId, TokenId),
sender: T::CrossAccountId,
budget: &dyn Budget,
) -> DispatchResult {
ensure!(
- <PalletStructure<T>>::indirectly_owned(sender, collection, token, budget)?,
+ <PalletStructure<T>>::check_indirectly_owned(
+ sender,
+ collection,
+ token,
+ Some(for_nest),
+ budget
+ )?,
<CommonError<T>>::OnlyOwnerAllowedToNest,
);
Ok(())
}
match handle.limits.nesting_rule() {
NestingRule::Disabled => fail!(<CommonError<T>>::NestingIsDisabled),
- NestingRule::Owner => ensure_sender_allowed::<T>(handle.id, under, sender, nesting_budget)?,
+ NestingRule::Owner => {
+ ensure_sender_allowed::<T>(handle.id, under, from, sender, nesting_budget)?
+ }
NestingRule::OwnerRestricted(whitelist) => {
ensure!(
- whitelist.contains(&from),
+ whitelist.contains(&from.0),
<CommonError<T>>::SourceCollectionIsNotAllowedToNest
);
- ensure_sender_allowed::<T>(handle.id, under, sender, nesting_budget)?
+ ensure_sender_allowed::<T>(handle.id, under, from, sender, nesting_budget)?
}
}
Ok(())
pallets/refungible/src/common.rsdiffbeforeafterboth--- a/pallets/refungible/src/common.rs
+++ b/pallets/refungible/src/common.rs
@@ -260,7 +260,7 @@
fn check_nesting(
&self,
_sender: <T>::CrossAccountId,
- _from: CollectionId,
+ _from: (CollectionId, TokenId),
_under: TokenId,
_budget: &dyn Budget,
) -> sp_runtime::DispatchResult {
pallets/refungible/src/lib.rsdiffbeforeafterboth--- a/pallets/refungible/src/lib.rs
+++ b/pallets/refungible/src/lib.rs
@@ -352,7 +352,12 @@
let dispatch = T::CollectionDispatch::dispatch(handle);
let dispatch = dispatch.as_dyn();
- dispatch.check_nesting(from.clone(), collection.id, target.1, nesting_budget)?;
+ dispatch.check_nesting(
+ from.clone(),
+ (collection.id, token),
+ target.1,
+ nesting_budget,
+ )?;
}
// =========
@@ -455,7 +460,8 @@
}
}
- for token in data.iter() {
+ for (i, token) in data.iter().enumerate() {
+ let token_id = TokenId(first_token_id + i as u32 + 1);
for (to, _) in token.users.iter() {
if let Some(target) = T::CrossTokenAddressMapping::address_to_token(to) {
let handle = <CollectionHandle<T>>::try_get(target.0)?;
@@ -464,7 +470,7 @@
dispatch.check_nesting(
sender.clone(),
- collection.id,
+ (collection.id, token_id),
target.1,
nesting_budget,
)?;
@@ -575,10 +581,11 @@
if let Some(source) = T::CrossTokenAddressMapping::address_to_token(from) {
// TODO: should collection owner be allowed to perform this transfer?
ensure!(
- <PalletStructure<T>>::indirectly_owned(
+ <PalletStructure<T>>::check_indirectly_owned(
spender.clone(),
source.0,
source.1,
+ None,
nesting_budget
)?,
<CommonError<T>>::ApprovedValueTooLow,
pallets/structure/src/lib.rsdiffbeforeafterboth--- a/pallets/structure/src/lib.rs
+++ b/pallets/structure/src/lib.rs
@@ -71,7 +71,7 @@
#[derive(PartialEq)]
pub enum Parent<CrossAccountId> {
/// Token owned by normal account
- Normal(CrossAccountId),
+ User(CrossAccountId),
/// Passed token not found
TokenNotFound,
/// Token owner is another token (target token still may not exist)
@@ -94,7 +94,7 @@
Ok(match handle.token_owner(token) {
Some(owner) => match T::CrossTokenAddressMapping::address_to_token(&owner) {
Some((collection, token)) => Parent::Token(collection, token),
- None => Parent::Normal(owner),
+ None => Parent::User(owner),
},
None => Parent::TokenNotFound,
})
@@ -137,29 +137,46 @@
) -> Result<T::CrossAccountId, DispatchError> {
let owner = Self::parent_chain(collection, token)
.take_while(|_| budget.consume())
- .find(|p| matches!(p, Ok(Parent::Normal(_) | Parent::TokenNotFound)))
+ .find(|p| matches!(p, Ok(Parent::User(_) | Parent::TokenNotFound)))
.ok_or(<Error<T>>::DepthLimit)??;
Ok(match owner {
- Parent::Normal(v) => v,
+ Parent::User(v) => v,
_ => fail!(<Error<T>>::TokenNotFound),
})
}
/// Check if token indirectly owned by specified user
- pub fn indirectly_owned(
+ pub fn check_indirectly_owned(
user: T::CrossAccountId,
collection: CollectionId,
token: TokenId,
+ for_nest: Option<(CollectionId, TokenId)>,
budget: &dyn Budget,
) -> Result<bool, DispatchError> {
let target_parent = match T::CrossTokenAddressMapping::address_to_token(&user) {
Some((collection, token)) => Parent::Token(collection, token),
- None => Parent::Normal(user),
+ None => Parent::User(user),
};
- Ok(Self::parent_chain(collection, token)
- .take_while(|_| budget.consume())
- .any(|parent| Ok(&target_parent) == parent.as_ref()))
+ // Tried to nest token in itself
+ if Some((collection, token)) == for_nest {
+ return Err(<Error<T>>::OuroborosDetected.into());
+ }
+
+ for parent in Self::parent_chain(collection, token).take_while(|_| budget.consume()) {
+ match parent? {
+ // Tried to nest token in chain, which has this token as one of parents
+ Parent::Token(collection, token) if Some((collection, token)) == for_nest => {
+ return Err(<Error<T>>::OuroborosDetected.into())
+ }
+ // Found needed parent, token is indirecty owned
+ v if v == target_parent => return Ok(true),
+ Parent::TokenNotFound => return Ok(false),
+ _ => {}
+ }
+ }
+
+ Err(<Error<T>>::DepthLimit.into())
}
}
tests/src/eth/util/helpers.tsdiffbeforeafterboth--- a/tests/src/eth/util/helpers.ts
+++ b/tests/src/eth/util/helpers.ts
@@ -23,7 +23,7 @@
import usingApi, {submitTransactionAsync} from '../../substrate/substrate-api';
import {IKeyringPair} from '@polkadot/types/types';
import {expect} from 'chai';
-import {getGenericResult, UNIQUE} from '../../util/helpers';
+import {CrossAccountId, getGenericResult, UNIQUE} from '../../util/helpers';
import * as solc from 'solc';
import config from '../../config';
import privateKey from '../../substrate/privateKey';
@@ -80,6 +80,11 @@
]);
return Web3.utils.toChecksumAddress('0x' + buf.toString('hex'));
}
+export function tokenIdToCross(collection: number, token: number): CrossAccountId {
+ return {
+ Ethereum: tokenIdToAddress(collection, token),
+ };
+}
export function createEthAccount(web3: Web3) {
const account = web3.eth.accounts.create();
tests/src/nesting/graphs.test.tsdiffbeforeafterboth--- /dev/null
+++ b/tests/src/nesting/graphs.test.ts
@@ -0,0 +1,51 @@
+import {ApiPromise} from '@polkadot/api';
+import {IKeyringPair} from '@polkadot/types/types';
+import {expect} from 'chai';
+import {tokenIdToCross} from '../eth/util/helpers';
+import privateKey from '../substrate/privateKey';
+import usingApi, {executeTransaction} from '../substrate/substrate-api';
+import {getCreateCollectionResult, transferExpectSuccess} from '../util/helpers';
+
+/**
+ * ```dot
+ * 4 -> 3 -> 2 -> 1
+ * 7 -> 6 -> 5 -> 2
+ * 8 -> 5
+ * ```
+ */
+async function buildComplexObjectGraph(api: ApiPromise, sender: IKeyringPair): Promise<number> {
+ const events = await executeTransaction(api, sender, api.tx.unique.createCollectionEx({mode: 'NFT'}));
+ const {collectionId} = getCreateCollectionResult(events);
+
+ await executeTransaction(api, sender, api.tx.unique.createMultipleItemsEx(collectionId, {NFT: Array(8).fill({owner: {Substrate: sender.address}})}));
+
+ await transferExpectSuccess(collectionId, 8, sender, tokenIdToCross(collectionId, 5));
+
+ await transferExpectSuccess(collectionId, 7, sender, tokenIdToCross(collectionId, 6));
+ await transferExpectSuccess(collectionId, 6, sender, tokenIdToCross(collectionId, 5));
+ await transferExpectSuccess(collectionId, 5, sender, tokenIdToCross(collectionId, 2));
+
+ await transferExpectSuccess(collectionId, 4, sender, tokenIdToCross(collectionId, 3));
+ await transferExpectSuccess(collectionId, 3, sender, tokenIdToCross(collectionId, 2));
+ await transferExpectSuccess(collectionId, 2, sender, tokenIdToCross(collectionId, 1));
+
+ return collectionId;
+}
+
+describe('graphs', () => {
+ it('ouroboros can\'t be created in graph', async () => {
+ await usingApi(async api => {
+ const alice = privateKey('//Alice');
+ const collection = await buildComplexObjectGraph(api, alice);
+
+ // to self
+ await expect(executeTransaction(api, alice, api.tx.unique.transfer(tokenIdToCross(collection, 1), collection, 1, 1)))
+ .to.be.rejectedWith(/structure\.OuroborosDetected/);
+ // to nested part of graph
+ await expect(executeTransaction(api, alice, api.tx.unique.transfer(tokenIdToCross(collection, 5), collection, 1, 1)))
+ .to.be.rejectedWith(/structure\.OuroborosDetected/);
+ await expect(executeTransaction(api, alice, api.tx.unique.transfer(tokenIdToCross(collection, 8), collection, 2, 1)))
+ .to.be.rejectedWith(/structure\.OuroborosDetected/);
+ });
+ });
+});