server/shop_stale_offer_test.go (2343B)
1 package main 2 3 import ( 4 "bytes" 5 "encoding/binary" 6 "reflect" 7 "testing" 8 ) 9 10 func TestShopStaleOfferRefreshesStacksWithoutWrites(t *testing.T) { 11 world, output := newShopWorld(t) 12 player, client := world.characters[1], world.clients[1] 13 inventory := player.inventory 14 inventory.LastID = 3 15 inventory.Items = []ownedItem{ 16 {ID: 1, Type: 51018, Template: 209283, Quality: 1, Slot: 67, Count: 1}, 17 {ID: 2, Type: 51005, Template: 25812, Quality: 2, Slot: 65, Count: 8}, 18 {ID: 3, Type: 51005, Template: 25812, Quality: 2, Slot: 66, Count: 7}} 19 if err := world.saveInventory(player, inventory); err != nil { 20 t.Fatal(err) 21 } 22 before, err := readTestItemStore(world) 23 if err != nil { 24 t.Fatal(err) 25 } 26 auditCheckpointWrites(t, world) 27 output.packets = nil 28 request := shopTradePacket([2]uint32{50000, 1}, 4, [2]uint32{50000, 1}, [2]uint32{104, 64})[20:] 29 30 for range 2 { 31 if err := world.handleTrade(client, request); err != nil { 32 t.Fatal(err) 33 } 34 } 35 after, err := readTestItemStore(world) 36 cold := newTestInventoryServer(t) 37 38 if err != nil || !bytes.Equal(before, after) || len(checkpointWrites(t, world)) != 0 || client.shop != nil || 39 !reflect.DeepEqual(player.inventory, inventory) || !reflect.DeepEqual(cold.characters[1].inventory, inventory) || 40 world.nextItem != 3 || cold.nextItem != 3 { 41 t.Fatal("stale offer changed inventory, cash or allocation", err) 42 } 43 if len(output.packets) < 2 || binary.BigEndian.Uint32(output.packets[0][16:20]) != 0x36284f6e || 44 binary.BigEndian.Uint32(output.packets[0][33:37]) != 2 { 45 t.Fatal("stale offer omitted cancellation before the refresh") 46 } 47 var additions [][4]uint32 48 for _, packet := range output.packets[1:] { 49 if binary.BigEndian.Uint32(packet[16:20]) == 0x052e2f0c { 50 additions = append(additions, [4]uint32{binary.BigEndian.Uint32(packet[29:33]), binary.BigEndian.Uint32(packet[33:37]), 51 binary.BigEndian.Uint32(packet[37:41]), binary.BigEndian.Uint32(packet[41:45])}) 52 } 53 if binary.BigEndian.Uint32(packet[16:20]) == 0x5e477770 && 54 binary.BigEndian.Uint32(packet[29:33]) == 112 && binary.BigEndian.Uint32(packet[37:41]) == 51 { 55 t.Fatal("refresh retired the unrelated live weapon") 56 } 57 } 58 if !reflect.DeepEqual(additions, [][4]uint32{{25812, 25811, 2, 8}, {25812, 25811, 2, 7}}) { 59 t.Fatal("stale offer omitted authoritative selected-quality stacks", additions) 60 } 61 }