From 76c38a52e71f2b73c2957a2b6e1f13d9a2cbdf94 Mon Sep 17 00:00:00 2001 From: Aleksandar Brayanov Date: Mon, 14 Nov 2022 20:37:55 +0000 Subject: [PATCH 01/17] added anti-snipe duration parameter to auction pallet and test case if it works --- pallets/auction/src/lib.rs | 11 +++ pallets/auction/src/mock.rs | 3 + pallets/auction/src/tests.rs | 137 ++++++++++------------------------- runtime/continuum/src/lib.rs | 2 + runtime/metaverse/src/lib.rs | 2 + runtime/pioneer/src/lib.rs | 2 + 6 files changed, 57 insertions(+), 100 deletions(-) diff --git a/pallets/auction/src/lib.rs b/pallets/auction/src/lib.rs index f2269f732..ef29c16f5 100644 --- a/pallets/auction/src/lib.rs +++ b/pallets/auction/src/lib.rs @@ -192,6 +192,10 @@ pub mod pallet { /// Minimum listing price #[pallet::constant] type MinimumListingPrice: Get>; + + /// Anti-snipe duration + #[pallet::constant] + type AntiSnipeDuration: Get; } #[pallet::storage] @@ -1124,6 +1128,10 @@ pub mod pallet { Self::swap_new_bid(id, (from.clone(), value), auction.bid.clone())?; + if auction_item.end_time.saturating_sub(>::block_number()) == T::AntiSnipeDuration::get() { + auction_item.end_time.saturating_add(T::AntiSnipeDuration::get()); + } + auction.bid = Some((from.clone(), value)); Self::deposit_event(Event::Bid(id, from, value)); @@ -1166,6 +1174,9 @@ pub mod pallet { // Reserve balance T::FungibleTokenCurrency::reserve(social_currency_id, &new_bidder, new_bid_price.saturated_into())?; auction_item.amount = new_bid_price.clone(); + if auction_item.end_time.saturating_sub(>::block_number()) == T::AntiSnipeDuration::get() { + auction_item.end_time.saturating_add(T::AntiSnipeDuration::get()); + } Ok(()) }) diff --git a/pallets/auction/src/mock.rs b/pallets/auction/src/mock.rs index 09d655643..8ab0d670c 100644 --- a/pallets/auction/src/mock.rs +++ b/pallets/auction/src/mock.rs @@ -239,6 +239,7 @@ parameter_types! { pub const NetworkFeeCommission: Perbill = Perbill::from_percent(1); // Network fee collected after an auction is over pub const OfferDuration: BlockNumber = 10; // Default 10 pub const MinimumListingPrice: Balance = 1; + pub const AntiSnipeDuration: BlockNumber = 5; // Default 5 } pub struct MetaverseInfoSource {} @@ -305,6 +306,7 @@ impl MetaverseTrait for MetaverseInfoSource { fn is_metaverse_owner(who: &AccountId) -> bool { who != &NO_METAVERSE_OWNER } + } impl Config for Runtime { @@ -325,6 +327,7 @@ impl Config for Runtime { type WeightInfo = (); type OfferDuration = OfferDuration; type MinimumListingPrice = MinimumListingPrice; + type AntiSnipeDuration = AntiSnipeDuration; } pub type AdaptedBasicCurrency = currencies::BasicCurrencyAdapter; diff --git a/pallets/auction/src/tests.rs b/pallets/auction/src/tests.rs index 26090bd2b..d54860813 100644 --- a/pallets/auction/src/tests.rs +++ b/pallets/auction/src/tests.rs @@ -308,106 +308,6 @@ fn create_new_multicurrency_buy_now_bundle_work() { }); } -/* -#[test] -// Creating auction should work -fn create_new_auction_should_work_for_valid_estate() { - ExtBuilder::default().build().execute_with(|| { - let item_id: ItemId = ItemId::Estate(ESTATE_ID_EXIST); - assert_ok!(AuctionModule::create_auction( - AuctionType::Auction, - item_id.clone(), - None, - ALICE, - 100, - 0, - ListingLevel::Global, - Perbill::from_percent(0u32) - )); - assert_eq!( - AuctionModule::auctions(0), - Some(AuctionInfo { - bid: None, - start: 1, - end: Some(101), - }) - ); - assert_eq!(AuctionModule::items_in_auction(item_id.clone()), Some(true)); - assert_eq!(Balances::free_balance(ALICE), 99999); - }); -} - -#[test] -// Creating auction should work -fn create_new_auction_should_fail_for_non_exist_estate() { - ExtBuilder::default().build().execute_with(|| { - let item_id: ItemId = ItemId::Estate(ESTATE_ID_NOT_EXIST); - assert_noop!( - AuctionModule::create_auction( - AuctionType::Auction, - item_id, - None, - ALICE, - 100, - 0, - ListingLevel::Global, - Perbill::from_percent(0u32), - ), - Error::::EstateDoesNotExist - ); - }); -} - - -#[test] -// Creating auction should work -fn create_new_auction_should_work_for_valid_landunit() { - ExtBuilder::default().build().execute_with(|| { - let item_id: ItemId = ItemId::LandUnit(LAND_UNIT_EXIST, ALICE_METAVERSE_ID); - assert_ok!(AuctionModule::create_auction( - AuctionType::Auction, - item_id.clone(), - None, - ALICE, - 100, - 0, - ListingLevel::Global, - Perbill::from_percent(0u32), - )); - assert_eq!( - AuctionModule::auctions(0), - Some(AuctionInfo { - bid: None, - start: 1, - end: Some(101), - }) - ); - assert_eq!(AuctionModule::items_in_auction(item_id), Some(true)); - assert_eq!(Balances::free_balance(ALICE), 99999); - }); -} - -#[test] -// Creating auction should fail -fn create_new_auction_should_fail_for_non_exist_landunit() { - ExtBuilder::default().build().execute_with(|| { - let item_id: ItemId = ItemId::LandUnit(LAND_UNIT_NOT_EXIST, ALICE_METAVERSE_ID); - assert_noop!( - AuctionModule::create_auction( - AuctionType::Auction, - item_id, - None, - ALICE, - 100, - 0, - ListingLevel::Global, - Perbill::from_percent(0u32), - ), - Error::::LandUnitDoesNotExist - ); - }); -} -*/ #[test] // Private create_auction should work fn create_auction_fail() { @@ -662,6 +562,43 @@ fn bid_works() { }); } +#[test] +// Walk the happy path +fn bid_anti_snipe_duration_works() { + ExtBuilder::default().build().execute_with(|| { + let owner = Origin::signed(BOB); + let bidder = Origin::signed(ALICE); + + init_test_nft(owner.clone()); + assert_ok!(AuctionModule::create_auction( + AuctionType::Auction, + ItemId::NFT(0, 0), + None, + BOB, + 100, + 0, + ListingLevel::Global, + Perbill::from_percent(0u32), + FungibleTokenId::NativeToken(0), + )); + + run_to_block(95); + + assert_ok!(AuctionModule::bid(bidder, 0, 200)); + + assert_eq!( + AuctionModule::auctions(0), + Some(AuctionInfo { + bid: None, + start: 1, + end: Some(106), + }) + ); + assert_eq!(last_event(), Event::AuctionModule(crate::Event::Bid(0, ALICE, 200))); + assert_eq!(Balances::reserved_balance(ALICE), 200); + }); +} + #[test] // Walk the happy path fn bid_multicurrency_works() { diff --git a/runtime/continuum/src/lib.rs b/runtime/continuum/src/lib.rs index a08a2ecd3..bca37a5d1 100644 --- a/runtime/continuum/src/lib.rs +++ b/runtime/continuum/src/lib.rs @@ -1432,6 +1432,7 @@ parameter_types! { pub const NetworkFeeCommission: Perbill = Perbill::from_percent(1); // Network fee collected after an auction is over pub const OfferDuration: BlockNumber = 100800; // Default 100800 Blocks pub const MinimumListingPrice: Balance = DOLLARS; + pub const AntiSnipeDuration: BlockNumber = 50; // Minimum anti snipe duration is 50 blocks } impl auction::Config for Runtime { @@ -1452,6 +1453,7 @@ impl auction::Config for Runtime { type WeightInfo = weights::module_auction::WeightInfo; type OfferDuration = OfferDuration; type MinimumListingPrice = MinimumListingPrice; + type AntiSnipeDuration = AntiSnipeDuration; } impl continuum::Config for Runtime { diff --git a/runtime/metaverse/src/lib.rs b/runtime/metaverse/src/lib.rs index 9dcce3928..3df3ac84a 100644 --- a/runtime/metaverse/src/lib.rs +++ b/runtime/metaverse/src/lib.rs @@ -629,6 +629,7 @@ parameter_types! { pub const NetworkFeeCommission: Perbill = Perbill::from_percent(1); // Network fee collected after an auction is over pub const OfferDuration: BlockNumber = 100800; // Default 100800 Blocks pub const MinimumListingPrice: Balance = DOLLARS; + pub const AntiSnipeDuration: BlockNumber = 50; // Minimum anti snipe duration is 50 blocks } impl auction::Config for Runtime { @@ -649,6 +650,7 @@ impl auction::Config for Runtime { type WeightInfo = weights::module_auction::WeightInfo; type OfferDuration = OfferDuration; type MinimumListingPrice = MinimumListingPrice; + type AntiSnipeDuration = AntiSnipeDuration; } impl continuum::Config for Runtime { diff --git a/runtime/pioneer/src/lib.rs b/runtime/pioneer/src/lib.rs index 97021314c..d9cb12a2f 100644 --- a/runtime/pioneer/src/lib.rs +++ b/runtime/pioneer/src/lib.rs @@ -1442,6 +1442,7 @@ parameter_types! { pub const NetworkFeeCommission: Perbill = Perbill::from_percent(1); // Network fee collected after an auction is over pub const OfferDuration: BlockNumber = 100800; // Default 100800 Blocks pub const MinimumListingPrice: Balance = DOLLARS; + pub const AntiSnipeDuration: BlockNumber = 50; // Minimum anti snipe duration is 50 blocks } impl auction::Config for Runtime { @@ -1462,6 +1463,7 @@ impl auction::Config for Runtime { type WeightInfo = weights::module_auction::WeightInfo; type OfferDuration = OfferDuration; type MinimumListingPrice = MinimumListingPrice; + type AntiSnipeDuration = AntiSnipeDuration; } impl continuum::Config for Runtime { From 5248a6caec9cb2801f3ac77a142045e3051bc97f Mon Sep 17 00:00:00 2001 From: Aleksandar Brayanov Date: Tue, 15 Nov 2022 01:09:57 +0000 Subject: [PATCH 02/17] anti-snipe duration check updates all relevant end times --- pallets/auction/src/lib.rs | 24 +++++++++++++++++++----- pallets/auction/src/tests.rs | 23 ++++++++++++++++++++--- 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/pallets/auction/src/lib.rs b/pallets/auction/src/lib.rs index ef29c16f5..022e0e44d 100644 --- a/pallets/auction/src/lib.rs +++ b/pallets/auction/src/lib.rs @@ -1076,7 +1076,7 @@ pub mod pallet { /// Internal auction bid handler fn auction_bid_handler(from: T::AccountId, id: AuctionId, value: Self::Balance) -> DispatchResult { - let auction_item: AuctionItem> = + let mut auction_item: AuctionItem> = Self::get_auction_item(id.clone()).ok_or(Error::::AuctionDoesNotExist)?; ensure!( auction_item.auction_type == AuctionType::Auction, @@ -1128,8 +1128,14 @@ pub mod pallet { Self::swap_new_bid(id, (from.clone(), value), auction.bid.clone())?; - if auction_item.end_time.saturating_sub(>::block_number()) == T::AntiSnipeDuration::get() { - auction_item.end_time.saturating_add(T::AntiSnipeDuration::get()); + if auction_item.end_time.saturating_sub(>::block_number()) <= T::AntiSnipeDuration::get() { + AuctionEndTime::::remove(auction_end, id); + let new_auction_end = auction_end.saturating_add(T::AntiSnipeDuration::get()); + auction_item.end_time = new_auction_end; + AuctionItems::::insert(id, auction_item); + AuctionEndTime::::insert(new_auction_end, id, ()); + auction.end = Some(new_auction_end); + } auction.bid = Some((from.clone(), value)); @@ -1174,8 +1180,16 @@ pub mod pallet { // Reserve balance T::FungibleTokenCurrency::reserve(social_currency_id, &new_bidder, new_bid_price.saturated_into())?; auction_item.amount = new_bid_price.clone(); - if auction_item.end_time.saturating_sub(>::block_number()) == T::AntiSnipeDuration::get() { - auction_item.end_time.saturating_add(T::AntiSnipeDuration::get()); + if auction_item.end_time.saturating_sub(>::block_number()) <= T::AntiSnipeDuration::get() { + let new_end = auction_item.end_time.saturating_add(T::AntiSnipeDuration::get()); + if let Some(auction_info) = Self::auctions(id) { + let mut new_auction_info = auction_info; + new_auction_info.end = Some(new_end); + Auctions::::insert(id, new_auction_info); + } + AuctionEndTime::::remove(auction_item.end_time, id); + AuctionEndTime::::insert(new_end, id, ()); + auction_item.end_time = new_end; } Ok(()) diff --git a/pallets/auction/src/tests.rs b/pallets/auction/src/tests.rs index d54860813..08f318da9 100644 --- a/pallets/auction/src/tests.rs +++ b/pallets/auction/src/tests.rs @@ -555,8 +555,16 @@ fn bid_works() { Perbill::from_percent(0u32), FungibleTokenId::NativeToken(0), )); - + run_to_block(95); assert_ok!(AuctionModule::bid(bidder, 0, 200)); + assert_eq!( + AuctionModule::auctions(0), + Some(AuctionInfo { + bid: Some((1, 200)), + start: 1, + end: Some(101), + }) + ); assert_eq!(last_event(), Event::AuctionModule(crate::Event::Bid(0, ALICE, 200))); assert_eq!(Balances::reserved_balance(ALICE), 200); }); @@ -581,19 +589,28 @@ fn bid_anti_snipe_duration_works() { Perbill::from_percent(0u32), FungibleTokenId::NativeToken(0), )); + let old_auction_item = AuctionModule::get_auction_item(0); - run_to_block(95); + run_to_block(96); assert_ok!(AuctionModule::bid(bidder, 0, 200)); assert_eq!( AuctionModule::auctions(0), Some(AuctionInfo { - bid: None, + bid: Some((1, 200)), start: 1, end: Some(106), }) ); + assert_eq!( + AuctionModule::auction_end_time(106, 0), + Some(()) + ); + assert_eq!( + AuctionModule::auction_end_time(101, 0), + None + ); assert_eq!(last_event(), Event::AuctionModule(crate::Event::Bid(0, ALICE, 200))); assert_eq!(Balances::reserved_balance(ALICE), 200); }); From 07af5955a31aa86cedaef2d3c028e7ca1c85900d Mon Sep 17 00:00:00 2001 From: Aleksandar Brayanov Date: Tue, 15 Nov 2022 05:59:13 +0000 Subject: [PATCH 03/17] fixed auction benchmarking and updated weights --- pallets/auction/src/lib.rs | 15 ++- pallets/auction/src/mock.rs | 1 - pallets/auction/src/tests.rs | 10 +- pallets/auction/src/weights.rs | 96 ++++++------------- .../continuum/src/weights/module_auction.rs | 38 ++++---- runtime/metaverse/src/benchmarking/auction.rs | 48 ++++++---- .../metaverse/src/weights/module_auction.rs | 38 ++++---- runtime/pioneer/src/weights/module_auction.rs | 38 ++++---- 8 files changed, 128 insertions(+), 156 deletions(-) diff --git a/pallets/auction/src/lib.rs b/pallets/auction/src/lib.rs index 022e0e44d..6641d82ef 100644 --- a/pallets/auction/src/lib.rs +++ b/pallets/auction/src/lib.rs @@ -1128,14 +1128,17 @@ pub mod pallet { Self::swap_new_bid(id, (from.clone(), value), auction.bid.clone())?; - if auction_item.end_time.saturating_sub(>::block_number()) <= T::AntiSnipeDuration::get() { + if auction_item + .end_time + .saturating_sub(>::block_number()) + <= T::AntiSnipeDuration::get() + { AuctionEndTime::::remove(auction_end, id); - let new_auction_end = auction_end.saturating_add(T::AntiSnipeDuration::get()); + let new_auction_end = auction_end.saturating_add(T::AntiSnipeDuration::get()); auction_item.end_time = new_auction_end; AuctionItems::::insert(id, auction_item); AuctionEndTime::::insert(new_auction_end, id, ()); auction.end = Some(new_auction_end); - } auction.bid = Some((from.clone(), value)); @@ -1180,7 +1183,11 @@ pub mod pallet { // Reserve balance T::FungibleTokenCurrency::reserve(social_currency_id, &new_bidder, new_bid_price.saturated_into())?; auction_item.amount = new_bid_price.clone(); - if auction_item.end_time.saturating_sub(>::block_number()) <= T::AntiSnipeDuration::get() { + if auction_item + .end_time + .saturating_sub(>::block_number()) + <= T::AntiSnipeDuration::get() + { let new_end = auction_item.end_time.saturating_add(T::AntiSnipeDuration::get()); if let Some(auction_info) = Self::auctions(id) { let mut new_auction_info = auction_info; diff --git a/pallets/auction/src/mock.rs b/pallets/auction/src/mock.rs index 8ab0d670c..18c827d2f 100644 --- a/pallets/auction/src/mock.rs +++ b/pallets/auction/src/mock.rs @@ -306,7 +306,6 @@ impl MetaverseTrait for MetaverseInfoSource { fn is_metaverse_owner(who: &AccountId) -> bool { who != &NO_METAVERSE_OWNER } - } impl Config for Runtime { diff --git a/pallets/auction/src/tests.rs b/pallets/auction/src/tests.rs index 08f318da9..b4228b4ca 100644 --- a/pallets/auction/src/tests.rs +++ b/pallets/auction/src/tests.rs @@ -603,14 +603,8 @@ fn bid_anti_snipe_duration_works() { end: Some(106), }) ); - assert_eq!( - AuctionModule::auction_end_time(106, 0), - Some(()) - ); - assert_eq!( - AuctionModule::auction_end_time(101, 0), - None - ); + assert_eq!(AuctionModule::auction_end_time(106, 0), Some(())); + assert_eq!(AuctionModule::auction_end_time(101, 0), None); assert_eq!(last_event(), Event::AuctionModule(crate::Event::Bid(0, ALICE, 200))); assert_eq!(Balances::reserved_balance(ALICE), 200); }); diff --git a/pallets/auction/src/weights.rs b/pallets/auction/src/weights.rs index 814961c4d..ae5449b85 100644 --- a/pallets/auction/src/weights.rs +++ b/pallets/auction/src/weights.rs @@ -18,18 +18,23 @@ //! Autogenerated weights for auction //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2022-08-03, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2022-11-15, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024 // Executed Command: // ./target/release/metaverse-node // benchmark -// --pallet=auction -// --extrinsic=* -// --steps=20 -// --repeat=10 +// pallet // --execution=wasm // --wasm-execution=compiled +// --pallet +// auction +// --extrinsic +// * +// --steps +// 20 +// --repeat +// 10 // --template=./template/weight-template.hbs // --output // ./pallets/auction/src/weights.rs @@ -47,66 +52,27 @@ pub trait WeightInfo { fn create_new_auction() -> Weight; fn create_new_buy_now( /// Weights for auction using the for collator node and recommended hardware. pub struct SubstrateWeight(PhantomData); -impl WeightInfo for SubstrateWeight { - fn create_new_auction() -> Weight { - (47_083_000 as Weight) - .saturating_add(T::DbWeight::get().reads(10 as Weight)) - .saturating_add(T::DbWeight::get().writes(8 as Weight)) - } - fn create_new_buy_now() -> Weight { - (46_880_000 as Weight) - .saturating_add(T::DbWeight::get().reads(10 as Weight)) - .saturating_add(T::DbWeight::get().writes(8 as Weight)) - } - fn bid() -> Weight { - (29_214_000 as Weight) - .saturating_add(T::DbWeight::get().reads(4 as Weight)) - .saturating_add(T::DbWeight::get().writes(4 as Weight)) - } - fn buy_now() -> Weight { - (94_897_000 as Weight) - .saturating_add(T::DbWeight::get().reads(13 as Weight)) - .saturating_add(T::DbWeight::get().writes(13 as Weight)) - } - fn make_offer() -> Weight { - (28_148_000 as Weight) - .saturating_add(T::DbWeight::get().reads(5 as Weight)) - .saturating_add(T::DbWeight::get().writes(3 as Weight)) - } - fn withdraw_offer() -> Weight { - (20_996_000 as Weight) - .saturating_add(T::DbWeight::get().reads(3 as Weight)) - .saturating_add(T::DbWeight::get().writes(3 as Weight)) - } - fn accept_offer() -> Weight { - (52_527_000 as Weight) - .saturating_add(T::DbWeight::get().reads(7 as Weight)) - .saturating_add(T::DbWeight::get().writes(7 as Weight)) - } - fn on_finalize() -> Weight { - (2_093_000 as Weight) - } - fn authorise_metaverse_collection() -> Weight { - (57_600_000 as Weight) - .saturating_add(T::DbWeight::get().reads(2 as Weight)) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) - } - fn remove_authorise_metaverse_collection() -> Weight { - (39_900_000 as Weight) - .saturating_add(T::DbWeight::get().reads(2 as Weight)) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) - } -} +impl WeightInfo for SubstrateWeight { fn create_new_auction() -> Weight { + (49_171_000 as Weight) .saturating_add(T::DbWeight::get().reads(10 as Weight)) .saturating_add(T::DbWeight::get().writes(8 as Weight)) } fn create_new_buy_now() -> Weight { + (50_385_000 as Weight) .saturating_add(T::DbWeight::get().reads(10 as Weight)) .saturating_add(T::DbWeight::get().writes(8 as Weight)) } fn bid() -> Weight { + (36_998_000 as Weight) .saturating_add(T::DbWeight::get().reads(4 as Weight)) .saturating_add(T::DbWeight::get().writes(6 as Weight)) } fn buy_now() -> Weight { + (97_943_000 as Weight) .saturating_add(T::DbWeight::get().reads(13 as Weight)) .saturating_add(T::DbWeight::get().writes(13 as Weight)) } fn authorise_metaverse_collection() -> Weight { + (16_103_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } fn remove_authorise_metaverse_collection() -> Weight { + (16_804_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } fn make_offer() -> Weight { + (30_668_000 as Weight) .saturating_add(T::DbWeight::get().reads(5 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } fn withdraw_offer() -> Weight { + (23_117_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } fn accept_offer() -> Weight { + (56_018_000 as Weight) .saturating_add(T::DbWeight::get().reads(7 as Weight)) .saturating_add(T::DbWeight::get().writes(7 as Weight)) } fn on_finalize() -> Weight { + (2_271_000 as Weight) }} // For backwards compatibility and tests impl WeightInfo for () { fn create_new_auction() -> Weight { - (47_083_000 as Weight) .saturating_add(RocksDbWeight::get().reads(10 as Weight)) .saturating_add(RocksDbWeight::get().writes(8 as Weight)) } fn create_new_buy_now() -> Weight { - (46_880_000 as Weight) .saturating_add(RocksDbWeight::get().reads(10 as Weight)) .saturating_add(RocksDbWeight::get().writes(8 as Weight)) } fn bid() -> Weight { - (29_214_000 as Weight) .saturating_add(RocksDbWeight::get().reads(4 as Weight)) .saturating_add(RocksDbWeight::get().writes(4 as Weight)) } fn buy_now() -> Weight { - (94_897_000 as Weight) .saturating_add(RocksDbWeight::get().reads(13 as Weight)) .saturating_add(RocksDbWeight::get().writes(13 as Weight)) } fn make_offer() -> Weight { - (28_148_000 as Weight) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) .saturating_add(RocksDbWeight::get().writes(3 as Weight)) } fn withdraw_offer() -> Weight { - (20_996_000 as Weight) .saturating_add(RocksDbWeight::get().reads(3 as Weight)) .saturating_add(RocksDbWeight::get().writes(3 as Weight)) } fn accept_offer() -> Weight { - (52_527_000 as Weight) .saturating_add(RocksDbWeight::get().reads(7 as Weight)) .saturating_add(RocksDbWeight::get().writes(7 as Weight)) } fn on_finalize() -> Weight { - (2_093_000 as Weight) } fn authorise_metaverse_collection() -> Weight { - (57_600_000 as Weight) .saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } fn remove_authorise_metaverse_collection() -> Weight { - (39_900_000 as Weight) .saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) }} + (49_171_000 as Weight) .saturating_add(RocksDbWeight::get().reads(10 as Weight)) .saturating_add(RocksDbWeight::get().writes(8 as Weight)) } fn create_new_buy_now() -> Weight { + (50_385_000 as Weight) .saturating_add(RocksDbWeight::get().reads(10 as Weight)) .saturating_add(RocksDbWeight::get().writes(8 as Weight)) } fn bid() -> Weight { + (36_998_000 as Weight) .saturating_add(RocksDbWeight::get().reads(4 as Weight)) .saturating_add(RocksDbWeight::get().writes(6 as Weight)) } fn buy_now() -> Weight { + (97_943_000 as Weight) .saturating_add(RocksDbWeight::get().reads(13 as Weight)) .saturating_add(RocksDbWeight::get().writes(13 as Weight)) } fn authorise_metaverse_collection() -> Weight { + (16_103_000 as Weight) .saturating_add(RocksDbWeight::get().reads(3 as Weight)) .saturating_add(RocksDbWeight::get().writes(2 as Weight)) } fn remove_authorise_metaverse_collection() -> Weight { + (16_804_000 as Weight) .saturating_add(RocksDbWeight::get().reads(3 as Weight)) .saturating_add(RocksDbWeight::get().writes(2 as Weight)) } fn make_offer() -> Weight { + (30_668_000 as Weight) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) .saturating_add(RocksDbWeight::get().writes(3 as Weight)) } fn withdraw_offer() -> Weight { + (23_117_000 as Weight) .saturating_add(RocksDbWeight::get().reads(3 as Weight)) .saturating_add(RocksDbWeight::get().writes(3 as Weight)) } fn accept_offer() -> Weight { + (56_018_000 as Weight) .saturating_add(RocksDbWeight::get().reads(7 as Weight)) .saturating_add(RocksDbWeight::get().writes(7 as Weight)) } fn on_finalize() -> Weight { + (2_271_000 as Weight) }} diff --git a/runtime/continuum/src/weights/module_auction.rs b/runtime/continuum/src/weights/module_auction.rs index 4d9318efb..c482a8cb2 100644 --- a/runtime/continuum/src/weights/module_auction.rs +++ b/runtime/continuum/src/weights/module_auction.rs @@ -12,51 +12,51 @@ pub struct WeightInfo(PhantomData); impl auction::WeightInfo for WeightInfo { fn create_new_auction() -> Weight { - (47_083_000 as Weight) + (49_171_000 as Weight) .saturating_add(T::DbWeight::get().reads(10 as Weight)) .saturating_add(T::DbWeight::get().writes(8 as Weight)) } fn create_new_buy_now() -> Weight { - (46_880_000 as Weight) + (50_385_000 as Weight) .saturating_add(T::DbWeight::get().reads(10 as Weight)) .saturating_add(T::DbWeight::get().writes(8 as Weight)) } fn bid() -> Weight { - (29_214_000 as Weight) + (36_998_000 as Weight) .saturating_add(T::DbWeight::get().reads(4 as Weight)) - .saturating_add(T::DbWeight::get().writes(4 as Weight)) + .saturating_add(T::DbWeight::get().writes(6 as Weight)) } fn buy_now() -> Weight { - (94_897_000 as Weight) + (97_943_000 as Weight) .saturating_add(T::DbWeight::get().reads(13 as Weight)) .saturating_add(T::DbWeight::get().writes(13 as Weight)) } + fn authorise_metaverse_collection() -> Weight { + (16_103_000 as Weight) + .saturating_add(T::DbWeight::get().reads(3 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + } + fn remove_authorise_metaverse_collection() -> Weight { + (16_804_000 as Weight) + .saturating_add(T::DbWeight::get().reads(3 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + } fn make_offer() -> Weight { - (28_148_000 as Weight) + (30_668_000 as Weight) .saturating_add(T::DbWeight::get().reads(5 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } fn withdraw_offer() -> Weight { - (20_996_000 as Weight) + (23_117_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } fn accept_offer() -> Weight { - (52_527_000 as Weight) + (56_018_000 as Weight) .saturating_add(T::DbWeight::get().reads(7 as Weight)) .saturating_add(T::DbWeight::get().writes(7 as Weight)) } fn on_finalize() -> Weight { - (2_093_000 as Weight) - } - fn authorise_metaverse_collection() -> Weight { - (57_600_000 as Weight) - .saturating_add(T::DbWeight::get().reads(2 as Weight)) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) - } - fn remove_authorise_metaverse_collection() -> Weight { - (39_900_000 as Weight) - .saturating_add(T::DbWeight::get().reads(2 as Weight)) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) + (2_271_000 as Weight) } } diff --git a/runtime/metaverse/src/benchmarking/auction.rs b/runtime/metaverse/src/benchmarking/auction.rs index 51efdb398..db50d5a9d 100644 --- a/runtime/metaverse/src/benchmarking/auction.rs +++ b/runtime/metaverse/src/benchmarking/auction.rs @@ -60,54 +60,56 @@ runtime_benchmarks! { create_new_buy_now{ System::set_block_number(1u32.into()); let caller: AccountId = account("caller", 0, SEED); - set_balance(CURRENCY_ID, &caller, dollar(10)); + set_balance(CURRENCY_ID, &caller, dollar(1000)); create_nft_group(); + mint_NFT(&caller, 0u32); create_nft_group(); set_metaverse_treasury_initial_balance(); Metaverse::create_metaverse(RawOrigin::Signed(caller.clone()).into(), vec![1u8]); - mint_NFT(&caller, 2u32); next_block(); - }: _(RawOrigin::Signed(caller.clone()), ItemId::NFT(2,0), dollar(1), 100u32.into(), ListingLevel::Local(METAVERSE_ID), MINING_CURRENCY_ID) + }: _(RawOrigin::Signed(caller.clone()), ItemId::NFT(0,0), dollar(1), 100u32.into(), ListingLevel::Local(METAVERSE_ID), MINING_CURRENCY_ID) // bid bid{ System::set_block_number(1u32.into()); let caller: AccountId = account("caller", 0, SEED); - set_balance(CURRENCY_ID, &caller, dollar(10)); + set_balance(CURRENCY_ID, &caller, dollar(1000)); let bidder: AccountId = account("bidder", 0, SEED); set_balance(CURRENCY_ID, &bidder, dollar(20)); set_balance(MINING_CURRENCY_ID, &bidder, dollar(2000)); create_nft_group(); + mint_NFT(&caller, 0u32); create_nft_group(); set_metaverse_treasury_initial_balance(); Metaverse::create_metaverse(RawOrigin::Signed(caller.clone()).into(), vec![1u8]); - mint_NFT(&caller, 2u32); - next_block(); - Auction::create_new_auction(RawOrigin::Signed(caller.clone()).into(), ItemId::NFT(2,0), dollar(1), 100u32.into(), ListingLevel::Local(METAVERSE_ID), MINING_CURRENCY_ID); next_block(); + Auction::create_new_auction(RawOrigin::Signed(caller.clone()).into(), ItemId::NFT(0,0), dollar(1), 500u32.into(), ListingLevel::Local(METAVERSE_ID), MINING_CURRENCY_ID); + run_to_block(499); }: _(RawOrigin::Signed(bidder.clone()), 0u32.into(), dollar(2)) // buy_now buy_now{ System::set_block_number(1u32.into()); let caller: AccountId = account("caller", 0, SEED); - set_balance(CURRENCY_ID, &caller, dollar(10)); + set_balance(CURRENCY_ID, &caller, dollar(1000)); let bidder: AccountId = account("bidder", 0, SEED); set_balance(CURRENCY_ID, &bidder, dollar(20)); set_balance(MINING_CURRENCY_ID, &bidder, dollar(2000)); create_nft_group(); + mint_NFT(&caller, 0u32); create_nft_group(); set_metaverse_treasury_initial_balance(); Metaverse::create_metaverse(RawOrigin::Signed(caller.clone()).into(), vec![1u8]); - mint_NFT(&caller, 2u32); next_block(); - Auction::create_new_buy_now(RawOrigin::Signed(caller.clone()).into(), ItemId::NFT(2,0), dollar(1), 100u32.into(), ListingLevel::Local(METAVERSE_ID), MINING_CURRENCY_ID); + Auction::create_new_buy_now(RawOrigin::Signed(caller.clone()).into(), ItemId::NFT(0,0), dollar(1), 100u32.into(), ListingLevel::Local(METAVERSE_ID), MINING_CURRENCY_ID); next_block(); }: _(RawOrigin::Signed(bidder.clone()), 0u32.into(), dollar(1)) authorise_metaverse_collection{ let alice: AccountId = account("alice", 0, SEED); - set_balance(CURRENCY_ID, &alice, dollar(10)); + set_balance(CURRENCY_ID, &alice, dollar(1000)); + create_nft_group(); + mint_NFT(&alice, 0u32); create_nft_group(); set_metaverse_treasury_initial_balance(); Metaverse::create_metaverse(RawOrigin::Signed(alice.clone()).into(), vec![1u8]); @@ -115,6 +117,9 @@ runtime_benchmarks! { remove_authorise_metaverse_collection { let alice: AccountId = account("alice", 0, SEED); + set_balance(CURRENCY_ID, &alice, dollar(1000)); + create_nft_group(); + mint_NFT(&alice, 0u32); create_nft_group(); set_metaverse_treasury_initial_balance(); Metaverse::create_metaverse(RawOrigin::Signed(alice.clone()).into(), vec![1u8]); @@ -123,18 +128,18 @@ runtime_benchmarks! { make_offer { let owner: AccountId = account("owner", 0, SEED); - set_balance(CURRENCY_ID, &owner, dollar(10)); + set_balance(CURRENCY_ID, &owner, dollar(1000)); let offeror: AccountId = account("offeror", 0, SEED); - set_balance(CURRENCY_ID, &offeror, dollar(10)); + set_balance(CURRENCY_ID, &offeror, dollar(1000)); create_nft_group(); mint_NFT(&owner, 0u32); }: _(RawOrigin::Signed(offeror.clone()), (0u32.into(), 0u32.into()), dollar(1)) withdraw_offer { let owner: AccountId = account("owner", 0, SEED); - set_balance(CURRENCY_ID, &owner, dollar(10)); + set_balance(CURRENCY_ID, &owner, dollar(1000)); let offeror: AccountId = account("offeror", 0, SEED); - set_balance(CURRENCY_ID, &offeror, dollar(10)); + set_balance(CURRENCY_ID, &offeror, dollar(1000)); create_nft_group(); mint_NFT(&owner, 0u32); Auction::make_offer(RawOrigin::Signed(offeror.clone()).into(), (0u32.into(), 0u32.into()), dollar(1)); @@ -142,9 +147,9 @@ runtime_benchmarks! { accept_offer { let owner: AccountId = account("owner", 0, SEED); - set_balance(CURRENCY_ID, &owner, dollar(10)); + set_balance(CURRENCY_ID, &owner, dollar(1000)); let offeror: AccountId = account("offeror", 0, SEED); - set_balance(CURRENCY_ID, &offeror, dollar(10)); + set_balance(CURRENCY_ID, &offeror, dollar(1000)); create_nft_group(); mint_NFT(&owner, 0u32); Auction::make_offer(RawOrigin::Signed(offeror.clone()).into(), (0u32.into(), 0u32.into()), dollar(1)); @@ -153,19 +158,20 @@ runtime_benchmarks! { on_finalize { System::set_block_number(1u32.into()); let caller = account("caller", 0, SEED); - set_balance(CURRENCY_ID, &caller, dollar(10)); + set_balance(CURRENCY_ID, &caller, dollar(1000)); let bidder = account("bidder", 1, SEED); - set_balance(CURRENCY_ID, &bidder, dollar(10)); + set_balance(CURRENCY_ID, &bidder, dollar(1000)); create_nft_group(); + mint_NFT(&caller, 0u32); create_nft_group(); set_metaverse_treasury_initial_balance(); Metaverse::create_metaverse(RawOrigin::Signed(caller.clone()).into(), vec![1u8]); - mint_NFT(&caller, 2u32); - Auction::create_new_auction(RawOrigin::Signed(caller.clone()).into(), ItemId::NFT(2,0), dollar(1), MinimumAuctionDuration::get(), ListingLevel::Local(METAVERSE_ID), CURRENCY_ID); + Auction::create_new_auction(RawOrigin::Signed(caller.clone()).into(), ItemId::NFT(0,0), dollar(1), MinimumAuctionDuration::get(), ListingLevel::Local(METAVERSE_ID), CURRENCY_ID); Auction::bid(RawOrigin::Signed(bidder.clone()).into(), 0u32.into(), dollar(2)); }: { Auction::on_finalize(System::block_number() + MinimumAuctionDuration::get()); } + } #[cfg(test)] diff --git a/runtime/metaverse/src/weights/module_auction.rs b/runtime/metaverse/src/weights/module_auction.rs index 0e3bc2af4..12d372028 100644 --- a/runtime/metaverse/src/weights/module_auction.rs +++ b/runtime/metaverse/src/weights/module_auction.rs @@ -9,51 +9,51 @@ pub struct WeightInfo(PhantomData); impl auction::WeightInfo for WeightInfo { fn create_new_auction() -> Weight { - (47_083_000 as Weight) + (49_171_000 as Weight) .saturating_add(T::DbWeight::get().reads(10 as Weight)) .saturating_add(T::DbWeight::get().writes(8 as Weight)) } fn create_new_buy_now() -> Weight { - (46_880_000 as Weight) + (50_385_000 as Weight) .saturating_add(T::DbWeight::get().reads(10 as Weight)) .saturating_add(T::DbWeight::get().writes(8 as Weight)) } fn bid() -> Weight { - (29_214_000 as Weight) + (36_998_000 as Weight) .saturating_add(T::DbWeight::get().reads(4 as Weight)) - .saturating_add(T::DbWeight::get().writes(4 as Weight)) + .saturating_add(T::DbWeight::get().writes(6 as Weight)) } fn buy_now() -> Weight { - (94_897_000 as Weight) + (97_943_000 as Weight) .saturating_add(T::DbWeight::get().reads(13 as Weight)) .saturating_add(T::DbWeight::get().writes(13 as Weight)) } + fn authorise_metaverse_collection() -> Weight { + (16_103_000 as Weight) + .saturating_add(T::DbWeight::get().reads(3 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + } + fn remove_authorise_metaverse_collection() -> Weight { + (16_804_000 as Weight) + .saturating_add(T::DbWeight::get().reads(3 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + } fn make_offer() -> Weight { - (28_148_000 as Weight) + (30_668_000 as Weight) .saturating_add(T::DbWeight::get().reads(5 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } fn withdraw_offer() -> Weight { - (20_996_000 as Weight) + (23_117_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } fn accept_offer() -> Weight { - (52_527_000 as Weight) + (56_018_000 as Weight) .saturating_add(T::DbWeight::get().reads(7 as Weight)) .saturating_add(T::DbWeight::get().writes(7 as Weight)) } fn on_finalize() -> Weight { - (2_093_000 as Weight) - } - fn authorise_metaverse_collection() -> Weight { - (57_600_000 as Weight) - .saturating_add(T::DbWeight::get().reads(2 as Weight)) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) - } - fn remove_authorise_metaverse_collection() -> Weight { - (39_900_000 as Weight) - .saturating_add(T::DbWeight::get().reads(2 as Weight)) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) + (2_271_000 as Weight) } } diff --git a/runtime/pioneer/src/weights/module_auction.rs b/runtime/pioneer/src/weights/module_auction.rs index 4d9318efb..c482a8cb2 100644 --- a/runtime/pioneer/src/weights/module_auction.rs +++ b/runtime/pioneer/src/weights/module_auction.rs @@ -12,51 +12,51 @@ pub struct WeightInfo(PhantomData); impl auction::WeightInfo for WeightInfo { fn create_new_auction() -> Weight { - (47_083_000 as Weight) + (49_171_000 as Weight) .saturating_add(T::DbWeight::get().reads(10 as Weight)) .saturating_add(T::DbWeight::get().writes(8 as Weight)) } fn create_new_buy_now() -> Weight { - (46_880_000 as Weight) + (50_385_000 as Weight) .saturating_add(T::DbWeight::get().reads(10 as Weight)) .saturating_add(T::DbWeight::get().writes(8 as Weight)) } fn bid() -> Weight { - (29_214_000 as Weight) + (36_998_000 as Weight) .saturating_add(T::DbWeight::get().reads(4 as Weight)) - .saturating_add(T::DbWeight::get().writes(4 as Weight)) + .saturating_add(T::DbWeight::get().writes(6 as Weight)) } fn buy_now() -> Weight { - (94_897_000 as Weight) + (97_943_000 as Weight) .saturating_add(T::DbWeight::get().reads(13 as Weight)) .saturating_add(T::DbWeight::get().writes(13 as Weight)) } + fn authorise_metaverse_collection() -> Weight { + (16_103_000 as Weight) + .saturating_add(T::DbWeight::get().reads(3 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + } + fn remove_authorise_metaverse_collection() -> Weight { + (16_804_000 as Weight) + .saturating_add(T::DbWeight::get().reads(3 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + } fn make_offer() -> Weight { - (28_148_000 as Weight) + (30_668_000 as Weight) .saturating_add(T::DbWeight::get().reads(5 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } fn withdraw_offer() -> Weight { - (20_996_000 as Weight) + (23_117_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } fn accept_offer() -> Weight { - (52_527_000 as Weight) + (56_018_000 as Weight) .saturating_add(T::DbWeight::get().reads(7 as Weight)) .saturating_add(T::DbWeight::get().writes(7 as Weight)) } fn on_finalize() -> Weight { - (2_093_000 as Weight) - } - fn authorise_metaverse_collection() -> Weight { - (57_600_000 as Weight) - .saturating_add(T::DbWeight::get().reads(2 as Weight)) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) - } - fn remove_authorise_metaverse_collection() -> Weight { - (39_900_000 as Weight) - .saturating_add(T::DbWeight::get().reads(2 as Weight)) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) + (2_271_000 as Weight) } } From d430e0eca65cbad62a9c24523b3adde4a605b546 Mon Sep 17 00:00:00 2001 From: Aleksandar Brayanov Date: Tue, 15 Nov 2022 20:39:26 +0000 Subject: [PATCH 04/17] separate build and test workflows --- .../workflows/{rust.yml => rust-build.yml} | 7 +--- .github/workflows/rust-test.yml | 38 +++++++++++++++++++ 2 files changed, 40 insertions(+), 5 deletions(-) rename .github/workflows/{rust.yml => rust-build.yml} (85%) create mode 100644 .github/workflows/rust-test.yml diff --git a/.github/workflows/rust.yml b/.github/workflows/rust-build.yml similarity index 85% rename from .github/workflows/rust.yml rename to .github/workflows/rust-build.yml index c65a43196..77cf9cbb7 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust-build.yml @@ -1,4 +1,4 @@ -name: Metaverse Build & Test +name: Metaverse Build on: pull_request: @@ -37,7 +37,4 @@ jobs: run: cargo fmt --all -- --check - name: Check Build run: | - SKIP_WASM_BUILD=1 cargo check --release --features with-pioneer-runtime,with-metaverse-runtime - - name: Run all test cases - run: | - SKIP_WASM_BUILD= cargo test --all --features with-pioneer-runtime + SKIP_WASM_BUILD=1 cargo check --release --features with-pioneer-runtime,with-metaverse-runtime \ No newline at end of file diff --git a/.github/workflows/rust-test.yml b/.github/workflows/rust-test.yml new file mode 100644 index 000000000..4b092798a --- /dev/null +++ b/.github/workflows/rust-test.yml @@ -0,0 +1,38 @@ +name: Metaverse Test + +on: + pull_request: + branches: + - master + push: + branches: + - master + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +jobs: + check: + # The type of runner that the job will run on + runs-on: ubuntu-20.04 + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v3 + + - name: Set-Up + run: sudo apt install -y cmake pkg-config libssl-dev git build-essential clang libclang-dev curl + + - name: Install Rustup + run: | + curl https://sh.rustup.rs -sSf | sh -s -- -y + source ~/.cargo/env + rustup default nightly && rustup update + rustup default nightly-2022-05-11 + rustup target add wasm32-unknown-unknown --toolchain nightly-2022-05-11 + - name: Check Rust version + run: rustup show + - name: Run all test cases + run: | + SKIP_WASM_BUILD= cargo test --all --features with-pioneer-runtime From a4c3db719d686d202c20f0893e56e9e7652ea32d Mon Sep 17 00:00:00 2001 From: Aleksandar Brayanov Date: Tue, 15 Nov 2022 21:18:39 +0000 Subject: [PATCH 05/17] bump actions version --- .github/workflows/rust-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rust-test.yml b/.github/workflows/rust-test.yml index 4b092798a..c3439c7cd 100644 --- a/.github/workflows/rust-test.yml +++ b/.github/workflows/rust-test.yml @@ -19,7 +19,7 @@ jobs: # Steps represent a sequence of tasks that will be executed as part of the job steps: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set-Up run: sudo apt install -y cmake pkg-config libssl-dev git build-essential clang libclang-dev curl From 8d91622fa988ed7be227f484c35395be4f7426e6 Mon Sep 17 00:00:00 2001 From: Aleksandar Brayanov Date: Tue, 15 Nov 2022 21:18:58 +0000 Subject: [PATCH 06/17] revert changes --- .github/workflows/rust-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rust-test.yml b/.github/workflows/rust-test.yml index c3439c7cd..4b092798a 100644 --- a/.github/workflows/rust-test.yml +++ b/.github/workflows/rust-test.yml @@ -19,7 +19,7 @@ jobs: # Steps represent a sequence of tasks that will be executed as part of the job steps: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v4 + - uses: actions/checkout@v3 - name: Set-Up run: sudo apt install -y cmake pkg-config libssl-dev git build-essential clang libclang-dev curl From 91ff0e86ac0a23199b31338e5006888ce6181875 Mon Sep 17 00:00:00 2001 From: Aleksandar Brayanov Date: Fri, 18 Nov 2022 05:28:54 +0000 Subject: [PATCH 07/17] added extrinsic for manual finalization of auction --- pallets/auction/src/lib.rs | 25 ++++++++++++++++++++++ pallets/auction/src/tests.rs | 40 ++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/pallets/auction/src/lib.rs b/pallets/auction/src/lib.rs index 6641d82ef..734d1c39c 100644 --- a/pallets/auction/src/lib.rs +++ b/pallets/auction/src/lib.rs @@ -293,6 +293,8 @@ pub mod pallet { AuctionHasNotStarted, /// Auction is expired AuctionIsExpired, + /// Auction is not expired + AuctionIsNotExpired, /// Auction type is supported for listing AuctionTypeIsNotSupported, /// Bid is not accepted e.g owner == bidder, listing stop accepting bid @@ -349,6 +351,8 @@ pub mod pallet { NoPermissionToMakeOffer, /// No permission to accept offer for a NFT. NoPermissionToAcceptOffer, + /// No permission to finalize auction + NoPermissionToFinalizeAuction, /// Listing price is below the minimum. ListingPriceIsBelowMinimum, /// Only metaverse owner can participate @@ -760,6 +764,27 @@ pub mod pallet { Self::deposit_event(Event::::NftOfferWithdrawn(asset.0, asset.1, offeror)); Ok(().into()) } + + /// Manually finalize ended auction. + /// + /// The dispatch origin for this call must be _Signed_. + /// - `auction_id`: the ID of the auction that will be finalized. + /// + /// Emits `AuctionFinalized` or `AuctionFinalizedNoBid` if successful. + #[pallet::weight(T::WeightInfo::on_finalize())] + pub fn finalize_auction(origin: OriginFor, auction_id: AuctionId) -> DispatchResultWithPostInfo { + let who = ensure_signed(origin)?; + + let auction = >::get(&auction_id).ok_or(Error::::AuctionDoesNotExist)?; + ensure!( + auction.end.ok_or(Error::::AuctionIsNotExpired)? < >::block_number(), + Error::::AuctionIsNotExpired + ); + + T::Handler::on_auction_ended(auction_id, auction.bid); + + Ok(().into()) + } } #[pallet::hooks] diff --git a/pallets/auction/src/tests.rs b/pallets/auction/src/tests.rs index b4228b4ca..82166ec9f 100644 --- a/pallets/auction/src/tests.rs +++ b/pallets/auction/src/tests.rs @@ -1726,3 +1726,43 @@ fn withdraw_offer_should_work() { assert_eq!(Balances::free_balance(BOB), 500); }); } + +#[test] +fn finalize_auction_should_fail() { + ExtBuilder::default().build().execute_with(|| { + let owner = Origin::signed(BOB); + let bidder = Origin::signed(ALICE); + init_test_nft(owner.clone()); + init_test_nft(owner.clone()); + assert_ok!(AuctionModule::create_auction( + AuctionType::Auction, + ItemId::NFT(0, 0), + None, + BOB, + 100, + 0, + ListingLevel::Global, + Perbill::from_percent(0u32), + FungibleTokenId::NativeToken(0) + )); + + run_to_block(10); + + assert_noop!( + AuctionModule::finalize_auction(Origin::signed(BOB), 100), + Error::::AuctionDoesNotExist + ); + + assert_noop!( + AuctionModule::finalize_auction(Origin::signed(BOB), 0), + Error::::AuctionIsNotExpired + ); + + run_to_block(102); + + assert_noop!( + AuctionModule::finalize_auction(Origin::signed(BOB), 0), + Error::::AuctionDoesNotExist + ); + }); +} From 734975d56e58939ebc3e7cda41ee959daba72190 Mon Sep 17 00:00:00 2001 From: Aleksandar Brayanov Date: Wed, 23 Nov 2022 08:36:59 +0000 Subject: [PATCH 08/17] cancel listing can be called by both seller and root --- pallets/auction/src/lib.rs | 9 +- pallets/auction/src/tests.rs | 92 +++++++++++++++++++ pallets/auction/src/weights.rs | 46 +++++----- .../continuum/src/weights/module_auction.rs | 25 +++-- runtime/metaverse/src/benchmarking/auction.rs | 18 ++++ .../metaverse/src/weights/module_auction.rs | 25 +++-- runtime/pioneer/src/weights/module_auction.rs | 25 +++-- 7 files changed, 185 insertions(+), 55 deletions(-) diff --git a/pallets/auction/src/lib.rs b/pallets/auction/src/lib.rs index 734d1c39c..7841b1f4d 100644 --- a/pallets/auction/src/lib.rs +++ b/pallets/auction/src/lib.rs @@ -607,15 +607,18 @@ pub mod pallet { /// - `from`: the listing owner who created this listing /// - `auction_id`: the auction id that wish to cancel /// - /// Emits `CollectionAuthorizationRemoveInMetaverse` if successful. - #[pallet::weight(T::WeightInfo::remove_authorise_metaverse_collection())] + /// Emits `AuctionCancelled` and `AuctionFinalizedNoBid` if successful. + #[pallet::weight(T::WeightInfo::cancel_listing())] #[transactional] pub fn cancel_listing( origin: OriginFor, from: T::AccountId, auction_id: AuctionId, ) -> DispatchResultWithPostInfo { - ensure_root(origin)?; + ensure!( + ensure_root(origin.clone()).is_ok() || ensure_signed(origin)? == from, + Error::::NoPermissionToCancelAuction + ); ensure!(Auctions::::contains_key(auction_id), Error::::AuctionDoesNotExist); let auction_item = AuctionItems::::get(auction_id).ok_or(Error::::AuctionDoesNotExist)?; diff --git a/pallets/auction/src/tests.rs b/pallets/auction/src/tests.rs index 82166ec9f..bb46ab4a0 100644 --- a/pallets/auction/src/tests.rs +++ b/pallets/auction/src/tests.rs @@ -1766,3 +1766,95 @@ fn finalize_auction_should_fail() { ); }); } + +#[test] +fn cancel_listing_should_work() { + ExtBuilder::default().build().execute_with(|| { + let owner = Origin::signed(BOB); + let bidder = Origin::signed(ALICE); + init_test_nft(owner.clone()); + assert_ok!(AuctionModule::create_auction( + AuctionType::Auction, + ItemId::NFT(0, 0), + None, + BOB, + 100, + 0, + ListingLevel::Global, + Perbill::from_percent(0u32), + FungibleTokenId::NativeToken(0) + )); + assert_eq!(Balances::free_balance(BOB), 496); + assert_eq!(AuctionModule::items_in_auction(ItemId::NFT(0, 0)), Some(true)); + assert_eq!( + AuctionModule::auctions(0), + Some(AuctionInfo { + bid: None, + start: 1, + end: Some(101), + }) + ); + + run_to_block(2); + assert_ok!(AuctionModule::cancel_listing(Origin::signed(BOB), BOB, 0)); + assert_eq!(Balances::free_balance(BOB), 497); + + assert_eq!(AuctionModule::items_in_auction(ItemId::NFT(0, 0)), None); + assert_eq!(AuctionModule::auctions(0), None); + + let event = mock::Event::AuctionModule(crate::Event::AuctionFinalizedNoBid(0)); + assert_eq!(last_event(), event); + }); +} + +#[test] +fn cancel_listing_should_fail() { + ExtBuilder::default().build().execute_with(|| { + let owner = Origin::signed(BOB); + let bidder = Origin::signed(ALICE); + init_test_nft(owner.clone()); + init_test_nft(owner.clone()); + assert_ok!(AuctionModule::create_auction( + AuctionType::Auction, + ItemId::NFT(0, 0), + None, + BOB, + 100, + 0, + ListingLevel::Global, + Perbill::from_percent(0u32), + FungibleTokenId::NativeToken(0) + )); + + run_to_block(10); + + assert_noop!( + AuctionModule::cancel_listing(Origin::signed(BOB), ALICE, 0), + Error::::NoPermissionToCancelAuction + ); + + assert_noop!( + AuctionModule::cancel_listing(Origin::signed(BOB), BOB, 1), + Error::::AuctionDoesNotExist + ); + + assert_noop!( + AuctionModule::cancel_listing(Origin::root(), ALICE, 0), + Error::::NoPermissionToCancelAuction + ); + + assert_noop!( + AuctionModule::cancel_listing(Origin::signed(ALICE), ALICE, 0), + Error::::NoPermissionToCancelAuction + ); + + //assert_ok!(AuctionModule::bid(Origin::signed(ALICE.clone()), 0, 200)); + + //run_to_block(11); + + //assert_noop!( + // AuctionModule::cancel_listing(Origin::signed(BOB), BOB, 0), + // Error::::AuctionAlreadyStartedOrBid + //); + }); +} diff --git a/pallets/auction/src/weights.rs b/pallets/auction/src/weights.rs index ae5449b85..ea5cddd0a 100644 --- a/pallets/auction/src/weights.rs +++ b/pallets/auction/src/weights.rs @@ -18,7 +18,7 @@ //! Autogenerated weights for auction //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2022-11-15, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2022-11-23, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024 // Executed Command: @@ -48,31 +48,33 @@ use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; use sp_std::marker::PhantomData; /// Weight functions needed for auction. -pub trait WeightInfo { fn create_new_auction() -> Weight; fn create_new_buy_now() -> Weight; fn bid() -> Weight; fn buy_now() -> Weight; fn authorise_metaverse_collection() -> Weight; fn remove_authorise_metaverse_collection() -> Weight; fn make_offer() -> Weight; fn withdraw_offer() -> Weight; fn accept_offer() -> Weight; fn on_finalize() -> Weight;} +pub trait WeightInfo { fn create_new_auction() -> Weight; fn create_new_buy_now() -> Weight; fn bid() -> Weight; fn buy_now() -> Weight; fn cancel_listing() -> Weight; fn authorise_metaverse_collection() -> Weight; fn remove_authorise_metaverse_collection() -> Weight; fn make_offer() -> Weight; fn withdraw_offer() -> Weight; fn accept_offer() -> Weight; fn on_finalize() -> Weight;} /// Weights for auction using the for collator node and recommended hardware. pub struct SubstrateWeight(PhantomData); impl WeightInfo for SubstrateWeight { fn create_new_auction() -> Weight { - (49_171_000 as Weight) .saturating_add(T::DbWeight::get().reads(10 as Weight)) .saturating_add(T::DbWeight::get().writes(8 as Weight)) } fn create_new_buy_now() -> Weight { - (50_385_000 as Weight) .saturating_add(T::DbWeight::get().reads(10 as Weight)) .saturating_add(T::DbWeight::get().writes(8 as Weight)) } fn bid() -> Weight { - (36_998_000 as Weight) .saturating_add(T::DbWeight::get().reads(4 as Weight)) .saturating_add(T::DbWeight::get().writes(6 as Weight)) } fn buy_now() -> Weight { - (97_943_000 as Weight) .saturating_add(T::DbWeight::get().reads(13 as Weight)) .saturating_add(T::DbWeight::get().writes(13 as Weight)) } fn authorise_metaverse_collection() -> Weight { - (16_103_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } fn remove_authorise_metaverse_collection() -> Weight { - (16_804_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } fn make_offer() -> Weight { - (30_668_000 as Weight) .saturating_add(T::DbWeight::get().reads(5 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } fn withdraw_offer() -> Weight { - (23_117_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } fn accept_offer() -> Weight { - (56_018_000 as Weight) .saturating_add(T::DbWeight::get().reads(7 as Weight)) .saturating_add(T::DbWeight::get().writes(7 as Weight)) } fn on_finalize() -> Weight { - (2_271_000 as Weight) }} + (51_004_000 as Weight) .saturating_add(T::DbWeight::get().reads(10 as Weight)) .saturating_add(T::DbWeight::get().writes(8 as Weight)) } fn create_new_buy_now() -> Weight { + (50_881_000 as Weight) .saturating_add(T::DbWeight::get().reads(10 as Weight)) .saturating_add(T::DbWeight::get().writes(8 as Weight)) } fn bid() -> Weight { + (37_231_000 as Weight) .saturating_add(T::DbWeight::get().reads(4 as Weight)) .saturating_add(T::DbWeight::get().writes(6 as Weight)) } fn buy_now() -> Weight { + (100_321_000 as Weight) .saturating_add(T::DbWeight::get().reads(13 as Weight)) .saturating_add(T::DbWeight::get().writes(13 as Weight)) } fn cancel_listing() -> Weight { + (39_602_000 as Weight) .saturating_add(T::DbWeight::get().reads(5 as Weight)) .saturating_add(T::DbWeight::get().writes(7 as Weight)) } fn authorise_metaverse_collection() -> Weight { + (15_958_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } fn remove_authorise_metaverse_collection() -> Weight { + (16_426_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } fn make_offer() -> Weight { + (30_306_000 as Weight) .saturating_add(T::DbWeight::get().reads(5 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } fn withdraw_offer() -> Weight { + (23_037_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } fn accept_offer() -> Weight { + (57_124_000 as Weight) .saturating_add(T::DbWeight::get().reads(7 as Weight)) .saturating_add(T::DbWeight::get().writes(7 as Weight)) } fn on_finalize() -> Weight { + (2_297_000 as Weight) }} // For backwards compatibility and tests impl WeightInfo for () { fn create_new_auction() -> Weight { - (49_171_000 as Weight) .saturating_add(RocksDbWeight::get().reads(10 as Weight)) .saturating_add(RocksDbWeight::get().writes(8 as Weight)) } fn create_new_buy_now() -> Weight { - (50_385_000 as Weight) .saturating_add(RocksDbWeight::get().reads(10 as Weight)) .saturating_add(RocksDbWeight::get().writes(8 as Weight)) } fn bid() -> Weight { - (36_998_000 as Weight) .saturating_add(RocksDbWeight::get().reads(4 as Weight)) .saturating_add(RocksDbWeight::get().writes(6 as Weight)) } fn buy_now() -> Weight { - (97_943_000 as Weight) .saturating_add(RocksDbWeight::get().reads(13 as Weight)) .saturating_add(RocksDbWeight::get().writes(13 as Weight)) } fn authorise_metaverse_collection() -> Weight { - (16_103_000 as Weight) .saturating_add(RocksDbWeight::get().reads(3 as Weight)) .saturating_add(RocksDbWeight::get().writes(2 as Weight)) } fn remove_authorise_metaverse_collection() -> Weight { - (16_804_000 as Weight) .saturating_add(RocksDbWeight::get().reads(3 as Weight)) .saturating_add(RocksDbWeight::get().writes(2 as Weight)) } fn make_offer() -> Weight { - (30_668_000 as Weight) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) .saturating_add(RocksDbWeight::get().writes(3 as Weight)) } fn withdraw_offer() -> Weight { - (23_117_000 as Weight) .saturating_add(RocksDbWeight::get().reads(3 as Weight)) .saturating_add(RocksDbWeight::get().writes(3 as Weight)) } fn accept_offer() -> Weight { - (56_018_000 as Weight) .saturating_add(RocksDbWeight::get().reads(7 as Weight)) .saturating_add(RocksDbWeight::get().writes(7 as Weight)) } fn on_finalize() -> Weight { - (2_271_000 as Weight) }} + (51_004_000 as Weight) .saturating_add(RocksDbWeight::get().reads(10 as Weight)) .saturating_add(RocksDbWeight::get().writes(8 as Weight)) } fn create_new_buy_now() -> Weight { + (50_881_000 as Weight) .saturating_add(RocksDbWeight::get().reads(10 as Weight)) .saturating_add(RocksDbWeight::get().writes(8 as Weight)) } fn bid() -> Weight { + (37_231_000 as Weight) .saturating_add(RocksDbWeight::get().reads(4 as Weight)) .saturating_add(RocksDbWeight::get().writes(6 as Weight)) } fn buy_now() -> Weight { + (100_321_000 as Weight) .saturating_add(RocksDbWeight::get().reads(13 as Weight)) .saturating_add(RocksDbWeight::get().writes(13 as Weight)) } fn cancel_listing() -> Weight { + (39_602_000 as Weight) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) .saturating_add(RocksDbWeight::get().writes(7 as Weight)) } fn authorise_metaverse_collection() -> Weight { + (15_958_000 as Weight) .saturating_add(RocksDbWeight::get().reads(3 as Weight)) .saturating_add(RocksDbWeight::get().writes(2 as Weight)) } fn remove_authorise_metaverse_collection() -> Weight { + (16_426_000 as Weight) .saturating_add(RocksDbWeight::get().reads(3 as Weight)) .saturating_add(RocksDbWeight::get().writes(2 as Weight)) } fn make_offer() -> Weight { + (30_306_000 as Weight) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) .saturating_add(RocksDbWeight::get().writes(3 as Weight)) } fn withdraw_offer() -> Weight { + (23_037_000 as Weight) .saturating_add(RocksDbWeight::get().reads(3 as Weight)) .saturating_add(RocksDbWeight::get().writes(3 as Weight)) } fn accept_offer() -> Weight { + (57_124_000 as Weight) .saturating_add(RocksDbWeight::get().reads(7 as Weight)) .saturating_add(RocksDbWeight::get().writes(7 as Weight)) } fn on_finalize() -> Weight { + (2_297_000 as Weight) }} diff --git a/runtime/continuum/src/weights/module_auction.rs b/runtime/continuum/src/weights/module_auction.rs index c482a8cb2..d29d1bbc8 100644 --- a/runtime/continuum/src/weights/module_auction.rs +++ b/runtime/continuum/src/weights/module_auction.rs @@ -12,51 +12,56 @@ pub struct WeightInfo(PhantomData); impl auction::WeightInfo for WeightInfo { fn create_new_auction() -> Weight { - (49_171_000 as Weight) + (51_004_000 as Weight) .saturating_add(T::DbWeight::get().reads(10 as Weight)) .saturating_add(T::DbWeight::get().writes(8 as Weight)) } fn create_new_buy_now() -> Weight { - (50_385_000 as Weight) + (50_881_000 as Weight) .saturating_add(T::DbWeight::get().reads(10 as Weight)) .saturating_add(T::DbWeight::get().writes(8 as Weight)) } fn bid() -> Weight { - (36_998_000 as Weight) + (37_231_000 as Weight) .saturating_add(T::DbWeight::get().reads(4 as Weight)) .saturating_add(T::DbWeight::get().writes(6 as Weight)) } fn buy_now() -> Weight { - (97_943_000 as Weight) + (100_321_000 as Weight) .saturating_add(T::DbWeight::get().reads(13 as Weight)) .saturating_add(T::DbWeight::get().writes(13 as Weight)) } + fn cancel_listing() -> Weight { + (39_602_000 as Weight) + .saturating_add(T::DbWeight::get().reads(5 as Weight)) + .saturating_add(T::DbWeight::get().writes(7 as Weight)) + } fn authorise_metaverse_collection() -> Weight { - (16_103_000 as Weight) + (15_958_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } fn remove_authorise_metaverse_collection() -> Weight { - (16_804_000 as Weight) + (16_426_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } fn make_offer() -> Weight { - (30_668_000 as Weight) + (30_306_000 as Weight) .saturating_add(T::DbWeight::get().reads(5 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } fn withdraw_offer() -> Weight { - (23_117_000 as Weight) + (23_037_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } fn accept_offer() -> Weight { - (56_018_000 as Weight) + (57_124_000 as Weight) .saturating_add(T::DbWeight::get().reads(7 as Weight)) .saturating_add(T::DbWeight::get().writes(7 as Weight)) } fn on_finalize() -> Weight { - (2_271_000 as Weight) + (2_297_000 as Weight) } } diff --git a/runtime/metaverse/src/benchmarking/auction.rs b/runtime/metaverse/src/benchmarking/auction.rs index db50d5a9d..34c7e8115 100644 --- a/runtime/metaverse/src/benchmarking/auction.rs +++ b/runtime/metaverse/src/benchmarking/auction.rs @@ -105,6 +105,24 @@ runtime_benchmarks! { next_block(); }: _(RawOrigin::Signed(bidder.clone()), 0u32.into(), dollar(1)) + // cancel listingg + cancel_listing{ + System::set_block_number(1u32.into()); + let caller: AccountId = account("caller", 0, SEED); + set_balance(CURRENCY_ID, &caller, dollar(1000)); + let bidder: AccountId = account("bidder", 0, SEED); + set_balance(CURRENCY_ID, &bidder, dollar(20)); + set_balance(MINING_CURRENCY_ID, &bidder, dollar(2000)); + create_nft_group(); + mint_NFT(&caller, 0u32); + create_nft_group(); + set_metaverse_treasury_initial_balance(); + Metaverse::create_metaverse(RawOrigin::Signed(caller.clone()).into(), vec![1u8]); + next_block(); + Auction::create_new_auction(RawOrigin::Signed(caller.clone()).into(), ItemId::NFT(0,0), dollar(1), 500u32.into(), ListingLevel::Local(METAVERSE_ID), MINING_CURRENCY_ID); + next_block(); + }: _(RawOrigin::Signed(caller.clone()), caller.clone(), 0u32.into()) + authorise_metaverse_collection{ let alice: AccountId = account("alice", 0, SEED); set_balance(CURRENCY_ID, &alice, dollar(1000)); diff --git a/runtime/metaverse/src/weights/module_auction.rs b/runtime/metaverse/src/weights/module_auction.rs index 12d372028..ef829327a 100644 --- a/runtime/metaverse/src/weights/module_auction.rs +++ b/runtime/metaverse/src/weights/module_auction.rs @@ -9,51 +9,56 @@ pub struct WeightInfo(PhantomData); impl auction::WeightInfo for WeightInfo { fn create_new_auction() -> Weight { - (49_171_000 as Weight) + (51_004_000 as Weight) .saturating_add(T::DbWeight::get().reads(10 as Weight)) .saturating_add(T::DbWeight::get().writes(8 as Weight)) } fn create_new_buy_now() -> Weight { - (50_385_000 as Weight) + (50_881_000 as Weight) .saturating_add(T::DbWeight::get().reads(10 as Weight)) .saturating_add(T::DbWeight::get().writes(8 as Weight)) } fn bid() -> Weight { - (36_998_000 as Weight) + (37_231_000 as Weight) .saturating_add(T::DbWeight::get().reads(4 as Weight)) .saturating_add(T::DbWeight::get().writes(6 as Weight)) } fn buy_now() -> Weight { - (97_943_000 as Weight) + (100_321_000 as Weight) .saturating_add(T::DbWeight::get().reads(13 as Weight)) .saturating_add(T::DbWeight::get().writes(13 as Weight)) } + fn cancel_listing() -> Weight { + (39_602_000 as Weight) + .saturating_add(T::DbWeight::get().reads(5 as Weight)) + .saturating_add(T::DbWeight::get().writes(7 as Weight)) + } fn authorise_metaverse_collection() -> Weight { - (16_103_000 as Weight) + (15_958_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } fn remove_authorise_metaverse_collection() -> Weight { - (16_804_000 as Weight) + (16_426_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } fn make_offer() -> Weight { - (30_668_000 as Weight) + (30_306_000 as Weight) .saturating_add(T::DbWeight::get().reads(5 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } fn withdraw_offer() -> Weight { - (23_117_000 as Weight) + (23_037_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } fn accept_offer() -> Weight { - (56_018_000 as Weight) + (57_124_000 as Weight) .saturating_add(T::DbWeight::get().reads(7 as Weight)) .saturating_add(T::DbWeight::get().writes(7 as Weight)) } fn on_finalize() -> Weight { - (2_271_000 as Weight) + (2_297_000 as Weight) } } diff --git a/runtime/pioneer/src/weights/module_auction.rs b/runtime/pioneer/src/weights/module_auction.rs index c482a8cb2..d29d1bbc8 100644 --- a/runtime/pioneer/src/weights/module_auction.rs +++ b/runtime/pioneer/src/weights/module_auction.rs @@ -12,51 +12,56 @@ pub struct WeightInfo(PhantomData); impl auction::WeightInfo for WeightInfo { fn create_new_auction() -> Weight { - (49_171_000 as Weight) + (51_004_000 as Weight) .saturating_add(T::DbWeight::get().reads(10 as Weight)) .saturating_add(T::DbWeight::get().writes(8 as Weight)) } fn create_new_buy_now() -> Weight { - (50_385_000 as Weight) + (50_881_000 as Weight) .saturating_add(T::DbWeight::get().reads(10 as Weight)) .saturating_add(T::DbWeight::get().writes(8 as Weight)) } fn bid() -> Weight { - (36_998_000 as Weight) + (37_231_000 as Weight) .saturating_add(T::DbWeight::get().reads(4 as Weight)) .saturating_add(T::DbWeight::get().writes(6 as Weight)) } fn buy_now() -> Weight { - (97_943_000 as Weight) + (100_321_000 as Weight) .saturating_add(T::DbWeight::get().reads(13 as Weight)) .saturating_add(T::DbWeight::get().writes(13 as Weight)) } + fn cancel_listing() -> Weight { + (39_602_000 as Weight) + .saturating_add(T::DbWeight::get().reads(5 as Weight)) + .saturating_add(T::DbWeight::get().writes(7 as Weight)) + } fn authorise_metaverse_collection() -> Weight { - (16_103_000 as Weight) + (15_958_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } fn remove_authorise_metaverse_collection() -> Weight { - (16_804_000 as Weight) + (16_426_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } fn make_offer() -> Weight { - (30_668_000 as Weight) + (30_306_000 as Weight) .saturating_add(T::DbWeight::get().reads(5 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } fn withdraw_offer() -> Weight { - (23_117_000 as Weight) + (23_037_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } fn accept_offer() -> Weight { - (56_018_000 as Weight) + (57_124_000 as Weight) .saturating_add(T::DbWeight::get().reads(7 as Weight)) .saturating_add(T::DbWeight::get().writes(7 as Weight)) } fn on_finalize() -> Weight { - (2_271_000 as Weight) + (2_297_000 as Weight) } } From b05a79ffcbb47726616e399986f5b9b6b39a9667 Mon Sep 17 00:00:00 2001 From: Justin Date: Thu, 24 Nov 2022 13:18:39 +1300 Subject: [PATCH 09/17] Add more comment to the anti snipe code --- pallets/auction/src/lib.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pallets/auction/src/lib.rs b/pallets/auction/src/lib.rs index 7841b1f4d..f83a49351 100644 --- a/pallets/auction/src/lib.rs +++ b/pallets/auction/src/lib.rs @@ -1161,11 +1161,18 @@ pub mod pallet { .saturating_sub(>::block_number()) <= T::AntiSnipeDuration::get() { + // Trigger anti-snipe + // Remove existing auction end AuctionEndTime::::remove(auction_end, id); + // Extend auction end time let new_auction_end = auction_end.saturating_add(T::AntiSnipeDuration::get()); + // Update new auction item end time auction_item.end_time = new_auction_end; + // Update storage key of auction item AuctionItems::::insert(id, auction_item); + // Update new auction end time AuctionEndTime::::insert(new_auction_end, id, ()); + // Update auction struct auction.end = Some(new_auction_end); } From 743ca5f5aade875ed557e82827a8266ca8be436f Mon Sep 17 00:00:00 2001 From: Justin Date: Thu, 24 Nov 2022 13:37:39 +1300 Subject: [PATCH 10/17] Adding more test cases on the anti-snipe auction --- pallets/auction/src/tests.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/pallets/auction/src/tests.rs b/pallets/auction/src/tests.rs index bb46ab4a0..6e4224e74 100644 --- a/pallets/auction/src/tests.rs +++ b/pallets/auction/src/tests.rs @@ -589,11 +589,10 @@ fn bid_anti_snipe_duration_works() { Perbill::from_percent(0u32), FungibleTokenId::NativeToken(0), )); - let old_auction_item = AuctionModule::get_auction_item(0); run_to_block(96); - assert_ok!(AuctionModule::bid(bidder, 0, 200)); + assert_ok!(AuctionModule::bid(bidder.clone(), 0, 200)); assert_eq!( AuctionModule::auctions(0), @@ -606,7 +605,20 @@ fn bid_anti_snipe_duration_works() { assert_eq!(AuctionModule::auction_end_time(106, 0), Some(())); assert_eq!(AuctionModule::auction_end_time(101, 0), None); assert_eq!(last_event(), Event::AuctionModule(crate::Event::Bid(0, ALICE, 200))); - assert_eq!(Balances::reserved_balance(ALICE), 200); + + // Move to the next block, test if auction keeps extending + run_to_block(97); + // Ensure another bid doesn't increase the end time + assert_ok!(AuctionModule::bid(bidder.clone(), 0, 201)); + assert_eq!(AuctionModule::auction_end_time(106, 0), Some(())); + assert_eq!(Balances::reserved_balance(ALICE), 201); + + run_to_block(107); + // Verify if auction finalized with new end time. + assert_eq!( + last_event(), + Event::AuctionModule(crate::Event::AuctionFinalized(0, 1, 201)) + ); }); } From 9d33c256fd44db244cd9889acca001bb771b7c97 Mon Sep 17 00:00:00 2001 From: Justin Date: Thu, 24 Nov 2022 13:41:24 +1300 Subject: [PATCH 11/17] Update cancel listing that allows only auction owner to have the permission. --- pallets/auction/src/lib.rs | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/pallets/auction/src/lib.rs b/pallets/auction/src/lib.rs index f83a49351..9d9e5bc15 100644 --- a/pallets/auction/src/lib.rs +++ b/pallets/auction/src/lib.rs @@ -604,21 +604,13 @@ pub mod pallet { /// /// The dispatch origin for this call must be _Root_. /// this call - /// - `from`: the listing owner who created this listing /// - `auction_id`: the auction id that wish to cancel /// /// Emits `AuctionCancelled` and `AuctionFinalizedNoBid` if successful. #[pallet::weight(T::WeightInfo::cancel_listing())] #[transactional] - pub fn cancel_listing( - origin: OriginFor, - from: T::AccountId, - auction_id: AuctionId, - ) -> DispatchResultWithPostInfo { - ensure!( - ensure_root(origin.clone()).is_ok() || ensure_signed(origin)? == from, - Error::::NoPermissionToCancelAuction - ); + pub fn cancel_listing(origin: OriginFor, auction_id: AuctionId) -> DispatchResultWithPostInfo { + let from = ensure_signed(origin)?; ensure!(Auctions::::contains_key(auction_id), Error::::AuctionDoesNotExist); let auction_item = AuctionItems::::get(auction_id).ok_or(Error::::AuctionDoesNotExist)?; From 0414f5fd80799116b02f0446daa45ebd0d43d9df Mon Sep 17 00:00:00 2001 From: Justin Date: Thu, 24 Nov 2022 14:03:50 +1300 Subject: [PATCH 12/17] Update unit test for cancel listing with new parameters --- pallets/auction/src/tests.rs | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/pallets/auction/src/tests.rs b/pallets/auction/src/tests.rs index 6e4224e74..5c19cd65b 100644 --- a/pallets/auction/src/tests.rs +++ b/pallets/auction/src/tests.rs @@ -1808,7 +1808,7 @@ fn cancel_listing_should_work() { ); run_to_block(2); - assert_ok!(AuctionModule::cancel_listing(Origin::signed(BOB), BOB, 0)); + assert_ok!(AuctionModule::cancel_listing(Origin::signed(BOB), 0)); assert_eq!(Balances::free_balance(BOB), 497); assert_eq!(AuctionModule::items_in_auction(ItemId::NFT(0, 0)), None); @@ -1841,32 +1841,13 @@ fn cancel_listing_should_fail() { run_to_block(10); assert_noop!( - AuctionModule::cancel_listing(Origin::signed(BOB), ALICE, 0), + AuctionModule::cancel_listing(Origin::signed(ALICE), 0), Error::::NoPermissionToCancelAuction ); assert_noop!( - AuctionModule::cancel_listing(Origin::signed(BOB), BOB, 1), + AuctionModule::cancel_listing(Origin::signed(BOB), 1), Error::::AuctionDoesNotExist ); - - assert_noop!( - AuctionModule::cancel_listing(Origin::root(), ALICE, 0), - Error::::NoPermissionToCancelAuction - ); - - assert_noop!( - AuctionModule::cancel_listing(Origin::signed(ALICE), ALICE, 0), - Error::::NoPermissionToCancelAuction - ); - - //assert_ok!(AuctionModule::bid(Origin::signed(ALICE.clone()), 0, 200)); - - //run_to_block(11); - - //assert_noop!( - // AuctionModule::cancel_listing(Origin::signed(BOB), BOB, 0), - // Error::::AuctionAlreadyStartedOrBid - //); }); } From a5aa8ccec1e25bec4d2edbcf6647e2f3f8a24c2c Mon Sep 17 00:00:00 2001 From: Justin Date: Thu, 24 Nov 2022 14:27:39 +1300 Subject: [PATCH 13/17] Deposit event for UI to handle when auction extended --- pallets/auction/src/lib.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pallets/auction/src/lib.rs b/pallets/auction/src/lib.rs index 9d9e5bc15..95b0a8181 100644 --- a/pallets/auction/src/lib.rs +++ b/pallets/auction/src/lib.rs @@ -280,6 +280,8 @@ pub mod pallet { NftOfferAccepted(ClassId, TokenId, T::AccountId), /// Nft offer is withdrawn [class_id, token_id, account_id] NftOfferWithdrawn(ClassId, TokenId, T::AccountId), + /// Auction extended. [auction_id, end_block] + AuctionExtended(AuctionId, T::BlockNumber), } /// Errors inform users that something went wrong. @@ -768,7 +770,7 @@ pub mod pallet { /// Emits `AuctionFinalized` or `AuctionFinalizedNoBid` if successful. #[pallet::weight(T::WeightInfo::on_finalize())] pub fn finalize_auction(origin: OriginFor, auction_id: AuctionId) -> DispatchResultWithPostInfo { - let who = ensure_signed(origin)?; + ensure_signed(origin)?; let auction = >::get(&auction_id).ok_or(Error::::AuctionDoesNotExist)?; ensure!( @@ -1166,6 +1168,7 @@ pub mod pallet { AuctionEndTime::::insert(new_auction_end, id, ()); // Update auction struct auction.end = Some(new_auction_end); + Self::deposit_event(Event::AuctionExtended(id, new_auction_end)); } auction.bid = Some((from.clone(), value)); From 666c7b7905ac12e955d2835d9fd0be532ac8c20b Mon Sep 17 00:00:00 2001 From: Justin Date: Thu, 24 Nov 2022 14:27:56 +1300 Subject: [PATCH 14/17] Include rust benchmarking on CI --- .github/workflows/rust-benchmark.yml | 40 ++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 .github/workflows/rust-benchmark.yml diff --git a/.github/workflows/rust-benchmark.yml b/.github/workflows/rust-benchmark.yml new file mode 100644 index 000000000..e52a07bf2 --- /dev/null +++ b/.github/workflows/rust-benchmark.yml @@ -0,0 +1,40 @@ +name: Metaverse Build Benchmarking + +on: + pull_request: + branches: + - master + push: + branches: + - master + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +jobs: + check: + # The type of runner that the job will run on + runs-on: ubuntu-20.04 + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v3 + + - name: Set-Up + run: sudo apt install -y cmake pkg-config libssl-dev git build-essential clang libclang-dev curl + + - name: Install Rustup + run: | + curl https://sh.rustup.rs -sSf | sh -s -- -y + source ~/.cargo/env + rustup default nightly && rustup update + rustup default nightly-2022-05-11 + rustup target add wasm32-unknown-unknown --toolchain nightly-2022-05-11 + - name: Check Rust version + run: rustup show + - name: Check Format + run: cargo fmt --all -- --check + - name: Build Benchmarking + run: | + SKIP_WASM_BUILD=1 cargo build --release --features runtime-benchmarks \ No newline at end of file From 1b2bc5464e955698c64262a473a43336da3ecaec Mon Sep 17 00:00:00 2001 From: Justin Date: Thu, 24 Nov 2022 14:50:39 +1300 Subject: [PATCH 15/17] Update new weight for new auction improvement --- pallets/auction/src/weights.rs | 58 ++++++++--------- runtime/metaverse/src/benchmarking/auction.rs | 26 ++++---- .../metaverse/src/weights/module_auction.rs | 62 +++++++++---------- 3 files changed, 73 insertions(+), 73 deletions(-) diff --git a/pallets/auction/src/weights.rs b/pallets/auction/src/weights.rs index ea5cddd0a..56e7e560b 100644 --- a/pallets/auction/src/weights.rs +++ b/pallets/auction/src/weights.rs @@ -18,23 +18,19 @@ //! Autogenerated weights for auction //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2022-11-23, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2022-11-24, STEPS: `20`, REPEAT: 10, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024 // Executed Command: // ./target/release/metaverse-node // benchmark // pallet +// --pallet=auction +// --extrinsic=* +// --steps=20 +// --repeat=10 // --execution=wasm // --wasm-execution=compiled -// --pallet -// auction -// --extrinsic -// * -// --steps -// 20 -// --repeat -// 10 // --template=./template/weight-template.hbs // --output // ./pallets/auction/src/weights.rs @@ -53,28 +49,28 @@ pub trait WeightInfo { fn create_new_auction() -> Weight; fn create_new_buy_now( /// Weights for auction using the for collator node and recommended hardware. pub struct SubstrateWeight(PhantomData); impl WeightInfo for SubstrateWeight { fn create_new_auction() -> Weight { - (51_004_000 as Weight) .saturating_add(T::DbWeight::get().reads(10 as Weight)) .saturating_add(T::DbWeight::get().writes(8 as Weight)) } fn create_new_buy_now() -> Weight { - (50_881_000 as Weight) .saturating_add(T::DbWeight::get().reads(10 as Weight)) .saturating_add(T::DbWeight::get().writes(8 as Weight)) } fn bid() -> Weight { - (37_231_000 as Weight) .saturating_add(T::DbWeight::get().reads(4 as Weight)) .saturating_add(T::DbWeight::get().writes(6 as Weight)) } fn buy_now() -> Weight { - (100_321_000 as Weight) .saturating_add(T::DbWeight::get().reads(13 as Weight)) .saturating_add(T::DbWeight::get().writes(13 as Weight)) } fn cancel_listing() -> Weight { - (39_602_000 as Weight) .saturating_add(T::DbWeight::get().reads(5 as Weight)) .saturating_add(T::DbWeight::get().writes(7 as Weight)) } fn authorise_metaverse_collection() -> Weight { - (15_958_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } fn remove_authorise_metaverse_collection() -> Weight { - (16_426_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } fn make_offer() -> Weight { - (30_306_000 as Weight) .saturating_add(T::DbWeight::get().reads(5 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } fn withdraw_offer() -> Weight { - (23_037_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } fn accept_offer() -> Weight { - (57_124_000 as Weight) .saturating_add(T::DbWeight::get().reads(7 as Weight)) .saturating_add(T::DbWeight::get().writes(7 as Weight)) } fn on_finalize() -> Weight { - (2_297_000 as Weight) }} + (50_000_000 as Weight) .saturating_add(T::DbWeight::get().reads(10 as Weight)) .saturating_add(T::DbWeight::get().writes(8 as Weight)) } fn create_new_buy_now() -> Weight { + (49_000_000 as Weight) .saturating_add(T::DbWeight::get().reads(10 as Weight)) .saturating_add(T::DbWeight::get().writes(8 as Weight)) } fn bid() -> Weight { + (38_000_000 as Weight) .saturating_add(T::DbWeight::get().reads(4 as Weight)) .saturating_add(T::DbWeight::get().writes(6 as Weight)) } fn buy_now() -> Weight { + (100_000_000 as Weight) .saturating_add(T::DbWeight::get().reads(13 as Weight)) .saturating_add(T::DbWeight::get().writes(13 as Weight)) } fn cancel_listing() -> Weight { + (38_000_000 as Weight) .saturating_add(T::DbWeight::get().reads(5 as Weight)) .saturating_add(T::DbWeight::get().writes(7 as Weight)) } fn authorise_metaverse_collection() -> Weight { + (16_000_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } fn remove_authorise_metaverse_collection() -> Weight { + (16_000_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } fn make_offer() -> Weight { + (30_000_000 as Weight) .saturating_add(T::DbWeight::get().reads(5 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } fn withdraw_offer() -> Weight { + (23_000_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } fn accept_offer() -> Weight { + (55_000_000 as Weight) .saturating_add(T::DbWeight::get().reads(7 as Weight)) .saturating_add(T::DbWeight::get().writes(7 as Weight)) } fn on_finalize() -> Weight { + (2_000_000 as Weight) }} // For backwards compatibility and tests impl WeightInfo for () { fn create_new_auction() -> Weight { - (51_004_000 as Weight) .saturating_add(RocksDbWeight::get().reads(10 as Weight)) .saturating_add(RocksDbWeight::get().writes(8 as Weight)) } fn create_new_buy_now() -> Weight { - (50_881_000 as Weight) .saturating_add(RocksDbWeight::get().reads(10 as Weight)) .saturating_add(RocksDbWeight::get().writes(8 as Weight)) } fn bid() -> Weight { - (37_231_000 as Weight) .saturating_add(RocksDbWeight::get().reads(4 as Weight)) .saturating_add(RocksDbWeight::get().writes(6 as Weight)) } fn buy_now() -> Weight { - (100_321_000 as Weight) .saturating_add(RocksDbWeight::get().reads(13 as Weight)) .saturating_add(RocksDbWeight::get().writes(13 as Weight)) } fn cancel_listing() -> Weight { - (39_602_000 as Weight) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) .saturating_add(RocksDbWeight::get().writes(7 as Weight)) } fn authorise_metaverse_collection() -> Weight { - (15_958_000 as Weight) .saturating_add(RocksDbWeight::get().reads(3 as Weight)) .saturating_add(RocksDbWeight::get().writes(2 as Weight)) } fn remove_authorise_metaverse_collection() -> Weight { - (16_426_000 as Weight) .saturating_add(RocksDbWeight::get().reads(3 as Weight)) .saturating_add(RocksDbWeight::get().writes(2 as Weight)) } fn make_offer() -> Weight { - (30_306_000 as Weight) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) .saturating_add(RocksDbWeight::get().writes(3 as Weight)) } fn withdraw_offer() -> Weight { - (23_037_000 as Weight) .saturating_add(RocksDbWeight::get().reads(3 as Weight)) .saturating_add(RocksDbWeight::get().writes(3 as Weight)) } fn accept_offer() -> Weight { - (57_124_000 as Weight) .saturating_add(RocksDbWeight::get().reads(7 as Weight)) .saturating_add(RocksDbWeight::get().writes(7 as Weight)) } fn on_finalize() -> Weight { - (2_297_000 as Weight) }} + (50_000_000 as Weight) .saturating_add(RocksDbWeight::get().reads(10 as Weight)) .saturating_add(RocksDbWeight::get().writes(8 as Weight)) } fn create_new_buy_now() -> Weight { + (49_000_000 as Weight) .saturating_add(RocksDbWeight::get().reads(10 as Weight)) .saturating_add(RocksDbWeight::get().writes(8 as Weight)) } fn bid() -> Weight { + (38_000_000 as Weight) .saturating_add(RocksDbWeight::get().reads(4 as Weight)) .saturating_add(RocksDbWeight::get().writes(6 as Weight)) } fn buy_now() -> Weight { + (100_000_000 as Weight) .saturating_add(RocksDbWeight::get().reads(13 as Weight)) .saturating_add(RocksDbWeight::get().writes(13 as Weight)) } fn cancel_listing() -> Weight { + (38_000_000 as Weight) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) .saturating_add(RocksDbWeight::get().writes(7 as Weight)) } fn authorise_metaverse_collection() -> Weight { + (16_000_000 as Weight) .saturating_add(RocksDbWeight::get().reads(3 as Weight)) .saturating_add(RocksDbWeight::get().writes(2 as Weight)) } fn remove_authorise_metaverse_collection() -> Weight { + (16_000_000 as Weight) .saturating_add(RocksDbWeight::get().reads(3 as Weight)) .saturating_add(RocksDbWeight::get().writes(2 as Weight)) } fn make_offer() -> Weight { + (30_000_000 as Weight) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) .saturating_add(RocksDbWeight::get().writes(3 as Weight)) } fn withdraw_offer() -> Weight { + (23_000_000 as Weight) .saturating_add(RocksDbWeight::get().reads(3 as Weight)) .saturating_add(RocksDbWeight::get().writes(3 as Weight)) } fn accept_offer() -> Weight { + (55_000_000 as Weight) .saturating_add(RocksDbWeight::get().reads(7 as Weight)) .saturating_add(RocksDbWeight::get().writes(7 as Weight)) } fn on_finalize() -> Weight { + (2_000_000 as Weight) }} diff --git a/runtime/metaverse/src/benchmarking/auction.rs b/runtime/metaverse/src/benchmarking/auction.rs index 34c7e8115..4373d1fcf 100644 --- a/runtime/metaverse/src/benchmarking/auction.rs +++ b/runtime/metaverse/src/benchmarking/auction.rs @@ -1,23 +1,27 @@ #![cfg(feature = "runtime-benchmarks")] -use super::utils::{ - create_nft_group, dollar, mint_NFT, set_balance, set_metaverse_treasury_initial_balance, test_attributes, -}; -use crate::{Auction, Balances, Call, Currencies, Event, Metaverse, MinimumAuctionDuration, Nft, Runtime, System}; -use auction::Config; -use auction_manager::{CheckAuctionItemHandler, ListingLevel}; -use core_primitives::{Attributes, CollectionType, MetaverseInfo, MetaverseTrait, NftMetadata, TokenType}; + use frame_benchmarking::{account, whitelisted_caller}; use frame_support::assert_ok; use frame_support::traits::{Currency, Get, OnFinalize, OnInitialize}; use frame_system::RawOrigin; use orml_benchmarking::runtime_benchmarks; -use primitives::{ - AccountId, FungibleTokenId, ItemId, UndeployedLandBlock, UndeployedLandBlockId, UndeployedLandBlockType, -}; use sp_runtime::traits::{AccountIdConversion, StaticLookup, UniqueSaturatedInto}; use sp_runtime::Perbill; use sp_std::{collections::btree_map::BTreeMap, prelude::*, vec}; +use auction::Config; +use auction_manager::{CheckAuctionItemHandler, ListingLevel}; +use core_primitives::{Attributes, CollectionType, MetaverseInfo, MetaverseTrait, NftMetadata, TokenType}; +use primitives::{ + AccountId, FungibleTokenId, ItemId, UndeployedLandBlock, UndeployedLandBlockId, UndeployedLandBlockType, +}; + +use crate::{Auction, Balances, Call, Currencies, Event, Metaverse, MinimumAuctionDuration, Nft, Runtime, System}; + +use super::utils::{ + create_nft_group, dollar, mint_NFT, set_balance, set_metaverse_treasury_initial_balance, test_attributes, +}; + //pub type AccountId = u128; pub type LandId = u64; pub type EstateId = u64; @@ -121,7 +125,7 @@ runtime_benchmarks! { next_block(); Auction::create_new_auction(RawOrigin::Signed(caller.clone()).into(), ItemId::NFT(0,0), dollar(1), 500u32.into(), ListingLevel::Local(METAVERSE_ID), MINING_CURRENCY_ID); next_block(); - }: _(RawOrigin::Signed(caller.clone()), caller.clone(), 0u32.into()) + }: _(RawOrigin::Signed(caller.clone()), 0u32.into()) authorise_metaverse_collection{ let alice: AccountId = account("alice", 0, SEED); diff --git a/runtime/metaverse/src/weights/module_auction.rs b/runtime/metaverse/src/weights/module_auction.rs index ef829327a..549b73b64 100644 --- a/runtime/metaverse/src/weights/module_auction.rs +++ b/runtime/metaverse/src/weights/module_auction.rs @@ -9,56 +9,56 @@ pub struct WeightInfo(PhantomData); impl auction::WeightInfo for WeightInfo { fn create_new_auction() -> Weight { - (51_004_000 as Weight) - .saturating_add(T::DbWeight::get().reads(10 as Weight)) - .saturating_add(T::DbWeight::get().writes(8 as Weight)) + (50_000_000 as Weight) + .saturating_add(DbWeight::get().reads(10 as Weight)) + .saturating_add(DbWeight::get().writes(8 as Weight)) } fn create_new_buy_now() -> Weight { - (50_881_000 as Weight) - .saturating_add(T::DbWeight::get().reads(10 as Weight)) - .saturating_add(T::DbWeight::get().writes(8 as Weight)) + (49_000_000 as Weight) + .saturating_add(DbWeight::get().reads(10 as Weight)) + .saturating_add(DbWeight::get().writes(8 as Weight)) } fn bid() -> Weight { - (37_231_000 as Weight) - .saturating_add(T::DbWeight::get().reads(4 as Weight)) - .saturating_add(T::DbWeight::get().writes(6 as Weight)) + (38_000_000 as Weight) + .saturating_add(DbWeight::get().reads(4 as Weight)) + .saturating_add(DbWeight::get().writes(6 as Weight)) } fn buy_now() -> Weight { - (100_321_000 as Weight) - .saturating_add(T::DbWeight::get().reads(13 as Weight)) - .saturating_add(T::DbWeight::get().writes(13 as Weight)) + (100_000_000 as Weight) + .saturating_add(DbWeight::get().reads(13 as Weight)) + .saturating_add(DbWeight::get().writes(13 as Weight)) } fn cancel_listing() -> Weight { - (39_602_000 as Weight) - .saturating_add(T::DbWeight::get().reads(5 as Weight)) - .saturating_add(T::DbWeight::get().writes(7 as Weight)) + (38_000_000 as Weight) + .saturating_add(DbWeight::get().reads(5 as Weight)) + .saturating_add(DbWeight::get().writes(7 as Weight)) } fn authorise_metaverse_collection() -> Weight { - (15_958_000 as Weight) - .saturating_add(T::DbWeight::get().reads(3 as Weight)) - .saturating_add(T::DbWeight::get().writes(2 as Weight)) + (16_000_000 as Weight) + .saturating_add(DbWeight::get().reads(3 as Weight)) + .saturating_add(DbWeight::get().writes(2 as Weight)) } fn remove_authorise_metaverse_collection() -> Weight { - (16_426_000 as Weight) - .saturating_add(T::DbWeight::get().reads(3 as Weight)) - .saturating_add(T::DbWeight::get().writes(2 as Weight)) + (16_000_000 as Weight) + .saturating_add(DbWeight::get().reads(3 as Weight)) + .saturating_add(DbWeight::get().writes(2 as Weight)) } fn make_offer() -> Weight { - (30_306_000 as Weight) - .saturating_add(T::DbWeight::get().reads(5 as Weight)) - .saturating_add(T::DbWeight::get().writes(3 as Weight)) + (30_000_000 as Weight) + .saturating_add(DbWeight::get().reads(5 as Weight)) + .saturating_add(DbWeight::get().writes(3 as Weight)) } fn withdraw_offer() -> Weight { - (23_037_000 as Weight) - .saturating_add(T::DbWeight::get().reads(3 as Weight)) - .saturating_add(T::DbWeight::get().writes(3 as Weight)) + (23_000_000 as Weight) + .saturating_add(DbWeight::get().reads(3 as Weight)) + .saturating_add(DbWeight::get().writes(3 as Weight)) } fn accept_offer() -> Weight { - (57_124_000 as Weight) - .saturating_add(T::DbWeight::get().reads(7 as Weight)) - .saturating_add(T::DbWeight::get().writes(7 as Weight)) + (55_000_000 as Weight) + .saturating_add(DbWeight::get().reads(7 as Weight)) + .saturating_add(DbWeight::get().writes(7 as Weight)) } fn on_finalize() -> Weight { - (2_297_000 as Weight) + (2_000_000 as Weight) } } From e5aefd20957d113bd683955a30db45b3faea7616 Mon Sep 17 00:00:00 2001 From: Justin Date: Thu, 24 Nov 2022 14:55:21 +1300 Subject: [PATCH 16/17] Add missing trait on DbWeight --- runtime/metaverse/src/lib.rs | 2 +- .../metaverse/src/weights/module_auction.rs | 40 +++++++++---------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/runtime/metaverse/src/lib.rs b/runtime/metaverse/src/lib.rs index 3df3ac84a..e497035b1 100644 --- a/runtime/metaverse/src/lib.rs +++ b/runtime/metaverse/src/lib.rs @@ -175,7 +175,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // `spec_version`, and `authoring_version` are the same between Wasm and native. // This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use // the compatible custom types. - spec_version: 47, + spec_version: 77, impl_version: 1, apis: RUNTIME_API_VERSIONS, transaction_version: 1, diff --git a/runtime/metaverse/src/weights/module_auction.rs b/runtime/metaverse/src/weights/module_auction.rs index 549b73b64..d0d46a37e 100644 --- a/runtime/metaverse/src/weights/module_auction.rs +++ b/runtime/metaverse/src/weights/module_auction.rs @@ -10,53 +10,53 @@ pub struct WeightInfo(PhantomData); impl auction::WeightInfo for WeightInfo { fn create_new_auction() -> Weight { (50_000_000 as Weight) - .saturating_add(DbWeight::get().reads(10 as Weight)) - .saturating_add(DbWeight::get().writes(8 as Weight)) + .saturating_add(T::DbWeight::get().reads(10 as Weight)) + .saturating_add(T::DbWeight::get().writes(8 as Weight)) } fn create_new_buy_now() -> Weight { (49_000_000 as Weight) - .saturating_add(DbWeight::get().reads(10 as Weight)) - .saturating_add(DbWeight::get().writes(8 as Weight)) + .saturating_add(T::DbWeight::get().reads(10 as Weight)) + .saturating_add(T::DbWeight::get().writes(8 as Weight)) } fn bid() -> Weight { (38_000_000 as Weight) - .saturating_add(DbWeight::get().reads(4 as Weight)) - .saturating_add(DbWeight::get().writes(6 as Weight)) + .saturating_add(T::DbWeight::get().reads(4 as Weight)) + .saturating_add(T::DbWeight::get().writes(6 as Weight)) } fn buy_now() -> Weight { (100_000_000 as Weight) - .saturating_add(DbWeight::get().reads(13 as Weight)) - .saturating_add(DbWeight::get().writes(13 as Weight)) + .saturating_add(T::DbWeight::get().reads(13 as Weight)) + .saturating_add(T::DbWeight::get().writes(13 as Weight)) } fn cancel_listing() -> Weight { (38_000_000 as Weight) - .saturating_add(DbWeight::get().reads(5 as Weight)) - .saturating_add(DbWeight::get().writes(7 as Weight)) + .saturating_add(T::DbWeight::get().reads(5 as Weight)) + .saturating_add(T::DbWeight::get().writes(7 as Weight)) } fn authorise_metaverse_collection() -> Weight { (16_000_000 as Weight) - .saturating_add(DbWeight::get().reads(3 as Weight)) - .saturating_add(DbWeight::get().writes(2 as Weight)) + .saturating_add(T::DbWeight::get().reads(3 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) } fn remove_authorise_metaverse_collection() -> Weight { (16_000_000 as Weight) - .saturating_add(DbWeight::get().reads(3 as Weight)) - .saturating_add(DbWeight::get().writes(2 as Weight)) + .saturating_add(T::DbWeight::get().reads(3 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) } fn make_offer() -> Weight { (30_000_000 as Weight) - .saturating_add(DbWeight::get().reads(5 as Weight)) - .saturating_add(DbWeight::get().writes(3 as Weight)) + .saturating_add(T::DbWeight::get().reads(5 as Weight)) + .saturating_add(T::DbWeight::get().writes(3 as Weight)) } fn withdraw_offer() -> Weight { (23_000_000 as Weight) - .saturating_add(DbWeight::get().reads(3 as Weight)) - .saturating_add(DbWeight::get().writes(3 as Weight)) + .saturating_add(T::DbWeight::get().reads(3 as Weight)) + .saturating_add(T::DbWeight::get().writes(3 as Weight)) } fn accept_offer() -> Weight { (55_000_000 as Weight) - .saturating_add(DbWeight::get().reads(7 as Weight)) - .saturating_add(DbWeight::get().writes(7 as Weight)) + .saturating_add(T::DbWeight::get().reads(7 as Weight)) + .saturating_add(T::DbWeight::get().writes(7 as Weight)) } fn on_finalize() -> Weight { (2_000_000 as Weight) From 6309a64679e84e400f715464bf10c29e1291a720 Mon Sep 17 00:00:00 2001 From: Justin Date: Thu, 24 Nov 2022 16:46:46 +1300 Subject: [PATCH 17/17] Bump metaverse version on testnet --- runtime/metaverse/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/metaverse/src/lib.rs b/runtime/metaverse/src/lib.rs index e497035b1..39bbeecc4 100644 --- a/runtime/metaverse/src/lib.rs +++ b/runtime/metaverse/src/lib.rs @@ -175,7 +175,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // `spec_version`, and `authoring_version` are the same between Wasm and native. // This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use // the compatible custom types. - spec_version: 77, + spec_version: 48, impl_version: 1, apis: RUNTIME_API_VERSIONS, transaction_version: 1,