Skip to content

Commit

Permalink
Reject instruction with offchain assets without a venue (#1715)
Browse files Browse the repository at this point in the history
Co-authored-by: Robert Gabriel Jakabosky <[email protected]>
  • Loading branch information
HenriqueNogara and Neopallium authored Sep 17, 2024
1 parent e5d9316 commit db18fa5
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
37 changes: 37 additions & 0 deletions pallets/runtime/tests/src/settlement_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4100,6 +4100,43 @@ fn reject_instruction_as_mediator() {
});
}

#[test]
fn missing_venue_for_offchain_asset() {
ExtBuilder::default().build().execute_with(|| {
let bob = User::new(AccountKeyring::Bob);
let alice = User::new(AccountKeyring::Alice);

let (asset_id, _) = create_and_issue_sample_asset_with_venue(&alice);

let legs: Vec<Leg> = vec![
Leg::Fungible {
sender: PortfolioId::default_portfolio(alice.did),
receiver: PortfolioId::default_portfolio(bob.did),
asset_id,
amount: 1_000_000,
},
Leg::OffChain {
sender_identity: alice.did,
receiver_identity: bob.did,
ticker: Ticker::from_slice_truncated(b"MYASSET"),
amount: 1_000_000,
},
];
assert_noop!(
Settlement::add_instruction(
alice.origin(),
None,
SettlementType::SettleOnAffirmation,
None,
None,
legs,
None,
),
Error::OffChainAssetsMustHaveAVenue
);
});
}

/// Asserts the storage has been updated after adding an instruction.
/// While each portfolio in `portfolios_pending_approval` must have a pending `AffirmationStatus`, each portfolio in `portfolios_pre_approved`
/// 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,
Expand Down
5 changes: 4 additions & 1 deletion pallets/settlement/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,9 @@ decl_error! {
/// The mediator's expiry date must be in the future.
InvalidExpiryDate,
/// The expiry date for the mediator's affirmation has passed.
MediatorAffirmationExpired
MediatorAffirmationExpired,
/// Offchain assets must have a venue.
OffChainAssetsMustHaveAVenue,
}
}

Expand Down Expand Up @@ -2055,6 +2057,7 @@ impl<T: Config> Module<T> {
amount,
..
} => {
ensure!(venue_id.is_some(), Error::<T>::OffChainAssetsMustHaveAVenue);
Self::ensure_valid_off_chain_leg(sender_identity, receiver_identity, *amount)?;
instruction_asset_count
.try_add_off_chain()
Expand Down

0 comments on commit db18fa5

Please sign in to comment.