diff --git a/__tests__/account.test.ts b/__tests__/account.test.ts index f3659cf6a..90a99222a 100644 --- a/__tests__/account.test.ts +++ b/__tests__/account.test.ts @@ -1,5 +1,3 @@ -import { Signature } from 'micro-starknet'; - import typedDataExample from '../__mocks__/typedDataExample.json'; import { Account, @@ -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, @@ -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); @@ -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(); }); @@ -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 }, @@ -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 }, diff --git a/__tests__/cairo1.test.ts b/__tests__/cairo1.test.ts index bbbcd1725..78206b2c2 100644 --- a/__tests__/cairo1.test.ts +++ b/__tests__/cairo1.test.ts @@ -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, @@ -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(); @@ -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); }); @@ -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]); }); @@ -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]); @@ -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], @@ -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], @@ -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', @@ -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); @@ -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); }); diff --git a/src/index.ts b/src/index.ts index c5713c280..b1ededfba 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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