Skip to content

Commit

Permalink
LP v2: fix integration tests (#1915)
Browse files Browse the repository at this point in the history
* chore: update submodule to latest `main` 6d7f242c0dd83b1b5a4f6d506370a1f3ecbef9ce

* wip: fix ITs

* chore: update submodule

* fix: remove sender param from `Transfer*` messages

* chore: cleanup

* docs: setup evm

* fix: msg tests

* fix: more ITs

* fix: missing refactor after rebase

* chore: update submodule to 223a0f36edabc675f8c74c47b20e366178df7ca3

* chore: improvements

* fmt

* Apply suggestions from code review

* chore: bump spec_version

* fmt: taplo
  • Loading branch information
wischli authored Jul 18, 2024
1 parent e7eb61c commit 976eebe
Show file tree
Hide file tree
Showing 24 changed files with 2,072 additions and 1,992 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ license = "LGPL-3.0"
homepage = "https://centrifuge.io/"
repository = "https://github.com/centrifuge/centrifuge-chain"
documentation = "https://reference.centrifuge.io/centrifuge_chain/index.html"
version = "0.13.0"
version = "0.13.1"

[workspace.dependencies]
hex-literal = { version = "0.4.1" }
Expand Down
2 changes: 1 addition & 1 deletion libs/types/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ pub mod liquidity_pools {
///
/// NOTE: Temporarily hardcoded.
pub const SOLIDITY_RESTRICTION_MANAGER_ADDRESS: [u8; 32] =
hex_literal::hex!("96ffc875c1fb9d072c6357920b27e894d2bac2ac000000000000000045564d00");
hex_literal::hex!("193356f6df34af00288f98bbb34d6ec98512ed32000000000000000045564d00");
}
10 changes: 4 additions & 6 deletions pallets/liquidity-pools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ pub mod pallet {
T::OutboundQueue::submit(
who,
destination,
Message::UpdateTrancheTokenPrice {
Message::UpdateTranchePrice {
pool_id: pool_id.into(),
tranche_id: tranche_id.into(),
currency,
Expand Down Expand Up @@ -589,7 +589,6 @@ pub mod pallet {
tranche_id: tranche_id.into(),
amount: amount.into(),
domain: domain_address.domain().into(),
sender: who.into(),
receiver: domain_address.address(),
},
)?;
Expand Down Expand Up @@ -658,10 +657,9 @@ pub mod pallet {
T::OutboundQueue::submit(
who.clone(),
receiver.domain(),
Message::Transfer {
Message::TransferAssets {
amount: amount.into(),
currency,
sender: who.into(),
receiver: receiver.address(),
},
)?;
Expand Down Expand Up @@ -792,7 +790,7 @@ pub mod pallet {
T::OutboundQueue::submit(
who,
domain,
Message::UpdateTrancheTokenMetadata {
Message::UpdateTrancheMetadata {
pool_id: pool_id.into(),
tranche_id: tranche_id.into(),
token_name,
Expand Down Expand Up @@ -968,7 +966,7 @@ pub mod pallet {
});

match msg {
Message::Transfer {
Message::TransferAssets {
currency,
receiver,
amount,
Expand Down
77 changes: 45 additions & 32 deletions pallets/liquidity-pools/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,29 +84,32 @@ pub enum Message {
// --- Gateway ---
/// Proof a message has been executed.
///
/// Directionality: Centrifuge -> EVM Domain. // TODO(@william): Check
/// Directionality: Centrifuge -> EVM Domain.
MessageProof {
// Hash of the message for which the proof is provided
hash: [u8; 32],
},
/// Initiate the recovery of a message.
///
/// Must only be callable by root.
///
/// Directionality: Centrifuge -> EVM Domain. // TODO(@william): Check
/// Directionality: Centrifuge -> EVM Domain.
InitiateMessageRecovery {
/// The hash of the message which shall be recovered
hash: [u8; 32],
/// The address of the router
address: Address,
},
/// Dispute the recovery of a message.
///
/// Must only be callable by root.
///
/// Directionality: Centrifuge -> EVM Domain. // TODO(@william): Check
/// Directionality: Centrifuge -> EVM Domain.
DisputeMessageRecovery {
/// The hash of the message which shall be disputed
hash: [u8; 32],
},
// TODO(@william): Fields + docs
// TODO(@william): Add fields + docs
Batch,
// --- Root ---
/// Schedules an EVM address to become rely-able by the gateway. Intended to
Expand Down Expand Up @@ -198,7 +201,7 @@ pub enum Message {
/// Update the price of a tranche token on the target domain.
///
/// Directionality: Centrifuge -> EVM Domain.
UpdateTrancheTokenPrice {
UpdateTranchePrice {
pool_id: u64,
tranche_id: TrancheId,
currency: u128,
Expand All @@ -212,13 +215,19 @@ pub enum Message {
/// migrating all associated balances.
///
/// Directionality: Centrifuge -> EVM Domain.
UpdateTrancheTokenMetadata {
UpdateTrancheMetadata {
pool_id: u64,
tranche_id: TrancheId,
#[serde(with = "serde_big_array::BigArray")]
token_name: [u8; TOKEN_NAME_SIZE],
token_symbol: [u8; TOKEN_SYMBOL_SIZE],
},
UpdateTrancheHook {
tranche_id: TrancheId,
/// The address to be used for this tranche token on the domain it will
/// be added and subsequently deployed in.
hook: Address,
},
/// Transfer non-tranche tokens fungibles. For v2, it will only support
/// stable-coins.
///
Expand All @@ -228,9 +237,8 @@ pub enum Message {
/// For Centrifuge -> EVM Domain: `AddAsset` should have been called
/// beforehand. For Centrifuge <- EVM Domain: We can assume `AddAsset`
/// has been called for that domain already.
Transfer {
TransferAssets {
currency: u128,
sender: Address,
receiver: Address,
amount: u128,
},
Expand All @@ -240,7 +248,6 @@ pub enum Message {
TransferTrancheTokens {
pool_id: u64,
tranche_id: TrancheId,
sender: Address,
domain: SerializableDomain,
receiver: Address,
amount: u128,
Expand Down Expand Up @@ -385,8 +392,18 @@ pub enum Message {
/// decreased by.
tranche_tokens_payout: u128,
},
// TODO(@william): Add fields + docs
TriggerRedeemRequest,
TriggerRedeemRequest {
/// The pool id
pool_id: u64,
/// The tranche id
tranche_id: TrancheId,
/// The investor's address
investor: Address,
/// The currency in which the redeem request should be realised in.
currency: u128,
/// The amount of tranche tokens which should be redeemed.
amount: u128,
},
}

impl LPEncoding for Message {
Expand Down Expand Up @@ -555,7 +572,7 @@ mod tests {
#[test]
fn update_tranche_token_price() {
test_encode_decode_identity(
Message::UpdateTrancheTokenPrice {
Message::UpdateTranchePrice {
pool_id: 1,
tranche_id: default_tranche_id(),
currency: TOKEN_ID,
Expand All @@ -577,33 +594,31 @@ mod tests {
valid_until: 1706260138,
}
},
"120000000000000002811acd5b3f17c06841c7e41e9e04cb1b0145645645645645645645645645645645645645645645645645645645645645640000000065b376aa",
"130000000000000002811acd5b3f17c06841c7e41e9e04cb1b0145645645645645645645645645645645645645645645645645645645645645640000000065b376aa",
)
}

#[test]
fn transfer_to_evm_address() {
test_encode_decode_identity(
Message::Transfer {
Message::TransferAssets {
currency: TOKEN_ID,
sender: default_address_32(),
receiver: vec_to_fixed_array(default_address_20()),
amount: AMOUNT,
},
"100000000000000000000000000eb5ec7b45645645645645645645645645645645645645645645645645645645645645641231231231231231231231231231231231231231000000000000000000000000000000000052b7d2dcc80cd2e4000000"
"110000000000000000000000000eb5ec7b1231231231231231231231231231231231231231000000000000000000000000000000000052b7d2dcc80cd2e4000000"
);
}

#[test]
fn transfer_to_centrifuge() {
test_encode_decode_identity(
Message::Transfer {
Message::TransferAssets {
currency: TOKEN_ID,
sender: vec_to_fixed_array(default_address_20()),
receiver: default_address_32(),
amount: AMOUNT,
},
"100000000000000000000000000eb5ec7b12312312312312312312312312312312312312310000000000000000000000004564564564564564564564564564564564564564564564564564564564564564000000000052b7d2dcc80cd2e4000000"
"110000000000000000000000000eb5ec7b4564564564564564564564564564564564564564564564564564564564564564000000000052b7d2dcc80cd2e4000000"
);
}

Expand All @@ -615,12 +630,11 @@ mod tests {
Message::TransferTrancheTokens {
pool_id: 1,
tranche_id: default_tranche_id(),
sender: default_address_32(),
domain: domain_address.domain().into(),
receiver: domain_address.address(),
amount: AMOUNT,
},
"110000000000000001811acd5b3f17c06841c7e41e9e04cb1b45645645645645645645645645645645645645645645645645645645645645640100000000000005041231231231231231231231231231231231231231000000000000000000000000000000000052b7d2dcc80cd2e4000000"
"120000000000000001811acd5b3f17c06841c7e41e9e04cb1b0100000000000005041231231231231231231231231231231231231231000000000000000000000000000000000052b7d2dcc80cd2e4000000"
);
}

Expand All @@ -630,12 +644,11 @@ mod tests {
Message::TransferTrancheTokens {
pool_id: 1,
tranche_id: default_tranche_id(),
sender: vec_to_fixed_array(default_address_20()),
domain: Domain::Centrifuge.into(),
receiver: default_address_32(),
amount: AMOUNT,
},
"110000000000000001811acd5b3f17c06841c7e41e9e04cb1b12312312312312312312312312312312312312310000000000000000000000000000000000000000004564564564564564564564564564564564564564564564564564564564564564000000000052b7d2dcc80cd2e4000000"
"120000000000000001811acd5b3f17c06841c7e41e9e04cb1b0000000000000000004564564564564564564564564564564564564564564564564564564564564564000000000052b7d2dcc80cd2e4000000"
)
}

Expand All @@ -649,7 +662,7 @@ mod tests {
currency: TOKEN_ID,
amount: AMOUNT,
},
"130000000000000001811acd5b3f17c06841c7e41e9e04cb1b45645645645645645645645645645645645645645645645645645645645645640000000000000000000000000eb5ec7b000000000052b7d2dcc80cd2e4000000",
"140000000000000001811acd5b3f17c06841c7e41e9e04cb1b45645645645645645645645645645645645645645645645645645645645645640000000000000000000000000eb5ec7b000000000052b7d2dcc80cd2e4000000",
)
}

Expand All @@ -662,7 +675,7 @@ mod tests {
investor: default_address_32(),
currency: TOKEN_ID,
},
"170000000000000001811acd5b3f17c06841c7e41e9e04cb1b45645645645645645645645645645645645645645645645645645645645645640000000000000000000000000eb5ec7b",
"180000000000000001811acd5b3f17c06841c7e41e9e04cb1b45645645645645645645645645645645645645645645645645645645645645640000000000000000000000000eb5ec7b",
)
}

Expand All @@ -676,7 +689,7 @@ mod tests {
currency: TOKEN_ID,
amount: AMOUNT,
},
"140000000000000001811acd5b3f17c06841c7e41e9e04cb1b45645645645645645645645645645645645645645645645645645645645645640000000000000000000000000eb5ec7b000000000052b7d2dcc80cd2e4000000",
"150000000000000001811acd5b3f17c06841c7e41e9e04cb1b45645645645645645645645645645645645645645645645645645645645645640000000000000000000000000eb5ec7b000000000052b7d2dcc80cd2e4000000",
)
}

Expand All @@ -689,7 +702,7 @@ mod tests {
investor: default_address_32(),
currency: TOKEN_ID,
},
"180000000000000001811acd5b3f17c06841c7e41e9e04cb1b45645645645645645645645645645645645645645645645645645645645645640000000000000000000000000eb5ec7b",
"190000000000000001811acd5b3f17c06841c7e41e9e04cb1b45645645645645645645645645645645645645645645645645645645645645640000000000000000000000000eb5ec7b",
)
}

Expand All @@ -704,7 +717,7 @@ mod tests {
currency_payout: AMOUNT / 2,
fulfilled_invest_amount: AMOUNT / 4,
},
"190000000000bce1a4811acd5b3f17c06841c7e41e9e04cb1b12312312312312312312312312312312312312310000000000000000000000000000000000000000000000000eb5ec7b0000000000295be96e64066972000000000000000014adf4b7320334b9000000",
"1a0000000000bce1a4811acd5b3f17c06841c7e41e9e04cb1b12312312312312312312312312312312312312310000000000000000000000000000000000000000000000000eb5ec7b0000000000295be96e64066972000000000000000014adf4b7320334b9000000",
)
}

Expand All @@ -718,7 +731,7 @@ mod tests {
currency: TOKEN_ID,
tranche_tokens_payout: AMOUNT / 2,
},
"1a0000000000bce1a4811acd5b3f17c06841c7e41e9e04cb1b12312312312312312312312312312312312312310000000000000000000000000000000000000000000000000eb5ec7b0000000000295be96e64066972000000",
"1b0000000000bce1a4811acd5b3f17c06841c7e41e9e04cb1b12312312312312312312312312312312312312310000000000000000000000000000000000000000000000000eb5ec7b0000000000295be96e64066972000000",
)
}

Expand All @@ -733,7 +746,7 @@ mod tests {
currency_payout: AMOUNT,
tranche_tokens_payout: AMOUNT / 2,
},
"150000000000bce1a4811acd5b3f17c06841c7e41e9e04cb1b12312312312312312312312312312312312312310000000000000000000000000000000000000000000000000eb5ec7b000000000052b7d2dcc80cd2e40000000000000000295be96e64066972000000",
"160000000000bce1a4811acd5b3f17c06841c7e41e9e04cb1b12312312312312312312312312312312312312310000000000000000000000000000000000000000000000000eb5ec7b000000000052b7d2dcc80cd2e40000000000000000295be96e64066972000000",
)
}

Expand All @@ -748,7 +761,7 @@ mod tests {
currency_payout: AMOUNT,
tranche_tokens_payout: AMOUNT / 2,
},
"160000000000bce1a4811acd5b3f17c06841c7e41e9e04cb1b12312312312312312312312312312312312312310000000000000000000000000000000000000000000000000eb5ec7b000000000052b7d2dcc80cd2e40000000000000000295be96e64066972000000",
"170000000000bce1a4811acd5b3f17c06841c7e41e9e04cb1b12312312312312312312312312312312312312310000000000000000000000000000000000000000000000000eb5ec7b000000000052b7d2dcc80cd2e40000000000000000295be96e64066972000000",
)
}

Expand All @@ -775,7 +788,7 @@ mod tests {
#[test]
fn update_tranche_token_metadata() {
test_encode_decode_identity(
Message::UpdateTrancheTokenMetadata {
Message::UpdateTrancheMetadata {
pool_id: 1,
tranche_id: default_tranche_id(),
token_name: vec_to_fixed_array(b"Some Name"),
Expand Down
6 changes: 2 additions & 4 deletions pallets/liquidity-pools/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,8 @@ mod transfer {
assert_eq!(destination, EVM_DOMAIN_ADDRESS.domain());
assert_eq!(
msg,
Message::Transfer {
Message::TransferAssets {
currency: util::currency_index(CURRENCY_ID),
sender: ALICE.into(),
receiver: EVM_DOMAIN_ADDRESS.address(),
amount: AMOUNT
}
Expand Down Expand Up @@ -307,7 +306,6 @@ mod transfer_tranche_tokens {
Message::TransferTrancheTokens {
pool_id: POOL_ID,
tranche_id: TRANCHE_ID,
sender: ALICE.into(),
domain: EVM_DOMAIN_ADDRESS.domain().into(),
receiver: EVM_DOMAIN_ADDRESS.address(),
amount: AMOUNT
Expand Down Expand Up @@ -642,7 +640,7 @@ mod update_token_price {
assert_eq!(destination, EVM_DOMAIN_ADDRESS.domain());
assert_eq!(
msg,
Message::UpdateTrancheTokenPrice {
Message::UpdateTranchePrice {
pool_id: POOL_ID,
tranche_id: TRANCHE_ID,
currency: util::currency_index(CURRENCY_ID),
Expand Down
Loading

0 comments on commit 976eebe

Please sign in to comment.