mirror of
https://github.com/IT4Change/gradido.git
synced 2026-02-06 09:56:05 +00:00
fix test and lint
This commit is contained in:
parent
ed8f289405
commit
64008b1564
@ -140,13 +140,11 @@ export class DltConnectorClient {
|
||||
}
|
||||
return succeed
|
||||
} catch (e) {
|
||||
console.log("catch response dlt:", e)
|
||||
throw new LogError('Error send sending transaction to dlt-connector: ', e)
|
||||
}
|
||||
}
|
||||
|
||||
public async registerAddress(dbUser: User): Promise<TransactionResult | undefined> {
|
||||
console.log('dlt:registerAddress')
|
||||
const params = {
|
||||
input: {
|
||||
user: {
|
||||
@ -159,15 +157,12 @@ export class DltConnectorClient {
|
||||
} as UserAccountDraft,
|
||||
}
|
||||
try {
|
||||
console.log('before send with', params)
|
||||
const {
|
||||
data: { registerAddress: result },
|
||||
} = await this.client.rawRequest<{ registerAddress: TransactionResult }>(
|
||||
registerAddress,
|
||||
params,
|
||||
)
|
||||
console.log('after send')
|
||||
console.log('result: ', result)
|
||||
logger.info('send register address transaction to dlt-connector', {
|
||||
params,
|
||||
result,
|
||||
@ -177,7 +172,6 @@ export class DltConnectorClient {
|
||||
}
|
||||
return result
|
||||
} catch (e) {
|
||||
console.log('exception', e)
|
||||
logger.error('Exception sending register address transaction to dlt-connector', e)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
import { TransactionRecipe } from '@model/TransactionRecipe'
|
||||
import { Arg, Mutation, Query, Resolver } from 'type-graphql'
|
||||
import { QueryFailedError } from 'typeorm'
|
||||
|
||||
import { TransactionRecipe } from '@model/TransactionRecipe'
|
||||
|
||||
import { TRANSMIT_TO_IOTA_INTERRUPTIVE_SLEEP_KEY } from '@/data/const'
|
||||
import { UserRepository } from '@/data/User.repository'
|
||||
import { RegisterAddressContext } from '@/interactions/backendToDb/account/RegisterAddress.context'
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import 'reflect-metadata'
|
||||
import { Account } from '@entity/Account'
|
||||
import { Community } from '@entity/Community'
|
||||
import { Decimal } from 'decimal.js-light'
|
||||
import { v4 } from 'uuid'
|
||||
|
||||
@ -8,11 +9,14 @@ import { TestDB } from '@test/TestDB'
|
||||
import { CONFIG } from '@/config'
|
||||
import { KeyPair } from '@/data/KeyPair'
|
||||
import { Mnemonic } from '@/data/Mnemonic'
|
||||
import { AddressType } from '@/data/proto/3_3/enum/AddressType'
|
||||
import { CrossGroupType } from '@/data/proto/3_3/enum/CrossGroupType'
|
||||
import { TransactionType } from '@/data/proto/3_3/enum/TransactionType'
|
||||
import { TransactionBody } from '@/data/proto/3_3/TransactionBody'
|
||||
import { AccountType } from '@/graphql/enum/AccountType'
|
||||
import { InputTransactionType } from '@/graphql/enum/InputTransactionType'
|
||||
import { TransactionDraft } from '@/graphql/input/TransactionDraft'
|
||||
import { UserAccountDraft } from '@/graphql/input/UserAccountDraft'
|
||||
import { iotaTopicFromCommunityUUID } from '@/utils/typeConverter'
|
||||
|
||||
import { CreateTransactionRecipeContext } from './CreateTransactionRecipe.context'
|
||||
@ -39,6 +43,7 @@ let moderator: UserSet
|
||||
let firstUser: UserSet
|
||||
let secondUser: UserSet
|
||||
let foreignUser: UserSet
|
||||
let homeCommunity: Community
|
||||
|
||||
const topic = iotaTopicFromCommunityUUID(homeCommunityUuid)
|
||||
const foreignTopic = iotaTopicFromCommunityUUID(foreignCommunityUuid)
|
||||
@ -46,7 +51,7 @@ const foreignTopic = iotaTopicFromCommunityUUID(foreignCommunityUuid)
|
||||
describe('interactions/backendToDb/transaction/Create Transaction Recipe Context Test', () => {
|
||||
beforeAll(async () => {
|
||||
await TestDB.instance.setupTestDB()
|
||||
await communitySeed(homeCommunityUuid, false)
|
||||
homeCommunity = await communitySeed(homeCommunityUuid, false)
|
||||
await communitySeed(foreignCommunityUuid, true, foreignKeyPair)
|
||||
|
||||
moderator = createUserSet(homeCommunityUuid, keyPair)
|
||||
@ -66,6 +71,43 @@ describe('interactions/backendToDb/transaction/Create Transaction Recipe Context
|
||||
await TestDB.instance.teardownTestDB()
|
||||
})
|
||||
|
||||
it('register address transaction', async () => {
|
||||
const userAccountDraft = new UserAccountDraft()
|
||||
userAccountDraft.accountType = AccountType.COMMUNITY_HUMAN
|
||||
userAccountDraft.createdAt = new Date().toISOString()
|
||||
userAccountDraft.user = firstUser.identifier
|
||||
const context = new CreateTransactionRecipeContext(userAccountDraft, {
|
||||
account: firstUser.account,
|
||||
community: homeCommunity,
|
||||
})
|
||||
await context.run()
|
||||
const transaction = context.getTransactionRecipe()
|
||||
expect(transaction).toMatchObject({
|
||||
type: TransactionType.REGISTER_ADDRESS,
|
||||
protocolVersion: '3.3',
|
||||
community: {
|
||||
rootPubkey: keyPair.publicKey,
|
||||
foreign: 0,
|
||||
iotaTopic: topic,
|
||||
},
|
||||
signingAccount: {
|
||||
derive2Pubkey: firstUser.account.derive2Pubkey,
|
||||
},
|
||||
})
|
||||
|
||||
const body = TransactionBody.fromBodyBytes(transaction.bodyBytes)
|
||||
expect(body.registerAddress).toBeDefined()
|
||||
if (!body.registerAddress) throw new Error()
|
||||
|
||||
expect(body).toMatchObject({
|
||||
type: CrossGroupType.LOCAL,
|
||||
registerAddress: {
|
||||
derivationIndex: 1,
|
||||
addressType: AddressType.COMMUNITY_HUMAN,
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
it('creation transaction', async () => {
|
||||
const creationTransactionDraft = new TransactionDraft()
|
||||
creationTransactionDraft.amount = new Decimal('2000')
|
||||
|
||||
@ -45,7 +45,6 @@ export class CreateTransactionRecipeContext {
|
||||
*/
|
||||
public async run(): Promise<boolean> {
|
||||
if (this.draft instanceof TransactionDraft) {
|
||||
const transactionRecipeRole = new BalanceChangingTransactionRecipeRole()
|
||||
// contain logic for translation from backend to dlt-connector format
|
||||
let transactionTypeRole: AbstractTransactionRole
|
||||
switch (this.draft.type) {
|
||||
@ -59,7 +58,10 @@ export class CreateTransactionRecipeContext {
|
||||
transactionTypeRole = new ReceiveTransactionRole(this.draft)
|
||||
break
|
||||
}
|
||||
await transactionRecipeRole.create(this.draft, transactionTypeRole)
|
||||
this.transactionRecipe = await new BalanceChangingTransactionRecipeRole().create(
|
||||
this.draft,
|
||||
transactionTypeRole,
|
||||
)
|
||||
return true
|
||||
} else if (this.draft instanceof CommunityDraft) {
|
||||
if (!this.data?.community) {
|
||||
|
||||
@ -20,7 +20,7 @@ export const communitySeed = async (
|
||||
|
||||
const community = await Community.findOneOrFail({ where: { iotaTopic } })
|
||||
if (foreign && keyPair) {
|
||||
// that isn't entirely correct, normally only the public key from foreign community is know, and will be come form blockchain
|
||||
// that isn't entirely correct, normally only the public key from foreign community is known, and will be come form blockchain
|
||||
keyPair.fillInCommunityKeys(community)
|
||||
await community.save()
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user