aleeusgr / potential-robot

minimal dApp testing suite
MIT License
3 stars 1 forks source link

Error: transaction doesn't have enough inputs to cover the outputs + fees + minLovelace #105

Closed aleeusgr closed 1 year ago

aleeusgr commented 1 year ago
          Error: transaction doesn't have enough inputs to cover the outputs + fees + minLovelace

https://www.hyperion-bt.org/helios-book/api/reference/tx.html?highlight=addcoll#addcollateral

https://www.hyperion-bt.org/helios-book/api/reference/networkparams.html

Originally posted by @aleeusgr in https://github.com/aleeusgr/potential-robot/issues/104#issuecomment-1556605860

aleeusgr commented 1 year ago

I get an error in https://github.com/aleeusgr/potential-robot/blob/d799586672f3daf1ce59a769a35256435468c24b/tests/helios-vesting-cancel.test.ts#L135

tx.dump().body.collateral[0]:

```shell { + origOutput: { + address: { + bech32: 'addr_test1vz2a83z0d5gceyghfrjqpaqu2f98evk8q6swje2c5ddqmaca2vhfl', + hex: '6095d3c44f6d118c911748e400f41c524a7cb2c706a0e96558a35a0df7', + }, + datum: null, + refScript: null, + value: { + assets: {}, + lovelace: '59747752', + }, + }, + txId: '28e8c61f4da31df8541b4fca272dd66b6fb258404bba7a8c8d7fc75d7b00c5ef', + utxoIdx: '1', + } ```

tx.dump().body.inputs[0]:

```shell { + origOutput: { + address: { + bech32: 'addr_test1wqzs96thkxedr0jpak4ar9qp6ew58uwexmuz99ah93ckv0q6z8ey4', + hex: '700502e977b1b2d1be41edabd19401d65d43f1d936f82297b72c71663c', + }, + datum: { + inlineCbor: '9f581c95d3c44f6d118c911748e400f41c524a7cb2c706a0e96558a35a0df7581c3b61a40bc5872219ce830fb9c792d8 d53fb87921f590287057e4e3b41b000001867b8b7b00ff', + inlineSchema: { + list: [ + { + bytes: '95d3c44f6d118c911748e400f41c524a7cb2c706a0e96558a35a0df7', + }, + { + bytes: '3b61a40bc5872219ce830fb9c792d8d53fb87921f590287057e4e3b4', + }, + { + int: 1677109984000, + }, + ], + }, + }, refScript: null, + value: { + assets: { + '49b106e698de78171de2faf35932635e1085c12508ca87718a2d4487': { + '56657374696e67204b6579': '1', + }, + }, + lovelace: '10000000', + }, + }, + txId: '28e8c61f4da31df8541b4fca272dd66b6fb258404bba7a8c8d7fc75d7b00c5ef', + utxoIdx: '0', + } ```

christianschmitz commented 1 year ago

If you have some spare utxos, you could use them to cover those fees: tx.finalize(networkParams, changeAddress, spareUtxos)

christianschmitz commented 1 year ago

You need to dump the complete body to be able to debug this properly (i.e. all the inputs and all the outputs)

aleeusgr commented 1 year ago

@christianschmitz thank you for responding. I will experiment with utxos next, here is tx.dump().body:

{                                                                                                          [71/794]
  +   collateral: [                                                                                                    
  +     {                                                                                                              
  +       origOutput: {                                                                                                
  +         address: {                                                                                                 
  +           bech32: 'addr_test1vz2a83z0d5gceyghfrjqpaqu2f98evk8q6swje2c5ddqmaca2vhfl',                               
  +           hex: '6095d3c44f6d118c911748e400f41c524a7cb2c706a0e96558a35a0df7',                                       
  +         },                                                                                                         
  +         datum: null,                                                                                               
  +         refScript: null,                                                                                           
  +         value: {                                                                                                   
  +           assets: {},                                                                                              
  +           lovelace: '59747752',                                                                                    
  +         },
  +       },
  +       txId: '28e8c61f4da31df8541b4fca272dd66b6fb258404bba7a8c8d7fc75d7b00c5ef',
  +       utxoIdx: '1',
  +     },
  +   ],
  +   collateralReturn: null,
  +   fee: '0',
  +   firstValidSlot: null,
nputs: [                                                                                                [49/794]
  +     {                                                                                                              
  +       origOutput: {                                                                                                
  +         address: {                                                                                                 
  +           bech32: 'addr_test1wqzs96thkxedr0jpak4ar9qp6ew58uwexmuz99ah93ckv0q6z8ey4',                               
  +           hex: '700502e977b1b2d1be41edabd19401d65d43f1d936f82297b72c71663c',                                       
  +         },                                                                                                         
  +         datum: {                                                                                                   
  +           inlineCbor: '9f581c95d3c44f6d118c911748e400f41c524a7cb2c706a0e96558a35a0df7581c3b61a40bc5872219ce830fb9c7
92d8d53fb87921f590287057e4e3b41b000001867b8b7b00ff',                                                                   
  +           inlineSchema: {                                                                                          
  +             list: [                                                                                                
  +               {                                                                                                    
  +                 bytes: '95d3c44f6d118c911748e400f41c524a7cb2c706a0e96558a35a0df7',                                 
  +               },                                                                                                   
  +               {                                                                                                    
  +                 bytes: '3b61a40bc5872219ce830fb9c792d8d53fb87921f590287057e4e3b4',                                 
  +               },                                                                                                   
  +               {                                                                                                    
  +                 int: 1677109984000,                                                                                
  +               },                                                                                                   
  +             ],                                                                                                     
  +           },                                                                                                       
  +         },                                                                                                         
  +         refScript: null, 
+         value: {                                                                                           [24/794]
  +           assets: {
  +             '49b106e698de78171de2faf35932635e1085c12508ca87718a2d4487': {
  +               '56657374696e67204b6579': '1',
  +             },
  +           },
  +           lovelace: '10000000',
  +         },
  +       },
  +       txId: '28e8c61f4da31df8541b4fca272dd66b6fb258404bba7a8c8d7fc75d7b00c5ef',
  +       utxoIdx: '0',
  +     },
  +   ],
  +   lastValidSlot: null,
  +   metadataHash: null,
  +   minted: null,
  +   outputs: [
  +     {
  +       address: {
  +         bech32: 'addr_test1vz2a83z0d5gceyghfrjqpaqu2f98evk8q6swje2c5ddqmaca2vhfl',
  +         hex: '6095d3c44f6d118c911748e400f41c524a7cb2c706a0e96558a35a0df7',
  +       },
  +       datum: null,
  +       refScript: null,
  +       value: {
  +         assets: {
  +           '49b106e698de78171de2faf35932635e1085c12508ca87718a2d4487': {
+             '56657374696e67204b6579': '1',
  +           },
  +         },
  +         lovelace: '10000000',
  +       },
  +     },
  +   ],
  +   refInputs: [],
  +   scriptDataHash: null,
  +   signers: [
  +     '95d3c44f6d118c911748e400f41c524a7cb2c706a0e96558a35a0df7',
  +   ],
  + }
christianschmitz commented 1 year ago

total input: 10000000 total output: 10000000

And fees will be > 0. Including some spareUtxos will be the easiest way to cover the fees.

aleeusgr commented 1 year ago

I thought that the purpose of the collateral to cover fees. Fair enough I stand corrected.

:thinking: I network.createUtxo but it does not show up...

lockAda takes all utxos from a wallet and leaves it with only one, I think I should add an explanation to it.

Or should I fix it?

aleeusgr commented 1 year ago

My wallet does not have spare utxos: my lockAda tx had a list of utxos's as input, and the output of the lock transaction sends all the change to a single utxo in alice.address;

if I duplicate https://github.com/aleeusgr/potential-robot/blob/d799586672f3daf1ce59a769a35256435468c24b/tests/helios-vesting-cancel.test.ts#L43 even after a transaction, my test shows only one utxo in alice.address; maybe I can only add utxos to a wallet if it didn't have any transactions, only for emulator instantiation. :thinking: A good way to do is to have several utxos at emulator instantiation and have lockAda consume only one utxo.

aleeusgr commented 1 year ago

@christianschmitz thanks for your help, I solved it.

I changed tx building process so that it consumes only one utxo, while api requires a list. Adding all utxos seems to be bunching stuff up together in one utxo in the transaction output (I got change of its value if I added network.createUtxo, and if I did so after submitting a lockAda transaction, new utxos did not appear in the wallet address.)

https://github.com/aleeusgr/potential-robot/blob/ee83e60b62775bde4563e6cc4bb48c3f7c3296a7/src/lockAda.ts#L48