git.delta.rocks / unique-network / refs/commits / 5a3127a55154

difftreelog

fix tests and weights

Trubnikov Sergey2023-04-28parent: #9e5de5c.patch.diff
in: master

16 files changed

modifiedpallets/balances-adapter/src/erc.rsdiffbeforeafterboth
1use 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 }
7576
76 // #[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 }
9596
96 // #[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 }
140141
141 // #[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 }
160161
161 // #[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,
modifiedpallets/balances-adapter/src/lib.rsdiffbeforeafterboth
11pub mod common;11pub mod common;
12pub mod erc;12pub mod erc;
13
14pub(crate) type SelfWeightOf<T> = <T as Config>::WeightInfo;
1315
14pub 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;
3841
39 #[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>;
55
56 type WeightInfo: WeightInfo;
52 }57 }
53 #[pallet::pallet]58 #[pallet::pallet]
54 pub struct Pallet<T>(_);59 pub struct Pallet<T>(_);
modifiedruntime/common/config/pallets/mod.rsdiffbeforeafterboth
94 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}
9899
99parameter_types! {100parameter_types! {
modifiedtests/src/addCollectionAdmin.test.tsdiffbeforeafterboth
1616
17import {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';
1920
20describe('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;
8283
83 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;
8687
87 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/);
8889
modifiedtests/src/allowLists.test.tsdiffbeforeafterboth
1616
17import {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';
2020
21describe('Integration Test ext. Allow list tests', () => {21describe('Integration Test ext. Allow list tests', () => {
22 let alice: IKeyringPair;22 let alice: IKeyringPair;
6060
61 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 });
141141
142 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 });
modifiedtests/src/change-collection-owner.test.tsdiffbeforeafterboth
1616
17import {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';
1920
20describe('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 });
128129
129 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 });
modifiedtests/src/confirmSponsorship.test.tsdiffbeforeafterboth
1616
17import {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';
1920
20async 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 });
199200
200 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 });
modifiedtests/src/eth/util/playgrounds/types.tsdiffbeforeafterboth
49 value: OptionUint,49 value: OptionUint,
50}50}
5151
52export const NON_EXISTENT_COLLECTION_ID = 4_294_967_295;
modifiedtests/src/removeCollectionAdmin.test.tsdiffbeforeafterboth
1616
17import {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';
1920
20describe('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 });
6970
70 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;
7273
73 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/);
modifiedtests/src/removeCollectionSponsor.test.tsdiffbeforeafterboth
1616
17import {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';
1920
20describe('integration test: ext. removeCollectionSponsor():', () => {21describe('integration test: ext. removeCollectionSponsor():', () => {
21 let donor: IKeyringPair;22 let donor: IKeyringPair;
91 });92 });
9293
93 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 });
9798
modifiedtests/src/setCollectionLimits.test.tsdiffbeforeafterboth
17// https://unique-network.readthedocs.io/en/latest/jsapi.html#setchainlimits17// https://unique-network.readthedocs.io/en/latest/jsapi.html#setchainlimits
18import {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';
2021
21const accountTokenOwnershipLimit = 0;22const accountTokenOwnershipLimit = 0;
22const sponsoredDataSize = 0;23const sponsoredDataSize = 0;
110 });111 });
111112
112 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,
modifiedtests/src/setCollectionSponsor.test.tsdiffbeforeafterboth
1616
17import {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';
1920
20describe('integration test: ext. setCollectionSponsor():', () => {21describe('integration test: ext. setCollectionSponsor():', () => {
21 let alice: IKeyringPair;22 let alice: IKeyringPair;
105 });106 });
106107
107 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 });
modifiedtests/src/setPermissions.test.tsdiffbeforeafterboth
1616
17import {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';
1920
20describe('Integration Test: Set Permissions', () => {21describe('Integration Test: Set Permissions', () => {
21 let alice: IKeyringPair;22 let alice: IKeyringPair;
85 });86 });
8687
87 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 });
modifiedtests/src/transfer.test.tsdiffbeforeafterboth
17import {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';
2121
22describe('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;
modifiedtests/src/transferFrom.test.tsdiffbeforeafterboth
1616
17import {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';
2020
21describe('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;
modifiedtests/src/util/playgrounds/types.tsdiffbeforeafterboth
33
4import {IKeyringPair} from '@polkadot/types/types';4import {IKeyringPair} from '@polkadot/types/types';
5
6export const NON_EXISTENT_COLLECTION_ID = 4_294_967_295;
57
6export interface IEvent {8export interface IEvent {
7 section: string;9 section: string;