Skip to content
This repository has been archived by the owner on Jul 23, 2024. It is now read-only.

Added newly added klay APIs for upper/lower bound gas price #684

Merged
merged 3 commits into from
Jul 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
171 changes: 171 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions packages/caver-rpc/src/klay.js
Original file line number Diff line number Diff line change
Expand Up @@ -2006,6 +2006,42 @@ class Klay {
call: 'klay_maxPriorityFeePerGas',
params: 0,
}),
/**
* Returns an upper bound gas price.
*
* @memberof Klay
* @method getUpperBoundGasPrice
* @instance
*
* @example
* const result = await caver.rpc.klay.getUpperBoundGasPrice()
*
* @param {function} [callback] Optional callback, returns an error object as the first parameter and the result as the second.
* @return {Promise<string>} An upper bound gas price
*/
new Method({
name: 'getUpperBoundGasPrice',
call: 'klay_upperBoundGasPrice',
params: 0,
}),
/**
* Returns a lower bound gas price.
*
* @memberof Klay
* @method getLowerBoundGasPrice
* @instance
*
* @example
* const result = await caver.rpc.klay.getLowerBoundGasPrice()
*
* @param {function} [callback] Optional callback, returns an error object as the first parameter and the result as the second.
* @return {Promise<string>} A lower bound gas price
*/
new Method({
name: 'getLowerBoundGasPrice',
call: 'klay_lowerBoundGasPrice',
params: 0,
}),
/**
* An object defines an access list result that includes accessList and gasUsed.
*
Expand Down
36 changes: 36 additions & 0 deletions test/packages/caver.rpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,42 @@ describe('caver.rpc.klay', () => {
}).timeout(100000)
})

context('caver.rpc.klay.getUpperBoundGasPrice', () => {
it('CAVERJS-UNIT-RPC-035: should call klay_upperBoundGasPrice', async () => {
sandbox.stub(caver.rpc.klay._requestManager, 'send').callsFake((data, callback) => {
expect(data.method).to.equal('klay_upperBoundGasPrice')
callback(undefined, {})
})

await caver.rpc.klay.getUpperBoundGasPrice()
}).timeout(100000)

it('CAVERJS-UNIT-RPC-036: should return an upper bound gas price', async () => {
const ret = await caver.rpc.klay.getUpperBoundGasPrice()
const gasPrice = await caver.rpc.klay.getGasPrice()
expect(_.isString(ret)).to.be.true
expect(caver.utils.hexToNumber(ret) >= caver.utils.hexToNumber(gasPrice)).to.be.true
}).timeout(100000)
})

context('caver.rpc.klay.getLowerBoundGasPrice', () => {
it('CAVERJS-UNIT-RPC-037: should call klay_lowerBoundGasPrice', async () => {
sandbox.stub(caver.rpc.klay._requestManager, 'send').callsFake((data, callback) => {
expect(data.method).to.equal('klay_lowerBoundGasPrice')
callback(undefined, {})
})

await caver.rpc.klay.getLowerBoundGasPrice()
}).timeout(100000)

it('CAVERJS-UNIT-RPC-038: should return an lower bound gas price', async () => {
const ret = await caver.rpc.klay.getLowerBoundGasPrice()
const gasPrice = await caver.rpc.klay.getGasPrice()
expect(_.isString(ret)).to.be.true
expect(caver.utils.hexToNumber(ret) <= caver.utils.hexToNumber(gasPrice)).to.be.true
}).timeout(100000)
})

context('caver.rpc.klay.createAccessList', () => {
const txArgs = {
from: '0x3bc5885c2941c5cda454bdb4a8c88aa7f248e312',
Expand Down
6 changes: 6 additions & 0 deletions types/packages/caver-rpc/src/klay.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,12 @@ export class Klay {
getMaxPriorityFeePerGas(
callback?: (error: Error, result: string) => void
): Promise<string>
getUpperBoundGasPrice(
callback?: (error: Error, result: string) => void
): Promise<string>
getLowerBoundGasPrice(
callback?: (error: Error, result: string) => void
): Promise<string>
createAccessList(
callObject: CallObject,
blockNumber: BlockNumber,
Expand Down
13 changes: 13 additions & 0 deletions types/test/rpc-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1133,6 +1133,19 @@ rpc.klay.getGasPrice()
// $ExpectType Promise<string>
rpc.klay.getGasPrice((err: Error, ret: string) => {})

// $ExpectType Promise<string>
rpc.klay.getMaxPriorityFeePerGas()
// $ExpectType Promise<string>
rpc.klay.getMaxPriorityFeePerGas((err: Error, ret: string) => {})
// $ExpectType Promise<string>
rpc.klay.getUpperBoundGasPrice()
// $ExpectType Promise<string>
rpc.klay.getUpperBoundGasPrice((err: Error, ret: string) => {})
// $ExpectType Promise<string>
rpc.klay.getLowerBoundGasPrice()
// $ExpectType Promise<string>
rpc.klay.getLowerBoundGasPrice((err: Error, ret: string) => {})

// $ExpectType Promise<string>
rpc.klay.getGasPriceAt(0)
// $ExpectType Promise<string>
Expand Down