vechain/thor-devkit.js

Encoding BigNumber produces Error

arjun-io opened this issue · 3 comments

Hi!

Noticed this issue with the latest version (0.11.0) of devkit, here are steps to reproduce:

let { abi } = require("thor-devkit")
let BigNumber = require('bignumber.js')
let fn = new abi.Function({
    "constant": false,
    "inputs": [
        {
            "name": "a1",
            "type": "uint256"
        },
        {
            "name": "a2",
            "type": "string"
        }
    ],
    "name": "f1",
    "outputs": [
        {
            "name": "r1",
            "type": "address"
        },
        {
            "name": "r2",
            "type": "bytes"
        }
    ],
    "payable": false,
    "stateMutability": "nonpayable",
    "type": "function"
})

let data = fn.encode(1, 'foo') // works
data = fn.encode(new BigNumber(1), 'foo') // errors
"dependencies": {
    "bignumber.js": "^9.0.0",
    "thor-devkit": "^0.11.0"
  }

devkit changed the ABI library since 0.9.1, a workaround for this is

fn.encode(new BigNumber(1).toString(), 'foo') 

or, downgrade to 0.8.*

We'll find a way to solve this issue

@arjun-io fn.encode will only accept primitive types, like number, string...
it's not a good idea to implicitly accept external lib types.

@qianbin makes sense but it appears that BigNumber used to work but broke in a recent version. Ideally breaking changes would be a major version change or at least noted.

Feel free to close this issue if it's a won't fix!