73 lines
2.0 KiB
Go
73 lines
2.0 KiB
Go
package common
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
func TestWarpModesUseVerifiedClientBanners(t *testing.T) {
|
|
chdirRepoRoot(t)
|
|
native, _, err := LoadBrowsableGachaBanners()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(native) < 2 {
|
|
t.Fatal("need two verified banner assets")
|
|
}
|
|
rows := []GachaBanner{
|
|
{ID: native[0].ID, GachaType: GachaTypeAvatarUp, RateUpItems5: []uint32{1}},
|
|
{ID: native[1].ID, GachaType: GachaTypeWeaponUp, RateUpItems5: []uint32{2}},
|
|
}
|
|
raw, _ := json.Marshal(rows)
|
|
if err := os.WriteFile("resources/Banners.json", raw, 0600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// A foreign/synthetic ID must never appear in a native Client response.
|
|
unverified := ^uint32(0)
|
|
raw, _ = json.Marshal([]GachaBanner{{ID: unverified, GachaType: GachaTypeAvatarUp, RateUpItems5: []uint32{3}}})
|
|
if err := os.WriteFile("resources/BannersUnlockAll.json", raw, 0600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, tc := range []struct {
|
|
mode int
|
|
want []uint32
|
|
}{{0, []uint32{native[0].ID, native[1].ID}}, {1, []uint32{native[0].ID, native[1].ID}}, {2, []uint32{native[0].ID}}, {3, []uint32{native[1].ID}}} {
|
|
visible, err := LoadVisibleGachaBanners(tc.mode)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
got := map[uint32]bool{}
|
|
for _, row := range visible {
|
|
got[row.ID] = true
|
|
}
|
|
if len(got) != len(tc.want) || got[unverified] {
|
|
t.Fatalf("mode %d wrong visible IDs: %v", tc.mode, got)
|
|
}
|
|
for _, id := range tc.want {
|
|
if !got[id] {
|
|
t.Fatalf("mode %d missing %d", tc.mode, id)
|
|
}
|
|
}
|
|
}
|
|
if _, err := LoadVisibleGachaBanners(-1); err == nil {
|
|
t.Fatal("invalid mode accepted")
|
|
}
|
|
}
|
|
|
|
func TestWarpModeReadIsReadOnlyAndKeepsOff(t *testing.T) {
|
|
t.Chdir(t.TempDir())
|
|
original := []byte(`{"warp_unlock_mode":0,"unrelated":true}`)
|
|
if err := os.WriteFile("persistent", original, 0600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
mode, err := ReadWarpUnlockMode()
|
|
if err != nil || mode == nil || *mode != 0 {
|
|
t.Fatalf("off lost: %v %v", mode, err)
|
|
}
|
|
after, _ := os.ReadFile("persistent")
|
|
if string(after) != string(original) {
|
|
t.Fatal("reader rewrote persistent")
|
|
}
|
|
}
|