difftreelog
fix tests and weights
in: master
16 files changed
pallets/balances-adapter/src/erc.rsdiffbeforeafterboth--- 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(<SelfWeightOf<T>>::transfer())]
+ #[weight(<SelfWeightOf<T>>::transfer())]
fn transfer(&mut self, caller: Caller, to: Address, amount: U256) -> Result<bool> {
let caller = T::CrossAccountId::from_eth(caller);
let to = T::CrossAccountId::from_eth(to);
@@ -93,7 +94,7 @@
Ok(true)
}
- // #[weight(<SelfWeightOf<T>>::transfer_from())]
+ #[weight(<SelfWeightOf<T>>::transfer())]
fn transfer_from(
&mut self,
caller: Caller,
@@ -138,7 +139,7 @@
Ok(balance.into())
}
- // #[weight(<SelfWeightOf<T>>::transfer())]
+ #[weight(<SelfWeightOf<T>>::transfer())]
fn transfer_cross(&mut self, caller: Caller, to: CrossAddress, amount: U256) -> Result<bool> {
let caller = T::CrossAccountId::from_eth(caller);
let to = to.into_sub_cross_account::<T>()?;
@@ -158,7 +159,7 @@
Ok(true)
}
- // #[weight(<SelfWeightOf<T>>::transfer_from())]
+ #[weight(<SelfWeightOf<T>>::transfer())]
fn transfer_from_cross(
&mut self,
caller: Caller,
pallets/balances-adapter/src/lib.rsdiffbeforeafterboth--- 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<T> = <T as Config>::WeightInfo;
+
pub struct NativeFungibleHandle<T: Config>(SubstrateRecorder<T>);
impl<T: Config> NativeFungibleHandle<T> {
pub fn new() -> NativeFungibleHandle<T> {
@@ -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<u8>;
type Name: Get<String>;
type Symbol: Get<String>;
+
+ type WeightInfo: WeightInfo;
}
#[pallet::pallet]
pub struct Pallet<T>(_);
runtime/common/config/pallets/mod.rsdiffbeforeafterboth--- 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<Self>;
}
parameter_types! {
tests/src/addCollectionAdmin.test.tsdiffbeforeafterboth--- 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/);
tests/src/allowLists.test.tsdiffbeforeafterboth--- 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/);
});
tests/src/change-collection-owner.test.tsdiffbeforeafterboth--- 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/);
});
tests/src/confirmSponsorship.test.tsdiffbeforeafterboth--- 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/);
});
tests/src/eth/util/playgrounds/types.tsdiffbeforeafterboth--- 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
tests/src/removeCollectionAdmin.test.tsdiffbeforeafterboth--- 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/);
tests/src/removeCollectionSponsor.test.tsdiffbeforeafterboth--- 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/);
});
tests/src/setCollectionLimits.test.tsdiffbeforeafterboth--- 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,
tests/src/setCollectionSponsor.test.tsdiffbeforeafterboth1// 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/>.1617import {IKeyringPair} from '@polkadot/types/types';18import {itSub, usingPlaygrounds, expect, Pallets} from './util';1920describe('integration test: ext. setCollectionSponsor():', () => {21 let alice: IKeyringPair;22 let bob: IKeyringPair;23 let charlie: IKeyringPair;2425 before(async () => {26 await usingPlaygrounds(async (helper, privateKey) => {27 const donor = await privateKey({url: import.meta.url});28 [alice, bob, charlie] = await helper.arrange.createAccounts([20n, 10n, 10n], donor);29 });30 });3132 itSub('Set NFT collection sponsor', async ({helper}) => {33 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionSponsor-1-NFT', tokenPrefix: 'SCS'});34 await expect(collection.setSponsor(alice, bob.address)).to.be.not.rejected;3536 expect((await collection.getData())?.raw.sponsorship).to.deep.equal({37 Unconfirmed: bob.address,38 });39 });4041 itSub('Set Fungible collection sponsor', async ({helper}) => {42 const collection = await helper.ft.mintCollection(alice, {name: 'SetCollectionSponsor-1-FT', tokenPrefix: 'SCS'});43 await expect(collection.setSponsor(alice, bob.address)).to.be.not.rejected;4445 expect((await collection.getData())?.raw.sponsorship).to.deep.equal({46 Unconfirmed: bob.address,47 });48 });4950 itSub.ifWithPallets('Set ReFungible collection sponsor', [Pallets.ReFungible], async ({helper}) => {51 const collection = await helper.rft.mintCollection(alice, {name: 'SetCollectionSponsor-1-RFT', tokenPrefix: 'SCS'});52 await expect(collection.setSponsor(alice, bob.address)).to.be.not.rejected;5354 expect((await collection.getData())?.raw.sponsorship).to.deep.equal({55 Unconfirmed: bob.address,56 });57 });5859 itSub('Set the same sponsor repeatedly', async ({helper}) => {60 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionSponsor-2', tokenPrefix: 'SCS'});61 await expect(collection.setSponsor(alice, bob.address)).to.be.not.rejected;62 await expect(collection.setSponsor(alice, bob.address)).to.be.not.rejected;6364 expect((await collection.getData())?.raw.sponsorship).to.deep.equal({65 Unconfirmed: bob.address,66 });67 });6869 itSub('Replace collection sponsor', async ({helper}) => {70 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionSponsor-3', tokenPrefix: 'SCS'});71 await expect(collection.setSponsor(alice, bob.address)).to.be.not.rejected;72 await expect(collection.setSponsor(alice, charlie.address)).to.be.not.rejected;7374 expect((await collection.getData())?.raw.sponsorship).to.deep.equal({75 Unconfirmed: charlie.address,76 });77 });7879 itSub('Collection admin add sponsor', async ({helper}) => {80 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionSponsor-4', tokenPrefix: 'SCS'});81 await collection.addAdmin(alice, {Substrate: bob.address});82 await expect(collection.setSponsor(bob, charlie.address)).to.be.not.rejected;8384 expect((await collection.getData())?.raw.sponsorship).to.deep.equal({85 Unconfirmed: charlie.address,86 });87 });88});8990describe('(!negative test!) integration test: ext. setCollectionSponsor():', () => {91 let alice: IKeyringPair;92 let bob: IKeyringPair;9394 before(async () => {95 await usingPlaygrounds(async (helper, privateKey) => {96 const donor = await privateKey({url: import.meta.url});97 [alice, bob] = await helper.arrange.createAccounts([10n, 5n], donor);98 });99 });100101 itSub('(!negative test!) Add sponsor with a non-owner', async ({helper}) => {102 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionSponsor-Neg-1', tokenPrefix: 'SCS'});103 await expect(collection.setSponsor(bob, bob.address))104 .to.be.rejectedWith(/common\.NoPermission/);105 });106107 itSub('(!negative test!) Add sponsor to a collection that never existed', async ({helper}) => {108 const collectionId = (1 << 32) - 1;109 await expect(helper.collection.setSponsor(alice, collectionId, bob.address))110 .to.be.rejectedWith(/common\.CollectionNotFound/);111 });112113 itSub('(!negative test!) Add sponsor to a collection that was destroyed', async ({helper}) => {114 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionSponsor-Neg-2', tokenPrefix: 'SCS'});115 await collection.burn(alice);116 await expect(collection.setSponsor(alice, bob.address))117 .to.be.rejectedWith(/common\.CollectionNotFound/);118 });119});1// 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/>.1617import {IKeyringPair} from '@polkadot/types/types';18import {itSub, usingPlaygrounds, expect, Pallets} from './util';19import {NON_EXISTENT_COLLECTION_ID} from './util/playgrounds/types';2021describe('integration test: ext. setCollectionSponsor():', () => {22 let alice: IKeyringPair;23 let bob: IKeyringPair;24 let charlie: IKeyringPair;2526 before(async () => {27 await usingPlaygrounds(async (helper, privateKey) => {28 const donor = await privateKey({url: import.meta.url});29 [alice, bob, charlie] = await helper.arrange.createAccounts([20n, 10n, 10n], donor);30 });31 });3233 itSub('Set NFT collection sponsor', async ({helper}) => {34 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionSponsor-1-NFT', tokenPrefix: 'SCS'});35 await expect(collection.setSponsor(alice, bob.address)).to.be.not.rejected;3637 expect((await collection.getData())?.raw.sponsorship).to.deep.equal({38 Unconfirmed: bob.address,39 });40 });4142 itSub('Set Fungible collection sponsor', async ({helper}) => {43 const collection = await helper.ft.mintCollection(alice, {name: 'SetCollectionSponsor-1-FT', tokenPrefix: 'SCS'});44 await expect(collection.setSponsor(alice, bob.address)).to.be.not.rejected;4546 expect((await collection.getData())?.raw.sponsorship).to.deep.equal({47 Unconfirmed: bob.address,48 });49 });5051 itSub.ifWithPallets('Set ReFungible collection sponsor', [Pallets.ReFungible], async ({helper}) => {52 const collection = await helper.rft.mintCollection(alice, {name: 'SetCollectionSponsor-1-RFT', tokenPrefix: 'SCS'});53 await expect(collection.setSponsor(alice, bob.address)).to.be.not.rejected;5455 expect((await collection.getData())?.raw.sponsorship).to.deep.equal({56 Unconfirmed: bob.address,57 });58 });5960 itSub('Set the same sponsor repeatedly', async ({helper}) => {61 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionSponsor-2', tokenPrefix: 'SCS'});62 await expect(collection.setSponsor(alice, bob.address)).to.be.not.rejected;63 await expect(collection.setSponsor(alice, bob.address)).to.be.not.rejected;6465 expect((await collection.getData())?.raw.sponsorship).to.deep.equal({66 Unconfirmed: bob.address,67 });68 });6970 itSub('Replace collection sponsor', async ({helper}) => {71 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionSponsor-3', tokenPrefix: 'SCS'});72 await expect(collection.setSponsor(alice, bob.address)).to.be.not.rejected;73 await expect(collection.setSponsor(alice, charlie.address)).to.be.not.rejected;7475 expect((await collection.getData())?.raw.sponsorship).to.deep.equal({76 Unconfirmed: charlie.address,77 });78 });7980 itSub('Collection admin add sponsor', async ({helper}) => {81 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionSponsor-4', tokenPrefix: 'SCS'});82 await collection.addAdmin(alice, {Substrate: bob.address});83 await expect(collection.setSponsor(bob, charlie.address)).to.be.not.rejected;8485 expect((await collection.getData())?.raw.sponsorship).to.deep.equal({86 Unconfirmed: charlie.address,87 });88 });89});9091describe('(!negative test!) integration test: ext. setCollectionSponsor():', () => {92 let alice: IKeyringPair;93 let bob: IKeyringPair;9495 before(async () => {96 await usingPlaygrounds(async (helper, privateKey) => {97 const donor = await privateKey({url: import.meta.url});98 [alice, bob] = await helper.arrange.createAccounts([10n, 5n], donor);99 });100 });101102 itSub('(!negative test!) Add sponsor with a non-owner', async ({helper}) => {103 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionSponsor-Neg-1', tokenPrefix: 'SCS'});104 await expect(collection.setSponsor(bob, bob.address))105 .to.be.rejectedWith(/common\.NoPermission/);106 });107108 itSub('(!negative test!) Add sponsor to a collection that never existed', async ({helper}) => {109 const collectionId = NON_EXISTENT_COLLECTION_ID;110 await expect(helper.collection.setSponsor(alice, collectionId, bob.address))111 .to.be.rejectedWith(/common\.CollectionNotFound/);112 });113114 itSub('(!negative test!) Add sponsor to a collection that was destroyed', async ({helper}) => {115 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionSponsor-Neg-2', tokenPrefix: 'SCS'});116 await collection.burn(alice);117 await expect(collection.setSponsor(alice, bob.address))118 .to.be.rejectedWith(/common\.CollectionNotFound/);119 });120});tests/src/setPermissions.test.tsdiffbeforeafterboth--- 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/);
});
tests/src/transfer.test.tsdiffbeforeafterboth--- 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;
tests/src/transferFrom.test.tsdiffbeforeafterboth--- 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;
tests/src/util/playgrounds/types.tsdiffbeforeafterboth--- 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;