text: /*
    Integration tests for the BITBOX. Only covers calls made to
    rest.bitcoin.com.
  
    TODO
  */
  
  const chai = require("chai")
  const assert = chai.assert
  const BITBOXSDK = require("../../src/bitbox-sdk").default
  const BITBOX = new BITBOXSDK()
  
  // Inspect utility used for debugging.
  const util = require("util")
  util.inspect.defaultOptions = {
    showHidden: true,
    colors: true,
    depth: 3
  }
  
  describe("#rawtransaction", () => {
    describe("#decodeRawTransaction", () => {
      it("should decode tx for a single hex", async () => {
        const hex =
          "0200000001b9b598d7d6d72fc486b2b3a3c03c79b5bade6ec9a77ced850515ab5e64edcc21010000006b483045022100a7b1b08956abb8d6f322aa709d8583c8ea492ba0585f1a6f4f9983520af74a5a0220411aee4a9a54effab617b0508c504c31681b15f9b187179b4874257badd4139041210360cfc66fdacb650bc4c83b4e351805181ee696b7d5ab4667c57b2786f51c413dffffffff0210270000000000001976a914eb4b180def88e3f5625b2d8ae2c098ff7d85f66488ac786e9800000000001976a914eb4b180def88e3f5625b2d8ae2c098ff7d85f66488ac00000000"
  
        const result = await BITBOX.RawTransactions.decodeRawTransaction(hex)
        //console.log(`result ${JSON.stringify(result, null, 2)}`)
  
        assert.hasAnyKeys(result, [
          "txid",
          "hash",
          "size",
          "version",
          "locktime",
          "vin",
          "vout"
        ])
        assert.isArray(result.vin)
        assert.isArray(result.vout)
      })
  
      it("should decode an array of tx hexes", async () => {
        const hexes = [
          "0200000001b9b598d7d6d72fc486b2b3a3c03c79b5bade6ec9a77ced850515ab5e64edcc21010000006b483045022100a7b1b08956abb8d6f322aa709d8583c8ea492ba0585f1a6f4f9983520af74a5a0220411aee4a9a54effab617b0508c504c31681b15f9b187179b4874257badd4139041210360cfc66fdacb650bc4c83b4e351805181ee696b7d5ab4667c57b2786f51c413dffffffff0210270000000000001976a914eb4b180def88e3f5625b2d8ae2c098ff7d85f66488ac786e9800000000001976a914eb4b180def88e3f5625b2d8ae2c098ff7d85f66488ac00000000",
          "0200000001b9b598d7d6d72fc486b2b3a3c03c79b5bade6ec9a77ced850515ab5e64edcc21010000006b483045022100a7b1b08956abb8d6f322aa709d8583c8ea492ba0585f1a6f4f9983520af74a5a0220411aee4a9a54effab617b0508c504c31681b15f9b187179b4874257badd4139041210360cfc66fdacb650bc4c83b4e351805181ee696b7d5ab4667c57b2786f51c413dffffffff0210270000000000001976a914eb4b180def88e3f5625b2d8ae2c098ff7d85f66488ac786e9800000000001976a914eb4b180def88e3f5625b2d8ae2c098ff7d85f66488ac00000000"
        ]
  
        const result = await BITBOX.RawTransactions.decodeRawTransaction(hexes)
        //console.log(`result ${JSON.stringify(result, null, 2)}`)
  
        assert.isArray(result)
        assert.hasAnyKeys(result[0], [
          "txid",
          "hash",
          "size",
          "version",
          "locktime",
          "vin",
          "vout"
        ])
        assert.isArray(result[0].vin)
        assert.isArray(result[0].vout)
      })
  
      it(`should throw an error for improper single input`, async () => {
        try {
          const addr = 12345
  
          await BITBOX.RawTransactions.decodeRawTransaction(addr)
          assert.equal(true, false, "Unexpected result!")
        } catch (err) {
          //console.log(`err: `, err)
          assert.include(
            err.message,
            `Input must be a string or array of strings.`
          )
        }
      })
    })
  
    describe("#getRawTransaction", () => {
      it("should decode a single txid, with concise output", async () => {
        const txid =
          "23213453b4642a73b4fc30d3112d72549ca153a8707255b14373b59e43558de1"
        const verbose = false
  
        const result = await BITBOX.RawTransactions.getRawTransaction(
          txid,
          verbose
        )
        //console.log(`result: ${JSON.stringify(result, null, 2)}`)
  
        assert.isString(result)
      })
  
      it("should decode a single txid, with verbose output", async () => {
        const txid =
          "23213453b4642a73b4fc30d3112d72549ca153a8707255b14373b59e43558de1"
        const verbose = true
  
        const result = await BITBOX.RawTransactions.getRawTransaction(
          txid,
          verbose
        )
        //console.log(`result: ${JSON.stringify(result, null, 2)}`)
  
        assert.hasAnyKeys(result, [
          "hex",
          "txid",
          "hash",
          "size",
          "version",
          "locktime",
          "vin",
          "vout",
          "blockhash",
          "confirmations",
          "time",
          "blocktime"
        ])
        assert.isArray(result.vin)
        assert.isArray(result.vout)
      })
  
      it("should decode an array of txids, with a concise output", async () => {
        const txid = [
          "23213453b4642a73b4fc30d3112d72549ca153a8707255b14373b59e43558de1",
          "b25d24fbb42d84812ed2cb55797f10fdec41afc7906ab563d1ec8c8676a2037f"
        ]
        const verbose = false
  
        const result = await BITBOX.RawTransactions.getRawTransaction(
          txid,
          verbose
        )
        //console.log(`result: ${JSON.stringify(result, null, 2)}`)
  
        assert.isArray(result)
        assert.isString(result[0])
      })
  
      it("should decode an array of txids, with a verbose output", async () => {
        const txid = [
          "23213453b4642a73b4fc30d3112d72549ca153a8707255b14373b59e43558de1",
          "b25d24fbb42d84812ed2cb55797f10fdec41afc7906ab563d1ec8c8676a2037f"
        ]
        const verbose = true
  
        const result = await BITBOX.RawTransactions.getRawTransaction(
          txid,
          verbose
        )
        //console.log(`result: ${JSON.stringify(result, null, 2)}`)
  
        assert.isArray(result)
        assert.hasAnyKeys(result[0], [
          "hex",
          "txid",
          "hash",
          "size",
          "version",
          "locktime",
          "vin",
          "vout",
          "blockhash",
          "confirmations",
          "time",
          "blocktime"
        ])
        assert.isArray(result[0].vin)
        assert.isArray(result[0].vout)
      })
    })
  })
  