Skip to content

Commit

Permalink
feat: cfe events pallet
Browse files Browse the repository at this point in the history
  • Loading branch information
msgmaxim committed Jan 11, 2024
1 parent c4aa0e1 commit b546f91
Show file tree
Hide file tree
Showing 40 changed files with 1,103 additions and 428 deletions.
37 changes: 37 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ members = [
'state-chain/pallets/cf-swapping',
'state-chain/pallets/cf-witnesser',
'state-chain/pallets/cf-tokenholder-governance',
'state-chain/pallets/cf-cfe-event-emitter',
'state-chain/cf-integration-tests',
'state-chain/runtime-upgrade-utilities',
'state-chain/runtime-utilities',
Expand All @@ -36,6 +37,7 @@ members = [
'state-chain/runtime',
'state-chain/traits',
'state-chain/primitives',
'state-chain/cfe-events',
'engine',
'engine/generate-genesis-keys',
'utilities',
Expand Down
1 change: 1 addition & 0 deletions engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ pallet-cf-threshold-signature = { path = "../state-chain/pallets/cf-threshold-si
pallet-cf-validator = { path = "../state-chain/pallets/cf-validator" }
pallet-cf-vaults = { path = "../state-chain/pallets/cf-vaults" }
pallet-cf-witnesser = { path = "../state-chain/pallets/cf-witnesser" }
pallet-cf-cfe-event-emitter = { path = "../state-chain/pallets/cf-cfe-event-emitter" }
state-chain-runtime = { path = "../state-chain/runtime" }
utilities = { path = "../utilities" }

Expand Down
321 changes: 118 additions & 203 deletions engine/src/state_chain_observer/sc_observer/mod.rs

Large diffs are not rendered by default.

53 changes: 17 additions & 36 deletions engine/src/state_chain_observer/sc_observer/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,17 @@ use crate::{
test_helpers::test_header,
},
};
use cf_chains::{
evm::{SchnorrVerificationComponents, Transaction},
Chain, ChainCrypto,
};
use cf_chains::{evm::Transaction, Chain, ChainCrypto};
use cf_primitives::{AccountRole, GENESIS_EPOCH};
use frame_system::Phase;
use futures::FutureExt;
use mockall::predicate::eq;
use multisig::{eth::EvmCryptoScheme, ChainSigning, SignatureToThresholdSignature};
use pallet_cf_cfe_event_emitter::{CfeEvent, TxBroadcastRequest};
use sp_runtime::AccountId32;

use sp_core::H256;
use state_chain_runtime::{
AccountId, BitcoinInstance, EthereumInstance, PolkadotInstance, Runtime, RuntimeCall,
RuntimeEvent,
};
use utilities::MakeCachedStream;

Expand All @@ -40,9 +36,6 @@ use utilities::task_scope::task_scope;

use super::crypto_compat::CryptoCompat;

const MOCK_ETH_TRANSACTION_OUT_ID: SchnorrVerificationComponents =
SchnorrVerificationComponents { s: [0; 32], k_times_g_address: [1; 20] };

async fn start_sc_observer<
BlockStream: crate::state_chain_observer::client::StateChainStreamApi,
>(
Expand Down Expand Up @@ -85,37 +78,25 @@ async fn only_encodes_and_signs_when_specified() {
let sc_block_stream =
tokio_stream::iter([block]).make_cached(test_header(20, None), |block| *block);

use state_chain_runtime::Runtime;

state_chain_client
.expect_storage_value::<frame_system::Events<Runtime>>()
.with(eq(block.hash))
.expect_storage_map_entry::<pallet_cf_cfe_event_emitter::CfeEvents<Runtime>>()
.with(eq(block.hash), eq(block.number))
.once()
.return_once(move |_| {
Ok(vec![
Box::new(frame_system::EventRecord {
phase: Phase::ApplyExtrinsic(0),
event: RuntimeEvent::EthereumBroadcaster(
pallet_cf_broadcast::Event::TransactionBroadcastRequest {
broadcast_id: Default::default(),
nominee: account_id,
transaction_payload: Transaction::default(),
transaction_out_id: MOCK_ETH_TRANSACTION_OUT_ID,
},
),
topics: vec![H256::default()],
.return_once(move |_, _| {
Ok(Some(vec![
CfeEvent::<Runtime>::EthTxBroadcastRequest(TxBroadcastRequest::<Runtime, _> {
broadcast_id: Default::default(),
nominee: account_id,
payload: Transaction::default(),
}),
Box::new(frame_system::EventRecord {
phase: Phase::ApplyExtrinsic(1),
event: RuntimeEvent::EthereumBroadcaster(
pallet_cf_broadcast::Event::TransactionBroadcastRequest {
broadcast_id: Default::default(),
nominee: AccountId32::new([1; 32]), // NOT OUR ACCOUNT ID
transaction_payload: Transaction::default(),
transaction_out_id: MOCK_ETH_TRANSACTION_OUT_ID,
},
),
topics: vec![H256::default()],
CfeEvent::<Runtime>::EthTxBroadcastRequest(TxBroadcastRequest::<Runtime, _> {
broadcast_id: Default::default(),
nominee: AccountId32::new([1; 32]), // NOT OUR ACCOUNT ID
payload: Transaction::default(),
}),
])
]))
});

let mut eth_rpc_mock_broadcast = MockEthRetryRpcClient::new();
Expand Down
1 change: 1 addition & 0 deletions state-chain/cf-integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ cf-chains = { path = '../chains', features = ['runtime-integration-tests'] }
cf-primitives = { path = '../primitives' }
cf-test-utilities = { path = '../test-utilities' }
cf-traits = { path = '../traits' }
cfe-events = { path = '../cfe-events' }
chainflip-node = { path = '../node' }
pallet-authorship = { git = "https://github.com/chainflip-io/substrate.git", tag = "chainflip-monthly-2023-08+5" }
pallet-cf-account-roles = { path = '../pallets/cf-account-roles' }
Expand Down
Loading

0 comments on commit b546f91

Please sign in to comment.