difftreelog
Fix Refungible balance tests
in: master
2 files changed
pallets/nft/src/mock.rsdiffbeforeafterboth10use pallet_transaction_payment::{CurrencyAdapter};10use pallet_transaction_payment::{CurrencyAdapter};11use frame_system as system;11use frame_system as system;12use pallet_evm::AddressMapping;12use pallet_evm::AddressMapping;13use crate::{EvmBackwardsAddressMapping, CrossAccountId};13use pallet_common::account::{EvmBackwardsAddressMapping, CrossAccountId};14use codec::{Encode, Decode};14use codec::{Encode, Decode};15use scale_info::TypeInfo;15use scale_info::TypeInfo;1616158}158}159159160impl pallet_template::Config for Test {160impl pallet_template::Config for Test {161 type Event = ();162 type WeightInfo = ();161 type WeightInfo = ();163 type CollectionCreationPrice = CollectionCreationPrice;164 type Currency = pallet_balances::Pallet<Test>;165 type TreasuryAccountId = TreasuryAccountId;166 type EvmAddressMapping = TestEvmAddressMapping;167 type EvmBackwardsAddressMapping = TestEvmBackwardsAddressMapping;168 type CrossAccountId = TestCrossAccountId;169}162}170163171// Build genesis storage according to the mock runtime.164// Build genesis storage according to the mock runtime.pallets/nft/src/tests.rsdiffbeforeafterboth1// Tests to be written here1// Tests to be written here2use super::*;2use super::*;3use crate::mock::*;3use crate::mock::*;4use crate::{AccessMode, CollectionMode, Ownership, CreateItemData};4use crate::{AccessMode, CollectionMode, CreateItemData};5use nft_data_structs::{5use nft_data_structs::{6 CreateNftData, CreateFungibleData, CreateReFungibleData, CollectionId, TokenId,6 CreateNftData, CreateFungibleData, CreateReFungibleData, CollectionId, TokenId,7 MAX_DECIMAL_POINTS,7 MAX_DECIMAL_POINTS,178 let data = default_re_fungible_data();178 let data = default_re_fungible_data();179 create_test_item(collection_id, &data.clone().into());179 create_test_item(collection_id, &data.clone().into());180 let item = TemplateModule::refungible_item_id(collection_id, 1).unwrap();180 let item = TemplateModule::refungible_item_id(collection_id, 1).unwrap();181 let balance = TemplateModule::balance(collection_id, 1, account(1));181 assert_eq!(item.const_data, data.const_data.into_inner());182 assert_eq!(item.const_data, data.const_data.into_inner());182 assert_eq!(item.variable_data, data.variable_data.into_inner());183 assert_eq!(item.variable_data, data.variable_data.into_inner());183 assert_eq!(184 assert_eq!(balance, 1023);184 item.owner[0],185 Ownership {186 owner: account(1),187 fraction: 1023188 }189 );190 });185 });191}186}215 ));210 ));216 for (index, data) in items_data.into_iter().enumerate() {211 for (index, data) in items_data.into_iter().enumerate() {217 let item = TemplateModule::refungible_item_id(1, (index + 1) as TokenId).unwrap();212 let item = TemplateModule::refungible_item_id(1, (index + 1) as TokenId).unwrap();213 let balance = TemplateModule::balance(1, 1, account(1));218 assert_eq!(item.const_data.to_vec(), data.const_data.into_inner());214 assert_eq!(item.const_data.to_vec(), data.const_data.into_inner());219 assert_eq!(item.variable_data.to_vec(), data.variable_data.into_inner());215 assert_eq!(item.variable_data.to_vec(), data.variable_data.into_inner());220 assert_eq!(216 assert_eq!(balance, 1023);221 item.owner[0],222 Ownership {223 owner: account(1),224 fraction: 1023225 }226 );227 }217 }228 });218 });318 let origin2 = Origin::signed(2);308 let origin2 = Origin::signed(2);319 {309 {320 let item = TemplateModule::refungible_item_id(collection_id, 1).unwrap();310 let item = TemplateModule::refungible_item_id(collection_id, 1).unwrap();311 let balance = TemplateModule::balance(collection_id, 1, account(1));321 assert_eq!(item.const_data, data.const_data.into_inner());312 assert_eq!(item.const_data, data.const_data.into_inner());322 assert_eq!(item.variable_data, data.variable_data.into_inner());313 assert_eq!(item.variable_data, data.variable_data.into_inner());323 assert_eq!(314 assert_eq!(balance, 1023);324 item.owner[0],325 Ownership {326 owner: account(1),327 fraction: 1023328 }329 );330 }315 }331 assert_eq!(TemplateModule::balance_count(1, 1), 1023);316 assert_eq!(TemplateModule::balance_count(1, 1), 1023);332 assert_eq!(TemplateModule::address_tokens(1, 1), [1]);317 assert_eq!(TemplateModule::address_tokens(1, 1), [1]);333318334 // change owner scenario319 // change owner scenario335 assert_ok!(TemplateModule::transfer(origin1, account(2), 1, 1, 1023));320 assert_ok!(TemplateModule::transfer(origin1, account(2), 1, 1, 1023));336 assert_eq!(321337 TemplateModule::refungible_item_id(1, 1).unwrap().owner[0],322 let balance2 = TemplateModule::balance(collection_id, 1, account(2));338 Ownership {323 assert_eq!(balance2, 1023);339 owner: account(2),340 fraction: 1023341 }342 );343 assert_eq!(TemplateModule::balance_count(1, 1), 0);324 assert_eq!(TemplateModule::balance_count(1, 1), 0);344 assert_eq!(TemplateModule::balance_count(1, 2), 1023);325 assert_eq!(TemplateModule::balance_count(1, 2), 1023);345 // assert_eq!(TemplateModule::address_tokens(1, 1), []);326 // assert_eq!(TemplateModule::address_tokens(1, 1), []);355 ));336 ));356 {337 {357 let item = TemplateModule::refungible_item_id(1, 1).unwrap();338 let item = TemplateModule::refungible_item_id(1, 1).unwrap();358 assert_eq!(339 let balance2 = TemplateModule::balance(collection_id, 1, account(2));359 item.owner[0],360 Ownership {361 owner: account(2),362 fraction: 523363 }364 );365 assert_eq!(340 let balance3 = TemplateModule::balance(collection_id, 1, account(3));366 item.owner[1],341 assert_eq!(balance2, 523);367 Ownership {342 assert_eq!(balance3, 500);368 owner: account(3),369 fraction: 500370 }371 );372 }343 }373 assert_eq!(TemplateModule::balance_count(1, 2), 523);344 assert_eq!(TemplateModule::balance_count(1, 2), 523);379 assert_ok!(TemplateModule::transfer(origin2, account(3), 1, 1, 200));350 assert_ok!(TemplateModule::transfer(origin2, account(3), 1, 1, 200));380 {351 {381 let item = TemplateModule::refungible_item_id(1, 1).unwrap();352 let item = TemplateModule::refungible_item_id(1, 1).unwrap();382 assert_eq!(353 let balance2 = TemplateModule::balance(collection_id, 1, account(2));383 item.owner[0],384 Ownership {385 owner: account(2),386 fraction: 323387 }388 );389 assert_eq!(354 let balance3 = TemplateModule::balance(collection_id, 1, account(3));390 item.owner[1],355 assert_eq!(balance2, 323);391 Ownership {356 assert_eq!(balance3, 700);392 owner: account(3),393 fraction: 700394 }395 );396 }357 }397 assert_eq!(TemplateModule::balance_count(1, 2), 323);358 assert_eq!(TemplateModule::balance_count(1, 2), 323);