-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add EventEmitter to XCM Executor #7234
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
Changes from 2 commits
d045373
2cece4e
4ecc682
fae11c8
2f1b65f
840fc9b
65061ea
b897548
f907e5d
e505c76
e128e27
5d406d8
6e18c46
ce5d746
b78317d
dd5a7de
56d500e
b5db8d5
ab43058
657ebc0
9409209
87c287f
59dd8a3
fdccc61
766bb23
948f851
1a38fa1
5a50a8d
897bff7
f592fca
5a0d383
fb2f40f
32159d5
d4b3067
71f1cd6
bc14b1c
a919206
6f54c39
507778f
b214336
76c2734
023cb52
a522a80
6d9a3c5
f3657c7
b5c5f3c
be2f75a
7274176
0e3661e
375b87f
9db8239
a95ed5e
2a49755
f67af1e
83a326e
8734178
54124d3
2abf83f
e1be968
ccfabf6
3d2d8d5
1258918
d16e6e4
66523c3
f3c4513
ef7c150
07854e8
29207c4
4fd304f
235ce5f
bb31ef7
43dc292
1746618
3056abc
848efa8
7db071f
459c85d
d22491e
94659c2
d0e60a9
076023d
c1514cc
4229dbc
7d0d4a5
8daa51e
d50af4d
e8f4b18
d9b3b83
cf72077
2fa8a95
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1456,3 +1456,55 @@ fn record_xcm_works() { | |
| assert_eq!(RecordedXcm::<Test>::get(), Some(message.into())); | ||
| }); | ||
| } | ||
|
|
||
| #[test] | ||
| fn execute_initiate_transfer_and_check_sent_event() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please add tests for the other events too
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As mentioned here, I was trying to add this test but, it looks like the events are being rollback due to failed transactions. Do you have any suggestions on how I can retrieve the events after the rollback?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm working on #7594. Once it's merged, you can use the log capture for testing.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @raymondkfcheung If I understood correctly with #7594 I'll check the logs and not the event emitted?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If events are rollback and assertions on events are not possible, then you can assert captured logs, like this.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you can finalise it this week, that would be great; otherwise, I'll continue working on it next Monday.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @raymondkfcheung You can work on this one, I'm not going to have the time finish this week as I'm going out on vacation. |
||
| let balances = vec![(ALICE, INITIAL_BALANCE)]; | ||
| new_test_ext_with_balances(balances).execute_with(|| { | ||
| let dest: Location = Location::new(1, [Junction::AccountId32 { network: None, id: BOB.into() }]); | ||
| let assets: Asset = (Parent, SEND_AMOUNT).into(); | ||
|
|
||
| let message = Xcm(vec![ | ||
| InitiateReserveWithdraw { | ||
| assets: Wild(All), | ||
| reserve: Parent.into(), | ||
| xcm: Xcm(vec![ | ||
| BuyExecution { fees: assets.clone(), weight_limit: Unlimited }, | ||
| DepositAsset { assets: All.into(), beneficiary: dest.clone() }, | ||
| ]), | ||
| }, | ||
| ]); | ||
|
|
||
| assert_ok!(XcmPallet::execute( | ||
| RuntimeOrigin::signed(ALICE), | ||
| Box::new(VersionedXcm::from(message.clone())), | ||
| BaseXcmWeight::get() * 3, | ||
| )); | ||
|
|
||
| let sender: Location = AccountId32 { network: None, id: ALICE.into() }.into(); | ||
| let expected_message = Xcm(vec![ | ||
| WithdrawAsset(Assets::new()), | ||
| ClearOrigin, | ||
| BuyExecution { fees: assets.clone(), weight_limit: Unlimited }, | ||
| DepositAsset { assets: All.into(), beneficiary: dest.clone() }, | ||
| ]); | ||
| let id = fake_message_hash(&expected_message); | ||
|
|
||
| assert_eq!( | ||
| last_events(2), | ||
| vec![ | ||
| RuntimeEvent::XcmPallet(crate::Event::Sent { | ||
| origin: sender, | ||
| destination: Parent.into(), | ||
| message: expected_message, | ||
| message_id: id, | ||
| }), | ||
| RuntimeEvent::XcmPallet(crate::Event::Attempted { | ||
| outcome: Outcome::Complete { | ||
| used: Weight::from_parts(1000, 1000) | ||
| } | ||
| }) | ||
| ] | ||
| ); | ||
| }); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| // Copyright (C) Parity Technologies (UK) Ltd. | ||
| // This file is part of Polkadot. | ||
|
|
||
| // Polkadot is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU General Public License as published by | ||
| // the Free Software Foundation, either version 3 of the License, or | ||
| // (at your option) any later version. | ||
|
|
||
| // Polkadot is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU General Public License for more details. | ||
|
|
||
| // You should have received a copy of the GNU General Public License | ||
| // along with Polkadot. If not, see <http://www.gnu.org/licenses/>. | ||
|
|
||
| use xcm::latest::prelude::*; | ||
|
|
||
| pub trait EventEmitter { | ||
raymondkfcheung marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| fn emit_sent_event( | ||
raymondkfcheung marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| origin: Location, | ||
| destination: Location, | ||
| message: Xcm<()>, | ||
raymondkfcheung marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| message_id: XcmHash, | ||
| ); | ||
| } | ||
|
|
||
| impl EventEmitter for () { | ||
| fn emit_sent_event( | ||
| _origin: Location, | ||
| _destination: Location, | ||
| _message: Xcm<()>, | ||
| _message_id: XcmHash, | ||
| ) {} | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.