|
| 1 | +/*- |
| 2 | + * |
| 3 | + * Hedera JSON RPC Relay |
| 4 | + * |
| 5 | + * Copyright (C) 2024 Hedera Hashgraph, LLC |
| 6 | + * |
| 7 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | + * you may not use this file except in compliance with the License. |
| 9 | + * You may obtain a copy of the License at |
| 10 | + * |
| 11 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | + * |
| 13 | + * Unless required by applicable law or agreed to in writing, software |
| 14 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | + * See the License for the specific language governing permissions and |
| 17 | + * limitations under the License. |
| 18 | + * |
| 19 | + */ |
| 20 | + |
| 21 | +import { expect } from 'chai'; |
| 22 | +import { Utils } from '../../src/utils'; |
| 23 | +import constants from '../../src/lib/constants'; |
| 24 | + |
| 25 | +describe('Utils', () => { |
| 26 | + describe('addPercentageBufferToGasPrice', () => { |
| 27 | + afterEach(() => { |
| 28 | + process.env.GAS_PRICE_PERCENTAGE_BUFFER = '0'; |
| 29 | + }); |
| 30 | + |
| 31 | + const TW_COEF = constants.TINYBAR_TO_WEIBAR_COEF; |
| 32 | + const TEST_CASES = [ |
| 33 | + { testName: 'zero input', buffer: '0', input: 0, output: 0 }, |
| 34 | + { testName: 'buffer 0%', buffer: '0', input: 10 * TW_COEF, output: 10 * TW_COEF }, |
| 35 | + { testName: 'buffer 7%', buffer: '7', input: 140 * TW_COEF, output: 150 * TW_COEF }, |
| 36 | + { testName: 'buffer 10%', buffer: '10', input: 126 * TW_COEF, output: 139 * TW_COEF }, |
| 37 | + { testName: 'buffer 12.25%', buffer: '12.25', input: 56 * TW_COEF, output: 63 * TW_COEF }, |
| 38 | + { testName: 'negative buffer -6%', buffer: '-6', input: 100 * TW_COEF, output: 94 * TW_COEF }, |
| 39 | + { testName: 'negative buffer -12.58%', buffer: '-12.58', input: 136 * TW_COEF, output: 119 * TW_COEF }, |
| 40 | + ]; |
| 41 | + for (let i in TEST_CASES) { |
| 42 | + it(TEST_CASES[i].testName, () => { |
| 43 | + process.env.GAS_PRICE_PERCENTAGE_BUFFER = TEST_CASES[i].buffer; |
| 44 | + expect(Utils.addPercentageBufferToGasPrice(TEST_CASES[i].input)).to.equal(TEST_CASES[i].output); |
| 45 | + }); |
| 46 | + } |
| 47 | + }); |
| 48 | +}); |
0 commit comments