Skip to content

Commit

Permalink
fix: review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
janek26 committed Nov 9, 2021
1 parent 7e04b5e commit 375043b
Show file tree
Hide file tree
Showing 14 changed files with 115 additions and 153 deletions.
32 changes: 16 additions & 16 deletions __tests__/account/account.test.ts → __tests__/account.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ import {
hash,
json,
number,
starknet,
} from '../../src';
stark,
} from '../src';

describe('getStarkAccountFromPk()', () => {
test('it works with valid pk', () => {
const pk = '0xb696427c0d79c5d28a1fa6f748bae1b98b3f4b86bd1a2505bab144673c856fa9';
describe('getStarkAccountFromPrivateKey()', () => {
test('it works with valid privateKey', () => {
const privateKey = '0xb696427c0d79c5d28a1fa6f748bae1b98b3f4b86bd1a2505bab144673c856fa9';

const starkKeyPair = ec.getKeyPair(pk);
const starkKeyPair = ec.getKeyPair(privateKey);
const starkKey = ec.getStarkKey(starkKeyPair);

expect(starkKey).toBe('0x060d46f8d7ef3d83ed05f3ed9beb91e22f9529289b9d863683fd71eafaf28035');
});
test('it works with valid pk', () => {
const pk = '0x5f65099e269b080000000000000000000000000000000000000000000000000';
test('it works with valid privateKey', () => {
const privateKey = '0x5f65099e269b080000000000000000000000000000000000000000000000000';

const starkKeyPair = ec.getKeyPair(pk);
const starkKeyPair = ec.getKeyPair(privateKey);
const starkKey = ec.getStarkKey(starkKeyPair);

expect(starkKey).toBe('0xf321e59b257a577836d8313150aabd21f412491358c329966218df76bab591');
Expand All @@ -40,9 +40,9 @@ const compiledErc20: CompiledContract = json.parse(
);

describe('deploy and test Wallet', () => {
const pk = starknet.randomAddress();
const privateKey = stark.randomAddress();

const starkKeyPair = ec.getKeyPair(pk);
const starkKeyPair = ec.getKeyPair(privateKey);
const starkKeyPub = ec.getStarkKey(starkKeyPair);
let wallet: Contract;
let walletAddress: string;
Expand Down Expand Up @@ -98,7 +98,7 @@ describe('deploy and test Wallet', () => {
hash.hashMessage(
'0', // needs to be walletAddress once it's possible to retrieve address(self) in cairo
erc20Address,
starknet.getSelectorFromName('transfer'),
stark.getSelectorFromName('transfer'),
[erc20Address, '10'],
nonce.toString()
)
Expand All @@ -109,7 +109,7 @@ describe('deploy and test Wallet', () => {
'execute',
{
to: erc20Address,
selector: starknet.getSelectorFromName('transfer'),
selector: stark.getSelectorFromName('transfer'),
calldata: [erc20Address, '10'],
nonce: nonce.toString(),
},
Expand All @@ -130,13 +130,13 @@ describe('deploy and test Wallet', () => {
});

test('build tx', async () => {
const pk = '0x1B69B4BE052FAB1';
const keyPair = ec.getKeyPair(pk);
const privateKey = '0x1B69B4BE052FAB1';
const keyPair = ec.getKeyPair(privateKey);
const address = ec.getStarkKey(keyPair);

expect(address).toBe('0x04024999b9574cb7623679ce049a609db62a95098982c5b28ac61abdebd1c82b');

const selector = starknet.getSelectorFromName('transfer');
const selector = stark.getSelectorFromName('transfer');

expect(selector).toBe(
number.toHex(
Expand Down
4 changes: 2 additions & 2 deletions __tests__/contract.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import fs from 'fs';

import { CompiledContract, Contract, defaultProvider, json, number, starknet } from '../src';
import { CompiledContract, Contract, defaultProvider, json, number, stark } from '../src';

const compiledERC20: CompiledContract = json.parse(
fs.readFileSync('./__mocks__/ERC20.json').toString('ascii')
);

describe('class Contract {}', () => {
const wallet = starknet.randomAddress();
const wallet = stark.randomAddress();
let contract: Contract;
beforeAll(async () => {
const {
Expand Down
12 changes: 6 additions & 6 deletions __tests__/provider.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'fs';

import { CompiledContract, compileCalldata, defaultProvider, json, starknet } from '../src';
import { CompiledContract, compileCalldata, defaultProvider, json, stark } from '../src';

const compiledArgentAccount = json.parse(
fs.readFileSync('./__mocks__/ArgentAccount.json').toString('ascii')
Expand Down Expand Up @@ -67,7 +67,7 @@ describe('defaultProvider', () => {
return expect(
defaultProvider.callContract({
contract_address: '0x58bceda58a83a5a100117ddc893234bad9c84a6833c2008f0f1ca90150149af',
entry_point_selector: starknet.getSelectorFromName('balance_of'),
entry_point_selector: stark.getSelectorFromName('balance_of'),
calldata: compileCalldata({
user: '0x58bceda58a83a5a100117ddc893234bad9c84a6833c2008f0f1ca90150149af',
}),
Expand All @@ -82,14 +82,14 @@ describe('defaultProvider', () => {

const contractDefinition = {
...inputContract,
program: starknet.compressProgram(inputContract.program),
program: stark.compressProgram(inputContract.program),
};

const response = await defaultProvider.addTransaction({
type: 'DEPLOY',
contract_address_salt: starknet.randomAddress(),
contract_address_salt: stark.randomAddress(),
constructor_calldata: compileCalldata({
signer: starknet.randomAddress(),
signer: stark.randomAddress(),
guardian: '0',
L1_address: '0',
}),
Expand All @@ -107,7 +107,7 @@ describe('defaultProvider', () => {
const response = await defaultProvider.deployContract(
inputContract,
compileCalldata({
signer: starknet.randomAddress(),
signer: stark.randomAddress(),
guardian: '0',
L1_address: '0',
})
Expand Down
10 changes: 5 additions & 5 deletions __tests__/signer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
ec,
json,
number,
starknet,
stark,
} from '../src';

const compiledArgentAccount: CompiledContract = json.parse(
Expand All @@ -20,9 +20,9 @@ const compiledErc20: CompiledContract = json.parse(
);

describe('deploy and test Wallet', () => {
const pk = starknet.randomAddress();
const privateKey = stark.randomAddress();

const starkKeyPair = ec.getKeyPair(pk);
const starkKeyPair = ec.getKeyPair(privateKey);
const starkKeyPub = ec.getStarkKey(starkKeyPair);
let walletAddress: string;
let erc20: Contract;
Expand Down Expand Up @@ -68,7 +68,7 @@ describe('deploy and test Wallet', () => {
test('read nonce', async () => {
const { result } = await signer.callContract({
contract_address: signer.address,
entry_point_selector: starknet.getSelectorFromName('get_current_nonce'),
entry_point_selector: stark.getSelectorFromName('get_current_nonce'),
});
const nonce = result[0];

Expand All @@ -85,7 +85,7 @@ describe('deploy and test Wallet', () => {
const { code, transaction_hash } = await signer.addTransaction({
type: 'INVOKE_FUNCTION',
contract_address: erc20Address,
entry_point_selector: starknet.getSelectorFromName('transfer'),
entry_point_selector: stark.getSelectorFromName('transfer'),
calldata: [erc20Address, '10'],
});

Expand Down
8 changes: 4 additions & 4 deletions __tests__/utils/ellipticalCurve.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { hashCalldata, hashMessage, pedersen } from '../../src/utils/hash';
import { toBN, toHex } from '../../src/utils/number';

test('getKeyPair()', () => {
const pk = '0x019800ea6a9a73f94aee6a3d2edf018fc770443e90c7ba121e8303ec6b349279';
const pair = getKeyPair(pk);
const privateKey = '0x019800ea6a9a73f94aee6a3d2edf018fc770443e90c7ba121e8303ec6b349279';
const pair = getKeyPair(privateKey);
// somehow needed, returns error else
expect(toHex(toBN(getStarkKey(pair)))).toBe(
'0x33f45f07e1bd1a51b45fc24ec8c8c9908db9e42191be9e169bfcac0c0d99745'
Expand All @@ -30,7 +30,7 @@ test('hashCalldata()', () => {
});

test('hashMessage()', () => {
const pk = '0x019800ea6a9a73f94aee6a3d2edf018fc770443e90c7ba121e8303ec6b349279';
const privateKey = '0x019800ea6a9a73f94aee6a3d2edf018fc770443e90c7ba121e8303ec6b349279';
const hashMsg = hashMessage(
'0x33f45f07e1bd1a51b45fc24ec8c8c9908db9e42191be9e169bfcac0c0d99745',
'5',
Expand All @@ -39,7 +39,7 @@ test('hashMessage()', () => {
'2'
);
expect(hashMsg).toBe('0xf7ec4a68876819eed838be83b5d5dc337081f4a5fb8e421f3d9bdef7c69e9b');
const keyPair = getKeyPair(pk);
const keyPair = getKeyPair(privateKey);
const { r, s } = sign(keyPair, removeHexPrefix(hashMsg));
expect(r.toString()).toStrictEqual(
toBN('2699852629692218907583414128365108566181098618321049245303767746418549764831').toString()
Expand Down
6 changes: 3 additions & 3 deletions __tests__/utils/utils.browser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import fs from 'fs';

import { constants, json, starknet } from '../../src';
import { constants, json, stark } from '../../src';

const { IS_BROWSER } = constants;

Expand All @@ -19,14 +19,14 @@ describe('compressProgram()', () => {
test('compresses a contract program', () => {
const inputContract = compiledArgentAccount as any;

const compressed = starknet.compressProgram(inputContract.program);
const compressed = stark.compressProgram(inputContract.program);

expect(compressed).toMatchSnapshot();
});
test('works with strings', () => {
const inputProgram = json.stringify(compiledArgentAccount.program);

const compressed = starknet.compressProgram(inputProgram);
const compressed = stark.compressProgram(inputProgram);

expect(compressed).toMatchSnapshot();
});
Expand Down
14 changes: 7 additions & 7 deletions __tests__/utils/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'fs';

import { constants, json, number, starknet } from '../../src';
import { constants, json, number, stark } from '../../src';

const { IS_BROWSER } = constants;

Expand All @@ -15,14 +15,14 @@ describe('compressProgram()', () => {
test('compresses a contract program', () => {
const inputProgram = compiledArgentAccount.program;

const compressed = starknet.compressProgram(inputProgram);
const compressed = stark.compressProgram(inputProgram);

expect(compressed).toMatchSnapshot();
});
test('works with strings', () => {
const inputProgram = json.stringify(compiledArgentAccount.program);

const compressed = starknet.compressProgram(inputProgram);
const compressed = stark.compressProgram(inputProgram);

expect(compressed).toMatchSnapshot();
});
Expand All @@ -37,24 +37,24 @@ describe('makeAddress()', () => {
test('test on eth address', () => {
const ethAddress = '0xdFD0F27FCe99b50909de0bDD328Aed6eAbe76BC5';

const starkAddress = starknet.makeAddress(ethAddress);
const starkAddress = stark.makeAddress(ethAddress);

expect(starkAddress).toBe('0xdfd0f27fce99b50909de0bdd328aed6eabe76bc5');
});
});
describe('getSelectorFromName()', () => {
test('hash works for value="test"', () => {
expect(starknet.getSelectorFromName('test')).toBe(
expect(stark.getSelectorFromName('test')).toBe(
'0x22ff5f21f0b81b113e63f7db6da94fedef11b2119b4088b89664fb9a3cb658'
);
});
test('hash works for value="initialize"', () => {
expect(starknet.getSelectorFromName('initialize')).toBe(
expect(stark.getSelectorFromName('initialize')).toBe(
'0x79dc0da7c54b95f10aa182ad0a46400db63156920adb65eca2654c0945a463'
);
});
test('hash works for value="mint"', () => {
expect(starknet.getSelectorFromName('mint')).toBe(
expect(stark.getSelectorFromName('mint')).toBe(
'0x2f0b3c5710379609eb5495f1ecd348cb28167711b73609fe565a72734550354'
);
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"*.{ts,js,md,yml,json}": "prettier --write"
},
"jest": {
"testTimeout": 300000
"testTimeout": 800000
},
"importSort": {
".js, .jsx, .ts, .tsx": {
Expand Down
2 changes: 1 addition & 1 deletion src/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import assert from 'minimalistic-assert';
import { Provider, defaultProvider } from './provider';
import { Abi } from './types';
import { BigNumberish, toBN } from './utils/number';
import { getSelectorFromName } from './utils/starknet';
import { getSelectorFromName } from './utils/stark';

export type Args = { [inputName: string]: string | string[] };
export type Calldata = string[];
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ export * as encode from './utils/encode';
export * as hash from './utils/hash';
export * as json from './utils/json';
export * as number from './utils/number';
export * as starknet from './utils/starknet';
export * as stark from './utils/stark';
export * as ec from './utils/ellipticCurve';
Loading

0 comments on commit 375043b

Please sign in to comment.