mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-09-12 23:30:35 +00:00
refactor: deprecate int32 (#7025)
* refactor: deprecate int32 * fix(db): reject legacy user quota schemas at startup * fix(quota): enforce wallet bounds and saturating billing conversions * fix(rate-limit): keep count*duration from wrapping int64 * fix: error message
This commit is contained in:
@@ -148,6 +148,35 @@ func TestRedeemCreditsQuotaExactlyOnce(t *testing.T) {
|
||||
assert.Equal(t, 500, user.Quota)
|
||||
}
|
||||
|
||||
func TestRedeemRejectsWalletOverflow(t *testing.T) {
|
||||
userId, key := setupRedeemFixture(t, 11)
|
||||
require.NoError(t, DB.Model(&User{}).Where("id = ?", userId).Update("quota", common.MaxWalletQuota-10).Error)
|
||||
|
||||
_, err := Redeem(key, userId)
|
||||
require.ErrorIs(t, err, ErrRedeemFailed)
|
||||
|
||||
var user User
|
||||
require.NoError(t, DB.First(&user, "id = ?", userId).Error)
|
||||
assert.Equal(t, common.MaxWalletQuota-10, user.Quota)
|
||||
|
||||
var redemption Redemption
|
||||
require.NoError(t, DB.First(&redemption, "key = ?", key).Error)
|
||||
assert.Equal(t, common.RedemptionCodeStatusEnabled, redemption.Status)
|
||||
}
|
||||
|
||||
func TestRedemptionQuotaRejectsWalletOverflow(t *testing.T) {
|
||||
setupRedeemFixture(t, 500)
|
||||
|
||||
redemption := &Redemption{
|
||||
Name: "overflow-redemption",
|
||||
Key: "10000000000000000000000000000002",
|
||||
Status: common.RedemptionCodeStatusEnabled,
|
||||
Quota: common.MaxWalletQuota + 1,
|
||||
CreatedTime: common.GetTimestamp(),
|
||||
}
|
||||
require.Error(t, redemption.Insert())
|
||||
}
|
||||
|
||||
// Exactly one of several concurrent redeems of the same code may win, and
|
||||
// quota must be credited exactly once.
|
||||
func TestRedeemConcurrentSingleSuccess(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user