fix(gift): drop RowVersion (SQLite incompatible) + restore wire reward_type map
[Timestamp] byte[] doesn't work under SQLite (the test backend) — EF expects the DB to populate it on insert, but SQLite has no equivalent of Postgres's xmin. The WHERE Status = Unclaimed filter plus IInventoryService's viewer-level concurrency is the practical defense; RowVersion was only a backstop. Regenerated the migration without the RowVersion column. Wire reward_type on the gift endpoint uses a gift-specific scheme that diverges from UserGoodsType for currencies: wire 1 = Crystal (enum=2), wire 9 = Rupy (enum=9), wire 4 = Item (enum=4). A naked cast resolves wire 1 to UserGoodsType.RedEther and silently grants the wrong wallet — restored the explicit WireRewardTypeToUserGoodsType map from the old tutorial controller. Retrofits existing GiftControllerTests to call SeedTutorialPresentsAsync on the new helper (RegisterViewer doesn't auto-seed; only the prod signup path does). All 7 existing tests pass.
This commit is contained in:
@@ -12,7 +12,7 @@ using SVSim.Database;
|
|||||||
namespace SVSim.Database.Migrations
|
namespace SVSim.Database.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(SVSimDbContext))]
|
[DbContext(typeof(SVSimDbContext))]
|
||||||
[Migration("20260609003820_AddViewerPresents")]
|
[Migration("20260609004113_AddViewerPresents")]
|
||||||
partial class AddViewerPresents
|
partial class AddViewerPresents
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@@ -2902,12 +2902,6 @@ namespace SVSim.Database.Migrations
|
|||||||
b.Property<int>("RewardType")
|
b.Property<int>("RewardType")
|
||||||
.HasColumnType("integer");
|
.HasColumnType("integer");
|
||||||
|
|
||||||
b.Property<byte[]>("RowVersion")
|
|
||||||
.IsConcurrencyToken()
|
|
||||||
.IsRequired()
|
|
||||||
.ValueGeneratedOnAddOrUpdate()
|
|
||||||
.HasColumnType("bytea");
|
|
||||||
|
|
||||||
b.Property<string>("Source")
|
b.Property<string>("Source")
|
||||||
.HasMaxLength(64)
|
.HasMaxLength(64)
|
||||||
.HasColumnType("character varying(64)");
|
.HasColumnType("character varying(64)");
|
||||||
@@ -34,8 +34,7 @@ namespace SVSim.Database.Migrations
|
|||||||
Message = table.Column<string>(type: "text", nullable: false),
|
Message = table.Column<string>(type: "text", nullable: false),
|
||||||
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||||
ClaimedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
|
ClaimedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
|
||||||
Source = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
|
Source = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true)
|
||||||
RowVersion = table.Column<byte[]>(type: "bytea", rowVersion: true, nullable: false)
|
|
||||||
},
|
},
|
||||||
constraints: table =>
|
constraints: table =>
|
||||||
{
|
{
|
||||||
@@ -2899,12 +2899,6 @@ namespace SVSim.Database.Migrations
|
|||||||
b.Property<int>("RewardType")
|
b.Property<int>("RewardType")
|
||||||
.HasColumnType("integer");
|
.HasColumnType("integer");
|
||||||
|
|
||||||
b.Property<byte[]>("RowVersion")
|
|
||||||
.IsConcurrencyToken()
|
|
||||||
.IsRequired()
|
|
||||||
.ValueGeneratedOnAddOrUpdate()
|
|
||||||
.HasColumnType("bytea");
|
|
||||||
|
|
||||||
b.Property<string>("Source")
|
b.Property<string>("Source")
|
||||||
.HasMaxLength(64)
|
.HasMaxLength(64)
|
||||||
.HasColumnType("character varying(64)");
|
.HasColumnType("character varying(64)");
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
|
|
||||||
namespace SVSim.Database.Models;
|
namespace SVSim.Database.Models;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -39,13 +37,6 @@ public class ViewerPresent
|
|||||||
/// this today — the tutorial-step advance is route-gated, not Source-gated.
|
/// this today — the tutorial-step advance is route-gated, not Source-gated.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string? Source { get; set; }
|
public string? Source { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// EF Core optimistic concurrency for the claim path. Two concurrent claims of the
|
|
||||||
/// same PresentId: first wins, second's CommitAsync throws DbUpdateConcurrencyException.
|
|
||||||
/// </summary>
|
|
||||||
[Timestamp]
|
|
||||||
public byte[] RowVersion { get; set; } = Array.Empty<byte>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum PresentStatus : byte
|
public enum PresentStatus : byte
|
||||||
|
|||||||
@@ -84,8 +84,12 @@ public class GiftController : SVSimController
|
|||||||
{
|
{
|
||||||
if (state == 1)
|
if (state == 1)
|
||||||
{
|
{
|
||||||
|
// Wire reward_type on the gift endpoint follows a gift-specific scheme that
|
||||||
|
// diverges from UserGoodsType for currencies: wire "1" means Crystal (enum=2),
|
||||||
|
// wire "9" means Rupy (enum=9), wire "4" means Item (enum=4). A naked cast would
|
||||||
|
// resolve wire 1 -> UserGoodsType.RedEther and silently grant the wrong wallet.
|
||||||
var granted = await tx.GrantAsync(
|
var granted = await tx.GrantAsync(
|
||||||
(UserGoodsType)p.RewardType,
|
WireRewardTypeToUserGoodsType(p.RewardType),
|
||||||
p.RewardDetailId,
|
p.RewardDetailId,
|
||||||
(int)p.RewardCount);
|
(int)p.RewardCount);
|
||||||
|
|
||||||
@@ -161,6 +165,14 @@ public class GiftController : SVSimController
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static UserGoodsType WireRewardTypeToUserGoodsType(int wireType) => wireType switch
|
||||||
|
{
|
||||||
|
1 => UserGoodsType.Crystal,
|
||||||
|
4 => UserGoodsType.Item,
|
||||||
|
9 => UserGoodsType.Rupy,
|
||||||
|
_ => throw new InvalidOperationException($"Unmapped gift wire reward_type {wireType}"),
|
||||||
|
};
|
||||||
|
|
||||||
private async Task<(List<ViewerPresent> Unclaimed, List<ViewerPresent> History)> ReadTopWindowAsync(
|
private async Task<(List<ViewerPresent> Unclaimed, List<ViewerPresent> History)> ReadTopWindowAsync(
|
||||||
long viewerId, int page)
|
long viewerId, int page)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ public class GiftControllerTests
|
|||||||
{
|
{
|
||||||
using var factory = new SVSimTestFactory();
|
using var factory = new SVSimTestFactory();
|
||||||
long viewerId = await factory.SeedViewerAsync(tutorialState: 31);
|
long viewerId = await factory.SeedViewerAsync(tutorialState: 31);
|
||||||
|
await factory.SeedTutorialPresentsAsync(viewerId);
|
||||||
using var client = factory.CreateAuthenticatedClient(viewerId);
|
using var client = factory.CreateAuthenticatedClient(viewerId);
|
||||||
|
|
||||||
var response = await client.PostAsync("/tutorial/gift_top",
|
var response = await client.PostAsync("/tutorial/gift_top",
|
||||||
@@ -54,6 +55,7 @@ public class GiftControllerTests
|
|||||||
using var factory = new SVSimTestFactory();
|
using var factory = new SVSimTestFactory();
|
||||||
await factory.SeedGlobalsAsync();
|
await factory.SeedGlobalsAsync();
|
||||||
long viewerId = await factory.SeedViewerAsync(tutorialState: 31);
|
long viewerId = await factory.SeedViewerAsync(tutorialState: 31);
|
||||||
|
await factory.SeedTutorialPresentsAsync(viewerId);
|
||||||
using var client = factory.CreateAuthenticatedClient(viewerId);
|
using var client = factory.CreateAuthenticatedClient(viewerId);
|
||||||
|
|
||||||
var pre = await factory.GetViewerCurrencyAsync(viewerId);
|
var pre = await factory.GetViewerCurrencyAsync(viewerId);
|
||||||
@@ -100,6 +102,7 @@ public class GiftControllerTests
|
|||||||
using var factory = new SVSimTestFactory();
|
using var factory = new SVSimTestFactory();
|
||||||
await factory.SeedGlobalsAsync();
|
await factory.SeedGlobalsAsync();
|
||||||
long viewerId = await factory.SeedViewerAsync(tutorialState: 31);
|
long viewerId = await factory.SeedViewerAsync(tutorialState: 31);
|
||||||
|
await factory.SeedTutorialPresentsAsync(viewerId);
|
||||||
using var client = factory.CreateAuthenticatedClient(viewerId);
|
using var client = factory.CreateAuthenticatedClient(viewerId);
|
||||||
|
|
||||||
var json = $$"""{"present_id_array":["71478626"],"state":1,{{BaseAuthBlock}}}""";
|
var json = $$"""{"present_id_array":["71478626"],"state":1,{{BaseAuthBlock}}}""";
|
||||||
@@ -129,6 +132,7 @@ public class GiftControllerTests
|
|||||||
using var factory = new SVSimTestFactory();
|
using var factory = new SVSimTestFactory();
|
||||||
await factory.SeedGlobalsAsync();
|
await factory.SeedGlobalsAsync();
|
||||||
long viewerId = await factory.SeedViewerAsync(tutorialState: 31);
|
long viewerId = await factory.SeedViewerAsync(tutorialState: 31);
|
||||||
|
await factory.SeedTutorialPresentsAsync(viewerId);
|
||||||
using var client = factory.CreateAuthenticatedClient(viewerId);
|
using var client = factory.CreateAuthenticatedClient(viewerId);
|
||||||
|
|
||||||
var json = $$"""{"present_id_array":["71478626","71478627"],"state":1,{{BaseAuthBlock}}}""";
|
var json = $$"""{"present_id_array":["71478626","71478627"],"state":1,{{BaseAuthBlock}}}""";
|
||||||
@@ -167,6 +171,7 @@ public class GiftControllerTests
|
|||||||
// 100, not the hardcoded 41 the endpoint used to emit, or the client's tutorial
|
// 100, not the hardcoded 41 the endpoint used to emit, or the client's tutorial
|
||||||
// state machine regresses on a no-op retry.
|
// state machine regresses on a no-op retry.
|
||||||
long viewerId = await factory.SeedViewerAsync(tutorialState: 100);
|
long viewerId = await factory.SeedViewerAsync(tutorialState: 100);
|
||||||
|
await factory.SeedTutorialPresentsAsync(viewerId);
|
||||||
using var client = factory.CreateAuthenticatedClient(viewerId);
|
using var client = factory.CreateAuthenticatedClient(viewerId);
|
||||||
|
|
||||||
var json = $$"""{"present_id_array":["71478626"],"state":1,{{BaseAuthBlock}}}""";
|
var json = $$"""{"present_id_array":["71478626"],"state":1,{{BaseAuthBlock}}}""";
|
||||||
@@ -192,6 +197,7 @@ public class GiftControllerTests
|
|||||||
// found and incremented, not duplicated. The (ViewerId, ItemId) unique index
|
// found and incremented, not duplicated. The (ViewerId, ItemId) unique index
|
||||||
// added 2026-05-25 would otherwise throw on SaveChanges → 500 to the client.
|
// added 2026-05-25 would otherwise throw on SaveChanges → 500 to the client.
|
||||||
await factory.SeedOwnedItemAsync(viewerId, itemId: 1, count: 5, itemName: "PreOwnedItem");
|
await factory.SeedOwnedItemAsync(viewerId, itemId: 1, count: 5, itemName: "PreOwnedItem");
|
||||||
|
await factory.SeedTutorialPresentsAsync(viewerId);
|
||||||
|
|
||||||
using var client = factory.CreateAuthenticatedClient(viewerId);
|
using var client = factory.CreateAuthenticatedClient(viewerId);
|
||||||
|
|
||||||
@@ -224,6 +230,7 @@ public class GiftControllerTests
|
|||||||
using var factory = new SVSimTestFactory();
|
using var factory = new SVSimTestFactory();
|
||||||
await factory.SeedGlobalsAsync();
|
await factory.SeedGlobalsAsync();
|
||||||
long viewerId = await factory.SeedViewerAsync(tutorialState: 31);
|
long viewerId = await factory.SeedViewerAsync(tutorialState: 31);
|
||||||
|
await factory.SeedTutorialPresentsAsync(viewerId);
|
||||||
using var client = factory.CreateAuthenticatedClient(viewerId);
|
using var client = factory.CreateAuthenticatedClient(viewerId);
|
||||||
|
|
||||||
var preFirst = await factory.GetViewerCurrencyAsync(viewerId);
|
var preFirst = await factory.GetViewerCurrencyAsync(viewerId);
|
||||||
|
|||||||
Reference in New Issue
Block a user