difftreelog
CORE-302 Some refactor
in: master
3 files changed
pallets/evm-collection/src/eth.rsdiffbeforeafterboth205 recorder: &Rc<SubstrateRecorder<T>>,205 recorder: &Rc<SubstrateRecorder<T>>,206) -> Result<CollectionHandle<T>> {206) -> Result<CollectionHandle<T>> {207 let collection_id = pallet_common::eth::map_eth_to_id(&collection_address)207 let collection_id = pallet_common::eth::map_eth_to_id(&collection_address)208 .ok_or(Error::Revert("Bad ETH prefix".into()))?;208 .ok_or(Error::Revert("Contract is not an unique collection".into()))?;209 let collection =209 let collection =210 pallet_common::CollectionHandle::new_with_recorder(collection_id, recorder.clone())210 pallet_common::CollectionHandle::new_with_recorder(collection_id, recorder.clone())211 .ok_or(Error::Revert("Create collection handle error".into()))?;211 .ok_or(Error::Revert("Create collection handle error".into()))?;216 let caller = T::CrossAccountId::from_eth(caller);216 let caller = T::CrossAccountId::from_eth(caller);217 collection217 collection218 .check_is_owner(&caller)218 .check_is_owner(&caller)219 .map_err(|e| Error::Revert(format!("{:?}", e)))?;219 .map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;220 Ok(())220 Ok(())221}221}222222223fn save<T: Config>(collection: CollectionHandle<T>) -> Result<()> {223fn save<T: Config>(collection: CollectionHandle<T>) -> Result<()> {224 collection224 Ok(collection225 .save()225 .save()226 .map_err(|e| Error::Revert(format!("{:?}", e)))226 .map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?)227}227}228228229pub struct CollectionOnMethodCall<T: Config>(PhantomData<*const T>);229pub struct CollectionOnMethodCall<T: Config>(PhantomData<*const T>);243 input: &[u8],243 input: &[u8],244 value: sp_core::U256,244 value: sp_core::U256,245 ) -> Option<PrecompileResult> {245 ) -> Option<PrecompileResult> {246 // TODO: Extract to another OnMethodCall handler247 if target != &T::ContractAddress::get() {246 if target != &T::ContractAddress::get() {248 return None;247 return None;249 }248 }tests/package.jsondiffbeforeafterboth73 "testBlockProduction": "mocha --timeout 9999999 -r ts-node/register ./**/block-production.test.ts",73 "testBlockProduction": "mocha --timeout 9999999 -r ts-node/register ./**/block-production.test.ts",74 "testEnableDisableTransfers": "mocha --timeout 9999999 -r ts-node/register ./**/enableDisableTransfer.test.ts",74 "testEnableDisableTransfers": "mocha --timeout 9999999 -r ts-node/register ./**/enableDisableTransfer.test.ts",75 "testLimits": "mocha --timeout 9999999 -r ts-node/register ./**/limits.test.ts",75 "testLimits": "mocha --timeout 9999999 -r ts-node/register ./**/limits.test.ts",76 "testEthCreateCollection": "mocha --timeout 9999999 -r ts-node/register ./**/eth/createCollection.test.ts",76 "polkadot-types-fetch-metadata": "curl -H 'Content-Type: application/json' -d '{\"id\":\"1\", \"jsonrpc\":\"2.0\", \"method\": \"state_getMetadata\", \"params\":[]}' http://localhost:9933 > src/interfaces/metadata.json",77 "polkadot-types-fetch-metadata": "curl -H 'Content-Type: application/json' -d '{\"id\":\"1\", \"jsonrpc\":\"2.0\", \"method\": \"state_getMetadata\", \"params\":[]}' http://localhost:9933 > src/interfaces/metadata.json",77 "polkadot-types-from-defs": "ts-node ./node_modules/.bin/polkadot-types-from-defs --endpoint src/interfaces/metadata.json --input src/interfaces/ --package .",78 "polkadot-types-from-defs": "ts-node ./node_modules/.bin/polkadot-types-from-defs --endpoint src/interfaces/metadata.json --input src/interfaces/ --package .",78 "polkadot-types-from-chain": "ts-node ./node_modules/.bin/polkadot-types-from-chain --endpoint src/interfaces/metadata.json --output src/interfaces/ --package .",79 "polkadot-types-from-chain": "ts-node ./node_modules/.bin/polkadot-types-from-chain --endpoint src/interfaces/metadata.json --output src/interfaces/ --package .",tests/src/eth/createCollection.test.tsdiffbeforeafterboth231 .call()).to.be.rejectedWith('NotSufficientFounds');231 .call()).to.be.rejectedWith('NotSufficientFounds');232 });232 });233233234 itWeb3('(!negative test!) Collection address (Bad ETH prefix)', async ({api, web3}) => {234 itWeb3('(!negative test!) Collection address (Contract is not an unique collection)', async ({api, web3}) => {235 const owner = await createEthAccountWithBalance(api, web3);235 const owner = await createEthAccountWithBalance(api, web3);236 const helper = collectionHelper(web3, owner);236 const helper = collectionHelper(web3, owner);237 const collectionAddressWithBadPrefix = '0x00112233445566778899AABBCCDDEEFF00112233';237 const collectionAddressWithBadPrefix = '0x00112233445566778899AABBCCDDEEFF00112233';238 const EXPECTED_ERROR = 'Bad ETH prefix';238 const EXPECTED_ERROR = 'Contract is not an unique collection';239 {239 {240 const sponsor = await createEthAccountWithBalance(api, web3);240 const sponsor = await createEthAccountWithBalance(api, web3);241 await expect(helper.methods241 await expect(helper.methods