From b4866a3e598c9e68e99bcb611355f41b167c7948 Mon Sep 17 00:00:00 2001 From: andy Date: Mon, 23 May 2022 15:02:04 +0000 Subject: [PATCH] fix tests --- tests/common.rs | 5 +- tests/test_item_pickup.rs | 1 + tests/test_shops.rs | 7 +++ tests/test_trade.rs | 32 ++++++++++++ tests/test_unseal_items.rs | 100 +++++++++++++++++++++++++++++-------- 5 files changed, 121 insertions(+), 24 deletions(-) diff --git a/tests/common.rs b/tests/common.rs index 6dbfc8a..0c6be23 100644 --- a/tests/common.rs +++ b/tests/common.rs @@ -47,10 +47,11 @@ pub async fn new_user_character_with_sid(entity_gateway: &mut let user = entity_gateway.create_user(new_user).await.unwrap(); let new_settings = NewUserSettingsEntity::new(user.id); let _settings = entity_gateway.create_user_settings(new_settings).await.unwrap(); - let mut new_character = NewCharacterEntity::new(user.id); + let mut new_character = NewCharacterEntity::new(user.id, 1); new_character.section_id = sid; let character = entity_gateway.create_character(new_character).await.unwrap(); - + entity_gateway.set_character_meseta(&character.id, Meseta(0)).await.unwrap(); + entity_gateway.set_bank_meseta(&character.id, BankName("".into()), Meseta(0)).await.unwrap(); (user, character) } diff --git a/tests/test_item_pickup.rs b/tests/test_item_pickup.rs index 2b18f86..41eba2d 100644 --- a/tests/test_item_pickup.rs +++ b/tests/test_item_pickup.rs @@ -27,6 +27,7 @@ async fn test_pick_up_individual_item() { special: None, attrs: [None, None, None], tekked: true, + kills: None, } ), }).await.unwrap()); diff --git a/tests/test_shops.rs b/tests/test_shops.rs index c4c4655..5b37766 100644 --- a/tests/test_shops.rs +++ b/tests/test_shops.rs @@ -274,6 +274,7 @@ async fn test_player_sells_3_attr_weapon_to_shop() { Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Dark, value: 100}), Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Native, value: 100}),], tekked: true, + kills: None, } ), }).await.unwrap()); @@ -635,6 +636,7 @@ async fn test_player_sells_untekked_weapon() { Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Dark, value: 100}), Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Native, value: 100}),], tekked: false, + kills: None, } ), }).await.unwrap()); @@ -679,6 +681,7 @@ async fn test_player_sells_rare_item() { Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Dark, value: 100}), Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Native, value: 100}),], tekked: true, + kills: None, } ), }).await.unwrap()); @@ -923,6 +926,7 @@ async fn test_player_sells_1_star_minusminus_unit() { item::unit::Unit { unit: item::unit::UnitType::PriestMind, modifier: Some(item::unit::UnitModifier::MinusMinus), + kills: None, } ), }).await.unwrap()); @@ -962,6 +966,7 @@ async fn test_player_sells_5_star_plusplus_unit() { item::unit::Unit { unit: item::unit::UnitType::GeneralHp, modifier: Some(item::unit::UnitModifier::PlusPlus), + kills: None, } ), }).await.unwrap()); @@ -1082,6 +1087,7 @@ async fn test_player_sells_rare_unit() { item::unit::Unit { unit: item::unit::UnitType::V101, modifier: None, + kills: None, } ), }).await.unwrap()); @@ -1122,6 +1128,7 @@ async fn test_player_cant_sell_if_meseta_would_go_over_max() { item::unit::Unit { unit: item::unit::UnitType::V101, modifier: None, + kills: None, } ), }).await.unwrap()); diff --git a/tests/test_trade.rs b/tests/test_trade.rs index 65505b3..949c40d 100644 --- a/tests/test_trade.rs +++ b/tests/test_trade.rs @@ -127,6 +127,7 @@ async fn test_trade_one_individual_item() { special: None, attrs: [None, None, None], tekked: true, + kills: None, } ), }).await.unwrap()); @@ -228,6 +229,7 @@ async fn test_trade_player2_to_player1() { special: None, attrs: [None, None, None], tekked: true, + kills: None, } ), }).await.unwrap()); @@ -329,6 +331,7 @@ async fn test_reverse_trade_ack_order() { special: None, attrs: [None, None, None], tekked: true, + kills: None, } ), }).await.unwrap()); @@ -641,6 +644,7 @@ async fn test_trade_individual_both() { special: None, attrs: [None, None, None], tekked: true, + kills: None, } ), }).await.unwrap()]; @@ -654,6 +658,7 @@ async fn test_trade_individual_both() { special: None, attrs: [None, None, None], tekked: true, + kills: None, } ), }).await.unwrap()]; @@ -1464,6 +1469,7 @@ async fn test_trade_individual_for_stacked() { special: None, attrs: [None, None, None], tekked: true, + kills: None, } ), }).await.unwrap()]; @@ -1634,6 +1640,7 @@ async fn test_trade_multiple_individual() { special: None, attrs: [None, None, None], tekked: true, + kills: None, } ), }).await.unwrap(), @@ -1646,6 +1653,7 @@ async fn test_trade_multiple_individual() { special: None, attrs: [None, None, None], tekked: true, + kills: None, } ), }).await.unwrap(), @@ -1660,6 +1668,7 @@ async fn test_trade_multiple_individual() { special: None, attrs: [None, None, None], tekked: true, + kills: None, } ), }).await.unwrap(), @@ -1672,6 +1681,7 @@ async fn test_trade_multiple_individual() { special: None, attrs: [None, None, None], tekked: true, + kills: None, } ), }).await.unwrap(), @@ -2161,6 +2171,7 @@ async fn test_trade_not_enough_inventory_space_individual() { special: None, attrs: [None, None, None], tekked: true, + kills: None, } ), } @@ -2183,6 +2194,7 @@ async fn test_trade_not_enough_inventory_space_individual() { special: None, attrs: [None, None, None], tekked: true, + kills: None, } ), } @@ -2300,6 +2312,7 @@ async fn test_trade_not_enough_inventory_space_stacked() { special: None, attrs: [None, None, None], tekked: true, + kills: None, } ), } @@ -2782,6 +2795,7 @@ async fn test_back_out_of_trade_last_minute() { special: None, attrs: [None, None, None], tekked: true, + kills: None, } ), }).await.unwrap()); @@ -2850,6 +2864,7 @@ async fn test_valid_trade_when_both_inventories_are_full() { special: None, attrs: [None, None, None], tekked: true, + kills: None, } ), } @@ -2872,6 +2887,7 @@ async fn test_valid_trade_when_both_inventories_are_full() { special: None, attrs: [None, None, None], tekked: true, + kills: None, } ), } @@ -2992,6 +3008,7 @@ async fn test_invalid_trade_when_both_inventories_are_full() { special: None, attrs: [None, None, None], tekked: true, + kills: None, } ), } @@ -3014,6 +3031,7 @@ async fn test_invalid_trade_when_both_inventories_are_full() { special: None, attrs: [None, None, None], tekked: true, + kills: None, } ), } @@ -3213,6 +3231,7 @@ async fn test_add_then_remove_individual_item() { special: None, attrs: [None, None, None], tekked: true, + kills: None, } ), }).await.unwrap()); @@ -3670,6 +3689,7 @@ async fn test_items_to_trade_data_does_not_match() { special: None, attrs: [None, None, None], tekked: true, + kills: None, } ), }).await.unwrap()); @@ -3715,6 +3735,7 @@ async fn test_items_to_trade_data_does_not_match() { special: None, attrs: [None, None, None], tekked: true, + kills: None, } )}); let titems = TradeItemBuilder::default() @@ -3753,6 +3774,7 @@ async fn test_items_to_trade_id_does_not_match() { special: None, attrs: [None, None, None], tekked: true, + kills: None, } ), }).await.unwrap()); @@ -3972,6 +3994,7 @@ async fn test_items_to_trade_count_less_than() { special: None, attrs: [None, None, None], tekked: true, + kills: None, } ), }).await.unwrap(), @@ -3984,6 +4007,7 @@ async fn test_items_to_trade_count_less_than() { special: None, attrs: [None, None, None], tekked: true, + kills: None, } ), }).await.unwrap(), @@ -3996,6 +4020,7 @@ async fn test_items_to_trade_count_less_than() { special: None, attrs: [None, None, None], tekked: true, + kills: None, } ), }).await.unwrap(), @@ -4076,6 +4101,7 @@ async fn test_items_to_trade_count_greater_than() { special: None, attrs: [None, None, None], tekked: true, + kills: None, } ), }).await.unwrap(), @@ -4088,6 +4114,7 @@ async fn test_items_to_trade_count_greater_than() { special: None, attrs: [None, None, None], tekked: true, + kills: None, } ), }).await.unwrap(), @@ -4100,6 +4127,7 @@ async fn test_items_to_trade_count_greater_than() { special: None, attrs: [None, None, None], tekked: true, + kills: None, } ), }).await.unwrap(), @@ -4184,6 +4212,7 @@ async fn test_items_to_trade_count_mismatch_with_meseta() { special: None, attrs: [None, None, None], tekked: true, + kills: None, } ), }).await.unwrap(), @@ -4196,6 +4225,7 @@ async fn test_items_to_trade_count_mismatch_with_meseta() { special: None, attrs: [None, None, None], tekked: true, + kills: None, } ), }).await.unwrap(), @@ -4208,6 +4238,7 @@ async fn test_items_to_trade_count_mismatch_with_meseta() { special: None, attrs: [None, None, None], tekked: true, + kills: None, } ), }).await.unwrap(), @@ -4286,6 +4317,7 @@ async fn test_dropping_item_after_trade() { special: None, attrs: [None, None, None], tekked: true, + kills: None, } ), }).await.unwrap()); diff --git a/tests/test_unseal_items.rs b/tests/test_unseal_items.rs index 238d203..654a670 100644 --- a/tests/test_unseal_items.rs +++ b/tests/test_unseal_items.rs @@ -10,12 +10,11 @@ use elseware::common::serverstate::{ClientId, ServerState}; use elseware::entity::gateway::{EntityGateway, InMemoryGateway}; -use elseware::entity::item; -use elseware::ship::ship::{ShipServerState, RecvShipPacket}; +use elseware::ship::ship::{ShipServerState, RecvShipPacket, SendShipPacket}; use elseware::entity::character::{SectionID}; use elseware::ship::room::{Difficulty}; -use elseware::ship::map::area::{MapArea}; use elseware::ship::monster::{MonsterType}; +use elseware::entity::item; use libpso::packet::ship::*; use libpso::packet::messages::*; @@ -27,7 +26,12 @@ use common::*; #[async_std::test] async fn test_item_drops_with_kill_counter() { let mut entity_gateway = InMemoryGateway::default(); - let (_user1, _char1) = new_user_character_with_sid(&mut entity_gateway, "a1", "a", SectionID::Skyly).await; + + let (_user1, mut char1) = new_user_character_with_sid(&mut entity_gateway, "a1", "a", SectionID::Skyly).await; + + char1.exp = 80000000; + entity_gateway.save_character(&char1).await.unwrap(); + let mut ship = Box::new(ShipServerState::builder() .gateway(entity_gateway.clone()) .build()); @@ -83,36 +87,88 @@ async fn test_item_drops_with_kill_counter() { let room = ship.blocks.0[0].rooms[0].as_mut().unwrap(); room.toggle_redbox_mode(); // enable redbox mode for sjs - println!("room redbox mode: {:?}", room.redbox); - println!("room.mode: {:?}", room.mode); - println!("killing gigue for sjs!"); + // println!("room redbox mode: {:?}", room.redbox); + // println!("room.mode: {:?}", room.mode); + // println!("killing gigue for sjs!"); let gigue_id = room.maps.get_enemy_id_by_monster_type(MonsterType::GiGue).unwrap(); - println!("found gigue id: {:?}!", gigue_id); - let pkts = ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::RequestItem(RequestItem { + // println!("found gigue id: {:?}!", gigue_id); + let packets = ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::RequestItem(RequestItem { client: 0, target: 0, map_area: 9, // seaside - pt_index: 55, // gigue ? + pt_index: 55, // gigue ? (taken from ingame logs) enemy_id: gigue_id, x: 0.0, y: 0.0, z: 0.0, - })))) - .await - .unwrap() - .collect::>(); // this should return 1 packet (ItemDrop)? - - println!("packets returned: {:?}", pkts); - assert!(false); + })))).await.unwrap().collect::>(); // this should return 1 packet (ItemDrop)? + + assert!(packets.len() == 1); + match &packets[0].1 { + SendShipPacket::Message(Message {msg: GameMessage::ItemDrop(item_drop)}) => { + assert_eq!(item_drop.item_bytes[10], 0x80) + } + _ => panic!("") + } } -// #[async_std::test] -// async fn test_all_equipped_kill_counters_increase_per_kill() { -// let mut entity_gateway = InMemoryGateway::default(); +#[async_std::test] +async fn test_all_equipped_kill_counters_increase_per_kill() { + let mut entity_gateway = InMemoryGateway::default(); -// let (_user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; -// } + let mut ship = Box::new(ShipServerState::builder() + .gateway(entity_gateway.clone()) + .build()); + + let mut p1_inv = Vec::new(); + p1_inv.push(entity_gateway.create_item( + item::NewItemEntity { + item: item::ItemDetail::Weapon( + item::weapon::Weapon { + weapon: item::weapon::WeaponType::SealedJSword, + grind: 0, + special: None, + attrs: [None, + None, + None,], + tekked: true, + kills: Some(0), + } + ), + }).await.unwrap()); + p1_inv.push(entity_gateway.create_item( + item::NewItemEntity { + item: item::ItemDetail::Unit( + item::unit::Unit { + unit: item::unit::UnitType::Limiter, + modifier: None, + kills: Some(0), + } + ), + }).await.unwrap()); + + let equipped = item::EquippedEntity { + weapon: Some(p1_inv[0].id), + armor: None, + shield: None, + unit: [Some(p1_inv[1].id), None, None, None], + mag: None, + }; + entity_gateway.set_character_equips(&char1.id, &equipped).await.unwrap(); + entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); + + + + + + log_in_char(&mut ship, ClientId(1), "a1", "a").await; + join_lobby(&mut ship, ClientId(1)).await; + create_room(&mut ship, ClientId(1), "room", "").await; + + +} // #[async_std::test] // async fn test_non_equipped_kill_counter_does_not_increase() {