Skip to content

Commit

Permalink
feat: finish!
Browse files Browse the repository at this point in the history
  • Loading branch information
rodolfopietro97 committed Oct 27, 2023
1 parent 215b642 commit 8aacdef
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 67 deletions.
21 changes: 0 additions & 21 deletions packages/core/src/utils/errors.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/core/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export * from './const';
export * from './errors';
export * from './bloom';
export * from './data';
export * from './transaction';
12 changes: 9 additions & 3 deletions packages/core/src/utils/transaction/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { address } from '../../address';
import { type TransactionClause } from '../../transaction';
import { TRANSACTIONS_GAS_CONSTANTS } from '../const';
import { dataUtils } from '../data';
import { ERRORS } from '../errors';
import { buildError, DATA } from '@vechain-sdk/errors';

/**
* Calculates intrinsic gas that a tx costs with the given set of clauses.
Expand All @@ -26,7 +26,10 @@ function intrinsicGas(clauses: TransactionClause[]): number {
if (clause.to !== null) {
// Invalid address
if (!address.isAddress(clause.to)) {
throw new Error(ERRORS.DATA.INVALID_DATA_TYPE('an address'));
throw buildError(
DATA.INVALID_DATA_TYPE,
'Invalid data type. Data should be an address.'
);
}

sum += TRANSACTIONS_GAS_CONSTANTS.CLAUSE_GAS;
Expand All @@ -47,7 +50,10 @@ function intrinsicGas(clauses: TransactionClause[]): number {
function _calculateDataUsedGas(data: string): number {
// Invalid data
if (data !== '' && !dataUtils.isHexString(data)) {
throw new Error(ERRORS.DATA.INVALID_DATA_TYPE('a hexadecimal string'));
throw buildError(
DATA.INVALID_DATA_TYPE,
'Invalid data type. Data should be an hexadecimal string.'
);
}

let sum = 0;
Expand Down
26 changes: 0 additions & 26 deletions packages/core/tests/utils/errors/errors.test.ts

This file was deleted.

11 changes: 7 additions & 4 deletions packages/core/tests/utils/transaction/fixture.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { ERRORS, TRANSACTIONS_GAS_CONSTANTS } from '../../../src';
import { type TransactionClause } from '../../../src';
import {
TRANSACTIONS_GAS_CONSTANTS,
type TransactionClause
} from '../../../src';
import { InvalidDataTypeError } from '@vechain-sdk/errors';

/**
* Invalid clauses data fixture
Expand All @@ -10,14 +13,14 @@ const invalidData = [
to: 'INVALID_ADDRESS',
value: 0,
data: '',
errorToThrow: ERRORS.DATA.INVALID_DATA_TYPE('an address')
errorToThrow: InvalidDataTypeError
},
// Invalid data field format for smart contract creation
{
to: null,
value: 0,
data: 'INVALID_DATA_FORMAT',
errorToThrow: ERRORS.DATA.INVALID_DATA_TYPE('a hexadecimal string')
errorToThrow: InvalidDataTypeError
}
];

Expand Down
24 changes: 12 additions & 12 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1286,14 +1286,14 @@ acorn-jsx@^5.3.2:
integrity sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==

acorn-walk@^8.1.1:
version "8.2.0"
resolved "https://registry.yarnpkg.com/acorn-walk/-/acorn-walk-8.2.0.tgz#741210f2e2426454508853a2f44d0ab83b7f69c1"
integrity sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA==
version "8.3.0"
resolved "https://registry.yarnpkg.com/acorn-walk/-/acorn-walk-8.3.0.tgz#2097665af50fd0cf7a2dfccd2b9368964e66540f"
integrity sha512-FS7hV565M5l1R08MXqo8odwMTB02C2UqzB17RVgu9EyuYFBqJZ3/ZY97sQD5FewVu1UyDFc1yztUDrAwT0EypA==

acorn@^8.4.1, acorn@^8.9.0:
version "8.10.0"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.10.0.tgz#8be5b3907a67221a81ab23c7889c4c5526b62ec5"
integrity sha512-F0SAmZ8iUtS//m8DmCTA0jlh6TDKkHQyK6xc6V4KDTyZKA9dnvX9/3sRTVQrWm79glUAZbnmmNcdYwUIHWVybw==
version "8.11.2"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.11.2.tgz#ca0d78b51895be5390a5903c5b3bdcdaf78ae40b"
integrity sha512-nc0Axzp/0FILLEVsm4fNwLCwMttvhEI263QtVPQcbpfZZ3ts0hLsZGOpE6czNlid7CJ9MlyH8reXkpsf3YUY4w==

[email protected]:
version "3.0.0"
Expand Down Expand Up @@ -1483,9 +1483,9 @@ axios@^0.27.2:
form-data "^4.0.0"

axios@^1.5.1:
version "1.5.1"
resolved "https://registry.yarnpkg.com/axios/-/axios-1.5.1.tgz#11fbaa11fc35f431193a9564109c88c1f27b585f"
integrity sha512-Q28iYCWzNHjAm+yEAot5QaAMxhMghWLFVf7rRdwhUI+c2jix2DUXjAHXVi+s1ibs3mjPO/cCgbA++3BjD0vP/A==
version "1.6.0"
resolved "https://registry.yarnpkg.com/axios/-/axios-1.6.0.tgz#f1e5292f26b2fd5c2e66876adc5b06cdbd7d2102"
integrity sha512-EZ1DYihju9pwVB+jg67ogm+Tmqc6JmhamRN6I4Zt8DfZu5lbcQGw3ozH9lFejSJgs/ibaef3A9PMXPLeefFGJg==
dependencies:
follow-redirects "^1.15.0"
form-data "^4.0.0"
Expand Down Expand Up @@ -2110,9 +2110,9 @@ duplexer2@~0.1.4:
readable-stream "^2.0.2"

electron-to-chromium@^1.4.535:
version "1.4.567"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.567.tgz#c92e8fbc2bd15df3068d92571733a218a5413add"
integrity sha512-8KR114CAYQ4/r5EIEsOmOMqQ9j0MRbJZR3aXD/KFA8RuKzyoUB4XrUCg+l8RUGqTVQgKNIgTpjaG8YHRPAbX2w==
version "1.4.568"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.568.tgz#6ab444e120dd7fd9c3789eac54d3132b6cfcd0f9"
integrity sha512-3TCOv8+BY6Ltpt1/CmGBMups2IdKOyfEmz4J8yIS4xLSeMm0Rf+psSaxLuswG9qMKt+XbNbmADybtXGpTFlbDg==

[email protected], elliptic@^6.5.4:
version "6.5.4"
Expand Down

0 comments on commit 8aacdef

Please sign in to comment.