truffle icon indicating copy to clipboard operation
truffle copied to clipboard

Integers in structs are not converted to BigNumbers

Open forshtat opened this issue 3 years ago • 5 comments

  • [X] I've asked for help in the Truffle Gitter before filing this issue.

Issue

When structs (tuples) are returned from the contract, their integer fields are not reformatted into a configured BigNubmer type, and remain as strings. This adds a lot of inconsistency to our project when trying to converge integer types.

Steps to Reproduce

Create a contract with the following code:

struct Struct {
    uint256 a;
    uint256 b;
}

function getStruct() external view returns (Struct memory);
function getA() external view returns (uint256);

and observe the difference in the Truffle console:

truffle(development)> c.getA()
BN {
  negative: 0,
  words: [ 150000, <1 empty item> ],
  length: 1,
  red: null
}

truffle(development)> c.getStruct()
[
  '150000',
  '100000',
  '110000',
  '10500',
  a: '150000',
  b: '100000',
]

Expected Behavior

Integer types should be reformatted to the correct BigNumber type.

Actual Results

Some integers are not reformatted and remain as strings.

forshtat avatar Mar 09 '21 14:03 forshtat

Thanks for reporting this; unfortunately I'm not sure there's any good way to fix this at the moment. We are planning a rewrite of all of our decoding functionality and once that's done this should be fixed, but unfortunately I'm not sure there's any real way to fix this short of completing that.

haltman-at avatar Mar 09 '21 23:03 haltman-at

Just a note: this rewrite is currently in progress!

eggplantzzz avatar Apr 07 '21 17:04 eggplantzzz

Any news?

TmLev avatar Feb 17 '22 13:02 TmLev

@haltman-at do you know anything about the progress on this?

eggplantzzz avatar Feb 17 '22 17:02 eggplantzzz

Unfortunately the contract rewrite has gotten delayed by other things, and I still can't see any good way to fix this without it. Hopefully we'll have time to get to it soon? (Btw @gnidan you may want to know about this...)

haltman-at avatar Feb 17 '22 18:02 haltman-at