-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix it so that when values are printed the order of numbers is numeric (
#338) ### Description If a list of values was printed that were keyed by numbers such as transactions to be executed in a governance proposal, they would be ordered incorrectly due to numbers being treated like strings. EG `1, 11, 12, 2,3, 4` this fixes that. <!-- start pr-codex --> --- ## PR-Codex overview This PR fixes the printing of values in numerical order in the `printValueMapRecursive` function in the `cli.ts` file. ### Detailed summary - Fixed sorting of values in `printValueMapRecursive` function to order numeric keys correctly - Added tests for printing number keys in numeric order
- Loading branch information
Showing
3 changed files
with
82 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@celo/celocli': patch | ||
--- | ||
|
||
Fix printing of values that should be ordered numerically |
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,71 @@ | ||
import { testWithAnvilL2 } from '@celo/dev-utils/lib/anvil-test' | ||
import { stripAnsiCodesFromNestedArray } from '../test-utils/cliUtils' | ||
import { printValueMapRecursive } from './cli' | ||
testWithAnvilL2('printValueMapRecursive', async () => { | ||
it('should print the key-value pairs in the value map recursively', () => { | ||
const valueMap = { | ||
key1: 'value1', | ||
key2: { | ||
nestedKey1: 'nestedValue1', | ||
nestedKey2: 'nestedValue2', | ||
}, | ||
} | ||
|
||
const mock = jest.fn() | ||
console.log = mock | ||
|
||
printValueMapRecursive(valueMap) | ||
|
||
expect(stripAnsiCodesFromNestedArray(mock.mock.calls)).toMatchInlineSnapshot(` | ||
[ | ||
[ | ||
"key1: value1 | ||
key2: | ||
nestedKey1: nestedValue1 | ||
nestedKey2: nestedValue2", | ||
], | ||
] | ||
`) | ||
}) | ||
|
||
it('should print number keys in numeric order', () => { | ||
const valueMap = { | ||
1: 'jeden', | ||
2: { | ||
1: '1', | ||
2: '2', | ||
11: '3', | ||
12: '4', | ||
21: '5', | ||
}, | ||
3: { | ||
'0x1': 'nestedValue1', | ||
jupiter: 'nestedValue2', | ||
potato: 'nestedValue3', | ||
}, | ||
} | ||
|
||
const mock = jest.fn() | ||
console.log = mock | ||
|
||
printValueMapRecursive(valueMap) | ||
|
||
expect(stripAnsiCodesFromNestedArray(mock.mock.calls)).toMatchInlineSnapshot(` | ||
[ | ||
[ | ||
"1: jeden | ||
2: | ||
1: 1 | ||
2: 2 | ||
11: 3 | ||
12: 4 | ||
21: 5 | ||
3: | ||
0x1: nestedValue1 | ||
jupiter: nestedValue2 | ||
potato: nestedValue3", | ||
], | ||
] | ||
`) | ||
}) | ||
}) |
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