mirror of
https://github.com/IT4Change/gradido.git
synced 2026-02-06 09:56:05 +00:00
finetuning of structure
This commit is contained in:
parent
19c8bb8d44
commit
04e0075679
@ -1,11 +1,12 @@
|
||||
import { KeyPairEd25519 } from 'gradido-blockchain-js'
|
||||
|
||||
import { getLogger, Logger } from 'log4js'
|
||||
import { LOG4JS_BASE_CATEGORY } from './config/const'
|
||||
import { HieroId } from './schemas/typeGuard.schema'
|
||||
import { LOG4JS_BASE_CATEGORY } from '../config/const'
|
||||
import { HieroId } from '../schemas/typeGuard.schema'
|
||||
|
||||
// Source: https://refactoring.guru/design-patterns/singleton/typescript/example
|
||||
// and ../federation/client/FederationClientFactory.ts
|
||||
// TODO: TTL (time to live) based, maybe even optional use of redis
|
||||
/**
|
||||
* A Singleton class defines the `getInstance` method that lets clients access
|
||||
* the unique singleton instance.
|
||||
@ -2,7 +2,7 @@ import { ConfirmedTransaction } from 'gradido-blockchain-js'
|
||||
import JsonRpcClient from 'jsonrpc-ts-client'
|
||||
import { JsonRpcEitherResponse } from 'jsonrpc-ts-client/dist/types/utils/jsonrpc'
|
||||
import { getLogger, Logger } from 'log4js'
|
||||
import { parse } from 'valibot'
|
||||
import * as v from 'valibot'
|
||||
import { CONFIG } from '../../config'
|
||||
import { LOG4JS_BASE_CATEGORY } from '../../config/const'
|
||||
import { Uuidv4Hash } from '../../data/Uuidv4Hash'
|
||||
@ -61,13 +61,13 @@ export class GradidoNodeClient {
|
||||
transactionIdentifier: TransactionIdentifierInput,
|
||||
): Promise<ConfirmedTransaction | undefined> {
|
||||
const parameter = {
|
||||
...parse(transactionIdentifierSchema, transactionIdentifier),
|
||||
...v.parse(transactionIdentifierSchema, transactionIdentifier),
|
||||
format: 'base64',
|
||||
}
|
||||
const response = await this.rpcCall<{ transaction: string }>('getTransaction', parameter)
|
||||
if (response.isSuccess()) {
|
||||
// this.logger.debug('result: ', response.result.transaction)
|
||||
return parse(confirmedTransactionSchema, response.result.transaction)
|
||||
return v.parse(confirmedTransactionSchema, response.result.transaction)
|
||||
}
|
||||
if (response.isError()) {
|
||||
if (response.error.code === GradidoNodeErrorCodes.TRANSACTION_NOT_FOUND) {
|
||||
@ -92,7 +92,7 @@ export class GradidoNodeClient {
|
||||
}
|
||||
const response = await this.rpcCall<{ transaction: string }>('getLastTransaction', parameter)
|
||||
if (response.isSuccess()) {
|
||||
return parse(confirmedTransactionSchema, response.result.transaction)
|
||||
return v.parse(confirmedTransactionSchema, response.result.transaction)
|
||||
}
|
||||
if (response.isError()) {
|
||||
if (response.error.code === GradidoNodeErrorCodes.GRADIDO_NODE_ERROR) {
|
||||
@ -121,7 +121,7 @@ export class GradidoNodeClient {
|
||||
*/
|
||||
public async getTransactions(input: TransactionsRangeInput): Promise<ConfirmedTransaction[]> {
|
||||
const parameter = {
|
||||
...parse(transactionsRangeSchema, input),
|
||||
...v.parse(transactionsRangeSchema, input),
|
||||
format: 'base64',
|
||||
}
|
||||
const result = await this.rpcCallResolved<{ transactions: string[] }>(
|
||||
@ -129,7 +129,7 @@ export class GradidoNodeClient {
|
||||
parameter,
|
||||
)
|
||||
return result.transactions.map((transactionBase64) =>
|
||||
parse(confirmedTransactionSchema, transactionBase64),
|
||||
v.parse(confirmedTransactionSchema, transactionBase64),
|
||||
)
|
||||
}
|
||||
|
||||
@ -146,8 +146,8 @@ export class GradidoNodeClient {
|
||||
pubkey: Hex32Input,
|
||||
): Promise<ConfirmedTransaction[]> {
|
||||
const parameter = {
|
||||
...parse(transactionsRangeSchema, transactionRange),
|
||||
pubkey: parse(hex32Schema, pubkey),
|
||||
...v.parse(transactionsRangeSchema, transactionRange),
|
||||
pubkey: v.parse(hex32Schema, pubkey),
|
||||
format: 'base64',
|
||||
}
|
||||
const response = await this.rpcCallResolved<{ transactions: string[] }>(
|
||||
@ -155,7 +155,7 @@ export class GradidoNodeClient {
|
||||
parameter,
|
||||
)
|
||||
return response.transactions.map((transactionBase64) =>
|
||||
parse(confirmedTransactionSchema, transactionBase64),
|
||||
v.parse(confirmedTransactionSchema, transactionBase64),
|
||||
)
|
||||
}
|
||||
|
||||
@ -172,14 +172,14 @@ export class GradidoNodeClient {
|
||||
|
||||
public async getAddressType(pubkey: Hex32Input, hieroTopic: HieroId): Promise<AddressType> {
|
||||
const parameter = {
|
||||
pubkey: parse(hex32Schema, pubkey),
|
||||
pubkey: v.parse(hex32Schema, pubkey),
|
||||
topic: hieroTopic,
|
||||
}
|
||||
const response = await this.rpcCallResolved<{ addressType: string }>(
|
||||
'getAddressType',
|
||||
parameter,
|
||||
)
|
||||
return parse(addressTypeSchema, response.addressType)
|
||||
return v.parse(addressTypeSchema, response.addressType)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -204,7 +204,7 @@ export class GradidoNodeClient {
|
||||
)
|
||||
if (response.isSuccess()) {
|
||||
this.logger.info(`call findUserByNameHash, used ${response.result.timeUsed}`)
|
||||
return parse(hex32Schema, response.result.pubkey)
|
||||
return v.parse(hex32Schema, response.result.pubkey)
|
||||
}
|
||||
if (
|
||||
response.isError() &&
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { beforeAll, describe, expect, it } from 'bun:test'
|
||||
import { parse } from 'valibot'
|
||||
import * as v from 'valibot'
|
||||
import {
|
||||
HieroId,
|
||||
HieroTransactionIdString,
|
||||
@ -12,14 +12,14 @@ let topic: HieroId
|
||||
const topicString = '0.0.261'
|
||||
let hieroTransactionId: HieroTransactionIdString
|
||||
beforeAll(() => {
|
||||
topic = parse(hieroIdSchema, topicString)
|
||||
hieroTransactionId = parse(hieroTransactionIdStringSchema, '0.0.261-1755348116-1281621')
|
||||
topic = v.parse(hieroIdSchema, topicString)
|
||||
hieroTransactionId = v.parse(hieroTransactionIdStringSchema, '0.0.261-1755348116-1281621')
|
||||
})
|
||||
|
||||
describe('transactionIdentifierSchema ', () => {
|
||||
it('valid, transaction identified by transactionNr and topic', () => {
|
||||
expect(
|
||||
parse(transactionIdentifierSchema, {
|
||||
v.parse(transactionIdentifierSchema, {
|
||||
transactionId: 1,
|
||||
topic: topicString,
|
||||
}),
|
||||
@ -31,7 +31,7 @@ describe('transactionIdentifierSchema ', () => {
|
||||
})
|
||||
it('valid, transaction identified by hieroTransactionId and topic', () => {
|
||||
expect(
|
||||
parse(transactionIdentifierSchema, {
|
||||
v.parse(transactionIdentifierSchema, {
|
||||
hieroTransactionId: '0.0.261-1755348116-1281621',
|
||||
topic: topicString,
|
||||
}),
|
||||
@ -42,7 +42,7 @@ describe('transactionIdentifierSchema ', () => {
|
||||
})
|
||||
it('invalid, missing topic', () => {
|
||||
expect(() =>
|
||||
parse(transactionIdentifierSchema, {
|
||||
v.parse(transactionIdentifierSchema, {
|
||||
transactionId: 1,
|
||||
hieroTransactionId: '0.0.261-1755348116-1281621',
|
||||
}),
|
||||
@ -50,7 +50,7 @@ describe('transactionIdentifierSchema ', () => {
|
||||
})
|
||||
it('invalid, transactionNr and iotaMessageId set', () => {
|
||||
expect(() =>
|
||||
parse(transactionIdentifierSchema, {
|
||||
v.parse(transactionIdentifierSchema, {
|
||||
transactionId: 1,
|
||||
hieroTransactionId: '0.0.261-1755348116-1281621',
|
||||
topic,
|
||||
|
||||
@ -5,12 +5,8 @@ import * as v from 'valibot'
|
||||
import { CONFIG } from '../../config'
|
||||
import { LOG4JS_BASE_CATEGORY } from '../../config/const'
|
||||
import { HieroId, Uuidv4 } from '../../schemas/typeGuard.schema'
|
||||
import {
|
||||
type Community,
|
||||
communitySchema,
|
||||
homeCommunityGraphqlQuery,
|
||||
setHomeCommunityTopicId,
|
||||
} from './community.schema'
|
||||
import { homeCommunityGraphqlQuery, setHomeCommunityTopicId } from './graphql'
|
||||
import { type Community, communitySchema } from './output.schema'
|
||||
|
||||
// Source: https://refactoring.guru/design-patterns/singleton/typescript/example
|
||||
// and ../federation/client/FederationClientFactory.ts
|
||||
|
||||
@ -1,43 +0,0 @@
|
||||
import { gql } from 'graphql-request'
|
||||
import * as v from 'valibot'
|
||||
import { dateSchema } from '../../schemas/typeConverter.schema'
|
||||
import { hieroIdSchema, uuidv4Schema } from '../../schemas/typeGuard.schema'
|
||||
|
||||
/**
|
||||
* Schema Definitions for graphql response
|
||||
*/
|
||||
export const communitySchema = v.object({
|
||||
uuid: uuidv4Schema,
|
||||
name: v.string('expect string type'),
|
||||
hieroTopicId: v.nullish(hieroIdSchema),
|
||||
foreign: v.boolean('expect boolean type'),
|
||||
creationDate: dateSchema,
|
||||
})
|
||||
|
||||
export type CommunityInput = v.InferInput<typeof communitySchema>
|
||||
export type Community = v.InferOutput<typeof communitySchema>
|
||||
|
||||
// graphql query for getting home community in tune with community schema
|
||||
export const homeCommunityGraphqlQuery = gql`
|
||||
query {
|
||||
homeCommunity {
|
||||
uuid
|
||||
name
|
||||
hieroTopicId
|
||||
foreign
|
||||
creationDate
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
export const setHomeCommunityTopicId = gql`
|
||||
mutation ($uuid: String!, $hieroTopicId: String){
|
||||
updateHomeCommunity(uuid: $uuid, hieroTopicId: $hieroTopicId) {
|
||||
uuid
|
||||
name
|
||||
hieroTopicId
|
||||
foreign
|
||||
creationDate
|
||||
}
|
||||
}
|
||||
`
|
||||
30
dlt-connector/src/client/backend/graphql.ts
Normal file
30
dlt-connector/src/client/backend/graphql.ts
Normal file
@ -0,0 +1,30 @@
|
||||
import { gql } from 'graphql-request'
|
||||
|
||||
/**
|
||||
* Schema Definitions for graphql requests
|
||||
*/
|
||||
|
||||
// graphql query for getting home community in tune with community schema
|
||||
export const homeCommunityGraphqlQuery = gql`
|
||||
query {
|
||||
homeCommunity {
|
||||
uuid
|
||||
name
|
||||
hieroTopicId
|
||||
foreign
|
||||
creationDate
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
export const setHomeCommunityTopicId = gql`
|
||||
mutation ($uuid: String!, $hieroTopicId: String){
|
||||
updateHomeCommunity(uuid: $uuid, hieroTopicId: $hieroTopicId) {
|
||||
uuid
|
||||
name
|
||||
hieroTopicId
|
||||
foreign
|
||||
creationDate
|
||||
}
|
||||
}
|
||||
`
|
||||
@ -2,7 +2,7 @@
|
||||
import { describe, expect, it } from 'bun:test'
|
||||
import * as v from 'valibot'
|
||||
import { hieroIdSchema, uuidv4Schema } from '../../schemas/typeGuard.schema'
|
||||
import { communitySchema } from './community.schema'
|
||||
import { communitySchema } from './output.schema'
|
||||
|
||||
describe('community.schema', () => {
|
||||
it('community', () => {
|
||||
14
dlt-connector/src/client/backend/output.schema.ts
Normal file
14
dlt-connector/src/client/backend/output.schema.ts
Normal file
@ -0,0 +1,14 @@
|
||||
import * as v from 'valibot'
|
||||
import { dateSchema } from '../../schemas/typeConverter.schema'
|
||||
import { hieroIdSchema, uuidv4Schema } from '../../schemas/typeGuard.schema'
|
||||
|
||||
export const communitySchema = v.object({
|
||||
uuid: uuidv4Schema,
|
||||
name: v.string('expect string type'),
|
||||
hieroTopicId: v.nullish(hieroIdSchema),
|
||||
foreign: v.boolean('expect boolean type'),
|
||||
creationDate: dateSchema,
|
||||
})
|
||||
|
||||
export type CommunityInput = v.InferInput<typeof communitySchema>
|
||||
export type Community = v.InferOutput<typeof communitySchema>
|
||||
@ -10,13 +10,11 @@ import {
|
||||
TopicMessageSubmitTransaction,
|
||||
TopicUpdateTransaction,
|
||||
TransactionId,
|
||||
TransactionReceipt,
|
||||
TransactionResponse,
|
||||
Wallet,
|
||||
} from '@hashgraph/sdk'
|
||||
import { GradidoTransaction, HieroTopicId } from 'gradido-blockchain-js'
|
||||
import { GradidoTransaction } from 'gradido-blockchain-js'
|
||||
import { getLogger, Logger } from 'log4js'
|
||||
import { parse } from 'valibot'
|
||||
import * as v from 'valibot'
|
||||
import { CONFIG } from '../../config'
|
||||
import { LOG4JS_BASE_CATEGORY } from '../../config/const'
|
||||
import { HieroId, hieroIdSchema } from '../../schemas/typeGuard.schema'
|
||||
@ -139,7 +137,7 @@ export class HieroClient {
|
||||
}
|
||||
this.logger.debug(`topic sequence number: ${info.sequenceNumber.toNumber()}`)
|
||||
// this.logger.debug(JSON.stringify(info, null, 2))
|
||||
return parse(topicInfoSchema, {
|
||||
return v.parse(topicInfoSchema, {
|
||||
topicId: topicId.toString(),
|
||||
sequenceNumber: info.sequenceNumber.toNumber(),
|
||||
expirationTime: info.expirationTime?.toDate(),
|
||||
@ -165,7 +163,7 @@ export class HieroClient {
|
||||
this.logger.addContext('topicId', createReceipt.topicId?.toString())
|
||||
const record = await createResponse.getRecordWithSigner(this.wallet)
|
||||
this.logger.info(`topic created, cost: ${record.transactionFee.toString()}`)
|
||||
return parse(hieroIdSchema, createReceipt.topicId?.toString())
|
||||
return v.parse(hieroIdSchema, createReceipt.topicId?.toString())
|
||||
}
|
||||
|
||||
public async updateTopic(topicId: HieroId): Promise<void> {
|
||||
|
||||
@ -1,16 +1,16 @@
|
||||
import dotenv from 'dotenv'
|
||||
import { InferOutput, parse, ValiError } from 'valibot'
|
||||
import * as v from 'valibot'
|
||||
import { configSchema } from './schema'
|
||||
|
||||
dotenv.config()
|
||||
|
||||
type ConfigOutput = InferOutput<typeof configSchema>
|
||||
type ConfigOutput = v.InferOutput<typeof configSchema>
|
||||
|
||||
let config: ConfigOutput
|
||||
try {
|
||||
config = parse(configSchema, process.env)
|
||||
config = v.parse(configSchema, process.env)
|
||||
} catch (error) {
|
||||
if (error instanceof ValiError) {
|
||||
if (error instanceof v.ValiError) {
|
||||
// biome-ignore lint/suspicious/noConsole: need to parse config before initializing logger
|
||||
console.error(
|
||||
`${error.issues[0].path[0].key}: ${error.message} received: ${error.issues[0].received}`,
|
||||
|
||||
@ -2,14 +2,14 @@ import { readFileSync } from 'node:fs'
|
||||
import { Elysia } from 'elysia'
|
||||
import { loadCryptoKeys, MemoryBlock } from 'gradido-blockchain-js'
|
||||
import { configure, getLogger, Logger } from 'log4js'
|
||||
import { parse } from 'valibot'
|
||||
import * as v from 'valibot'
|
||||
import { KeyPairCacheManager } from './cache/KeyPairCacheManager'
|
||||
import { BackendClient } from './client/backend/BackendClient'
|
||||
import { GradidoNodeClient } from './client/GradidoNode/GradidoNodeClient'
|
||||
import { HieroClient } from './client/hiero/HieroClient'
|
||||
import { CONFIG } from './config'
|
||||
import { MIN_TOPIC_EXPIRE_MILLISECONDS_FOR_UPDATE } from './config/const'
|
||||
import { SendToHieroContext } from './interactions/sendToHiero/SendToHiero.context'
|
||||
import { KeyPairCacheManager } from './KeyPairCacheManager'
|
||||
import { Community, communitySchema } from './schemas/transaction.schema'
|
||||
import { appRoutes } from './server'
|
||||
import { isPortOpenRetry } from './utils/network'
|
||||
@ -133,7 +133,7 @@ async function homeCommunitySetup({ backend, hiero }: Clients, logger: Logger):
|
||||
logger.info(`home community topic: ${homeCommunity.hieroTopicId}`)
|
||||
logger.info(`gradido node server: ${CONFIG.NODE_SERVER_URL}`)
|
||||
logger.info(`gradido backend server: ${CONFIG.BACKEND_SERVER_URL}`)
|
||||
return parse(communitySchema, homeCommunity)
|
||||
return v.parse(communitySchema, homeCommunity)
|
||||
}
|
||||
|
||||
main().catch((e) => {
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
import { afterAll, beforeAll, describe, expect, it, mock } from 'bun:test'
|
||||
import { KeyPairEd25519, MemoryBlock } from 'gradido-blockchain-js'
|
||||
import { parse } from 'valibot'
|
||||
import * as v from 'valibot'
|
||||
import { KeyPairCacheManager } from '../../cache/KeyPairCacheManager'
|
||||
import { KeyPairIdentifierLogic } from '../../data/KeyPairIdentifier.logic'
|
||||
import { KeyPairCacheManager } from '../../KeyPairCacheManager'
|
||||
import { identifierKeyPairSchema } from '../../schemas/account.schema'
|
||||
import { HieroId, hieroIdSchema } from '../../schemas/typeGuard.schema'
|
||||
import { ResolveKeyPair } from './ResolveKeyPair.context'
|
||||
@ -41,11 +41,11 @@ afterAll(() => {
|
||||
|
||||
describe('KeyPairCalculation', () => {
|
||||
beforeAll(() => {
|
||||
KeyPairCacheManager.getInstance().setHomeCommunityTopicId(parse(hieroIdSchema, '0.0.21732'))
|
||||
KeyPairCacheManager.getInstance().setHomeCommunityTopicId(v.parse(hieroIdSchema, '0.0.21732'))
|
||||
})
|
||||
it('community key pair', async () => {
|
||||
const identifier = new KeyPairIdentifierLogic(
|
||||
parse(identifierKeyPairSchema, { communityTopicId: topicId }),
|
||||
v.parse(identifierKeyPairSchema, { communityTopicId: topicId }),
|
||||
)
|
||||
const keyPair = await ResolveKeyPair(identifier)
|
||||
expect(keyPair.getPublicKey()?.convertToHex()).toBe(
|
||||
@ -54,7 +54,7 @@ describe('KeyPairCalculation', () => {
|
||||
})
|
||||
it('user key pair', async () => {
|
||||
const identifier = new KeyPairIdentifierLogic(
|
||||
parse(identifierKeyPairSchema, {
|
||||
v.parse(identifierKeyPairSchema, {
|
||||
communityTopicId: topicId,
|
||||
account: { userUuid },
|
||||
}),
|
||||
@ -69,7 +69,7 @@ describe('KeyPairCalculation', () => {
|
||||
|
||||
it('account key pair', async () => {
|
||||
const identifier = new KeyPairIdentifierLogic(
|
||||
parse(identifierKeyPairSchema, {
|
||||
v.parse(identifierKeyPairSchema, {
|
||||
communityTopicId: topicId,
|
||||
account: { userUuid, accountNr: 1 },
|
||||
}),
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
import { KeyPairEd25519 } from 'gradido-blockchain-js'
|
||||
|
||||
import { KeyPairCacheManager } from '../../cache/KeyPairCacheManager'
|
||||
import { KeyPairIdentifierLogic } from '../../data/KeyPairIdentifier.logic'
|
||||
import { KeyPairCacheManager } from '../../KeyPairCacheManager'
|
||||
import { AccountKeyPairRole } from './AccountKeyPair.role'
|
||||
import { ForeignCommunityKeyPairRole } from './ForeignCommunityKeyPair.role'
|
||||
import { HomeCommunityKeyPairRole } from './HomeCommunityKeyPair.role'
|
||||
|
||||
@ -5,8 +5,8 @@ import {
|
||||
TransferAmount,
|
||||
} from 'gradido-blockchain-js'
|
||||
import { parse } from 'valibot'
|
||||
import { KeyPairCacheManager } from '../../cache/KeyPairCacheManager'
|
||||
import { KeyPairIdentifierLogic } from '../../data/KeyPairIdentifier.logic'
|
||||
import { KeyPairCacheManager } from '../../KeyPairCacheManager'
|
||||
import {
|
||||
CreationTransaction,
|
||||
creationTransactionSchema,
|
||||
|
||||
@ -5,7 +5,7 @@ import {
|
||||
GradidoTransfer,
|
||||
TransferAmount,
|
||||
} from 'gradido-blockchain-js'
|
||||
import { parse } from 'valibot'
|
||||
import * as v from 'valibot'
|
||||
import { KeyPairIdentifierLogic } from '../../data/KeyPairIdentifier.logic'
|
||||
import {
|
||||
DeferredTransferTransaction,
|
||||
@ -21,8 +21,8 @@ export class DeferredTransferTransactionRole extends AbstractTransactionRole {
|
||||
private readonly deferredTransferTransaction: DeferredTransferTransaction
|
||||
constructor(transaction: Transaction) {
|
||||
super()
|
||||
this.deferredTransferTransaction = parse(deferredTransferTransactionSchema, transaction)
|
||||
this.seed = parse(identifierSeedSchema, this.deferredTransferTransaction.linkedUser.seed)
|
||||
this.deferredTransferTransaction = v.parse(deferredTransferTransactionSchema, transaction)
|
||||
this.seed = v.parse(identifierSeedSchema, this.deferredTransferTransaction.linkedUser.seed)
|
||||
}
|
||||
|
||||
getSenderCommunityTopicId(): HieroId {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { GradidoTransactionBuilder, GradidoTransfer, TransferAmount } from 'gradido-blockchain-js'
|
||||
import { parse } from 'valibot'
|
||||
import * as v from 'valibot'
|
||||
import { GradidoNodeClient } from '../../client/GradidoNode/GradidoNodeClient'
|
||||
import { KeyPairIdentifierLogic } from '../../data/KeyPairIdentifier.logic'
|
||||
import {
|
||||
@ -17,7 +17,7 @@ export class RedeemDeferredTransferTransactionRole extends AbstractTransactionRo
|
||||
private readonly redeemDeferredTransferTransaction: RedeemDeferredTransferTransaction
|
||||
constructor(transaction: Transaction) {
|
||||
super()
|
||||
this.redeemDeferredTransferTransaction = parse(
|
||||
this.redeemDeferredTransferTransaction = v.parse(
|
||||
redeemDeferredTransferTransactionSchema,
|
||||
transaction,
|
||||
)
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { describe, expect, it } from 'bun:test'
|
||||
import { InteractionToJson, InteractionValidate, ValidateType_SINGLE } from 'gradido-blockchain-js'
|
||||
import { parse } from 'valibot'
|
||||
import * as v from 'valibot'
|
||||
import { transactionSchema } from '../../schemas/transaction.schema'
|
||||
import { hieroIdSchema } from '../../schemas/typeGuard.schema'
|
||||
import { RegisterAddressTransactionRole } from './RegisterAddressTransaction.role'
|
||||
@ -22,10 +22,10 @@ const transaction = {
|
||||
describe('RegisterAddressTransaction.role', () => {
|
||||
it('get correct prepared builder', async () => {
|
||||
const registerAddressTransactionRole = new RegisterAddressTransactionRole(
|
||||
parse(transactionSchema, transaction),
|
||||
v.parse(transactionSchema, transaction),
|
||||
)
|
||||
expect(registerAddressTransactionRole.getSenderCommunityTopicId()).toBe(
|
||||
parse(hieroIdSchema, '0.0.21732'),
|
||||
v.parse(hieroIdSchema, '0.0.21732'),
|
||||
)
|
||||
expect(() => registerAddressTransactionRole.getRecipientCommunityTopicId()).toThrow()
|
||||
const builder = await registerAddressTransactionRole.getGradidoTransactionBuilder()
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { AddressType, GradidoTransactionBuilder } from 'gradido-blockchain-js'
|
||||
import { parse } from 'valibot'
|
||||
import * as v from 'valibot'
|
||||
import { KeyPairIdentifierLogic } from '../../data/KeyPairIdentifier.logic'
|
||||
import { Uuidv4Hash } from '../../data/Uuidv4Hash'
|
||||
import {
|
||||
@ -20,8 +20,8 @@ export class RegisterAddressTransactionRole extends AbstractTransactionRole {
|
||||
private readonly account: IdentifierCommunityAccount
|
||||
constructor(input: Transaction) {
|
||||
super()
|
||||
this.registerAddressTransaction = parse(registerAddressTransactionSchema, input)
|
||||
this.account = parse(identifierCommunityAccountSchema, input.user.account)
|
||||
this.registerAddressTransaction = v.parse(registerAddressTransactionSchema, input)
|
||||
this.account = v.parse(identifierCommunityAccountSchema, input.user.account)
|
||||
}
|
||||
|
||||
getSenderCommunityTopicId(): HieroId {
|
||||
|
||||
@ -4,7 +4,7 @@ import {
|
||||
GradidoTransactionBuilder,
|
||||
TransferAmount,
|
||||
} from 'gradido-blockchain-js'
|
||||
import { parse } from 'valibot'
|
||||
import * as v from 'valibot'
|
||||
import { KeyPairIdentifierLogic } from '../../data/KeyPairIdentifier.logic'
|
||||
import {
|
||||
Transaction,
|
||||
@ -19,7 +19,7 @@ export class TransferTransactionRole extends AbstractTransactionRole {
|
||||
private transferTransaction: TransferTransaction
|
||||
constructor(input: Transaction) {
|
||||
super()
|
||||
this.transferTransaction = parse(transferTransactionSchema, input)
|
||||
this.transferTransaction = v.parse(transferTransactionSchema, input)
|
||||
}
|
||||
|
||||
getSenderCommunityTopicId(): HieroId {
|
||||
|
||||
@ -1,2 +0,0 @@
|
||||
import { MemoryBlock } from 'gradido-blockchain-js'
|
||||
import * as v from 'valibot'
|
||||
@ -4,7 +4,7 @@ import { TypeBoxFromValibot } from '@sinclair/typemap'
|
||||
import { randomBytes } from 'crypto'
|
||||
import { AddressType_COMMUNITY_HUMAN } from 'gradido-blockchain-js'
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
import { parse } from 'valibot'
|
||||
import * as v from 'valibot'
|
||||
import { AccountType } from '../enum/AccountType'
|
||||
import { InputTransactionType } from '../enum/InputTransactionType'
|
||||
import {
|
||||
@ -35,7 +35,7 @@ const transactionLinkCode = (date: Date): string => {
|
||||
let topic: HieroId
|
||||
const topicString = '0.0.261'
|
||||
beforeAll(() => {
|
||||
topic = parse(hieroIdSchema, topicString)
|
||||
topic = v.parse(hieroIdSchema, topicString)
|
||||
})
|
||||
|
||||
describe('transaction schemas', () => {
|
||||
@ -45,9 +45,9 @@ describe('transaction schemas', () => {
|
||||
let memo: Memo
|
||||
beforeAll(() => {
|
||||
userUuidString = uuidv4()
|
||||
userUuid = parse(uuidv4Schema, userUuidString)
|
||||
userUuid = v.parse(uuidv4Schema, userUuidString)
|
||||
memoString = 'TestMemo'
|
||||
memo = parse(memoSchema, memoString)
|
||||
memo = v.parse(memoSchema, memoString)
|
||||
})
|
||||
describe('register address', () => {
|
||||
let registerAddress: TransactionInput
|
||||
@ -63,7 +63,7 @@ describe('transaction schemas', () => {
|
||||
}
|
||||
})
|
||||
it('valid transaction schema', () => {
|
||||
expect(parse(transactionSchema, registerAddress)).toEqual({
|
||||
expect(v.parse(transactionSchema, registerAddress)).toEqual({
|
||||
user: {
|
||||
communityTopicId: topic,
|
||||
account: {
|
||||
@ -77,7 +77,7 @@ describe('transaction schemas', () => {
|
||||
})
|
||||
})
|
||||
it('valid register address schema', () => {
|
||||
expect(parse(registerAddressTransactionSchema, registerAddress)).toEqual({
|
||||
expect(v.parse(registerAddressTransactionSchema, registerAddress)).toEqual({
|
||||
user: {
|
||||
communityTopicId: topic,
|
||||
account: {
|
||||
@ -112,7 +112,7 @@ describe('transaction schemas', () => {
|
||||
type: InputTransactionType.GRADIDO_TRANSFER,
|
||||
createdAt: '2022-01-01T00:00:00.000Z',
|
||||
}
|
||||
expect(parse(transactionSchema, gradidoTransfer)).toEqual({
|
||||
expect(v.parse(transactionSchema, gradidoTransfer)).toEqual({
|
||||
user: {
|
||||
communityTopicId: topic,
|
||||
account: {
|
||||
@ -127,7 +127,7 @@ describe('transaction schemas', () => {
|
||||
accountNr: 0,
|
||||
},
|
||||
},
|
||||
amount: parse(gradidoAmountSchema, gradidoTransfer.amount!),
|
||||
amount: v.parse(gradidoAmountSchema, gradidoTransfer.amount!),
|
||||
memo,
|
||||
type: gradidoTransfer.type,
|
||||
createdAt: new Date(gradidoTransfer.createdAt),
|
||||
@ -150,7 +150,7 @@ describe('transaction schemas', () => {
|
||||
createdAt: '2022-01-01T00:00:00.000Z',
|
||||
targetDate: '2021-11-01T10:00',
|
||||
}
|
||||
expect(parse(transactionSchema, gradidoCreation)).toEqual({
|
||||
expect(v.parse(transactionSchema, gradidoCreation)).toEqual({
|
||||
user: {
|
||||
communityTopicId: topic,
|
||||
account: { userUuid, accountNr: 0 },
|
||||
@ -159,7 +159,7 @@ describe('transaction schemas', () => {
|
||||
communityTopicId: topic,
|
||||
account: { userUuid, accountNr: 0 },
|
||||
},
|
||||
amount: parse(gradidoAmountSchema, gradidoCreation.amount!),
|
||||
amount: v.parse(gradidoAmountSchema, gradidoCreation.amount!),
|
||||
memo,
|
||||
type: gradidoCreation.type,
|
||||
createdAt: new Date(gradidoCreation.createdAt),
|
||||
@ -168,7 +168,7 @@ describe('transaction schemas', () => {
|
||||
})
|
||||
it('valid, gradido transaction link / deferred transfer', () => {
|
||||
const seed = transactionLinkCode(new Date())
|
||||
const seedParsed = parse(identifierSeedSchema, seed)
|
||||
const seedParsed = v.parse(identifierSeedSchema, seed)
|
||||
const gradidoTransactionLink: TransactionInput = {
|
||||
user: {
|
||||
communityTopicId: topicString,
|
||||
@ -186,7 +186,7 @@ describe('transaction schemas', () => {
|
||||
createdAt: '2022-01-01T00:00:00.000Z',
|
||||
timeoutDuration: 60 * 60 * 24 * 30,
|
||||
}
|
||||
expect(parse(transactionSchema, gradidoTransactionLink)).toEqual({
|
||||
expect(v.parse(transactionSchema, gradidoTransactionLink)).toEqual({
|
||||
user: {
|
||||
communityTopicId: topic,
|
||||
account: {
|
||||
@ -198,11 +198,11 @@ describe('transaction schemas', () => {
|
||||
communityTopicId: topic,
|
||||
seed: seedParsed,
|
||||
},
|
||||
amount: parse(gradidoAmountSchema, gradidoTransactionLink.amount!),
|
||||
amount: v.parse(gradidoAmountSchema, gradidoTransactionLink.amount!),
|
||||
memo,
|
||||
type: gradidoTransactionLink.type,
|
||||
createdAt: new Date(gradidoTransactionLink.createdAt),
|
||||
timeoutDuration: parse(timeoutDurationSchema, gradidoTransactionLink.timeoutDuration!),
|
||||
timeoutDuration: v.parse(timeoutDurationSchema, gradidoTransactionLink.timeoutDuration!),
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
import { beforeAll, describe, expect, it, mock } from 'bun:test'
|
||||
import { AccountId, Timestamp, TransactionId } from '@hashgraph/sdk'
|
||||
import { GradidoTransaction, KeyPairEd25519, MemoryBlock } from 'gradido-blockchain-js'
|
||||
import { parse } from 'valibot'
|
||||
import { KeyPairCacheManager } from '../KeyPairCacheManager'
|
||||
import * as v from 'valibot'
|
||||
import { KeyPairCacheManager } from '../cache/KeyPairCacheManager'
|
||||
import { HieroId, hieroIdSchema } from '../schemas/typeGuard.schema'
|
||||
import { appRoutes } from '.'
|
||||
|
||||
@ -44,7 +44,7 @@ mock.module('../config', () => ({
|
||||
}))
|
||||
|
||||
beforeAll(() => {
|
||||
KeyPairCacheManager.getInstance().setHomeCommunityTopicId(parse(hieroIdSchema, '0.0.21732'))
|
||||
KeyPairCacheManager.getInstance().setHomeCommunityTopicId(v.parse(hieroIdSchema, '0.0.21732'))
|
||||
})
|
||||
|
||||
describe('Server', () => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user