fix(gacha): validate reward pool before charging currency (#175)

Filter out gacha entries with no items at the query level (EXISTS
subquery) and reorder Play methods to validate the pool before
calling transact(), so players are never charged for a misconfigured
gacha.
This commit is contained in:
Houmgaor
2026-03-10 11:28:11 +01:00
parent 915e9bc0b0
commit 2365b63e9c
4 changed files with 52 additions and 19 deletions

View File

@@ -186,7 +186,10 @@ func TestHandleMsgMhfReceiveGachaItem_Freeze(t *testing.T) {
func TestHandleMsgMhfPlayNormalGacha_TransactError(t *testing.T) {
server := createMockServer()
gachaRepo := &mockGachaRepo{txErr: errors.New("transact failed")}
gachaRepo := &mockGachaRepo{
txErr: errors.New("transact failed"),
rewardPool: []GachaEntry{{ID: 10, Weight: 100}},
}
server.gachaRepo = gachaRepo
server.userRepo = &mockUserRepoGacha{}
ensureGachaService(server)
@@ -269,7 +272,10 @@ func TestHandleMsgMhfPlayNormalGacha_Success(t *testing.T) {
func TestHandleMsgMhfPlayStepupGacha_TransactError(t *testing.T) {
server := createMockServer()
gachaRepo := &mockGachaRepo{txErr: errors.New("transact failed")}
gachaRepo := &mockGachaRepo{
txErr: errors.New("transact failed"),
rewardPool: []GachaEntry{{ID: 10, Weight: 100}},
}
server.gachaRepo = gachaRepo
server.userRepo = &mockUserRepoGacha{}
ensureGachaService(server)
@@ -473,7 +479,10 @@ func TestHandleMsgMhfGetBoxGachaInfo_Success(t *testing.T) {
func TestHandleMsgMhfPlayBoxGacha_TransactError(t *testing.T) {
server := createMockServer()
gachaRepo := &mockGachaRepo{txErr: errors.New("transact failed")}
gachaRepo := &mockGachaRepo{
txErr: errors.New("transact failed"),
rewardPool: []GachaEntry{{ID: 10, Weight: 100}},
}
server.gachaRepo = gachaRepo
server.userRepo = &mockUserRepoGacha{}
ensureGachaService(server)