-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SYS-3965: added first stage migration of processed events mechanism to eth-bridge #390
Merged
MBrozhko34
merged 29 commits into
feat/SYS-3560-add-event-listener
from
SYS-3965-migration-processed-events-mechanism-first
May 22, 2024
Merged
Changes from 22 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
76d87a2
Sys 3931 identify events (#368)
ivan-cholakov 22252f3
SYS-3635: extends the voting mechanism
thadouk 668ec6b
SYS-3930: Extends validate unsigned for new extrinsic (#370)
thadouk 31f33bf
SYS-3930: Implement Vote Processing (#371)
thadouk 5d718a7
feat: added runtime-api for eth-event polling (#376)
ivan-cholakov ad9c0ff
feat: added runtime-api for eth-event polling (#376)
ivan-cholakov 88f7000
SYS-3932 - implement initial version of polling mechanism (#378)
ivan-cholakov b535a33
added functionality
MBrozhko34 bc8a0fd
tests, mock, more changes
MBrozhko34 9af749d
Introduces initial range consesnus mechanism (#391)
thadouk 61cb434
Exposes initial range voting via the runtime API (#393)
thadouk 13b32f3
SYS-3930 Adds unit tests for event votes (#372)
thadouk 787caa3
Merge branch 'feat/SYS-3560-add-event-listener' into SYS-3965-migrati…
MBrozhko34 0bf2b26
tidy-up, add comments
MBrozhko34 5b1abf1
fix merge issue, add more comments
MBrozhko34 c483d18
SYS-3930 Cleanup and finalises interface with runtime (#396)
thadouk 842e507
Merge remote-tracking branch 'origin/feat/SYS-3560-add-event-listener…
thadouk 41933c7
Squashed commit of the following:
thadouk e87e939
Merge branch 'test-squash-thadouk-michaels-work' into SYS-3965-migrat…
thadouk e807d3c
rename event and update
nahuseyoum 0cc35cb
Merge branch 'SYS-3965-migration-processed-events-mechanism-first' of…
nahuseyoum c0c44f9
update code and fix tests
nahuseyoum 5b8b876
Change error handling in process events, fmt code
MBrozhko34 0b52c39
re-add accepted and rejected events
MBrozhko34 3a41efd
fix error handling
MBrozhko34 e19db3b
revert error handling, do not throw errors
MBrozhko34 4b74809
revert again
MBrozhko34 f527116
small tests fix
MBrozhko34 66e0143
Update pallets/eth-bridge/src/lib.rs
MBrozhko34 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// Copyright 2023 Aventus Network Systems (UK) Ltd. | ||
|
||
#![cfg(test)] | ||
use crate::{eth::generate_send_calldata, mock::*, request::*, *}; | ||
use frame_support::{ | ||
assert_err, assert_noop, assert_ok, dispatch::DispatchResultWithPostInfo, error::BadOrigin, | ||
}; | ||
use sp_runtime::{testing::UintAuthorityId, DispatchError}; | ||
pub extern crate alloc; | ||
use alloc::collections::BTreeSet; | ||
use sp_avn_common::event_discovery::EthBridgeEventsFilter; | ||
|
||
const ROOT_HASH: &str = "30b83f0d722d1d4308ab4660a72dbaf0a7392d5674eca3cd21d57256d42df7a0"; | ||
const REWARDS: &[u8] = b"15043665996000000000"; | ||
const AVG_STAKED: &[u8] = b"9034532443555111110000"; | ||
const PERIOD: &[u8] = b"3"; | ||
const T2_PUB_KEY: &str = "14aeac90dbd3573458f9e029eb2de122ee94f2f0bc5ee4b6c6c5839894f1a547"; | ||
const T1_PUB_KEY: &str = "23d79f6492dddecb436333a5e7a4cfcc969f568e01283fa2964aae15327fb8a3b685a4d0f3ef9b3c2adb20f681dbc74b7f82c1cf8438d37f2c10e9c79591e9ea"; | ||
|
||
// Added this function as in event_listener_tests to initialize the active event range | ||
fn init_active_range() { | ||
ActiveEthereumRange::<TestRuntime>::put(ActiveEthRange { | ||
range: EthBlockRange { start_block: 1, length: 1000 }, | ||
partition: 0, | ||
event_types_filter: EthBridgeEventsFilter::try_from(vec![ | ||
ValidEvents::AddedValidator, | ||
ValidEvents::Lifted, | ||
ValidEvents::AvtGrowthLifted, | ||
ValidEvents::AvtLowerClaimed, | ||
] | ||
.into_iter() | ||
.collect::<BTreeSet<ValidEvents>>()).unwrap() | ||
}); | ||
} | ||
|
||
mod process_events { | ||
use sp_avn_common::event_types::EthEventId; | ||
use super::*; | ||
|
||
// succesfully process the specified ethereum_event | ||
#[test] | ||
fn succesful_event_processing_accepted() { | ||
let mut ext = ExtBuilder::build_default().with_validators().as_externality(); | ||
ext.execute_with(|| { | ||
let context = setup_context(); | ||
init_active_range(); | ||
|
||
// Two calls needed as upon the first there are not enough votes to pass the condition in lib.rs line 563, to reach the call of process_ethereum_events_partition() | ||
assert_ok!(EthBridge::submit_ethereum_events(RuntimeOrigin::none(), context.author.clone(), context.mock_event_partition.clone(), context.test_signature.clone())); | ||
assert_ok!(EthBridge::submit_ethereum_events(RuntimeOrigin::none(), context.author_two.clone(), context.mock_event_partition.clone(), context.test_signature_two.clone())); | ||
|
||
assert!(System::events().iter().any(|record| record.event == | ||
mock::RuntimeEvent::EthBridge(Event::<TestRuntime>::EventProcessed { | ||
accepted: true, | ||
eth_event_id: context.eth_event_id.clone(), | ||
}))); | ||
}); | ||
} | ||
|
||
|
||
// This test should fail processing the ethereum_event and emit the specified event | ||
#[test] | ||
fn succesful_event_processing_not_accepted() { | ||
let mut ext = ExtBuilder::build_default().with_validators().as_externality(); | ||
ext.execute_with(|| { | ||
let context = setup_context(); | ||
init_active_range(); | ||
assert_ok!(EthBridge::submit_ethereum_events(RuntimeOrigin::none(), context.author.clone(), context.bad_mock_event_partition.clone(), context.test_signature.clone())); | ||
assert_ok!(EthBridge::submit_ethereum_events(RuntimeOrigin::none(), context.author_two.clone(), context.bad_mock_event_partition.clone(), context.test_signature.clone())); | ||
|
||
|
||
assert!(System::events().iter().any(|record| record.event == | ||
mock::RuntimeEvent::EthBridge(Event::<TestRuntime>::EventProcessed { | ||
accepted: false, | ||
eth_event_id: context.bad_eth_event_id.clone(), | ||
}))); | ||
}); | ||
} | ||
|
||
|
||
// This test should fail on the check T::ProcessedEventsChecker::processed_event_exists(&event.event_id.clone()), if the event is already in the system | ||
#[test] | ||
fn event_already_processed() { | ||
let mut ext = ExtBuilder::build_default().with_validators().as_externality(); | ||
ext.execute_with(|| { | ||
let context = setup_context(); | ||
init_active_range(); | ||
assert_ok!(EthBridge::submit_ethereum_events(RuntimeOrigin::none(), context.author, context.mock_event_partition, context.test_signature)); | ||
}); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.