From e7953131834e06d97acb8a7f75e3abfbb749a1e1 Mon Sep 17 00:00:00 2001 From: shekohex Date: Thu, 4 Jan 2024 10:34:53 +0000 Subject: [PATCH] bugfix: Fix claims pallet (#394) * Fix claims pallet * Add claims test account to the testnet * DRY * fix: correct the way to wrap the message (#396) --------- Co-authored-by: Trung-Tin Pham <60747384+AtelyPham@users.noreply.github.com> --- node/src/chainspec/mainnet.rs | 1 - node/src/chainspec/testnet.rs | 22 ++- node/src/distributions/develop.rs | 42 +++++ node/src/distributions/mainnet.rs | 39 ----- pallets/claims/src/lib.rs | 41 +++-- pallets/claims/src/tests.rs | 152 ++++++++++++++----- pallets/claims/src/utils/ethereum_address.rs | 8 + 7 files changed, 216 insertions(+), 89 deletions(-) diff --git a/node/src/chainspec/mainnet.rs b/node/src/chainspec/mainnet.rs index b7c2e43d9..547066202 100644 --- a/node/src/chainspec/mainnet.rs +++ b/node/src/chainspec/mainnet.rs @@ -125,7 +125,6 @@ pub fn local_mainnet_config(chain_id: u64) -> Result { mainnet::get_edgeware_genesis_balance_distribution(), mainnet::get_leaderboard_balance_distribution(), mainnet::get_substrate_balance_distribution(), - mainnet::get_local_balance_distribution(), ]), // Genesis investor / team distribution (pallet-balances + pallet-vesting) combine_distributions(vec![ diff --git a/node/src/chainspec/testnet.rs b/node/src/chainspec/testnet.rs index 68dd4dfc2..9af1c3f11 100644 --- a/node/src/chainspec/testnet.rs +++ b/node/src/chainspec/testnet.rs @@ -124,8 +124,12 @@ pub fn local_testnet_config(chain_id: u64) -> Result { get_account_id_from_seed::("Eve"), ], chain_id, - vec![], - vec![], + combine_distributions(vec![ + develop::get_evm_balance_distribution(), + testnet::get_evm_balance_distribution(), + ]), + testnet::get_substrate_balance_distribution(), + develop::get_local_claims(), true, ) }, @@ -199,6 +203,7 @@ pub fn tangle_testnet_config(chain_id: u64) -> Result { testnet::get_evm_balance_distribution(), ]), testnet::get_substrate_balance_distribution(), + vec![], true, ) }, @@ -228,6 +233,7 @@ fn testnet_genesis( chain_id: u64, genesis_evm_distribution: Vec<(H160, fp_evm::GenesisAccount)>, genesis_substrate_distribution: Vec<(AccountId, Balance)>, + claims: Vec<(MultiAddress, Balance)>, _enable_println: bool, ) -> RuntimeGenesisConfig { const ENDOWMENT: Balance = 10_000_000 * UNIT; @@ -242,10 +248,13 @@ fn testnet_genesis( .collect(); let num_endowed_accounts = endowed_accounts.len(); - let claims: Vec<(MultiAddress, Balance, Option)> = endowed_accounts + + let claims_list: Vec<(MultiAddress, Balance, Option)> = endowed_accounts .iter() .map(|x| (MultiAddress::Native(x.clone()), ENDOWMENT, Some(StatementKind::Regular))) + .chain(claims.clone().into_iter().map(|(a, b)| (a, b, Some(StatementKind::Regular)))) .collect(); + let vesting_claims: Vec<( MultiAddress, BoundedVec<(Balance, Balance, BlockNumber), MaxVestingSchedules>, @@ -256,6 +265,11 @@ fn testnet_genesis( bounded_vec.try_push((ENDOWMENT, ENDOWMENT, 0)).unwrap(); (MultiAddress::Native(x.clone()), bounded_vec) }) + .chain(claims.into_iter().map(|(a, b)| { + let mut bounded_vec = BoundedVec::new(); + bounded_vec.try_push((b, b, 0)).unwrap(); + (a, bounded_vec) + })) .collect(); RuntimeGenesisConfig { @@ -338,7 +352,7 @@ fn testnet_genesis( phantom: PhantomData, }, claims: ClaimsConfig { - claims, + claims: claims_list, vesting: vesting_claims, expiry: Some(( 200u64, diff --git a/node/src/distributions/develop.rs b/node/src/distributions/develop.rs index 4bf3b5fa2..d000da596 100644 --- a/node/src/distributions/develop.rs +++ b/node/src/distributions/develop.rs @@ -16,7 +16,49 @@ use std::str::FromStr; use fp_evm::GenesisAccount; +use pallet_airdrop_claims::MultiAddress; use sp_core::{H160, U256}; +use sp_runtime::AccountId32; +use tangle_primitives::Balance; + +pub fn get_local_claims() -> Vec<(MultiAddress, Balance)> { + vec![ + // Test account with a simple menmonic + // Mnemonic: "test test test test test test test test test test test junk" + // Path: m/44'/60'/0'/0/0 + // Private Key: 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 + ( + MultiAddress::EVM( + H160::from_str("f39Fd6e51aad88F6F4ce6aB8827279cffFb92266") + .expect("internal H160 is valid; qed") + .into(), + ), + 1_000_000_000_000_000_000_000_000u128, + ), + ( + MultiAddress::EVM( + H160::from_str("2DFA35bd8C59C38FB3eC4e71b0106160E130A40E") + .expect("internal H160 is valid; qed") + .into(), + ), + 1_000_000_000_000_000_000_000_000u128, + ), + ( + MultiAddress::Native( + AccountId32::from_str("5EbkKKTdRJzP1j3aM3S7q178du6tW7ZVWK9Dtjx9CbTFEpGf") + .expect("internal AccountId32 is valid; qed"), + ), + 1_000_000_000_000_000_000_000_000u128, + ), + ( + MultiAddress::Native( + AccountId32::from_str("5DLXgUoVVeCZKHduaVhkH4RvLcyG1GdQwLqYLd4aFuYX1qve") + .expect("internal AccountId32 is valid; qed"), + ), + 1_000_000_000_000_000_000_000_000u128, + ), + ] +} pub fn get_evm_balance_distribution() -> Vec<(H160, GenesisAccount)> { vec![ diff --git a/node/src/distributions/mainnet.rs b/node/src/distributions/mainnet.rs index dd76bcf64..5526e3238 100644 --- a/node/src/distributions/mainnet.rs +++ b/node/src/distributions/mainnet.rs @@ -165,45 +165,6 @@ pub fn get_leaderboard_balance_distribution() -> DistributionResult { ) } -/// Used for testing purposes -/// -/// DO NOT USE IN MAINNET -pub fn get_local_balance_distribution() -> DistributionResult { - let list = vec![ - // Test account with a simple menmonic - // Mnemonic: "test test test test test test test test test test test junk" - // Path: m/44'/60'/0'/0/0 - // Private Key: 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 - H160::from_str("f39Fd6e51aad88F6F4ce6aB8827279cffFb92266") - .expect("internal H160 is valid; qed"), - // Test account with a simple menmonic - // Mnemonic: "test test test test test test test test test test test junk" - // Path: m/44'/60'/0'/0/1 - // Private Key: 0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d - H160::from_str("70997970C51812dc3A010C7d01b50e0d17dc79C8") - .expect("internal H160 is valid; qed"), - // H160 address of Alice dev account - // Derived from SS58 (42 prefix) address - // SS58: 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY - // hex: 0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d - // Using the full hex key, truncating to the first 20 bytes (the first 40 hex - // chars) - H160::from_str("d43593c715fdd31c61141abd04a99fd6822c8558") - .expect("internal H160 is valid; qed"), - ]; - let endowment = ONE_PERCENT_TOTAL_SUPPLY / list.len() as u128; - let local_list: Vec<(MultiAddress, u128)> = list - .into_iter() - .map(|address| (MultiAddress::EVM(EthereumAddress(address.0)), endowment)) - .collect(); - get_distribution_for( - local_list, - Some(StatementKind::Regular), - ONE_MONTH_BLOCKS, - TWO_YEARS_BLOCKS, - ) -} - pub fn get_substrate_balance_distribution() -> DistributionResult { let arr = get_edgeware_snapshot_list() .into_iter() diff --git a/pallets/claims/src/lib.rs b/pallets/claims/src/lib.rs index bf59221cb..ce25103a8 100644 --- a/pallets/claims/src/lib.rs +++ b/pallets/claims/src/lib.rs @@ -323,8 +323,7 @@ pub mod pallet { signature: MultiAddressSignature, ) -> DispatchResult { ensure_none(origin)?; - - let data = dest.using_encoded(to_ascii_hex); + let data = dest.as_ref().map(Self::encode_multi_address).unwrap_or_default(); let signer = Self::get_signer_multi_address(signer.clone(), signature, data, vec![])?; ensure!(Signing::::get(&signer).is_none(), Error::::InvalidStatement); Self::process_claim(signer, dest)?; @@ -407,8 +406,7 @@ pub mod pallet { statement: Vec, ) -> DispatchResult { ensure_none(origin)?; - - let data = dest.using_encoded(to_ascii_hex); + let data = dest.as_ref().map(Self::encode_multi_address).unwrap_or_default(); let signer = Self::get_signer_multi_address(signer.clone(), signature, data, statement.clone())?; if let Some(s) = Signing::::get(signer.clone()) { @@ -460,7 +458,7 @@ pub mod pallet { // The weight of this logic is included in the `claim` dispatchable. // Call::claim { dest: account, signer, signature } => { - let data = account.using_encoded(to_ascii_hex); + let data = account.as_ref().map(Self::encode_multi_address).unwrap_or_default(); match Self::get_signer_multi_address( signer.clone(), signature.clone(), @@ -475,7 +473,7 @@ pub mod pallet { // The weight of this logic is included in the `claim_attest` dispatchable. // Call::claim_attest { dest: account, signer, signature, statement } => { - let data = account.using_encoded(to_ascii_hex); + let data = account.as_ref().map(Self::encode_multi_address).unwrap_or_default(); match Self::get_signer_multi_address( signer.clone(), signature.clone(), @@ -525,7 +523,13 @@ fn to_ascii_hex(data: &[u8]) -> Vec { } impl Pallet { - // Constructs the message that Ethereum RPC's `personal_sign` and `eth_sign` would sign. + fn encode_multi_address(multi_address: &MultiAddress) -> Vec { + match multi_address { + MultiAddress::EVM(ref address) => address.using_encoded(to_ascii_hex), + MultiAddress::Native(ref address) => address.using_encoded(to_ascii_hex), + } + } + /// Constructs the message that Ethereum RPC's `personal_sign` and `eth_sign` would sign. fn ethereum_signable_message(what: &[u8], extra: &[u8]) -> Vec { let prefix = T::Prefix::get(); let mut l = prefix.len() + what.len() + extra.len(); @@ -554,8 +558,10 @@ impl Pallet { // Constructs the message that PolkadotJS would sign. fn polkadotjs_signable_message(what: &[u8], extra: &[u8]) -> Vec { + let mut v = Vec::new(); let prefix = T::Prefix::get(); - let mut v = prefix.to_vec(); + + v.extend_from_slice(prefix); v.extend_from_slice(what); v.extend_from_slice(extra); v @@ -570,6 +576,7 @@ impl Pallet { extra: &[u8], ) -> Option { let msg = keccak_256(&Self::polkadotjs_signable_message(what, extra)); + let public: Public = match addr.clone() { MultiAddress::EVM(_) => return None, MultiAddress::Native(a) => { @@ -578,9 +585,25 @@ impl Pallet { Public(bytes) }, }; + match sr25519_verify(&s.0, &msg, &public) { true => Some(addr), - false => None, + false => { + // If the signature verification fails, we try to wrap the hashed msg in a + // `` tag and try again. + let polkadotjs_prefix = b""; + let polkadotjs_suffix = b""; + + let mut wrapped_msg = Vec::new(); + wrapped_msg.extend_from_slice(polkadotjs_prefix); + wrapped_msg.extend_from_slice(&msg); + wrapped_msg.extend_from_slice(polkadotjs_suffix); + + match sr25519_verify(&s.0, &wrapped_msg, &public) { + true => Some(addr), + false => None, + } + }, } } diff --git a/pallets/claims/src/tests.rs b/pallets/claims/src/tests.rs index c8c6a92cc..eef2b40ae 100644 --- a/pallets/claims/src/tests.rs +++ b/pallets/claims/src/tests.rs @@ -81,7 +81,11 @@ fn claiming_works() { RuntimeOrigin::none(), Some(get_multi_address_account_id(42)), None, - sig::(&alice(), &Some(get_multi_address_account_id(42)).encode(), &[][..]) + sig::( + &alice(), + &get_multi_address_account_id(42).to_account_id_32().encode(), + &[][..] + ) )); assert_eq!( Balances::free_balance(&get_multi_address_account_id(42).to_account_id_32()), @@ -117,7 +121,11 @@ fn basic_claim_moving_works() { RuntimeOrigin::none(), Some(get_multi_address_account_id(42)), None, - sig::(&alice(), &Some(get_multi_address_account_id(42)).encode(), &[][..]) + sig::( + &alice(), + &get_multi_address_account_id(42).to_account_id_32().encode(), + &[][..] + ) ), Error::::SignerHasNoClaim ); @@ -125,7 +133,11 @@ fn basic_claim_moving_works() { RuntimeOrigin::none(), Some(get_multi_address_account_id(42)), None, - sig::(&bob(), &Some(get_multi_address_account_id(42)).encode(), &[][..]) + sig::( + &bob(), + &get_multi_address_account_id(42).to_account_id_32().encode(), + &[][..] + ) )); assert_eq!( Balances::free_balance(&get_multi_address_account_id(42).to_account_id_32()), @@ -149,7 +161,7 @@ fn claim_attest_moving_works() { )); let s = sig::( &bob(), - &Some(get_multi_address_account_id(42)).encode(), + &get_multi_address_account_id(42).to_account_id_32().encode(), StatementKind::Regular.to_text(), ); assert_ok!(ClaimsPallet::claim_attest( @@ -173,14 +185,22 @@ fn claiming_does_not_bypass_signing() { RuntimeOrigin::none(), Some(get_multi_address_account_id(42)), None, - sig::(&alice(), &Some(get_multi_address_account_id(42)).encode(), &[][..]) + sig::( + &alice(), + &get_multi_address_account_id(42).to_account_id_32().encode(), + &[][..] + ) )); assert_noop!( ClaimsPallet::claim( RuntimeOrigin::none(), Some(get_multi_address_account_id(42)), None, - sig::(&dave(), &Some(get_multi_address_account_id(42)).encode(), &[][..]) + sig::( + &dave(), + &get_multi_address_account_id(42).to_account_id_32().encode(), + &[][..] + ) ), Error::::InvalidStatement, ); @@ -189,7 +209,11 @@ fn claiming_does_not_bypass_signing() { RuntimeOrigin::none(), Some(get_multi_address_account_id(42)), None, - sig::(&eve(), &Some(get_multi_address_account_id(42)).encode(), &[][..]) + sig::( + &eve(), + &get_multi_address_account_id(42).to_account_id_32().encode(), + &[][..] + ) ), Error::::InvalidStatement, ); @@ -197,7 +221,11 @@ fn claiming_does_not_bypass_signing() { RuntimeOrigin::none(), Some(get_multi_address_account_id(42)), None, - sig::(&frank(), &Some(get_multi_address_account_id(42)).encode(), &[][..]) + sig::( + &frank(), + &get_multi_address_account_id(42).to_account_id_32().encode(), + &[][..] + ) )); }); } @@ -206,7 +234,7 @@ fn claiming_does_not_bypass_signing() { fn attest_claiming_works() { new_test_ext().execute_with(|| { assert_eq!(Balances::free_balance(get_multi_address_account_id(42).to_account_id_32()), 0); - let data = Some(get_multi_address_account_id(42)).encode(); + let data = get_multi_address_account_id(42).to_account_id_32().encode(); let s = sig::(&dave(), &data, StatementKind::Safe.to_text()); let r = ClaimsPallet::claim_attest( RuntimeOrigin::none(), @@ -230,7 +258,7 @@ fn attest_claiming_works() { let s = sig::( &dave(), - &Some(get_multi_address_account_id(42)).encode(), + &get_multi_address_account_id(42).to_account_id_32().encode(), StatementKind::Regular.to_text(), ); assert_ok!(ClaimsPallet::claim_attest( @@ -248,7 +276,7 @@ fn attest_claiming_works() { let s = sig::( &dave(), - &Some(get_multi_address_account_id(42)).encode(), + &get_multi_address_account_id(42).to_account_id_32().encode(), StatementKind::Regular.to_text(), ); let r = ClaimsPallet::claim_attest( @@ -266,7 +294,11 @@ fn attest_claiming_works() { fn cannot_bypass_attest_claiming() { new_test_ext().execute_with(|| { assert_eq!(Balances::free_balance(get_multi_address_account_id(42).to_account_id_32()), 0); - let s = sig::(&dave(), &Some(get_multi_address_account_id(42)).encode(), &[]); + let s = sig::( + &dave(), + &get_multi_address_account_id(42).to_account_id_32().encode(), + &[], + ); let r = ClaimsPallet::claim( RuntimeOrigin::none(), Some(get_multi_address_account_id(42)), @@ -296,7 +328,11 @@ fn add_claim_works() { RuntimeOrigin::none(), Some(get_multi_address_account_id(69)), None, - sig::(&bob(), &Some(get_multi_address_account_id(69)).encode(), &[][..]) + sig::( + &bob(), + &get_multi_address_account_id(69).to_account_id_32().encode(), + &[][..] + ) ), Error::::SignerHasNoClaim, ); @@ -306,7 +342,11 @@ fn add_claim_works() { RuntimeOrigin::none(), Some(get_multi_address_account_id(69)), None, - sig::(&bob(), &Some(get_multi_address_account_id(69)).encode(), &[][..]) + sig::( + &bob(), + &get_multi_address_account_id(69).to_account_id_32().encode(), + &[][..] + ) )); assert_eq!( Balances::free_balance(get_multi_address_account_id(69).to_account_id_32()), @@ -339,7 +379,11 @@ fn add_claim_with_vesting_works() { RuntimeOrigin::none(), Some(get_multi_address_account_id(69)), None, - sig::(&bob(), &Some(get_multi_address_account_id(69)).encode(), &[][..]) + sig::( + &bob(), + &get_multi_address_account_id(69).to_account_id_32().encode(), + &[][..] + ) ), Error::::SignerHasNoClaim, ); @@ -354,7 +398,11 @@ fn add_claim_with_vesting_works() { RuntimeOrigin::none(), Some(get_multi_address_account_id(69)), None, - sig::(&bob(), &Some(get_multi_address_account_id(69)).encode(), &[][..]) + sig::( + &bob(), + &get_multi_address_account_id(69).to_account_id_32().encode(), + &[][..] + ) )); assert_eq!( Balances::free_balance(get_multi_address_account_id(69).to_account_id_32()), @@ -394,7 +442,7 @@ fn add_claim_with_statement_works() { assert_eq!(Balances::free_balance(get_multi_address_account_id(42).to_account_id_32()), 0); let signature = sig::( &bob(), - &Some(get_multi_address_account_id(69)).encode(), + &get_multi_address_account_id(69).to_account_id_32().encode(), StatementKind::Regular.to_text(), ); @@ -448,7 +496,11 @@ fn origin_signed_claiming_fail() { RuntimeOrigin::signed(get_multi_address_account_id(42).to_account_id_32()), Some(get_multi_address_account_id(42)), None, - sig::(&alice(), &Some(get_multi_address_account_id(42)).encode(), &[][..]) + sig::( + &alice(), + &get_multi_address_account_id(42).to_account_id_32().encode(), + &[][..] + ) ), sp_runtime::traits::BadOrigin, ); @@ -463,14 +515,22 @@ fn double_claiming_doesnt_work() { RuntimeOrigin::none(), Some(get_multi_address_account_id(42)), None, - sig::(&alice(), &Some(get_multi_address_account_id(42)).encode(), &[][..]) + sig::( + &alice(), + &get_multi_address_account_id(42).to_account_id_32().encode(), + &[][..] + ) )); assert_noop!( ClaimsPallet::claim( RuntimeOrigin::none(), Some(get_multi_address_account_id(42)), None, - sig::(&alice(), &Some(get_multi_address_account_id(42)).encode(), &[][..]) + sig::( + &alice(), + &get_multi_address_account_id(42).to_account_id_32().encode(), + &[][..] + ) ), Error::::SignerHasNoClaim ); @@ -511,7 +571,11 @@ fn claiming_while_vested_doesnt_work() { RuntimeOrigin::none(), Some(get_multi_address_account_id(69)), None, - sig::(&bob(), &Some(get_multi_address_account_id(69)).encode(), &[][..]) + sig::( + &bob(), + &get_multi_address_account_id(69).to_account_id_32().encode(), + &[][..] + ) ), Error::::VestedBalanceExists, ); @@ -527,7 +591,11 @@ fn non_sender_sig_doesnt_work() { RuntimeOrigin::none(), Some(get_multi_address_account_id(42)), None, - sig::(&alice(), &Some(get_multi_address_account_id(69)).encode(), &[][..]) + sig::( + &alice(), + &get_multi_address_account_id(69).to_account_id_32().encode(), + &[][..] + ) ), Error::::SignerHasNoClaim ); @@ -543,7 +611,11 @@ fn non_claimant_doesnt_work() { RuntimeOrigin::none(), Some(get_multi_address_account_id(42)), None, - sig::(&bob(), &Some(get_multi_address_account_id(69)).encode(), &[][..]) + sig::( + &bob(), + &get_multi_address_account_id(69).to_account_id_32().encode(), + &[][..] + ) ), Error::::SignerHasNoClaim ); @@ -576,7 +648,7 @@ fn validate_unsigned_works() { signer: None, signature: sig::( &alice(), - &Some(get_multi_address_account_id(1)).encode(), + &get_multi_address_account_id(1).to_account_id_32().encode(), &[][..] ) } @@ -608,7 +680,7 @@ fn validate_unsigned_works() { signer: None, signature: sig::( &bob(), - &Some(get_multi_address_account_id(1)).encode(), + &get_multi_address_account_id(1).to_account_id_32().encode(), &[][..] ) } @@ -617,7 +689,7 @@ fn validate_unsigned_works() { ); let s = sig::( &dave(), - &Some(get_multi_address_account_id(1)).encode(), + &get_multi_address_account_id(1).to_account_id_32().encode(), StatementKind::Regular.to_text(), ); let call = ClaimsCall::claim_attest { @@ -651,7 +723,7 @@ fn validate_unsigned_works() { let s = sig::( &bob(), - &Some(get_multi_address_account_id(1)).encode(), + &get_multi_address_account_id(1).to_account_id_32().encode(), StatementKind::Regular.to_text(), ); let call = ClaimsCall::claim_attest { @@ -667,7 +739,7 @@ fn validate_unsigned_works() { let s = sig::( &dave(), - &Some(get_multi_address_account_id(1)).encode(), + &get_multi_address_account_id(1).to_account_id_32().encode(), StatementKind::Safe.to_text(), ); let call = ClaimsCall::claim_attest { @@ -683,7 +755,7 @@ fn validate_unsigned_works() { let s = sig::( &dave(), - &Some(get_multi_address_account_id(1)).encode(), + &get_multi_address_account_id(1).to_account_id_32().encode(), StatementKind::Safe.to_text(), ); let call = ClaimsCall::claim_attest { @@ -708,7 +780,11 @@ fn test_unclaimed_returned_to_destination() { RuntimeOrigin::none(), Some(get_multi_address_account_id(42)), None, - sig::(&alice(), &Some(get_multi_address_account_id(42)).encode(), &[][..]) + sig::( + &alice(), + &get_multi_address_account_id(42).to_account_id_32().encode(), + &[][..] + ) )); assert_eq!(Total::::get(), original_total_claims - claim_of_alice); @@ -735,7 +811,11 @@ fn test_unclaimed_returned_to_destination() { RuntimeOrigin::none(), Some(get_multi_address_account_id(42)), None, - sig::(&frank(), &Some(get_multi_address_account_id(42)).encode(), &[][..]) + sig::( + &frank(), + &get_multi_address_account_id(42).to_account_id_32().encode(), + &[][..] + ) ), Error::::PotUnderflow ); @@ -753,7 +833,7 @@ fn test_claim_from_substrate_address_to_evm() { Some(sr25519_utils::sub(&alice_sr25519())), sr25519_utils::sig::( &alice_sr25519(), - &Some(get_multi_address_account_id(42)).encode(), + &get_multi_address_account_id(42).to_account_id_32().encode(), &[][..] ) )); @@ -770,7 +850,7 @@ fn test_claim_from_substrate_address_to_evm() { None, sr25519_utils::sig::( &bob_sr25519(), - &Some(get_multi_address_account_id(42)).encode(), + &get_multi_address_account_id(42).to_account_id_32().encode(), &[][..] ) ), @@ -801,7 +881,7 @@ fn test_claim_from_substrate_address_to_evm() { Some(sr25519_utils::sub(&bob_sr25519())), sr25519_utils::sig::( &bob_sr25519(), - &Some(get_multi_address_account_id(42)).encode(), + &get_multi_address_account_id(42).to_account_id_32().encode(), &[][..] ) ), @@ -821,7 +901,7 @@ fn test_double_claim_fails_for_substrate_account() { Some(sr25519_utils::sub(&alice_sr25519())), sr25519_utils::sig::( &alice_sr25519(), - &Some(get_multi_address_account_id(42)).encode(), + &get_multi_address_account_id(42).to_account_id_32().encode(), &[][..] ) )); @@ -838,7 +918,7 @@ fn test_double_claim_fails_for_substrate_account() { Some(sr25519_utils::sub(&alice_sr25519())), sr25519_utils::sig::( &alice_sr25519(), - &Some(get_multi_address_account_id(42)).encode(), + &get_multi_address_account_id(42).to_account_id_32().encode(), &[][..] ) ), diff --git a/pallets/claims/src/utils/ethereum_address.rs b/pallets/claims/src/utils/ethereum_address.rs index c8e8dfc6c..8c64a0e9c 100644 --- a/pallets/claims/src/utils/ethereum_address.rs +++ b/pallets/claims/src/utils/ethereum_address.rs @@ -47,6 +47,14 @@ impl From for H160 { } } +impl From for EthereumAddress { + fn from(a: H160) -> Self { + let mut r = Self::default(); + r.0.copy_from_slice(&a.0); + r + } +} + #[derive(Clone, Copy, Eq, Encode, Decode, TypeInfo)] pub struct EcdsaSignature(pub [u8; 65]);