diff --git a/bytecodec/build.gradle.kts b/bytecodec/build.gradle.kts index 762b81e..7531756 100644 --- a/bytecodec/build.gradle.kts +++ b/bytecodec/build.gradle.kts @@ -4,4 +4,7 @@ plugins { id("buildsrc.convention.sonarlint") } -dependencies { testImplementation(libs.bundles.kotest) } +dependencies { + testImplementation(project(":common.test")) + testImplementation(libs.bundles.kotest) +} diff --git a/bytecodec/src/test/kotlin/de/fiereu/bytecodec/AtomsTest.kt b/bytecodec/src/test/kotlin/de/fiereu/bytecodec/AtomsTest.kt index 912a627..cdb5841 100644 --- a/bytecodec/src/test/kotlin/de/fiereu/bytecodec/AtomsTest.kt +++ b/bytecodec/src/test/kotlin/de/fiereu/bytecodec/AtomsTest.kt @@ -1,9 +1,9 @@ package de.fiereu.bytecodec -import de.fiereu.bytecodec.test.assertBytesRoundtrip -import de.fiereu.bytecodec.test.assertValueRoundtrip -import de.fiereu.bytecodec.test.decodeBytes -import de.fiereu.bytecodec.test.encodeToBytes +import de.fiereu.openmmo.common.test.assertBytesRoundtrip +import de.fiereu.openmmo.common.test.assertValueRoundtrip +import de.fiereu.openmmo.common.test.decodeBytes +import de.fiereu.openmmo.common.test.encodeToBytes import io.kotest.assertions.throwables.shouldThrow import io.kotest.core.spec.style.FunSpec import io.kotest.matchers.shouldBe diff --git a/bytecodec/src/test/kotlin/de/fiereu/bytecodec/CombinatorsTest.kt b/bytecodec/src/test/kotlin/de/fiereu/bytecodec/CombinatorsTest.kt index d2d44c8..a7e85fa 100644 --- a/bytecodec/src/test/kotlin/de/fiereu/bytecodec/CombinatorsTest.kt +++ b/bytecodec/src/test/kotlin/de/fiereu/bytecodec/CombinatorsTest.kt @@ -1,9 +1,9 @@ package de.fiereu.bytecodec -import de.fiereu.bytecodec.test.assertBytesRoundtrip -import de.fiereu.bytecodec.test.assertValueRoundtrip -import de.fiereu.bytecodec.test.decodeBytes -import de.fiereu.bytecodec.test.encodeToBytes +import de.fiereu.openmmo.common.test.assertBytesRoundtrip +import de.fiereu.openmmo.common.test.assertValueRoundtrip +import de.fiereu.openmmo.common.test.decodeBytes +import de.fiereu.openmmo.common.test.encodeToBytes import io.kotest.assertions.throwables.shouldThrow import io.kotest.core.spec.style.FunSpec import io.kotest.matchers.shouldBe diff --git a/bytecodec/src/test/kotlin/de/fiereu/bytecodec/PacketCodecTest.kt b/bytecodec/src/test/kotlin/de/fiereu/bytecodec/PacketCodecTest.kt index 67dae60..0fd08ff 100644 --- a/bytecodec/src/test/kotlin/de/fiereu/bytecodec/PacketCodecTest.kt +++ b/bytecodec/src/test/kotlin/de/fiereu/bytecodec/PacketCodecTest.kt @@ -1,8 +1,8 @@ package de.fiereu.bytecodec -import de.fiereu.bytecodec.test.assertBytesRoundtrip -import de.fiereu.bytecodec.test.assertValueRoundtrip -import de.fiereu.bytecodec.test.encodeToBytes +import de.fiereu.openmmo.common.test.assertBytesRoundtrip +import de.fiereu.openmmo.common.test.assertValueRoundtrip +import de.fiereu.openmmo.common.test.encodeToBytes import io.kotest.core.spec.style.FunSpec import io.kotest.matchers.shouldBe diff --git a/common.test/build.gradle.kts b/common.test/build.gradle.kts new file mode 100644 index 0000000..6527389 --- /dev/null +++ b/common.test/build.gradle.kts @@ -0,0 +1,13 @@ +plugins { + id("buildsrc.convention.kotlin-jvm") + id("buildsrc.convention.spotless") + id("buildsrc.convention.sonarlint") +} + +dependencies { + api(project(":bytecodec")) + api(project(":common")) + api(libs.bundles.kotest) + // Only DockerAvailable needs this, so consumers that never touch it stay clear of testcontainers. + compileOnly(libs.testcontainers.postgresql) +} diff --git a/server.game/src/test/kotlin/de/fiereu/openmmo/server/game/testsupport/DockerAvailable.kt b/common.test/src/main/kotlin/de/fiereu/openmmo/common/test/DockerAvailable.kt similarity index 89% rename from server.game/src/test/kotlin/de/fiereu/openmmo/server/game/testsupport/DockerAvailable.kt rename to common.test/src/main/kotlin/de/fiereu/openmmo/common/test/DockerAvailable.kt index 75e8caf..4b959fb 100644 --- a/server.game/src/test/kotlin/de/fiereu/openmmo/server/game/testsupport/DockerAvailable.kt +++ b/common.test/src/main/kotlin/de/fiereu/openmmo/common/test/DockerAvailable.kt @@ -1,4 +1,4 @@ -package de.fiereu.openmmo.server.game.testsupport +package de.fiereu.openmmo.common.test import io.kotest.core.annotation.Condition import io.kotest.core.spec.Spec diff --git a/common.test/src/main/kotlin/de/fiereu/openmmo/common/test/Fixtures.kt b/common.test/src/main/kotlin/de/fiereu/openmmo/common/test/Fixtures.kt new file mode 100644 index 0000000..02ae262 --- /dev/null +++ b/common.test/src/main/kotlin/de/fiereu/openmmo/common/test/Fixtures.kt @@ -0,0 +1,16 @@ +package de.fiereu.openmmo.common.test + +import de.fiereu.bytecodec.ByteArrayReadBuffer + +private object Fixtures + +/** + * Reads a captured payload from a module's `src/test/resources/fixtures`. The path is + * `///.bin` and the name ends in the client version the capture + * came from, when that is known. + */ +fun fixture(path: String): ByteArray = + Fixtures.javaClass.getResourceAsStream("/fixtures/$path")?.readBytes() + ?: error("no fixture at /fixtures/$path") + +fun fixtureBuffer(path: String): ByteArrayReadBuffer = ByteArrayReadBuffer(fixture(path)) diff --git a/bytecodec/src/main/kotlin/de/fiereu/bytecodec/test/TestHelpers.kt b/common.test/src/main/kotlin/de/fiereu/openmmo/common/test/TestHelpers.kt similarity index 90% rename from bytecodec/src/main/kotlin/de/fiereu/bytecodec/test/TestHelpers.kt rename to common.test/src/main/kotlin/de/fiereu/openmmo/common/test/TestHelpers.kt index c4b9d84..16be363 100644 --- a/bytecodec/src/main/kotlin/de/fiereu/bytecodec/test/TestHelpers.kt +++ b/common.test/src/main/kotlin/de/fiereu/openmmo/common/test/TestHelpers.kt @@ -1,8 +1,9 @@ -package de.fiereu.bytecodec.test +package de.fiereu.openmmo.common.test import de.fiereu.bytecodec.ByteArrayReadBuffer import de.fiereu.bytecodec.Codec import de.fiereu.bytecodec.GrowableWriteBuffer +import de.fiereu.openmmo.common.utils.toHex private fun contentEqual(a: Any?, b: Any?): Boolean = when { @@ -43,5 +44,3 @@ fun Codec.assertBytesRoundtrip(bytes: ByteArray) { ) } } - -private fun ByteArray.toHex(): String = joinToString("") { "%02x".format(it.toInt() and 0xFF) } diff --git a/network/build.gradle.kts b/network/build.gradle.kts index 2e5b43a..07a1920 100644 --- a/network/build.gradle.kts +++ b/network/build.gradle.kts @@ -9,6 +9,7 @@ dependencies { api(libs.netty) api(libs.kotlinx.coroutines) implementation(libs.kotlin.logging) + testImplementation(project(":common.test")) testImplementation(libs.bundles.kotest) testImplementation(libs.kotlinx.coroutines.test) testRuntimeOnly(libs.logback) diff --git a/network/src/test/kotlin/de/fiereu/network/handshake/HandshakeCodecsTest.kt b/network/src/test/kotlin/de/fiereu/network/handshake/HandshakeCodecsTest.kt index 645568a..7403100 100644 --- a/network/src/test/kotlin/de/fiereu/network/handshake/HandshakeCodecsTest.kt +++ b/network/src/test/kotlin/de/fiereu/network/handshake/HandshakeCodecsTest.kt @@ -1,8 +1,8 @@ package de.fiereu.network.handshake -import de.fiereu.bytecodec.test.assertValueRoundtrip -import de.fiereu.bytecodec.test.decodeBytes -import de.fiereu.bytecodec.test.encodeToBytes +import de.fiereu.openmmo.common.test.assertValueRoundtrip +import de.fiereu.openmmo.common.test.decodeBytes +import de.fiereu.openmmo.common.test.encodeToBytes import io.kotest.core.spec.style.FunSpec import io.kotest.matchers.shouldBe import java.security.interfaces.ECPublicKey diff --git a/protocols.game/build.gradle.kts b/protocols.game/build.gradle.kts index 34fd19f..3cabd62 100644 --- a/protocols.game/build.gradle.kts +++ b/protocols.game/build.gradle.kts @@ -7,5 +7,6 @@ plugins { dependencies { api(project(":network")) api(project(":common")) + testImplementation(project(":common.test")) testImplementation(libs.bundles.kotest) } diff --git a/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/BattleActionSelectPacketTest.kt b/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/BattleActionSelectPacketTest.kt index da44b07..0992fd1 100644 --- a/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/BattleActionSelectPacketTest.kt +++ b/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/BattleActionSelectPacketTest.kt @@ -1,8 +1,9 @@ package de.fiereu.openmmo.net.game -import de.fiereu.bytecodec.test.decodeBytes -import de.fiereu.bytecodec.test.encodeToBytes import de.fiereu.openmmo.common.enums.BattleAction +import de.fiereu.openmmo.common.test.decodeBytes +import de.fiereu.openmmo.common.test.encodeToBytes +import de.fiereu.openmmo.common.test.fixture import de.fiereu.openmmo.net.game.packets.battle.BattleActionSelectPacket import de.fiereu.openmmo.net.game.packets.battle.BattleActionSelectPacketCodec import io.kotest.core.spec.style.FunSpec @@ -11,7 +12,7 @@ import io.kotest.matchers.shouldBe class BattleActionSelectPacketTest : FunSpec({ test("decodes a captured move selection") { - val bytes = byteArrayOf(0x00, 0x00, 0x2B, 0x00, 0x00) + val bytes = fixture("game/c2s/32/move_selection.bin") val decoded = BattleActionSelectPacketCodec.decodeBytes(bytes) decoded shouldBe BattleActionSelectPacket( @@ -25,21 +26,7 @@ class BattleActionSelectPacketTest : } test("decodes a captured item throw") { - val bytes = - byteArrayOf( - 0x00, - 0x01, - 0x8C.toByte(), - 0x13, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0xFF.toByte()) + val bytes = fixture("game/c2s/32/item_throw.bin") val decoded = BattleActionSelectPacketCodec.decodeBytes(bytes) decoded shouldBe BattleActionSelectPacket( @@ -53,7 +40,7 @@ class BattleActionSelectPacketTest : } test("decodes a run selection with no tail") { - val bytes = byteArrayOf(0x00, 0x03) + val bytes = fixture("game/c2s/32/run.bin") val decoded = BattleActionSelectPacketCodec.decodeBytes(bytes) decoded shouldBe BattleActionSelectPacket( @@ -67,7 +54,7 @@ class BattleActionSelectPacketTest : } test("decodes a captured switch to a party index") { - val bytes = byteArrayOf(0x00, 0x02, 0x01, 0x00) + val bytes = fixture("game/c2s/32/switch.bin") val decoded = BattleActionSelectPacketCodec.decodeBytes(bytes) decoded shouldBe BattleActionSelectPacket( diff --git a/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/BattleEntityMoveEventPacketTest.kt b/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/BattleEntityMoveEventPacketTest.kt index 8aacc30..e0ecaf9 100644 --- a/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/BattleEntityMoveEventPacketTest.kt +++ b/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/BattleEntityMoveEventPacketTest.kt @@ -1,7 +1,7 @@ package de.fiereu.openmmo.net.game -import de.fiereu.bytecodec.test.decodeBytes -import de.fiereu.bytecodec.test.encodeToBytes +import de.fiereu.openmmo.common.test.decodeBytes +import de.fiereu.openmmo.common.test.encodeToBytes import de.fiereu.openmmo.net.game.packets.battle.BattleActionEvent import de.fiereu.openmmo.net.game.packets.battle.BattleEffectTarget import de.fiereu.openmmo.net.game.packets.battle.BattleEntityMoveEventPacket diff --git a/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/BattleFieldStatePacketTest.kt b/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/BattleFieldStatePacketTest.kt index 3aa8ed2..25d9f36 100644 --- a/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/BattleFieldStatePacketTest.kt +++ b/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/BattleFieldStatePacketTest.kt @@ -1,22 +1,18 @@ package de.fiereu.openmmo.net.game -import de.fiereu.bytecodec.test.decodeBytes -import de.fiereu.bytecodec.test.encodeToBytes +import de.fiereu.openmmo.common.test.decodeBytes +import de.fiereu.openmmo.common.test.encodeToBytes +import de.fiereu.openmmo.common.test.fixture import de.fiereu.openmmo.net.game.packets.battle.BattleFieldStatePacket import de.fiereu.openmmo.net.game.packets.battle.BattleFieldStatePacketCodec import de.fiereu.openmmo.net.game.packets.battle.BattleMonBlock import io.kotest.core.spec.style.FunSpec import io.kotest.matchers.shouldBe -import java.util.Base64 - -// A two-monster party wild encounter (Snivy active, Patrat benched), scrubbed of capture data. -private const val CAPTURED_TWO_PARTY = - "AgAAAAAAAAAAAAAAAP8AAAAAABYAAAD/ACAABlQAZQBzAHQAAAAAAJABAAAAAAD/AAJMAxqsDwADgAGkAAQAAAAAAAECAAABAMABAAAAAADvAQYAAAAAAAAWABYAAAAA/wMBQQAhACsAAAAAAAABAQDAAgAAAAAA+AECAAABAAAADgAOAAAAAP8DATIAIQAAAAAAAAABAADvAQYAAAAAAAAD/wAAAABmZmZmAQYAAAAAAAEBAAABAMADAAAAAAD4AQIAAAEAAAAOAA4AAAAA/wMAAQAA+AECAAAAAAEAA/8AAAAAZmZmZgAAAAA=" class BattleFieldStatePacketTest : FunSpec({ test("round-trips a two-party wild field state byte for byte") { - val bytes = Base64.getDecoder().decode(CAPTURED_TWO_PARTY) + val bytes = fixture("game/s2c/30/wild_two_party_scrubbed.bin") val decoded = BattleFieldStatePacketCodec.decodeBytes(bytes) decoded.playerName shouldBe "Test" decoded.playerParty.size shouldBe 2 @@ -25,7 +21,7 @@ class BattleFieldStatePacketTest : } test("decodes the structured mon fields from the capture") { - val bytes = Base64.getDecoder().decode(CAPTURED_TWO_PARTY) + val bytes = fixture("game/s2c/30/wild_two_party_scrubbed.bin") val decoded = BattleFieldStatePacketCodec.decodeBytes(bytes) val snivy = decoded.playerParty[0] diff --git a/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/BattleSwitchInPacketTest.kt b/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/BattleSwitchInPacketTest.kt index 00cc2ac..9398765 100644 --- a/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/BattleSwitchInPacketTest.kt +++ b/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/BattleSwitchInPacketTest.kt @@ -1,7 +1,8 @@ package de.fiereu.openmmo.net.game -import de.fiereu.bytecodec.test.decodeBytes -import de.fiereu.bytecodec.test.encodeToBytes +import de.fiereu.openmmo.common.test.decodeBytes +import de.fiereu.openmmo.common.test.encodeToBytes +import de.fiereu.openmmo.common.test.fixture import de.fiereu.openmmo.common.utils.toHex import de.fiereu.openmmo.net.game.packets.battle.BattleMonBlock import de.fiereu.openmmo.net.game.packets.battle.BattleSwitchInPacket @@ -48,7 +49,7 @@ class BattleSwitchInPacketTest : fullBlock = false, ) val bytes = BattleSwitchInPacketCodec.encodeToBytes(packet) - bytes.toHex() shouldBe "000000010000ef010600000000000003ff0000000066666666" + bytes.toHex() shouldBe fixture("game/s2c/35/return_switch_in.bin").toHex() } // A benched monster coming out carries its full block then its active detail. The block diff --git a/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/CharactersListPacketTest.kt b/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/CharactersListPacketTest.kt index 91a0a62..0625a04 100644 --- a/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/CharactersListPacketTest.kt +++ b/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/CharactersListPacketTest.kt @@ -1,8 +1,7 @@ package de.fiereu.openmmo.net.game -import de.fiereu.bytecodec.ByteArrayReadBuffer import de.fiereu.bytecodec.U8 -import de.fiereu.openmmo.common.utils.hexToBytes +import de.fiereu.openmmo.common.test.fixtureBuffer import de.fiereu.openmmo.net.game.codecs.CharacterInfoCodecShort import de.fiereu.openmmo.net.game.codecs.DefaultSkinSetCodec import de.fiereu.openmmo.net.game.codecs.PokemonCodec @@ -10,28 +9,10 @@ import de.fiereu.openmmo.net.game.codecs.SkinSetCodecNoLeading import io.kotest.core.spec.style.FunSpec import io.kotest.matchers.shouldBe -/** A captured character list. Only the second character has a party, and the third one after it. */ -private const val CAPTURED_LIST_32710 = - "03009008849CEFC41A4D0061006300680065007200520069006E0000000000DA02220101280A696A0C0A696A00000000" + - "001900000000000000000000000000200001000000000000000000FFFFFFFF0000000000000000000000000200040100" + - "06000600020000000000FF0000000000004C030BB80E0003180030029C00000000009088C41C56091861007300740072" + - "0069006400650066006F007500720000000000DA02220100EFCD646A36A69C670000000000B05303007C010000000000" + - "00000020005C005C030000028D0100028D01000000000000000000000002FF02028E010009000D00000100000000FF00" + - "00000000024C031AAC0F00038001A400040000000100C008522BEDAF1A0000009088C41C560918009088C41C56091801" + - "0000EF01BA707DDB009088C41C560918610073007400720069006400650066006F007500720000000000000007180000" + - "002801000000430021002B0016000000231E19000000000000000000000500000100000000000000040502FFFFFFFF03" + - "00EFBDF71E00000020000000000000008686536A0000FFFF00000090882BE6F6C01A4D00610063006800650072004400" + - "6500720000000000DA022201002CF9646AEFF8646A00000000003B0000000000000000000000000020003D0002000000" + - "0133000201330002000000000000000000000100020133010003000200020100000000FF0000000000034C031E280A00" + - "02540070002000000000" - class CharactersListPacketTest : FunSpec({ test("a captured client 32710 character list is consumed to the last byte") { - val bytes = CAPTURED_LIST_32710.hexToBytes() - bytes.size shouldBe 538 - - val buf = ByteArrayReadBuffer(bytes) + val buf = fixtureBuffer("game/s2c/02/character_list_32710.bin") val names = mutableListOf() val parties = mutableListOf() repeat(U8.read(buf)) { @@ -51,15 +32,8 @@ class CharactersListPacketTest : } test("a captured client 32710 monster record is consumed to the last byte") { - // One SocialListEntryAdd payload, which is a bare monster record. - val bytes = - ("00C0885FCC11CB1A00000090484E2A11CB1A0090484E2A11CB1A0100000400184204670090484E2A11CB1A4D00610063" + - "006800520052000000000000000513000000870000000032000A002D0021003400232823190000000000000000000000" + - "000000000000000000580500FFFFFFFF0300EFBDF71E0000002000000000000000EB516F6A0000FFFF0000") - .hexToBytes() - bytes.size shouldBe 139 - - val buf = ByteArrayReadBuffer(bytes) + // A SocialListEntryAdd payload, which is a bare monster record. + val buf = fixtureBuffer("game/s2c/14/monster_record_32710.bin") val mon = PokemonCodec.read(buf) mon.dexId shouldBe 4 diff --git a/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/CreateCharacterPacketTest.kt b/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/CreateCharacterPacketTest.kt index 61b55da..bd288a7 100644 --- a/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/CreateCharacterPacketTest.kt +++ b/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/CreateCharacterPacketTest.kt @@ -1,9 +1,9 @@ package de.fiereu.openmmo.net.game -import de.fiereu.bytecodec.test.decodeBytes -import de.fiereu.bytecodec.test.encodeToBytes import de.fiereu.openmmo.common.enums.SkinSlot -import de.fiereu.openmmo.common.utils.hexToBytes +import de.fiereu.openmmo.common.test.decodeBytes +import de.fiereu.openmmo.common.test.encodeToBytes +import de.fiereu.openmmo.common.test.fixture import de.fiereu.openmmo.common.utils.toHex import de.fiereu.openmmo.net.game.packets.CreateCharacterPacketCodec import io.kotest.core.spec.style.FunSpec @@ -12,9 +12,7 @@ import io.kotest.matchers.shouldBe class CreateCharacterPacketTest : FunSpec({ test("decodes the captured female Hoenn character creation") { - val bytes = - "4c0061006e0061006e0061005400650073007400540077006f0000000101014c0304600f00030800680084" - .hexToBytes() + val bytes = fixture("game/c2s/03/female_hoenn.bin") val packet = CreateCharacterPacketCodec.decodeBytes(bytes) @@ -33,8 +31,7 @@ class CreateCharacterPacketTest : } test("roundtrips the new male Hoenn character creation capture") { - val bytes = - "4d006100630068006500720044006500720000000001034c031e280a00025400700020".hexToBytes() + val bytes = fixture("game/c2s/03/male_hoenn_32710.bin") val packet = CreateCharacterPacketCodec.decodeBytes(bytes) @@ -46,8 +43,7 @@ class CreateCharacterPacketTest : } test("roundtrips the independent female Kanto character creation capture") { - val bytes = - "4d0061006300680065007200520069006e0000000100004c030bb80e0003180030029c".hexToBytes() + val bytes = fixture("game/c2s/03/female_kanto_32710.bin") val packet = CreateCharacterPacketCodec.decodeBytes(bytes) diff --git a/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/DialogActionPacketTest.kt b/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/DialogActionPacketTest.kt index 731226f..8dd07aa 100644 --- a/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/DialogActionPacketTest.kt +++ b/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/DialogActionPacketTest.kt @@ -1,8 +1,8 @@ package de.fiereu.openmmo.net.game -import de.fiereu.bytecodec.test.decodeBytes -import de.fiereu.bytecodec.test.encodeToBytes -import de.fiereu.openmmo.common.utils.hexToBytes +import de.fiereu.openmmo.common.test.decodeBytes +import de.fiereu.openmmo.common.test.encodeToBytes +import de.fiereu.openmmo.common.test.fixture import de.fiereu.openmmo.common.utils.toHex import de.fiereu.openmmo.net.game.packets.dialog.CreatureDataArg import de.fiereu.openmmo.net.game.packets.dialog.DialogActionPacketCodec @@ -12,26 +12,25 @@ import io.kotest.matchers.shouldBe class DialogActionPacketTest : FunSpec({ - // Every case is a real 0x21 dialog action from the NPC interaction capture. val captures = listOf( - "0c2e0d00b52903e008bf86c4c01ab004000000", - "006400000000ffffffffffffffff0000000000", - "0e04f90600010ae008bf86c4c01ab004000000", - "0d04f80600010ae008bf86c4c01ab004000001000992d00300", + "flags_0c_type_2e", + "flags_00_type_64", + "flags_0e_type_04", + "creature_arg", + "species_arg", ) test("round-trips every captured dialog action byte for byte") { - captures.forEach { hex -> - val packet = DialogActionPacketCodec.decodeBytes(hex.hexToBytes()) - DialogActionPacketCodec.encodeToBytes(packet).toHex() shouldBe hex + captures.forEach { name -> + val bytes = fixture("game/s2c/21/$name.bin") + val packet = DialogActionPacketCodec.decodeBytes(bytes) + DialogActionPacketCodec.encodeToBytes(packet).toHex() shouldBe bytes.toHex() } } test("decodes the fields of a dialog action carrying a creature arg") { - val packet = - DialogActionPacketCodec.decodeBytes( - "0d04f80600010ae008bf86c4c01ab004000001000992d00300".hexToBytes()) + val packet = DialogActionPacketCodec.decodeBytes(fixture("game/s2c/21/creature_arg.bin")) packet.flags shouldBe 0x0d.toByte() packet.actionType shouldBe 0x04.toByte() packet.textId shouldBe 0x010006f8 @@ -41,7 +40,7 @@ class DialogActionPacketTest : } test("species-name argument uses the captured party slot variable and species order") { - val bytes = "000400000000ffffffffffffffff0000000001020101ff0000".hexToBytes() + val bytes = fixture("game/s2c/21/species_arg.bin") val packet = DialogActionPacketCodec.decodeBytes(bytes) packet.messageArgs shouldBe listOf(TextPokemonSpeciesArg(1, 1, 255)) diff --git a/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/DialogActionResponsePacketTest.kt b/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/DialogActionResponsePacketTest.kt index 972f494..32f0511 100644 --- a/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/DialogActionResponsePacketTest.kt +++ b/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/DialogActionResponsePacketTest.kt @@ -1,7 +1,8 @@ package de.fiereu.openmmo.net.game -import de.fiereu.bytecodec.test.decodeBytes -import de.fiereu.bytecodec.test.encodeToBytes +import de.fiereu.openmmo.common.test.decodeBytes +import de.fiereu.openmmo.common.test.encodeToBytes +import de.fiereu.openmmo.common.test.fixture import de.fiereu.openmmo.net.game.packets.dialog.DialogActionResponsePacket import de.fiereu.openmmo.net.game.packets.dialog.DialogActionResponsePacketCodec import io.kotest.core.spec.style.FunSpec @@ -9,10 +10,9 @@ import io.kotest.matchers.shouldBe class DialogActionResponsePacketTest : FunSpec({ - // The client replies to a 0x21 dialog action with the action id and a response byte. This is - // the "0c 00" the capture sends back after the "0c" dialog action. + // The client replies to a 0x21 dialog action with the action id and a response byte. test("round-trips the captured dialog reply") { - val bytes = byteArrayOf(0x0c, 0x00) + val bytes = fixture("game/c2s/21/dialog_reply.bin") val packet = DialogActionResponsePacketCodec.decodeBytes(bytes) packet shouldBe DialogActionResponsePacket(id = 0x0c, unk = 0) DialogActionResponsePacketCodec.encodeToBytes(packet) shouldBe bytes diff --git a/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/Fixtures.kt b/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/Fixtures.kt deleted file mode 100644 index 4049d11..0000000 --- a/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/Fixtures.kt +++ /dev/null @@ -1,15 +0,0 @@ -package de.fiereu.openmmo.net.game - -import de.fiereu.bytecodec.ByteArrayReadBuffer - -private object Fixtures - -/** - * Reads a captured payload from `src/test/resources/fixtures`. The path is - * `///.bin` and the name ends in the client version the capture - * came from. - */ -fun fixture(path: String): ByteArrayReadBuffer = - ByteArrayReadBuffer( - Fixtures.javaClass.getResourceAsStream("/fixtures/$path")?.readBytes() - ?: error("no fixture at /fixtures/$path")) diff --git a/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/FriendListPacketTest.kt b/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/FriendListPacketTest.kt index b46ab45..edd72e2 100644 --- a/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/FriendListPacketTest.kt +++ b/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/FriendListPacketTest.kt @@ -1,7 +1,7 @@ package de.fiereu.openmmo.net.game -import de.fiereu.bytecodec.test.decodeBytes -import de.fiereu.bytecodec.test.encodeToBytes +import de.fiereu.openmmo.common.test.decodeBytes +import de.fiereu.openmmo.common.test.encodeToBytes import de.fiereu.openmmo.net.game.packets.FriendListEntry import de.fiereu.openmmo.net.game.packets.FriendListPacket import de.fiereu.openmmo.net.game.packets.FriendListPacketCodec diff --git a/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/GameCodecRoundtripTest.kt b/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/GameCodecRoundtripTest.kt index b457880..0c6adc4 100644 --- a/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/GameCodecRoundtripTest.kt +++ b/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/GameCodecRoundtripTest.kt @@ -1,8 +1,8 @@ package de.fiereu.openmmo.net.game -import de.fiereu.bytecodec.test.decodeBytes -import de.fiereu.bytecodec.test.encodeToBytes import de.fiereu.openmmo.common.enums.Direction +import de.fiereu.openmmo.common.test.decodeBytes +import de.fiereu.openmmo.common.test.encodeToBytes import de.fiereu.openmmo.net.game.packets.DialogStatePacket import de.fiereu.openmmo.net.game.packets.DialogStatePacketCodec import de.fiereu.openmmo.net.game.packets.EntityLeavePacket diff --git a/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/GtlListingsPagePacketTest.kt b/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/GtlListingsPagePacketTest.kt index 34eb1de..b44b4cc 100644 --- a/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/GtlListingsPagePacketTest.kt +++ b/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/GtlListingsPagePacketTest.kt @@ -1,5 +1,6 @@ package de.fiereu.openmmo.net.game +import de.fiereu.openmmo.common.test.fixtureBuffer import de.fiereu.openmmo.net.game.packets.gtl.GtlListKind import de.fiereu.openmmo.net.game.packets.gtl.GtlListingsPagePacketCodec import de.fiereu.openmmo.net.game.packets.gtl.GtlListingsPageRequestPacketCodec @@ -9,7 +10,7 @@ import io.kotest.matchers.shouldBe class GtlListingsPagePacketTest : FunSpec({ test("a captured price list request round trips") { - val buf = fixture("game/c2s/e4/price_list_request_31914.bin") + val buf = fixtureBuffer("game/c2s/e4/price_list_request_31914.bin") val request = GtlListingsPageRequestPacketCodec.read(buf) request.requestId shouldBe 3.toByte() @@ -20,7 +21,7 @@ class GtlListingsPagePacketTest : } test("a captured price list page is consumed to the last byte") { - val buf = fixture("game/s2c/fe/price_history_32710.bin") + val buf = fixtureBuffer("game/s2c/fe/price_history_32710.bin") val page = GtlListingsPagePacketCodec.read(buf) page.requestId shouldBe 1.toByte() @@ -35,7 +36,7 @@ class GtlListingsPagePacketTest : } test("a later price list page reports which page it answers") { - val buf = fixture("game/s2c/fe/price_history_page2_31914.bin") + val buf = fixtureBuffer("game/s2c/fe/price_history_page2_31914.bin") val page = GtlListingsPagePacketCodec.read(buf) page.requestId shouldBe 3.toByte() diff --git a/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/GtlMarketListingsPacketTest.kt b/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/GtlMarketListingsPacketTest.kt index 77be79f..2df5968 100644 --- a/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/GtlMarketListingsPacketTest.kt +++ b/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/GtlMarketListingsPacketTest.kt @@ -1,6 +1,7 @@ package de.fiereu.openmmo.net.game import de.fiereu.bytecodec.ByteArrayReadBuffer +import de.fiereu.openmmo.common.test.fixtureBuffer import de.fiereu.openmmo.net.game.packets.gtl.GtlMarketListingsPacketCodec import de.fiereu.openmmo.net.game.packets.gtl.GtlMarketListingsRequestPacketCodec import io.kotest.core.spec.style.FunSpec @@ -15,7 +16,7 @@ class GtlMarketListingsPacketTest : } test("a captured board page is consumed to the last byte") { - val buf = fixture("game/s2c/70/board_page_31914.bin") + val buf = fixtureBuffer("game/s2c/70/board_page_31914.bin") val board = GtlMarketListingsPacketCodec.read(buf) board.fullReset shouldBe false diff --git a/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/GtlOpenSessionPacketTest.kt b/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/GtlOpenSessionPacketTest.kt index 584630e..581a243 100644 --- a/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/GtlOpenSessionPacketTest.kt +++ b/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/GtlOpenSessionPacketTest.kt @@ -1,7 +1,6 @@ package de.fiereu.openmmo.net.game -import de.fiereu.bytecodec.ByteArrayReadBuffer -import de.fiereu.openmmo.common.utils.hexToBytes +import de.fiereu.openmmo.common.test.fixtureBuffer import de.fiereu.openmmo.net.game.packets.CategoryFlagsPacketCodec import de.fiereu.openmmo.net.game.packets.gtl.GtlOpenSessionPacketCodec import io.kotest.core.spec.style.FunSpec @@ -10,21 +9,19 @@ import io.kotest.matchers.shouldBe class GtlOpenSessionPacketTest : FunSpec({ test("the first open carries no timestamp") { - val buf = fixture("game/c2s/a5/open_session_first_31914.bin") + val buf = fixtureBuffer("game/c2s/a5/open_session_first_31914.bin") GtlOpenSessionPacketCodec.read(buf).sessionTimestamp shouldBe 0L buf.remaining() shouldBe 0 } test("the next open echoes the timestamp the server just sent") { - // The flag bytes are opaque, so only the header comes from the capture. - val flagBytes = ("01" + "85C2F6559E010000" + "3603" + "00".repeat(822)).hexToBytes() - val flagBuf = ByteArrayReadBuffer(flagBytes) + val flagBuf = fixtureBuffer("game/s2c/dc/category_flags_31914.bin") val flags = CategoryFlagsPacketCodec.read(flagBuf) flags.entryKind shouldBe 1 flags.flagBits.size shouldBe 822 flagBuf.remaining() shouldBe 0 - val reopen = fixture("game/c2s/a5/open_session_reopen_31914.bin") + val reopen = fixtureBuffer("game/c2s/a5/open_session_reopen_31914.bin") GtlOpenSessionPacketCodec.read(reopen).sessionTimestamp shouldBe flags.timestampMillis reopen.remaining() shouldBe 0 } diff --git a/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/GtlSearchPagePacketTest.kt b/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/GtlSearchPagePacketTest.kt index 115a919..cef9afc 100644 --- a/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/GtlSearchPagePacketTest.kt +++ b/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/GtlSearchPagePacketTest.kt @@ -1,5 +1,6 @@ package de.fiereu.openmmo.net.game +import de.fiereu.openmmo.common.test.fixtureBuffer import de.fiereu.openmmo.net.game.packets.gtl.GtlItemListing import de.fiereu.openmmo.net.game.packets.gtl.GtlListKind import de.fiereu.openmmo.net.game.packets.gtl.GtlPokemonListing @@ -10,7 +11,7 @@ import io.kotest.matchers.shouldBe class GtlSearchPagePacketTest : FunSpec({ test("a captured item page is consumed to the last byte") { - val buf = fixture("game/s2c/9b/item_page_32710.bin") + val buf = fixtureBuffer("game/s2c/9b/item_page_32710.bin") val page = GtlSearchPagePacketCodec.read(buf) page.requestId shouldBe 7.toByte() @@ -30,7 +31,7 @@ class GtlSearchPagePacketTest : } test("a captured monster page is consumed to the last byte") { - val buf = fixture("game/s2c/9b/monster_page_32710.bin") + val buf = fixtureBuffer("game/s2c/9b/monster_page_32710.bin") val page = GtlSearchPagePacketCodec.read(buf) page.requestId shouldBe 1.toByte() @@ -53,7 +54,7 @@ class GtlSearchPagePacketTest : } test("a page that is not an item board carries no quote strip") { - val buf = fixture("game/s2c/9b/own_listings_page_31914.bin") + val buf = fixtureBuffer("game/s2c/9b/own_listings_page_31914.bin") val page = GtlSearchPagePacketCodec.read(buf) page.listKind shouldBe GtlListKind.OWN_LISTINGS diff --git a/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/GtlSearchPageRequestPacketTest.kt b/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/GtlSearchPageRequestPacketTest.kt index 25031a6..802336f 100644 --- a/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/GtlSearchPageRequestPacketTest.kt +++ b/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/GtlSearchPageRequestPacketTest.kt @@ -1,5 +1,6 @@ package de.fiereu.openmmo.net.game +import de.fiereu.openmmo.common.test.fixtureBuffer import de.fiereu.openmmo.net.game.packets.gtl.GtlFilterKind import de.fiereu.openmmo.net.game.packets.gtl.GtlListKind import de.fiereu.openmmo.net.game.packets.gtl.GtlSearchPageRequestPacketCodec @@ -10,7 +11,7 @@ import io.kotest.matchers.shouldBe class GtlSearchPageRequestPacketTest : FunSpec({ test("an unfiltered search carries no filters") { - val buf = fixture("game/c2s/9b/own_listings_request_31914.bin") + val buf = fixtureBuffer("game/c2s/9b/own_listings_request_31914.bin") val request = GtlSearchPageRequestPacketCodec.read(buf) request.requestId shouldBe 3.toByte() @@ -22,7 +23,7 @@ class GtlSearchPageRequestPacketTest : } test("a search filtered to one species carries its dex id") { - val buf = fixture("game/c2s/9b/one_species_filter_32710.bin") + val buf = fixtureBuffer("game/c2s/9b/one_species_filter_32710.bin") val request = GtlSearchPageRequestPacketCodec.read(buf) request.requestId shouldBe 4.toByte() @@ -31,7 +32,7 @@ class GtlSearchPageRequestPacketTest : } test("a search filtered to thirteen species carries all of them") { - val buf = fixture("game/c2s/9b/thirteen_species_filter_32710.bin") + val buf = fixtureBuffer("game/c2s/9b/thirteen_species_filter_32710.bin") val request = GtlSearchPageRequestPacketCodec.read(buf) request.listKind shouldBe GtlListKind.ITEM @@ -42,7 +43,7 @@ class GtlSearchPageRequestPacketTest : } test("a filtered search carries one entry per filter") { - val buf = fixture("game/c2s/9b/eleven_filters_32710.bin") + val buf = fixtureBuffer("game/c2s/9b/eleven_filters_32710.bin") val request = GtlSearchPageRequestPacketCodec.read(buf) request.filters.size shouldBe 11 diff --git a/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/GtlTradeLogRequestPacketTest.kt b/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/GtlTradeLogRequestPacketTest.kt index 3228a3b..6a4b757 100644 --- a/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/GtlTradeLogRequestPacketTest.kt +++ b/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/GtlTradeLogRequestPacketTest.kt @@ -1,6 +1,7 @@ package de.fiereu.openmmo.net.game import de.fiereu.bytecodec.ByteArrayReadBuffer +import de.fiereu.openmmo.common.test.fixtureBuffer import de.fiereu.openmmo.net.game.packets.SceneObjectStatesPacketCodec import de.fiereu.openmmo.net.game.packets.gtl.GtlTradeLogRequestPacketCodec import io.kotest.core.spec.style.FunSpec @@ -13,7 +14,7 @@ class GtlTradeLogRequestPacketTest : GtlTradeLogRequestPacketCodec.read(request) request.remaining() shouldBe 0 - val reply = fixture("game/s2c/5e/empty_trade_log_31914.bin") + val reply = fixtureBuffer("game/s2c/5e/empty_trade_log_31914.bin") SceneObjectStatesPacketCodec.read(reply).objects shouldBe emptyList() reply.remaining() shouldBe 0 } diff --git a/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/GuildMembershipPacketTest.kt b/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/GuildMembershipPacketTest.kt index a9509bd..2ef4732 100644 --- a/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/GuildMembershipPacketTest.kt +++ b/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/GuildMembershipPacketTest.kt @@ -1,7 +1,7 @@ package de.fiereu.openmmo.net.game -import de.fiereu.bytecodec.test.decodeBytes -import de.fiereu.bytecodec.test.encodeToBytes +import de.fiereu.openmmo.common.test.decodeBytes +import de.fiereu.openmmo.common.test.encodeToBytes import de.fiereu.openmmo.net.game.packets.guild.GuildMembershipPacket import de.fiereu.openmmo.net.game.packets.guild.GuildMembershipPacketCodec import de.fiereu.openmmo.net.game.packets.guild.GuildProfileData diff --git a/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/GuildRankPermissionUpdatePacketTest.kt b/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/GuildRankPermissionUpdatePacketTest.kt index 8ac364f..6a0db14 100644 --- a/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/GuildRankPermissionUpdatePacketTest.kt +++ b/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/GuildRankPermissionUpdatePacketTest.kt @@ -1,9 +1,9 @@ package de.fiereu.openmmo.net.game -import de.fiereu.bytecodec.test.decodeBytes -import de.fiereu.bytecodec.test.encodeToBytes import de.fiereu.openmmo.common.enums.GuildPermission import de.fiereu.openmmo.common.enums.GuildRank +import de.fiereu.openmmo.common.test.decodeBytes +import de.fiereu.openmmo.common.test.encodeToBytes import de.fiereu.openmmo.net.game.packets.guild.GuildRankPermissionUpdatePacket import de.fiereu.openmmo.net.game.packets.guild.GuildRankPermissionUpdatePacketCodec import io.kotest.core.spec.style.FunSpec diff --git a/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/MoveLearnPacketsTest.kt b/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/MoveLearnPacketsTest.kt index d20718b..6a98c29 100644 --- a/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/MoveLearnPacketsTest.kt +++ b/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/MoveLearnPacketsTest.kt @@ -1,7 +1,8 @@ package de.fiereu.openmmo.net.game -import de.fiereu.bytecodec.test.decodeBytes -import de.fiereu.bytecodec.test.encodeToBytes +import de.fiereu.openmmo.common.test.decodeBytes +import de.fiereu.openmmo.common.test.encodeToBytes +import de.fiereu.openmmo.common.test.fixture import de.fiereu.openmmo.net.game.packets.battle.moves.MoveLearnPromptPacket import de.fiereu.openmmo.net.game.packets.battle.moves.MoveLearnPromptPacketCodec import de.fiereu.openmmo.net.game.packets.battle.moves.MoveLearnReplyPacket @@ -16,21 +17,17 @@ private const val WATER_GUN: Short = 55 private const val LEER: Short = 43 private const val UNOVA_MOVE: Short = 526 -private fun entityIdBytes() = - byteArrayOf( - 0x00, 0xC0.toByte(), 0xC8.toByte(), 0x2A, 0xEF.toByte(), 0xAD.toByte(), 0xCE.toByte(), 0x1A) - class MoveLearnPacketsTest : FunSpec({ test("decodes a captured prompt for one move") { - val bytes = entityIdBytes() + byteArrayOf(0x01, 0x9A.toByte(), 0x00) + val bytes = fixture("game/s2c/17/prompt_one_move_32710.bin") val decoded = MoveLearnPromptPacketCodec.decodeBytes(bytes) decoded shouldBe MoveLearnPromptPacket(ENTITY_ID, listOf(FURY_SWIPES)) MoveLearnPromptPacketCodec.encodeToBytes(decoded) shouldBe bytes } test("decodes a captured prompt for two moves") { - val bytes = entityIdBytes() + byteArrayOf(0x02, 0x18, 0x02, 0x59, 0x01) + val bytes = fixture("game/s2c/17/prompt_two_moves_32710.bin") val decoded = MoveLearnPromptPacketCodec.decodeBytes(bytes) decoded shouldBe MoveLearnPromptPacket(ENTITY_ID, listOf(536, 345)) MoveLearnPromptPacketCodec.encodeToBytes(decoded) shouldBe bytes @@ -38,21 +35,7 @@ class MoveLearnPacketsTest : // Fury Swipes took the slot Leer held. test("decodes a captured reply that swapped a move in") { - val bytes = - entityIdBytes() + - byteArrayOf( - 0x04, - 0x0E, - 0x02, - 0x9A.toByte(), - 0x00, - 0x7A, - 0x00, - 0x37, - 0x00, - 0x01, - 0x9A.toByte(), - 0x00) + val bytes = fixture("game/c2s/0a/reply_swapped_32710.bin") val decoded = MoveLearnReplyPacketCodec.decodeBytes(bytes) decoded shouldBe MoveLearnReplyPacket( @@ -65,10 +48,7 @@ class MoveLearnPacketsTest : // The moveset comes back as it was, so the player kept Leer. test("decodes a captured reply that declined") { - val bytes = - entityIdBytes() + - byteArrayOf( - 0x04, 0x0E, 0x02, 0x2B, 0x00, 0x7A, 0x00, 0x37, 0x00, 0x01, 0x9A.toByte(), 0x00) + val bytes = fixture("game/c2s/0a/reply_declined_32710.bin") val decoded = MoveLearnReplyPacketCodec.decodeBytes(bytes) decoded shouldBe MoveLearnReplyPacket( diff --git a/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/PokemonContainerPacketTest.kt b/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/PokemonContainerPacketTest.kt index 6e5faf4..04fe700 100644 --- a/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/PokemonContainerPacketTest.kt +++ b/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/PokemonContainerPacketTest.kt @@ -1,19 +1,19 @@ package de.fiereu.openmmo.net.game -import de.fiereu.bytecodec.test.decodeBytes -import de.fiereu.bytecodec.test.encodeToBytes import de.fiereu.openmmo.common.Pokemon import de.fiereu.openmmo.common.PokemonMove import de.fiereu.openmmo.common.enums.EVs import de.fiereu.openmmo.common.enums.IVs import de.fiereu.openmmo.common.enums.PokemonContainer +import de.fiereu.openmmo.common.test.decodeBytes +import de.fiereu.openmmo.common.test.encodeToBytes +import de.fiereu.openmmo.common.test.fixture import de.fiereu.openmmo.net.game.codecs.PokemonCodec import de.fiereu.openmmo.net.game.packets.PokemonContainerPacket import de.fiereu.openmmo.net.game.packets.PokemonContainerPacketCodec import io.kotest.core.spec.style.FunSpec import io.kotest.matchers.shouldBe import java.time.LocalDateTime -import java.util.Base64 private fun testMon(id: Long, dex: Int, slot: Short) = Pokemon( @@ -40,13 +40,10 @@ private fun testMon(id: Long, dex: Int, slot: Short) = caughtAt = LocalDateTime.of(2026, 1, 1, 0, 0, 0), ) -private const val CAPTURED_PARTY = - "AQEBAMABAAAAAAAAAACQAQAAAAAAAJABAAAAAAABAADvAbpwfdsAkAEAAAAAAFQAZQBzAHQAAAAAAAAABRQAAAClAAAAADIAIQArAAAAAAAjHgAAAAAAAAAAAAAAAAAAAQAAAAAAAAAEBQL/////AwDvvfceAAAAIAAAAAAAAACGhlNqAAD//wAA" - class PokemonContainerPacketTest : FunSpec({ test("round-trips a captured party container and exposes the monster fields") { - val bytes = Base64.getDecoder().decode(CAPTURED_PARTY) + val bytes = bytes() val decoded = PokemonContainerPacketCodec.decodeBytes(bytes) val mon = decoded.pokemon.single() mon.dexId shouldBe 495 @@ -125,4 +122,4 @@ class PokemonContainerPacketTest : } }) -private fun bytes(): ByteArray = Base64.getDecoder().decode(CAPTURED_PARTY) +private fun bytes(): ByteArray = fixture("game/s2c/13/party_scrubbed.bin") diff --git a/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/codecs/CharacterInfoCodecTest.kt b/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/codecs/CharacterInfoCodecTest.kt index d5ab2a9..9cf17cf 100644 --- a/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/codecs/CharacterInfoCodecTest.kt +++ b/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/codecs/CharacterInfoCodecTest.kt @@ -1,8 +1,8 @@ package de.fiereu.openmmo.net.game.codecs -import de.fiereu.bytecodec.test.decodeBytes -import de.fiereu.bytecodec.test.encodeToBytes import de.fiereu.openmmo.common.CharacterInfo +import de.fiereu.openmmo.common.test.decodeBytes +import de.fiereu.openmmo.common.test.encodeToBytes import io.kotest.core.spec.style.FunSpec import io.kotest.matchers.shouldBe import java.time.LocalDateTime diff --git a/protocols.game/src/test/resources/fixtures/README.md b/protocols.game/src/test/resources/fixtures/README.md index cf40392..49d7fc9 100644 --- a/protocols.game/src/test/resources/fixtures/README.md +++ b/protocols.game/src/test/resources/fixtures/README.md @@ -4,11 +4,16 @@ Raw packet payloads from real captures, one file per packet. ///_.bin -Packet id is lowercase hex without a prefix. The version matters: the wire format changes between -clients. +Packet id is lowercase hex without a prefix. The version matters, the wire format changes between +clients, so carry it whenever the capture can be traced back to a session. A few older payloads +predate that rule and have no suffix. `_scrubbed` means player data was replaced before the payload +was committed, so it no longer matches anything in the archive. + +`fixture` gives you the bytes, `fixtureBuffer` wraps them for a codec that reads from a buffer. Both +live in the `common.test` module. ```kotlin -val buf = fixture("game/s2c/9b/monster_page_32710.bin") +val buf = fixtureBuffer("game/s2c/9b/monster_page_32710.bin") GtlSearchPagePacketCodec.read(buf) buf.remaining() shouldBe 0 ``` diff --git a/protocols.game/src/test/resources/fixtures/game/c2s/03/female_hoenn.bin b/protocols.game/src/test/resources/fixtures/game/c2s/03/female_hoenn.bin new file mode 100644 index 0000000..8fe20f0 Binary files /dev/null and b/protocols.game/src/test/resources/fixtures/game/c2s/03/female_hoenn.bin differ diff --git a/protocols.game/src/test/resources/fixtures/game/c2s/03/female_kanto_32710.bin b/protocols.game/src/test/resources/fixtures/game/c2s/03/female_kanto_32710.bin new file mode 100644 index 0000000..edb9ebd Binary files /dev/null and b/protocols.game/src/test/resources/fixtures/game/c2s/03/female_kanto_32710.bin differ diff --git a/protocols.game/src/test/resources/fixtures/game/c2s/03/male_hoenn_32710.bin b/protocols.game/src/test/resources/fixtures/game/c2s/03/male_hoenn_32710.bin new file mode 100644 index 0000000..0cf1b10 Binary files /dev/null and b/protocols.game/src/test/resources/fixtures/game/c2s/03/male_hoenn_32710.bin differ diff --git a/protocols.game/src/test/resources/fixtures/game/c2s/0a/reply_declined_32710.bin b/protocols.game/src/test/resources/fixtures/game/c2s/0a/reply_declined_32710.bin new file mode 100644 index 0000000..5c8157a Binary files /dev/null and b/protocols.game/src/test/resources/fixtures/game/c2s/0a/reply_declined_32710.bin differ diff --git a/protocols.game/src/test/resources/fixtures/game/c2s/0a/reply_swapped_32710.bin b/protocols.game/src/test/resources/fixtures/game/c2s/0a/reply_swapped_32710.bin new file mode 100644 index 0000000..44ca181 Binary files /dev/null and b/protocols.game/src/test/resources/fixtures/game/c2s/0a/reply_swapped_32710.bin differ diff --git a/protocols.game/src/test/resources/fixtures/game/c2s/21/dialog_reply.bin b/protocols.game/src/test/resources/fixtures/game/c2s/21/dialog_reply.bin new file mode 100644 index 0000000..e0868eb Binary files /dev/null and b/protocols.game/src/test/resources/fixtures/game/c2s/21/dialog_reply.bin differ diff --git a/protocols.game/src/test/resources/fixtures/game/c2s/32/item_throw.bin b/protocols.game/src/test/resources/fixtures/game/c2s/32/item_throw.bin new file mode 100644 index 0000000..28de4d3 Binary files /dev/null and b/protocols.game/src/test/resources/fixtures/game/c2s/32/item_throw.bin differ diff --git a/protocols.game/src/test/resources/fixtures/game/c2s/32/move_selection.bin b/protocols.game/src/test/resources/fixtures/game/c2s/32/move_selection.bin new file mode 100644 index 0000000..ab2e984 Binary files /dev/null and b/protocols.game/src/test/resources/fixtures/game/c2s/32/move_selection.bin differ diff --git a/protocols.game/src/test/resources/fixtures/game/c2s/32/run.bin b/protocols.game/src/test/resources/fixtures/game/c2s/32/run.bin new file mode 100644 index 0000000..a903574 Binary files /dev/null and b/protocols.game/src/test/resources/fixtures/game/c2s/32/run.bin differ diff --git a/protocols.game/src/test/resources/fixtures/game/c2s/32/switch.bin b/protocols.game/src/test/resources/fixtures/game/c2s/32/switch.bin new file mode 100644 index 0000000..4f81a0d Binary files /dev/null and b/protocols.game/src/test/resources/fixtures/game/c2s/32/switch.bin differ diff --git a/protocols.game/src/test/resources/fixtures/game/s2c/02/character_list_32710.bin b/protocols.game/src/test/resources/fixtures/game/s2c/02/character_list_32710.bin new file mode 100644 index 0000000..cca0804 Binary files /dev/null and b/protocols.game/src/test/resources/fixtures/game/s2c/02/character_list_32710.bin differ diff --git a/protocols.game/src/test/resources/fixtures/game/s2c/13/party_scrubbed.bin b/protocols.game/src/test/resources/fixtures/game/s2c/13/party_scrubbed.bin new file mode 100644 index 0000000..31fdf00 Binary files /dev/null and b/protocols.game/src/test/resources/fixtures/game/s2c/13/party_scrubbed.bin differ diff --git a/protocols.game/src/test/resources/fixtures/game/s2c/14/monster_record_32710.bin b/protocols.game/src/test/resources/fixtures/game/s2c/14/monster_record_32710.bin new file mode 100644 index 0000000..028baf0 Binary files /dev/null and b/protocols.game/src/test/resources/fixtures/game/s2c/14/monster_record_32710.bin differ diff --git a/protocols.game/src/test/resources/fixtures/game/s2c/17/prompt_one_move_32710.bin b/protocols.game/src/test/resources/fixtures/game/s2c/17/prompt_one_move_32710.bin new file mode 100644 index 0000000..366b6b8 Binary files /dev/null and b/protocols.game/src/test/resources/fixtures/game/s2c/17/prompt_one_move_32710.bin differ diff --git a/protocols.game/src/test/resources/fixtures/game/s2c/17/prompt_two_moves_32710.bin b/protocols.game/src/test/resources/fixtures/game/s2c/17/prompt_two_moves_32710.bin new file mode 100644 index 0000000..fcd8c20 Binary files /dev/null and b/protocols.game/src/test/resources/fixtures/game/s2c/17/prompt_two_moves_32710.bin differ diff --git a/protocols.game/src/test/resources/fixtures/game/s2c/21/creature_arg.bin b/protocols.game/src/test/resources/fixtures/game/s2c/21/creature_arg.bin new file mode 100644 index 0000000..9538bf4 Binary files /dev/null and b/protocols.game/src/test/resources/fixtures/game/s2c/21/creature_arg.bin differ diff --git a/protocols.game/src/test/resources/fixtures/game/s2c/21/flags_00_type_64.bin b/protocols.game/src/test/resources/fixtures/game/s2c/21/flags_00_type_64.bin new file mode 100644 index 0000000..183eab2 Binary files /dev/null and b/protocols.game/src/test/resources/fixtures/game/s2c/21/flags_00_type_64.bin differ diff --git a/protocols.game/src/test/resources/fixtures/game/s2c/21/flags_0c_type_2e.bin b/protocols.game/src/test/resources/fixtures/game/s2c/21/flags_0c_type_2e.bin new file mode 100644 index 0000000..94e0808 Binary files /dev/null and b/protocols.game/src/test/resources/fixtures/game/s2c/21/flags_0c_type_2e.bin differ diff --git a/protocols.game/src/test/resources/fixtures/game/s2c/21/flags_0e_type_04.bin b/protocols.game/src/test/resources/fixtures/game/s2c/21/flags_0e_type_04.bin new file mode 100644 index 0000000..7062228 Binary files /dev/null and b/protocols.game/src/test/resources/fixtures/game/s2c/21/flags_0e_type_04.bin differ diff --git a/protocols.game/src/test/resources/fixtures/game/s2c/21/species_arg.bin b/protocols.game/src/test/resources/fixtures/game/s2c/21/species_arg.bin new file mode 100644 index 0000000..98ba3df Binary files /dev/null and b/protocols.game/src/test/resources/fixtures/game/s2c/21/species_arg.bin differ diff --git a/protocols.game/src/test/resources/fixtures/game/s2c/30/wild_two_party_scrubbed.bin b/protocols.game/src/test/resources/fixtures/game/s2c/30/wild_two_party_scrubbed.bin new file mode 100644 index 0000000..ca00d6a Binary files /dev/null and b/protocols.game/src/test/resources/fixtures/game/s2c/30/wild_two_party_scrubbed.bin differ diff --git a/protocols.game/src/test/resources/fixtures/game/s2c/35/return_switch_in.bin b/protocols.game/src/test/resources/fixtures/game/s2c/35/return_switch_in.bin new file mode 100644 index 0000000..233e89e Binary files /dev/null and b/protocols.game/src/test/resources/fixtures/game/s2c/35/return_switch_in.bin differ diff --git a/protocols.game/src/test/resources/fixtures/game/s2c/dc/category_flags_31914.bin b/protocols.game/src/test/resources/fixtures/game/s2c/dc/category_flags_31914.bin new file mode 100644 index 0000000..c5a64a3 Binary files /dev/null and b/protocols.game/src/test/resources/fixtures/game/s2c/dc/category_flags_31914.bin differ diff --git a/protocols.login/build.gradle.kts b/protocols.login/build.gradle.kts index c142d51..346d169 100644 --- a/protocols.login/build.gradle.kts +++ b/protocols.login/build.gradle.kts @@ -8,5 +8,6 @@ dependencies { api(project(":network")) api(project(":common")) api(libs.ineter) + testImplementation(project(":common.test")) testImplementation(libs.bundles.kotest) } diff --git a/protocols.login/src/test/kotlin/de/fiereu/openmmo/net/login/LoginCodecRoundtripTest.kt b/protocols.login/src/test/kotlin/de/fiereu/openmmo/net/login/LoginCodecRoundtripTest.kt index 67d84cb..743b35e 100644 --- a/protocols.login/src/test/kotlin/de/fiereu/openmmo/net/login/LoginCodecRoundtripTest.kt +++ b/protocols.login/src/test/kotlin/de/fiereu/openmmo/net/login/LoginCodecRoundtripTest.kt @@ -1,7 +1,7 @@ package de.fiereu.openmmo.net.login -import de.fiereu.bytecodec.test.decodeBytes -import de.fiereu.bytecodec.test.encodeToBytes +import de.fiereu.openmmo.common.test.decodeBytes +import de.fiereu.openmmo.common.test.encodeToBytes import de.fiereu.openmmo.net.login.packets.JoinGameServerPacket import de.fiereu.openmmo.net.login.packets.JoinGameServerPacketCodec import de.fiereu.openmmo.net.login.packets.MfaResponsePacket diff --git a/server.game/build.gradle.kts b/server.game/build.gradle.kts index 85adcc9..6894028 100644 --- a/server.game/build.gradle.kts +++ b/server.game/build.gradle.kts @@ -27,6 +27,7 @@ dependencies { implementation(libs.logback) implementation(libs.kotlinx.serialization.json) + testImplementation(project(":common.test")) testImplementation(libs.bundles.kotest) testImplementation(libs.kotlinx.coroutines.test) } diff --git a/server.game/src/test/kotlin/de/fiereu/openmmo/server/game/storage/CharacterRepositoryIT.kt b/server.game/src/test/kotlin/de/fiereu/openmmo/server/game/storage/CharacterRepositoryIT.kt index b6989a9..62eb07d 100644 --- a/server.game/src/test/kotlin/de/fiereu/openmmo/server/game/storage/CharacterRepositoryIT.kt +++ b/server.game/src/test/kotlin/de/fiereu/openmmo/server/game/storage/CharacterRepositoryIT.kt @@ -8,9 +8,9 @@ import de.fiereu.openmmo.common.enums.Direction import de.fiereu.openmmo.common.enums.EVs import de.fiereu.openmmo.common.enums.IVs import de.fiereu.openmmo.common.enums.PokemonContainer +import de.fiereu.openmmo.common.test.DockerAvailable import de.fiereu.openmmo.db.game.tables.references.CHARACTER_ITEMS import de.fiereu.openmmo.db.game.tables.references.POKEMON -import de.fiereu.openmmo.server.game.testsupport.DockerAvailable import io.kotest.assertions.throwables.shouldThrowAny import io.kotest.core.annotation.EnabledIf import io.kotest.core.spec.style.FunSpec diff --git a/server.login/build.gradle.kts b/server.login/build.gradle.kts index 52dcb84..2889799 100644 --- a/server.login/build.gradle.kts +++ b/server.login/build.gradle.kts @@ -25,6 +25,7 @@ dependencies { implementation(libs.kotlin.logging) implementation(libs.logback) + testImplementation(project(":common.test")) testImplementation(libs.bundles.kotest) testImplementation(libs.kotlinx.coroutines.test) } diff --git a/server.login/src/test/kotlin/de/fiereu/openmmo/server/login/auth/JooqUserStoreIT.kt b/server.login/src/test/kotlin/de/fiereu/openmmo/server/login/auth/JooqUserStoreIT.kt index e90d094..fc5e5e6 100644 --- a/server.login/src/test/kotlin/de/fiereu/openmmo/server/login/auth/JooqUserStoreIT.kt +++ b/server.login/src/test/kotlin/de/fiereu/openmmo/server/login/auth/JooqUserStoreIT.kt @@ -1,7 +1,7 @@ package de.fiereu.openmmo.server.login.auth import de.fiereu.openmmo.common.enums.LoginState -import de.fiereu.openmmo.server.login.testsupport.DockerAvailable +import de.fiereu.openmmo.common.test.DockerAvailable import io.kotest.core.annotation.EnabledIf import io.kotest.core.spec.style.FunSpec import io.kotest.matchers.shouldBe diff --git a/server.login/src/test/kotlin/de/fiereu/openmmo/server/login/testsupport/DockerAvailable.kt b/server.login/src/test/kotlin/de/fiereu/openmmo/server/login/testsupport/DockerAvailable.kt deleted file mode 100644 index dd1dfa6..0000000 --- a/server.login/src/test/kotlin/de/fiereu/openmmo/server/login/testsupport/DockerAvailable.kt +++ /dev/null @@ -1,12 +0,0 @@ -package de.fiereu.openmmo.server.login.testsupport - -import io.kotest.core.annotation.Condition -import io.kotest.core.spec.Spec -import kotlin.reflect.KClass -import org.testcontainers.DockerClientFactory - -/** Gates Testcontainers specs so machines without Docker skip them instead of failing. */ -class DockerAvailable : Condition { - override fun evaluate(kclass: KClass): Boolean = - runCatching { DockerClientFactory.instance().isDockerAvailable() }.getOrDefault(false) -} diff --git a/settings.gradle.kts b/settings.gradle.kts index b83a132..c4d33df 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -15,6 +15,7 @@ include(":keys") include(":patcher") include(":common") include(":bytecodec") +include(":common.test") include(":network") include(":protocols.login") include(":protocols.game")