difftreelog
Merge pull request #202 from UniqueNetwork/fix/invalid-mode-evm-sponsoring
in: master
Remove "invalid" collection mode, update frontier for sponsoring fixes, readme update, setVariableMetadata usage due CORE-37
13 files changed
Cargo.lockdiffbeforeafterboth2342[[package]]2342[[package]]2343name = "fc-consensus"2343name = "fc-consensus"2344version = "2.0.0-dev"2344version = "2.0.0-dev"2345source = "git+https://github.com/uniquenetwork/frontier.git?branch=injected-transactions-parachain#264af3adc427aefba9ce8a1c5d1c11a6d98d009c"2345source = "git+https://github.com/uniquenetwork/frontier.git?branch=injected-transactions-parachain#9e8630ae4e420f764dad25eec1e0ef41cf6a2694"2346dependencies = [2346dependencies = [2347 "async-trait",2347 "async-trait",2348 "derive_more",2348 "derive_more",2369[[package]]2369[[package]]2370name = "fc-db"2370name = "fc-db"2371version = "2.0.0-dev"2371version = "2.0.0-dev"2372source = "git+https://github.com/uniquenetwork/frontier.git?branch=injected-transactions-parachain#264af3adc427aefba9ce8a1c5d1c11a6d98d009c"2372source = "git+https://github.com/uniquenetwork/frontier.git?branch=injected-transactions-parachain#9e8630ae4e420f764dad25eec1e0ef41cf6a2694"2373dependencies = [2373dependencies = [2374 "fp-storage",2374 "fp-storage",2375 "kvdb",2375 "kvdb",2385[[package]]2385[[package]]2386name = "fc-mapping-sync"2386name = "fc-mapping-sync"2387version = "2.0.0-dev"2387version = "2.0.0-dev"2388source = "git+https://github.com/uniquenetwork/frontier.git?branch=injected-transactions-parachain#264af3adc427aefba9ce8a1c5d1c11a6d98d009c"2388source = "git+https://github.com/uniquenetwork/frontier.git?branch=injected-transactions-parachain#9e8630ae4e420f764dad25eec1e0ef41cf6a2694"2389dependencies = [2389dependencies = [2390 "fc-consensus",2390 "fc-consensus",2391 "fc-db",2391 "fc-db",2403[[package]]2403[[package]]2404name = "fc-rpc"2404name = "fc-rpc"2405version = "2.0.0-dev"2405version = "2.0.0-dev"2406source = "git+https://github.com/uniquenetwork/frontier.git?branch=injected-transactions-parachain#264af3adc427aefba9ce8a1c5d1c11a6d98d009c"2406source = "git+https://github.com/uniquenetwork/frontier.git?branch=injected-transactions-parachain#9e8630ae4e420f764dad25eec1e0ef41cf6a2694"2407dependencies = [2407dependencies = [2408 "ethereum",2408 "ethereum",2409 "ethereum-types",2409 "ethereum-types",2444[[package]]2444[[package]]2445name = "fc-rpc-core"2445name = "fc-rpc-core"2446version = "1.1.0-dev"2446version = "1.1.0-dev"2447source = "git+https://github.com/uniquenetwork/frontier.git?branch=injected-transactions-parachain#264af3adc427aefba9ce8a1c5d1c11a6d98d009c"2447source = "git+https://github.com/uniquenetwork/frontier.git?branch=injected-transactions-parachain#9e8630ae4e420f764dad25eec1e0ef41cf6a2694"2448dependencies = [2448dependencies = [2449 "ethereum-types",2449 "ethereum-types",2450 "jsonrpc-core 15.1.0",2450 "jsonrpc-core 15.1.0",2564[[package]]2564[[package]]2565name = "fp-consensus"2565name = "fp-consensus"2566version = "2.0.0-dev"2566version = "2.0.0-dev"2567source = "git+https://github.com/uniquenetwork/frontier.git?branch=injected-transactions-parachain#264af3adc427aefba9ce8a1c5d1c11a6d98d009c"2567source = "git+https://github.com/uniquenetwork/frontier.git?branch=injected-transactions-parachain#9e8630ae4e420f764dad25eec1e0ef41cf6a2694"2568dependencies = [2568dependencies = [2569 "ethereum",2569 "ethereum",2570 "parity-scale-codec",2570 "parity-scale-codec",2578[[package]]2578[[package]]2579name = "fp-evm"2579name = "fp-evm"2580version = "3.0.0-dev"2580version = "3.0.0-dev"2581source = "git+https://github.com/uniquenetwork/frontier.git?branch=injected-transactions-parachain#264af3adc427aefba9ce8a1c5d1c11a6d98d009c"2581source = "git+https://github.com/uniquenetwork/frontier.git?branch=injected-transactions-parachain#9e8630ae4e420f764dad25eec1e0ef41cf6a2694"2582dependencies = [2582dependencies = [2583 "evm",2583 "evm",2584 "impl-trait-for-tuples 0.1.3",2584 "impl-trait-for-tuples 0.1.3",2591[[package]]2591[[package]]2592name = "fp-rpc"2592name = "fp-rpc"2593version = "3.0.0-dev"2593version = "3.0.0-dev"2594source = "git+https://github.com/uniquenetwork/frontier.git?branch=injected-transactions-parachain#264af3adc427aefba9ce8a1c5d1c11a6d98d009c"2594source = "git+https://github.com/uniquenetwork/frontier.git?branch=injected-transactions-parachain#9e8630ae4e420f764dad25eec1e0ef41cf6a2694"2595dependencies = [2595dependencies = [2596 "ethereum",2596 "ethereum",2597 "ethereum-types",2597 "ethereum-types",2607[[package]]2607[[package]]2608name = "fp-storage"2608name = "fp-storage"2609version = "2.0.0"2609version = "2.0.0"2610source = "git+https://github.com/uniquenetwork/frontier.git?branch=injected-transactions-parachain#264af3adc427aefba9ce8a1c5d1c11a6d98d009c"2610source = "git+https://github.com/uniquenetwork/frontier.git?branch=injected-transactions-parachain#9e8630ae4e420f764dad25eec1e0ef41cf6a2694"261126112612[[package]]2612[[package]]2613name = "frame-benchmarking"2613name = "frame-benchmarking"323932393240[[package]]3240[[package]]3241name = "hex-literal"3241name = "hex-literal"3242version = "0.3.1"3242version = "0.3.3"3243source = "registry+https://github.com/rust-lang/crates.io-index"3243source = "registry+https://github.com/rust-lang/crates.io-index"3244checksum = "5af1f635ef1bc545d78392b136bfe1c9809e029023c84a3638a864a10b8819c8"3244checksum = "21e4590e13640f19f249fe3e4eca5113bc4289f2497710378190e7f4bd96f45b"324532453246[[package]]3246[[package]]3247name = "hex_fmt"3247name = "hex_fmt"5841[[package]]5841[[package]]5842name = "pallet-ethereum"5842name = "pallet-ethereum"5843version = "4.0.0-dev"5843version = "4.0.0-dev"5844source = "git+https://github.com/uniquenetwork/frontier.git?branch=injected-transactions-parachain#264af3adc427aefba9ce8a1c5d1c11a6d98d009c"5844source = "git+https://github.com/uniquenetwork/frontier.git?branch=injected-transactions-parachain#9e8630ae4e420f764dad25eec1e0ef41cf6a2694"5845dependencies = [5845dependencies = [5846 "ethereum",5846 "ethereum",5847 "ethereum-types",5847 "ethereum-types",5869[[package]]5869[[package]]5870name = "pallet-evm"5870name = "pallet-evm"5871version = "6.0.0-dev"5871version = "6.0.0-dev"5872source = "git+https://github.com/uniquenetwork/frontier.git?branch=injected-transactions-parachain#264af3adc427aefba9ce8a1c5d1c11a6d98d009c"5872source = "git+https://github.com/uniquenetwork/frontier.git?branch=injected-transactions-parachain#9e8630ae4e420f764dad25eec1e0ef41cf6a2694"5873dependencies = [5873dependencies = [5874 "evm",5874 "evm",5875 "evm-gasometer",5875 "evm-gasometer",README.mddiffbeforeafterboth6363642. Remove all installed toolchains with `rustup toolchain list` and `rustup toolchain uninstall <toolchain>`.642. Remove all installed toolchains with `rustup toolchain list` and `rustup toolchain uninstall <toolchain>`.6565663. Install install nightly 2021-03-01 and make it default:663. Install install nightly 2021-06-28 and make it default:676768```bash68```bash69rustup toolchain install nightly-2021-03-0169rustup toolchain install nightly-2021-06-2870rustup default nightly-2021-03-0170rustup default nightly-2021-06-2871```71```7272734. Add wasm target for nightly toolchain:734. Add wasm target for nightly toolchain:747475```bash75```bash76rustup target add wasm32-unknown-unknown --toolchain nightly-2021-03-0176rustup target add wasm32-unknown-unknown --toolchain nightly-2021-06-2877```77```7878795. Build:795. Build:135135136## Building and Running as Parachain locally136## Building and Running as Parachain locally137137138Rust toolchain: nightly-2021-04-23138Rust toolchain: nightly-2021-06-28139Note: checkout this project and polkadot project (see below) in the sibling folders (both under the same folder)139Note: checkout this project and polkadot project (see below) in the sibling folders (both under the same folder)140140141### Build relay141### Build relay142142143```143```144git clone https://github.com/paritytech/polkadot.git144git clone https://github.com/paritytech/polkadot.git145cd polkadot145cd polkadot146git checkout aa386760146git checkout release-v0.9.9147cargo build --release147cargo build --release148```148```149149208208209First of all, add rust toolchain and make it default.209First of all, add rust toolchain and make it default.210```bash210```bash211rustup target add wasm32-unknown-unknown --toolchain nightly-2020-10-01211rustup target add wasm32-unknown-unknown --toolchain nightly-2021-06-28212```212```213213214Then in "/node/src" run build command below214Then in "/node/src" run build command below215```bash215```bash216cargo +nightly-2020-10-01 build --release --features runtime-benchmarks216cargo +nightly-2021-06-28 build --release --features runtime-benchmarks217```217```218218219Run benchmark219Run benchmarkpallets/nft/src/eth/mod.rsdiffbeforeafterboth103 CollectionMode::ReFungible => {103 CollectionMode::ReFungible => {104 include_bytes!("stubs/UniqueRefungible.raw") as &[u8]104 include_bytes!("stubs/UniqueRefungible.raw") as &[u8]105 }105 }106 CollectionMode::Invalid => include_bytes!("stubs/UniqueInvalid.raw") as &[u8],107 }106 }108 .to_owned()107 .to_owned()109 })108 })pallets/nft/src/eth/stubs/UniqueInvalid.rawdiffbeforeafterbothno changes
pallets/nft/src/lib.rsdiffbeforeafterboth1347 sender.clone(),1347 sender.clone(),1348 recipient.clone(),1348 recipient.clone(),1349 )?,1349 )?,1350 _ => (),1351 };1350 };135213511353 Self::deposit_event(RawEvent::Transfer(1352 Self::deposit_event(RawEvent::Transfer(1493 from.clone(),1492 from.clone(),1494 recipient.clone(),1493 recipient.clone(),1495 )?,1494 )?,1496 _ => (),1497 };1495 };149814961499 if matches!(collection.mode, CollectionMode::Fungible(_)) {1497 if matches!(collection.mode, CollectionMode::Fungible(_)) {1534 Self::set_re_fungible_variable_data(collection, item_id, data)?1532 Self::set_re_fungible_variable_data(collection, item_id, data)?1535 }1533 }1536 CollectionMode::Fungible(_) => fail!(Error::<T>::CantStoreMetadataInFungibleTokens),1534 CollectionMode::Fungible(_) => fail!(Error::<T>::CantStoreMetadataInFungibleTokens),1537 _ => fail!(Error::<T>::UnexpectedCollectionType),1538 };1535 };153915361540 Ok(())1537 Ok(())1618 CollectionMode::NFT => Self::burn_nft_item(collection, item_id)?,1615 CollectionMode::NFT => Self::burn_nft_item(collection, item_id)?,1619 CollectionMode::Fungible(_) => Self::burn_fungible_item(sender, collection, value)?,1616 CollectionMode::Fungible(_) => Self::burn_fungible_item(sender, collection, value)?,1620 CollectionMode::ReFungible => Self::burn_refungible_item(collection, item_id, sender)?,1617 CollectionMode::ReFungible => Self::burn_refungible_item(collection, item_id, sender)?,1621 _ => (),1622 };1618 };162316191624 Ok(())1620 Ok(())1723 fail!(Error::<T>::NotReFungibleDataUsedToMintReFungibleCollectionToken);1719 fail!(Error::<T>::NotReFungibleDataUsedToMintReFungibleCollectionToken);1724 }1720 }1725 }1721 }1726 _ => {1727 fail!(Error::<T>::UnexpectedCollectionType);1728 }1729 };1722 };173017231731 Ok(())1724 Ok(())2034 .iter()2027 .iter()2035 .find(|i| i.owner == *subject)2028 .find(|i| i.owner == *subject)2036 .map(|i| i.fraction),2029 .map(|i| i.fraction),2037 CollectionMode::Invalid => None,2038 }2030 }2039 }2031 }204020322071 CollectionMode::ReFungible => {2063 CollectionMode::ReFungible => {2072 <ReFungibleItemList<T>>::contains_key(collection_id, item_id)2064 <ReFungibleItemList<T>>::contains_key(collection_id, item_id)2073 }2065 }2074 _ => false,2075 };2066 };207620672077 ensure!(exists, Error::<T>::TokenNotFound);2068 ensure!(exists, Error::<T>::TokenNotFound);pallets/nft/src/sponsorship.rsdiffbeforeafterboth127127128 sponsored128 sponsored129 }129 }130 _ => false,131 };130 };132 }131 }133132primitives/nft/src/lib.rsdiffbeforeafterboth73#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq)]73#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq)]74#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]74#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]75pub enum CollectionMode {75pub enum CollectionMode {76 Invalid,77 NFT,76 NFT,78 // decimal points77 // decimal points79 Fungible(DecimalPoints),78 Fungible(DecimalPoints),80 ReFungible,79 ReFungible,81}80}8283impl Default for CollectionMode {84 fn default() -> Self {85 Self::Invalid86 }87}888189impl CollectionMode {82impl CollectionMode {90 pub fn id(&self) -> u8 {83 pub fn id(&self) -> u8 {91 match self {84 match self {92 CollectionMode::Invalid => 0,93 CollectionMode::NFT => 1,85 CollectionMode::NFT => 1,94 CollectionMode::Fungible(_) => 2,86 CollectionMode::Fungible(_) => 2,95 CollectionMode::ReFungible => 3,87 CollectionMode::ReFungible => 3,runtime_types.jsondiffbeforeafterboth18 "DecimalPoints": "u8",18 "DecimalPoints": "u8",19 "CollectionMode": {19 "CollectionMode": {20 "_enum": {20 "_enum": {21 "Invalid": null,22 "NFT": null,21 "NFT": null,23 "Fungible": "DecimalPoints",22 "Fungible": "DecimalPoints",24 "ReFungible": null23 "ReFungible": nulltests/README.mddiffbeforeafterboth51. Checkout polkadot in sibling folder with this project51. Checkout polkadot in sibling folder with this project6```bash6```bash7git clone https://github.com/paritytech/polkadot.git && cd polkadot7git clone https://github.com/paritytech/polkadot.git && cd polkadot8git checkout aa38676098git checkout release-v0.9.99```9```1010112. Build with nightly-2021-04-23112. Build with nightly-2021-06-2812```bash12```bash13cargo build --release13cargo build --release14```14```tests/src/createCollection.test.tsdiffbeforeafterboth33});33});343435describe('(!negative test!) integration test: ext. createCollection():', () => {35describe('(!negative test!) integration test: ext. createCollection():', () => {36 it('(!negative test!) create new NFT collection whith incorrect data (mode)', async () => {37 await usingApi(async (api) => {38 const AcollectionCount = parseInt((await api.query.nft.createdCollectionCount()).toString(), 10);3940 const badTransaction = async () => {41 await createCollectionExpectSuccess({mode: {type: 'Invalid'}});42 };43 await expect(badTransaction()).to.be.rejected;4445 const BcollectionCount = parseInt((await api.query.nft.createdCollectionCount()).toString(), 10);46 expect(BcollectionCount).to.be.equal(AcollectionCount, 'Error: Incorrect collection created.');47 });48 });49 it('(!negative test!) create new NFT collection whith incorrect data (collection_name)', async () => {36 it('(!negative test!) create new NFT collection whith incorrect data (collection_name)', async () => {50 await createCollectionExpectFailure({ name: 'A'.repeat(65), mode: {type: 'NFT'}});37 await createCollectionExpectFailure({ name: 'A'.repeat(65), mode: {type: 'NFT'}});51 });38 });tests/src/scheduler.test.tsdiffbeforeafterboth28 await setCollectionSponsorExpectSuccess(nftCollectionId, Alice.address);28 await setCollectionSponsorExpectSuccess(nftCollectionId, Alice.address);29 await confirmSponsorshipExpectSuccess(nftCollectionId);29 await confirmSponsorshipExpectSuccess(nftCollectionId);303031 await scheduleTransferExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob, 1, 6000, 4);31 await scheduleTransferExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob, 1, 12000, 4);32 });32 });33 });33 });34});34});tests/src/setVariableMetaData.test.tsdiffbeforeafterboth17 setVariableMetaDataExpectFailure,17 setVariableMetaDataExpectFailure,18 setVariableMetaDataExpectSuccess,18 setVariableMetaDataExpectSuccess,19 addCollectionAdminExpectSuccess,19 addCollectionAdminExpectSuccess,20 setMetadataUpdatePermissionFlagExpectSuccess,20} from './util/helpers';21} from './util/helpers';212222chai.use(chaiAsPromised);23chai.use(chaiAsPromised);62 bob = privateKey('//Bob');63 bob = privateKey('//Bob');63 collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });64 collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });64 tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT');65 tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT');66 await setMetadataUpdatePermissionFlagExpectSuccess(alice, collectionId, 'Admin');65 await addCollectionAdminExpectSuccess(alice, collectionId, bob);67 await addCollectionAdminExpectSuccess(alice, collectionId, bob);66 });68 });67 });69 });tests/src/util/helpers.tsdiffbeforeafterboth224 return result;224 return result;225}225}226227interface Invalid {228 type: 'Invalid';229}230226231interface Nft {227interface Nft {232 type: 'NFT';228 type: 'NFT';241 type: 'ReFungible';237 type: 'ReFungible';242}238}243239244type CollectionMode = Nft | Fungible | ReFungible | Invalid;240type CollectionMode = Nft | Fungible | ReFungible;245241246export type CreateCollectionParams = {242export type CreateCollectionParams = {247 mode: CollectionMode,243 mode: CollectionMode,275 modeprm = { fungible: mode.decimalPoints };271 modeprm = { fungible: mode.decimalPoints };276 } else if (mode.type === 'ReFungible') {272 } else if (mode.type === 'ReFungible') {277 modeprm = { refungible: null };273 modeprm = { refungible: null };278 } else if (mode.type === 'Invalid') {274 }279 modeprm = { invalid: null };280 }281275282 const tx = api.tx.nft.createCollection(strToUTF16(name), strToUTF16(description), strToUTF16(tokenPrefix), modeprm);276 const tx = api.tx.nft.createCollection(strToUTF16(name), strToUTF16(description), strToUTF16(tokenPrefix), modeprm);283 const events = await submitTransactionAsync(alicePrivateKey, tx);277 const events = await submitTransactionAsync(alicePrivateKey, tx);317 modeprm = { fungible: mode.decimalPoints };311 modeprm = { fungible: mode.decimalPoints };318 } else if (mode.type === 'ReFungible') {312 } else if (mode.type === 'ReFungible') {319 modeprm = { refungible: null };313 modeprm = { refungible: null };320 } else if (mode.type === 'Invalid') {314 }321 modeprm = { invalid: null };322 }323315324 await usingApi(async (api) => {316 await usingApi(async (api) => {325 // Get number of collections before the transaction317 // Get number of collections before the transaction