async function _addUsers ({ userCount, executeAll, executeOne, existingUserIds, addedUserIds, walletIndexToUserIdMap, uploadProfilePic = true }) {
  await logOps('Add users', async () => {
    const users = genRandomUsers(userCount)

    await executeAll(async (libs, i) => {
      try {
        // If user already exists, do not recreate user and use existing user
        const existingUser = await getUser({ executeOne, walletIndex: i })
        let userId

        if (existingUser) {
          logger.info(`Found existing user=${existingUser.user_id}`)
          existingUserIds.push(existingUser.user_id)
          userId = existingUser.user_id

        } else {
          const createNewUser = async () => {
            const start = Date.now()
            logger.info(`Creating new user...`)

            const userMetadata = users[i]
            let newUserId

            if (uploadProfilePic) {
              let picPath
              try {
                // get random image from web
                const randomImageFilePath = await getRandomImageFilePath(TEMP_IMG_STORAGE_PATH)
                picPath = randomImageFilePath
              } catch (e) {
                console.log(`[_addUsers] Error fetching random image: ${e.message}`)
                picPath = USER_PIC_PATH
              }
              newUserId = await uploadProfileImagesAndAddUser(libs, userMetadata, picPath)

            } else {
              newUserId = await addUser(libs, userMetadata)
            }

            logger.info(`Created new user=${newUserId} in ${Date.now() - start}ms`)

            addedUserIds.push(newUserId)
            userId = newUserId
          }

          const createNewUserTimeoutMs = 300000 // 300sec = 5 min
          await racePromiseWithTimeout(createNewUser(), createNewUserTimeoutMs, `Failed to create new user for index ${i} in ${createNewUserTimeoutMs}`)
        }

        await executeOne(i, libs => libs.waitForLatestBlock())

        // add to wallet index to userId mapping
        walletIndexToUserIdMap[i] = userId

        // print userIds that exist and were added
        if (addedUserIds.length) logger.info(`Added users, userIds=${addedUserIds}`)
        if (existingUserIds.length) logger.info(`Existing users, userIds=${existingUserIds}`)
      } catch (e) {
        logger.error('GOT ERR CREATING USER')
        console.error(e) // this prints out the stack trace
        throw e
      }
    })
  })
}
/**
 * Helper function to add a user. If the wallet index is already used to create a user, add that userId to
 * the walletIndexToUserMap.
 * @param {*} userCount
 * @param {*} executeAll
 * @param {*} executeOne
 * @param {int[]} existingUserIds
 * @param {int[]} addedUserIds
 * @param {Object} walletIndexToUserIdMap
 * @param {boolean} uploadProfilePic flag to upload profile pic on sign up or not
 */
Helper function to add a user. If the wallet index is already used to create a user, add that userId to
the walletIndexToUserMap.
Helper function to add a user . If the wallet index is already used to create a user add that userId to the walletIndexToUserMap .
async function _addUsers ({ userCount, executeAll, executeOne, existingUserIds, addedUserIds, walletIndexToUserIdMap, uploadProfilePic = true }) {
  await logOps('Add users', async () => {
    const users = genRandomUsers(userCount)
    await executeAll(async (libs, i) => {
      try {
        const existingUser = await getUser({ executeOne, walletIndex: i })
        let userId
        if (existingUser) {
          logger.info(`Found existing user=${existingUser.user_id}`)
          existingUserIds.push(existingUser.user_id)
          userId = existingUser.user_id
        } else {
          const createNewUser = async () => {
            const start = Date.now()
            logger.info(`Creating new user...`)
            const userMetadata = users[i]
            let newUserId
            if (uploadProfilePic) {
              let picPath
              try {
                const randomImageFilePath = await getRandomImageFilePath(TEMP_IMG_STORAGE_PATH)
                picPath = randomImageFilePath
              } catch (e) {
                console.log(`[_addUsers] Error fetching random image: ${e.message}`)
                picPath = USER_PIC_PATH
              }
              newUserId = await uploadProfileImagesAndAddUser(libs, userMetadata, picPath)
            } else {
              newUserId = await addUser(libs, userMetadata)
            }
            logger.info(`Created new user=${newUserId} in ${Date.now() - start}ms`)
            addedUserIds.push(newUserId)
            userId = newUserId
          }
          const createNewUserTimeoutMs = 300000 
          await racePromiseWithTimeout(createNewUser(), createNewUserTimeoutMs, `Failed to create new user for index ${i} in ${createNewUserTimeoutMs}`)
        }
        await executeOne(i, libs => libs.waitForLatestBlock())
        walletIndexToUserIdMap[i] = userId
        if (addedUserIds.length) logger.info(`Added users, userIds=${addedUserIds}`)
        if (existingUserIds.length) logger.info(`Existing users, userIds=${existingUserIds}`)
      } catch (e) {
        logger.error('GOT ERR CREATING USER')
        console.error(e) 
        throw e
      }
    })
  })
}
async function _addUsers ( { userCount , executeAll , executeOne , existingUserIds , addedUserIds , walletIndexToUserIdMap , uploadProfilePic = true } ) { await logOps ( 'Add users' , async ( ) => { const users = genRandomUsers ( userCount ) await executeAll ( async ( libs , i ) => { try { const existingUser = await getUser ( { executeOne , walletIndex : i } ) let userId if ( existingUser ) { logger . info ( ` ${ existingUser . user_id } ` ) existingUserIds . push ( existingUser . user_id ) userId = existingUser . user_id } else { const createNewUser = async ( ) => { const start = Date . now ( ) logger . info ( ` ` ) const userMetadata = users [ i ] let newUserId if ( uploadProfilePic ) { let picPath try { const randomImageFilePath = await getRandomImageFilePath ( TEMP_IMG_STORAGE_PATH ) picPath = randomImageFilePath } catch ( e ) { console . log ( ` ${ e . message } ` ) picPath = USER_PIC_PATH } newUserId = await uploadProfileImagesAndAddUser ( libs , userMetadata , picPath ) } else { newUserId = await addUser ( libs , userMetadata ) } logger . info ( ` ${ newUserId } ${ Date . now ( ) - start } ` ) addedUserIds . push ( newUserId ) userId = newUserId } const createNewUserTimeoutMs = 300000 await racePromiseWithTimeout ( createNewUser ( ) , createNewUserTimeoutMs , ` ${ i } ${ createNewUserTimeoutMs } ` ) } await executeOne ( i , libs => libs . waitForLatestBlock ( ) ) walletIndexToUserIdMap [ i ] = userId if ( addedUserIds . length ) logger . info ( ` ${ addedUserIds } ` ) if ( existingUserIds . length ) logger . info ( ` ${ existingUserIds } ` ) } catch ( e ) { logger . error ( 'GOT ERR CREATING USER' ) console . error ( e ) throw e } } ) } ) }
Helper function to add a user.
Helper function to add a user .
// If user already exists, do not recreate user and use existing user // get random image from web // 300sec = 5 min // add to wallet index to userId mapping // print userIds that exist and were added // this prints out the stack trace