Skip to content

Commit 8ac9afa

Browse files
committed
test: cover equip effect removal underflow guard
1 parent f127ffc commit 8ac9afa

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

internal/player/runtime_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2397,6 +2397,29 @@ func occupiedInventorySlotsExcept(skip ...inventory.SlotIndex) []inventory.ItemI
23972397
return items
23982398
}
23992399

2400+
func TestRuntimeRemoveEquipTemplateEffectRejectsPointUnderflowWithoutMutation(t *testing.T) {
2401+
persisted := loginticket.Character{
2402+
ID: 0x01030102,
2403+
VID: 0x02040102,
2404+
Name: "PeerTwo",
2405+
Points: [255]int32{
2406+
1: -1<<31 + 5,
2407+
},
2408+
}
2409+
runtime := NewRuntime(persisted, SessionLink{Login: "peer-two", CharacterIndex: 1})
2410+
before := runtime.LiveCharacter()
2411+
2412+
if result, ok := runtime.RemoveEquipTemplateEffect(bootstrapEquipmentPointTemplate(12200, inventory.EquipmentSlotWeapon, 1, 1, 10), inventory.EquipmentSlotWeapon); ok {
2413+
t.Fatalf("expected underflowing equip template effect removal to fail closed, got %+v", result)
2414+
}
2415+
if got := runtime.LiveCharacter(); !reflect.DeepEqual(got, before) {
2416+
t.Fatalf("underflowing equip template effect removal mutated live character: got %#v want %#v", got, before)
2417+
}
2418+
if got := runtime.PersistedSnapshot().Points[1]; got != -1<<31+5 {
2419+
t.Fatalf("underflowing equip template effect removal mutated persisted points: got %d want %d", got, -1<<31+5)
2420+
}
2421+
}
2422+
24002423
func TestRuntimeApplyPointDeltaAdjustsLivePointsWithoutMutatingPersistedSnapshot(t *testing.T) {
24012424
persisted := loginticket.Character{
24022425
ID: 0x01030102,

0 commit comments

Comments
 (0)