mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
seed transaction signature for the three creations
This commit is contained in:
parent
c3fe8b90dd
commit
3392ca025a
@ -8,6 +8,7 @@ import { Migration } from './Migration'
|
||||
import { ServerUser } from './ServerUser'
|
||||
import { Transaction } from './Transaction'
|
||||
import { TransactionCreation } from './TransactionCreation'
|
||||
import { TransactionSignature } from './TransactionSignature'
|
||||
import { TransactionSendCoin } from './TransactionSendCoin'
|
||||
import { User } from './User'
|
||||
import { UserSetting } from './UserSetting'
|
||||
@ -24,6 +25,7 @@ export const entities = [
|
||||
ServerUser,
|
||||
Transaction,
|
||||
TransactionCreation,
|
||||
TransactionSignature,
|
||||
TransactionSendCoin,
|
||||
User,
|
||||
UserSetting,
|
||||
|
||||
18
database/src/factories/transaction-signature.factory.ts
Normal file
18
database/src/factories/transaction-signature.factory.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import Faker from 'faker'
|
||||
import { define } from 'typeorm-seeding'
|
||||
import { TransactionSignature } from '../../entity/TransactionSignature'
|
||||
import { TransactionSignatureContext } from '../interface/TransactionContext'
|
||||
import { randomBytes } from 'crypto'
|
||||
|
||||
define(TransactionSignature, (faker: typeof Faker, context?: TransactionSignatureContext) => {
|
||||
if (!context || !context.transaction) {
|
||||
throw new Error('TransactionSignature: No transaction present!')
|
||||
}
|
||||
|
||||
const transactionSignature = new TransactionSignature()
|
||||
transactionSignature.signature = context.signature ? context.signature : randomBytes(64)
|
||||
transactionSignature.pubkey = context.pubkey ? context.pubkey : randomBytes(32)
|
||||
transactionSignature.transaction = context.transaction
|
||||
|
||||
return transactionSignature
|
||||
})
|
||||
@ -44,3 +44,9 @@ export interface UserTransactionContext {
|
||||
balance?: number
|
||||
balanceDate?: Date
|
||||
}
|
||||
|
||||
export interface TransactionSignatureContext {
|
||||
signature?: Buffer
|
||||
pubkey?: Buffer
|
||||
transaction?: Transaction
|
||||
}
|
||||
|
||||
@ -35,4 +35,6 @@ export interface UserInterface {
|
||||
targetDate?: Date
|
||||
amount?: number
|
||||
creationTxHash?: Buffer
|
||||
signature?: Buffer
|
||||
signaturePubkey?: Buffer
|
||||
}
|
||||
|
||||
@ -10,6 +10,7 @@ import {
|
||||
TransactionContext,
|
||||
TransactionCreationContext,
|
||||
UserTransactionContext,
|
||||
TransactionSignatureContext,
|
||||
} from '../../interface/TransactionContext'
|
||||
import { UserInterface } from '../../interface/UserInterface'
|
||||
import { User } from '../../../entity/User'
|
||||
@ -19,6 +20,7 @@ import { ServerUser } from '../../../entity/ServerUser'
|
||||
import { LoginUserRoles } from '../../../entity/LoginUserRoles'
|
||||
import { Balance } from '../../../entity/Balance'
|
||||
import { Transaction } from '../../../entity/Transaction'
|
||||
import { TransactionSignature } from '../../../entity/TransactionSignature'
|
||||
import { UserTransaction } from '../../../entity/UserTransaction'
|
||||
import { TransactionCreation } from '../../../entity/TransactionCreation'
|
||||
import { Factory } from 'typeorm-seeding'
|
||||
@ -48,6 +50,9 @@ export const userSeeder = async (factory: Factory, userData: UserInterface): Pro
|
||||
await factory(UserTransaction)(
|
||||
createUserTransactionContext(userData, user, transaction),
|
||||
).create()
|
||||
await factory(TransactionSignature)(
|
||||
createTransactionSignatureContext(userData, transaction),
|
||||
).create()
|
||||
}
|
||||
}
|
||||
|
||||
@ -162,3 +167,14 @@ const createUserTransactionContext = (
|
||||
balanceDate: context.recordDate,
|
||||
}
|
||||
}
|
||||
|
||||
const createTransactionSignatureContext = (
|
||||
context: UserInterface,
|
||||
transaction: Transaction,
|
||||
): TransactionSignatureContext => {
|
||||
return {
|
||||
signature: context.signature,
|
||||
pubkey: context.signaturePubkey,
|
||||
transaction,
|
||||
}
|
||||
}
|
||||
|
||||
@ -31,4 +31,12 @@ export const bibiBloxberg = {
|
||||
'51103dc0fc2ca5d5d75a9557a1e899304e5406cfdb1328d8df6414d527b0118100000000000000000000000000000000',
|
||||
'hex',
|
||||
),
|
||||
signature: Buffer.from(
|
||||
'2a2c71f3e41adc060bbc3086577e2d57d24eeeb0a7727339c3f85aad813808f601d7e1df56a26e0929d2e67fc054fca429ccfa283ed2782185c7f009fe008f0c',
|
||||
'hex',
|
||||
),
|
||||
signaturePubkey: Buffer.from(
|
||||
'7281e0ee3258b08801f3ec73e431b4519677f65c03b0382c63a913b5784ee770',
|
||||
'hex',
|
||||
),
|
||||
}
|
||||
|
||||
@ -31,4 +31,12 @@ export const bobBaumeister = {
|
||||
'be095dc87acb94987e71168fee8ecbf50ecb43a180b1006e75d573b35725c69c00000000000000000000000000000000',
|
||||
'hex',
|
||||
),
|
||||
signature: Buffer.from(
|
||||
'1fbd6b9a3d359923b2501557f3bc79fa7e428127c8090fb16bc490b4d87870ab142b3817ddd902d22f0b26472a483233784a0e460c0622661752a13978903905',
|
||||
'hex',
|
||||
),
|
||||
signaturePubkey: Buffer.from(
|
||||
'7281e0ee3258b08801f3ec73e431b4519677f65c03b0382c63a913b5784ee770',
|
||||
'hex',
|
||||
),
|
||||
}
|
||||
|
||||
@ -31,4 +31,12 @@ export const raeuberHotzenplotz = {
|
||||
'23ba44fd84deb59b9f32969ad0cb18bfa4588be1bdb99c396888506474c16c1900000000000000000000000000000000',
|
||||
'hex',
|
||||
),
|
||||
signature: Buffer.from(
|
||||
'756d3da061687c575d1dbc5073908f646aa5f498b0927b217c83b48af471450e571dfe8421fb8e1f1ebd1104526b7e7c6fa78684e2da59c8f7f5a8dc3d9e5b0b',
|
||||
'hex',
|
||||
),
|
||||
signaturePubkey: Buffer.from(
|
||||
'7281e0ee3258b08801f3ec73e431b4519677f65c03b0382c63a913b5784ee770',
|
||||
'hex',
|
||||
),
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user