HathorNetwork / hathor-explorer-service

MIT License
1 stars 3 forks source link

feat: change push_tx to post #256

Closed r4mmer closed 1 year ago

r4mmer commented 1 year ago

Acceptance Criteria

Security Checklist

r4mmer commented 1 year ago

To test this api you need a valid signed and mined transaction hex. This script helps with this:

const hathorLib = require('@hathor/wallet-lib'); // or require('.') if running on wallet-lib

const connection = new hathorLib.Connection({
    network: 'mainnet',
    servers: ['https://node1.mainnet.hathor.network/v1a/'],
    connectionTimeout: 5000,
});

connection.on('wallet-load-partial-update', console.log)

const seed = '<put your seed here>';

const store = new hathorLib.MemoryStore();
const storage = new hathorLib.Storage(store);
const walletConfig = {
    seed,
    pinCode: '1234',
    password: '1234',
    connection,
    storage,
};

const wallet = new hathorLib.HathorWallet(walletConfig);

async function waitReady(w) {
  while (!w.isReady()) {
    await new Promise(res => setTimeout(() => { res() }, 1000));
  }
  console.log('wallet ready');
}

async function main() {
  wallet.start().then(console.log);
  await waitReady(wallet);
  const addr = await wallet.getCurrentAddress();

  const balance = await wallet.getBalance('00');
  console.log(JSON.stringify(balance, null, 2));

  const sendTx = new hathorLib.SendTransaction({
    pin: '1234',
    storage: wallet.storage,
    outputs: [{ type: 'p2pkh', address: addr.address, value: 1, token: '00' }],
  });

  const tx = await sendTx.run('mine-tx');
  // const tx = await sendTx.run('prepare-tx');
  console.log(tx);
  console.log(tx.toHex());
}

main();
r4mmer commented 1 year ago

The code looks good to me. ✔️

I'm only wondering why we don't have refactored tests for the changed route. Shouldn't the previous tests stop working as we changed the verb and the parameters from query to body?

The tests do not cover the api handlers, only the gateways and usecases, these receive hex_tx as a parameters and not the request dict. So the tests stay the same while the handler just extracts the data from a different place in the request.