You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

748 lines
18 KiB

9 years ago
9 years ago
9 years ago
9 years ago
8 years ago
8 years ago
9 years ago
8 years ago
8 years ago
9 years ago
7 years ago
7 years ago
9 years ago
9 years ago
7 years ago
7 years ago
7 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
  1. package main
  2. import (
  3. "bufio"
  4. "encoding/hex"
  5. "errors"
  6. "fmt"
  7. "io"
  8. "os"
  9. "strings"
  10. "github.com/spf13/cobra"
  11. cmn "github.com/tendermint/tmlibs/common"
  12. "github.com/tendermint/tmlibs/log"
  13. abcicli "github.com/tendermint/abci/client"
  14. "github.com/tendermint/abci/example/code"
  15. "github.com/tendermint/abci/example/counter"
  16. "github.com/tendermint/abci/example/dummy"
  17. "github.com/tendermint/abci/server"
  18. servertest "github.com/tendermint/abci/tests/server"
  19. "github.com/tendermint/abci/types"
  20. "github.com/tendermint/abci/version"
  21. )
  22. // client is a global variable so it can be reused by the console
  23. var (
  24. client abcicli.Client
  25. logger log.Logger
  26. )
  27. // flags
  28. var (
  29. // global
  30. flagAddress string
  31. flagAbci string
  32. flagVerbose bool // for the println output
  33. flagLogLevel string // for the logger
  34. // query
  35. flagPath string
  36. flagHeight int
  37. flagProve bool
  38. // counter
  39. flagAddrC string
  40. flagSerial bool
  41. // dummy
  42. flagAddrD string
  43. flagPersist string
  44. )
  45. var RootCmd = &cobra.Command{
  46. Use: "abci-cli",
  47. Short: "the ABCI CLI tool wraps an ABCI client",
  48. Long: "the ABCI CLI tool wraps an ABCI client and is used for testing ABCI servers",
  49. PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
  50. switch cmd.Use {
  51. case "counter", "dummy": // for the examples apps, don't pre-run
  52. return nil
  53. case "version": // skip running for version command
  54. return nil
  55. }
  56. if logger == nil {
  57. allowLevel, err := log.AllowLevel(flagLogLevel)
  58. if err != nil {
  59. return err
  60. }
  61. logger = log.NewFilter(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), allowLevel)
  62. }
  63. if client == nil {
  64. var err error
  65. client, err = abcicli.NewClient(flagAddress, flagAbci, false)
  66. if err != nil {
  67. return err
  68. }
  69. client.SetLogger(logger.With("module", "abci-client"))
  70. if err := client.Start(); err != nil {
  71. return err
  72. }
  73. }
  74. return nil
  75. },
  76. }
  77. // Structure for data passed to print response.
  78. type response struct {
  79. // generic abci response
  80. Data []byte
  81. Code uint32
  82. Log string
  83. Query *queryResponse
  84. }
  85. type queryResponse struct {
  86. Key []byte
  87. Value []byte
  88. Height int64
  89. Proof []byte
  90. }
  91. func Execute() error {
  92. addGlobalFlags()
  93. addCommands()
  94. return RootCmd.Execute()
  95. }
  96. func addGlobalFlags() {
  97. RootCmd.PersistentFlags().StringVarP(&flagAddress, "address", "", "tcp://0.0.0.0:46658", "address of application socket")
  98. RootCmd.PersistentFlags().StringVarP(&flagAbci, "abci", "", "socket", "either socket or grpc")
  99. RootCmd.PersistentFlags().BoolVarP(&flagVerbose, "verbose", "v", false, "print the command and results as if it were a console session")
  100. RootCmd.PersistentFlags().StringVarP(&flagLogLevel, "log_level", "", "debug", "set the logger level")
  101. }
  102. func addQueryFlags() {
  103. queryCmd.PersistentFlags().StringVarP(&flagPath, "path", "", "/store", "path to prefix query with")
  104. queryCmd.PersistentFlags().IntVarP(&flagHeight, "height", "", 0, "height to query the blockchain at")
  105. queryCmd.PersistentFlags().BoolVarP(&flagProve, "prove", "", false, "whether or not to return a merkle proof of the query result")
  106. }
  107. func addCounterFlags() {
  108. counterCmd.PersistentFlags().StringVarP(&flagAddrC, "addr", "", "tcp://0.0.0.0:46658", "listen address")
  109. counterCmd.PersistentFlags().BoolVarP(&flagSerial, "serial", "", false, "enforce incrementing (serial) transactions")
  110. }
  111. func addDummyFlags() {
  112. dummyCmd.PersistentFlags().StringVarP(&flagAddrD, "addr", "", "tcp://0.0.0.0:46658", "listen address")
  113. dummyCmd.PersistentFlags().StringVarP(&flagPersist, "persist", "", "", "directory to use for a database")
  114. }
  115. func addCommands() {
  116. RootCmd.AddCommand(batchCmd)
  117. RootCmd.AddCommand(consoleCmd)
  118. RootCmd.AddCommand(echoCmd)
  119. RootCmd.AddCommand(infoCmd)
  120. RootCmd.AddCommand(setOptionCmd)
  121. RootCmd.AddCommand(deliverTxCmd)
  122. RootCmd.AddCommand(checkTxCmd)
  123. RootCmd.AddCommand(commitCmd)
  124. RootCmd.AddCommand(versionCmd)
  125. RootCmd.AddCommand(testCmd)
  126. addQueryFlags()
  127. RootCmd.AddCommand(queryCmd)
  128. // examples
  129. addCounterFlags()
  130. RootCmd.AddCommand(counterCmd)
  131. addDummyFlags()
  132. RootCmd.AddCommand(dummyCmd)
  133. }
  134. var batchCmd = &cobra.Command{
  135. Use: "batch",
  136. Short: "run a batch of abci commands against an application",
  137. Long: `run a batch of abci commands against an application
  138. This command is run by piping in a file containing a series of commands
  139. you'd like to run:
  140. abci-cli batch < example.file
  141. where example.file looks something like:
  142. set_option serial on
  143. check_tx 0x00
  144. check_tx 0xff
  145. deliver_tx 0x00
  146. check_tx 0x00
  147. deliver_tx 0x01
  148. deliver_tx 0x04
  149. info
  150. `,
  151. Args: cobra.ExactArgs(0),
  152. RunE: func(cmd *cobra.Command, args []string) error {
  153. return cmdBatch(cmd, args)
  154. },
  155. }
  156. var consoleCmd = &cobra.Command{
  157. Use: "console",
  158. Short: "start an interactive ABCI console for multiple commands",
  159. Long: `start an interactive ABCI console for multiple commands
  160. This command opens an interactive console for running any of the other commands
  161. without opening a new connection each time
  162. `,
  163. Args: cobra.ExactArgs(0),
  164. ValidArgs: []string{"echo", "info", "set_option", "deliver_tx", "check_tx", "commit", "query"},
  165. RunE: func(cmd *cobra.Command, args []string) error {
  166. return cmdConsole(cmd, args)
  167. },
  168. }
  169. var echoCmd = &cobra.Command{
  170. Use: "echo",
  171. Short: "have the application echo a message",
  172. Long: "have the application echo a message",
  173. Args: cobra.ExactArgs(1),
  174. RunE: func(cmd *cobra.Command, args []string) error {
  175. return cmdEcho(cmd, args)
  176. },
  177. }
  178. var infoCmd = &cobra.Command{
  179. Use: "info",
  180. Short: "get some info about the application",
  181. Long: "get some info about the application",
  182. Args: cobra.ExactArgs(0),
  183. RunE: func(cmd *cobra.Command, args []string) error {
  184. return cmdInfo(cmd, args)
  185. },
  186. }
  187. var setOptionCmd = &cobra.Command{
  188. Use: "set_option",
  189. Short: "set an option on the application",
  190. Long: "set an option on the application",
  191. Args: cobra.ExactArgs(2),
  192. RunE: func(cmd *cobra.Command, args []string) error {
  193. return cmdSetOption(cmd, args)
  194. },
  195. }
  196. var deliverTxCmd = &cobra.Command{
  197. Use: "deliver_tx",
  198. Short: "deliver a new transaction to the application",
  199. Long: "deliver a new transaction to the application",
  200. Args: cobra.ExactArgs(1),
  201. RunE: func(cmd *cobra.Command, args []string) error {
  202. return cmdDeliverTx(cmd, args)
  203. },
  204. }
  205. var checkTxCmd = &cobra.Command{
  206. Use: "check_tx",
  207. Short: "validate a transaction",
  208. Long: "validate a transaction",
  209. Args: cobra.ExactArgs(1),
  210. RunE: func(cmd *cobra.Command, args []string) error {
  211. return cmdCheckTx(cmd, args)
  212. },
  213. }
  214. var commitCmd = &cobra.Command{
  215. Use: "commit",
  216. Short: "commit the application state and return the Merkle root hash",
  217. Long: "commit the application state and return the Merkle root hash",
  218. Args: cobra.ExactArgs(0),
  219. RunE: func(cmd *cobra.Command, args []string) error {
  220. return cmdCommit(cmd, args)
  221. },
  222. }
  223. var versionCmd = &cobra.Command{
  224. Use: "version",
  225. Short: "print ABCI console version",
  226. Long: "print ABCI console version",
  227. Args: cobra.ExactArgs(0),
  228. RunE: func(cmd *cobra.Command, args []string) error {
  229. fmt.Println(version.Version)
  230. return nil
  231. },
  232. }
  233. var queryCmd = &cobra.Command{
  234. Use: "query",
  235. Short: "query the application state",
  236. Long: "query the application state",
  237. Args: cobra.ExactArgs(1),
  238. RunE: func(cmd *cobra.Command, args []string) error {
  239. return cmdQuery(cmd, args)
  240. },
  241. }
  242. var counterCmd = &cobra.Command{
  243. Use: "counter",
  244. Short: "ABCI demo example",
  245. Long: "ABCI demo example",
  246. Args: cobra.ExactArgs(0),
  247. RunE: func(cmd *cobra.Command, args []string) error {
  248. return cmdCounter(cmd, args)
  249. },
  250. }
  251. var dummyCmd = &cobra.Command{
  252. Use: "dummy",
  253. Short: "ABCI demo example",
  254. Long: "ABCI demo example",
  255. Args: cobra.ExactArgs(0),
  256. RunE: func(cmd *cobra.Command, args []string) error {
  257. return cmdDummy(cmd, args)
  258. },
  259. }
  260. var testCmd = &cobra.Command{
  261. Use: "test",
  262. Short: "run integration tests",
  263. Long: "run integration tests",
  264. Args: cobra.ExactArgs(0),
  265. RunE: func(cmd *cobra.Command, args []string) error {
  266. return cmdTest(cmd, args)
  267. },
  268. }
  269. // Generates new Args array based off of previous call args to maintain flag persistence
  270. func persistentArgs(line []byte) []string {
  271. // generate the arguments to run from original os.Args
  272. // to maintain flag arguments
  273. args := os.Args
  274. args = args[:len(args)-1] // remove the previous command argument
  275. if len(line) > 0 { // prevents introduction of extra space leading to argument parse errors
  276. args = append(args, strings.Split(string(line), " ")...)
  277. }
  278. return args
  279. }
  280. //--------------------------------------------------------------------------------
  281. func compose(fs []func() error) error {
  282. if len(fs) == 0 {
  283. return nil
  284. } else {
  285. err := fs[0]()
  286. if err == nil {
  287. return compose(fs[1:])
  288. } else {
  289. return err
  290. }
  291. }
  292. }
  293. func cmdTest(cmd *cobra.Command, args []string) error {
  294. return compose(
  295. []func() error{
  296. func() error { return servertest.InitChain(client) },
  297. func() error { return servertest.SetOption(client, "serial", "on") },
  298. func() error { return servertest.Commit(client, nil) },
  299. func() error { return servertest.DeliverTx(client, []byte("abc"), code.CodeTypeBadNonce, nil) },
  300. func() error { return servertest.Commit(client, nil) },
  301. func() error { return servertest.DeliverTx(client, []byte{0x00}, code.CodeTypeOK, nil) },
  302. func() error { return servertest.Commit(client, []byte{0, 0, 0, 0, 0, 0, 0, 1}) },
  303. func() error { return servertest.DeliverTx(client, []byte{0x00}, code.CodeTypeBadNonce, nil) },
  304. func() error { return servertest.DeliverTx(client, []byte{0x01}, code.CodeTypeOK, nil) },
  305. func() error { return servertest.DeliverTx(client, []byte{0x00, 0x02}, code.CodeTypeOK, nil) },
  306. func() error { return servertest.DeliverTx(client, []byte{0x00, 0x03}, code.CodeTypeOK, nil) },
  307. func() error { return servertest.DeliverTx(client, []byte{0x00, 0x00, 0x04}, code.CodeTypeOK, nil) },
  308. func() error {
  309. return servertest.DeliverTx(client, []byte{0x00, 0x00, 0x06}, code.CodeTypeBadNonce, nil)
  310. },
  311. func() error { return servertest.Commit(client, []byte{0, 0, 0, 0, 0, 0, 0, 5}) },
  312. })
  313. }
  314. func cmdBatch(cmd *cobra.Command, args []string) error {
  315. bufReader := bufio.NewReader(os.Stdin)
  316. for {
  317. line, more, err := bufReader.ReadLine()
  318. if more {
  319. return errors.New("Input line is too long")
  320. } else if err == io.EOF {
  321. break
  322. } else if len(line) == 0 {
  323. continue
  324. } else if err != nil {
  325. return err
  326. }
  327. cmdArgs := persistentArgs(line)
  328. if err := muxOnCommands(cmd, cmdArgs); err != nil {
  329. return err
  330. }
  331. fmt.Println()
  332. }
  333. return nil
  334. }
  335. func cmdConsole(cmd *cobra.Command, args []string) error {
  336. for {
  337. fmt.Printf("> ")
  338. bufReader := bufio.NewReader(os.Stdin)
  339. line, more, err := bufReader.ReadLine()
  340. if more {
  341. return errors.New("Input is too long")
  342. } else if err != nil {
  343. return err
  344. }
  345. pArgs := persistentArgs(line)
  346. if err := muxOnCommands(cmd, pArgs); err != nil {
  347. return err
  348. }
  349. }
  350. return nil
  351. }
  352. func muxOnCommands(cmd *cobra.Command, pArgs []string) error {
  353. if len(pArgs) < 2 {
  354. return errors.New("expecting persistent args of the form: abci-cli [command] <...>")
  355. }
  356. // TODO: this parsing is fragile
  357. args := []string{}
  358. for i := 0; i < len(pArgs); i++ {
  359. arg := pArgs[i]
  360. // check for flags
  361. if strings.HasPrefix(arg, "-") {
  362. // if it has an equal, we can just skip
  363. if strings.Contains(arg, "=") {
  364. continue
  365. }
  366. // if its a boolean, we can just skip
  367. _, err := cmd.Flags().GetBool(strings.TrimLeft(arg, "-"))
  368. if err == nil {
  369. continue
  370. }
  371. // otherwise, we need to skip the next one too
  372. i += 1
  373. continue
  374. }
  375. // append the actual arg
  376. args = append(args, arg)
  377. }
  378. var subCommand string
  379. var actualArgs []string
  380. if len(args) > 1 {
  381. subCommand = args[1]
  382. }
  383. if len(args) > 2 {
  384. actualArgs = args[2:]
  385. }
  386. cmd.Use = subCommand // for later print statements ...
  387. switch strings.ToLower(subCommand) {
  388. case "check_tx":
  389. return cmdCheckTx(cmd, actualArgs)
  390. case "commit":
  391. return cmdCommit(cmd, actualArgs)
  392. case "deliver_tx":
  393. return cmdDeliverTx(cmd, actualArgs)
  394. case "echo":
  395. return cmdEcho(cmd, actualArgs)
  396. case "info":
  397. return cmdInfo(cmd, actualArgs)
  398. case "query":
  399. return cmdQuery(cmd, actualArgs)
  400. case "set_option":
  401. return cmdSetOption(cmd, actualArgs)
  402. default:
  403. return cmdUnimplemented(cmd, pArgs)
  404. }
  405. }
  406. func cmdUnimplemented(cmd *cobra.Command, args []string) error {
  407. // TODO: Print out all the sub-commands available
  408. msg := "unimplemented command"
  409. if err := cmd.Help(); err != nil {
  410. msg = err.Error()
  411. }
  412. if len(args) > 0 {
  413. msg += fmt.Sprintf(" args: [%s]", strings.Join(args, " "))
  414. }
  415. printResponse(cmd, args, response{
  416. Code: codeBad,
  417. Log: msg,
  418. })
  419. return nil
  420. }
  421. // Have the application echo a message
  422. func cmdEcho(cmd *cobra.Command, args []string) error {
  423. msg := ""
  424. if len(args) > 0 {
  425. msg = args[0]
  426. }
  427. res, err := client.EchoSync(msg)
  428. if err != nil {
  429. return err
  430. }
  431. printResponse(cmd, args, response{
  432. Data: []byte(res.Message),
  433. })
  434. return nil
  435. }
  436. // Get some info from the application
  437. func cmdInfo(cmd *cobra.Command, args []string) error {
  438. var version string
  439. if len(args) == 1 {
  440. version = args[0]
  441. }
  442. res, err := client.InfoSync(types.RequestInfo{version})
  443. if err != nil {
  444. return err
  445. }
  446. printResponse(cmd, args, response{
  447. Data: []byte(res.Data),
  448. })
  449. return nil
  450. }
  451. const codeBad uint32 = 10
  452. // Set an option on the application
  453. func cmdSetOption(cmd *cobra.Command, args []string) error {
  454. if len(args) < 2 {
  455. printResponse(cmd, args, response{
  456. Code: codeBad,
  457. Log: "want at least arguments of the form: <key> <value>",
  458. })
  459. return nil
  460. }
  461. key, val := args[0], args[1]
  462. res, err := client.SetOptionSync(types.RequestSetOption{key, val})
  463. if err != nil {
  464. return err
  465. }
  466. printResponse(cmd, args, response{
  467. Code: res.Code,
  468. Log: res.Log,
  469. })
  470. return nil
  471. }
  472. // Append a new tx to application
  473. func cmdDeliverTx(cmd *cobra.Command, args []string) error {
  474. if len(args) == 0 {
  475. printResponse(cmd, args, response{
  476. Code: codeBad,
  477. Log: "want the tx",
  478. })
  479. return nil
  480. }
  481. txBytes, err := stringOrHexToBytes(args[0])
  482. if err != nil {
  483. return err
  484. }
  485. res, err := client.DeliverTxSync(txBytes)
  486. if err != nil {
  487. return err
  488. }
  489. printResponse(cmd, args, response{
  490. Code: res.Code,
  491. Data: res.Data,
  492. Log: res.Log,
  493. })
  494. return nil
  495. }
  496. // Validate a tx
  497. func cmdCheckTx(cmd *cobra.Command, args []string) error {
  498. if len(args) == 0 {
  499. printResponse(cmd, args, response{
  500. Code: codeBad,
  501. Log: "want the tx",
  502. })
  503. return nil
  504. }
  505. txBytes, err := stringOrHexToBytes(args[0])
  506. if err != nil {
  507. return err
  508. }
  509. res, err := client.CheckTxSync(txBytes)
  510. if err != nil {
  511. return err
  512. }
  513. printResponse(cmd, args, response{
  514. Code: res.Code,
  515. Data: res.Data,
  516. Log: res.Log,
  517. })
  518. return nil
  519. }
  520. // Get application Merkle root hash
  521. func cmdCommit(cmd *cobra.Command, args []string) error {
  522. res, err := client.CommitSync()
  523. if err != nil {
  524. return err
  525. }
  526. printResponse(cmd, args, response{
  527. Code: res.Code,
  528. Data: res.Data,
  529. Log: res.Log,
  530. })
  531. return nil
  532. }
  533. // Query application state
  534. func cmdQuery(cmd *cobra.Command, args []string) error {
  535. if len(args) == 0 {
  536. printResponse(cmd, args, response{
  537. Code: codeBad,
  538. Log: "want the query",
  539. })
  540. return nil
  541. }
  542. queryBytes, err := stringOrHexToBytes(args[0])
  543. if err != nil {
  544. return err
  545. }
  546. resQuery, err := client.QuerySync(types.RequestQuery{
  547. Data: queryBytes,
  548. Path: flagPath,
  549. Height: int64(flagHeight),
  550. Prove: flagProve,
  551. })
  552. if err != nil {
  553. return err
  554. }
  555. printResponse(cmd, args, response{
  556. Code: resQuery.Code,
  557. Log: resQuery.Log,
  558. Query: &queryResponse{
  559. Key: resQuery.Key,
  560. Value: resQuery.Value,
  561. Height: resQuery.Height,
  562. Proof: resQuery.Proof,
  563. },
  564. })
  565. return nil
  566. }
  567. func cmdCounter(cmd *cobra.Command, args []string) error {
  568. app := counter.NewCounterApplication(flagSerial)
  569. logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout))
  570. // Start the listener
  571. srv, err := server.NewServer(flagAddrC, flagAbci, app)
  572. if err != nil {
  573. return err
  574. }
  575. srv.SetLogger(logger.With("module", "abci-server"))
  576. if err := srv.Start(); err != nil {
  577. return err
  578. }
  579. // Wait forever
  580. cmn.TrapSignal(func() {
  581. // Cleanup
  582. srv.Stop()
  583. })
  584. return nil
  585. }
  586. func cmdDummy(cmd *cobra.Command, args []string) error {
  587. logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout))
  588. // Create the application - in memory or persisted to disk
  589. var app types.Application
  590. if flagPersist == "" {
  591. app = dummy.NewDummyApplication()
  592. } else {
  593. app = dummy.NewPersistentDummyApplication(flagPersist)
  594. app.(*dummy.PersistentDummyApplication).SetLogger(logger.With("module", "dummy"))
  595. }
  596. // Start the listener
  597. srv, err := server.NewServer(flagAddrD, flagAbci, app)
  598. if err != nil {
  599. return err
  600. }
  601. srv.SetLogger(logger.With("module", "abci-server"))
  602. if err := srv.Start(); err != nil {
  603. return err
  604. }
  605. // Wait forever
  606. cmn.TrapSignal(func() {
  607. // Cleanup
  608. srv.Stop()
  609. })
  610. return nil
  611. }
  612. //--------------------------------------------------------------------------------
  613. func printResponse(cmd *cobra.Command, args []string, rsp response) {
  614. if flagVerbose {
  615. fmt.Println(">", cmd.Use, strings.Join(args, " "))
  616. }
  617. // Always print the status code.
  618. if rsp.Code == types.CodeTypeOK {
  619. fmt.Printf("-> code: OK\n")
  620. } else {
  621. fmt.Printf("-> code: %d\n", rsp.Code)
  622. }
  623. if len(rsp.Data) != 0 {
  624. // Do no print this line when using the commit command
  625. // because the string comes out as gibberish
  626. if cmd.Use != "commit" {
  627. fmt.Printf("-> data: %s\n", rsp.Data)
  628. }
  629. fmt.Printf("-> data.hex: 0x%X\n", rsp.Data)
  630. }
  631. if rsp.Log != "" {
  632. fmt.Printf("-> log: %s\n", rsp.Log)
  633. }
  634. if rsp.Query != nil {
  635. fmt.Printf("-> height: %d\n", rsp.Query.Height)
  636. if rsp.Query.Key != nil {
  637. fmt.Printf("-> key: %s\n", rsp.Query.Key)
  638. fmt.Printf("-> key.hex: %X\n", rsp.Query.Key)
  639. }
  640. if rsp.Query.Value != nil {
  641. fmt.Printf("-> value: %s\n", rsp.Query.Value)
  642. fmt.Printf("-> value.hex: %X\n", rsp.Query.Value)
  643. }
  644. if rsp.Query.Proof != nil {
  645. fmt.Printf("-> proof: %X\n", rsp.Query.Proof)
  646. }
  647. }
  648. }
  649. // NOTE: s is interpreted as a string unless prefixed with 0x
  650. func stringOrHexToBytes(s string) ([]byte, error) {
  651. if len(s) > 2 && strings.ToLower(s[:2]) == "0x" {
  652. b, err := hex.DecodeString(s[2:])
  653. if err != nil {
  654. err = fmt.Errorf("Error decoding hex argument: %s", err.Error())
  655. return nil, err
  656. }
  657. return b, nil
  658. }
  659. if !strings.HasPrefix(s, "\"") || !strings.HasSuffix(s, "\"") {
  660. err := fmt.Errorf("Invalid string arg: \"%s\". Must be quoted or a \"0x\"-prefixed hex string", s)
  661. return nil, err
  662. }
  663. return []byte(s[1 : len(s)-1]), nil
  664. }