import { getDcomm, createTests, Matcher } from "./e2etestlib"
import { KeystoreAPI } from "src/apis/keystore/api"
import BN from "bn.js"
import Dcomm from "src"
import { EVMAPI } from "src/apis/evm"

describe("ACTChain", (): void => {
  const dcomm: Dcomm = getDcomm()
  const actchain: EVMAPI = dcomm.ACTChain()
  const keystore: KeystoreAPI = dcomm.NodeKeys()

  let exportTxHash = { value: "" }

  const user: string = "dcommJsACTChainUser"
  const passwd: string = "dcommJsP@ssw4rd"
  const key: string =
    "PrivateKey-ewoqjP7PxY4yr3iLTpLisriqt94hdyDFNgchSxGGztUrTXtNN"
  const privateKeyHex: string =
    "0x56289e99c94b6912bfc12adc093c9b51124f0dc54ac7a766b2bc5ccf558d8027"
  const whaleAddr: string = "0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC"
  const astChainAddr: string = "AST-custom18jma8ppw3nhx5r4ap8clazz0dps7rv5u9xde7p"

  // test_name        response_promise                            resp_fn          matcher           expected_value/obtained_value
  const tests_spec: any = [
    [
      "createUser",
      () => keystore.createUser(user, passwd),
      (x) => x,
      Matcher.toEqual,
      () => { return {} }
    ],
    [
      "importKey",
      () => actchain.importKey(user, passwd, key),
      (x) => x,
      Matcher.toBe,
      () => whaleAddr
    ],
    [
      "exportDCM",
      () => actchain.exportDCM(user, passwd, astChainAddr, new BN(10)),
      (x) => x,
      Matcher.Get,
      () => exportTxHash
    ],
    [
      "getBaseFee",
      () => actchain.getBaseFee(),
      (x) => x,
      Matcher.toBe,
      () => "0x34630b8a00"
    ],
    [
      "getMaxPriorityFeePerGas",
      () => actchain.getMaxPriorityFeePerGas(),
      (x) => x,
      Matcher.toBe,
      () => "0x0"
    ],
    [
      "exportKey",
      () => actchain.exportKey(user, passwd, whaleAddr),
      (x) => x,
      Matcher.toEqual,
      () => ({
        privateKey: key,
        privateKeyHex: privateKeyHex
      })
    ]
  ]

  createTests(tests_spec)
})