git.delta.rocks / unique-network / refs/commits / 6dd2322471d4

difftreelog

refactor `collection_limits`, add docs for `CollectionLimits`

PraetorP2022-12-16parent: #07c2857.patch.diff
in: master

9 files changed

modifiedpallets/common/src/erc.rsdiffbeforeafterboth
358 ),358 ),
359 limits359 limits
360 .sponsored_data_rate_limit360 .sponsored_data_rate_limit
361 .map(|limit| {361 .and_then(|limit| {
362 (
363 EvmCollectionLimits::SponsoredDataRateLimit,
364 match limit {
365 SponsoringRateLimit::Blocks(_) => true,362 if let SponsoringRateLimit::Blocks(blocks) = limit {
366 _ => false,363 Some((
367 },
368 match limit {
369 SponsoringRateLimit::Blocks(blocks) => blocks.into(),364 EvmCollectionLimits::SponsoredDataRateLimit,
370 _ => Default::default(),365 true,
366 blocks.into(),
367 ))
371 },368 } else {
372 )369 None
370 }
373 })371 })
374 .unwrap_or((372 .unwrap_or((
375 EvmCollectionLimits::SponsoredDataRateLimit,373 EvmCollectionLimits::SponsoredDataRateLimit,
modifiedpallets/common/src/eth.rsdiffbeforeafterboth
156 }156 }
157}157}
158
159/// [`CollectionLimits`](up_data_structs::CollectionLimits) representation for EVM.
158#[derive(Debug, Default, Clone, Copy, AbiCoder)]160#[derive(Debug, Default, Clone, Copy, AbiCoder)]
159#[repr(u8)]161#[repr(u8)]
160pub enum CollectionLimits {162pub enum CollectionLimits {
modifiedtests/src/eth/collectionLimits.test.tsdiffbeforeafterboth
1import {IKeyringPair} from '@polkadot/types/types';1import {IKeyringPair} from '@polkadot/types/types';
2import {Pallets} from '../util';2import {Pallets} from '../util';
3import {CollectionLimits, expect, itEth, usingEthPlaygrounds} from './util';3import {expect, itEth, usingEthPlaygrounds} from './util';
4import {CollectionLimits} from './util/playgrounds/types';
45
56
6describe('Can set collection limits', () => {7describe('Can set collection limits', () => {
62 // Check limits from eth:63 // Check limits from eth:
63 const limitsEvm = await collectionEvm.methods.collectionLimits().call({from: owner});64 const limitsEvm = await collectionEvm.methods.collectionLimits().call({from: owner});
64 expect(limitsEvm).to.have.length(9);65 expect(limitsEvm).to.have.length(9);
65 expect(limitsEvm[0]).to.deep.eq(['0', true, limits.accountTokenOwnershipLimit.toString()]);66 expect(limitsEvm[0]).to.deep.eq([CollectionLimits.AccountTokenOwnership.toString(), true, limits.accountTokenOwnershipLimit.toString()]);
66 expect(limitsEvm[1]).to.deep.eq(['1', true, limits.sponsoredDataSize.toString()]);67 expect(limitsEvm[1]).to.deep.eq([CollectionLimits.SponsoredDataSize.toString(), true, limits.sponsoredDataSize.toString()]);
67 expect(limitsEvm[2]).to.deep.eq(['2', true, limits.sponsoredDataRateLimit.toString()]);68 expect(limitsEvm[2]).to.deep.eq([CollectionLimits.SponsoredDataRateLimit.toString(), true, limits.sponsoredDataRateLimit.toString()]);
68 expect(limitsEvm[3]).to.deep.eq(['3', true, limits.tokenLimit.toString()]);69 expect(limitsEvm[3]).to.deep.eq([CollectionLimits.TokenLimit.toString(), true, limits.tokenLimit.toString()]);
69 expect(limitsEvm[4]).to.deep.eq(['4', true, limits.sponsorTransferTimeout.toString()]);70 expect(limitsEvm[4]).to.deep.eq([CollectionLimits.SponsorTransferTimeout.toString(), true, limits.sponsorTransferTimeout.toString()]);
70 expect(limitsEvm[5]).to.deep.eq(['5', true, limits.sponsorApproveTimeout.toString()]);71 expect(limitsEvm[5]).to.deep.eq([CollectionLimits.SponsorApproveTimeout.toString(), true, limits.sponsorApproveTimeout.toString()]);
71 expect(limitsEvm[6]).to.deep.eq(['6', true, limits.ownerCanTransfer.toString()]);72 expect(limitsEvm[6]).to.deep.eq([CollectionLimits.OwnerCanTransfer.toString(), true, limits.ownerCanTransfer.toString()]);
72 expect(limitsEvm[7]).to.deep.eq(['7', true, limits.ownerCanDestroy.toString()]);73 expect(limitsEvm[7]).to.deep.eq([CollectionLimits.OwnerCanDestroy.toString(), true, limits.ownerCanDestroy.toString()]);
73 expect(limitsEvm[8]).to.deep.eq(['8', true, limits.transfersEnabled.toString()]);74 expect(limitsEvm[8]).to.deep.eq([CollectionLimits.TransferEnabled.toString(), true, limits.transfersEnabled.toString()]);
74 }));75 }));
75});76});
7677
modifiedtests/src/eth/createFTCollection.test.tsdiffbeforeafterboth
17import {IKeyringPair} from '@polkadot/types/types';17import {IKeyringPair} from '@polkadot/types/types';
18import {evmToAddress} from '@polkadot/util-crypto';18import {evmToAddress} from '@polkadot/util-crypto';
19import {Pallets, requirePalletsOrSkip} from '../util';19import {Pallets, requirePalletsOrSkip} from '../util';
20import {CollectionLimits, expect, itEth, usingEthPlaygrounds} from './util';20import {expect, itEth, usingEthPlaygrounds} from './util';
21import { CollectionLimits } from './util/playgrounds/types';
2122
22const DECIMALS = 18;23const DECIMALS = 18;
2324
modifiedtests/src/eth/createNFTCollection.test.tsdiffbeforeafterboth
1616
17import {evmToAddress} from '@polkadot/util-crypto';17import {evmToAddress} from '@polkadot/util-crypto';
18import {IKeyringPair} from '@polkadot/types/types';18import {IKeyringPair} from '@polkadot/types/types';
19import {CollectionLimits, expect, itEth, usingEthPlaygrounds} from './util';19import {expect, itEth, usingEthPlaygrounds} from './util';
20import { CollectionLimits } from './util/playgrounds/types';
2021
2122
22describe('Create NFT collection from EVM', () => {23describe('Create NFT collection from EVM', () => {
modifiedtests/src/eth/createRFTCollection.test.tsdiffbeforeafterboth
17import {evmToAddress} from '@polkadot/util-crypto';17import {evmToAddress} from '@polkadot/util-crypto';
18import {IKeyringPair} from '@polkadot/types/types';18import {IKeyringPair} from '@polkadot/types/types';
19import {Pallets, requirePalletsOrSkip} from '../util';19import {Pallets, requirePalletsOrSkip} from '../util';
20import {CollectionLimits, expect, itEth, usingEthPlaygrounds} from './util';20import {expect, itEth, usingEthPlaygrounds} from './util';
21import { CollectionLimits } from './util/playgrounds/types';
2122
2223
23describe('Create RFT collection from EVM', () => {24describe('Create RFT collection from EVM', () => {
modifiedtests/src/eth/events.test.tsdiffbeforeafterboth
1616
17import {expect} from 'chai';17import {expect} from 'chai';
18import {IKeyringPair} from '@polkadot/types/types';18import {IKeyringPair} from '@polkadot/types/types';
19import {CollectionLimits, EthUniqueHelper, itEth, usingEthPlaygrounds} from './util';19import {EthUniqueHelper, itEth, usingEthPlaygrounds} from './util';
20import {IEvent, TCollectionMode} from '../util/playgrounds/types';20import {IEvent, TCollectionMode} from '../util/playgrounds/types';
21import {Pallets, requirePalletsOrSkip} from '../util';21import {Pallets, requirePalletsOrSkip} from '../util';
22import {EthTokenPermissions, NormalizedEvent} from './util/playgrounds/types';22import {CollectionLimits, EthTokenPermissions, NormalizedEvent} from './util/playgrounds/types';
2323
24let donor: IKeyringPair;24let donor: IKeyringPair;
25 25
modifiedtests/src/eth/util/index.tsdiffbeforeafterboth
26 Allowlisted = 1,26 Allowlisted = 1,
27 Generous = 2,27 Generous = 2,
28}28}
29export enum CollectionLimits {29
30 AccountTokenOwnership,
31 SponsoredDataSize,
32 SponsoredDataRateLimit,
33 TokenLimit,
34 SponsorTransferTimeout,
35 SponsorApproveTimeout,
36 OwnerCanTransfer,
37 OwnerCanDestroy,
38 TransferEnabled
39}
4030
41export const usingEthPlaygrounds = async (code: (helper: EthUniqueHelper, privateKey: (seed: string | {filename: string}) => Promise<IKeyringPair>) => Promise<void>) => {31export const usingEthPlaygrounds = async (code: (helper: EthUniqueHelper, privateKey: (seed: string | {filename: string}) => Promise<IKeyringPair>) => Promise<void>) => {
42 const silentConsole = new SilentConsole();32 const silentConsole = new SilentConsole();
modifiedtests/src/eth/util/playgrounds/types.tsdiffbeforeafterboth
25 TokenOwner,25 TokenOwner,
26 CollectionAdmin26 CollectionAdmin
27}27}
28export enum CollectionLimits {
29 AccountTokenOwnership,
30 SponsoredDataSize,
31 SponsoredDataRateLimit,
32 TokenLimit,
33 SponsorTransferTimeout,
34 SponsorApproveTimeout,
35 OwnerCanTransfer,
36 OwnerCanDestroy,
37 TransferEnabled
38}
39