44import { jest , expect , describe , test , beforeEach } from '@jest/globals'
55import BlockdaemonSigningDriver from './index.js'
66import { SigningAPIClient } from './signing-api-sdk.js'
7- import { Transaction } from '@canton-network/core-signing-lib'
7+ import { Transaction , Key } from '@canton-network/core-signing-lib'
88
99describe ( 'BlockdaemonSigningDriver' , ( ) => {
1010 const config = {
@@ -21,6 +21,10 @@ describe('BlockdaemonSigningDriver', () => {
2121
2222 mockClient = {
2323 signTransaction : jest . fn ( ) ,
24+ getTransaction : jest . fn ( ) ,
25+ getTransactions : jest . fn ( ) ,
26+ getKeys : jest . fn ( ) ,
27+ createKey : jest . fn ( ) ,
2428 } as unknown as jest . Mocked < SigningAPIClient >
2529
2630 driver = new BlockdaemonSigningDriver ( config )
@@ -67,4 +71,139 @@ describe('BlockdaemonSigningDriver', () => {
6771 publicKey : mockResponse . publicKey ,
6872 } )
6973 } )
74+
75+ test ( 'createKey calls client.createKey with correct params' , async ( ) => {
76+ const createKeyParams = {
77+ name : 'new-key' ,
78+ }
79+
80+ const mockResponse = {
81+ id : 'key-id' ,
82+ name : 'new-key' ,
83+ publicKey : 'new-public-key' ,
84+ }
85+
86+ mockClient . createKey . mockResolvedValue ( mockResponse as Key )
87+
88+ const result = await driver
89+ . controller ( userId )
90+ . createKey ( createKeyParams )
91+
92+ expect ( mockClient . createKey ) . toHaveBeenCalledWith ( {
93+ name : createKeyParams . name ,
94+ userIdentifier : userId ,
95+ } )
96+
97+ expect ( result ) . toEqual ( {
98+ id : mockResponse . id ,
99+ name : mockResponse . name ,
100+ publicKey : mockResponse . publicKey ,
101+ } )
102+ } )
103+
104+ test ( 'getTransaction calls client.getTransaction with correct params' , async ( ) => {
105+ const getTransactionParams = {
106+ txId : 'tx-id' ,
107+ }
108+
109+ const mockResponse = {
110+ txId : 'tx-id' ,
111+ status : 'signed' ,
112+ signature : 'signature-bytes' ,
113+ publicKey : 'some-public-key' ,
114+ }
115+
116+ mockClient . getTransaction . mockResolvedValue ( mockResponse as Transaction )
117+
118+ const result = await driver
119+ . controller ( userId )
120+ . getTransaction ( getTransactionParams )
121+
122+ expect ( mockClient . getTransaction ) . toHaveBeenCalledWith ( {
123+ txId : getTransactionParams . txId ,
124+ userIdentifier : userId ,
125+ } )
126+
127+ expect ( result ) . toEqual ( {
128+ txId : mockResponse . txId ,
129+ status : mockResponse . status ,
130+ signature : mockResponse . signature ,
131+ publicKey : mockResponse . publicKey ,
132+ } )
133+ } )
134+
135+ test ( 'getTransactions calls client.getTransactions with correct params' , async ( ) => {
136+ const getTransactionsParams = {
137+ txIds : [ 'tx-id-1' , 'tx-id-2' ] ,
138+ publicKeys : [ 'pk-1' ] ,
139+ }
140+
141+ const mockResponse = [
142+ {
143+ txId : 'tx-id-1' ,
144+ status : 'signed' ,
145+ signature : 'sig-1' ,
146+ publicKey : 'pk-1' ,
147+ } ,
148+ {
149+ txId : 'tx-id-2' ,
150+ status : 'pending' ,
151+ signature : 'sig-2' ,
152+ publicKey : 'pk-1' ,
153+ } ,
154+ ]
155+
156+ mockClient . getTransactions . mockResolvedValue (
157+ mockResponse as Transaction [ ]
158+ )
159+
160+ const result = await driver
161+ . controller ( userId )
162+ . getTransactions ( getTransactionsParams )
163+
164+ expect ( mockClient . getTransactions ) . toHaveBeenCalledWith ( {
165+ txIds : getTransactionsParams . txIds ,
166+ publicKeys : getTransactionsParams . publicKeys ,
167+ userIdentifier : userId ,
168+ } )
169+
170+ expect ( result ) . toEqual ( {
171+ transactions : mockResponse . map ( ( tx ) => ( {
172+ txId : tx . txId ,
173+ status : tx . status ,
174+ signature : tx . signature ,
175+ publicKey : tx . publicKey ,
176+ } ) ) ,
177+ } )
178+ } )
179+
180+ test ( 'getKeys calls client.getKeys with correct params' , async ( ) => {
181+ const mockResponse = [
182+ {
183+ id : 'key-1' ,
184+ name : 'Key 1' ,
185+ publicKey : 'pk-1' ,
186+ } ,
187+ {
188+ id : 'key-2' ,
189+ name : 'Key 2' ,
190+ publicKey : 'pk-2' ,
191+ } ,
192+ ]
193+
194+ mockClient . getKeys . mockResolvedValue ( mockResponse as Key [ ] )
195+
196+ const result = await driver . controller ( userId ) . getKeys ( )
197+
198+ expect ( mockClient . getKeys ) . toHaveBeenCalled ( )
199+
200+ expect ( result ) . toEqual ( {
201+ keys : mockResponse . map ( ( k ) => ( {
202+ id : k . id ,
203+ name : k . name ,
204+ publicKey : k . publicKey ,
205+ userIdentifier : userId ,
206+ } ) ) ,
207+ } )
208+ } )
70209} )
0 commit comments