Skip to content

Commit db18fa5

Browse files
Reject instruction with offchain assets without a venue (#1715)
Co-authored-by: Robert Gabriel Jakabosky <rjakabosky+neopallium@neoawareness.com>
1 parent e5d9316 commit db18fa5

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

pallets/runtime/tests/src/settlement_test.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4100,6 +4100,43 @@ fn reject_instruction_as_mediator() {
41004100
});
41014101
}
41024102

4103+
#[test]
4104+
fn missing_venue_for_offchain_asset() {
4105+
ExtBuilder::default().build().execute_with(|| {
4106+
let bob = User::new(AccountKeyring::Bob);
4107+
let alice = User::new(AccountKeyring::Alice);
4108+
4109+
let (asset_id, _) = create_and_issue_sample_asset_with_venue(&alice);
4110+
4111+
let legs: Vec<Leg> = vec![
4112+
Leg::Fungible {
4113+
sender: PortfolioId::default_portfolio(alice.did),
4114+
receiver: PortfolioId::default_portfolio(bob.did),
4115+
asset_id,
4116+
amount: 1_000_000,
4117+
},
4118+
Leg::OffChain {
4119+
sender_identity: alice.did,
4120+
receiver_identity: bob.did,
4121+
ticker: Ticker::from_slice_truncated(b"MYASSET"),
4122+
amount: 1_000_000,
4123+
},
4124+
];
4125+
assert_noop!(
4126+
Settlement::add_instruction(
4127+
alice.origin(),
4128+
None,
4129+
SettlementType::SettleOnAffirmation,
4130+
None,
4131+
None,
4132+
legs,
4133+
None,
4134+
),
4135+
Error::OffChainAssetsMustHaveAVenue
4136+
);
4137+
});
4138+
}
4139+
41034140
/// Asserts the storage has been updated after adding an instruction.
41044141
/// While each portfolio in `portfolios_pending_approval` must have a pending `AffirmationStatus`, each portfolio in `portfolios_pre_approved`
41054142
/// must have an affirmed status. The number of pending affirmations must be equal to the number of portfolios in `portfolios_pending_approval` + the number of offchain legs,

pallets/settlement/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,9 @@ decl_error! {
230230
/// The mediator's expiry date must be in the future.
231231
InvalidExpiryDate,
232232
/// The expiry date for the mediator's affirmation has passed.
233-
MediatorAffirmationExpired
233+
MediatorAffirmationExpired,
234+
/// Offchain assets must have a venue.
235+
OffChainAssetsMustHaveAVenue,
234236
}
235237
}
236238

@@ -2055,6 +2057,7 @@ impl<T: Config> Module<T> {
20552057
amount,
20562058
..
20572059
} => {
2060+
ensure!(venue_id.is_some(), Error::<T>::OffChainAssetsMustHaveAVenue);
20582061
Self::ensure_valid_off_chain_leg(sender_identity, receiver_identity, *amount)?;
20592062
instruction_asset_count
20602063
.try_add_off_chain()

0 commit comments

Comments
 (0)