Skip to content

Commit

Permalink
Feat: LP integration tests (#1720)
Browse files Browse the repository at this point in the history
* feat: wip build script

* wip: intermediate

* feat: update lp submodule

* feat: update lp submodule

* feat: intermedaite

* feat: deploy first code

* feat: add raw

* feat: add raw

* feat: first run for deploying on sol side

* feat: add notes for tomorrow

* feat: evm side setup

* update remote lp

* feat: try using local script

* feat: update lp deps

* fix: latest sol version does not have reference anymore.

* feat: erc20 deploys

* feat: set router

* feat: register assets

* feat: add currencies to local lp deployment

* feat: test AddCurrency msg

* chore: reorg

* feat: addPool test

* chore: refactor prep new tests

* chore: refactor tests

* wip: test add_tranche

* fix: apply merge

* docs: improve + show todos

* chore: finish setup tests

* fix: use correct evm currency addresses

* fix: setup requirements

* tests: finish allow, disallow investment currency

* feat: new evm exposure

* fix: add_currency and add_pool

* fix: rm unssued

* chore: clean up

* feat: allow different verifier after process outbound

* wip: adding redo failing test

* feat: failure testable

* feat: register evm contract

* fix: lp deployment

* chore: update submodule branch

* refactor: sync evm setup order with solidity

* deps: update submodule

* wip: update submodule

* wip: attempt different sourceAddress

* Fix/lp integration tests member (#1779)

* wip

* feat: update member

* feat: mint assets to investors at setup

* tests: finish add_tranche

* chore: add names for lp tranche id stable coins

* tests: finish allow_investment_currency

* tests: finish disallow_investment_currency

* fix: add evm approve to investor setup

* wip: increase invest order

* tests: finish update_tranche_token_metadata

* tests: finish update_tranche_token_price

* tests: add transfer_tranche_tokens

* tests: add transfer_tokens

* chore: apply suggestions from code review

* chore: remove increase invest test

* fmt: taplo

* wip: fix missing EVM build in target dir

* wip attempt 2: add submodule update

* wip 3: use du instead of ll debug

* wip 4: graceful panic handler ci

* wip 4

* wip 5

* wip 5

* wip 6

* wip 7

* wip

* wip

* wip

* wip 10

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip: disable scache

* wip: use SCCACHE_RECACHE

* wip: reenable sscache

* wip: investment_collect

* fix: issue with precompile account codes

* fix: runtime generic precompile

* wip: adding 3 pool with foreign usdc

* wip: invest working, verifying collect

* feat: invest and collect

* feat: cancel investment

* wip

* feat: additional test

* Add checks for submodules in GHA

* commit-test (#1822)

* commit-test

* try with the home directory full

* testing

* supress cargo output

* keep checking submodules

* typo

* typo 2

* remove echo

* typo "s"

* Add ./ to folders in ci run

* better checks

* better runtime folder logic

* unbound variable

* slow down logs

* remove concurrency, add logs to output

* completely removed concurrency

* infinite loop

* output the contents of target dir

* log current dir and files

* break the loop when cargo finishes

* max depth of target output

* check for release folder

* remove the target output verbose

* output cargo logs into a file

* log current dir and files also in error msg

* remove the idea  of output file

* try to get rust logs working

* fix: error logs

* disable verbose cargo test logs

* fix: typo

* add rust cwd

* fix cwd for submodules dir

* debug submodules dir

* distinguish between error and not error

* more lightweight error

* debug cwd in evm.rs

* add tmp build step

* fix verbose logging

* add foundry

* add more printlns

* reduce noise strict

* revert debug changes

* docs: improve LP_SOL_SOURCES error msg and rustdocs

* fmt: taplo

---------

Co-authored-by: William Freudenberger <[email protected]>

* fix: clippy 1

* fix: clippy 2

* fix: clippy 3

* ci: re-enable submodule pulling (#1863)

* wip: try roundtrip transfer

* feat: roundtrip tests

* fix: add_tranche

* feat: tt transfer to Centrifuge

* chore: remove debug tests

* chore: rm test that is now covered in lp/transfers

* feat: move existing test to generic

* fix: eth tx after merge main

* fix: failing precompile test

* feat: enable precompile for all runtimes

* fix: transfers

* fix: after merge main

* fix: fmt with nightly

* fix: import

* fix: unneeded import

* fix: env and block

* fix: ethereum transact inte test

* chore: review suggestion use parachain_state_mut

* fix: part 1 build script

* chore: mv naming for Luis

* chore: make precompile associated type

* fix: wrong imports of Precompiles from runtimes

* chore: remove unneeded conversion H160

---------

Co-authored-by: William Freudenberger <[email protected]>
Co-authored-by: Guillermo Perez <[email protected]>
  • Loading branch information
3 people authored Jun 13, 2024
1 parent b1a000b commit 3b6a8c9
Show file tree
Hide file tree
Showing 53 changed files with 5,070 additions and 831 deletions.
19 changes: 14 additions & 5 deletions .github/workflows/sanity-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@ concurrency:
group: 'tests-${{ github.event.pull_request.head.label || github.head_ref || github.ref }}'
cancel-in-progress: true
permissions:
id-token: write
contents: read
id-token: write
contents: read
jobs:
test-n-lint:
name: ${{ matrix.target }}
runs-on: ubuntu-latest-8-cores
strategy:
matrix:
target: [test-general, test-integration,
lint-fmt, lint-clippy, cargo-build, docs-build, lint-taplo]
target: [ test-general, test-integration,
lint-fmt, lint-clippy, cargo-build, docs-build, lint-taplo ]
steps:
- name: Check out code
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b #4.1.4
with:
submodules: 'recursive'

- name: Prep build
uses: ./.github/actions/prep-ubuntu
Expand All @@ -27,6 +29,10 @@ jobs:
GWIP: ${{ secrets.GWIP_SCCACHE }}
GSA: ${{ secrets.GSA_SCCACHE }}

# Required for integration tests evm interaction
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1

- name: Runing cargo ${{ matrix.target }}
run: ./ci/run-check.sh
env:
Expand All @@ -38,10 +44,12 @@ jobs:
runs-on: ubuntu-latest #-4-cores
strategy:
matrix:
runtime: [altair, centrifuge]
runtime: [ altair, centrifuge ]
steps:
- name: Check out code
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b #4.1.4
with:
submodules: 'recursive'

- name: Prep build
uses: ./.github/actions/prep-ubuntu
Expand All @@ -50,6 +58,7 @@ jobs:
GWIP: ${{ secrets.GWIP_SCCACHE }}
GSA: ${{ secrets.GSA_SCCACHE }}


- name: Runing cargo ${{ matrix.target }}
run: ./ci/run-check.sh
env:
Expand Down
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "runtime/integration-tests/submodules/liquidity-pools"]
path = runtime/integration-tests/submodules/liquidity-pools
url = [email protected]:centrifuge/liquidity-pools.git
branch = centrifuge-chain/release-v1.0
19 changes: 13 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion libs/types/src/domain_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ pub enum DomainAddress {
EVM(EVMChainId, [u8; 20]),
}

impl DomainAddress {
pub fn evm(chain_id: EVMChainId, address: [u8; 20]) -> Self {
Self::EVM(chain_id, address)
}

pub fn centrifuge(address: [u8; 32]) -> Self {
Self::Centrifuge(address)
}
}

impl From<DomainAddress> for Domain {
fn from(x: DomainAddress) -> Self {
match x {
Expand All @@ -100,7 +110,7 @@ impl DomainAddress {
pub fn address(&self) -> [u8; 32] {
match self.clone() {
Self::Centrifuge(x) => x,
Self::EVM(_, x) => vec_to_fixed_array(x.to_vec()),
Self::EVM(_, x) => vec_to_fixed_array(x),
}
}

Expand Down
6 changes: 3 additions & 3 deletions libs/types/src/tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,18 +175,18 @@ pub struct GeneralCurrencyIndex<Index, Prefix> {
_phantom: PhantomData<Prefix>,
}

impl<Index, Prefix> TryInto<GeneralCurrencyIndex<Index, Prefix>> for CurrencyId
impl<Index, Prefix> TryFrom<CurrencyId> for GeneralCurrencyIndex<Index, Prefix>
where
Index: From<u128>,
Prefix: Get<[u8; 12]>,
{
type Error = DispatchError;

fn try_into(self) -> Result<GeneralCurrencyIndex<Index, Prefix>, Self::Error> {
fn try_from(value: CurrencyId) -> Result<GeneralCurrencyIndex<Index, Prefix>, Self::Error> {
let mut bytes = [0u8; 16];
bytes[..12].copy_from_slice(&Prefix::get());

let currency_bytes: [u8; 4] = match &self {
let currency_bytes: [u8; 4] = match &value {
CurrencyId::ForeignAsset(id32) => Ok(id32.to_be_bytes()),
_ => Err(DispatchError::Token(TokenError::Unsupported)),
}?;
Expand Down
6 changes: 3 additions & 3 deletions libs/utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ use sp_std::{cmp::min, vec::Vec};
/// Build a fixed-size array using as many elements from `src` as possible
/// without overflowing and ensuring that the array is 0 padded in the case
/// where `src.len()` is smaller than S.
pub fn vec_to_fixed_array<const S: usize>(src: Vec<u8>) -> [u8; S] {
pub fn vec_to_fixed_array<const S: usize>(src: impl AsRef<[u8]>) -> [u8; S] {
let mut dest = [0; S];
let len = min(src.len(), S);
dest[..len].copy_from_slice(&src.as_slice()[..len]);
let len = min(src.as_ref().len(), S);
dest[..len].copy_from_slice(&src.as_ref()[..len]);

dest
}
Expand Down
34 changes: 6 additions & 28 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
// module level.
#![allow(clippy::derive_partial_eq_without_eq)]

use std::collections::BTreeMap;

use altair_runtime::constants::currency::{AIR, MILLI_AIR};
use cfg_primitives::{
currency_decimals, parachains, AccountId, AuraId, Balance, BlockNumber, CFG, MILLI_CFG,
Expand All @@ -36,11 +34,11 @@ use cfg_types::{
use cfg_utils::vec_to_fixed_array;
use cumulus_primitives_core::ParaId;
use hex_literal::hex;
use runtime_common::{account_conversion::AccountConverter, evm::precompile::H160Addresses};
use runtime_common::account_conversion::AccountConverter;
use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup};
use sc_service::{ChainType, Properties};
use serde::{Deserialize, Serialize};
use sp_core::{sr25519, Encode, Pair, Public, H160};
use sp_core::{sr25519, Encode, Pair, Public};
use sp_runtime::{
traits::{IdentifyAccount, Verify},
FixedPointNumber,
Expand All @@ -58,10 +56,7 @@ pub type CentrifugeChainSpec =
pub type DevelopmentChainSpec =
sc_service::GenericChainSpec<development_runtime::RuntimeGenesisConfig, Extensions>;

use altair_runtime::AltairPrecompiles;
use centrifuge_runtime::CentrifugePrecompiles;
use cfg_types::fixed_point::Rate;
use development_runtime::DevelopmentPrecompiles;

/// Helper function to generate a crypto pair from seed
pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {
Expand Down Expand Up @@ -357,7 +352,7 @@ fn centrifuge_genesis(
"chainId": Into::<u32>::into(chain_id),
},
"evm": {
"accounts": precompile_account_genesis::<CentrifugePrecompiles>(),
"accounts": runtime_common::evm::precompile::utils::precompile_account_genesis::<centrifuge_runtime::Precompiles>(),
},
"polkadotXcm": {
"safeXcmVersion": Some(SAFE_XCM_VERSION),
Expand Down Expand Up @@ -451,7 +446,7 @@ fn altair_genesis(
"chainId": Into::<u32>::into(chain_id),
},
"evm": {
"accounts": precompile_account_genesis::<AltairPrecompiles>(),
"accounts": runtime_common::evm::precompile::utils::precompile_account_genesis::<altair_runtime::Precompiles>(),
},
"polkadotXcm": {
"safeXcmVersion": Some(SAFE_XCM_VERSION),
Expand Down Expand Up @@ -594,7 +589,7 @@ fn development_genesis(
"chainId": Into::<u32>::into(chain_id),
},
"evm": {
"accounts": precompile_account_genesis::<DevelopmentPrecompiles>(),
"accounts": runtime_common::evm::precompile::utils::precompile_account_genesis::<development_runtime::Precompiles>(),
},
"polkadotXcm": {
"safeXcmVersion": Some(SAFE_XCM_VERSION),
Expand Down Expand Up @@ -648,7 +643,7 @@ fn asset_registry_assets() -> Vec<(CurrencyId, Vec<u8>)> {
Parachain(parachains::rococo::acala::ID),
GeneralKey {
length: parachains::rococo::acala::AUSD_KEY.to_vec().len() as u8,
data: vec_to_fixed_array(parachains::rococo::acala::AUSD_KEY.to_vec()),
data: vec_to_fixed_array(parachains::rococo::acala::AUSD_KEY),
},
],
))),
Expand Down Expand Up @@ -724,20 +719,3 @@ fn asset_registry_assets() -> Vec<(CurrencyId, Vec<u8>)> {
),
]
}

fn precompile_account_genesis<PrecompileSet: H160Addresses>(
) -> BTreeMap<H160, fp_evm::GenesisAccount> {
PrecompileSet::h160_addresses()
.map(|addr| {
(
addr,
fp_evm::GenesisAccount {
nonce: Default::default(),
balance: Default::default(),
storage: Default::default(),
code: runtime_common::evm::precompile::utils::REVERT_BYTECODE.to_vec(),
},
)
})
.collect()
}
2 changes: 1 addition & 1 deletion pallets/ethereum-transaction/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ pub mod pallet {
}),
})?;

// NOTE: The Ethereuem side of things never returns a DispatchError
// NOTE: The Ethereum side of things never returns a DispatchError
// if the execution failed. But we can check that manually by
// querying the `Pending` storage of the pallet-ethereum.
let pending = pallet_ethereum::Pending::<T>::get();
Expand Down
6 changes: 4 additions & 2 deletions pallets/investments/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2510,15 +2510,17 @@ fn collecting_fully_works() {
#[allow(non_snake_case)]
let SINGLE_REDEEM_AMOUNT_C = 50 * CURRENCY;
#[allow(non_snake_case)]
let TOTAL_REDEEM_AMOUNT = SINGLE_REDEEM_AMOUNT_A + SINGLE_REDEEM_AMOUNT_B + SINGLE_REDEEM_AMOUNT_C;
let TOTAL_REDEEM_AMOUNT =
SINGLE_REDEEM_AMOUNT_A + SINGLE_REDEEM_AMOUNT_B + SINGLE_REDEEM_AMOUNT_C;
#[allow(non_snake_case)]
let SINGLE_INVEST_AMOUNT_A = 50 * CURRENCY;
#[allow(non_snake_case)]
let SINGLE_INVEST_AMOUNT_B = 50 * CURRENCY;
#[allow(non_snake_case)]
let SINGLE_INVEST_AMOUNT_C = 50 * CURRENCY;
#[allow(non_snake_case)]
let TOTAL_INVEST_AMOUNT = SINGLE_INVEST_AMOUNT_A + SINGLE_INVEST_AMOUNT_B + SINGLE_INVEST_AMOUNT_C;
let TOTAL_INVEST_AMOUNT =
SINGLE_INVEST_AMOUNT_A + SINGLE_INVEST_AMOUNT_B + SINGLE_INVEST_AMOUNT_C;
#[allow(non_snake_case)]
let FULL_FULFILL = FulfillmentWithPrice {
of_amount: Perquintill::one(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ pub struct SourceConverter {
pub domain: Domain,
}

impl SourceConverter {
pub fn new(domain: Domain) -> Self {
Self { domain }
}
}

impl SourceConverter {
pub fn try_convert(&self, maybe_address: &[u8]) -> Option<DomainAddress> {
match self.domain {
Expand Down
14 changes: 14 additions & 0 deletions pallets/liquidity-pools-gateway/routers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,20 @@ where
pub _marker: PhantomData<T>,
}

impl<T> EVMRouter<T>
where
T: frame_system::Config + pallet_ethereum_transaction::Config + pallet_evm::Config,
OriginFor<T>:
From<pallet_ethereum::Origin> + Into<Result<pallet_ethereum::Origin, OriginFor<T>>>,
{
pub fn new(evm_domain: EVMDomain) -> Self {
Self {
evm_domain,
_marker: Default::default(),
}
}
}

impl<T> EVMRouter<T>
where
T: frame_system::Config + pallet_ethereum_transaction::Config + pallet_evm::Config,
Expand Down
13 changes: 13 additions & 0 deletions pallets/liquidity-pools-gateway/routers/src/routers/axelar_evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,19 @@ where
OriginFor<T>:
From<pallet_ethereum::Origin> + Into<Result<pallet_ethereum::Origin, OriginFor<T>>>,
{
pub fn new(
router: EVMRouter<T>,
evm_chain: BoundedVec<u8, ConstU32<MAX_AXELAR_EVM_CHAIN_SIZE>>,
liquidity_pools_contract_address: H160,
) -> Self {
Self {
router,
evm_chain,
liquidity_pools_contract_address,
_marker: Default::default(),
}
}

/// Calls the init function on the EVM router.
pub fn do_init(&self) -> DispatchResult {
self.router.do_init()
Expand Down
8 changes: 4 additions & 4 deletions pallets/liquidity-pools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,8 @@ pub mod pallet {
let investment_id = Self::derive_invest_id(pool_id, tranche_id)?;
let metadata = T::AssetRegistry::metadata(&investment_id.into())
.ok_or(Error::<T>::TrancheMetadataNotFound)?;
let token_name = vec_to_fixed_array(metadata.name.into_inner());
let token_symbol = vec_to_fixed_array(metadata.symbol.into_inner());
let token_name = vec_to_fixed_array(metadata.name);
let token_symbol = vec_to_fixed_array(metadata.symbol);

// Send the message to the domain
T::OutboundQueue::submit(
Expand Down Expand Up @@ -793,8 +793,8 @@ pub mod pallet {
let investment_id = Self::derive_invest_id(pool_id, tranche_id)?;
let metadata = T::AssetRegistry::metadata(&investment_id.into())
.ok_or(Error::<T>::TrancheMetadataNotFound)?;
let token_name = vec_to_fixed_array(metadata.name.into_inner());
let token_symbol = vec_to_fixed_array(metadata.symbol.into_inner());
let token_name = vec_to_fixed_array(metadata.name);
let token_symbol = vec_to_fixed_array(metadata.symbol);

T::OutboundQueue::submit(
who,
Expand Down
Loading

0 comments on commit 3b6a8c9

Please sign in to comment.