Skip to content

Commit

Permalink
fix: added TEST_TRANSACTION_RECORD_COST_TOLERANCE config
Browse files Browse the repository at this point in the history
Signed-off-by: Logan Nguyen <[email protected]>
  • Loading branch information
quiet-node committed Oct 31, 2024
1 parent aafba38 commit 2bf2bf2
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 18 deletions.
24 changes: 13 additions & 11 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ The following table lists the available properties along with their default valu
Unless you need to set a non-default value, it is recommended to only populate overridden properties in the custom `.env`.

| Name | Default | Description |
|-----------------------------|-----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| --------------------------- | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `BATCH_REQUESTS_ENABLED` | "true" | Flag to disable or enable batch requests. |
| `BATCH_REQUESTS_MAX_SIZE` | "100" | Maximum number of requests allowed in a batch. |
| `CHAIN_ID` | "" | The network chain id. Local and previewnet envs should use `0x12a` (298). Previewnet, Testnet and Mainnet should use `0x129` (297), `0x128` (296) and `0x127` (295) respectively. |
| `HEDERA_NETWORK` | "" | Which network to connect to. Automatically populates the main node & mirror node endpoints. Can be `previewnet`, `testnet`, `mainnet` or a map of network IPs -> node accountIds e.g. `{"127.0.0.1:50211":"0.0.3"}` |
| `INPUT_SIZE_LIMIT` | "1mb" | The [koa-jsonrpc](https://github.com/Bitclimb/koa-jsonrpc) maximum size allowed for requests |
| `LOG_LEVEL ` | "trace" | The logging level for the application. Valid values are `trace`, `debug`, `info`, `warn`, `error`, and `fatal`. |
| `LOG_LEVEL ` | "trace" | The logging level for the application. Valid values are `trace`, `debug`, `info`, `warn`, `error`, and `fatal`. |
| `MAX_BLOCK_RANGE` | "5" | The maximum block number greater than the mirror node's latest block to query for |
| `OPERATOR_ID_MAIN` | "" | Operator account ID used to pay for transactions. In `S.R.N` format, e.g. `0.0.1001`. |
| `OPERATOR_KEY_FORMAT` | "DER" | Operator private key format. Valid types are `DER`, `HEX_ECDSA`, or `HEX_ED25519` |
Expand All @@ -50,7 +50,7 @@ The following table lists the available properties along with their default valu
Unless you need to set a non-default value, it is recommended to only populate overridden properties in the custom `.env`.

| Name | Default | Description |
|---------------------------------------------|----------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ------------------------------------------- | -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `CACHE_MAX` | "1000" | The maximum number (or size) of items that remain in the cache (assuming no TTL pruning or explicit deletions). |
| `CACHE_TTL` | "3_600_000" | Max time to live in ms, for items before they are considered stale. Default is one hour in milliseconds |
| `CLIENT_TRANSPORT_SECURITY` | "false" | Flag to enable or disable TLS for both networks. |
Expand Down Expand Up @@ -117,7 +117,7 @@ The following table lists the available properties along with their default valu
Unless you need to set a non-default value, it is recommended to only populate overridden properties in the custom `.env`.

| Name | Default | Description |
|---------------------------------|-------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ------------------------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `WS_BATCH_REQUESTS_ENABLED` | "true" | Flag to disable or enable batch requests on the websocket server. |
| `WS_BATCH_REQUESTS_MAX_SIZE` | "20" | Maximum number of requests allowed in a batch on websocket server. |
| `SUBSCRIPTIONS_ENABLED` | "false" | If enabled eth_subscribe will be enabled using WebSockets. |
Expand Down Expand Up @@ -182,13 +182,14 @@ See [`.env.previewnet.sample`](./examples/.env.previewnet.sample).
The following table lists the available properties along with their default values for the tests utilized in the [Server](/packages/server/) and [Relay](/packages/relay/) packages.
Unless you need to set a non-default value, it is recommended to only populate overridden properties in the custom `.env`.

| Name | Default | Description |
| -------------------------- | ------- | ----------------------------------------------------------------------------- |
| `LOCAL_NODE` | "" | Flag if relay is hosted in the Hedera local node setup. |
| `E2E_RELAY_HOST` | "" | Remote relay url to point to. |
| `DEV_MODE` | "false" | Flag if relay should operate in developer optimization mode. |
| `TEST_WS_SERVER` | "false" | Flag config for enable or disable the WS server tests. |
| `TEST_GAS_PRICE_DEVIATION` | 0.2 | Value to use as deviation when comparing gas prices in the rpc-batch1.spec.ts |
| Name | Default | Description |
| ---------------------------------------- | ------- | -------------------------------------------------------------------------------------------------- |
| `LOCAL_NODE` | "" | Flag if relay is hosted in the Hedera local node setup. |
| `E2E_RELAY_HOST` | "" | Remote relay url to point to. |
| `DEV_MODE` | "false" | Flag if relay should operate in developer optimization mode. |
| `TEST_WS_SERVER` | "false" | Flag config for enable or disable the WS server tests. |
| `TEST_GAS_PRICE_DEVIATION` | 0.2 | Value to use as deviation when comparing gas prices in the rpc-batch1.spec.ts |
| `TEST_TRANSACTION_RECORD_COST_TOLERANCE` | 0.02 | Defines the acceptable tolerance level for discrepancies in transaction record costs during tests. |

For test context additional fields need to be set. The following example showcases a `hedera-local-node` instance (where values match those noted on [Local Node Network Variables](https://github.com/hashgraph/hedera-local-node#network-variables)

Expand Down Expand Up @@ -230,6 +231,7 @@ CLIENT_DURATION_RESET= 21600
CLIENT_ERROR_RESET= 100
MAX_CHUNKS=20
TEST_GAS_PRICE_DEVIATION=0.80
TEST_TRANSACTION_RECORD_COST_TOLERANCE=0.05
```

> **_NOTE:_** Acceptance tests can be pointed at a remote locations (previewnet and testnet and custom environments). In this case configuration will require details for remote consensus node gRPC endpoints [previewnet / testnet](https://docs.hedera.com/hedera/networks/testnet/testnet-nodes) / [mainnet](https://docs.hedera.com/hedera/networks/mainnet/mainnet-nodes) and [Mirror Node REST API endpoints](https://docs.hedera.com/hedera/sdks-and-apis/rest-api), be sure to configure `HEDERA_NETWORK` and `MIRROR_NODE_URL` appropriately to point away from your local host and to valid deployed services. When pointing to previewnet and testnet, account Ids (`OPERATOR_ID_MAIN`) and private keys (`OPERATOR_KEY_MAIN`) for previewnet and tests may be obtained from the [Hedera Portal](http://portal.hedera.com).
Expand Down
6 changes: 6 additions & 0 deletions packages/config-service/src/services/globalConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,12 @@ export class GlobalConfig {
required: false,
defaultValue: null,
},
TEST_TRANSACTION_RECORD_COST_TOLERANCE: {
envName: 'TEST_TRANSACTION_RECORD_COST_TOLERANCE',
type: 'boolean',
required: false,
defaultValue: null,
},
TEST_WS_SERVER: {
envName: 'TEST_WS_SERVER',
type: 'boolean',
Expand Down
18 changes: 11 additions & 7 deletions packages/server/tests/acceptance/hbarLimiter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,11 @@ describe('@hbarlimiter HBAR Limiter Acceptance Tests', function () {

return contract;
};
const transactionReecordCostTolerance = Number(ConfigService.get(`TEST_TRANSACTION_RECORD_COST_TOLERANCE`) || 0.02);

const verifyRemainingLimit = (expectedCost: number, remainingHbarsBefore: number, remainingHbarsAfter: number) => {
const delta = 0.05 * expectedCost;
const delta = transactionReecordCostTolerance * expectedCost;
global.logger.debug(`Tolerance: ${transactionReecordCostTolerance}`);
global.logger.debug(`Expected cost: ${expectedCost} ±${delta}`);
global.logger.debug(`Actual cost: ${remainingHbarsBefore - remainingHbarsAfter}`);
global.logger.debug(`Actual delta: ${(remainingHbarsBefore - remainingHbarsAfter) / (expectedCost * 100)}`);
Expand Down Expand Up @@ -235,7 +237,7 @@ describe('@hbarlimiter HBAR Limiter Acceptance Tests', function () {

// Note: expectedTxCost may be retrieved from mirror node which doesn't include the getRecord transaction fee.
// calculating delta = expectedTxCost * tolerance to account for this difference in transaction costs.
const delta = expectedTxCost * 0.002;
const delta = expectedTxCost * transactionReecordCostTolerance;

while (initialRemainingHbars - updatedRemainingHbars > expectedTxCost + delta) {
logger.warn(
Expand Down Expand Up @@ -320,7 +322,6 @@ describe('@hbarlimiter HBAR Limiter Acceptance Tests', function () {
});

it('HBAR limiter is updated within acceptable tolerance range in relation to actual spent amount by the relay operator', async function () {
const TOLERANCE = 0.02;
const initialRemainingHbars = Number(await metrics.get(testConstants.METRICS.REMAINING_HBAR_LIMIT));
expect(initialRemainingHbars).to.be.gt(0);

Expand All @@ -341,8 +342,12 @@ describe('@hbarlimiter HBAR Limiter Acceptance Tests', function () {
const hbarLimitReducedAmount = initialRemainingHbars - updatedRemainingHbars;

expect(updatedRemainingHbars).to.be.lt(initialRemainingHbars);
Assertions.expectWithinTolerance(amountPaidByOperator, hbarLimitReducedAmount, TOLERANCE);
Assertions.expectWithinTolerance(amountPaidByOperator, totalOperatorFees, TOLERANCE);
Assertions.expectWithinTolerance(
amountPaidByOperator,
hbarLimitReducedAmount,
transactionReecordCostTolerance,
);
Assertions.expectWithinTolerance(amountPaidByOperator, totalOperatorFees, transactionReecordCostTolerance);
});

it('should verify the estimated and actual transaction fees for file transactions are approximately equal', async function () {
Expand Down Expand Up @@ -606,8 +611,7 @@ describe('@hbarlimiter HBAR Limiter Acceptance Tests', function () {

const amountSpent = await pollForProperAmountSpent(hbarSpendingPlan, 1, expectedTxCost);

const tolerance = 0.01;
expect(amountSpent).to.be.approximately(expectedTxCost, tolerance * expectedTxCost);
expect(amountSpent).to.be.approximately(expectedTxCost, transactionReecordCostTolerance * expectedTxCost);
});

it(`Should eventually exhaust the hbar limit for ${subscriptionTier} user and still allow another ${subscriptionTier} user to make calls`, async () => {
Expand Down
1 change: 1 addition & 0 deletions packages/server/tests/localAcceptance.env
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ DEBUG_API_ENABLED=true
SEND_RAW_TRANSACTION_SIZE_LIMIT=131072
BATCH_REQUESTS_ENABLED=true
TEST_GAS_PRICE_DEVIATION=0.2
TEST_TRANSACTION_RECORD_COST_TOLERANCE=0.05
WS_NEW_HEADS_ENABLED=false
INITIAL_BALANCE='5000000000'
LIMIT_DURATION=90000
Expand Down

0 comments on commit 2bf2bf2

Please sign in to comment.