git.delta.rocks / unique-network / refs/commits / 42c7b2c48281

difftreelog

fix Return sponsor address in canonical form.

Trubnikov Sergey2022-08-24parent: #e12eaf1.patch.diff
in: master

4 files changed

modifiedCargo.lockdiffbeforeafterboth
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2345,7 +2345,7 @@
 [[package]]
 name = "fc-consensus"
 version = "2.0.0-dev"
-source = "git+https://github.com/uniquenetwork/frontier?branch=unique-polkadot-v0.9.27#64915c0986fcf2bbe942794b838c0cf359c93c21"
+source = "git+https://github.com/uniquenetwork/frontier?branch=unique-polkadot-v0.9.27#69945f20e8dc06ab9e0dd636848a8db6a408c71c"
 dependencies = [
  "async-trait",
  "fc-db",
@@ -2364,7 +2364,7 @@
 [[package]]
 name = "fc-db"
 version = "2.0.0-dev"
-source = "git+https://github.com/uniquenetwork/frontier?branch=unique-polkadot-v0.9.27#64915c0986fcf2bbe942794b838c0cf359c93c21"
+source = "git+https://github.com/uniquenetwork/frontier?branch=unique-polkadot-v0.9.27#69945f20e8dc06ab9e0dd636848a8db6a408c71c"
 dependencies = [
  "fp-storage",
  "kvdb-rocksdb",
@@ -2380,7 +2380,7 @@
 [[package]]
 name = "fc-mapping-sync"
 version = "2.0.0-dev"
-source = "git+https://github.com/uniquenetwork/frontier?branch=unique-polkadot-v0.9.27#64915c0986fcf2bbe942794b838c0cf359c93c21"
+source = "git+https://github.com/uniquenetwork/frontier?branch=unique-polkadot-v0.9.27#69945f20e8dc06ab9e0dd636848a8db6a408c71c"
 dependencies = [
  "fc-db",
  "fp-consensus",
@@ -2397,7 +2397,7 @@
 [[package]]
 name = "fc-rpc"
 version = "2.0.0-dev"
-source = "git+https://github.com/uniquenetwork/frontier?branch=unique-polkadot-v0.9.27#64915c0986fcf2bbe942794b838c0cf359c93c21"
+source = "git+https://github.com/uniquenetwork/frontier?branch=unique-polkadot-v0.9.27#69945f20e8dc06ab9e0dd636848a8db6a408c71c"
 dependencies = [
  "ethereum",
  "ethereum-types",
@@ -2437,7 +2437,7 @@
 [[package]]
 name = "fc-rpc-core"
 version = "1.1.0-dev"
-source = "git+https://github.com/uniquenetwork/frontier?branch=unique-polkadot-v0.9.27#64915c0986fcf2bbe942794b838c0cf359c93c21"
+source = "git+https://github.com/uniquenetwork/frontier?branch=unique-polkadot-v0.9.27#69945f20e8dc06ab9e0dd636848a8db6a408c71c"
 dependencies = [
  "ethereum",
  "ethereum-types",
@@ -2578,7 +2578,7 @@
 [[package]]
 name = "fp-consensus"
 version = "2.0.0-dev"
-source = "git+https://github.com/uniquenetwork/frontier?branch=unique-polkadot-v0.9.27#64915c0986fcf2bbe942794b838c0cf359c93c21"
+source = "git+https://github.com/uniquenetwork/frontier?branch=unique-polkadot-v0.9.27#69945f20e8dc06ab9e0dd636848a8db6a408c71c"
 dependencies = [
  "ethereum",
  "parity-scale-codec 3.1.5",
@@ -2590,7 +2590,7 @@
 [[package]]
 name = "fp-evm"
 version = "3.0.0-dev"
-source = "git+https://github.com/uniquenetwork/frontier?branch=unique-polkadot-v0.9.27#64915c0986fcf2bbe942794b838c0cf359c93c21"
+source = "git+https://github.com/uniquenetwork/frontier?branch=unique-polkadot-v0.9.27#69945f20e8dc06ab9e0dd636848a8db6a408c71c"
 dependencies = [
  "evm",
  "frame-support",
@@ -2604,7 +2604,7 @@
 [[package]]
 name = "fp-evm-mapping"
 version = "0.1.0"
-source = "git+https://github.com/uniquenetwork/frontier?branch=unique-polkadot-v0.9.27#64915c0986fcf2bbe942794b838c0cf359c93c21"
+source = "git+https://github.com/uniquenetwork/frontier?branch=unique-polkadot-v0.9.27#69945f20e8dc06ab9e0dd636848a8db6a408c71c"
 dependencies = [
  "frame-support",
  "sp-core",
@@ -2613,7 +2613,7 @@
 [[package]]
 name = "fp-rpc"
 version = "3.0.0-dev"
-source = "git+https://github.com/uniquenetwork/frontier?branch=unique-polkadot-v0.9.27#64915c0986fcf2bbe942794b838c0cf359c93c21"
+source = "git+https://github.com/uniquenetwork/frontier?branch=unique-polkadot-v0.9.27#69945f20e8dc06ab9e0dd636848a8db6a408c71c"
 dependencies = [
  "ethereum",
  "ethereum-types",
@@ -2630,7 +2630,7 @@
 [[package]]
 name = "fp-self-contained"
 version = "1.0.0-dev"
-source = "git+https://github.com/uniquenetwork/frontier?branch=unique-polkadot-v0.9.27#64915c0986fcf2bbe942794b838c0cf359c93c21"
+source = "git+https://github.com/uniquenetwork/frontier?branch=unique-polkadot-v0.9.27#69945f20e8dc06ab9e0dd636848a8db6a408c71c"
 dependencies = [
  "ethereum",
  "frame-support",
@@ -2646,7 +2646,7 @@
 [[package]]
 name = "fp-storage"
 version = "2.0.0"
-source = "git+https://github.com/uniquenetwork/frontier?branch=unique-polkadot-v0.9.27#64915c0986fcf2bbe942794b838c0cf359c93c21"
+source = "git+https://github.com/uniquenetwork/frontier?branch=unique-polkadot-v0.9.27#69945f20e8dc06ab9e0dd636848a8db6a408c71c"
 dependencies = [
  "parity-scale-codec 3.1.5",
 ]
@@ -5445,7 +5445,7 @@
 [[package]]
 name = "pallet-base-fee"
 version = "1.0.0"
-source = "git+https://github.com/uniquenetwork/frontier?branch=unique-polkadot-v0.9.27#64915c0986fcf2bbe942794b838c0cf359c93c21"
+source = "git+https://github.com/uniquenetwork/frontier?branch=unique-polkadot-v0.9.27#69945f20e8dc06ab9e0dd636848a8db6a408c71c"
 dependencies = [
  "fp-evm",
  "frame-support",
@@ -5660,7 +5660,7 @@
 [[package]]
 name = "pallet-ethereum"
 version = "4.0.0-dev"
-source = "git+https://github.com/uniquenetwork/frontier?branch=unique-polkadot-v0.9.27#64915c0986fcf2bbe942794b838c0cf359c93c21"
+source = "git+https://github.com/uniquenetwork/frontier?branch=unique-polkadot-v0.9.27#69945f20e8dc06ab9e0dd636848a8db6a408c71c"
 dependencies = [
  "ethereum",
  "ethereum-types",
@@ -5689,7 +5689,7 @@
 [[package]]
 name = "pallet-evm"
 version = "6.0.0-dev"
-source = "git+https://github.com/uniquenetwork/frontier?branch=unique-polkadot-v0.9.27#64915c0986fcf2bbe942794b838c0cf359c93c21"
+source = "git+https://github.com/uniquenetwork/frontier?branch=unique-polkadot-v0.9.27#69945f20e8dc06ab9e0dd636848a8db6a408c71c"
 dependencies = [
  "evm",
  "fp-evm",
@@ -12130,7 +12130,7 @@
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675"
 dependencies = [
- "cfg-if 1.0.0",
+ "cfg-if 0.1.10",
  "digest 0.10.3",
  "rand 0.8.5",
  "static_assertions",
modifiedpallets/evm-contract-helpers/src/eth.rsdiffbeforeafterboth
--- a/pallets/evm-contract-helpers/src/eth.rs
+++ b/pallets/evm-contract-helpers/src/eth.rs
@@ -126,8 +126,14 @@
 	fn get_sponsor(&self, contract_address: address) -> Result<(address, uint256)> {
 		let sponsor =
 			Pallet::<T>::get_sponsor(contract_address).ok_or("Contract has no sponsor")?;
-		let sponsor_sub = pallet_common::eth::convert_cross_account_to_uint256::<T>(&sponsor);
-		Ok((*sponsor.as_eth(), sponsor_sub))
+		let result: (address, uint256) = if sponsor.is_canonical_substrate() {
+			let sponsor = pallet_common::eth::convert_cross_account_to_uint256::<T>(&sponsor);
+			(Default::default(), sponsor)
+		} else {
+			let sponsor =  *sponsor.as_eth();
+			(sponsor, Default::default())
+		};
+		Ok(result)
 	}
 
 	/// Check tat contract has confirmed sponsor.
modifiedruntime/tests/src/lib.rsdiffbeforeafterboth
before · runtime/tests/src/lib.rs
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.89// 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/>.1617#![allow(clippy::from_over_into)]1819use sp_core::{H160, H256, U256};20use frame_support::{21	parameter_types,22	traits::{Everything, ConstU32, ConstU64},23	weights::IdentityFee,24};25use sp_runtime::{26	traits::{BlakeTwo256, IdentityLookup},27	testing::Header,28};29use pallet_transaction_payment::{CurrencyAdapter};30use frame_system as system;31use pallet_evm::{32	AddressMapping, account::CrossAccountId, EnsureAddressNever, SubstrateBlockHashMapping,33};34use fp_evm_mapping::EvmBackwardsAddressMapping;35use parity_scale_codec::{Encode, Decode, MaxEncodedLen};36use scale_info::TypeInfo;3738use up_data_structs::mapping::{CrossTokenAddressMapping, EvmTokenAddressMapping};3940#[path = "../../common/dispatch.rs"]41mod dispatch;4243use dispatch::CollectionDispatchT;4445#[path = "../../common/weights.rs"]46mod weights;4748use weights::CommonWeights;4950type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;51type Block = frame_system::mocking::MockBlock<Test>;5253#[cfg(test)]54mod tests;5556// Configure a mock runtime to test the pallet.57frame_support::construct_runtime!(58	pub enum Test where59		Block = Block,60		NodeBlock = Block,61		UncheckedExtrinsic = UncheckedExtrinsic,62	{63		System: frame_system,64		Unique: pallet_unique::{Pallet, Call, Storage, Event<T>},65		Balances: pallet_balances::{Pallet, Call, Storage, Event<T>},66		Common: pallet_common::{Pallet, Storage, Event<T>},67		Fungible: pallet_fungible::{Pallet, Storage},68		Refungible: pallet_refungible::{Pallet, Storage},69		Nonfungible: pallet_nonfungible::{Pallet, Storage},70		Structure: pallet_structure::{Pallet, Storage, Event<T>},71		TransactionPayment: pallet_transaction_payment::{Pallet, Storage, Event<T>},72		Ethereum: pallet_ethereum::{Pallet, Config, Call, Storage, Event, Origin},73		EVM: pallet_evm::{Pallet, Config, Call, Storage, Event<T>},74	}75);7677parameter_types! {78	pub const BlockHashCount: u64 = 250;79	pub const SS58Prefix: u8 = 42;80}8182impl system::Config for Test {83	type Event = Event;84	type BaseCallFilter = Everything;85	type BlockWeights = ();86	type BlockLength = ();87	type DbWeight = ();88	type Origin = Origin;89	type Call = Call;90	type Index = u64;91	type BlockNumber = u64;92	type Hash = H256;93	type Hashing = BlakeTwo256;94	type AccountId = u64;95	type Lookup = IdentityLookup<Self::AccountId>;96	type Header = Header;97	type BlockHashCount = BlockHashCount;98	type Version = ();99	type PalletInfo = PalletInfo;100	type AccountData = pallet_balances::AccountData<u64>;101	type OnNewAccount = ();102	type OnKilledAccount = ();103	type SystemWeightInfo = ();104	type SS58Prefix = SS58Prefix;105	type OnSetCode = ();106	type MaxConsumers = ConstU32<16>;107}108109parameter_types! {110	pub const ExistentialDeposit: u64 = 1;111	pub const MaxLocks: u32 = 50;112}113//frame_system::Module<Test>;114impl pallet_balances::Config for Test {115	type Event = Event;116	type AccountStore = System;117	type Balance = u64;118	type DustRemoval = ();119	type ExistentialDeposit = ExistentialDeposit;120	type WeightInfo = ();121	type MaxLocks = MaxLocks;122	type MaxReserves = ();123	type ReserveIdentifier = [u8; 8];124}125126parameter_types! {127	pub const OperationalFeeMultiplier: u8 = 5;128}129130impl pallet_transaction_payment::Config for Test {131	type Event = Event;132	type OnChargeTransaction = CurrencyAdapter<pallet_balances::Pallet<Test>, ()>;133	type LengthToFee = IdentityFee<u64>;134	type WeightToFee = IdentityFee<u64>;135	type FeeMultiplierUpdate = ();136	type OperationalFeeMultiplier = OperationalFeeMultiplier;137}138139parameter_types! {140	pub const MinimumPeriod: u64 = 1;141}142impl pallet_timestamp::Config for Test {143	type Moment = u64;144	type OnTimestampSet = ();145	type MinimumPeriod = MinimumPeriod;146	type WeightInfo = ();147}148149parameter_types! {150	pub const CollectionCreationPrice: u32 = 100;151	pub TreasuryAccountId: u64 = 1234;152	pub EthereumChainId: u32 = 1111;153}154155pub struct TestEvmAddressMapping;156impl AddressMapping<u64> for TestEvmAddressMapping {157	fn into_account_id(_addr: sp_core::H160) -> u64 {158		unimplemented!()159	}160}161162pub struct TestEvmBackwardsAddressMapping;163impl EvmBackwardsAddressMapping<u64> for TestEvmBackwardsAddressMapping {164	fn from_account_id(_account_id: u64) -> sp_core::H160 {165		unimplemented!()166	}167}168169#[derive(Encode, Decode, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, TypeInfo, MaxEncodedLen)]170pub struct TestCrossAccountId(u64, sp_core::H160);171impl CrossAccountId<u64> for TestCrossAccountId {172	fn as_sub(&self) -> &u64 {173		&self.0174	}175	fn as_eth(&self) -> &sp_core::H160 {176		&self.1177	}178	fn from_sub(sub: u64) -> Self {179		let mut eth = [0; 20];180		eth[12..20].copy_from_slice(&sub.to_be_bytes());181		Self(sub, sp_core::H160(eth))182	}183	fn from_eth(eth: sp_core::H160) -> Self {184		let mut sub_raw = [0; 8];185		sub_raw.copy_from_slice(&eth.0[0..8]);186		let sub = u64::from_be_bytes(sub_raw);187		Self(sub, eth)188	}189	fn conv_eq(&self, other: &Self) -> bool {190		self.as_sub() == other.as_sub()191	}192}193194impl Default for TestCrossAccountId {195	fn default() -> Self {196		Self::from_sub(0)197	}198}199200parameter_types! {201	pub BlockGasLimit: U256 = 0u32.into();202}203204impl pallet_ethereum::Config for Test {205	type Event = Event;206	type StateRoot = pallet_ethereum::IntermediateStateRoot<Self>;207}208209impl pallet_evm::Config for Test {210	type Event = Event;211	type FeeCalculator = ();212	type GasWeightMapping = ();213	type CallOrigin = EnsureAddressNever<Self::CrossAccountId>;214	type WithdrawOrigin = EnsureAddressNever<Self::CrossAccountId>;215	type AddressMapping = TestEvmAddressMapping;216	type Currency = Balances;217	type PrecompilesType = ();218	type PrecompilesValue = ();219	type Runner = pallet_evm::runner::stack::Runner<Self>;220	type ChainId = ConstU64<0>;221	type BlockGasLimit = BlockGasLimit;222	type OnMethodCall = ();223	type OnCreate = ();224	type OnChargeTransaction = ();225	type FindAuthor = ();226	type BlockHashMapping = SubstrateBlockHashMapping<Self>;227	type TransactionValidityHack = ();228}229impl pallet_evm_coder_substrate::Config for Test {}230231impl pallet_common::Config for Test {232	type WeightInfo = ();233	type Event = Event;234	type Currency = Balances;235	type CollectionCreationPrice = CollectionCreationPrice;236	type TreasuryAccountId = TreasuryAccountId;237238	type CollectionDispatch = CollectionDispatchT<Self>;239	type EvmTokenAddressMapping = EvmTokenAddressMapping;240	type CrossTokenAddressMapping = CrossTokenAddressMapping<Self::AccountId>;241	type ContractAddress = EvmCollectionHelpersAddress;242}243244impl pallet_evm::account::Config for Test {245	type CrossAccountId = TestCrossAccountId;246	type EvmAddressMapping = TestEvmAddressMapping;247	type EvmBackwardsAddressMapping = TestEvmBackwardsAddressMapping;248}249250impl pallet_structure::Config for Test {251	type WeightInfo = ();252	type Event = Event;253	type Call = Call;254}255impl pallet_fungible::Config for Test {256	type WeightInfo = ();257}258impl pallet_refungible::Config for Test {259	type WeightInfo = ();260}261impl pallet_nonfungible::Config for Test {262	type WeightInfo = ();263}264265parameter_types! {266	// 0x6c4e9fe1ae37a41e93cee429e8e1881abdcbb54f267	pub const EvmCollectionHelpersAddress: H160 = H160([268		0x6c, 0x4e, 0x9f, 0xe1, 0xae, 0x37, 0xa4, 0x1e, 0x93, 0xce, 0xe4, 0x29, 0xe8, 0xe1, 0x88, 0x1a, 0xbd, 0xcb, 0xb5, 0x4f,269	]);270}271272impl pallet_unique::Config for Test {273	type Event = Event;274	type WeightInfo = ();275	type CommonWeightInfo = CommonWeights<Self>;276	type RefungibleExtensionsWeightInfo = CommonWeights<Self>;277}278279// Build genesis storage according to the mock runtime.280pub fn new_test_ext() -> sp_io::TestExternalities {281	system::GenesisConfig::default()282		.build_storage::<Test>()283		.unwrap()284		.into()285}
modifiedtests/src/eth/contractSponsoring.test.tsdiffbeforeafterboth
--- a/tests/src/eth/contractSponsoring.test.ts
+++ b/tests/src/eth/contractSponsoring.test.ts
@@ -129,8 +129,7 @@
     const result = await helpers.methods.getSponsor(flipper.options.address).call();
 
     expect(result[0]).to.be.eq(flipper.options.address);
-    const sponsorSub = api.registry.createType('AccountId', '0x' + BigInt(result[1]).toString(16).padStart(64, '0')).toJSON();
-    expect(sponsorSub).to.be.eq(evmToAddress(flipper.options.address));
+    expect(result[1]).to.be.eq('0');
   });
 
   itWeb3('Get confirmed sponsor', async ({api, web3, privateKeyWrapper}) => {
@@ -144,8 +143,7 @@
     const result = await helpers.methods.getSponsor(flipper.options.address).call();
 
     expect(result[0]).to.be.eq(sponsor);
-    const sponsorSub = api.registry.createType('AccountId', '0x' + BigInt(result[1]).toString(16).padStart(64, '0')).toJSON();
-    expect(sponsorSub).to.be.eq(evmToAddress(sponsor));
+    expect(result[1]).to.be.eq('0');
   });
 
   itWeb3('Sponsor can be removed by the address that deployed the contract', async ({api, web3, privateKeyWrapper}) => {