Skip to content

Commit

Permalink
Merge branch 'starknet-io:develop' into issue-starknet-io#1014
Browse files Browse the repository at this point in the history
  • Loading branch information
fmmesen authored Oct 22, 2024
2 parents 088a398 + d9826c9 commit 5739ede
Show file tree
Hide file tree
Showing 6 changed files with 346 additions and 21 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# [6.15.0](https://github.com/starknet-io/starknet.js/compare/v6.14.1...v6.15.0) (2024-10-16)

### Features

- num.toHex64 ensure 0x(64 char) format ([#1222](https://github.com/starknet-io/starknet.js/issues/1222)) ([56020cd](https://github.com/starknet-io/starknet.js/commit/56020cdbcd9d1cbe7d58d66b554790bbea8762fe))

## [6.14.1](https://github.com/starknet-io/starknet.js/compare/v6.14.0...v6.14.1) (2024-09-30)

### Bug Fixes
Expand Down
74 changes: 65 additions & 9 deletions __tests__/utils/num.test.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { num } from '../../src';
import {
isHex,
toBigInt,
toHex,
hexToDecimalString,
cleanHex,
addPercent,
assertInRange,
bigNumberishArrayToDecimalStringArray,
bigNumberishArrayToHexadecimalStringArray,
isStringWholeNumber,
cleanHex,
getDecimalString,
getHexString,
getHexStringArray,
toCairoBool,
hexToBytes,
addPercent,
hexToDecimalString,
isHex,
isStringWholeNumber,
toBigInt,
toCairoBool,
toHex,
} from '../../src/utils/num';
import { num } from '../../src';

describe('isHex', () => {
test('should return true for valid hex strings', () => {
Expand Down Expand Up @@ -174,3 +174,59 @@ describe('isBigNumberish', () => {
expect(num.isBigNumberish('zero')).toBe(false);
});
});

describe('toStorageKey, toHex64', () => {
test('should convert to 0x + 64 hex unrestricted', () => {
expect(() => num.toStorageKey('monorepo')).toThrow();

const key1 = num.toStorageKey('0x123');
expect(key1).toEqual('0x0000000000000000000000000000000000000000000000000000000000000123');
expect(key1.length).toEqual(66);

const key11 = num.toStorageKey(
'0x000000000000000000000000000000000000000000000000000000000000000000000000000000000123'
);
expect(key11).toEqual('0x0000000000000000000000000000000000000000000000000000000000000123');
expect(key11.length).toEqual(66);

const key2 = num.toStorageKey(123);
expect(key2).toEqual('0x000000000000000000000000000000000000000000000000000000000000007b');
expect(key2.length).toEqual(66);

const key3 = num.toStorageKey(123n);
expect(key3).toEqual('0x000000000000000000000000000000000000000000000000000000000000007b');
expect(key3.length).toEqual(66);
});

test('should convert to 0x + 64 hex restricted', () => {
expect(() => num.toHex64('monorepo')).toThrow();

const key1 = num.toHex64('0x123');
expect(key1).toEqual('0x0000000000000000000000000000000000000000000000000000000000000123');
expect(key1.length).toEqual(66);

const key11 = num.toHex64(
'0x000000000000000000000000000000000000000000000000000000000000000000000000000000000123'
);
expect(key11).toEqual('0x0000000000000000000000000000000000000000000000000000000000000123');
expect(key11.length).toEqual(66);

expect(() =>
num.toHex64(
'0x123000000000000000000000000000000000000000000000000000000000000000000000000000000123'
)
).toThrow(TypeError);

const key2 = num.toHex64(123);
expect(key2).toEqual('0x000000000000000000000000000000000000000000000000000000000000007b');
expect(key2.length).toEqual(66);

const key3 = num.toHex64(123n);
expect(key3).toEqual('0x000000000000000000000000000000000000000000000000000000000000007b');
expect(key3.length).toEqual(66);

const key4 = num.toHex64('0x82bdafb0c4a2b03cd0f16ddcc3339da37f2cbb1aecb2a419764e35b7c3a8ec29');
expect(key4).toEqual('0x82bdafb0c4a2b03cd0f16ddcc3339da37f2cbb1aecb2a419764e35b7c3a8ec29');
expect(key4.length).toEqual(66);
});
});
Loading

0 comments on commit 5739ede

Please sign in to comment.