@@ -114,3 +114,52 @@ test('buildTransaction for transfer - snapshot', async () => {
114114
115115 expect ( result ) . toMatchSnapshot ( ) ;
116116} ) ;
117+
118+
119+ test ( 'transfer returns signed tx' , async ( ) => {
120+ const client = await Client . create ( { network : 'testnet' , autoRestore : false } ) ;
121+ await client . connect ( ) ;
122+
123+ const result = await client . transfer ( {
124+ to : 'tmt1q9mfg7d6ul2nt5yhmm7l7r6wwyqkd822rymr83uc' ,
125+ amount : 10 ,
126+ } ) ;
127+
128+ expect ( result ) . toBe ( 'signed-transaction' ) ;
129+ } ) ;
130+
131+ test ( 'buildTransaction called with correct params' , async ( ) => {
132+ const spy = jest . spyOn ( Client . prototype as any , 'buildTransaction' ) ;
133+ const client = await Client . create ( { network : 'testnet' , autoRestore : false } ) ;
134+
135+ await client . connect ( ) ;
136+
137+ await client . transfer ( {
138+ to : 'tmt1q9mfg7d6ul2nt5yhmm7l7r6wwyqkd822rymr83uc' ,
139+ amount : 5 ,
140+ } ) ;
141+
142+ expect ( spy ) . toHaveBeenCalledWith ( {
143+ type : 'Transfer' ,
144+ params : expect . objectContaining ( {
145+ to : 'tmt1q9mfg7d6ul2nt5yhmm7l7r6wwyqkd822rymr83uc' ,
146+ amount : 5 ,
147+ } ) ,
148+ } ) ;
149+ } ) ;
150+
151+ test ( 'fails transfer if not enough utxo' , async ( ) => {
152+ fetchMock . mockIf ( 'https://api.mintini.app/account' , async ( ) => {
153+ return {
154+ body : JSON . stringify ( { utxos : [ ] } ) , // no utxos
155+ } ;
156+ } ) ;
157+
158+ const client = await Client . create ( { network : 'testnet' , autoRestore : false } ) ;
159+ await client . connect ( ) ;
160+
161+ await expect ( client . transfer ( {
162+ to : 'tmt1q9mfg7d6ul2nt5yhmm7l7r6wwyqkd822rymr83uc' ,
163+ amount : 999999999 ,
164+ } ) ) . rejects . toThrow ( 'Not enough coin UTXOs' ) ;
165+ } ) ;
0 commit comments