Skip to content

Commit

Permalink
Merge branch 'develop' into fix/contract-error-response-parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
janek26 authored Jun 20, 2022
2 parents 8dbf8e4 + df6547d commit 405402a
Show file tree
Hide file tree
Showing 6 changed files with 1,147 additions and 1,543 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## [3.15.3](https://github.com/0xs34n/starknet.js/compare/v3.15.2...v3.15.3) (2022-06-20)

### Bug Fixes

- **dev:** regenerated package-lock.json ([849cb1e](https://github.com/0xs34n/starknet.js/commit/849cb1ea3ffd7ba10b40b232d0ebc46b6599c7ea))
- use cross-fetch only for jest ([83be37a](https://github.com/0xs34n/starknet.js/commit/83be37a9e3328a44abd9583b8167c3cb8d882790))

## [3.15.2](https://github.com/0xs34n/starknet.js/compare/v3.15.1...v3.15.2) (2022-06-18)

### Bug Fixes
Expand Down
3 changes: 3 additions & 0 deletions __tests__/jest.setup.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/* eslint-disable no-console */
import fetch from 'cross-fetch';
import { register } from 'fetch-intercept';

global.fetch = fetch;

jest.setTimeout(50 * 60 * 1000);

if (process.env.DEBUG === 'true') {
Expand Down
64 changes: 64 additions & 0 deletions __tests__/utils/typedData.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import typedDataExample from '../../__mocks__/typedDataExample.json';
import { number } from '../../src';
import { BigNumberish } from '../../src/utils/number';
import { encodeType, getMessageHash, getStructHash, getTypeHash } from '../../src/utils/typedData';

describe('typedData', () => {
Expand Down Expand Up @@ -34,4 +36,66 @@ describe('typedData', () => {
`"0x6fcff244f63e38b9d88b9e3378d44757710d1b244282b435cb472053c8d78d0"`
);
});

interface StringStruct {
len: BigNumberish;
data: BigNumberish[];
}
function stringToStringStruct(str: string): StringStruct {
const len = str.length;
const data = str.split('').map((char) => number.toHex(number.toBN(char.charCodeAt(0))));
return { len, data };
}

const typedDataStringExample = {
types: {
StarkNetDomain: [
{ name: 'name', type: 'felt' },
{ name: 'version', type: 'felt' },
{ name: 'chainId', type: 'felt' },
],
Person: [
{ name: 'name', type: 'felt' },
{ name: 'wallet', type: 'felt' },
],
String: [
{ name: 'len', type: 'felt' },
{ name: 'data', type: 'felt*' },
],
Mail: [
{ name: 'from', type: 'Person' },
{ name: 'to', type: 'Person' },
{ name: 'contents', type: 'String' },
],
},
primaryType: 'Mail',
domain: {
name: 'StarkNet Mail',
version: '1',
chainId: 1,
},
message: {
from: {
name: 'Cow',
wallet: '0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826',
},
to: {
name: 'Bob',
wallet: '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB',
},
contents: stringToStringStruct(
'this is way longer than just 32 characters, to test if that is possible within a typedData struct.'
),
},
};

test('should transform strings correctly', () => {
const hash = getMessageHash(
typedDataStringExample,
'0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826'
);
expect(hash).toMatchInlineSnapshot(
`"0x70338fb11b8f70b68b261de8a322bcb004bd85e88ac47d9147982c7f5ac66fd"`
);
});
});
Loading

0 comments on commit 405402a

Please sign in to comment.