Skip to content

Commit

Permalink
fix: export utils provider,selector, contract, events. Simulate dev i…
Browse files Browse the repository at this point in the history
…mport on tests
  • Loading branch information
tabaktoni committed Jun 23, 2023
1 parent a5b628f commit 00b7bdf
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 30 deletions.
30 changes: 15 additions & 15 deletions __tests__/account.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { Signature } from 'micro-starknet';

import typedDataExample from '../__mocks__/typedDataExample.json';
import {
Account,
Expand All @@ -8,20 +6,16 @@ import {
Provider,
TransactionStatus,
TransactionType,
cairo,
contractClassResponseToLegacyCompiledContract,
ec,
extractContractHashes,
hash,
num,
parseUDCEvent,
shortString,
stark,
} from '../src';
import { uint256 } from '../src/utils/calldata/cairo';
import {
contractClassResponseToLegacyCompiledContract,
extractContractHashes,
} from '../src/utils/contract';
import { parseUDCEvent } from '../src/utils/events';
import { calculateContractAddressFromHash, feeTransactionVersion } from '../src/utils/hash';
import { cleanHex, hexToDecimalString, toBigInt, toHex } from '../src/utils/num';
import { encodeShortString } from '../src/utils/shortString';
import { randomAddress } from '../src/utils/stark';
import {
compiledErc20,
compiledHelloSierra,
Expand All @@ -37,6 +31,12 @@ import {
} from './fixtures';
import { initializeMatcher } from './schema';

const { cleanHex, hexToDecimalString, toBigInt, toHex } = num;
const { encodeShortString } = shortString;
const { randomAddress } = stark;
const { uint256 } = cairo;
const { Signature } = ec.starkCurve;

describe('deploy and test Wallet', () => {
const provider = new Provider(getTestProvider());
const account = getTestAccount(provider);
Expand Down Expand Up @@ -94,7 +94,7 @@ describe('deploy and test Wallet', () => {
});

expect(result).toMatchSchemaRef('EstimateFee');
expect(innerInvokeEstFeeSpy.mock.calls[0][1].version).toBe(feeTransactionVersion);
expect(innerInvokeEstFeeSpy.mock.calls[0][1].version).toBe(hash.feeTransactionVersion);
innerInvokeEstFeeSpy.mockClear();
});

Expand Down Expand Up @@ -304,7 +304,7 @@ describe('deploy and test Wallet', () => {
await provider.waitForTransaction(declareAccount.transaction_hash);
const privateKey = stark.randomAddress();
const starkKeyPub = ec.starkCurve.getStarkKey(privateKey);
const precalculatedAddress = calculateContractAddressFromHash(
const precalculatedAddress = hash.calculateContractAddressFromHash(
starkKeyPub,
accountClassHash,
{ publicKey: starkKeyPub },
Expand Down Expand Up @@ -612,7 +612,7 @@ describe('deploy and test Wallet', () => {

const privateKey = stark.randomAddress();
starkKeyPub = ec.starkCurve.getStarkKey(privateKey);
precalculatedAddress = calculateContractAddressFromHash(
precalculatedAddress = hash.calculateContractAddressFromHash(
starkKeyPub,
accountClassHash,
{ publicKey: starkKeyPub },
Expand Down
32 changes: 17 additions & 15 deletions __tests__/cairo1.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@ import {
ec,
hash,
num,
selector,
shortString,
stark,
} from '../src';
import { isCairo1Abi } from '../src/utils/calldata/cairo';
import { toHex } from '../src/utils/num';
import { starknetKeccak } from '../src/utils/selector';
import {
compiledC1Account,
compiledC1AccountCasm,
Expand All @@ -34,6 +32,10 @@ import {
} from './fixtures';
import { initializeMatcher } from './schema';

const { uint256, tuple, isCairo1Abi } = cairo;
const { toHex } = num;
const { starknetKeccak } = selector;

describeIfDevnet('Cairo 1 Devnet', () => {
describe('API & Contract interactions', () => {
const provider = getTestProvider();
Expand Down Expand Up @@ -140,7 +142,7 @@ describeIfDevnet('Cairo 1 Devnet', () => {
expect(result).toBe(2n ** 256n - 1n);

// defined as struct
const result1 = await cairo1Contract.test_u256(cairo.uint256(2n ** 256n - 2n));
const result1 = await cairo1Contract.test_u256(uint256(2n ** 256n - 2n));
expect(result1).toBe(2n ** 256n - 1n);
});

Expand Down Expand Up @@ -217,7 +219,7 @@ describeIfDevnet('Cairo 1 Devnet', () => {
});

test('Cairo 1 Contract Interaction - echo flat un-named un-nested tuple', async () => {
const status = await cairo1Contract.echo_un_tuple(cairo.tuple(77, 123));
const status = await cairo1Contract.echo_un_tuple(tuple(77, 123));
expect(Object.values(status)).toEqual([77n, 123n]);
});

Expand All @@ -231,10 +233,10 @@ describeIfDevnet('Cairo 1 Devnet', () => {

// uint256 defined as struct
const status11 = await cairo1Contract.echo_array_u256([
cairo.uint256(123),
cairo.uint256(55),
cairo.uint256(77),
cairo.uint256(255),
uint256(123),
uint256(55),
uint256(77),
uint256(255),
]);
expect(status11).toEqual([123n, 55n, 77n, 255n]);

Expand Down Expand Up @@ -322,7 +324,7 @@ describeIfDevnet('Cairo 1 Devnet', () => {
1: true,
});

const res1 = await cairo1Contract.tuple_echo(cairo.tuple([1, 2, 3], [4, 5, 6]));
const res1 = await cairo1Contract.tuple_echo(tuple([1, 2, 3], [4, 5, 6]));
expect(res1).toEqual({
0: [1n, 2n, 3n],
1: [4n, 5n, 6n],
Expand All @@ -348,7 +350,7 @@ describeIfDevnet('Cairo 1 Devnet', () => {
initial_supply: myFalseUint256,
recipient: '0x7e00d496e324876bbc8531f2d9a82bf154d1a04a50218ee74cdd372f75a551a',
decimals: 18,
tupoftup: cairo.tuple(cairo.tuple(34, '0x5e'), myFalseUint256),
tupoftup: tuple(tuple(34, '0x5e'), myFalseUint256),
card: myOrder2bis,
longText: 'Bug is back, for ever, here and everywhere',
array1: [100, 101, 102],
Expand All @@ -359,9 +361,9 @@ describeIfDevnet('Cairo 1 Devnet', () => {
],
array3: [myOrder2bis, myOrder2bis],
array4: [myFalseUint256, myFalseUint256],
tuple1: cairo.tuple(40000n, myOrder2bis, [54, 55n, '0xae'], 'texte'),
tuple1: tuple(40000n, myOrder2bis, [54, 55n, '0xae'], 'texte'),
name: 'niceToken',
array5: [cairo.tuple(251, 40000n), cairo.tuple(252, 40001n)],
array5: [tuple(251, 40000n), tuple(252, 40001n)],
};
const myRawArgsArray: RawArgsArray = [
'niceToken',
Expand Down Expand Up @@ -520,7 +522,7 @@ describeIfDevnet('Cairo 1 Devnet', () => {
entrypoint: 'transfer',
calldata: {
recipient: toBeAccountAddress,
amount: cairo.uint256(1_000_000_000_000_000),
amount: uint256(1_000_000_000_000_000),
},
});
await account.waitForTransaction(transaction_hash);
Expand Down Expand Up @@ -592,7 +594,7 @@ describeIfSequencerTestnet2('Cairo1 Testnet2', () => {
});

test('Cairo 1 - uint256 struct', async () => {
const myUint256 = cairo.uint256(2n ** 256n - 2n);
const myUint256 = uint256(2n ** 256n - 2n);
const result = await cairo1Contract.test_u256(myUint256);
expect(result).toBe(2n ** 256n - 1n);
});
Expand Down
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,13 @@ export * as shortString from './utils/shortString';
export * as typedData from './utils/typedData';
export * as ec from './utils/ec';
export * as starknetId from './utils/starknetId';
export * as provider from './utils/provider';
export * as selector from './utils/selector';
export * from './utils/address';
export * from './utils/url';
export * from './utils/calldata';
export * from './utils/contract';
export * from './utils/events';

/**
* Deprecated
Expand Down

0 comments on commit 00b7bdf

Please sign in to comment.