Skip to content

Commit 4c23de0

Browse files
committed
fix: test browser and node
1 parent b686f04 commit 4c23de0

File tree

5 files changed

+37
-3
lines changed

5 files changed

+37
-3
lines changed

__tests__/__snapshots__/utils.browser.test.ts.snap

Lines changed: 3 additions & 0 deletions
Large diffs are not rendered by default.

__tests__/utils.browser.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @jest-environment jsdom
3+
*/
4+
5+
import { compressProgram, isBrowser } from '..';
6+
import compiledArgentAccount from '../__mocks__/ArgentAccount.json';
7+
8+
test('isBrowser', () => {
9+
expect(isBrowser).toBe(true);
10+
});
11+
describe('compressProgram()', () => {
12+
test('compresses a contract program', () => {
13+
const inputContract = compiledArgentAccount as any;
14+
15+
const compressed = compressProgram(inputContract.program);
16+
17+
expect(compressed).toMatchSnapshot();
18+
});
19+
});

__tests__/utils.test.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
import { compressProgram } from '..';
1+
import { compressProgram, makeAddress, isBrowser } from '..';
22
import compiledArgentAccount from '../__mocks__/ArgentAccount.json';
33

4+
test('isNode', () => {
5+
expect(isBrowser).toBe(false);
6+
});
47
describe('compressProgram()', () => {
58
test('compresses a contract program', () => {
69
const inputContract = compiledArgentAccount as any;
@@ -11,3 +14,12 @@ describe('compressProgram()', () => {
1114
});
1215
// there's basically no error case with almost all types being supported
1316
});
17+
describe('makeAddress()', () => {
18+
test('test on eth address', () => {
19+
const ethAddress = '0xdFD0F27FCe99b50909de0bDD328Aed6eAbe76BC5';
20+
21+
const starkAddress = makeAddress(ethAddress);
22+
23+
expect(starkAddress).toBe('0x00000000000000000000000dfd0f27fce99b50909de0bdd328aed6eabe76bc5');
24+
});
25+
});

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import type {
1111
CompiledContract,
1212
} from './types';
1313

14-
const API_URL = 'https://alpha2.starknet.io/';
14+
const API_URL = 'https://alpha2.starknet.io';
1515
const FEEDER_GATEWAY_URL = `${API_URL}/feeder_gateway`;
1616
const GATEWAY_URL = `${API_URL}/gateway`;
1717

src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { gzip } from 'pako';
22
import { CompressedProgram, Program } from './types';
33
import { CONTRACT_ADDRESS_LOWER_BOUND, CONTRACT_ADDRESS_UPPER_BOUND } from './constants';
44

5-
const isBrowser = typeof window !== 'undefined';
5+
export const isBrowser = typeof window !== 'undefined';
66

77
export const btoaUniversal = (b: ArrayBuffer): string =>
88
isBrowser ? btoa(String.fromCharCode.apply(null, b as any)) : Buffer.from(b).toString('base64');

0 commit comments

Comments
 (0)