Skip to content

Commit

Permalink
Change VenueId to Option (#1700)
Browse files Browse the repository at this point in the history
* Change VenueId to Option

* Add instruction migration

---------

Co-authored-by: Adam Dossa <[email protected]>
  • Loading branch information
HenriqueNogara and adamdossa authored Aug 15, 2024
1 parent 0d3a34e commit e292afc
Show file tree
Hide file tree
Showing 13 changed files with 145 additions and 72 deletions.
2 changes: 1 addition & 1 deletion pallets/common/src/traits/settlement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ decl_event!(
/// (did, venue_id, instruction_id, settlement_type, trade_date, value_date, legs, memo)
InstructionCreated(
IdentityId,
VenueId,
Option<VenueId>,
InstructionId,
SettlementType<BlockNumber>,
Option<Moment>,
Expand Down
2 changes: 1 addition & 1 deletion pallets/runtime/tests/src/asset_pallet/base_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ fn base_transfer_locked_asset() {
));
assert_ok!(Settlement::add_and_affirm_instruction(
alice.origin(),
VenueId(0),
Some(VenueId(0)),
SettlementType::SettleOnAffirmation,
None,
None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ fn controller_transfer_locked_asset() {
));
assert_ok!(Settlement::add_instruction(
alice.origin(),
VenueId(0),
Some(VenueId(0)),
SettlementType::SettleManual(System::block_number() + 1),
None,
None,
Expand Down
2 changes: 1 addition & 1 deletion pallets/runtime/tests/src/asset_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1938,7 +1938,7 @@ fn controller_transfer_locked_asset() {
));
assert_ok!(Settlement::add_instruction(
alice.origin(),
VenueId(0),
Some(VenueId(0)),
SettlementType::SettleManual(System::block_number() + 1),
None,
None,
Expand Down
2 changes: 1 addition & 1 deletion pallets/runtime/tests/src/portfolio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ fn delete_portfolio_with_locked_nfts() {
}];
assert_ok!(Settlement::add_and_affirm_instruction(
alice.origin(),
venue_id,
Some(venue_id),
SettlementType::SettleOnAffirmation,
None,
None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ fn execute_instruction_storage_pruning() {

// Asserts all storage have been pruned
assert_eq!(InstructionAffirmsPending::get(instruction_id), 0);
assert_eq!(VenueInstructions::iter_prefix_values(venue_id).next(), None);
assert_eq!(
VenueInstructions::iter_prefix_values(venue_id.unwrap()).next(),
None
);
assert_eq!(
InstructionLegs::iter_prefix_values(instruction_id).next(),
None
Expand Down
4 changes: 2 additions & 2 deletions pallets/runtime/tests/src/settlement_pallet/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type Nft = pallet_nft::Module<TestStorage>;
type Settlement = pallet_settlement::Module<TestStorage>;

/// Calls [`create_and_issue_sample_asset`] and creates a venue for `asset_owner`.
pub fn create_and_issue_sample_asset_with_venue(asset_owner: &User) -> (AssetID, VenueId) {
pub fn create_and_issue_sample_asset_with_venue(asset_owner: &User) -> (AssetID, Option<VenueId>) {
let asset_id = create_and_issue_sample_asset(&asset_owner);

let venue_id = Settlement::venue_counter();
Expand All @@ -23,5 +23,5 @@ pub fn create_and_issue_sample_asset_with_venue(asset_owner: &User) -> (AssetID,
VenueType::Other
));

(asset_id, venue_id)
(asset_id, Some(venue_id))
}
37 changes: 23 additions & 14 deletions pallets/runtime/tests/src/settlement_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,10 @@ fn token_swap() {
assert_instruction_details(instruction_id, instruction_details);

assert_affirms_pending(instruction_id, 2);
assert_eq!(venue_instructions(venue_counter), vec![instruction_id]);
assert_eq!(
venue_instructions(venue_counter.unwrap()),
vec![instruction_id]
);

alice.assert_all_balances_unchanged();
bob.assert_all_balances_unchanged();
Expand Down Expand Up @@ -614,7 +617,10 @@ fn settle_on_block() {
);

assert_affirms_pending(instruction_id, 2);
assert_eq!(venue_instructions(venue_counter), vec![instruction_id]);
assert_eq!(
venue_instructions(venue_counter.unwrap()),
vec![instruction_id]
);

alice.assert_all_balances_unchanged();
bob.assert_all_balances_unchanged();
Expand Down Expand Up @@ -746,7 +752,10 @@ fn failed_execution() {
instruction_details
);
assert_affirms_pending(instruction_id, 2);
assert_eq!(venue_instructions(venue_counter), vec![instruction_id]);
assert_eq!(
venue_instructions(venue_counter.unwrap()),
vec![instruction_id]
);

// Ensure balances have not changed.
alice.assert_all_balances_unchanged();
Expand Down Expand Up @@ -864,7 +873,7 @@ fn venue_filtering() {
assert_ok!(Settlement::allow_venues(
alice.origin(),
asset_id,
vec![venue_counter]
vec![venue_counter.unwrap()]
));
assert_ok!(Settlement::add_and_affirm_instruction(
alice.origin(),
Expand All @@ -886,7 +895,7 @@ fn venue_filtering() {
assert_ok!(Settlement::disallow_venues(
alice.origin(),
asset_id,
vec![venue_counter]
vec![venue_counter.unwrap()]
));
next_block();
// Second instruction fails to settle due to venue being not whitelisted
Expand Down Expand Up @@ -992,7 +1001,7 @@ fn basic_fuzzing() {
}
assert_ok!(Settlement::add_instruction(
alice.origin(),
venue_counter,
Some(venue_counter),
SettlementType::SettleOnBlock(block_number),
None,
None,
Expand Down Expand Up @@ -2275,7 +2284,7 @@ fn basic_settlement_with_memo() {
fn create_instruction(
alice: &User,
bob: &User,
venue_counter: VenueId,
venue_counter: Option<VenueId>,
asset_id: AssetID,
amount: u128,
) -> InstructionId {
Expand Down Expand Up @@ -2677,7 +2686,7 @@ fn add_and_affirm_nft_instruction() {
}];
assert_ok!(Settlement::add_and_affirm_instruction(
alice.origin(),
venue_id,
Some(venue_id),
SettlementType::SettleOnAffirmation,
None,
None,
Expand Down Expand Up @@ -2786,7 +2795,7 @@ fn add_and_affirm_nft_not_owned() {
assert_noop!(
Settlement::add_and_affirm_instruction(
alice.origin(),
venue_id,
Some(venue_id),
SettlementType::SettleOnAffirmation,
None,
None,
Expand Down Expand Up @@ -2854,7 +2863,7 @@ fn add_same_nft_different_legs() {
assert_noop!(
Settlement::add_and_affirm_instruction(
alice.origin(),
venue_id,
Some(venue_id),
SettlementType::SettleOnAffirmation,
None,
None,
Expand Down Expand Up @@ -2910,7 +2919,7 @@ fn add_and_affirm_with_receipts_nfts() {
}];
assert_ok!(Settlement::add_instruction(
alice.origin(),
venue_id,
Some(venue_id),
SettlementType::SettleOnAffirmation,
None,
None,
Expand Down Expand Up @@ -2964,7 +2973,7 @@ fn add_instruction_unexpected_offchain_asset() {
assert_noop!(
Settlement::add_instruction(
alice.origin(),
venue_counter,
Some(venue_counter),
SettlementType::SettleOnAffirmation,
None,
None,
Expand All @@ -2983,7 +2992,7 @@ fn add_instruction_unexpected_offchain_asset() {
assert_noop!(
Settlement::add_instruction(
alice.origin(),
venue_counter,
Some(venue_counter),
SettlementType::SettleOnAffirmation,
None,
None,
Expand Down Expand Up @@ -3091,7 +3100,7 @@ fn affirm_offchain_asset_without_receipt() {
}];
assert_ok!(Settlement::add_instruction(
alice.origin(),
venue,
Some(venue),
SettlementType::SettleOnAffirmation,
None,
None,
Expand Down
22 changes: 11 additions & 11 deletions pallets/settlement/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ where
);
Module::<T>::add_instruction_with_mediators(
sender.origin.clone().into(),
venue_id,
Some(venue_id),
settlement_type,
None,
None,
Expand Down Expand Up @@ -436,7 +436,7 @@ benchmarks! {
let parameters = setup_legs::<T>(&alice, &bob, f, n, o, false, false);
Module::<T>::add_instruction(
alice.origin.clone().into(),
venue_id,
Some(venue_id),
SettlementType::SettleOnAffirmation,
None,
None,
Expand Down Expand Up @@ -489,7 +489,7 @@ benchmarks! {
let venue_id = create_venue_::<T>(alice.did(), vec![alice.account()]);

let parameters = setup_legs::<T>(&alice, &bob, f, n, o, false, false);
}: _(alice.origin, venue_id, settlement_type, None, None, parameters.legs, memo)
}: _(alice.origin, Some(venue_id), settlement_type, None, None, parameters.legs, memo)

add_and_affirm_instruction {
// Number of fungible, non-fungible and offchain LEGS in the instruction
Expand All @@ -504,7 +504,7 @@ benchmarks! {
let venue_id = create_venue_::<T>(alice.did(), vec![alice.account()]);

let parameters = setup_legs::<T>(&alice, &bob, f, n, o, false, false);
}: _(alice.origin, venue_id, settlement_type, None, None, parameters.legs, parameters.portfolios.sdr_portfolios, memo)
}: _(alice.origin, Some(venue_id), settlement_type, None, None, parameters.legs, parameters.portfolios.sdr_portfolios, memo)

affirm_instruction {
// Number of fungible and non-fungible assets in the portfolios
Expand All @@ -519,7 +519,7 @@ benchmarks! {
let parameters = setup_legs::<T>(&alice, &bob, f, n, T::MaxNumberOfOffChainAssets::get(), false, false);
Module::<T>::add_instruction(
alice.origin.clone().into(),
venue_id,
Some(venue_id),
SettlementType::SettleOnAffirmation,
None,
None,
Expand Down Expand Up @@ -613,7 +613,7 @@ benchmarks! {
let parameters = setup_legs::<T>(&alice, &bob, f, n, o, false, false);
Module::<T>::add_instruction(
alice.origin.clone().into(),
venue_id,
Some(venue_id),
SettlementType::SettleOnAffirmation,
None,
None,
Expand Down Expand Up @@ -650,7 +650,7 @@ benchmarks! {
let parameters = setup_legs::<T>(&alice, &bob, f, n, T::MaxNumberOfOffChainAssets::get(), false, false);
Module::<T>::add_instruction(
alice.origin.clone().into(),
venue_id,
Some(venue_id),
SettlementType::SettleOnAffirmation,
None,
None,
Expand Down Expand Up @@ -692,7 +692,7 @@ benchmarks! {
let mediators: BTreeSet<IdentityId> = (0..m).map(|i| IdentityId::from(i as u128)).collect();

let parameters = setup_legs::<T>(&alice, &bob, f, n, o, false, false);
}: _(alice.origin, venue_id, settlement_type, None, None, parameters.legs, memo, mediators.try_into().unwrap())
}: _(alice.origin, Some(venue_id), settlement_type, None, None, parameters.legs, memo, mediators.try_into().unwrap())

add_and_affirm_with_mediators {
// Number of fungible, non-fungible, offchain legs and mediators
Expand All @@ -709,7 +709,7 @@ benchmarks! {
let mediators: BTreeSet<IdentityId> = (0..m).map(|i| IdentityId::from(i as u128)).collect();

let parameters = setup_legs::<T>(&alice, &bob, f, n, o, false, false);
}: _(alice.origin, venue_id, settlement_type, None, None, parameters.legs, parameters.portfolios.sdr_portfolios, memo, mediators.try_into().unwrap())
}: _(alice.origin, Some(venue_id), settlement_type, None, None, parameters.legs, parameters.portfolios.sdr_portfolios, memo, mediators.try_into().unwrap())

affirm_instruction_as_mediator {
let bob = UserBuilder::<T>::default().generate_did().build("Bob");
Expand All @@ -730,7 +730,7 @@ benchmarks! {
);
Module::<T>::add_instruction_with_mediators(
alice.origin.clone().into(),
venue_id,
Some(venue_id),
SettlementType::SettleOnAffirmation,
None,
None,
Expand Down Expand Up @@ -760,7 +760,7 @@ benchmarks! {
);
Module::<T>::add_instruction_with_mediators(
alice.origin.clone().into(),
venue_id,
Some(venue_id),
SettlementType::SettleOnAffirmation,
None,
None,
Expand Down
Loading

0 comments on commit e292afc

Please sign in to comment.