Skip to content

Commit

Permalink
Increase coverage (#1329)
Browse files Browse the repository at this point in the history
* fix: add mock test for eth_getTransactionByBlockHashAndIndex

* fix: fix typo

* fix: full coverage for eth_getTransactionByBlockNumberAndIndex

* fix: increase coverage

* fix: remove console.logs

* fix: remove error

* fix: change sonar config
  • Loading branch information
fabiorigam authored Sep 23, 2024
1 parent 5d7cf02 commit b0739f9
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,6 @@ class HardhatVeChainProvider extends VeChainProvider {
error
);
}

// Throw the error
throw this.buildHardhatErrorFunctionCallback(
`Error on request ${args.method}`,
error as Error
);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ const ethGetTransactionByBlockNumberAndIndex = async (
typeof params[1] !== 'string'
)
throw new JSONRPCInvalidParams(
'eth_getTransactionByBlockHashAndIndex',
'eth_getTransactionByBlockNumberAndIndex',
-32602,
`Invalid input params for "eth_getTransactionByBlockHashAndIndex" method. See ${RPC_DOCUMENTATION_URL} for details.`,
`Invalid input params for "eth_getTransactionByBlockNumberAndIndex" method. See ${RPC_DOCUMENTATION_URL} for details.`,
{ params }
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ const ethGetTransactionByBlockHashAndIndexTestCases = [
value: '0x0',
yParity: '0x0'
}
},
{
description:
"eth_getTransactionByBlockHashAndIndex with a hash that doesn't exist",
params: [
'0x000000000b2bce3c70bc649a02749e8687721b09ed2e15997f466536b20bb127',
'0x0'
],
expected: null
}
];

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { HexInt } from '@vechain/sdk-core';
import { JSONRPCInvalidParams } from '@vechain/sdk-errors';
import {
JSONRPCInternalError,
JSONRPCInvalidParams
} from '@vechain/sdk-errors';

/**
* Positive test cases for eth_getTransactionByBlockNumberAndIndex
Expand Down Expand Up @@ -59,6 +62,11 @@ const ethGetTransactionByBlockNumberAndIndexTestCases = [
value: '0x0',
yParity: '0x0'
}
},
{
description: 'eth_getTransactionByBlockHashAndIndex should return null',
params: [HexInt.of(0).toString(), '0x0'],
expected: null
}
];

Expand All @@ -77,6 +85,14 @@ const invalidEthGetTransactionByBlockNumberAndIndexTestCases = [
description: 'Should throw an error when second param is not a strin',
params: ['0x0', 0],
expectedError: JSONRPCInvalidParams
},
{
description: 'Should throw an error when first param is invalid',
params: [
'0xb3b20624f8f0f86eb50dd04688409e5cea4bd02d700bf6e79e9384d47d6a5a35',
'0x0'
],
expectedError: JSONRPCInternalError
}
];

Expand Down
3 changes: 2 additions & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ sonar.test.inclusions=packages/**/tests/**/*
sonar.javascript.lcov.reportPaths=coverage/**/lcov.info
sonar.coverage.exclusions= \
packages/**/index.ts, \
packages/**/jest*.js,
packages/**/jest*.js, \
packages/network/tests/utils/subscriptions/fixture.ts
sonar.cpd.exclusions= \
packages/core/**/const/abi.ts, \
packages/network/src/utils/const/thor-solo/thor-solo.ts, \
Expand Down

1 comment on commit b0739f9

@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: 98%
98.59% (4210/4270) 97.02% (1336/1377) 98.27% (853/868)
Title Tests Skipped Failures Errors Time
core 783 0 💤 0 ❌ 0 🔥 1m 53s ⏱️
network 692 0 💤 0 ❌ 0 🔥 4m 43s ⏱️
errors 42 0 💤 0 ❌ 0 🔥 18.398s ⏱️

Please sign in to comment.