From 5a3127a55154160c569d27e68c4298b61752fb4f Mon Sep 17 00:00:00 2001 From: Trubnikov Sergey Date: Fri, 28 Apr 2023 12:18:38 +0000 Subject: [PATCH] fix tests and weights --- --- a/pallets/balances-adapter/src/erc.rs +++ b/pallets/balances-adapter/src/erc.rs @@ -1,6 +1,7 @@ -use crate::{Config, NativeFungibleHandle}; +use crate::{Config, NativeFungibleHandle, SelfWeightOf}; use evm_coder::{abi::AbiType, ToLog, generate_stubgen, solidity_interface, types::*}; use frame_support::traits::{Currency, ExistenceRequirement}; +use pallet_balances::WeightInfo; use pallet_common::{ erc::{CommonEvmHandler, CrossAccountId, PrecompileHandle, PrecompileResult}, eth::CrossAddress, @@ -73,7 +74,7 @@ Ok(total.into()) } - // #[weight(>::transfer())] + #[weight(>::transfer())] fn transfer(&mut self, caller: Caller, to: Address, amount: U256) -> Result { let caller = T::CrossAccountId::from_eth(caller); let to = T::CrossAccountId::from_eth(to); @@ -93,7 +94,7 @@ Ok(true) } - // #[weight(>::transfer_from())] + #[weight(>::transfer())] fn transfer_from( &mut self, caller: Caller, @@ -138,7 +139,7 @@ Ok(balance.into()) } - // #[weight(>::transfer())] + #[weight(>::transfer())] fn transfer_cross(&mut self, caller: Caller, to: CrossAddress, amount: U256) -> Result { let caller = T::CrossAccountId::from_eth(caller); let to = to.into_sub_cross_account::()?; @@ -158,7 +159,7 @@ Ok(true) } - // #[weight(>::transfer_from())] + #[weight(>::transfer())] fn transfer_from_cross( &mut self, caller: Caller, --- a/pallets/balances-adapter/src/lib.rs +++ b/pallets/balances-adapter/src/lib.rs @@ -11,6 +11,8 @@ pub mod common; pub mod erc; +pub(crate) type SelfWeightOf = ::WeightInfo; + pub struct NativeFungibleHandle(SubstrateRecorder); impl NativeFungibleHandle { pub fn new() -> NativeFungibleHandle { @@ -34,6 +36,7 @@ pub mod pallet { use alloc::string::String; use frame_support::{traits::Get, sp_runtime::DispatchResult}; + use pallet_balances::WeightInfo; use sp_core::U256; #[pallet::config] @@ -49,6 +52,8 @@ type Decimals: Get; type Name: Get; type Symbol: Get; + + type WeightInfo: WeightInfo; } #[pallet::pallet] pub struct Pallet(_); --- a/runtime/common/config/pallets/mod.rs +++ b/runtime/common/config/pallets/mod.rs @@ -94,6 +94,7 @@ type Decimals = Decimals; type Name = Name; type Symbol = Symbol; + type WeightInfo = pallet_balances::weights::SubstrateWeight; } parameter_types! { --- a/tests/src/addCollectionAdmin.test.ts +++ b/tests/src/addCollectionAdmin.test.ts @@ -16,6 +16,7 @@ import {IKeyringPair} from '@polkadot/types/types'; import {itSub, usingPlaygrounds, expect} from './util'; +import {NON_EXISTENT_COLLECTION_ID} from './util/playgrounds/types'; describe('Integration Test addCollectionAdmin(collection_id, new_admin_id):', () => { let donor: IKeyringPair; @@ -82,7 +83,7 @@ itSub("Can't add collection admin of not existing collection.", async ({helper}) => { const [alice, bob] = await helper.arrange.createAccounts([10n, 10n, 10n], donor); - const collectionId = (1 << 32) - 1; + const collectionId = NON_EXISTENT_COLLECTION_ID; await expect(helper.collection.addAdmin(alice, collectionId, {Substrate: bob.address})).to.be.rejectedWith(/common\.CollectionNotFound/); --- a/tests/src/allowLists.test.ts +++ b/tests/src/allowLists.test.ts @@ -16,7 +16,7 @@ import {IKeyringPair} from '@polkadot/types/types'; import {usingPlaygrounds, expect, itSub} from './util'; -import {ICollectionPermissions} from './util/playgrounds/types'; +import {ICollectionPermissions, NON_EXISTENT_COLLECTION_ID} from './util/playgrounds/types'; describe('Integration Test ext. Allow list tests', () => { let alice: IKeyringPair; @@ -60,7 +60,7 @@ describe('Negative', () => { itSub('Nobody can add address to allow list of non-existing collection', async ({helper}) => { - const collectionId = (1<<32) - 1; + const collectionId = NON_EXISTENT_COLLECTION_ID; await expect(helper.nft.addToAllowList(bob, collectionId, {Substrate: charlie.address})) .to.be.rejectedWith(/common\.CollectionNotFound/); }); @@ -140,7 +140,7 @@ }); itSub('Nobody can remove address from allow list of non-existing collection', async ({helper}) => { - const collectionId = (1<<32) - 1; + const collectionId = NON_EXISTENT_COLLECTION_ID; await expect(helper.collection.removeFromAllowList(bob, collectionId, {Substrate: charlie.address})) .to.be.rejectedWith(/common\.CollectionNotFound/); }); --- a/tests/src/change-collection-owner.test.ts +++ b/tests/src/change-collection-owner.test.ts @@ -16,6 +16,7 @@ import {IKeyringPair} from '@polkadot/types/types'; import {usingPlaygrounds, expect, itSub} from './util'; +import {NON_EXISTENT_COLLECTION_ID} from './util/playgrounds/types'; describe('Integration Test changeCollectionOwner(collection_id, new_owner):', () => { let alice: IKeyringPair; @@ -127,7 +128,7 @@ }); itSub('Can\'t change owner of a non-existing collection.', async ({helper}) => { - const collectionId = (1 << 32) - 1; + const collectionId = NON_EXISTENT_COLLECTION_ID; const changeOwnerTx = () => helper.collection.changeOwner(bob, collectionId, bob.address); await expect(changeOwnerTx()).to.be.rejectedWith(/common\.CollectionNotFound/); }); --- a/tests/src/confirmSponsorship.test.ts +++ b/tests/src/confirmSponsorship.test.ts @@ -16,6 +16,7 @@ import {IKeyringPair} from '@polkadot/types/types'; import {usingPlaygrounds, expect, itSub, Pallets} from './util'; +import {NON_EXISTENT_COLLECTION_ID} from './util/playgrounds/types'; async function setSponsorHelper(collection: any, signer: IKeyringPair, sponsorAddress: string) { await collection.setSponsor(signer, sponsorAddress); @@ -198,7 +199,7 @@ }); itSub('(!negative test!) Confirm sponsorship for a collection that never existed', async ({helper}) => { - const collectionId = (1 << 32) - 1; + const collectionId = NON_EXISTENT_COLLECTION_ID; const confirmSponsorshipTx = () => helper.collection.confirmSponsorship(bob, collectionId); await expect(confirmSponsorshipTx()).to.be.rejectedWith(/common\.CollectionNotFound/); }); --- a/tests/src/eth/util/playgrounds/types.ts +++ b/tests/src/eth/util/playgrounds/types.ts @@ -48,5 +48,3 @@ field: CollectionLimitField, value: OptionUint, } - -export const NON_EXISTENT_COLLECTION_ID = 4_294_967_295; \ No newline at end of file --- a/tests/src/removeCollectionAdmin.test.ts +++ b/tests/src/removeCollectionAdmin.test.ts @@ -16,6 +16,7 @@ import {IKeyringPair} from '@polkadot/types/types'; import {itSub, usingPlaygrounds, expect} from './util'; +import {NON_EXISTENT_COLLECTION_ID} from './util/playgrounds/types'; describe('Integration Test removeCollectionAdmin(collection_id, account_id):', () => { let alice: IKeyringPair; @@ -68,7 +69,7 @@ }); itSub('Can\'t remove collection admin from not existing collection', async ({helper}) => { - const collectionId = (1 << 32) - 1; + const collectionId = NON_EXISTENT_COLLECTION_ID; await expect(helper.collection.removeAdmin(alice, collectionId, {Substrate: bob.address})) .to.be.rejectedWith(/common\.CollectionNotFound/); --- a/tests/src/removeCollectionSponsor.test.ts +++ b/tests/src/removeCollectionSponsor.test.ts @@ -16,6 +16,7 @@ import {IKeyringPair} from '@polkadot/types/types'; import {itSub, usingPlaygrounds, expect} from './util'; +import {NON_EXISTENT_COLLECTION_ID} from './util/playgrounds/types'; describe('integration test: ext. removeCollectionSponsor():', () => { let donor: IKeyringPair; @@ -91,7 +92,7 @@ }); itSub('(!negative test!) Remove sponsor for a collection that never existed', async ({helper}) => { - const collectionId = (1 << 32) - 1; + const collectionId = NON_EXISTENT_COLLECTION_ID; await expect(helper.collection.removeSponsor(alice, collectionId)).to.be.rejectedWith(/common\.CollectionNotFound/); }); --- a/tests/src/setCollectionLimits.test.ts +++ b/tests/src/setCollectionLimits.test.ts @@ -17,6 +17,7 @@ // https://unique-network.readthedocs.io/en/latest/jsapi.html#setchainlimits import {IKeyringPair} from '@polkadot/types/types'; import {itSub, usingPlaygrounds, expect} from './util'; +import {NON_EXISTENT_COLLECTION_ID} from './util/playgrounds/types'; const accountTokenOwnershipLimit = 0; const sponsoredDataSize = 0; @@ -110,7 +111,7 @@ }); itSub('execute setCollectionLimits for not exists collection', async ({helper}) => { - const nonExistentCollectionId = (1 << 32) - 1; + const nonExistentCollectionId = NON_EXISTENT_COLLECTION_ID; await expect(helper.collection.setLimits( alice, nonExistentCollectionId, --- a/tests/src/setCollectionSponsor.test.ts +++ b/tests/src/setCollectionSponsor.test.ts @@ -16,6 +16,7 @@ import {IKeyringPair} from '@polkadot/types/types'; import {itSub, usingPlaygrounds, expect, Pallets} from './util'; +import {NON_EXISTENT_COLLECTION_ID} from './util/playgrounds/types'; describe('integration test: ext. setCollectionSponsor():', () => { let alice: IKeyringPair; @@ -105,7 +106,7 @@ }); itSub('(!negative test!) Add sponsor to a collection that never existed', async ({helper}) => { - const collectionId = (1 << 32) - 1; + const collectionId = NON_EXISTENT_COLLECTION_ID; await expect(helper.collection.setSponsor(alice, collectionId, bob.address)) .to.be.rejectedWith(/common\.CollectionNotFound/); }); --- a/tests/src/setPermissions.test.ts +++ b/tests/src/setPermissions.test.ts @@ -16,6 +16,7 @@ import {IKeyringPair} from '@polkadot/types/types'; import {itSub, usingPlaygrounds, expect} from './util'; +import {NON_EXISTENT_COLLECTION_ID} from './util/playgrounds/types'; describe('Integration Test: Set Permissions', () => { let alice: IKeyringPair; @@ -85,7 +86,7 @@ }); itSub('fails on not existing collection', async ({helper}) => { - const collectionId = (1 << 32) - 1; + const collectionId = NON_EXISTENT_COLLECTION_ID; await expect(helper.collection.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: true})) .to.be.rejectedWith(/common\.CollectionNotFound/); }); --- a/tests/src/transfer.test.ts +++ b/tests/src/transfer.test.ts @@ -17,7 +17,7 @@ import {IKeyringPair} from '@polkadot/types/types'; import {itEth, usingEthPlaygrounds} from './eth/util'; import {itSub, Pallets, usingPlaygrounds, expect} from './util'; -import {NON_EXISTENT_COLLECTION_ID} from './eth/util/playgrounds/types'; +import {NON_EXISTENT_COLLECTION_ID} from './util/playgrounds/types'; describe('Integration Test Transfer(recipient, collection_id, item_id, value)', () => { let donor: IKeyringPair; --- a/tests/src/transferFrom.test.ts +++ b/tests/src/transferFrom.test.ts @@ -16,7 +16,7 @@ import {IKeyringPair} from '@polkadot/types/types'; import {itSub, Pallets, usingPlaygrounds, expect} from './util'; -import {NON_EXISTENT_COLLECTION_ID} from './eth/util/playgrounds/types'; +import {NON_EXISTENT_COLLECTION_ID} from './util/playgrounds/types'; describe('Integration Test transferFrom(from, recipient, collection_id, item_id, value):', () => { let alice: IKeyringPair; --- a/tests/src/util/playgrounds/types.ts +++ b/tests/src/util/playgrounds/types.ts @@ -3,6 +3,8 @@ import {IKeyringPair} from '@polkadot/types/types'; +export const NON_EXISTENT_COLLECTION_ID = 4_294_967_295; + export interface IEvent { section: string; method: string; -- gitstuff