Skip to content

Commit

Permalink
fix: removed circular dependencies from the core package (#1349)
Browse files Browse the repository at this point in the history
* fix: circular dependency 1

* fix: circular dependency 1

* fix: more dependencies fixed

* fix: more dependencies fixed

* fix: more dependencies fixed

* fix: more fixes

* fix: more fixes

* fix: more fixes

* fix: more fixes

* fix: more fixes

* fix: more fixes

* fix: more fixes

* fix: more fixes

* fix: more fixes

* fix: added exclusion temporarily

* fix: added exclusion temporarily
  • Loading branch information
freemanzMrojo authored Sep 26, 2024
1 parent 8f60e9e commit b09bbfb
Show file tree
Hide file tree
Showing 27 changed files with 117 additions and 120 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ jobs:

- name: Lint
run: yarn lint

- name: Circular dependencies check
run: yarn check:circular-dependencies

- name: Build
run: yarn build
3 changes: 2 additions & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
yarn build
yarn lint
yarn check:circular-dependencies
yarn test:unit && git add docs
yarn check-tests-naming
yarn check:tests-naming
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"stop-thor-solo": "echo 'Stopping thor solo node ...' && docker compose down && echo 'Thor solo node stopped ...'",
"postinstall": "husky",
"build": "turbo build",
"check:circular-dependencies": "turbo check:circular-dependencies",
"pre-release": "ts-node scripts/pre-release.ts",
"test-rpc-proxy": "ts-node scripts/test-rpc-proxy.ts",
"generate:apidocs": "typedoc --options typedoc.json --logLevel Error",
Expand All @@ -40,7 +41,7 @@
"test:solo": "(yarn start-thor-solo && yarn test && yarn stop-thor-solo) || yarn stop-thor-solo",
"test:browser:solo": "(yarn start-thor-solo && yarn test:browser && yarn stop-thor-solo) || yarn stop-thor-solo",
"merge-coverage": "ts-node scripts/merge-coverage.ts",
"check-tests-naming": "ts-node scripts/check-tests-naming.ts"
"check:tests-naming": "ts-node scripts/check-tests-naming.ts"
},
"devDependencies": {
"@changesets/cli": "^2.27.7",
Expand Down
1 change: 1 addition & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
],
"scripts": {
"build": "rm -rf ./dist && tsup-node src/index.ts --format cjs,esm --dts",
"check:circular-dependencies": "npx madge --exclude 'transaction/Clause.ts' --circular --extensions ts src",
"lint": "eslint --ext .ts src --ext .ts tests",
"format": "prettier --write src/**/*.ts tests/**/*.ts",
"test:unit": "rm -rf ./coverageUnit && jest --coverage --coverageDirectory=coverageUnit --group=unit",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Hex } from '../../../vcdm';
import { Hex } from '../../../vcdm/Hex';
import { InvalidRLP } from '@vechain/sdk-errors';

/**
Expand Down
8 changes: 5 additions & 3 deletions packages/core/src/encoding/rlp/helpers/numerickind.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { InvalidRLP } from '@vechain/sdk-errors';
import { FixedPointNumber, Hex, HexUInt } from '../../../vcdm';
import { FixedPointNumber } from '../../../vcdm/FixedPointNumber';
import { Hex } from '../../../vcdm/Hex';
import { HexUInt } from '../../../vcdm/HexUInt';
import { type RLPInput } from '../types';

/**
Expand Down Expand Up @@ -204,8 +206,8 @@ const decodeBufferToNumberOrHex = (buffer: Buffer): number | string => {
};

export {
validateNumericKindData,
assertValidNumericKindBuffer,
decodeBufferToNumberOrHex,
encodeBigIntToBuffer,
decodeBufferToNumberOrHex
validateNumericKindData
};
3 changes: 1 addition & 2 deletions packages/core/src/encoding/rlp/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { RLPBase } from './rlp';
import { RLPProfiles } from './kind';
import * as RLPProfiles from './kind';

export * from './rlp';
export * from './kind';
export type * from './types.d';
export * from './helpers';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Hex } from '../../../../vcdm';
import { Hex } from '../../../../vcdm/Hex';
import { ScalarKind } from '../scalarkind.abstract';
import {
assertValidHexBlobKindBuffer,
Expand Down
17 changes: 3 additions & 14 deletions packages/core/src/encoding/rlp/kind/index.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
import { BufferKind } from './bufferkind';
import { NumericKind } from './numerickind';
import { ScalarKind } from './scalarkind.abstract';
import { ScalarKind, type RLPProfile } from './scalarkind.abstract';
import {
CompactFixedHexBlobKind,
FixedHexBlobKind,
HexBlobKind,
OptionalFixedHexBlobKind
} from './hexblobkinds';

/**
* RLP_CODER profile classes.
*/
export const RLPProfiles: {
ScalarKind: typeof ScalarKind;
BufferKind: typeof BufferKind;
NumericKind: typeof NumericKind;
HexBlobKind: typeof HexBlobKind;
FixedHexBlobKind: typeof FixedHexBlobKind;
OptionalFixedHexBlobKind: typeof OptionalFixedHexBlobKind;
CompactFixedHexBlobKind: typeof CompactFixedHexBlobKind;
} = {
export {
ScalarKind,
BufferKind,
NumericKind,
Expand All @@ -29,4 +18,4 @@ export const RLPProfiles: {
CompactFixedHexBlobKind
};

export type { ScalarKind };
export type { RLPProfile };
29 changes: 25 additions & 4 deletions packages/core/src/encoding/rlp/kind/scalarkind.abstract.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@
import {
type RLPInput,
type BufferOutput,
type RLPValidObject,
type DataOutput
type DataOutput,
type RLPInput,
type RLPValidObject
} from '../types';

/* ------- RLP Profile Types ------- */
/**
* `RLPProfile` Interface - Describes the profile of the RLP encoding.
*/
interface RLPProfile {
name: string;
kind: ScalarKind | ArrayKind | StructKind;
}

/**
* `ArrayKind` Interface - Describes an array-kind in the RLP encoding profile.
*/
interface ArrayKind {
item: RLPProfile['kind'];
}

/**
* `StructKind` Type - Describes a structured-kind in the RLP encoding profile using an array of `RLPProfile`.
*/
type StructKind = RLPProfile[];

/**
* `ScalarKind` Abstract Class - A base for scalar kinds providing contract for data and buffer manipulations.
*/
Expand All @@ -29,4 +50,4 @@ abstract class ScalarKind {
public abstract buffer(buffer: Buffer, context: string): BufferOutput;
}

export { ScalarKind };
export { ScalarKind, type RLPProfile };
9 changes: 4 additions & 5 deletions packages/core/src/encoding/rlp/rlp.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { RLP } from '@ethereumjs/rlp';
import { InvalidRLP } from '@vechain/sdk-errors';
import { ScalarKind, type RLPProfile } from './kind/scalarkind.abstract';
import {
type RLPInput,
type RLPOutput,
type RLPProfile,
type RLPValidObject,
type RLPValueType
} from './types';
import { RLPProfiles } from '.';
import { InvalidRLP } from '@vechain/sdk-errors';

/**
* Encodes data using the Ethereumjs RLP library.
Expand Down Expand Up @@ -81,7 +80,7 @@ const _packData = (
const kind = profile.kind;

// ScalarKind: direct encoding using the provided method.
if (kind instanceof RLPProfiles.ScalarKind) {
if (kind instanceof ScalarKind) {
return kind.data(obj, context).encode();
}

Expand Down Expand Up @@ -142,7 +141,7 @@ const _unpackData = (
const kind = profile.kind;

// ScalarKind: Direct decoding using the provided method.
if (kind instanceof RLPProfiles.ScalarKind) {
if (kind instanceof ScalarKind) {
if (!Buffer.isBuffer(packed) && !(packed instanceof Uint8Array)) {
throw new InvalidRLP(
'_unpackData()',
Expand Down
31 changes: 3 additions & 28 deletions packages/core/src/encoding/rlp/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { type Input, type NestedUint8Array } from '@ethereumjs/rlp';
import { type ScalarKind } from './kind';
/**
* Represents a valid input for the RLP (Recursive Length Prefix) encoding.
* The RLP encoding is used to encode arbitrary binary data (nested arrays of bytes).
Expand Down Expand Up @@ -51,27 +50,6 @@ type RLPValidObject = Record<string, RLPValueType>;
*/
type RLPValueType = RLPInput | RLPComplexObject | RLPComplexObject[];

/* ------- RLP Profile Types ------- */
/**
* `RLPProfile` Interface - Describes the profile of the RLP encoding.
*/
interface RLPProfile {
name: string;
kind: ScalarKind | ArrayKind | StructKind;
}

/**
* `ArrayKind` Interface - Describes an array-kind in the RLP encoding profile.
*/
interface ArrayKind {
item: RLPProfile['kind'];
}

/**
* `StructKind` Type - Describes a structured-kind in the RLP encoding profile using an array of `RLPProfile`.
*/
type StructKind = RLPProfile[];

/**
* `DataOutput` Interface - Provides an encoding mechanism to convert data into a Buffer.
*/
Expand All @@ -87,13 +65,10 @@ interface BufferOutput {
}

export type {
BufferOutput,
DataOutput,
RLPInput,
RLPOutput,
RLPValidObject,
RLPValueType,
RLPProfile,
ArrayKind,
StructKind,
DataOutput,
BufferOutput
RLPValueType
};
5 changes: 3 additions & 2 deletions packages/core/src/hdkey/HDKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import * as s_bip32 from '@scure/bip32';
import * as s_bip39 from '@scure/bip39';
import * as nc_utils from '@noble/curves/abstract/utils';
import { base58 } from '@scure/base';
import { FixedPointNumber, Sha256 } from '../vcdm';
import { FixedPointNumber } from '../vcdm/FixedPointNumber';
import { Sha256 } from '../vcdm/hash/Sha256';
import { HexUInt } from '../vcdm/HexUInt';
import { Secp256k1 } from '../secp256k1';
import { Secp256k1 } from '../secp256k1/Secp256k1';
import {
InvalidHDKey,
InvalidHDKeyMnemonic,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/secp256k1/Secp256k1.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as nc_utils from '@noble/curves/abstract/utils';
import { HexUInt } from '../vcdm';
import { HexUInt } from '../vcdm/HexUInt';
import { randomBytes as nh_randomBytes } from '@noble/hashes/utils';
import { secp256k1 as nc_secp256k1 } from '@noble/curves/secp256k1';
import {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/transaction/Clause.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { InvalidDataType } from '@vechain/sdk-errors';
import { ERC721_ABI, VIP180_ABI } from '../utils';
import {
abi,
ABIContract,
Expand All @@ -11,9 +12,8 @@ import {
} from '../vcdm';
import { Hex } from '../vcdm/Hex';
import { HexInt } from '../vcdm/HexInt';
import { ERC721_ABI, VIP180_ABI } from '../utils';
import { type ClauseOptions, type TransactionClause } from './index';
import type { DeployParams } from './DeployParams';
import { type ClauseOptions, type TransactionClause } from './types';

/**
* This class represent a transaction clause.
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/transaction/handlers/sign.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Address } from '../../vcdm';
import { Address } from '../../vcdm/Address';
import { Secp256k1 } from '../../secp256k1';
import { Transaction } from '../transaction';
import {
Expand Down
7 changes: 4 additions & 3 deletions packages/core/src/transaction/transaction.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { Address, Hex } from '../vcdm';
import { Blake2b256 } from '../vcdm/hash/Blake2b256';
import {
InvalidSecp256k1Signature,
InvalidTransactionField,
NotDelegatedTransaction,
UnavailableTransactionField
} from '@vechain/sdk-errors';
import { type RLPValidObject } from '../encoding';
import { Secp256k1 } from '../secp256k1';
import {
BLOCK_REF_LENGTH,
Expand All @@ -15,7 +14,9 @@ import {
TransactionUtils,
UNSIGNED_TRANSACTION_RLP
} from '../utils';
import { type RLPValidObject } from '../encoding';
import { Address } from '../vcdm/Address';
import { Hex } from '../vcdm/Hex';
import { Blake2b256 } from '../vcdm/hash/Blake2b256';
import { type TransactionBody } from './types';

/**
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/utils/data/data.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as nc_utils from '@noble/curves/abstract/utils';
import { Hex, Txt } from '../../vcdm';
import { InvalidDataType } from '@vechain/sdk-errors';
import { Hex } from '../../vcdm/Hex';
import { Txt } from '../../vcdm/Txt';
import { ZERO_BYTES } from '../const';

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/utils/transaction/transaction.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { InvalidDataType } from '@vechain/sdk-errors';
import { type TransactionClause } from '../../transaction';
import { Address } from '../../vcdm';
import { type TransactionClause } from '../../transaction/types';
import { Address } from '../../vcdm/Address';
import { Hex } from '../../vcdm/Hex';
import { TRANSACTIONS_GAS_CONSTANTS } from '../const';

Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/vcdm/Address.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Keccak256 } from './hash/Keccak256';
import { HDKey } from '../hdkey';
import { HDKey } from '../hdkey/HDKey';
import { Hex } from './Hex';
import { HexUInt } from './HexUInt';
import { Secp256k1 } from '../secp256k1';
import { Secp256k1 } from '../secp256k1/Secp256k1';
import { Txt } from './Txt';
import {
InvalidDataType,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/vcdm/account/Account.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { InvalidOperation } from '@vechain/sdk-errors';
import { type Address } from '../Address';
import { type Currency } from '../currency';
import { type Currency } from '../currency/Currency';
import { type VeChainDataModel } from '../VeChainDataModel';

type AccountType = 'EOA' | 'Contract';
Expand Down
7 changes: 3 additions & 4 deletions packages/core/src/vcdm/currency/VET.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { Clause } from '../../transaction';
import { Coin } from './Coin';
import { Clause, type ClauseOptions } from '../../transaction';
import { type Address } from '../Address';
import { FixedPointNumber } from '../FixedPointNumber';
import { Txt } from '../Txt';
import { Coin } from './Coin';
import { Units } from './Units';
import { type Address } from '../Address';
import { type ClauseOptions } from '../../transaction';

/**
* Represents a
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/vcdm/hash/Blake2b256.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { blake2b as nh_blake2b } from '@noble/hashes/blake2b';
import { InvalidOperation } from '@vechain/sdk-errors';
import { Hex, Txt } from '../index';
import { Hex } from '../Hex';
import { HexUInt } from '../HexUInt';
import { Txt } from '../Txt';

/**
* Represents the result of an [BLAKE](https://en.wikipedia.org/wiki/BLAKE_(hash_function)) [BlAKE2B 256](https://www.blake2.net/) hash operation.
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/vcdm/hash/Keccak256.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { keccak_256 as nh_keccak_256 } from '@noble/hashes/sha3';
import { InvalidOperation } from '@vechain/sdk-errors';
import { Hex, Txt } from '../index';
import { Hex } from '../Hex';
import { HexUInt } from '../HexUInt';
import { Txt } from '../Txt';

/**
* Represents the result of an [SHA-3](https://en.wikipedia.org/wiki/SHA-3) [KECCAK 256](https://keccak.team/keccak.html) hash operation.
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/vcdm/hash/Sha256.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as nh_sha256 from '@noble/hashes/sha256';
import { InvalidOperation } from '@vechain/sdk-errors';
import { Hex, Txt } from '../index';
import { Hex } from '../Hex';
import { HexUInt } from '../HexUInt';
import { Txt } from '../Txt';

/**
* Represents the result of an [SHA256](https://en.wikipedia.org/wiki/SHA-2) hash operation.
Expand Down
Loading

1 comment on commit b09bbfb

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test Coverage

Summary

Lines Statements Branches Functions
Coverage: 97%
97.8% (4184/4278) 95.83% (1359/1418) 97.05% (856/882)
Title Tests Skipped Failures Errors Time
core 764 0 💤 0 ❌ 0 🔥 1m 52s ⏱️
network 692 0 💤 0 ❌ 0 🔥 4m 30s ⏱️
errors 42 0 💤 0 ❌ 0 🔥 17.331s ⏱️

Please sign in to comment.