Skip to content

Commit

Permalink
fix: test browser and node
Browse files Browse the repository at this point in the history
  • Loading branch information
janek26 committed Oct 22, 2021
1 parent b686f04 commit 4c23de0
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 3 deletions.
3 changes: 3 additions & 0 deletions __tests__/__snapshots__/utils.browser.test.ts.snap

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions __tests__/utils.browser.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* @jest-environment jsdom
*/

import { compressProgram, isBrowser } from '..';
import compiledArgentAccount from '../__mocks__/ArgentAccount.json';

test('isBrowser', () => {
expect(isBrowser).toBe(true);
});
describe('compressProgram()', () => {
test('compresses a contract program', () => {
const inputContract = compiledArgentAccount as any;

const compressed = compressProgram(inputContract.program);

expect(compressed).toMatchSnapshot();
});
});
14 changes: 13 additions & 1 deletion __tests__/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { compressProgram } from '..';
import { compressProgram, makeAddress, isBrowser } from '..';
import compiledArgentAccount from '../__mocks__/ArgentAccount.json';

test('isNode', () => {
expect(isBrowser).toBe(false);
});
describe('compressProgram()', () => {
test('compresses a contract program', () => {
const inputContract = compiledArgentAccount as any;
Expand All @@ -11,3 +14,12 @@ describe('compressProgram()', () => {
});
// there's basically no error case with almost all types being supported
});
describe('makeAddress()', () => {
test('test on eth address', () => {
const ethAddress = '0xdFD0F27FCe99b50909de0bDD328Aed6eAbe76BC5';

const starkAddress = makeAddress(ethAddress);

expect(starkAddress).toBe('0x00000000000000000000000dfd0f27fce99b50909de0bdd328aed6eabe76bc5');
});
});
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type {
CompiledContract,
} from './types';

const API_URL = 'https://alpha2.starknet.io/';
const API_URL = 'https://alpha2.starknet.io';
const FEEDER_GATEWAY_URL = `${API_URL}/feeder_gateway`;
const GATEWAY_URL = `${API_URL}/gateway`;

Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { gzip } from 'pako';
import { CompressedProgram, Program } from './types';
import { CONTRACT_ADDRESS_LOWER_BOUND, CONTRACT_ADDRESS_UPPER_BOUND } from './constants';

const isBrowser = typeof window !== 'undefined';
export const isBrowser = typeof window !== 'undefined';

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

0 comments on commit 4c23de0

Please sign in to comment.