Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible Bug on Result Class (abstract-coder.ts) #3787

Closed
dennohpeter opened this issue Feb 16, 2023 · 1 comment
Closed

Possible Bug on Result Class (abstract-coder.ts) #3787

dennohpeter opened this issue Feb 16, 2023 · 1 comment
Assignees
Labels
fixed/complete This Bug is fixed or Enhancement is complete and published. investigate Under investigation and may be a bug. v6 Issues regarding v6

Comments

@dennohpeter
Copy link

Ethers Version

6.0.3

Search Terms

No response

Describe the Problem

.slice(-1) and .toArray() are not working as expected.

.slice(-1): - should return the last item in the array, instead it's return the whole array plus undefined element on index 0

.toArray(): should return an array of the input items, instead it's returning nested array [[]]

Code Snippet

import { Result } from "ethers";

// test Result
  let result = new Result(
    "0x000000",
    "0x000001",
    "0x000002",
    "0x000003",
    "0x000004"
  );

  // returns result array
  console.info({ result });

  // working fine; i.e slice(0, 1) returns the first element
  console.info({ resultFirstElement: result.slice(0, 1) });

  // ISSUE 1:
  // NOT working as expected; i.e slice(-1) returns the last element, instead it returns the whole array plus the undefined item
  //    {
  //   resultLastElement: Result(6) [
  //     undefined,
  //     '0x000000',
  //     '0x000001',
  //     '0x000002',
  //     '0x000003',
  //     '0x000004'
  //   ]
  // }
  console.info({ resultLastElement: result.slice(-1) });

  console.info({ restOfTheElements: result.slice(1) });

  // ISSUE 2:
  // NOT working as expected; i.e toArray() returns Array of Result Array, instead of Array of Strings
  // actual result: {
  //   toArray: [
  //     Result(5) [
  //       '0x000000',
  //       '0x000001',
  //       '0x000002',
  //       '0x000003',
  //       '0x000004'
  //     ]
  //   ]
  // }

  // expected result: [ '0x000000', '0x000001', '0x000002', '0x000003', '0x000004' ]
  console.info({ toArray: result.toArray() });

  // Comparing with Array
  let arr = new Array(
    "0x000000",
    "0x000001",
    "0x000002",
    "0x000003",
    "0x000004"
  );

  console.info({ arr });

  // working fine working; i.e slice(0, 1) returns the first element
  console.info({ arrFirstElement: arr.slice(0, 1) });

  // working fine; i.e slice(-1) returns the last element
  console.info({ arrLastElement: arr.slice(-1) });

  // working fine; i.e slice(1) returns elements from index 1 to the end
  console.info({ restOfTheElements: arr.slice(1) });

Contract ABI

No response

Errors

No response

Environment

node.js (v12 or newer)

Environment (Other)

No response

@dennohpeter dennohpeter added the investigate Under investigation and may be a bug. label Feb 16, 2023
@dennohpeter dennohpeter changed the title Possible Issues with Result Class (abstract-coder.ts) Possible Bug on Result Class (abstract-coder.ts) Feb 16, 2023
@ricmoo ricmoo added on-deck This Enhancement or Bug is currently being worked on. minor-bump Planned for the next minor version bump. v6 Issues regarding v6 and removed minor-bump Planned for the next minor version bump. labels Feb 18, 2023
@ricmoo
Copy link
Member

ricmoo commented Feb 19, 2023

Fixed in v6.0.5.

Thanks! :)

@ricmoo ricmoo closed this as completed Feb 19, 2023
@ricmoo ricmoo added fixed/complete This Bug is fixed or Enhancement is complete and published. and removed on-deck This Enhancement or Bug is currently being worked on. labels Feb 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed/complete This Bug is fixed or Enhancement is complete and published. investigate Under investigation and may be a bug. v6 Issues regarding v6
Projects
None yet
Development

No branches or pull requests

2 participants