Skip to content

Commit

Permalink
Merge pull request #1422 from Conflux-Chain/cfx_estimateGasAndCollateral
Browse files Browse the repository at this point in the history
Cfx estimate gas and collateral
  • Loading branch information
iosh committed Sep 27, 2024
2 parents acfde56 + 4038e9b commit 3169e93
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 68 deletions.
6 changes: 6 additions & 0 deletions .yarn/versions/4e981df6.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
releases:
"@fluent-wallet/cfx_estimate-gas-and-collateral": patch

declined:
- helios
- helios-background
117 changes: 49 additions & 68 deletions packages/background/src/index.integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [{}],
Expand All @@ -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', () => {
Expand Down Expand Up @@ -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)
})
})
})
})
25 changes: 25 additions & 0 deletions packages/rpcs/cfx_estimateGasAndCollateral/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
Bytes,
epochRefNoMined,
chainId,
catn,
Hash32,
} from '@fluent-wallet/spec'

export const NAME = 'cfx_estimateGasAndCollateral'
Expand Down Expand Up @@ -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,
],
Expand Down

0 comments on commit 3169e93

Please sign in to comment.