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
before · Cargo.lock
971 packageslockfile v3
after · Cargo.lock
971 packageslockfile v3
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
--- a/runtime/tests/src/lib.rs
+++ b/runtime/tests/src/lib.rs
@@ -167,7 +167,7 @@
 }
 
 #[derive(Encode, Decode, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, TypeInfo, MaxEncodedLen)]
-pub struct TestCrossAccountId(u64, sp_core::H160);
+pub struct TestCrossAccountId(u64, sp_core::H160, bool);
 impl CrossAccountId<u64> for TestCrossAccountId {
 	fn as_sub(&self) -> &u64 {
 		&self.0
@@ -178,17 +178,20 @@
 	fn from_sub(sub: u64) -> Self {
 		let mut eth = [0; 20];
 		eth[12..20].copy_from_slice(&sub.to_be_bytes());
-		Self(sub, sp_core::H160(eth))
+		Self(sub, sp_core::H160(eth), true)
 	}
 	fn from_eth(eth: sp_core::H160) -> Self {
 		let mut sub_raw = [0; 8];
 		sub_raw.copy_from_slice(&eth.0[0..8]);
 		let sub = u64::from_be_bytes(sub_raw);
-		Self(sub, eth)
+		Self(sub, eth, false)
 	}
 	fn conv_eq(&self, other: &Self) -> bool {
 		self.as_sub() == other.as_sub()
 	}
+	fn is_canonical_substrate(&self) -> bool {
+		self.2
+	}
 }
 
 impl Default for TestCrossAccountId {
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}) => {