From da74853fdf1a8f6948b0cb817e57b5fba5355957 Mon Sep 17 00:00:00 2001 From: iosh Date: Fri, 27 Sep 2024 14:33:28 +0800 Subject: [PATCH 1/3] chore: add more fields to cfx_estimateGasAndCollateral --- .../background/src/index.integration.test.js | 117 ++++++++---------- .../cfx_estimateGasAndCollateral/index.js | 25 ++++ 2 files changed, 74 insertions(+), 68 deletions(-) diff --git a/packages/background/src/index.integration.test.js b/packages/background/src/index.integration.test.js index d202ba1c7..db893effb 100644 --- a/packages/background/src/index.integration.test.js +++ b/packages/background/src/index.integration.test.js @@ -279,8 +279,40 @@ describe('integration test', () => { ).toBe('1337') }) }) + + describe('cfx_call', async () => { + test('cfx_call', async () => { + const {token1} = await deployCRC20() + await request({ + method: 'wallet_importMnemonic', + params: {mnemonic: MNEMONIC, password}, + }) + expect( + ( + await request({ + method: 'cfx_call', + params: [ + { + to: token1.contractAddress, + data: '0x06fdde03', + maxPriorityFeePerGas: '0x4a817c800', + maxFeePerGas: '0x4a817c800', + type: '0x2', + }, + ], + }) + ).result.startsWith('0x'), + ).toBe(true) + }) + }) + describe('cfx_estimateGasAndCollateral', () => { test('cfx_estimateGasAndCollateral', async () => { + const {token1} = await deployCRC20() + await request({ + method: 'wallet_importMnemonic', + params: {mnemonic: MNEMONIC, password}, + }) res = await request({ method: 'cfx_estimateGasAndCollateral', params: [{}], @@ -289,6 +321,23 @@ describe('integration test', () => { expect(res.result.gasLimit).toBeDefined() expect(res.result.gasUsed).toBeDefined() expect(res.result.storageCollateralized).toBeDefined() + + const estimateRes = await request({ + method: 'cfx_estimateGasAndCollateral', + params: [ + { + type: '0x2', + to: token1.contractAddress, + data: '0x06fdde03', + maxPriorityFeePerGas: '0x4a817c800', + maxFeePerGas: '0x4a817c800', + }, + ], + }) + expect(estimateRes?.result).toBeDefined() + expect(estimateRes.result.gasLimit).toBeDefined() + expect(estimateRes.result.gasUsed).toBeDefined() + expect(estimateRes.result.storageCollateralized).toBeDefined() }) }) describe('eth_estimateGas', () => { @@ -2891,73 +2940,5 @@ describe('integration test', () => { expect(res.result.startsWith('0x')).toBe(true) }) }) - - describe('cfx_call', async () => { - test('cfx_call', async () => { - const {token1} = await deployCRC20() - await request({ - method: 'wallet_importMnemonic', - params: {mnemonic: MNEMONIC, password}, - }) - expect( - ( - await request({ - method: 'cfx_call', - params: [ - { - to: token1.contractAddress, - data: '0x06fdde03', - }, - ], - }) - ).result.startsWith('0x'), - ).toBe(true) - expect( - ( - await request({ - method: 'cfx_call', - params: [ - { - to: token1.contractAddress, - data: '0x06fdde03', - maxPriorityFeePerGas: '0x4a817c800', - }, - ], - }) - ).result.startsWith('0x'), - ).toBe(true) - expect( - ( - await request({ - method: 'cfx_call', - params: [ - { - to: token1.contractAddress, - data: '0x06fdde03', - maxPriorityFeePerGas: '0x4a817c800', - maxFeePerGas: '0x4a817c800', - }, - ], - }) - ).result.startsWith('0x'), - ).toBe(true) - expect( - ( - await request({ - method: 'cfx_call', - params: [ - { - to: token1.contractAddress, - data: '0x06fdde03', - maxPriorityFeePerGas: '0x4a817c800', - maxFeePerGas: '0x4a817c800', - type: '0x2', - }, - ], - }) - ).result.startsWith('0x'), - ).toBe(true) - }) - }) }) }) diff --git a/packages/rpcs/cfx_estimateGasAndCollateral/index.js b/packages/rpcs/cfx_estimateGasAndCollateral/index.js index e932039a5..5109fd4b0 100644 --- a/packages/rpcs/cfx_estimateGasAndCollateral/index.js +++ b/packages/rpcs/cfx_estimateGasAndCollateral/index.js @@ -7,6 +7,8 @@ import { Bytes, epochRefNoMined, chainId, + catn, + Hash32, } from '@fluent-wallet/spec' export const NAME = 'cfx_estimateGasAndCollateral' @@ -35,6 +37,29 @@ export const schemas = { ['nonce', {optional: true, doc: 'default to 0x0'}, Uint], ['storageLimit', {optional: true}, Uint], ['epochHeight', {optional: true}, Uint], + ['type', {optional: true}, Uint], + ['maxPriorityFeePerGas', {optional: true}, Uint], + ['maxFeePerGas', {optional: true}, Uint], + [ + 'accessList', + {optional: true}, + [ + catn, + [ + 'AccessListEntry', + [ + map, + {closed: true}, + ['address', {optional: true}, base32Address], + [ + 'storageKeys', + {optional: true}, + [catn, ['32BtyeHexValue', Hash32]], + ], + ], + ], + ], + ], ], epochRefNoMined, ], From 73db2af0002f0dc201c6e263f4d362a3f89cd085 Mon Sep 17 00:00:00 2001 From: iosh Date: Fri, 27 Sep 2024 14:34:29 +0800 Subject: [PATCH 2/3] chore: update version --- .yarn/versions/4e981df6.yml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .yarn/versions/4e981df6.yml diff --git a/.yarn/versions/4e981df6.yml b/.yarn/versions/4e981df6.yml new file mode 100644 index 000000000..6bb96d64c --- /dev/null +++ b/.yarn/versions/4e981df6.yml @@ -0,0 +1,5 @@ +releases: + "@fluent-wallet/cfx_estimate-gas-and-collateral": patch + +declined: + - helios-background From 4038e9bb6809807088d22fa934d7772e269542de Mon Sep 17 00:00:00 2001 From: iosh Date: Fri, 27 Sep 2024 14:38:33 +0800 Subject: [PATCH 3/3] chore: update version --- .yarn/versions/4e981df6.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.yarn/versions/4e981df6.yml b/.yarn/versions/4e981df6.yml index 6bb96d64c..20d56e825 100644 --- a/.yarn/versions/4e981df6.yml +++ b/.yarn/versions/4e981df6.yml @@ -2,4 +2,5 @@ releases: "@fluent-wallet/cfx_estimate-gas-and-collateral": patch declined: + - helios - helios-background