How CBOR Parse Task in Standard mode works?

122 Views Asked by At

I wonder how cborparse in mode="standard" works cause I can't make it work.

Resources

Chainlink CBOR Parse Task - docs

Chainlink CBOR Prase Task - implementation

Chainlink CBOR Parse Task - implementation tests

Online CBOR encoder Online uft8 to bytes converter

Environment

Chainlink Node v1.7.0, and v1.8.1.

Case OK: cborparse in mode="diet" (default)

Test Case

Input

{"path":["recent","usd"],"url":"https://etherprice.com/api"}

Input CBOR encoded

A264706174688266726563656E74637573646375726C781A68747470733A2F2F657468657270726963652E636F6D2F617069

Webhook TOML spec

type = "webhook"
schemaVersion = 1
name = "Test decode CBOR diet"
observationSource = """
    merge               [type="merge" left=<{"input": "0x"}> right=<{"input": "0xA264706174688266726563656E74637573646375726C781A68747470733A2F2F657468657270726963652E636F6D2F617069"}>]
    decode_cbor         [type="cborparse" data="$(merge.input)"]

    merge -> decode_cbor
"""

JSON job run

{
  "__typename": "JobRun",
  "id": "240",
  "allErrors": [
  ],
  "createdAt": "2022-10-14T12:06:56.646544Z",
  "fatalErrors": [
  ],
  "finishedAt": "2022-10-14T12:06:56.64718Z",
  "job": {
    "__typename": "Job",
    "id": "225",
    "name": "Test decode CBOR diet",
    "observationSource": " merge [type="merge" left=<{"input": "0x"}> right=<{"input": "0xA264706174688266726563656E74637573646375726C781A68747470733A2F2F657468657270726963652E636F6D2F617069"}>] decode_cbor [type="cborparse" data="$(merge.input)"] "
  },
  "status": "COMPLETED",
  "inputs": {
    "decode_cbor": {
      "path": [
        "recent",
        "usd"
      ],
      "url": "https://etherprice.com/api"
    },
    "jobRun": {
      "meta": null
    },
    "merge": {
      "input": "0xA264706174688266726563656E74637573646375726C781A68747470733A2F2F657468657270726963652E636F6D2F617069"
    }
  },
  "outputs": [
    "{"path":["recent","usd"],"url":"https://etherprice.com/api"}"
  ],
  "taskRuns": [
  ]
}

Case KO: cborparse in mode="standard"

Test Case

Input

{"path":["recent","usd"],"url":"https://etherprice.com/api"}

Input CBOR encoded

A264706174688266726563656E74637573646375726C781A68747470733A2F2F657468657270726963652E636F6D2F617069

Input CBOR encoded as array of bytes

[41, 32, 36, 34, 37, 30, 36, 31, 37, 34, 36, 38, 38, 32, 36, 36, 37, 32, 36, 35, 36, 33, 36, 35, 36, 45, 37, 34, 36, 33, 37, 35, 37, 33, 36, 34, 36, 33, 37, 35, 37, 32, 36, 43, 37, 38, 31, 41, 36, 38, 37, 34, 37, 34, 37, 30, 37, 33, 33, 41, 32, 46, 32, 46, 36, 35, 37, 34, 36, 38, 36, 35, 37, 32, 37, 30, 37, 32, 36, 39, 36, 33, 36, 35, 32, 45, 36, 33, 36, 46, 36, 44, 32, 46, 36, 31, 37, 30, 36, 39]

Below few TOML specs attempted but none of them work. They always fail with data: parameter is empty (common part of the JSON job run shared below):

{
  "__typename": "JobRun",
  "id": "246",
  "allErrors": [
    "data: parameter is empty"
  ],
  "createdAt": "2022-10-14T12:31:42.234027Z",
  "fatalErrors": [
    "data: parameter is empty"
  ],
  "finishedAt": "2022-10-14T12:31:42.236091Z",
  "job": {
    "__typename": "Job",
    "id": "232",
    "name": "Test decode CBOR standard",
    "observationSource": " decode_cbor [type="cborparse" mode="standard" data=<it_does_not_matter>] "
  },
  "status": "ERRORED",
  "inputs": {
    "decode_cbor": {
    },
    "jobRun": {
      "meta": null
    }
  },
  "outputs": [
    null
  ],
  "taskRuns": [
    {
      "__typename": "TaskRun",
      "id": "9c374ffb-cf80-41c9-a3b7-08391abd48fa",
      "createdAt": "2022-10-14T12:31:42.234993Z",
      "dotID": "decode_cbor",
      "error": "data: parameter is empty",
      "finishedAt": "2022-10-14T12:31:42.236021Z",
      "output": "null",
      "type": "cborparse"
    }
  ]
}

Test 1: webhook TOML spec where data has an hexStr

data has is a hexStr

type = "webhook"
schemaVersion = 1
name = "Test decode CBOR diet 1"
observationSource = """
    decode_cbor         [type="cborparse" mode="standard" data="0xA264706174688266726563656E74637573646375726C781A68747470733A2F2F657468657270726963652E636F6D2F617069"]
"""

I've tried also multiple syntax combinations, adding and removing [ ], 0x, "". For instance:

type = "webhook"
schemaVersion = 1
name = "Test decode CBOR standard 3"
observationSource = """
    decode_cbor         [type="cborparse" mode="standard" data=<{["0xA264706174688266726563656E74637573646375726C781A68747470733A2F2F657468657270726963652E636F6D2F617069"]}>]
"""

Test 2: webhook TOML spec where data does not have hexStr

data is <{ ... }>. I've also tried this with scaped quotes (old syntax)

type = "webhook"
schemaVersion = 1
name = "Test decode CBOR standard 1"
observationSource = """
    decode_cbor         [type="cborparse" mode="standard" data=<{41, 32, 36, 34, 36, 45, 36, 31, 36, 44, 36, 35, 36, 34, 36, 33, 36, 31, 36, 43, 36, 43, 36, 36, 36, 39, 36, 45, 37, 30, 37, 35, 37, 34, 37, 33, 38, 32, 41, 32, 36, 34, 36, 45, 36, 31, 36, 44, 36, 35, 36, 39, 37, 32, 36, 35, 37, 31, 37, 35, 36, 35, 37, 33, 37, 34, 34, 39, 36, 34, 36, 34, 37, 34, 37, 39, 37, 30, 36, 35, 36, 37, 36, 32, 37, 39, 37, 34, 36, 35, 37, 33, 33, 33, 33, 32, 41, 34, 36, 34, 36, 45, 36, 31, 36, 44, 36, 35, 36, 37, 37, 32, 36, 35, 37, 33, 37, 35, 36, 43, 37, 34, 37, 33, 36, 34, 37, 34, 37, 39, 37, 30, 36, 35, 36, 37, 36, 32, 37, 39, 37, 34, 36, 35, 37, 33, 35, 42, 35, 44, 36, 36, 36, 35, 36, 45, 36, 33, 36, 46, 36, 34, 36, 35, 41, 32, 36, 36, 36, 44, 36, 35, 37, 34, 36, 38, 36, 46, 36, 34, 36, 36, 37, 30, 36, 31, 36, 33, 36, 42, 36, 35, 36, 34, 36, 34, 36, 34, 36, 31, 37, 34, 36, 31, 36, 41, 37, 32, 36, 35, 37, 33, 37, 35, 36, 43, 37, 34, 37, 33, 35, 32, 36, 31, 37, 37, 36, 41, 36, 33, 36, 46, 36, 44, 37, 30, 36, 46, 36, 45, 36, 35, 36, 45, 37, 34, 37, 33, 38, 35, 41, 32, 36, 34, 36, 45, 36, 31, 36, 44, 36, 35, 36, 36, 36, 37, 36, 31, 36, 44, 36, 35, 34, 39, 36, 34, 36, 34, 37, 34, 37, 39, 37, 30, 36, 35, 36, 36, 37, 35, 36, 39, 36, 45, 37, 34, 33, 33, 33, 32, 41, 32, 36, 34, 36, 45, 36, 31, 36, 44, 36, 35, 36, 39, 37, 33, 37, 34, 36, 31, 37, 32, 37, 34, 35, 34, 36, 39, 36, 44, 36, 35, 36, 34, 37, 34, 37, 39, 37, 30, 36, 35, 36, 36, 37, 35, 36, 39, 36, 45, 37, 34, 33, 34, 33, 30, 41, 34, 36, 34, 36, 45, 36, 31, 36, 44, 36, 35, 36, 45, 36, 38, 36, 46, 36, 44, 36, 35, 35, 34, 36, 35, 36, 31, 36, 44, 34, 43, 36, 35, 36, 45, 36, 37, 37, 34, 36, 38, 36, 34, 37, 34, 37, 39, 37, 30, 36, 35, 36, 35, 37, 35, 36, 39, 36, 45, 37, 34, 33, 38, 36, 36, 36, 44, 36, 35, 37, 34, 36, 38, 36, 46, 36, 34, 36, 36, 36, 43, 36, 35, 36, 45, 36, 37, 37, 34, 36, 38, 36, 34, 36, 34, 36, 31, 37, 34, 36, 31, 36, 38, 36, 38, 36, 46, 36, 44, 36, 35, 35, 34, 36, 35, 36, 31, 36, 44, 41, 32, 36, 34, 36, 45, 36, 31, 36, 44, 36, 35, 36, 38, 36, 38, 36, 46, 36, 44, 36, 35, 35, 34, 36, 35, 36, 31, 36, 44, 36, 34, 37, 34, 37, 39, 37, 30, 36, 35, 36, 36, 37, 33, 37, 34, 37, 32, 36, 39, 36}>]
"""

data is <{[ ... ]}>. I've also tried this with scaped quotes (old syntax)

type = "webhook"
schemaVersion = 1
name = "Test decode CBOR standard 2"
observationSource = """
    decode_cbor         [type="cborparse" mode="standard" data=<{[41, 32, 36, 34, 36, 45, 36, 31, 36, 44, 36, 35, 36, 34, 36, 33, 36, 31, 36, 43, 36, 43, 36, 36, 36, 39, 36, 45, 37, 30, 37, 35, 37, 34, 37, 33, 38, 32, 41, 32, 36, 34, 36, 45, 36, 31, 36, 44, 36, 35, 36, 39, 37, 32, 36, 35, 37, 31, 37, 35, 36, 35, 37, 33, 37, 34, 34, 39, 36, 34, 36, 34, 37, 34, 37, 39, 37, 30, 36, 35, 36, 37, 36, 32, 37, 39, 37, 34, 36, 35, 37, 33, 33, 33, 33, 32, 41, 34, 36, 34, 36, 45, 36, 31, 36, 44, 36, 35, 36, 37, 37, 32, 36, 35, 37, 33, 37, 35, 36, 43, 37, 34, 37, 33, 36, 34, 37, 34, 37, 39, 37, 30, 36, 35, 36, 37, 36, 32, 37, 39, 37, 34, 36, 35, 37, 33, 35, 42, 35, 44, 36, 36, 36, 35, 36, 45, 36, 33, 36, 46, 36, 34, 36, 35, 41, 32, 36, 36, 36, 44, 36, 35, 37, 34, 36, 38, 36, 46, 36, 34, 36, 36, 37, 30, 36, 31, 36, 33, 36, 42, 36, 35, 36, 34, 36, 34, 36, 34, 36, 31, 37, 34, 36, 31, 36, 41, 37, 32, 36, 35, 37, 33, 37, 35, 36, 43, 37, 34, 37, 33, 35, 32, 36, 31, 37, 37, 36, 41, 36, 33, 36, 46, 36, 44, 37, 30, 36, 46, 36, 45, 36, 35, 36, 45, 37, 34, 37, 33, 38, 35, 41, 32, 36, 34, 36, 45, 36, 31, 36, 44, 36, 35, 36, 36, 36, 37, 36, 31, 36, 44, 36, 35, 34, 39, 36, 34, 36, 34, 37, 34, 37, 39, 37, 30, 36, 35, 36, 36, 37, 35, 36, 39, 36, 45, 37, 34, 33, 33, 33, 32, 41, 32, 36, 34, 36, 45, 36, 31, 36, 44, 36, 35, 36, 39, 37, 33, 37, 34, 36, 31, 37, 32, 37, 34, 35, 34, 36, 39, 36, 44, 36, 35, 36, 34, 37, 34, 37, 39, 37, 30, 36, 35, 36, 36, 37, 35, 36, 39, 36, 45, 37, 34, 33, 34, 33, 30, 41, 34, 36, 34, 36, 45, 36, 31, 36, 44, 36, 35, 36, 45, 36, 38, 36, 46, 36, 44, 36, 35, 35, 34, 36, 35, 36, 31, 36, 44, 34, 43, 36, 35, 36, 45, 36, 37, 37, 34, 36, 38, 36, 34, 37, 34, 37, 39, 37, 30, 36, 35, 36, 35, 37, 35, 36, 39, 36, 45, 37, 34, 33, 38, 36, 36, 36, 44, 36, 35, 37, 34, 36, 38, 36, 46, 36, 34, 36, 36, 36, 43, 36, 35, 36, 45, 36, 37, 37, 34, 36, 38, 36, 34, 36, 34, 36, 31, 37, 34, 36, 31, 36, 38, 36, 38, 36, 46, 36, 44, 36, 35, 35, 34, 36, 35, 36, 31, 36, 44, 41, 32, 36, 34, 36, 45, 36, 31, 36, 44, 36, 35, 36, 38, 36, 38, 36, 46, 36, 44, 36, 35, 35, 34, 36, 35, 36, 31, 36, 44, 36, 34, 37, 34, 37, 39, 37, 30, 36, 35, 36, 36, 37, 33, 37, 34, 37, 32, 36, 39, 36]}>]
""

Summary

Did I get wrong how this task is used and its purpose? May be the standard mode just return straight data?, but why I'm always getting data parameters is empty?

One alternative for me to understand better what's going on would be implementing a unit test in task.cborparse_test.go, but may be someone has the answer!

Thanks!

1

There are 1 best solutions below

4
ZeusLawyer On

When using mode=standard, can actually skip the character <{[.

So you can specify the value of data in the TOML as the hex string

decode_cbor [type="cborparse" mode="standard" data="0xA264706174688266726563656E74637573646375726C781A68747470733A2F2F657468657270726963652E636F6D2F617069"]

or

reference it from a variable like $(foo).

Give that a shot and let me know if you've had trouble.

Also, not sure you need the merge task :

merge [ type="merge" left=<{"input": "0x"}> right=<{"input": "0xA264706174688266726563656E74637573646375726C781A68747470733A2F2F657468657270726963652E636F6D2F617069"}>]

Hope this helps.