|
@@ -1,5 +1,8 @@
|
|
|
#![cfg(test)]
|
|
|
-
|
|
|
+use crate::tests::fixtures::{
|
|
|
+ create_default_member_owned_channel_with_video, create_initial_storage_buckets_helper,
|
|
|
+ increase_account_balance_helper,
|
|
|
+};
|
|
|
use crate::tests::mock::*;
|
|
|
use crate::*;
|
|
|
use frame_support::{assert_err, assert_ok};
|
|
@@ -12,12 +15,14 @@ fn sell_nft() {
|
|
|
|
|
|
let video_id = NextVideoId::<Test>::get();
|
|
|
|
|
|
- create_simple_channel_and_video(FIRST_MEMBER_ORIGIN, FIRST_MEMBER_ID);
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_MEMBER_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ create_default_member_owned_channel_with_video();
|
|
|
|
|
|
// Issue nft
|
|
|
assert_ok!(Content::issue_nft(
|
|
|
- Origin::signed(FIRST_MEMBER_ORIGIN),
|
|
|
- ContentActor::Member(FIRST_MEMBER_ID),
|
|
|
+ Origin::signed(DEFAULT_MEMBER_ACCOUNT_ID),
|
|
|
+ ContentActor::Member(DEFAULT_MEMBER_ID),
|
|
|
video_id,
|
|
|
None,
|
|
|
b"metablob".to_vec(),
|
|
@@ -29,14 +34,12 @@ fn sell_nft() {
|
|
|
// Events number before tested calls
|
|
|
let number_of_events_before_call = System::events().len();
|
|
|
|
|
|
- let price = 100;
|
|
|
-
|
|
|
// Sell nft
|
|
|
assert_ok!(Content::sell_nft(
|
|
|
- Origin::signed(FIRST_MEMBER_ORIGIN),
|
|
|
+ Origin::signed(DEFAULT_MEMBER_ACCOUNT_ID),
|
|
|
video_id,
|
|
|
- ContentActor::Member(FIRST_MEMBER_ID),
|
|
|
- price,
|
|
|
+ ContentActor::Member(DEFAULT_MEMBER_ID),
|
|
|
+ DEFAULT_NFT_PRICE,
|
|
|
));
|
|
|
|
|
|
// Runtime tested state after call
|
|
@@ -49,17 +52,18 @@ fn sell_nft() {
|
|
|
cost,
|
|
|
),
|
|
|
..
|
|
|
- }) if price == cost
|
|
|
- ));
|
|
|
-
|
|
|
- let sell_order_made_event = get_test_event(RawEvent::NFTSellOrderMade(
|
|
|
- video_id,
|
|
|
- ContentActor::Member(FIRST_MEMBER_ID),
|
|
|
- price,
|
|
|
+ }) if DEFAULT_NFT_PRICE == cost
|
|
|
));
|
|
|
|
|
|
// Last event checked
|
|
|
- assert_event(sell_order_made_event, number_of_events_before_call + 1);
|
|
|
+ assert_event(
|
|
|
+ MetaEvent::content(RawEvent::NFTSellOrderMade(
|
|
|
+ video_id,
|
|
|
+ ContentActor::Member(DEFAULT_MEMBER_ID),
|
|
|
+ DEFAULT_NFT_PRICE,
|
|
|
+ )),
|
|
|
+ number_of_events_before_call + 1,
|
|
|
+ );
|
|
|
})
|
|
|
}
|
|
|
|
|
@@ -71,14 +75,12 @@ fn sell_nft_video_does_not_exist() {
|
|
|
|
|
|
let video_id = NextVideoId::<Test>::get();
|
|
|
|
|
|
- let price = 100;
|
|
|
-
|
|
|
// Make an attempt to sell nft which corresponding video does not exist yet
|
|
|
let sell_nft_result = Content::sell_nft(
|
|
|
- Origin::signed(FIRST_MEMBER_ORIGIN),
|
|
|
+ Origin::signed(DEFAULT_MEMBER_ACCOUNT_ID),
|
|
|
video_id,
|
|
|
- ContentActor::Member(FIRST_MEMBER_ID),
|
|
|
- price,
|
|
|
+ ContentActor::Member(DEFAULT_MEMBER_ID),
|
|
|
+ DEFAULT_NFT_PRICE,
|
|
|
);
|
|
|
|
|
|
// Failure checked
|
|
@@ -94,16 +96,16 @@ fn sell_nft_not_issued() {
|
|
|
|
|
|
let video_id = NextVideoId::<Test>::get();
|
|
|
|
|
|
- create_simple_channel_and_video(FIRST_MEMBER_ORIGIN, FIRST_MEMBER_ID);
|
|
|
-
|
|
|
- let price = 100;
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_MEMBER_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ create_default_member_owned_channel_with_video();
|
|
|
|
|
|
// Make an attempt to sell nft which is not issued yet
|
|
|
let sell_nft_result = Content::sell_nft(
|
|
|
- Origin::signed(FIRST_MEMBER_ORIGIN),
|
|
|
+ Origin::signed(DEFAULT_MEMBER_ACCOUNT_ID),
|
|
|
video_id,
|
|
|
- ContentActor::Member(FIRST_MEMBER_ID),
|
|
|
- price,
|
|
|
+ ContentActor::Member(DEFAULT_MEMBER_ID),
|
|
|
+ DEFAULT_NFT_PRICE,
|
|
|
);
|
|
|
|
|
|
// Failure checked
|
|
@@ -119,14 +121,14 @@ fn sell_nft_auth_failed() {
|
|
|
|
|
|
let video_id = NextVideoId::<Test>::get();
|
|
|
|
|
|
- create_simple_channel_and_video(FIRST_MEMBER_ORIGIN, FIRST_MEMBER_ID);
|
|
|
-
|
|
|
- let price = 100;
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_MEMBER_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ create_default_member_owned_channel_with_video();
|
|
|
|
|
|
// Issue nft
|
|
|
assert_ok!(Content::issue_nft(
|
|
|
- Origin::signed(FIRST_MEMBER_ORIGIN),
|
|
|
- ContentActor::Member(FIRST_MEMBER_ID),
|
|
|
+ Origin::signed(DEFAULT_MEMBER_ACCOUNT_ID),
|
|
|
+ ContentActor::Member(DEFAULT_MEMBER_ID),
|
|
|
video_id,
|
|
|
None,
|
|
|
b"metablob".to_vec(),
|
|
@@ -135,10 +137,10 @@ fn sell_nft_auth_failed() {
|
|
|
|
|
|
// Make an attempt to sell nft with wrong credentials
|
|
|
let sell_nft_result = Content::sell_nft(
|
|
|
- Origin::signed(FIRST_MEMBER_ORIGIN),
|
|
|
+ Origin::signed(UNAUTHORIZED_MEMBER_ACCOUNT_ID),
|
|
|
video_id,
|
|
|
- ContentActor::Member(UNKNOWN_ID),
|
|
|
- price,
|
|
|
+ ContentActor::Member(DEFAULT_MEMBER_ID),
|
|
|
+ DEFAULT_NFT_PRICE,
|
|
|
);
|
|
|
|
|
|
// Failure checked
|
|
@@ -154,26 +156,26 @@ fn sell_nft_not_authorized() {
|
|
|
|
|
|
let video_id = NextVideoId::<Test>::get();
|
|
|
|
|
|
- create_simple_channel_and_video(FIRST_MEMBER_ORIGIN, FIRST_MEMBER_ID);
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_MEMBER_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ create_default_member_owned_channel_with_video();
|
|
|
|
|
|
// Issue nft
|
|
|
assert_ok!(Content::issue_nft(
|
|
|
- Origin::signed(FIRST_MEMBER_ORIGIN),
|
|
|
- ContentActor::Member(FIRST_MEMBER_ID),
|
|
|
+ Origin::signed(DEFAULT_MEMBER_ACCOUNT_ID),
|
|
|
+ ContentActor::Member(DEFAULT_MEMBER_ID),
|
|
|
video_id,
|
|
|
None,
|
|
|
b"metablob".to_vec(),
|
|
|
None
|
|
|
));
|
|
|
|
|
|
- let price = 100;
|
|
|
-
|
|
|
// Make an attempt to sell nft if actor is not authorized
|
|
|
let sell_nft_result = Content::sell_nft(
|
|
|
- Origin::signed(FIRST_MEMBER_ORIGIN),
|
|
|
+ Origin::signed(UNAUTHORIZED_MEMBER_ACCOUNT_ID),
|
|
|
video_id,
|
|
|
- ContentActor::Member(SECOND_MEMBER_ID),
|
|
|
- price,
|
|
|
+ ContentActor::Member(UNAUTHORIZED_MEMBER_ID),
|
|
|
+ DEFAULT_NFT_PRICE,
|
|
|
);
|
|
|
|
|
|
// Failure checked
|
|
@@ -189,12 +191,14 @@ fn sell_nft_transactional_status_is_not_idle() {
|
|
|
|
|
|
let video_id = NextVideoId::<Test>::get();
|
|
|
|
|
|
- create_simple_channel_and_video(FIRST_MEMBER_ORIGIN, FIRST_MEMBER_ID);
|
|
|
+ create_initial_storage_buckets_helper();
|
|
|
+ increase_account_balance_helper(DEFAULT_MEMBER_ACCOUNT_ID, INITIAL_BALANCE);
|
|
|
+ create_default_member_owned_channel_with_video();
|
|
|
|
|
|
// Issue nft
|
|
|
assert_ok!(Content::issue_nft(
|
|
|
- Origin::signed(FIRST_MEMBER_ORIGIN),
|
|
|
- ContentActor::Member(FIRST_MEMBER_ID),
|
|
|
+ Origin::signed(DEFAULT_MEMBER_ACCOUNT_ID),
|
|
|
+ ContentActor::Member(DEFAULT_MEMBER_ID),
|
|
|
video_id,
|
|
|
None,
|
|
|
b"metablob".to_vec(),
|
|
@@ -203,21 +207,19 @@ fn sell_nft_transactional_status_is_not_idle() {
|
|
|
|
|
|
// Offer nft
|
|
|
assert_ok!(Content::offer_nft(
|
|
|
- Origin::signed(FIRST_MEMBER_ORIGIN),
|
|
|
+ Origin::signed(DEFAULT_MEMBER_ACCOUNT_ID),
|
|
|
video_id,
|
|
|
- ContentActor::Member(FIRST_MEMBER_ID),
|
|
|
+ ContentActor::Member(DEFAULT_MEMBER_ID),
|
|
|
SECOND_MEMBER_ID,
|
|
|
None,
|
|
|
));
|
|
|
|
|
|
- let price = 100;
|
|
|
-
|
|
|
// Make an attempt to sell nft when it is already offered
|
|
|
let sell_nft_result = Content::sell_nft(
|
|
|
- Origin::signed(FIRST_MEMBER_ORIGIN),
|
|
|
+ Origin::signed(DEFAULT_MEMBER_ACCOUNT_ID),
|
|
|
video_id,
|
|
|
- ContentActor::Member(FIRST_MEMBER_ID),
|
|
|
- price,
|
|
|
+ ContentActor::Member(DEFAULT_MEMBER_ID),
|
|
|
+ DEFAULT_NFT_PRICE,
|
|
|
);
|
|
|
|
|
|
// Failure checked
|