测试环境开箱和探索不在检查链上记录

This commit is contained in:
CounterFire2023 2024-04-24 17:45:11 +08:00
parent c45c4c5bf4
commit 084f8d195a
4 changed files with 58 additions and 10 deletions

View File

@ -16,6 +16,7 @@
"repairdata2": "ts-node -r tsconfig-paths/register src/repairdata2.ts",
"repairredis": "ts-node -r tsconfig-paths/register src/repairredis.ts",
"checkredis": "ts-node -r tsconfig-paths/register src/checkredis.ts",
"additem": "ts-node -r tsconfig-paths/register src/addboxdata.ts",
"test:watch": "jest --watch",
"test": "jest"
},

43
src/addboxdata.ts Normal file
View File

@ -0,0 +1,43 @@
import mongoose from 'mongoose'
import * as dotenv from 'dotenv'
const envFile = process.env.NODE_ENV && process.env.NODE_ENV === 'production' ? `.env.production` : '.env.development'
dotenv.config({ path: envFile })
console.log(process.env.DB_MAIN)
import { ActivityChest } from 'models/ActivityChest'
import { ScoreRecord } from 'models/ScoreRecord'
import { DeleteRecord } from 'models/DeleteRecord'
import { rankKey, updateRank, updateRankInvite } from 'services/rank.svr'
import { ZRedisClient } from 'zutils'
import { RANK_SCORE_SCALE } from 'common/Constants'
import { uuid } from 'zutils/utils/security.util'
const db = mongoose.connection
const totalKey = 'uaw_activity:score'
const keyInvite = `uaw_activity:invite`
const addItem = async (key, item) => {
return new Promise((resolve, reject) => {
new ZRedisClient().pub.sadd(key, item, () => {
resolve(true)
})
})
}
;(async () => {
try {
let opts = { url: process.env.REDIS }
new ZRedisClient(opts)
for (let i = 0; i < 10; i++) {
let id = uuid()
await addItem('chest_bonus_1', id)
}
for (let i = 0; i < 100; i++) {
let id = uuid()
await addItem('chest_bonus_2', id)
}
} catch (e) {
console.log(e)
}
console.log('end')
process.exit(0)
})()

View File

@ -320,9 +320,11 @@ class BoxController extends BaseController {
if (!isObjectIdString(chestId)) {
throw new ZError(11, 'must provide valid chestId')
}
const openRecord = await ChestRecord.findOne({ from: user.address.toLowerCase(), chestId })
if (!openRecord) {
throw new ZError(12, 'onchain open record not found')
if (process.env.NODE_ENV === 'production') {
const openRecord = await ChestRecord.findOne({ from: user.address.toLowerCase(), chestId })
if (!openRecord) {
throw new ZError(12, 'onchain open record not found')
}
}
const chest = await ActivityChest.findById(chestId)
if (!chest) {

View File

@ -352,13 +352,15 @@ class GameController extends BaseController {
if (!isObjectId(id)) {
throw new ZError(12, 'invalid id')
}
const chainRecord = await GeneralScription.findOne({
from: user.address.toLowerCase(),
op: 'explore',
data: id,
})
if (!chainRecord) {
throw new ZError(13, 'waiting for chain confirm')
if (process.env.NODE_ENV === 'production') {
const chainRecord = await GeneralScription.findOne({
from: user.address.toLowerCase(),
op: 'explore',
data: id,
})
if (!chainRecord) {
throw new ZError(13, 'waiting for chain confirm')
}
}
const exploreRecord = await ExploreRecord.findById(id)
if (!exploreRecord) {