difftreelog
CORE-345 Remove deprecated methods
in: master
6 files changed
Cargo.lockdiffbeforeafterboth--- a/Cargo.lock
+++ b/Cargo.lock
@@ -989,9 +989,9 @@
[[package]]
name = "camino"
-version = "1.0.8"
+version = "1.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "07fd178c5af4d59e83498ef15cf3f154e1a6f9d091270cb86283c65ef44e9ef0"
+checksum = "869119e97797867fd90f5e22af7d0bd274bd4635ebb9eb68c04f3f513ae6c412"
dependencies = [
"serde",
]
@@ -6090,29 +6090,6 @@
"pallet-evm-coder-substrate",
"pallet-nonfungible",
"parity-scale-codec 3.1.2",
- "scale-info",
- "serde_json",
- "sp-core",
- "sp-runtime",
- "sp-std",
- "up-data-structs",
-]
-
-[[package]]
-name = "pallet-evm-collection"
-version = "0.1.0"
-dependencies = [
- "ethereum",
- "evm-coder",
- "fp-evm-mapping",
- "frame-support",
- "frame-system",
- "log",
- "pallet-common",
- "pallet-evm",
- "pallet-evm-coder-substrate",
- "pallet-nonfungible",
- "parity-scale-codec",
"scale-info",
"serde-json-core",
"sp-core",
pallets/evm-collection/src/eth.rsdiffbeforeafterboth--- a/pallets/evm-collection/src/eth.rs
+++ b/pallets/evm-collection/src/eth.rs
@@ -27,8 +27,7 @@
use sp_core::H160;
use up_data_structs::{
CreateCollectionData, MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH,
- MAX_COLLECTION_NAME_LENGTH, OFFCHAIN_SCHEMA_LIMIT, VARIABLE_ON_CHAIN_SCHEMA_LIMIT,
- CONST_ON_CHAIN_SCHEMA_LIMIT,
+ MAX_COLLECTION_NAME_LENGTH,
};
use crate::{Config, Pallet};
use frame_support::traits::Get;
@@ -48,7 +47,7 @@
}
#[derive(ToLog)]
-pub enum CollectionEvent {
+pub enum EthCollectionEvent {
CollectionCreated {
#[indexed]
owner: address,
@@ -95,7 +94,7 @@
let address = pallet_common::eth::collection_id_to_address(collection_id);
<PalletEvm<T>>::deposit_log(
- CollectionEvent::CollectionCreated {
+ EthCollectionEvent::CollectionCreated {
owner: *caller.as_eth(),
collection_id: address,
}
@@ -126,58 +125,6 @@
if !collection.confirm_sponsorship(caller.as_sub()) {
return Err(Error::Revert("Caller is not set as sponsor".into()));
}
- collection.save().map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;
- Ok(())
- }
-
- fn set_offchain_schema(
- &self,
- caller: caller,
- collection_address: address,
- schema: string,
- ) -> Result<void> {
- let mut collection = collection_from_address(collection_address, &self.0)?;
- check_is_owner(caller, &collection)?;
-
- let schema = schema
- .into_bytes()
- .try_into()
- .map_err(|_| error_feild_too_long(stringify!(shema), OFFCHAIN_SCHEMA_LIMIT))?;
- // collection.offchain_schema = schema;
- collection.save().map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;
- Ok(())
- }
-
- fn set_variable_on_chain_schema(
- &self,
- caller: caller,
- collection_address: address,
- variable: string,
- ) -> Result<void> {
- let mut collection = collection_from_address(collection_address, &self.0)?;
- check_is_owner(caller, &collection)?;
-
- let variable = variable.into_bytes().try_into().map_err(|_| {
- error_feild_too_long(stringify!(variable), VARIABLE_ON_CHAIN_SCHEMA_LIMIT)
- })?;
- // collection.variable_on_chain_schema = variable;
- collection.save().map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;
- Ok(())
- }
-
- fn set_const_on_chain_schema(
- &self,
- caller: caller,
- collection_address: address,
- const_on_chain: string,
- ) -> Result<void> {
- let mut collection = collection_from_address(collection_address, &self.0)?;
- check_is_owner(caller, &collection)?;
-
- let const_on_chain = const_on_chain.into_bytes().try_into().map_err(|_| {
- error_feild_too_long(stringify!(const_on_chain), CONST_ON_CHAIN_SCHEMA_LIMIT)
- })?;
- // collection.const_on_chain_schema = const_on_chain;
collection.save().map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;
Ok(())
}
primitives/data-structs/Cargo.tomldiffbeforeafterboth--- a/primitives/data-structs/Cargo.toml
+++ b/primitives/data-structs/Cargo.toml
@@ -40,6 +40,6 @@
"sp-std/std",
"pallet-evm/std",
]
-serde1 = ["serde"]
+serde1 = ["serde/alloc"]
limit-testing = []
runtime-benchmarks = []
\ No newline at end of file
primitives/rpc/src/lib.rsdiffbeforeafterboth--- a/primitives/rpc/src/lib.rs
+++ b/primitives/rpc/src/lib.rs
@@ -72,7 +72,6 @@
token: TokenId,
) -> Result<u128>;
- fn eth_contract_code(account: H160) -> Option<Vec<u8>>;
fn adminlist(collection: CollectionId) -> Result<Vec<CrossAccountId>>;
fn allowlist(collection: CollectionId) -> Result<Vec<CrossAccountId>>;
fn allowed(collection: CollectionId, user: CrossAccountId) -> Result<bool>;
runtime/opal/src/lib.rsdiffbeforeafterboth--- a/runtime/opal/src/lib.rs
+++ b/runtime/opal/src/lib.rs
@@ -50,6 +50,7 @@
pub use pallet_balances::Call as BalancesCall;
pub use pallet_evm::{
EnsureAddressTruncated, HashedAddressMapping, Runner, account::CrossAccountId as _, OnMethodCall,
+ Account as EVMAccount, FeeCalculator, GasWeightMapping,
};
pub use frame_support::{
construct_runtime, match_types,
@@ -79,7 +80,6 @@
};
use smallvec::smallvec;
use codec::{Encode, Decode};
-use pallet_evm::{Account as EVMAccount, FeeCalculator, GasWeightMapping, OnMethodCall};
use fp_rpc::TransactionStatus;
use sp_runtime::{
traits::{BlockNumberProvider, Dispatchable, PostDispatchInfoOf, Saturating},
tests/src/eth/createCollection.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.8//9// 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 nonFungibleAbi from './nonFungibleAbi.json';18import {ApiPromise} from '@polkadot/api';19import {evmToAddress} from '@polkadot/util-crypto';20import {expect} from 'chai';21import {getCreatedCollectionCount, getDetailedCollectionInfo} from '../util/helpers';22import {23 collectionHelper,24 collectionIdFromAddress,25 collectionIdToAddress,26 createEthAccount,27 createEthAccountWithBalance,28 GAS_ARGS,29 itWeb3,30 normalizeAddress,31 normalizeEvents,32} from './util/helpers';3334async function getCollectionAddressFromResult(api: ApiPromise, result: any) {35 const collectionIdAddress = normalizeAddress(result.events[0].raw.topics[2]);36 const collectionId = collectionIdFromAddress(collectionIdAddress); 37 const collection = (await getDetailedCollectionInfo(api, collectionId))!;38 return {collectionIdAddress, collectionId, collection};39}4041describe('Create collection from EVM', () => {42 itWeb3('Create collection', async ({api, web3}) => {43 const owner = await createEthAccountWithBalance(api, web3);44 const helper = collectionHelper(web3, owner);45 const collectionName = 'CollectionEVM';46 const description = 'Some description';47 const tokenPrefix = 'token prefix';48 49 const collectionCountBefore = await getCreatedCollectionCount(api);50 const result = await helper.methods51 .create721Collection(collectionName, description, tokenPrefix)52 .send();53 const collectionCountAfter = await getCreatedCollectionCount(api);54 55 const {collectionId, collection} = await getCollectionAddressFromResult(api, result);56 expect(collectionCountAfter - collectionCountBefore).to.be.eq(1);57 expect(collectionId).to.be.eq(collectionCountAfter);58 expect(collection.name.map(v => String.fromCharCode(v.toNumber())).join('')).to.be.eq(collectionName);59 expect(collection.description.map(v => String.fromCharCode(v.toNumber())).join('')).to.be.eq(description);60 expect(collection.tokenPrefix.toHuman()).to.be.eq(tokenPrefix);61 expect(collection.schemaVersion.type).to.be.eq('ImageURL');62 });63 64 itWeb3('Set sponsorship', async ({api, web3}) => {65 const owner = await createEthAccountWithBalance(api, web3);66 const helper = collectionHelper(web3, owner);67 let result = await helper.methods.create721Collection('Sponsor collection', '1', '1').send();68 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);69 const sponsor = await createEthAccountWithBalance(api, web3);70 result = await helper.methods.setSponsor(collectionIdAddress, sponsor).send();71 let collection = (await getDetailedCollectionInfo(api, collectionId))!;72 expect(collection.sponsorship.isUnconfirmed).to.be.true;73 expect(collection.sponsorship.asUnconfirmed.toHuman()).to.be.eq(evmToAddress(sponsor));74 await expect(helper.methods.confirmSponsorship(collectionIdAddress).call()).to.be.rejectedWith('Caller is not set as sponsor');75 const sponsorHelper = collectionHelper(web3, sponsor);76 await sponsorHelper.methods.confirmSponsorship(collectionIdAddress).send();77 collection = (await getDetailedCollectionInfo(api, collectionId))!;78 expect(collection.sponsorship.isConfirmed).to.be.true;79 expect(collection.sponsorship.asConfirmed.toHuman()).to.be.eq(evmToAddress(sponsor));80 });81 82 itWeb3('Set offchain schema', async ({api, web3}) => {83 const owner = await createEthAccountWithBalance(api, web3);84 const helper = collectionHelper(web3, owner);85 let result = await helper.methods.create721Collection('Schema collection', '2', '2').send();86 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);87 const schema = 'Some schema';88 result = await helper.methods.setOffchainSchema(collectionIdAddress, schema).send();89 const collection = (await getDetailedCollectionInfo(api, collectionId))!;90 expect(collection.offchainSchema.toHuman()).to.be.eq(schema);91 });92 93 itWeb3('Set variable on chain schema', async ({api, web3}) => {94 const owner = await createEthAccountWithBalance(api, web3);95 const helper = collectionHelper(web3, owner);96 let result = await helper.methods.create721Collection('Variable collection', '3', '3').send();97 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);98 const variable = 'Some variable';99 result = await helper.methods.setVariableOnChainSchema(collectionIdAddress, variable).send();100 const collection = (await getDetailedCollectionInfo(api, collectionId))!;101 expect(collection.variableOnChainSchema.toHuman()).to.be.eq(variable);102 });103 104 itWeb3('Set const on chain schema', async ({api, web3}) => {105 const owner = await createEthAccountWithBalance(api, web3);106 const helper = collectionHelper(web3, owner);107 let result = await helper.methods.create721Collection('Const collection', '4', '4').send();108 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);109 const constSchema = 'Some const';110 result = await helper.methods.setConstOnChainSchema(collectionIdAddress, constSchema).send();111 const collection = (await getDetailedCollectionInfo(api, collectionId))!;112 expect(collection.constOnChainSchema.toHuman()).to.be.eq(constSchema);113 });114115 itWeb3('Set limits', async ({api, web3}) => {116 const owner = await createEthAccountWithBalance(api, web3);117 const helper = collectionHelper(web3, owner);118 const result = await helper.methods.create721Collection('Const collection', '5', '5').send();119 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);120 const limits = {121 accountTokenOwnershipLimit: 1000,122 sponsoredDataSize: 1024,123 sponsoredDataRateLimit: {Blocks: 30},124 tokenLimit: 1000000,125 sponsorTransferTimeout: 6,126 sponsorApproveTimeout: 6,127 ownerCanTransfer: false,128 ownerCanDestroy: false,129 transfersEnabled: false,130 };131132 const limitsJson = JSON.stringify(limits, null, 1);133 await helper.methods.setLimits(collectionIdAddress, limitsJson).send();134 135 const collection = (await getDetailedCollectionInfo(api, collectionId))!;136 expect(collection.limits.accountTokenOwnershipLimit.unwrap().toNumber()).to.be.eq(limits.accountTokenOwnershipLimit);137 expect(collection.limits.sponsoredDataSize.unwrap().toNumber()).to.be.eq(limits.sponsoredDataSize);138 expect(collection.limits.sponsoredDataRateLimit.unwrap().asBlocks.toNumber()).to.be.eq(limits.sponsoredDataRateLimit.Blocks);139 expect(collection.limits.tokenLimit.unwrap().toNumber()).to.be.eq(limits.tokenLimit);140 expect(collection.limits.sponsorTransferTimeout.unwrap().toNumber()).to.be.eq(limits.sponsorTransferTimeout);141 expect(collection.limits.sponsorApproveTimeout.unwrap().toNumber()).to.be.eq(limits.sponsorApproveTimeout);142 expect(collection.limits.ownerCanTransfer.toHuman()).to.be.eq(limits.ownerCanTransfer);143 expect(collection.limits.ownerCanDestroy.toHuman()).to.be.eq(limits.ownerCanDestroy);144 expect(collection.limits.transfersEnabled.toHuman()).to.be.eq(limits.transfersEnabled);145 });146147 itWeb3('Check tokenURI', async ({web3, api}) => {148 const owner = await createEthAccountWithBalance(api, web3);149 const helper = collectionHelper(web3, owner);150 let result = await helper.methods.create721Collection('Mint collection', '6', '6').send();151 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);152 const receiver = createEthAccount(web3);153 const contract = new web3.eth.Contract(nonFungibleAbi as any, collectionIdAddress, {from: owner, ...GAS_ARGS});154 const nextTokenId = await contract.methods.nextTokenId().call();155156 expect(nextTokenId).to.be.equal('1');157 result = await contract.methods.mintWithTokenURI(158 receiver,159 nextTokenId,160 'Test URI',161 ).send();162163 const events = normalizeEvents(result.events);164 const address = collectionIdToAddress(collectionId);165166 expect(events).to.be.deep.equal([167 {168 address,169 event: 'Transfer',170 args: {171 from: '0x0000000000000000000000000000000000000000',172 to: receiver,173 tokenId: nextTokenId,174 },175 },176 ]);177178 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');179180 // TODO: this wont work right now, need release 919000 first181 // await helper.methods.setOffchainSchema(collectionIdAddress, 'https://offchain-service.local/token-info/{id}').send();182 // const tokenUri = await contract.methods.tokenURI(nextTokenId).call();183 // expect(tokenUri).to.be.equal(`https://offchain-service.local/token-info/${nextTokenId}`);184 });185});186187describe('(!negative tests!) Create collection from EVM', () => {188 itWeb3('(!negative test!) Create collection (bad lengths)', async ({api, web3}) => {189 const owner = await createEthAccountWithBalance(api, web3);190 const helper = collectionHelper(web3, owner);191 {192 const MAX_NAME_LENGHT = 64;193 const collectionName = 'A'.repeat(MAX_NAME_LENGHT + 1);194 const description = 'A';195 const tokenPrefix = 'A';196 197 await expect(helper.methods198 .create721Collection(collectionName, description, tokenPrefix)199 .call()).to.be.rejectedWith('name is too long. Max length is ' + MAX_NAME_LENGHT);200 201 }202 { 203 const MAX_DESCRIPTION_LENGHT = 256;204 const collectionName = 'A';205 const description = 'A'.repeat(MAX_DESCRIPTION_LENGHT + 1);206 const tokenPrefix = 'A';207 await expect(helper.methods208 .create721Collection(collectionName, description, tokenPrefix)209 .call()).to.be.rejectedWith('description is too long. Max length is ' + MAX_DESCRIPTION_LENGHT);210 }211 { 212 const MAX_TOKEN_PREFIX_LENGHT = 16;213 const collectionName = 'A';214 const description = 'A';215 const tokenPrefix = 'A'.repeat(MAX_TOKEN_PREFIX_LENGHT + 1);216 await expect(helper.methods217 .create721Collection(collectionName, description, tokenPrefix)218 .call()).to.be.rejectedWith('token_prefix is too long. Max length is ' + MAX_TOKEN_PREFIX_LENGHT);219 }220 });221 222 itWeb3('(!negative test!) Create collection (no funds)', async ({web3}) => {223 const owner = await createEthAccount(web3);224 const helper = collectionHelper(web3, owner);225 const collectionName = 'A';226 const description = 'A';227 const tokenPrefix = 'A';228 229 await expect(helper.methods230 .create721Collection(collectionName, description, tokenPrefix)231 .call()).to.be.rejectedWith('NotSufficientFounds');232 });233234 itWeb3('(!negative test!) Collection address (Contract is not an unique collection)', async ({api, web3}) => {235 const owner = await createEthAccountWithBalance(api, web3);236 const helper = collectionHelper(web3, owner);237 const collectionAddressWithBadPrefix = '0x00112233445566778899AABBCCDDEEFF00112233';238 const EXPECTED_ERROR = 'Contract is not an unique collection';239 {240 const sponsor = await createEthAccountWithBalance(api, web3);241 await expect(helper.methods242 .setSponsor(collectionAddressWithBadPrefix, sponsor)243 .call()).to.be.rejectedWith(EXPECTED_ERROR);244 245 const sponsorHelper = collectionHelper(web3, sponsor);246 await expect(sponsorHelper.methods247 .confirmSponsorship(collectionAddressWithBadPrefix)248 .call()).to.be.rejectedWith(EXPECTED_ERROR);249 }250 {251 const schema = 'Some schema';252 await expect(helper.methods253 .setOffchainSchema(collectionAddressWithBadPrefix, schema)254 .call()).to.be.rejectedWith(EXPECTED_ERROR);255 }256 {257 const variable = 'Some variable';258 await expect(helper.methods259 .setVariableOnChainSchema(collectionAddressWithBadPrefix, variable)260 .call()).to.be.rejectedWith(EXPECTED_ERROR);261 }262 {263 const constData = 'Some const';264 await expect(helper.methods265 .setConstOnChainSchema(collectionAddressWithBadPrefix, constData)266 .call()).to.be.rejectedWith(EXPECTED_ERROR);267 }268 {269 const limits = '{"account_token_ownership_limit":1000}';270 await expect(helper.methods271 .setLimits(collectionAddressWithBadPrefix, limits)272 .call()).to.be.rejectedWith(EXPECTED_ERROR);273 }274 });275276 itWeb3('(!negative test!) Check owner', async ({api, web3}) => {277 const owner = await createEthAccountWithBalance(api, web3);278 const notOwner = await createEthAccount(web3);279 const helperFromOwner = collectionHelper(web3, owner);280 const helperFromNotOwner = collectionHelper(web3, notOwner);281 const result = await helperFromOwner.methods.create721Collection('A', 'A', 'A').send();282 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);283 const EXPECTED_ERROR = 'NoPermission';284 {285 const sponsor = await createEthAccountWithBalance(api, web3);286 await expect(helperFromNotOwner.methods287 .setSponsor(collectionIdAddress, sponsor)288 .call()).to.be.rejectedWith(EXPECTED_ERROR);289 290 const sponsorHelper = collectionHelper(web3, sponsor);291 await expect(sponsorHelper.methods292 .confirmSponsorship(collectionIdAddress)293 .call()).to.be.rejectedWith('Caller is not set as sponsor');294 }295 {296 const schema = 'Some schema';297 await expect(helperFromNotOwner.methods298 .setOffchainSchema(collectionIdAddress, schema)299 .call()).to.be.rejectedWith(EXPECTED_ERROR);300 }301 {302 const variable = 'Some variable';303 await expect(helperFromNotOwner.methods304 .setVariableOnChainSchema(collectionIdAddress, variable)305 .call()).to.be.rejectedWith(EXPECTED_ERROR);306 }307 {308 const constData = 'Some const';309 await expect(helperFromNotOwner.methods310 .setConstOnChainSchema(collectionIdAddress, constData)311 .call()).to.be.rejectedWith(EXPECTED_ERROR);312 }313 {314 const limits = '{"account_token_ownership_limit":1000}';315 await expect(helperFromNotOwner.methods316 .setLimits(collectionIdAddress, limits)317 .call()).to.be.rejectedWith(EXPECTED_ERROR);318 }319 });320321 itWeb3('(!negative test!) Set offchain schema (length limit)', async ({api, web3}) => {322 const owner = await createEthAccountWithBalance(api, web3);323 const helper = collectionHelper(web3, owner);324 const result = await helper.methods.create721Collection('Schema collection', 'A', 'A').send();325 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);326 const OFFCHAIN_SCHEMA_LIMIT = 8192;327 const schema = 'A'.repeat(OFFCHAIN_SCHEMA_LIMIT + 1);328 await expect(helper.methods329 .setOffchainSchema(collectionIdAddress, schema)330 .call()).to.be.rejectedWith('schema is too long. Max length is ' + OFFCHAIN_SCHEMA_LIMIT);331 });332333 itWeb3('(!negative test!) Set variable on chain schema (length limit)', async ({api, web3}) => {334 const owner = await createEthAccountWithBalance(api, web3);335 const helper = collectionHelper(web3, owner);336 const result = await helper.methods.create721Collection('Schema collection', 'A', 'A').send();337 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);338 const VARIABLE_ON_CHAIN_SCHEMA_LIMIT = 8192;339 const variable = 'A'.repeat(VARIABLE_ON_CHAIN_SCHEMA_LIMIT + 1);340 await expect(helper.methods341 .setVariableOnChainSchema(collectionIdAddress, variable)342 .call()).to.be.rejectedWith('variable is too long. Max length is ' + VARIABLE_ON_CHAIN_SCHEMA_LIMIT);343 });344345 itWeb3('(!negative test!) Set const on chain schema (length limit)', async ({api, web3}) => {346 const owner = await createEthAccountWithBalance(api, web3);347 const helper = collectionHelper(web3, owner);348 const result = await helper.methods.create721Collection('Schema collection', 'A', 'A').send();349 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);350 const CONST_ON_CHAIN_SCHEMA_LIMIT = 32768;351 const constData = 'A'.repeat(CONST_ON_CHAIN_SCHEMA_LIMIT + 1);352 await expect(helper.methods353 .setConstOnChainSchema(collectionIdAddress, constData)354 .call()).to.be.rejectedWith('const_on_chain is too long. Max length is ' + CONST_ON_CHAIN_SCHEMA_LIMIT);355 });356357 itWeb3('(!negative test!) Set limits', async ({api, web3}) => {358 const owner = await createEthAccountWithBalance(api, web3);359 const helper = collectionHelper(web3, owner);360 const result = await helper.methods.create721Collection('Schema collection', 'A', 'A').send();361 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);362 const badJson = '{accountTokenOwnershipLimit: 1000}';363 await expect(helper.methods364 .setLimits(collectionIdAddress, badJson)365 .call()).to.be.rejectedWith('Parse JSON error:');366 });367});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.8//9// 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 nonFungibleAbi from './nonFungibleAbi.json';18import {ApiPromise} from '@polkadot/api';19import {evmToAddress} from '@polkadot/util-crypto';20import {expect} from 'chai';21import {getCreatedCollectionCount, getDetailedCollectionInfo} from '../util/helpers';22import {23 collectionHelper,24 collectionIdFromAddress,25 collectionIdToAddress,26 createEthAccount,27 createEthAccountWithBalance,28 GAS_ARGS,29 itWeb3,30 normalizeAddress,31 normalizeEvents,32} from './util/helpers';3334async function getCollectionAddressFromResult(api: ApiPromise, result: any) {35 const collectionIdAddress = normalizeAddress(result.events[0].raw.topics[2]);36 const collectionId = collectionIdFromAddress(collectionIdAddress); 37 const collection = (await getDetailedCollectionInfo(api, collectionId))!;38 return {collectionIdAddress, collectionId, collection};39}4041describe('Create collection from EVM', () => {42 itWeb3('Create collection', async ({api, web3}) => {43 const owner = await createEthAccountWithBalance(api, web3);44 const helper = collectionHelper(web3, owner);45 const collectionName = 'CollectionEVM';46 const description = 'Some description';47 const tokenPrefix = 'token prefix';48 49 const collectionCountBefore = await getCreatedCollectionCount(api);50 const result = await helper.methods51 .create721Collection(collectionName, description, tokenPrefix)52 .send();53 const collectionCountAfter = await getCreatedCollectionCount(api);54 55 const {collectionId, collection} = await getCollectionAddressFromResult(api, result);56 expect(collectionCountAfter - collectionCountBefore).to.be.eq(1);57 expect(collectionId).to.be.eq(collectionCountAfter);58 expect(collection.name.map(v => String.fromCharCode(v.toNumber())).join('')).to.be.eq(collectionName);59 expect(collection.description.map(v => String.fromCharCode(v.toNumber())).join('')).to.be.eq(description);60 expect(collection.tokenPrefix.toHuman()).to.be.eq(tokenPrefix);61 expect(collection.schemaVersion.type).to.be.eq('ImageURL');62 });63 64 itWeb3('Set sponsorship', async ({api, web3}) => {65 const owner = await createEthAccountWithBalance(api, web3);66 const helper = collectionHelper(web3, owner);67 let result = await helper.methods.create721Collection('Sponsor collection', '1', '1').send();68 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);69 const sponsor = await createEthAccountWithBalance(api, web3);70 result = await helper.methods.setSponsor(collectionIdAddress, sponsor).send();71 let collection = (await getDetailedCollectionInfo(api, collectionId))!;72 expect(collection.sponsorship.isUnconfirmed).to.be.true;73 expect(collection.sponsorship.asUnconfirmed.toHuman()).to.be.eq(evmToAddress(sponsor));74 await expect(helper.methods.confirmSponsorship(collectionIdAddress).call()).to.be.rejectedWith('Caller is not set as sponsor');75 const sponsorHelper = collectionHelper(web3, sponsor);76 await sponsorHelper.methods.confirmSponsorship(collectionIdAddress).send();77 collection = (await getDetailedCollectionInfo(api, collectionId))!;78 expect(collection.sponsorship.isConfirmed).to.be.true;79 expect(collection.sponsorship.asConfirmed.toHuman()).to.be.eq(evmToAddress(sponsor));80 });8182 itWeb3('Set limits', async ({api, web3}) => {83 const owner = await createEthAccountWithBalance(api, web3);84 const helper = collectionHelper(web3, owner);85 const result = await helper.methods.create721Collection('Const collection', '5', '5').send();86 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);87 const limits = {88 accountTokenOwnershipLimit: 1000,89 sponsoredDataSize: 1024,90 sponsoredDataRateLimit: {Blocks: 30},91 tokenLimit: 1000000,92 sponsorTransferTimeout: 6,93 sponsorApproveTimeout: 6,94 ownerCanTransfer: false,95 ownerCanDestroy: false,96 transfersEnabled: false,97 };9899 const limitsJson = JSON.stringify(limits, null, 1);100 await helper.methods.setLimits(collectionIdAddress, limitsJson).send();101 102 const collection = (await getDetailedCollectionInfo(api, collectionId))!;103 expect(collection.limits.accountTokenOwnershipLimit.unwrap().toNumber()).to.be.eq(limits.accountTokenOwnershipLimit);104 expect(collection.limits.sponsoredDataSize.unwrap().toNumber()).to.be.eq(limits.sponsoredDataSize);105 expect(collection.limits.sponsoredDataRateLimit.unwrap().asBlocks.toNumber()).to.be.eq(limits.sponsoredDataRateLimit.Blocks);106 expect(collection.limits.tokenLimit.unwrap().toNumber()).to.be.eq(limits.tokenLimit);107 expect(collection.limits.sponsorTransferTimeout.unwrap().toNumber()).to.be.eq(limits.sponsorTransferTimeout);108 expect(collection.limits.sponsorApproveTimeout.unwrap().toNumber()).to.be.eq(limits.sponsorApproveTimeout);109 expect(collection.limits.ownerCanTransfer.toHuman()).to.be.eq(limits.ownerCanTransfer);110 expect(collection.limits.ownerCanDestroy.toHuman()).to.be.eq(limits.ownerCanDestroy);111 expect(collection.limits.transfersEnabled.toHuman()).to.be.eq(limits.transfersEnabled);112 });113114 itWeb3('Check tokenURI', async ({web3, api}) => {115 const owner = await createEthAccountWithBalance(api, web3);116 const helper = collectionHelper(web3, owner);117 let result = await helper.methods.create721Collection('Mint collection', '6', '6').send();118 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);119 const receiver = createEthAccount(web3);120 const contract = new web3.eth.Contract(nonFungibleAbi as any, collectionIdAddress, {from: owner, ...GAS_ARGS});121 const nextTokenId = await contract.methods.nextTokenId().call();122123 expect(nextTokenId).to.be.equal('1');124 result = await contract.methods.mintWithTokenURI(125 receiver,126 nextTokenId,127 'Test URI',128 ).send();129130 const events = normalizeEvents(result.events);131 const address = collectionIdToAddress(collectionId);132133 expect(events).to.be.deep.equal([134 {135 address,136 event: 'Transfer',137 args: {138 from: '0x0000000000000000000000000000000000000000',139 to: receiver,140 tokenId: nextTokenId,141 },142 },143 ]);144145 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');146147 // TODO: this wont work right now, need release 919000 first148 // await helper.methods.setOffchainSchema(collectionIdAddress, 'https://offchain-service.local/token-info/{id}').send();149 // const tokenUri = await contract.methods.tokenURI(nextTokenId).call();150 // expect(tokenUri).to.be.equal(`https://offchain-service.local/token-info/${nextTokenId}`);151 });152});153154describe('(!negative tests!) Create collection from EVM', () => {155 itWeb3('(!negative test!) Create collection (bad lengths)', async ({api, web3}) => {156 const owner = await createEthAccountWithBalance(api, web3);157 const helper = collectionHelper(web3, owner);158 {159 const MAX_NAME_LENGHT = 64;160 const collectionName = 'A'.repeat(MAX_NAME_LENGHT + 1);161 const description = 'A';162 const tokenPrefix = 'A';163 164 await expect(helper.methods165 .create721Collection(collectionName, description, tokenPrefix)166 .call()).to.be.rejectedWith('name is too long. Max length is ' + MAX_NAME_LENGHT);167 168 }169 { 170 const MAX_DESCRIPTION_LENGHT = 256;171 const collectionName = 'A';172 const description = 'A'.repeat(MAX_DESCRIPTION_LENGHT + 1);173 const tokenPrefix = 'A';174 await expect(helper.methods175 .create721Collection(collectionName, description, tokenPrefix)176 .call()).to.be.rejectedWith('description is too long. Max length is ' + MAX_DESCRIPTION_LENGHT);177 }178 { 179 const MAX_TOKEN_PREFIX_LENGHT = 16;180 const collectionName = 'A';181 const description = 'A';182 const tokenPrefix = 'A'.repeat(MAX_TOKEN_PREFIX_LENGHT + 1);183 await expect(helper.methods184 .create721Collection(collectionName, description, tokenPrefix)185 .call()).to.be.rejectedWith('token_prefix is too long. Max length is ' + MAX_TOKEN_PREFIX_LENGHT);186 }187 });188 189 itWeb3('(!negative test!) Create collection (no funds)', async ({web3}) => {190 const owner = await createEthAccount(web3);191 const helper = collectionHelper(web3, owner);192 const collectionName = 'A';193 const description = 'A';194 const tokenPrefix = 'A';195 196 await expect(helper.methods197 .create721Collection(collectionName, description, tokenPrefix)198 .call()).to.be.rejectedWith('NotSufficientFounds');199 });200201 itWeb3('(!negative test!) Collection address (Contract is not an unique collection)', async ({api, web3}) => {202 const owner = await createEthAccountWithBalance(api, web3);203 const helper = collectionHelper(web3, owner);204 const collectionAddressWithBadPrefix = '0x00112233445566778899AABBCCDDEEFF00112233';205 const EXPECTED_ERROR = 'Contract is not an unique collection';206 {207 const sponsor = await createEthAccountWithBalance(api, web3);208 await expect(helper.methods209 .setSponsor(collectionAddressWithBadPrefix, sponsor)210 .call()).to.be.rejectedWith(EXPECTED_ERROR);211 212 const sponsorHelper = collectionHelper(web3, sponsor);213 await expect(sponsorHelper.methods214 .confirmSponsorship(collectionAddressWithBadPrefix)215 .call()).to.be.rejectedWith(EXPECTED_ERROR);216 }217 {218 const limits = '{"account_token_ownership_limit":1000}';219 await expect(helper.methods220 .setLimits(collectionAddressWithBadPrefix, limits)221 .call()).to.be.rejectedWith(EXPECTED_ERROR);222 }223 });224225 itWeb3('(!negative test!) Check owner', async ({api, web3}) => {226 const owner = await createEthAccountWithBalance(api, web3);227 const notOwner = await createEthAccount(web3);228 const helperFromOwner = collectionHelper(web3, owner);229 const helperFromNotOwner = collectionHelper(web3, notOwner);230 const result = await helperFromOwner.methods.create721Collection('A', 'A', 'A').send();231 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);232 const EXPECTED_ERROR = 'NoPermission';233 {234 const sponsor = await createEthAccountWithBalance(api, web3);235 await expect(helperFromNotOwner.methods236 .setSponsor(collectionIdAddress, sponsor)237 .call()).to.be.rejectedWith(EXPECTED_ERROR);238 239 const sponsorHelper = collectionHelper(web3, sponsor);240 await expect(sponsorHelper.methods241 .confirmSponsorship(collectionIdAddress)242 .call()).to.be.rejectedWith('Caller is not set as sponsor');243 }244 {245 const limits = '{"account_token_ownership_limit":1000}';246 await expect(helperFromNotOwner.methods247 .setLimits(collectionIdAddress, limits)248 .call()).to.be.rejectedWith(EXPECTED_ERROR);249 }250 });251252 itWeb3('(!negative test!) Set limits', async ({api, web3}) => {253 const owner = await createEthAccountWithBalance(api, web3);254 const helper = collectionHelper(web3, owner);255 const result = await helper.methods.create721Collection('Schema collection', 'A', 'A').send();256 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);257 const badJson = '{accountTokenOwnershipLimit: 1000}';258 await expect(helper.methods259 .setLimits(collectionIdAddress, badJson)260 .call()).to.be.rejectedWith('Parse JSON error:');261 });262});