From c5844ebce80b029cf408a62cf8e535883ebc8532 Mon Sep 17 00:00:00 2001 From: shekohex Date: Mon, 13 Jan 2025 15:42:15 +0200 Subject: [PATCH] fix: operator input in the MAD precompile `delegate` call (#882) --- node/tests/evm_restaking.rs | 4 ++-- precompiles/multi-asset-delegation/src/lib.rs | 3 +-- precompiles/multi-asset-delegation/src/tests.rs | 8 ++++++++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/node/tests/evm_restaking.rs b/node/tests/evm_restaking.rs index 9b8f9b12..b17066d1 100644 --- a/node/tests/evm_restaking.rs +++ b/node/tests/evm_restaking.rs @@ -399,7 +399,7 @@ fn operator_join_delegator_delegate_erc20() { let delegate_result = precompile .delegate( - alice.address().into_word(), + alice.address().to_account_id().0.into(), U256::ZERO, *usdc.address(), delegate_amount, @@ -498,7 +498,7 @@ fn operator_join_delegator_delegate_asset_id() { let delegate_result = precompile .delegate( - alice.address().into_word(), + alice.address().to_account_id().0.into(), U256::from(t.usdc_asset_id), Address::ZERO, U256::from(delegate_amount), diff --git a/precompiles/multi-asset-delegation/src/lib.rs b/precompiles/multi-asset-delegation/src/lib.rs index 5abd970c..74329606 100644 --- a/precompiles/multi-asset-delegation/src/lib.rs +++ b/precompiles/multi-asset-delegation/src/lib.rs @@ -372,8 +372,7 @@ where let caller = handle.context().caller; let who = Runtime::AddressMapping::into_account_id(caller); - let operator = - Runtime::AddressMapping::into_account_id(H160::from_slice(&operator.0[12..])); + let operator = Runtime::AccountId::from(WrappedAccountId32(operator.0)); let (deposit_asset, amount) = match (asset_id.as_u128(), token_address.0 .0) { (0, erc20_token) if erc20_token != [0; 20] => { diff --git a/precompiles/multi-asset-delegation/src/tests.rs b/precompiles/multi-asset-delegation/src/tests.rs index ae196dc4..ab41ab3a 100644 --- a/precompiles/multi-asset-delegation/src/tests.rs +++ b/precompiles/multi-asset-delegation/src/tests.rs @@ -260,6 +260,14 @@ fn test_delegate_assets() { .execute_returns(()); assert_eq!(Assets::balance(1, delegator_account), 500 - 200); // no change when delegating + assert!(Operators::::get(operator_account) + .unwrap() + .delegations + .iter() + .find(|x| x.delegator == delegator_account + && x.asset_id == Asset::Custom(1) + && x.amount == 100) + .is_some()); }); }