server/shop_rotation_test.go (2239B)
1 package main 2 3 import ( 4 "ao/server/gamedata" 5 "slices" 6 "testing" 7 "time" 8 ) 9 10 func TestShopRotationKeepsSuppliesAndStarterStockStable(t *testing.T) { 11 original := gamedata.ShopStock[99491] 12 gamedata.ShopStock[99491] = []gamedata.ShopItem{{Template: 21605, Quality: 1}, {Template: 85596, Quality: 5}, {Template: 85596, Quality: 100}} 13 t.Cleanup(func() { gamedata.ShopStock[99491] = original }) 14 world := &server{} 15 first := world.shopCatalog(3221488799, 99491, time.Unix(0, 0)) 16 same := world.shopCatalog(3221488799, 99491, time.Unix(1799, 0)) 17 if !slices.Equal(first, same) { 18 t.Fatal("stock changed within a restock period") 19 } 20 changed := false 21 for period := int64(1); period <= 8; period++ { 22 stock := world.shopCatalog(3221488799, 99491, time.Unix(period*1800, 0)) 23 if !slices.Equal(stock, first) { 24 changed = true 25 } 26 if len(stock) < 2 || stock[0] != (gamedata.ShopItem{Template: 21605, Quality: 1}) || stock[1] != (gamedata.ShopItem{Template: 85596, Quality: 5}) { 27 t.Fatal("stable supplies or starter armor rotated out") 28 } 29 if len(stock) == 3 && (stock[2].Quality < 90 || stock[2].Quality > 110 || !gamedata.ItemQualitySupported(stock[2].Template, stock[2].Quality)) { 30 t.Fatal("rotation invented an unsupported QL", stock) 31 } 32 } 33 if !changed { 34 t.Fatal("stock never rotated") 35 } 36 if gamedata.ShopStock[99491][2].Quality != 100 { 37 t.Fatal("rotation modified embedded source stock") 38 } 39 } 40 41 func TestShopRotationDoesNotChangeOpenTrade(t *testing.T) { 42 world, _ := newPurchaseWorld(t) 43 client := world.clients[1] 44 before := slices.Clone(client.shop.stock) 45 world.shopCatalog(client.shop.machine, 99491, time.Now().Add(30*time.Minute)) 46 if !slices.Equal(client.shop.stock, before) { 47 t.Fatal("refresh changed an open trade") 48 } 49 if err := world.handleTrade(client, shopTradePacket([2]uint32{50000, 1}, 4, [2]uint32{51035, client.shop.machine}, [2]uint32{111, 0})[20:]); err != nil { 50 t.Fatal(err) 51 } 52 if err := world.handleTrade(client, shopTradePacket([2]uint32{50000, 1}, 1, [2]uint32{}, [2]uint32{})[20:]); err != nil { 53 t.Fatal(err) 54 } 55 purchased := world.characters[1].inventory.Items[1] 56 if purchased.Template != 95577 || purchased.Quality != 1 { 57 t.Fatal("open trade delivered changed stock", purchased) 58 } 59 }