Skip to content

Commit

Permalink
[move-examples] cleanup testing
Browse files Browse the repository at this point in the history
* Looks like not everything was being tested
* Each test had a lot of boiler plate
* The marketplace examples had consts that broke general testing
  • Loading branch information
davidiw committed Dec 12, 2022
1 parent 209ac52 commit b3026da
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ module marketplace::marketplace_auction_example {
*simple_map::borrow(&auction.bids, &highest_price)
}

#[test(lister = @0xAF, bidder_a = @0xBB, bidder_b = @0xBA, framework = @0x1, house = @marketplace, fee_account = @0xa)]
#[test(lister = @marketplace, bidder_a = @0xBB, bidder_b = @0xBA, framework = @0x1, house = @marketplace, fee_account = @0xa)]
public fun test_listing_one_and_two_bids(
lister: signer,
bidder_a: signer,
Expand Down Expand Up @@ -561,7 +561,7 @@ module marketplace::marketplace_auction_example {
assert!(coin::balance<coin::FakeMoney>(signer::address_of(&lister)) == 297, 1);
}

#[test(lister = @0xAF, bidder_a = @0xBB, framework = @0x1, house = @marketplace)]
#[test(lister = @marketplace, bidder_a = @0xBB, framework = @0x1, house = @marketplace)]
public fun test_cancel_bid(
lister: signer,
bidder_a: signer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ module marketplace::marketplace_bid_utils {
assert!(coin::balance<coin::FakeMoney>(lister) == 9, 1);
}

#[test(owner = @0xAF, bidder_a = @0xBB, aptos_framework = @aptos_framework)]
#[test(owner = @marketplace, bidder_a = @0xBB, aptos_framework = @aptos_framework)]
#[expected_failure(abort_code = 1, location = marketplace::marketplace_bid_utils)]
public fun test_wrong_coin_amount(
owner: signer,
Expand All @@ -600,7 +600,7 @@ module marketplace::marketplace_bid_utils {
execute_listing_bid(bid_id, entry, @aptos_framework, 0, 1);
}

#[test(owner = @0xAF, bidder_a = @0xBB, aptos_framework = @aptos_framework)]
#[test(owner = @marketplace, bidder_a = @0xBB, aptos_framework = @aptos_framework)]
#[expected_failure(abort_code = 5, location = marketplace::marketplace_bid_utils)]
public fun test_wrong_token_amount(
owner: signer,
Expand All @@ -618,7 +618,7 @@ module marketplace::marketplace_bid_utils {
execute_listing_bid(bid_id, entry, @aptos_framework, 0, 1);
}

#[test(owner = @0xAF, bidder_a = @0xBB, aptos_framework = @aptos_framework)]
#[test(owner = @marketplace, bidder_a = @0xBB, aptos_framework = @aptos_framework)]
public fun test_increase_bid(
owner: signer,
bidder_a: signer,
Expand Down Expand Up @@ -685,7 +685,7 @@ module marketplace::marketplace_bid_utils {
(entry, token_id)
}

#[test(owner = @0xAF, buyer = @0xBB, framework = @aptos_framework, market = @0x33)]
#[test(owner = @marketplace, buyer = @0xBB, framework = @aptos_framework, market = @0x33)]
fun test_buy_successful(
owner: &signer,
buyer: &signer,
Expand Down Expand Up @@ -754,7 +754,7 @@ module marketplace::marketplace_bid_utils {
);
}

#[test(owner = @0xAF, bidder_a = @0xBB, framework = @aptos_framework, buyer = @0xee)]
#[test(owner = @marketplace, bidder_a = @0xBB, framework = @aptos_framework, buyer = @0xee)]
#[expected_failure(abort_code = 65546, location = marketplace::marketplace_bid_utils)]
fun test_buy_from_auction_listing(
owner: &signer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ module marketplace::marketplace_listing_utils {
}


#[test(owner = @0xAF)]
#[test(owner = @marketplace)]
public fun test_cancel_listing(owner: signer)acquires ListingRecords {
use aptos_framework::coin;

Expand Down
90 changes: 37 additions & 53 deletions aptos-move/move-examples/tests/move_unit_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,89 +54,73 @@ pub fn aptos_test_natives() -> NativeFunctionTable {
)
}

#[test]
fn test_data_structures() {
fn test_common(pkg: &str) {
let named_address = BTreeMap::from([(
String::from("data_structures"),
AccountAddress::from_hex_literal("0x1").unwrap(),
String::from(pkg),
AccountAddress::from_hex_literal("0xf00d").unwrap(),
)]);
run_tests_for_pkg("data_structures", named_address);
run_tests_for_pkg(pkg, named_address);
}

#[test]
fn test_hello_blockchain() {
fn test_resource_account_common(pkg: &str) {
let named_address = BTreeMap::from([(
String::from("hello_blockchain"),
AccountAddress::from_hex_literal("0x1").unwrap(),
String::from(pkg),
create_resource_address(AccountAddress::from_hex_literal("0xcafe").unwrap(), &[]),
)]);
run_tests_for_pkg("hello_blockchain", named_address);
run_tests_for_pkg(pkg, named_address);
}

#[test]
fn test_message_board() {
let named_address = BTreeMap::from([(
String::from("message_board"),
AccountAddress::from_hex_literal("0x1").unwrap(),
)]);
run_tests_for_pkg("message_board", named_address);
fn test_data_structures() {
test_common("data_structures");
}

#[test]
fn test_minter() {
let named_address = BTreeMap::new();
run_tests_for_pkg("scripts/minter", named_address);
fn test_defi() {
test_common("defi");
}

#[test]
fn test_two_by_two_transfer() {
let named_address = BTreeMap::new();
run_tests_for_pkg("scripts/two_by_two_transfer", named_address);
fn test_hello_blockchain() {
test_common("hello_blockchain");
}

#[test]
fn test_shared_account() {
let named_address = BTreeMap::from([(
String::from("shared_account"),
AccountAddress::from_hex_literal("0x1").unwrap(),
)]);
run_tests_for_pkg("shared_account", named_address);
fn test_marketplace() {
test_common("marketplace")
}

#[test]
fn test_message_board() {
test_common("message_board");
}

#[test]
fn test_mint_nft() {
let addr = AccountAddress::from_hex_literal("0xcafe").unwrap();
let named_address = BTreeMap::from([
(
String::from("mint_nft"),
create_resource_address(
AccountAddress::from_hex_literal("0xcafe").unwrap(),
vec![].as_slice(),
),
),
(
String::from("source_addr"),
AccountAddress::from_hex_literal("0xcafe").unwrap(),
),
(String::from("mint_nft"), create_resource_address(addr, &[])),
(String::from("source_addr"), addr),
]);
run_tests_for_pkg("mint_nft/4-Getting-Production-Ready", named_address);
}

#[test]
fn test_nft_auction_house() {
let named_address = BTreeMap::from([(
String::from("marketplace"),
AccountAddress::from_hex_literal("0xAF").unwrap(),
)]);
run_tests_for_pkg("marketplace", named_address);
fn test_minter() {
run_tests_for_pkg("scripts/minter", BTreeMap::new());
}

#[test]
fn test_resource_account() {
let named_address = BTreeMap::from([(
String::from("resource_account"),
create_resource_address(
AccountAddress::from_hex_literal("0xcafe").unwrap(),
vec![].as_slice(),
),
)]);
run_tests_for_pkg("resource_account", named_address);
test_resource_account_common("resource_account");
}

#[test]
fn test_shared_account() {
test_common("shared_account");
}

#[test]
fn test_two_by_two_transfer() {
run_tests_for_pkg("scripts/two_by_two_transfer", BTreeMap::new());
}

0 comments on commit b3026da

Please sign in to comment.