-
-
Notifications
You must be signed in to change notification settings - Fork 289
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: chunkIntoN to chunk correctly (#6035)
* fix: fixed chunkIntoN to chunk correctly (#6018) * FIX: fixed chunkIntoN to chunk correctly chunkIntoN was chunking into N chunks, however it is used to chunk eth_getCode and eth_getProof responses into chunks of 2, so the desired action should be to chunk into chunks of length N https://github.com/ChainSafe/lodestar/blob/unstable/packages/prover/src/utils/evm.ts#L105 Because the current tests work on chunking array of length 4 into 2 the previous behavior was working and passing tests. When there are 6 requests the current behavior no longer works * Fix strings in test * Add more test cases * Update test title * Update packages/prover/test/unit/utils/conversion.test.ts Co-authored-by: Nico Flaig <nflaig@protonmail.com> * Update the test description * Update the test description * Update the test description --------- Co-authored-by: Roman Dvorkin <121502696+rdvorkin@users.noreply.github.com> Co-authored-by: Nico Flaig <nflaig@protonmail.com>
- Loading branch information
1 parent
1aa6561
commit 93709ff
Showing
2 changed files
with
90 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import {expect} from "chai"; | ||
import {chunkIntoN} from "../../../src/utils/conversion.js"; | ||
|
||
describe("utils/conversion", () => { | ||
describe("chunkIntoN", () => { | ||
const testCases = [ | ||
{ | ||
title: "even number of chunks", | ||
input: { | ||
data: [1, 2, 3, 4, 5, 6], | ||
n: 2, | ||
}, | ||
output: [ | ||
[1, 2], | ||
[3, 4], | ||
[5, 6], | ||
], | ||
}, | ||
{ | ||
title: "even number of chunks with additional element", | ||
input: { | ||
data: [1, 2, 3, 4, 5, 6, 7], | ||
n: 2, | ||
}, | ||
output: [[1, 2], [3, 4], [5, 6], [7]], | ||
}, | ||
{ | ||
title: "odd number of chunks", | ||
input: { | ||
data: [1, 2, 3, 4, 5, 6], | ||
n: 3, | ||
}, | ||
output: [ | ||
[1, 2, 3], | ||
[4, 5, 6], | ||
], | ||
}, | ||
{ | ||
title: "odd number of chunks with additional element", | ||
input: { | ||
data: [1, 2, 3, 4, 5, 6, 7], | ||
n: 3, | ||
}, | ||
output: [[1, 2, 3], [4, 5, 6], [7]], | ||
}, | ||
{ | ||
title: "data less than chunk size", | ||
input: { | ||
data: [1], | ||
n: 3, | ||
}, | ||
output: [[1]], | ||
}, | ||
{ | ||
title: "data 1 less than chunk size", | ||
input: { | ||
data: [1, 2], | ||
n: 3, | ||
}, | ||
output: [[1, 2]], | ||
}, | ||
{ | ||
title: "data 1 extra than chunk size", | ||
input: { | ||
data: [1, 2, 3, 4], | ||
n: 3, | ||
}, | ||
output: [[1, 2, 3], [4]], | ||
}, | ||
]; | ||
|
||
for (const {title, input, output} of testCases) { | ||
it(`should chunkify data when ${title}`, async () => { | ||
expect(chunkIntoN(input.data, input.n)).to.be.deep.eq(output); | ||
}); | ||
} | ||
|
||
it("should not change the order of elements", () => { | ||
expect(chunkIntoN([6, 5, 4, 3, 2, 1], 2)).to.be.deep.eq([ | ||
[6, 5], | ||
[4, 3], | ||
[2, 1], | ||
]); | ||
}); | ||
}); | ||
}); |