Skip to content

Commit d129b10

Browse files
committed
fix: address additional CodeRabbit review comments
- Fix missing parentheses in tests/minapp/index.ts toString() call - Add error handling to gRPC exchange promise chain - Remove async modifier from globalsetup.ts (no await needed) - Add race condition protection for pool initialization - Document DEV_CERT_PRIVATE_KEY as development-only test key
1 parent 14cacff commit d129b10

5 files changed

Lines changed: 19 additions & 7 deletions

File tree

src/Zemu.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ export default class Zemu {
9090
private static containerPool: ContainerPool | null = null
9191
private static poolEnabled: boolean = process.env.ZEMU_DISABLE_POOL !== 'true'
9292
private static poolInitialized = false
93+
private static poolInitPromise: Promise<void> | null = null
9394
private pooledContainer: IPooledContainer | null = null
9495
private usingPool = false
9596

@@ -258,7 +259,10 @@ export default class Zemu {
258259
try {
259260
// Initialize pool if not already done
260261
if (!Zemu.poolInitialized && Zemu.containerPool === null) {
261-
await Zemu.initializePool()
262+
if (!Zemu.poolInitPromise) {
263+
Zemu.poolInitPromise = Zemu.initializePool()
264+
}
265+
await Zemu.poolInitPromise
262266
}
263267

264268
if (!Zemu.containerPool || !Zemu.poolInitialized) {

src/emulator.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import path from 'node:path'
1818
import { Transform } from 'node:stream'
1919
import Docker, { type Container, type ContainerInfo } from 'dockerode'
2020

21+
// Development certificate key for emulator testing only - NOT FOR PRODUCTION USE
22+
// This is a well-known test key used by the Ledger emulator for development purposes
2123
export const DEV_CERT_PRIVATE_KEY = 'ff701d781f43ce106f72dc26a46b6a83e053b5d07bb3d4ceab79c91ca822a66b'
2224
export const BOLOS_SDK = '/project/deps/nanos-secure-sdk'
2325
export const DEFAULT_APP_PATH = '/project/app/bin'

src/grpc/index.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,15 @@ export default class GRPCRouter {
3434
this.server.addService(rpcDefinition.ledger_go.ZemuCommand.service, {
3535
Exchange(call: any, callback: any, ctx = self) {
3636
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
37-
void ctx.httpTransport.exchange(call.request.command).then((response: Buffer) => {
38-
callback(null, { reply: response })
39-
})
37+
void ctx.httpTransport
38+
.exchange(call.request.command)
39+
.then((response: Buffer) => {
40+
callback(null, { reply: response })
41+
})
42+
.catch((err: unknown) => {
43+
// propagate transport failure back to the client
44+
callback(err as Error)
45+
})
4046
},
4147
})
4248
this.server.bindAsync(this.serverAddress, ServerCredentials.createInsecure(), (err, port) => {

tests/globalsetup.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ const catchExit = () => {
77
})
88
}
99

10-
module.exports = async () => {
11-
await catchExit()
10+
module.exports = () => {
11+
catchExit()
1212
}

tests/minapp/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export function processErrorResponse(response: any) {
2525
if (Object.hasOwn(response, 'statusCode')) {
2626
return {
2727
return_code: response.statusCode,
28-
error_message: response.statusCode.toString,
28+
error_message: response.statusCode.toString(),
2929
}
3030
}
3131

0 commit comments

Comments
 (0)