Skip to content

Commit

Permalink
add IT required changes
Browse files Browse the repository at this point in the history
  • Loading branch information
lemunozm committed Aug 14, 2024
1 parent 074a4b4 commit af9bc6c
Show file tree
Hide file tree
Showing 15 changed files with 109 additions and 140 deletions.
14 changes: 7 additions & 7 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ use cfg_primitives::{
SAFE_XCM_VERSION,
};
use cfg_types::{
domain_address::DomainAddress,
fee_keys::FeeKey,
tokens::{usdc, AssetMetadata, CrossChainTransferability, CurrencyId, CustomMetadata},
};
use cfg_utils::vec_to_fixed_array;
use cumulus_primitives_core::ParaId;
use hex_literal::hex;
use runtime_common::account_conversion::AccountConverter;
use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup};
use sc_service::{ChainType, Properties};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -271,8 +271,8 @@ fn centrifuge_genesis(
let chain_id: u32 = id.into();

endowed_accounts.extend(endowed_evm_accounts.into_iter().map(|(addr, id)| {
let chain_id = id.unwrap_or_else(|| chain_id.into());
AccountConverter::convert_evm_address(chain_id, addr)
let chain_id = id.unwrap_or(chain_id.into());
DomainAddress::from_evm(chain_id, addr).as_local()
}));

let num_endowed_accounts = endowed_accounts.len();
Expand Down Expand Up @@ -371,8 +371,8 @@ fn altair_genesis(
let chain_id: u32 = id.into();

endowed_accounts.extend(endowed_evm_accounts.into_iter().map(|(addr, id)| {
let chain_id = id.unwrap_or_else(|| chain_id.into());
AccountConverter::convert_evm_address(chain_id, addr)
let chain_id = id.unwrap_or(chain_id.into());
DomainAddress::from_evm(chain_id, addr).as_local()
}));

let num_endowed_accounts = endowed_accounts.len();
Expand Down Expand Up @@ -472,8 +472,8 @@ fn development_genesis(
let chain_id: u32 = id.into();

endowed_accounts.extend(endowed_evm_accounts.into_iter().map(|(addr, id)| {
let chain_id = id.unwrap_or_else(|| chain_id.into());
AccountConverter::convert_evm_address(chain_id, addr)
let chain_id = id.unwrap_or(chain_id.into());
DomainAddress::from_evm(chain_id, addr).as_local()
}));

let num_endowed_accounts = endowed_accounts.len();
Expand Down
6 changes: 3 additions & 3 deletions pallets/axelar-router/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const LP_CONTRACT_ADDRESS: H160 = H160::repeat_byte(1);
const AXELAR_CONTRACT_ADDRESS: H160 = H160::repeat_byte(2);
const SOURCE_ADDRESS: H160 = H160::repeat_byte(3);
const AXELAR_CONTRACT_HASH: H256 = H256::repeat_byte(42);
const SENDER: DomainAddress = DomainAddress::Centrifuge([0; 32]);
const SENDER: DomainAddress = DomainAddress::Local([0; 32]);
const MESSAGE: &[u8] = &[1, 2, 3];
const FEE_VALUE: U256 = U256::zero();
const GAS_LIMIT: U256 = U256::one();
Expand Down Expand Up @@ -91,7 +91,7 @@ mod send {
correct_configuration();

Transactor::mock_call(move |from, to, data, value, gas_price, gas_limit| {
assert_eq!(from, H160::from_slice(&SENDER.address()[0..20]));
assert_eq!(from, SENDER.as_eth());
assert_eq!(to, AXELAR_CONTRACT_ADDRESS);
assert_eq!(data, &wrap_message(MESSAGE.to_vec()));
assert_eq!(value, FEE_VALUE);
Expand Down Expand Up @@ -143,7 +143,7 @@ mod receive {

Receiver::mock_receive(|middleware, origin, message| {
assert_eq!(middleware, Middleware(AxelarId::Evm(CHAIN_ID)));
assert_eq!(origin, DomainAddress::EVM(CHAIN_ID, SOURCE_ADDRESS.0));
assert_eq!(origin, DomainAddress::Evm(CHAIN_ID, SOURCE_ADDRESS.0));
assert_eq!(&message, MESSAGE);
Ok(())
});
Expand Down
4 changes: 2 additions & 2 deletions pallets/liquidity-pools-gateway/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use frame_support::{derive_impl, weights::constants::RocksDbWeight};
use frame_system::EnsureRoot;
use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
use scale_info::TypeInfo;
use sp_core::{crypto::AccountId32, H256};
use sp_core::{crypto::AccountId32};
use sp_runtime::{traits::IdentityLookup, DispatchError, DispatchResult};

use crate::{pallet as pallet_liquidity_pools_gateway, EnsureLocal, GatewayMessage};
Expand Down Expand Up @@ -115,7 +115,7 @@ impl cfg_mocks::router_message::pallet::Config for Runtime {
}

frame_support::parameter_types! {
pub Sender: DomainAddress = DomainAddress::Centrifuge(AccountId32::from(H256::from_low_u64_be(1).to_fixed_bytes()).into());
pub Sender: DomainAddress = DomainAddress::Local([1; 32]);
pub const MaxIncomingMessageSize: u32 = 1024;
pub const LpAdminAccount: AccountId32 = LP_ADMIN_ACCOUNT;
}
Expand Down
2 changes: 2 additions & 0 deletions pallets/liquidity-pools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,13 @@ pub use message::Message;
pub mod hooks;
mod inbound;

/*
#[cfg(test)]
mod mock;
#[cfg(test)]
mod tests;
*/

pub type GeneralCurrencyIndexType = u128;

Expand Down
4 changes: 2 additions & 2 deletions pallets/liquidity-pools/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ mod tests {
}

#[test]
fn transfer_tranche_tokens_to_moonbeam() {
fn transfer_tranche_tokens_to_chain() {
let domain_address = DomainAddress::Evm(1284, default_address_20());

test_encode_decode_identity(
Expand All @@ -752,7 +752,7 @@ mod tests {
receiver: domain_address.as_local(),
amount: AMOUNT,
},
"120000000000000001811acd5b3f17c06841c7e41e9e04cb1b0100000000000005041231231231231231231231231231231231231231000000000000000000000000000000000052b7d2dcc80cd2e4000000"
"120000000000000001811acd5b3f17c06841c7e41e9e04cb1b0100000000000005041231231231231231231231231231231231231231000000000000050445564d00000000000052b7d2dcc80cd2e4000000"
);
}

Expand Down
84 changes: 36 additions & 48 deletions runtime/integration-tests/src/cases/liquidity_pools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,10 @@ use pallet_liquidity_pools::Message;
use pallet_liquidity_pools_gateway::message::GatewayMessage;
use pallet_liquidity_pools_gateway_queue::MessageNonceStore;
use pallet_pool_system::tranches::{TrancheInput, TrancheLoc, TrancheType};
use runtime_common::{
account_conversion::AccountConverter, foreign_investments::IdentityPoolCurrencyConverter,
xcm::general_key,
};
use runtime_common::{foreign_investments::IdentityPoolCurrencyConverter, xcm::general_key};
use sp_core::Get;
use sp_runtime::{
traits::{AccountIdConversion, Convert, EnsureAdd, One, Zero},
traits::{AccountIdConversion, EnsureAdd, One, Zero},
BoundedVec, DispatchError, FixedPointNumber, Perquintill, SaturatedConversion,
};
use staging_xcm::{
Expand Down Expand Up @@ -72,11 +69,11 @@ pub const POOL_ID: PoolId = 42;
pub const MOONBEAM_EVM_CHAIN_ID: u64 = 1284;
pub const DEFAULT_EVM_ADDRESS_MOONBEAM: [u8; 20] = [99; 20];
pub const DEFAULT_VALIDITY: Seconds = 2555583502;
pub const DOMAIN_MOONBEAM: Domain = Domain::EVM(MOONBEAM_EVM_CHAIN_ID);
pub const DOMAIN_MOONBEAM: Domain = Domain::Evm(MOONBEAM_EVM_CHAIN_ID);
pub const DEFAULT_DOMAIN_ADDRESS_MOONBEAM: DomainAddress =
DomainAddress::EVM(MOONBEAM_EVM_CHAIN_ID, DEFAULT_EVM_ADDRESS_MOONBEAM);
DomainAddress::Evm(MOONBEAM_EVM_CHAIN_ID, DEFAULT_EVM_ADDRESS_MOONBEAM);
pub const DEFAULT_OTHER_DOMAIN_ADDRESS: DomainAddress =
DomainAddress::EVM(MOONBEAM_EVM_CHAIN_ID, [0; 20]);
DomainAddress::Evm(MOONBEAM_EVM_CHAIN_ID, [0; 20]);

pub type LiquidityPoolMessage = Message;

Expand Down Expand Up @@ -280,10 +277,7 @@ pub mod utils {

assert_ok!(orml_tokens::Pallet::<T>::set_balance(
<T as frame_system::Config>::RuntimeOrigin::root(),
AccountId::from(
<T as pallet_liquidity_pools_gateway::Config>::Sender::get().address()
)
.into(),
T::Sender::get().as_local::<AccountId>().into(),
GLMR_CURRENCY_ID,
DEFAULT_BALANCE_GLMR,
0,
Expand Down Expand Up @@ -509,7 +503,7 @@ pub mod utils {
assert_eq!(
orml_tokens::Pallet::<T>::balance(
default_investment_id::<T>().into(),
&AccountConverter::convert(DEFAULT_OTHER_DOMAIN_ADDRESS)
&DEFAULT_OTHER_DOMAIN_ADDRESS.as_local(),
),
0
);
Expand Down Expand Up @@ -683,8 +677,8 @@ mod foreign_investments {
env.parachain_state_mut(|| {
let pool_id = POOL_ID;
let amount = 10 * decimals(12);
let investor =
AccountConverter::domain_account_to_account(DOMAIN_MOONBEAM, Keyring::Bob.id());
let investor: AccountId =
DomainAddress::new(DOMAIN_MOONBEAM, Keyring::Bob.into()).as_local();
let currency_id = AUSD_CURRENCY_ID;
let currency_decimals = currency_decimals::AUSD;

Expand Down Expand Up @@ -731,8 +725,8 @@ mod foreign_investments {
env.parachain_state_mut(|| {
let pool_id = POOL_ID;
let invest_amount: u128 = 10 * decimals(12);
let investor =
AccountConverter::domain_account_to_account(DOMAIN_MOONBEAM, Keyring::Bob.id());
let investor: AccountId =
DomainAddress::new(DOMAIN_MOONBEAM, Keyring::Bob.into()).as_local();
let currency_id: CurrencyId = AUSD_CURRENCY_ID;
let currency_decimals = currency_decimals::AUSD;

Expand Down Expand Up @@ -821,8 +815,8 @@ mod foreign_investments {
env.parachain_state_mut(|| {
let pool_id = POOL_ID;
let invest_amount = 10 * decimals(12);
let investor =
AccountConverter::domain_account_to_account(DOMAIN_MOONBEAM, Keyring::Bob.id());
let investor: AccountId =
DomainAddress::new(DOMAIN_MOONBEAM, Keyring::Bob.into()).as_local();
let currency_id = AUSD_CURRENCY_ID;
let currency_decimals = currency_decimals::AUSD;

Expand Down Expand Up @@ -921,8 +915,8 @@ mod foreign_investments {
env.parachain_state_mut(|| {
let pool_id = POOL_ID;
let amount = 10 * decimals(12);
let investor =
AccountConverter::domain_account_to_account(DOMAIN_MOONBEAM, Keyring::Bob.id());
let investor: AccountId =
DomainAddress::new(DOMAIN_MOONBEAM, Keyring::Bob.into()).as_local();
let currency_id = AUSD_CURRENCY_ID;
let currency_decimals = currency_decimals::AUSD;
let sending_domain_locator =
Expand Down Expand Up @@ -1029,7 +1023,7 @@ mod foreign_investments {

let nonce = MessageNonceStore::<T>::get();

let sender = <T as pallet_liquidity_pools_gateway::Config>::Sender::get();
let sender = T::Sender::get();

// Clearing of foreign InvestState should be dispatched
assert!(frame_system::Pallet::<T>::events().iter().any(|e| {
Expand Down Expand Up @@ -1067,8 +1061,8 @@ mod foreign_investments {
env.parachain_state_mut(|| {
let pool_id = POOL_ID;
let invest_amount = 10 * decimals(12);
let investor =
AccountConverter::domain_account_to_account(DOMAIN_MOONBEAM, Keyring::Bob.id());
let investor: AccountId =
DomainAddress::new(DOMAIN_MOONBEAM, Keyring::Bob.into()).as_local();
let currency_id = AUSD_CURRENCY_ID;
let currency_decimals = currency_decimals::AUSD;
let sending_domain_locator =
Expand Down Expand Up @@ -1304,8 +1298,8 @@ mod foreign_investments {
env.parachain_state_mut(|| {
let pool_id = POOL_ID;
let amount = 10 * decimals(12);
let investor =
AccountConverter::domain_account_to_account(DOMAIN_MOONBEAM, Keyring::Bob.id());
let investor: AccountId =
DomainAddress::new(DOMAIN_MOONBEAM, Keyring::Bob.into()).as_local();
let currency_id = AUSD_CURRENCY_ID;
let currency_decimals = currency_decimals::AUSD;

Expand Down Expand Up @@ -1357,8 +1351,8 @@ mod foreign_investments {
env.parachain_state_mut(|| {
let pool_id = POOL_ID;
let redeem_amount = 10 * decimals(12);
let investor =
AccountConverter::domain_account_to_account(DOMAIN_MOONBEAM, Keyring::Bob.id());
let investor: AccountId =
DomainAddress::new(DOMAIN_MOONBEAM, Keyring::Bob.into()).as_local();
let currency_id = AUSD_CURRENCY_ID;
let currency_decimals = currency_decimals::AUSD;
let sending_domain_locator =
Expand Down Expand Up @@ -1452,8 +1446,8 @@ mod foreign_investments {
env.parachain_state_mut(|| {
let pool_id = POOL_ID;
let redeem_amount = 10 * decimals(12);
let investor =
AccountConverter::domain_account_to_account(DOMAIN_MOONBEAM, Keyring::Bob.id());
let investor: AccountId =
DomainAddress::new(DOMAIN_MOONBEAM, Keyring::Bob.into()).as_local();
let currency_id = AUSD_CURRENCY_ID;
let currency_decimals = currency_decimals::AUSD;
let pool_account = pallet_pool_system::pool_types::PoolLocator { pool_id }
Expand Down Expand Up @@ -1645,10 +1639,8 @@ mod foreign_investments {
env.parachain_state_mut(|| {
let pool_id = POOL_ID;
let amount: u128 = 10 * decimals(12);
let investor = AccountConverter::domain_account_to_account(
DOMAIN_MOONBEAM,
Keyring::Bob.id(),
);
let investor: AccountId =
DomainAddress::new(DOMAIN_MOONBEAM, Keyring::Bob.into()).as_local();
let currency_id: CurrencyId = AUSD_CURRENCY_ID;
let currency_decimals = currency_decimals::AUSD;
create_currency_pool::<T>(pool_id, currency_id, currency_decimals.into());
Expand Down Expand Up @@ -1725,10 +1717,8 @@ mod foreign_investments {
env.parachain_state_mut(|| {
let pool_id = POOL_ID;
let amount: u128 = 10 * decimals(12);
let investor = AccountConverter::domain_account_to_account(
DOMAIN_MOONBEAM,
Keyring::Bob.id(),
);
let investor: AccountId =
DomainAddress::new(DOMAIN_MOONBEAM, Keyring::Bob.into()).as_local();
let currency_id: CurrencyId = AUSD_CURRENCY_ID;
let currency_decimals = currency_decimals::AUSD;
create_currency_pool::<T>(pool_id, currency_id, currency_decimals.into());
Expand Down Expand Up @@ -1815,10 +1805,8 @@ mod foreign_investments {

env.parachain_state_mut(|| {
let pool_id = POOL_ID;
let investor = AccountConverter::domain_account_to_account(
DOMAIN_MOONBEAM,
Keyring::Bob.id(),
);
let investor: AccountId =
DomainAddress::new(DOMAIN_MOONBEAM, Keyring::Bob.into()).as_local();
let pool_currency = AUSD_CURRENCY_ID;
let currency_decimals = currency_decimals::AUSD;
let foreign_currency: CurrencyId = USDT_CURRENCY_ID;
Expand Down Expand Up @@ -1877,8 +1865,8 @@ mod foreign_investments {

env.parachain_state_mut(|| {
let pool_id = POOL_ID;
let investor =
AccountConverter::domain_account_to_account(DOMAIN_MOONBEAM, Keyring::Bob.id());
let investor: AccountId =
DomainAddress::new(DOMAIN_MOONBEAM, Keyring::Bob.into()).as_local();
let pool_currency: CurrencyId = AUSD_CURRENCY_ID;
let foreign_currency: CurrencyId = USDT_CURRENCY_ID;
let pool_currency_decimals = currency_decimals::AUSD;
Expand Down Expand Up @@ -1999,8 +1987,8 @@ mod foreign_investments {

env.parachain_state_mut(|| {
let pool_id = POOL_ID;
let investor =
AccountConverter::domain_account_to_account(DOMAIN_MOONBEAM, Keyring::Bob.id());
let investor: AccountId =
DomainAddress::new(DOMAIN_MOONBEAM, Keyring::Bob.into()).as_local();
let trader: AccountId = Keyring::Alice.into();
let pool_currency: CurrencyId = AUSD_CURRENCY_ID;
let foreign_currency: CurrencyId = USDT_CURRENCY_ID;
Expand Down Expand Up @@ -2147,8 +2135,8 @@ mod foreign_investments {

env.parachain_state_mut(|| {
let pool_id = POOL_ID;
let investor =
AccountConverter::domain_account_to_account(DOMAIN_MOONBEAM, Keyring::Bob.id());
let investor: AccountId =
DomainAddress::new(DOMAIN_MOONBEAM, Keyring::Bob.into()).as_local();
let pool_currency: CurrencyId = AUSD_CURRENCY_ID;
let foreign_currency: CurrencyId = USDT_CURRENCY_ID;
let pool_currency_decimals = currency_decimals::AUSD;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn inbound<T: Runtime + FudgeSupport>() {
let expected_event = env.parachain_state_mut(|| {
let nonce = <T as pallet_liquidity_pools_gateway_queue::Config>::MessageNonce::one();
let message = GatewayMessage::Inbound {
domain_address: DomainAddress::EVM(1, [2; 20]),
domain_address: DomainAddress::Evm(1, [2; 20]),
message: Message::Invalid,
};

Expand Down Expand Up @@ -55,8 +55,8 @@ fn outbound<T: Runtime + FudgeSupport>() {
let expected_event = env.parachain_state_mut(|| {
let nonce = <T as pallet_liquidity_pools_gateway_queue::Config>::MessageNonce::one();
let message = GatewayMessage::Outbound {
sender: DomainAddress::Centrifuge([1; 32]),
destination: Domain::EVM(1),
sender: DomainAddress::Local([1; 32]),
destination: Domain::Evm(1),
message: Message::Invalid,
};

Expand Down
3 changes: 1 addition & 2 deletions runtime/integration-tests/src/cases/lp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ use frame_system::pallet_prelude::OriginFor;
use hex_literal::hex;
use pallet_axelar_router::{AxelarConfig, DomainConfig, EvmConfig, FeeValues};
use pallet_evm::FeeCalculator;
use runtime_common::account_conversion::AccountConverter;
pub use setup_lp::*;
use sp_core::Get;
use sp_runtime::traits::{BlakeTwo256, Hash};
Expand Down Expand Up @@ -86,7 +85,7 @@ pub const EVM_DOMAIN_STR: &str = "TestDomain";
/// The test domain ChainId for the tests.
pub const EVM_DOMAIN_CHAIN_ID: u64 = 1;

pub const EVM_DOMAIN: Domain = Domain::EVM(EVM_DOMAIN_CHAIN_ID);
pub const EVM_DOMAIN: Domain = Domain::Evm(EVM_DOMAIN_CHAIN_ID);

/// Represents Solidity enum Domain.Centrifuge
pub const DOMAIN_CENTRIFUGE: u8 = 0;
Expand Down
Loading

0 comments on commit af9bc6c

Please sign in to comment.