fixed seeds

This commit is contained in:
Ulf Gebhardt 2022-02-20 04:02:05 +01:00
parent bfde22b261
commit 6b78161182
Signed by: ulfgebhardt
GPG Key ID: DA6B843E748679C9
11 changed files with 54 additions and 108 deletions

View File

@ -49,7 +49,7 @@ export class Transaction extends BaseEntity {
nullable: true, nullable: true,
default: null, default: null,
}) })
sendReceiverPublicKey: Buffer sendReceiverPublicKey: Buffer | null
@Column({ @Column({
name: 'send_receiver_user_id', name: 'send_receiver_user_id',
@ -58,8 +58,8 @@ export class Transaction extends BaseEntity {
nullable: true, nullable: true,
default: null, default: null,
}) })
sendReceiverUserId: number sendReceiverUserId: number | null
@Column({ name: 'send_sender_final_balance', length: 20, nullable: true, default: null }) @Column({ name: 'send_sender_final_balance', length: 20, nullable: true, default: null })
sendSenderFinalBalance: BigInt sendSenderFinalBalance: BigInt | null
} }

View File

@ -1,18 +0,0 @@
import Faker from 'faker'
import { define } from 'typeorm-seeding'
import { TransactionCreation } from '../../entity/TransactionCreation'
import { TransactionCreationContext } from '../interface/TransactionContext'
define(TransactionCreation, (faker: typeof Faker, context?: TransactionCreationContext) => {
if (!context || !context.userId || !context.transaction) {
throw new Error('TransactionCreation: No userId and/or transaction present!')
}
const transactionCreation = new TransactionCreation()
transactionCreation.userId = context.userId
transactionCreation.amount = context.amount ? context.amount : 100000
transactionCreation.targetDate = context.targetDate ? context.targetDate : new Date()
transactionCreation.transaction = context.transaction
return transactionCreation
})

View File

@ -5,17 +5,24 @@ import { TransactionContext } from '../interface/TransactionContext'
import { randomBytes } from 'crypto' import { randomBytes } from 'crypto'
define(Transaction, (faker: typeof Faker, context?: TransactionContext) => { define(Transaction, (faker: typeof Faker, context?: TransactionContext) => {
if (!context) context = {} if (!context) {
throw new Error('TransactionContext not well defined.')
}
const transaction = new Transaction() const transaction = new Transaction()
transaction.transactionTypeId = context.transactionTypeId ? context.transactionTypeId : 2 transaction.transactionTypeId = context.transactionTypeId // || 2
transaction.txHash = context.txHash ? context.txHash : randomBytes(48) transaction.userId = context.userId
transaction.memo = context.memo || context.memo === '' ? context.memo : faker.lorem.sentence() transaction.amount = context.amount
transaction.received = context.received ? context.received : new Date() transaction.txHash = context.txHash || randomBytes(48)
transaction.signature = context.signature ? context.signature : randomBytes(64) transaction.memo = context.memo
transaction.pubkey = context.signaturePubkey ? context.signaturePubkey : randomBytes(32) transaction.received = context.received || new Date()
if (context.transactionSendCoin) transaction.transactionSendCoin = context.transactionSendCoin transaction.signature = context.signature || randomBytes(64)
if (context.transactionCreation) transaction.transactionCreation = context.transactionCreation transaction.pubkey = context.pubkey || randomBytes(32)
transaction.creationIdentHash = context.creationIdentHash || randomBytes(32)
transaction.creationDate = context.creationDate || new Date()
transaction.sendReceiverPublicKey = context.sendReceiverPublicKey || null
transaction.sendReceiverUserId = context.sendReceiverUserId || null
transaction.sendSenderFinalBalance = context.sendSenderFinalBalance || null
return transaction return transaction
}) })

View File

@ -1,18 +1,20 @@
import { Transaction } from '../../entity/Transaction' import { Transaction } from '../../entity/Transaction'
import { TransactionSendCoin } from '../../entity/TransactionSendCoin'
import { TransactionCreation } from '../../entity/TransactionCreation'
import { User } from '../../entity/User' import { User } from '../../entity/User'
export interface TransactionContext { export interface TransactionContext {
transactionTypeId?: number transactionTypeId: number
userId: number
amount: BigInt
txHash?: Buffer txHash?: Buffer
memo?: string memo: string
received?: Date received?: Date
blockchainTypeId?: number
signature?: Buffer signature?: Buffer
signaturePubkey?: Buffer pubkey?: Buffer
transactionSendCoin?: TransactionSendCoin creationIdentHash?: Buffer
transactionCreation?: TransactionCreation creationDate?: Date
sendReceiverPublicKey?: Buffer
sendReceiverUserId?: number
sendSenderFinalBalance?: BigInt
} }
export interface BalanceContext { export interface BalanceContext {
@ -32,13 +34,6 @@ export interface TransactionSendCoinContext {
transaction?: Transaction transaction?: Transaction
} }
export interface TransactionCreationContext {
userId?: number
amount?: number
targetDate?: Date
transaction?: Transaction
}
export interface UserTransactionContext { export interface UserTransactionContext {
userId?: number userId?: number
transactionId?: number transactionId?: number

View File

@ -11,7 +11,6 @@ export interface UserInterface {
emailChecked?: boolean emailChecked?: boolean
language?: string language?: string
deletedAt?: Date deletedAt?: Date
groupId?: number
publisherId?: number publisherId?: number
passphrase?: string passphrase?: string
// from server user // from server user
@ -27,9 +26,8 @@ export interface UserInterface {
// balance // balance
balanceModified?: Date balanceModified?: Date
recordDate?: Date recordDate?: Date
targetDate?: Date creationDate?: Date
amount?: number amount?: number
creationTxHash?: Buffer creationTxHash?: Buffer
signature?: Buffer signature?: Buffer
signaturePubkey?: Buffer
} }

View File

@ -2,7 +2,6 @@ import { UserContext, ServerUserContext } from '../../interface/UserContext'
import { import {
BalanceContext, BalanceContext,
TransactionContext, TransactionContext,
TransactionCreationContext,
UserTransactionContext, UserTransactionContext,
} from '../../interface/TransactionContext' } from '../../interface/TransactionContext'
import { UserInterface } from '../../interface/UserInterface' import { UserInterface } from '../../interface/UserInterface'
@ -11,7 +10,6 @@ import { ServerUser } from '../../../entity/ServerUser'
import { Balance } from '../../../entity/Balance' import { Balance } from '../../../entity/Balance'
import { Transaction } from '../../../entity/Transaction' import { Transaction } from '../../../entity/Transaction'
import { UserTransaction } from '../../../entity/UserTransaction' import { UserTransaction } from '../../../entity/UserTransaction'
import { TransactionCreation } from '../../../entity/TransactionCreation'
import { Factory } from 'typeorm-seeding' import { Factory } from 'typeorm-seeding'
export const userSeeder = async (factory: Factory, userData: UserInterface): Promise<void> => { export const userSeeder = async (factory: Factory, userData: UserInterface): Promise<void> => {
@ -25,10 +23,7 @@ export const userSeeder = async (factory: Factory, userData: UserInterface): Pro
// create some GDD for the user // create some GDD for the user
await factory(Balance)(createBalanceContext(userData, user)).create() await factory(Balance)(createBalanceContext(userData, user)).create()
const transaction = await factory(Transaction)( const transaction = await factory(Transaction)(
createTransactionContext(userData, 1, 'Herzlich Willkommen bei Gradido!'), createTransactionContext(userData, user, 1, 'Herzlich Willkommen bei Gradido!'),
).create()
await factory(TransactionCreation)(
createTransactionCreationContext(userData, user, transaction),
).create() ).create()
await factory(UserTransaction)( await factory(UserTransaction)(
createUserTransactionContext(userData, user, transaction), createUserTransactionContext(userData, user, transaction),
@ -76,27 +71,18 @@ const createBalanceContext = (context: UserInterface, user: User): BalanceContex
const createTransactionContext = ( const createTransactionContext = (
context: UserInterface, context: UserInterface,
user: User,
type: number, type: number,
memo: string, memo: string,
): TransactionContext => { ): TransactionContext => {
return { return {
transactionTypeId: type, transactionTypeId: type,
userId: user.id,
amount: BigInt(context.amount || 100000),
txHash: context.creationTxHash, txHash: context.creationTxHash,
memo, memo,
received: context.recordDate, received: context.recordDate,
} creationDate: context.creationDate,
}
const createTransactionCreationContext = (
context: UserInterface,
user: User,
transaction: Transaction,
): TransactionCreationContext => {
return {
userId: user.id,
amount: context.amount,
targetDate: context.targetDate,
transaction,
} }
} }
@ -112,6 +98,6 @@ const createUserTransactionContext = (
balance: context.amount, balance: context.amount,
balanceDate: context.recordDate, balanceDate: context.recordDate,
signature: context.signature, signature: context.signature,
pubkey: context.signaturePubkey, pubkey: context.pubKey,
} }
} }

View File

@ -1,8 +1,9 @@
export const bibiBloxberg = { import { UserInterface } from '../../interface/UserInterface'
export const bibiBloxberg: UserInterface = {
email: 'bibi@bloxberg.de', email: 'bibi@bloxberg.de',
firstName: 'Bibi', firstName: 'Bibi',
lastName: 'Bloxberg', lastName: 'Bloxberg',
username: 'bibi',
// description: 'Hex Hex', // description: 'Hex Hex',
password: BigInt('12825419584724616625'), password: BigInt('12825419584724616625'),
pubKey: Buffer.from('42de7e4754625b730018c3b4ea745a4d043d9d867af352d0f08871793dfa6743', 'hex'), pubKey: Buffer.from('42de7e4754625b730018c3b4ea745a4d043d9d867af352d0f08871793dfa6743', 'hex'),
@ -14,16 +15,13 @@ export const bibiBloxberg = {
createdAt: new Date('2021-11-26T11:32:16'), createdAt: new Date('2021-11-26T11:32:16'),
emailChecked: true, emailChecked: true,
language: 'de', language: 'de',
disabled: false,
groupId: 1,
passphrase: passphrase:
'knife normal level all hurdle crucial color avoid warrior stadium road bachelor affair topple hawk pottery right afford immune two ceiling budget glance hour ', 'knife normal level all hurdle crucial color avoid warrior stadium road bachelor affair topple hawk pottery right afford immune two ceiling budget glance hour ',
mnemonicType: 2,
isAdmin: false, isAdmin: false,
addBalance: true, addBalance: true,
balanceModified: new Date('2021-11-30T10:37:11'), balanceModified: new Date('2021-11-30T10:37:11'),
recordDate: new Date('2021-11-30T10:37:11'), recordDate: new Date('2021-11-30T10:37:11'),
targetDate: new Date('2021-08-01 00:00:00'), creationDate: new Date('2021-08-01 00:00:00'),
amount: 10000000, amount: 10000000,
creationTxHash: Buffer.from( creationTxHash: Buffer.from(
'51103dc0fc2ca5d5d75a9557a1e899304e5406cfdb1328d8df6414d527b0118100000000000000000000000000000000', '51103dc0fc2ca5d5d75a9557a1e899304e5406cfdb1328d8df6414d527b0118100000000000000000000000000000000',
@ -33,8 +31,4 @@ export const bibiBloxberg = {
'2a2c71f3e41adc060bbc3086577e2d57d24eeeb0a7727339c3f85aad813808f601d7e1df56a26e0929d2e67fc054fca429ccfa283ed2782185c7f009fe008f0c', '2a2c71f3e41adc060bbc3086577e2d57d24eeeb0a7727339c3f85aad813808f601d7e1df56a26e0929d2e67fc054fca429ccfa283ed2782185c7f009fe008f0c',
'hex', 'hex',
), ),
signaturePubkey: Buffer.from(
'7281e0ee3258b08801f3ec73e431b4519677f65c03b0382c63a913b5784ee770',
'hex',
),
} }

View File

@ -1,8 +1,9 @@
export const bobBaumeister = { import { UserInterface } from '../../interface/UserInterface'
export const bobBaumeister: UserInterface = {
email: 'bob@baumeister.de', email: 'bob@baumeister.de',
firstName: 'Bob', firstName: 'Bob',
lastName: 'der Baumeister', lastName: 'der Baumeister',
username: 'bob',
// description: 'Können wir das schaffen? Ja, wir schaffen das!', // description: 'Können wir das schaffen? Ja, wir schaffen das!',
password: BigInt('3296644341468822636'), password: BigInt('3296644341468822636'),
pubKey: Buffer.from('a509d9a146374fc975e3677db801ae8a4a83bff9dea96da64053ff6de6b2dd7e', 'hex'), pubKey: Buffer.from('a509d9a146374fc975e3677db801ae8a4a83bff9dea96da64053ff6de6b2dd7e', 'hex'),
@ -14,16 +15,13 @@ export const bobBaumeister = {
createdAt: new Date('2021-11-26T11:36:31'), createdAt: new Date('2021-11-26T11:36:31'),
emailChecked: true, emailChecked: true,
language: 'de', language: 'de',
disabled: false,
groupId: 1,
passphrase: passphrase:
'detail master source effort unable waste tilt flush domain orchard art truck hint barrel response gate impose peanut secret merry three uncle wink resource ', 'detail master source effort unable waste tilt flush domain orchard art truck hint barrel response gate impose peanut secret merry three uncle wink resource ',
mnemonicType: 2,
isAdmin: false, isAdmin: false,
addBalance: true, addBalance: true,
balanceModified: new Date('2021-11-30T10:37:14'), balanceModified: new Date('2021-11-30T10:37:14'),
recordDate: new Date('2021-11-30T10:37:14'), recordDate: new Date('2021-11-30T10:37:14'),
targetDate: new Date('2021-08-01 00:00:00'), creationDate: new Date('2021-08-01 00:00:00'),
amount: 10000000, amount: 10000000,
creationTxHash: Buffer.from( creationTxHash: Buffer.from(
'be095dc87acb94987e71168fee8ecbf50ecb43a180b1006e75d573b35725c69c00000000000000000000000000000000', 'be095dc87acb94987e71168fee8ecbf50ecb43a180b1006e75d573b35725c69c00000000000000000000000000000000',
@ -33,8 +31,4 @@ export const bobBaumeister = {
'1fbd6b9a3d359923b2501557f3bc79fa7e428127c8090fb16bc490b4d87870ab142b3817ddd902d22f0b26472a483233784a0e460c0622661752a13978903905', '1fbd6b9a3d359923b2501557f3bc79fa7e428127c8090fb16bc490b4d87870ab142b3817ddd902d22f0b26472a483233784a0e460c0622661752a13978903905',
'hex', 'hex',
), ),
signaturePubkey: Buffer.from(
'7281e0ee3258b08801f3ec73e431b4519677f65c03b0382c63a913b5784ee770',
'hex',
),
} }

View File

@ -1,8 +1,9 @@
export const garrickOllivander = { import { UserInterface } from '../../interface/UserInterface'
export const garrickOllivander: UserInterface = {
email: 'garrick@ollivander.com', email: 'garrick@ollivander.com',
firstName: 'Garrick', firstName: 'Garrick',
lastName: 'Ollivander', lastName: 'Ollivander',
username: 'garrick',
// description: `Curious ... curious ... // description: `Curious ... curious ...
// Renowned wandmaker Mr Ollivander owns the wand shop Ollivanders: Makers of Fine Wands Since 382 BC in Diagon Alley. His shop is widely considered the best place to purchase a wand.`, // Renowned wandmaker Mr Ollivander owns the wand shop Ollivanders: Makers of Fine Wands Since 382 BC in Diagon Alley. His shop is widely considered the best place to purchase a wand.`,
password: BigInt('0'), password: BigInt('0'),
@ -10,11 +11,8 @@ export const garrickOllivander = {
createdAt: new Date('2022-01-10T10:23:17'), createdAt: new Date('2022-01-10T10:23:17'),
emailChecked: false, emailChecked: false,
language: 'en', language: 'en',
disabled: false,
groupId: 1,
passphrase: passphrase:
'human glide theory clump wish history other duty door fringe neck industry ostrich equal plate diesel tornado neck people antenna door category moon hen ', 'human glide theory clump wish history other duty door fringe neck industry ostrich equal plate diesel tornado neck people antenna door category moon hen ',
mnemonicType: 2,
isAdmin: false, isAdmin: false,
addBalance: false, addBalance: false,
} }

View File

@ -1,8 +1,9 @@
export const peterLustig = { import { UserInterface } from '../../interface/UserInterface'
export const peterLustig: UserInterface = {
email: 'peter@lustig.de', email: 'peter@lustig.de',
firstName: 'Peter', firstName: 'Peter',
lastName: 'Lustig', lastName: 'Lustig',
username: 'peter',
// description: 'Latzhose und Nickelbrille', // description: 'Latzhose und Nickelbrille',
password: BigInt('3917921995996627700'), password: BigInt('3917921995996627700'),
pubKey: Buffer.from('7281e0ee3258b08801f3ec73e431b4519677f65c03b0382c63a913b5784ee770', 'hex'), pubKey: Buffer.from('7281e0ee3258b08801f3ec73e431b4519677f65c03b0382c63a913b5784ee770', 'hex'),
@ -14,11 +15,8 @@ export const peterLustig = {
createdAt: new Date('2020-11-25T10:48:43'), createdAt: new Date('2020-11-25T10:48:43'),
emailChecked: true, emailChecked: true,
language: 'de', language: 'de',
disabled: false,
groupId: 1,
passphrase: passphrase:
'okay property choice naive calm present weird increase stuff royal vibrant frame attend wood one else tribe pull hedgehog woman kitchen hawk snack smart ', 'okay property choice naive calm present weird increase stuff royal vibrant frame attend wood one else tribe pull hedgehog woman kitchen hawk snack smart ',
mnemonicType: 2,
role: 'admin', role: 'admin',
serverUserPassword: '$2y$10$TzIWLeZoKs251gwrhSQmHeKhKI/EQ4EV5ClfAT8Ufnb4lcUXPa5X.', serverUserPassword: '$2y$10$TzIWLeZoKs251gwrhSQmHeKhKI/EQ4EV5ClfAT8Ufnb4lcUXPa5X.',
activated: 1, activated: 1,

View File

@ -1,8 +1,9 @@
export const raeuberHotzenplotz = { import { UserInterface } from '../../interface/UserInterface'
export const raeuberHotzenplotz: UserInterface = {
email: 'raeuber@hotzenplotz.de', email: 'raeuber@hotzenplotz.de',
firstName: 'Räuber', firstName: 'Räuber',
lastName: 'Hotzenplotz', lastName: 'Hotzenplotz',
username: 'räuber',
// description: 'Pfefferpistole', // description: 'Pfefferpistole',
password: BigInt('12123692783243004812'), password: BigInt('12123692783243004812'),
pubKey: Buffer.from('d7c70f94234dff071d982aa8f41583876c356599773b5911b39080da2b8c2d2b', 'hex'), pubKey: Buffer.from('d7c70f94234dff071d982aa8f41583876c356599773b5911b39080da2b8c2d2b', 'hex'),
@ -14,16 +15,13 @@ export const raeuberHotzenplotz = {
createdAt: new Date('2021-11-26T11:32:16'), createdAt: new Date('2021-11-26T11:32:16'),
emailChecked: true, emailChecked: true,
language: 'de', language: 'de',
disabled: false,
groupId: 1,
passphrase: passphrase:
'gospel trip tenant mouse spider skill auto curious man video chief response same little over expire drum display fancy clinic keen throw urge basket ', 'gospel trip tenant mouse spider skill auto curious man video chief response same little over expire drum display fancy clinic keen throw urge basket ',
mnemonicType: 2,
isAdmin: false, isAdmin: false,
addBalance: true, addBalance: true,
balanceModified: new Date('2021-11-30T10:37:13'), balanceModified: new Date('2021-11-30T10:37:13'),
recordDate: new Date('2021-11-30T10:37:13'), recordDate: new Date('2021-11-30T10:37:13'),
targetDate: new Date('2021-08-01 00:00:00'), creationDate: new Date('2021-08-01 00:00:00'),
amount: 10000000, amount: 10000000,
creationTxHash: Buffer.from( creationTxHash: Buffer.from(
'23ba44fd84deb59b9f32969ad0cb18bfa4588be1bdb99c396888506474c16c1900000000000000000000000000000000', '23ba44fd84deb59b9f32969ad0cb18bfa4588be1bdb99c396888506474c16c1900000000000000000000000000000000',
@ -33,8 +31,4 @@ export const raeuberHotzenplotz = {
'756d3da061687c575d1dbc5073908f646aa5f498b0927b217c83b48af471450e571dfe8421fb8e1f1ebd1104526b7e7c6fa78684e2da59c8f7f5a8dc3d9e5b0b', '756d3da061687c575d1dbc5073908f646aa5f498b0927b217c83b48af471450e571dfe8421fb8e1f1ebd1104526b7e7c6fa78684e2da59c8f7f5a8dc3d9e5b0b',
'hex', 'hex',
), ),
signaturePubkey: Buffer.from(
'7281e0ee3258b08801f3ec73e431b4519677f65c03b0382c63a913b5784ee770',
'hex',
),
} }