Skip to content

Commit 70a6dab

Browse files
lukasaricLuka Saricivpavicitabaktonisemantic-release-bot
authored
Chore/replace enums with companion pattern approach (#1083)
* test: test setup refactor & remove rpc sequencer * fix: enable sequencer tests to run on goerli * chore: format markdowns * fix: remove unnecessary goerli describeIf comment * chore: remove setup verifier & simplify envs check logic * test: naming improvements * test: update test setup data log for testnet * test: change from goerli to sepolia * test: rename from rpc testnet to testnet * test: remove `TEST_PROVIDER_BASE_URL` * chore: replace enums with companion pattern * chore: convert caior option & result enums to consts * chore: add `ValuesType<T>` type helper * test: Improve tests performance (#1121) * test: fix transaction retry interval fallback for devnet tests * test: remove test.only * chore: revert from describeIfNot to describeIf * Update _test.yml (#1126) * chore(release): 6.9.0 [skip ci] # [6.9.0](v6.8.0...v6.9.0) (2024-05-21) ### Bug Fixes * cannot infer ts2742 types from [email protected] ([#1098](#1098)) ([f1c3b8e](f1c3b8e)) * remove [warning] from typedoc for external usage ([#1095](#1095)) ([195186f](195186f)), closes [#1121](#1121) [#1126](#1126) ### Features * add type coverage ([#1120](#1120)) ([eceda5d](eceda5d)) * provider.getL1MessageHash ([#1123](#1123)) ([1489cf2](1489cf2)) ### Reverts * Revert "chore: add examples to JsDoc for transaction.ts file (#1105)" (#1108) ([59eb01e](59eb01e)), closes [#1105](#1105) [#1108](#1108) * fix: use proper constants --------- Co-authored-by: Luka Saric <[email protected]> Co-authored-by: Ivan Pavičić <[email protected]> Co-authored-by: Toni Tabak <[email protected]> Co-authored-by: semantic-release-bot <[email protected]>
1 parent 12fd0f8 commit 70a6dab

File tree

26 files changed

+350
-246
lines changed

26 files changed

+350
-246
lines changed

.eslintrc

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,15 @@
55
"node": true,
66
"jest": true
77
},
8-
"extends": ["airbnb-base", "airbnb-typescript/base", "prettier", "plugin:prettier/recommended"],
9-
"ignorePatterns": ["tsup.config.ts"],
8+
"extends": [
9+
"airbnb-base",
10+
"airbnb-typescript/base",
11+
"prettier",
12+
"plugin:prettier/recommended"
13+
],
14+
"ignorePatterns": [
15+
"tsup.config.ts"
16+
],
1017
"globals": {
1118
"Atomics": "readonly",
1219
"SharedArrayBuffer": "readonly"
@@ -17,13 +24,24 @@
1724
"sourceType": "module",
1825
"project": "./tsconfig.eslint.json"
1926
},
20-
"plugins": ["@typescript-eslint"],
27+
"plugins": [
28+
"@typescript-eslint"
29+
],
2130
"rules": {
2231
"class-methods-use-this": 0,
2332
"import/prefer-default-export": 0,
33+
"@typescript-eslint/no-redeclare": 0,
2434
"@typescript-eslint/naming-convention": 0,
25-
"@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_" }],
26-
"@typescript-eslint/no-use-before-define": ["error", "nofunc"],
35+
"@typescript-eslint/no-unused-vars": [
36+
"error",
37+
{
38+
"argsIgnorePattern": "^_"
39+
}
40+
],
41+
"@typescript-eslint/no-use-before-define": [
42+
"error",
43+
"nofunc"
44+
],
2745
"func-names": 0
2846
}
2947
}

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
# [6.9.0](https://github.com/starknet-io/starknet.js/compare/v6.8.0...v6.9.0) (2024-05-21)
2+
3+
### Bug Fixes
4+
5+
- cannot infer ts2742 types from [email protected] ([#1098](https://github.com/starknet-io/starknet.js/issues/1098)) ([f1c3b8e](https://github.com/starknet-io/starknet.js/commit/f1c3b8e3aeb96f6efb7e512ac3ba689253004c9d))
6+
- remove [warning] from typedoc for external usage ([#1095](https://github.com/starknet-io/starknet.js/issues/1095)) ([195186f](https://github.com/starknet-io/starknet.js/commit/195186fc2974ab0d164b1a48c68f7bf026329df5)), closes [#1121](https://github.com/starknet-io/starknet.js/issues/1121) [#1126](https://github.com/starknet-io/starknet.js/issues/1126)
7+
8+
### Features
9+
10+
- add type coverage ([#1120](https://github.com/starknet-io/starknet.js/issues/1120)) ([eceda5d](https://github.com/starknet-io/starknet.js/commit/eceda5dc1c39e472e1105e07797e76aaac3c1531))
11+
- provider.getL1MessageHash ([#1123](https://github.com/starknet-io/starknet.js/issues/1123)) ([1489cf2](https://github.com/starknet-io/starknet.js/commit/1489cf25e7e8598ab161cecc62c82495f64daa33))
12+
13+
### Reverts
14+
15+
- Revert "chore: add examples to JsDoc for transaction.ts file (#1105)" (#1108) ([59eb01e](https://github.com/starknet-io/starknet.js/commit/59eb01e451cf64dfdacd6d34b2a709e0a1029f15)), closes [#1105](https://github.com/starknet-io/starknet.js/issues/1105) [#1108](https://github.com/starknet-io/starknet.js/issues/1108)
16+
117
# [6.8.0](https://github.com/starknet-io/starknet.js/compare/v6.7.0...v6.8.0) (2024-04-23)
218

319
### Bug Fixes

__tests__/account.starknetId.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ describe('deploy and test Wallet', () => {
9393

9494
test('Get the stark name of the account (using starknet.id)', async () => {
9595
const address = await account.getAddressFromStarkName('fricoben.stark', namingAddress);
96-
expect(hexToDecimalString(address as string)).toEqual(hexToDecimalString(account.address));
96+
expect(hexToDecimalString(address)).toEqual(hexToDecimalString(account.address));
9797
});
9898

9999
test('Get the account from a stark name of the account (using starknet.id)', async () => {

__tests__/utils/starknetId.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ function generateString(length: number, seed: number): string {
1818
return result;
1919
}
2020

21-
describe('Should tets StarknetId utils', () => {
21+
describe('Should test StarknetId utils', () => {
2222
test('Should test useEncoded and useDecoded hook with a random string', () => {
2323
for (let index = 0; index < 2500; index += 1) {
2424
const randomString = generateString(10, index);
25-
expect(useDecoded([useEncoded(randomString)])).toBe(randomString.concat('.stark'));
25+
const decoded = useDecoded([useEncoded(randomString)]);
26+
expect(decoded).toBe(randomString.concat('.stark'));
2627
}
2728
});
2829

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "starknet",
3-
"version": "6.8.0",
3+
"version": "6.9.0",
44
"description": "JavaScript library for Starknet",
55
"main": "dist/index.js",
66
"module": "dist/index.mjs",

src/account/default.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,16 @@ export class Account extends Provider implements AccountInterface {
6767

6868
public cairoVersion: CairoVersion;
6969

70-
readonly transactionVersion: ETransactionVersion.V2 | ETransactionVersion.V3;
70+
readonly transactionVersion: typeof ETransactionVersion.V2 | typeof ETransactionVersion.V3;
7171

7272
constructor(
7373
providerOrOptions: ProviderOptions | ProviderInterface,
7474
address: string,
7575
pkOrSigner: Uint8Array | string | SignerInterface,
7676
cairoVersion?: CairoVersion,
77-
transactionVersion: ETransactionVersion.V2 | ETransactionVersion.V3 = ETransactionVersion.V2 // TODO: Discuss this, set to v2 for backward compatibility
77+
transactionVersion:
78+
| typeof ETransactionVersion.V2
79+
| typeof ETransactionVersion.V3 = ETransactionVersion.V2 // TODO: Discuss this, set to v2 for backward compatibility
7880
) {
7981
super(providerOrOptions);
8082
this.address = address.toLowerCase();

src/channel/rpc_0_6.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import { getVersionsByType } from '../utils/transaction';
3131

3232
const defaultOptions = {
3333
headers: { 'Content-Type': 'application/json' },
34-
blockIdentifier: BlockTag.pending,
34+
blockIdentifier: BlockTag.PENDING,
3535
retries: 200,
3636
};
3737

@@ -93,7 +93,7 @@ export class RpcChannel {
9393
if (rpcError) {
9494
const { code, message, data } = rpcError;
9595
throw new LibraryError(
96-
`RPC: ${method} with params ${stringify(params, null, 2)}\n
96+
`RPC: ${method} with params ${stringify(params, null, 2)}\n
9797
${code}: ${message}: ${stringify(data)}`
9898
);
9999
}

src/channel/rpc_0_7.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import { getVersionsByType } from '../utils/transaction';
3131

3232
const defaultOptions = {
3333
headers: { 'Content-Type': 'application/json' },
34-
blockIdentifier: BlockTag.pending,
34+
blockIdentifier: BlockTag.PENDING,
3535
retries: 200,
3636
};
3737

src/constants.ts

Lines changed: 44 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ETransactionVersion } from './types/api';
2+
import { ValuesType } from './types/helpers/valuesType';
23

34
export { IS_BROWSER } from './utils/encode';
45

@@ -24,43 +25,56 @@ export const MAX_STORAGE_ITEM_SIZE = 256n;
2425
export const ADDR_BOUND = 2n ** 251n - MAX_STORAGE_ITEM_SIZE;
2526

2627
const range = (min: bigint, max: bigint) => ({ min, max }) as const;
28+
2729
export const RANGE_FELT = range(ZERO, PRIME - 1n);
2830
export const RANGE_I128 = range(-(2n ** 127n), 2n ** 127n - 1n);
2931
export const RANGE_U128 = range(ZERO, 2n ** 128n - 1n);
3032

31-
export enum BaseUrl {
32-
SN_MAIN = 'https://alpha-mainnet.starknet.io',
33-
SN_SEPOLIA = 'https://alpha-sepolia.starknet.io',
34-
}
35-
36-
export enum NetworkName {
37-
SN_MAIN = 'SN_MAIN',
38-
SN_SEPOLIA = 'SN_SEPOLIA',
39-
}
40-
41-
export enum StarknetChainId {
42-
SN_MAIN = '0x534e5f4d41494e', // encodeShortString('SN_MAIN'),
43-
SN_SEPOLIA = '0x534e5f5345504f4c4941', // encodeShortString('SN_SEPOLIA')
44-
}
45-
46-
export enum TransactionHashPrefix {
47-
DECLARE = '0x6465636c617265', // encodeShortString('declare'),
48-
DEPLOY = '0x6465706c6f79', // encodeShortString('deploy'),
49-
DEPLOY_ACCOUNT = '0x6465706c6f795f6163636f756e74', // encodeShortString('deploy_account'),
50-
INVOKE = '0x696e766f6b65', // encodeShortString('invoke'),
51-
L1_HANDLER = '0x6c315f68616e646c6572', // encodeShortString('l1_handler'),
52-
}
53-
54-
export const enum feeMarginPercentage {
55-
L1_BOUND_MAX_AMOUNT = 50,
56-
L1_BOUND_MAX_PRICE_PER_UNIT = 50,
57-
MAX_FEE = 50,
58-
}
33+
export const BaseUrl = {
34+
SN_MAIN: 'https://alpha-mainnet.starknet.io',
35+
SN_SEPOLIA: 'https://alpha-sepolia.starknet.io',
36+
} as const;
37+
38+
export type BaseUrl = ValuesType<typeof BaseUrl>;
39+
40+
export const NetworkName = {
41+
SN_MAIN: 'SN_MAIN',
42+
SN_SEPOLIA: 'SN_SEPOLIA',
43+
} as const;
44+
45+
export type NetworkName = ValuesType<typeof NetworkName>;
46+
47+
export const StarknetChainId = {
48+
SN_MAIN: '0x534e5f4d41494e', // encodeShortString('SN_MAIN'),
49+
SN_SEPOLIA: '0x534e5f5345504f4c4941', // encodeShortString('SN_SEPOLIA')
50+
} as const;
51+
52+
export type StarknetChainId = ValuesType<typeof StarknetChainId>;
53+
54+
export const TransactionHashPrefix = {
55+
DECLARE: '0x6465636c617265', // encodeShortString('declare'),
56+
DEPLOY: '0x6465706c6f79', // encodeShortString('deploy'),
57+
DEPLOY_ACCOUNT: '0x6465706c6f795f6163636f756e74', // encodeShortString('deploy_account'),
58+
INVOKE: '0x696e766f6b65', // encodeShortString('invoke'),
59+
L1_HANDLER: '0x6c315f68616e646c6572', // encodeShortString('l1_handler'),
60+
} as const;
61+
62+
export type TransactionHashPrefix = ValuesType<typeof TransactionHashPrefix>;
63+
64+
export const FeeMarginPercentage = {
65+
L1_BOUND_MAX_AMOUNT: 50,
66+
L1_BOUND_MAX_PRICE_PER_UNIT: 50,
67+
MAX_FEE: 50,
68+
} as const;
69+
70+
export type FeeMarginPercentage = ValuesType<typeof FeeMarginPercentage>;
5971

6072
export const UDC = {
6173
ADDRESS: '0x041a78e741e5af2fec34b695679bc6891742439f7afb8484ecd7766661ad02bf',
6274
ENTRYPOINT: 'deployContract',
63-
};
75+
} as const;
76+
77+
export type UDC = ValuesType<typeof UDC>;
6478

6579
export const RPC_DEFAULT_VERSION = 'v0_7';
6680

@@ -73,4 +87,4 @@ export const RPC_NODES = {
7387
`https://starknet-sepolia.public.blastapi.io/rpc/${RPC_DEFAULT_VERSION}`,
7488
`https://free-rpc.nethermind.io/sepolia-juno/${RPC_DEFAULT_VERSION}`,
7589
],
76-
};
90+
} as const;

0 commit comments

Comments
 (0)