difftreelog
fix tests and weights
in: master
16 files changed
pallets/balances-adapter/src/erc.rsdiffbeforeafterboth1use crate::{Config, NativeFungibleHandle};1use crate::{Config, NativeFungibleHandle, SelfWeightOf};2use evm_coder::{abi::AbiType, ToLog, generate_stubgen, solidity_interface, types::*};2use evm_coder::{abi::AbiType, ToLog, generate_stubgen, solidity_interface, types::*};3use frame_support::traits::{Currency, ExistenceRequirement};3use frame_support::traits::{Currency, ExistenceRequirement};4use pallet_balances::WeightInfo;4use pallet_common::{5use pallet_common::{5 erc::{CommonEvmHandler, CrossAccountId, PrecompileHandle, PrecompileResult},6 erc::{CommonEvmHandler, CrossAccountId, PrecompileHandle, PrecompileResult},6 eth::CrossAddress,7 eth::CrossAddress,73 Ok(total.into())74 Ok(total.into())74 }75 }757676 // #[weight(<SelfWeightOf<T>>::transfer())]77 #[weight(<SelfWeightOf<T>>::transfer())]77 fn transfer(&mut self, caller: Caller, to: Address, amount: U256) -> Result<bool> {78 fn transfer(&mut self, caller: Caller, to: Address, amount: U256) -> Result<bool> {78 let caller = T::CrossAccountId::from_eth(caller);79 let caller = T::CrossAccountId::from_eth(caller);79 let to = T::CrossAccountId::from_eth(to);80 let to = T::CrossAccountId::from_eth(to);93 Ok(true)94 Ok(true)94 }95 }959696 // #[weight(<SelfWeightOf<T>>::transfer_from())]97 #[weight(<SelfWeightOf<T>>::transfer())]97 fn transfer_from(98 fn transfer_from(98 &mut self,99 &mut self,99 caller: Caller,100 caller: Caller,138 Ok(balance.into())139 Ok(balance.into())139 }140 }140141141 // #[weight(<SelfWeightOf<T>>::transfer())]142 #[weight(<SelfWeightOf<T>>::transfer())]142 fn transfer_cross(&mut self, caller: Caller, to: CrossAddress, amount: U256) -> Result<bool> {143 fn transfer_cross(&mut self, caller: Caller, to: CrossAddress, amount: U256) -> Result<bool> {143 let caller = T::CrossAccountId::from_eth(caller);144 let caller = T::CrossAccountId::from_eth(caller);144 let to = to.into_sub_cross_account::<T>()?;145 let to = to.into_sub_cross_account::<T>()?;158 Ok(true)159 Ok(true)159 }160 }160161161 // #[weight(<SelfWeightOf<T>>::transfer_from())]162 #[weight(<SelfWeightOf<T>>::transfer())]162 fn transfer_from_cross(163 fn transfer_from_cross(163 &mut self,164 &mut self,164 caller: Caller,165 caller: Caller,pallets/balances-adapter/src/lib.rsdiffbeforeafterboth11pub mod common;11pub mod common;12pub mod erc;12pub mod erc;1314pub(crate) type SelfWeightOf<T> = <T as Config>::WeightInfo;131514pub struct NativeFungibleHandle<T: Config>(SubstrateRecorder<T>);16pub struct NativeFungibleHandle<T: Config>(SubstrateRecorder<T>);15impl<T: Config> NativeFungibleHandle<T> {17impl<T: Config> NativeFungibleHandle<T> {34pub mod pallet {36pub mod pallet {35 use alloc::string::String;37 use alloc::string::String;36 use frame_support::{traits::Get, sp_runtime::DispatchResult};38 use frame_support::{traits::Get, sp_runtime::DispatchResult};39 use pallet_balances::WeightInfo;37 use sp_core::U256;40 use sp_core::U256;384139 #[pallet::config]42 #[pallet::config]50 type Name: Get<String>;53 type Name: Get<String>;51 type Symbol: Get<String>;54 type Symbol: Get<String>;5556 type WeightInfo: WeightInfo;52 }57 }53 #[pallet::pallet]58 #[pallet::pallet]54 pub struct Pallet<T>(_);59 pub struct Pallet<T>(_);runtime/common/config/pallets/mod.rsdiffbeforeafterboth94 type Decimals = Decimals;94 type Decimals = Decimals;95 type Name = Name;95 type Name = Name;96 type Symbol = Symbol;96 type Symbol = Symbol;97 type WeightInfo = pallet_balances::weights::SubstrateWeight<Self>;97}98}989999parameter_types! {100parameter_types! {tests/src/addCollectionAdmin.test.tsdiffbeforeafterboth161617import {IKeyringPair} from '@polkadot/types/types';17import {IKeyringPair} from '@polkadot/types/types';18import {itSub, usingPlaygrounds, expect} from './util';18import {itSub, usingPlaygrounds, expect} from './util';19import {NON_EXISTENT_COLLECTION_ID} from './util/playgrounds/types';192020describe('Integration Test addCollectionAdmin(collection_id, new_admin_id):', () => {21describe('Integration Test addCollectionAdmin(collection_id, new_admin_id):', () => {21 let donor: IKeyringPair;22 let donor: IKeyringPair;828383 itSub("Can't add collection admin of not existing collection.", async ({helper}) => {84 itSub("Can't add collection admin of not existing collection.", async ({helper}) => {84 const [alice, bob] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);85 const [alice, bob] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);85 const collectionId = (1 << 32) - 1;86 const collectionId = NON_EXISTENT_COLLECTION_ID;868787 await expect(helper.collection.addAdmin(alice, collectionId, {Substrate: bob.address})).to.be.rejectedWith(/common\.CollectionNotFound/);88 await expect(helper.collection.addAdmin(alice, collectionId, {Substrate: bob.address})).to.be.rejectedWith(/common\.CollectionNotFound/);8889tests/src/allowLists.test.tsdiffbeforeafterboth161617import {IKeyringPair} from '@polkadot/types/types';17import {IKeyringPair} from '@polkadot/types/types';18import {usingPlaygrounds, expect, itSub} from './util';18import {usingPlaygrounds, expect, itSub} from './util';19import {ICollectionPermissions} from './util/playgrounds/types';19import {ICollectionPermissions, NON_EXISTENT_COLLECTION_ID} from './util/playgrounds/types';202021describe('Integration Test ext. Allow list tests', () => {21describe('Integration Test ext. Allow list tests', () => {22 let alice: IKeyringPair;22 let alice: IKeyringPair;606061 describe('Negative', () => {61 describe('Negative', () => {62 itSub('Nobody can add address to allow list of non-existing collection', async ({helper}) => {62 itSub('Nobody can add address to allow list of non-existing collection', async ({helper}) => {63 const collectionId = (1<<32) - 1;63 const collectionId = NON_EXISTENT_COLLECTION_ID;64 await expect(helper.nft.addToAllowList(bob, collectionId, {Substrate: charlie.address}))64 await expect(helper.nft.addToAllowList(bob, collectionId, {Substrate: charlie.address}))65 .to.be.rejectedWith(/common\.CollectionNotFound/);65 .to.be.rejectedWith(/common\.CollectionNotFound/);66 });66 });140 });140 });141141142 itSub('Nobody can remove address from allow list of non-existing collection', async ({helper}) => {142 itSub('Nobody can remove address from allow list of non-existing collection', async ({helper}) => {143 const collectionId = (1<<32) - 1;143 const collectionId = NON_EXISTENT_COLLECTION_ID;144 await expect(helper.collection.removeFromAllowList(bob, collectionId, {Substrate: charlie.address}))144 await expect(helper.collection.removeFromAllowList(bob, collectionId, {Substrate: charlie.address}))145 .to.be.rejectedWith(/common\.CollectionNotFound/);145 .to.be.rejectedWith(/common\.CollectionNotFound/);146 });146 });tests/src/change-collection-owner.test.tsdiffbeforeafterboth161617import {IKeyringPair} from '@polkadot/types/types';17import {IKeyringPair} from '@polkadot/types/types';18import {usingPlaygrounds, expect, itSub} from './util';18import {usingPlaygrounds, expect, itSub} from './util';19import {NON_EXISTENT_COLLECTION_ID} from './util/playgrounds/types';192020describe('Integration Test changeCollectionOwner(collection_id, new_owner):', () => {21describe('Integration Test changeCollectionOwner(collection_id, new_owner):', () => {21 let alice: IKeyringPair;22 let alice: IKeyringPair;127 });128 });128129129 itSub('Can\'t change owner of a non-existing collection.', async ({helper}) => {130 itSub('Can\'t change owner of a non-existing collection.', async ({helper}) => {130 const collectionId = (1 << 32) - 1;131 const collectionId = NON_EXISTENT_COLLECTION_ID;131 const changeOwnerTx = () => helper.collection.changeOwner(bob, collectionId, bob.address);132 const changeOwnerTx = () => helper.collection.changeOwner(bob, collectionId, bob.address);132 await expect(changeOwnerTx()).to.be.rejectedWith(/common\.CollectionNotFound/);133 await expect(changeOwnerTx()).to.be.rejectedWith(/common\.CollectionNotFound/);133 });134 });tests/src/confirmSponsorship.test.tsdiffbeforeafterboth161617import {IKeyringPair} from '@polkadot/types/types';17import {IKeyringPair} from '@polkadot/types/types';18import {usingPlaygrounds, expect, itSub, Pallets} from './util';18import {usingPlaygrounds, expect, itSub, Pallets} from './util';19import {NON_EXISTENT_COLLECTION_ID} from './util/playgrounds/types';192020async function setSponsorHelper(collection: any, signer: IKeyringPair, sponsorAddress: string) {21async function setSponsorHelper(collection: any, signer: IKeyringPair, sponsorAddress: string) {21 await collection.setSponsor(signer, sponsorAddress);22 await collection.setSponsor(signer, sponsorAddress);198 });199 });199200200 itSub('(!negative test!) Confirm sponsorship for a collection that never existed', async ({helper}) => {201 itSub('(!negative test!) Confirm sponsorship for a collection that never existed', async ({helper}) => {201 const collectionId = (1 << 32) - 1;202 const collectionId = NON_EXISTENT_COLLECTION_ID;202 const confirmSponsorshipTx = () => helper.collection.confirmSponsorship(bob, collectionId);203 const confirmSponsorshipTx = () => helper.collection.confirmSponsorship(bob, collectionId);203 await expect(confirmSponsorshipTx()).to.be.rejectedWith(/common\.CollectionNotFound/);204 await expect(confirmSponsorshipTx()).to.be.rejectedWith(/common\.CollectionNotFound/);204 });205 });tests/src/eth/util/playgrounds/types.tsdiffbeforeafterboth49 value: OptionUint,49 value: OptionUint,50}50}515152export const NON_EXISTENT_COLLECTION_ID = 4_294_967_295;tests/src/removeCollectionAdmin.test.tsdiffbeforeafterboth161617import {IKeyringPair} from '@polkadot/types/types';17import {IKeyringPair} from '@polkadot/types/types';18import {itSub, usingPlaygrounds, expect} from './util';18import {itSub, usingPlaygrounds, expect} from './util';19import {NON_EXISTENT_COLLECTION_ID} from './util/playgrounds/types';192020describe('Integration Test removeCollectionAdmin(collection_id, account_id):', () => {21describe('Integration Test removeCollectionAdmin(collection_id, account_id):', () => {21 let alice: IKeyringPair;22 let alice: IKeyringPair;68 });69 });697070 itSub('Can\'t remove collection admin from not existing collection', async ({helper}) => {71 itSub('Can\'t remove collection admin from not existing collection', async ({helper}) => {71 const collectionId = (1 << 32) - 1;72 const collectionId = NON_EXISTENT_COLLECTION_ID;727373 await expect(helper.collection.removeAdmin(alice, collectionId, {Substrate: bob.address}))74 await expect(helper.collection.removeAdmin(alice, collectionId, {Substrate: bob.address}))74 .to.be.rejectedWith(/common\.CollectionNotFound/);75 .to.be.rejectedWith(/common\.CollectionNotFound/);tests/src/removeCollectionSponsor.test.tsdiffbeforeafterboth161617import {IKeyringPair} from '@polkadot/types/types';17import {IKeyringPair} from '@polkadot/types/types';18import {itSub, usingPlaygrounds, expect} from './util';18import {itSub, usingPlaygrounds, expect} from './util';19import {NON_EXISTENT_COLLECTION_ID} from './util/playgrounds/types';192020describe('integration test: ext. removeCollectionSponsor():', () => {21describe('integration test: ext. removeCollectionSponsor():', () => {21 let donor: IKeyringPair;22 let donor: IKeyringPair;91 });92 });929393 itSub('(!negative test!) Remove sponsor for a collection that never existed', async ({helper}) => {94 itSub('(!negative test!) Remove sponsor for a collection that never existed', async ({helper}) => {94 const collectionId = (1 << 32) - 1;95 const collectionId = NON_EXISTENT_COLLECTION_ID;95 await expect(helper.collection.removeSponsor(alice, collectionId)).to.be.rejectedWith(/common\.CollectionNotFound/);96 await expect(helper.collection.removeSponsor(alice, collectionId)).to.be.rejectedWith(/common\.CollectionNotFound/);96 });97 });9798tests/src/setCollectionLimits.test.tsdiffbeforeafterboth17// https://unique-network.readthedocs.io/en/latest/jsapi.html#setchainlimits17// https://unique-network.readthedocs.io/en/latest/jsapi.html#setchainlimits18import {IKeyringPair} from '@polkadot/types/types';18import {IKeyringPair} from '@polkadot/types/types';19import {itSub, usingPlaygrounds, expect} from './util';19import {itSub, usingPlaygrounds, expect} from './util';20import {NON_EXISTENT_COLLECTION_ID} from './util/playgrounds/types';202121const accountTokenOwnershipLimit = 0;22const accountTokenOwnershipLimit = 0;22const sponsoredDataSize = 0;23const sponsoredDataSize = 0;110 });111 });111112112 itSub('execute setCollectionLimits for not exists collection', async ({helper}) => {113 itSub('execute setCollectionLimits for not exists collection', async ({helper}) => {113 const nonExistentCollectionId = (1 << 32) - 1;114 const nonExistentCollectionId = NON_EXISTENT_COLLECTION_ID;114 await expect(helper.collection.setLimits(115 await expect(helper.collection.setLimits(115 alice,116 alice,116 nonExistentCollectionId,117 nonExistentCollectionId,tests/src/setCollectionSponsor.test.tsdiffbeforeafterboth161617import {IKeyringPair} from '@polkadot/types/types';17import {IKeyringPair} from '@polkadot/types/types';18import {itSub, usingPlaygrounds, expect, Pallets} from './util';18import {itSub, usingPlaygrounds, expect, Pallets} from './util';19import {NON_EXISTENT_COLLECTION_ID} from './util/playgrounds/types';192020describe('integration test: ext. setCollectionSponsor():', () => {21describe('integration test: ext. setCollectionSponsor():', () => {21 let alice: IKeyringPair;22 let alice: IKeyringPair;105 });106 });106107107 itSub('(!negative test!) Add sponsor to a collection that never existed', async ({helper}) => {108 itSub('(!negative test!) Add sponsor to a collection that never existed', async ({helper}) => {108 const collectionId = (1 << 32) - 1;109 const collectionId = NON_EXISTENT_COLLECTION_ID;109 await expect(helper.collection.setSponsor(alice, collectionId, bob.address))110 await expect(helper.collection.setSponsor(alice, collectionId, bob.address))110 .to.be.rejectedWith(/common\.CollectionNotFound/);111 .to.be.rejectedWith(/common\.CollectionNotFound/);111 });112 });tests/src/setPermissions.test.tsdiffbeforeafterboth161617import {IKeyringPair} from '@polkadot/types/types';17import {IKeyringPair} from '@polkadot/types/types';18import {itSub, usingPlaygrounds, expect} from './util';18import {itSub, usingPlaygrounds, expect} from './util';19import {NON_EXISTENT_COLLECTION_ID} from './util/playgrounds/types';192020describe('Integration Test: Set Permissions', () => {21describe('Integration Test: Set Permissions', () => {21 let alice: IKeyringPair;22 let alice: IKeyringPair;85 });86 });868787 itSub('fails on not existing collection', async ({helper}) => {88 itSub('fails on not existing collection', async ({helper}) => {88 const collectionId = (1 << 32) - 1;89 const collectionId = NON_EXISTENT_COLLECTION_ID;89 await expect(helper.collection.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: true}))90 await expect(helper.collection.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: true}))90 .to.be.rejectedWith(/common\.CollectionNotFound/);91 .to.be.rejectedWith(/common\.CollectionNotFound/);91 });92 });tests/src/transfer.test.tsdiffbeforeafterboth17import {IKeyringPair} from '@polkadot/types/types';17import {IKeyringPair} from '@polkadot/types/types';18import {itEth, usingEthPlaygrounds} from './eth/util';18import {itEth, usingEthPlaygrounds} from './eth/util';19import {itSub, Pallets, usingPlaygrounds, expect} from './util';19import {itSub, Pallets, usingPlaygrounds, expect} from './util';20import {NON_EXISTENT_COLLECTION_ID} from './eth/util/playgrounds/types';20import {NON_EXISTENT_COLLECTION_ID} from './util/playgrounds/types';212122describe('Integration Test Transfer(recipient, collection_id, item_id, value)', () => {22describe('Integration Test Transfer(recipient, collection_id, item_id, value)', () => {23 let donor: IKeyringPair;23 let donor: IKeyringPair;tests/src/transferFrom.test.tsdiffbeforeafterboth161617import {IKeyringPair} from '@polkadot/types/types';17import {IKeyringPair} from '@polkadot/types/types';18import {itSub, Pallets, usingPlaygrounds, expect} from './util';18import {itSub, Pallets, usingPlaygrounds, expect} from './util';19import {NON_EXISTENT_COLLECTION_ID} from './eth/util/playgrounds/types';19import {NON_EXISTENT_COLLECTION_ID} from './util/playgrounds/types';202021describe('Integration Test transferFrom(from, recipient, collection_id, item_id, value):', () => {21describe('Integration Test transferFrom(from, recipient, collection_id, item_id, value):', () => {22 let alice: IKeyringPair;22 let alice: IKeyringPair;tests/src/util/playgrounds/types.tsdiffbeforeafterboth334import {IKeyringPair} from '@polkadot/types/types';4import {IKeyringPair} from '@polkadot/types/types';56export const NON_EXISTENT_COLLECTION_ID = 4_294_967_295;576export interface IEvent {8export interface IEvent {7 section: string;9 section: string;