Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: cip64 regressions #6

Merged
merged 4 commits into from Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
87 changes: 83 additions & 4 deletions src/chains/celo/formatters.test.ts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: (not related to changes in this PR)

Based on this recent Slack convo with @mcortesi, transaction receipts do not include feeCurrency, gatewayFee, or gatewayFeeRecipient fields, which means they are undefined in every transaction receipt object (by default). We can thus look into removing them from the expected and actual transaction receipt (in tests), because they will always trivially be equal.

I suggest we fix this in a separate PR to keep this one clean and get the regression fix merged as soon as possible.

describe('transactionReceipt', () => {
  test('formatter', () => {
    const { transactionReceipt } = celo.formatters!
    expect(
      transactionReceipt.format({
        blockHash:
          '0x89644bbd5c8d682a2e9611170e6c1f02573d866d286f006cbf517eec7254ec2d',
        blockNumber: '0x1',
        contractAddress: '0xa152f8bb749c55e9943a3a0a3111d18ee2b3f94e',
        cumulativeGasUsed: '0x2',
        effectiveGasPrice: '0x3',
-       feeCurrency: null,
        from: '0xa152f8bb749c55e9943a3a0a3111d18ee2b3f94e',
        gasUsed: '0x4',
-       gatewayFee: null,
-       gatewayFeeRecipient: null,
        logs: [],
        to: '0x15d4c048f83bd7e37d49ea4c83a07267ec4203da',
        status: '0x0',
        type: '0x0',
      }),
    ).toMatchInlineSnapshot(`
      {
        "blockHash": "0x89644bbd5c8d682a2e9611170e6c1f02573d866d286f006cbf517eec7254ec2d",
        "blockNumber": 1n,
        "contractAddress": "0xa152f8bb749c55e9943a3a0a3111d18ee2b3f94e",
        "cumulativeGasUsed": 2n,
        "effectiveGasPrice": 3n,
-       "feeCurrency": null,
        "from": "0xa152f8bb749c55e9943a3a0a3111d18ee2b3f94e",
        "gasUsed": 4n,
-       "gatewayFee": null,
-       "gatewayFeeRecipient": null,
        "logs": [],
        "status": "reverted",
        "to": "0x15d4c048f83bd7e37d49ea4c83a07267ec4203da",
        "transactionIndex": null,
        "type": "legacy",
      }
    `)

Expand Up @@ -751,9 +751,9 @@ describe('transactionReceipt', () => {
})

describe('transactionRequest', () => {
test('formatter', () => {
const { transactionRequest } = celo.formatters!
const { transactionRequest } = celo.formatters!

test('formatter cip42', () => {
expect(
transactionRequest.format({
feeCurrency: '0x0f16e9b0d03470827a95cdfd0cb8a8a3b46969b9',
Expand Down Expand Up @@ -819,7 +819,6 @@ describe('transactionRequest', () => {
maxFeePerGas: 2n,
maxPriorityFeePerGas: 1n,
nonce: 1,
type: 'cip42',
value: 1n,
}),
).toMatchInlineSnapshot(`
Expand All @@ -838,6 +837,63 @@ describe('transactionRequest', () => {
}
`)

expect(
transactionRequest.format({
feeCurrency: '0x0f16e9b0d03470827a95cdfd0cb8a8a3b46969b9',
from: '0x0f16e9b0d03470827a95cdfd0cb8a8a3b46969b9',
gas: 1n,
gatewayFee: 4n,
gatewayFeeRecipient: '0x0f16e9b0d03470827a95cdfd0cb8a8a3b46969b9',
maxFeePerGas: 2n,
maxPriorityFeePerGas: 1n,
nonce: 1,
value: 1n,
}),
).toMatchInlineSnapshot(`
{
"feeCurrency": "0x0f16e9b0d03470827a95cdfd0cb8a8a3b46969b9",
"from": "0x0f16e9b0d03470827a95cdfd0cb8a8a3b46969b9",
"gas": "0x1",
"gasPrice": undefined,
"gatewayFee": "0x4",
"gatewayFeeRecipient": "0x0f16e9b0d03470827a95cdfd0cb8a8a3b46969b9",
"maxFeePerGas": "0x2",
"maxPriorityFeePerGas": "0x1",
"nonce": "0x1",
"type": "0x7c",
"value": "0x1",
}
`)

expect(
transactionRequest.format({
feeCurrency: '0x0f16e9b0d03470827a95cdfd0cb8a8a3b46969b9',
from: '0x0f16e9b0d03470827a95cdfd0cb8a8a3b46969b9',
gas: 1n,
gatewayFee: 4n,
gatewayFeeRecipient: '0x0f16e9b0d03470827a95cdfd0cb8a8a3b46969b9',
maxFeePerGas: 2n,
maxPriorityFeePerGas: 4n,
nonce: 1,
value: 1n,
}),
).toMatchInlineSnapshot(`
{
"feeCurrency": "0x0f16e9b0d03470827a95cdfd0cb8a8a3b46969b9",
"from": "0x0f16e9b0d03470827a95cdfd0cb8a8a3b46969b9",
"gas": "0x1",
"gasPrice": undefined,
"gatewayFee": "0x4",
"gatewayFeeRecipient": "0x0f16e9b0d03470827a95cdfd0cb8a8a3b46969b9",
"maxFeePerGas": "0x2",
"maxPriorityFeePerGas": "0x4",
"nonce": "0x1",
"type": "0x7c",
"value": "0x1",
}
`)
})
test('formatter cip64', () => {
expect(
nicolasbrugneaux marked this conversation as resolved.
Show resolved Hide resolved
transactionRequest.format({
feeCurrency: '0x0f16e9b0d03470827a95cdfd0cb8a8a3b46969b9',
Expand All @@ -846,7 +902,6 @@ describe('transactionRequest', () => {
maxFeePerGas: 2n,
maxPriorityFeePerGas: 1n,
nonce: 1,
type: 'cip64',
value: 1n,
}),
).toMatchInlineSnapshot(`
Expand All @@ -862,5 +917,29 @@ describe('transactionRequest', () => {
"value": "0x1",
}
`)

expect(
transactionRequest.format({
from: '0x0f16e9b0d03470827a95cdfd0cb8a8a3b46969b9',
to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8', // Recipient (illustrative address)
value: 1n,
feeCurrency: '0x874069Fa1Eb16D44d622F2e0Ca25eeA172369bC1', // cUSD fee currency
maxFeePerGas: 2n, // Special field for dynamic fee transaction type (EIP-1559)
maxPriorityFeePerGas: 2n, // Special field for dynamic fee transaction type (EIP-1559)
}),
).toMatchInlineSnapshot(`
{
"feeCurrency": "0x874069Fa1Eb16D44d622F2e0Ca25eeA172369bC1",
"from": "0x0f16e9b0d03470827a95cdfd0cb8a8a3b46969b9",
"gas": undefined,
"gasPrice": undefined,
"maxFeePerGas": "0x2",
"maxPriorityFeePerGas": "0x2",
"nonce": undefined,
"to": "0x70997970c51812dc3a010c7d01b50e0d17dc79c8",
"type": "0x7b",
"value": "0x1",
}
`)
})
})
21 changes: 3 additions & 18 deletions src/chains/celo/formatters.ts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: (not related to changes in this PR)

Based on this recent Slack convo with @mcortesi, transaction receipts do not include feeCurrency, gatewayFee, or gatewayFeeRecipient fields, which means they are undefined in every transaction receipt object (by default). We can thus look into removing them from here

transactionReceipt: /*#__PURE__*/ defineTransactionReceipt({
    format(
      args: CeloRpcTransactionReceiptOverrides,
    ): CeloTransactionReceiptOverrides {
      return {
-        feeCurrency: args.feeCurrency,
-        gatewayFee: args.gatewayFee ? hexToBigInt(args.gatewayFee) : null,
-        gatewayFeeRecipient: args.gatewayFeeRecipient,
      }
    },
  }),

I suggest we fix this in a separate PR to keep this one clean and get the regression fix merged as soon as possible.

Expand Up @@ -19,22 +19,7 @@ import type {
CeloTransactionReceiptOverrides,
CeloTransactionRequest,
} from './types.js'

function isTransactionRequestCIP64(args: CeloTransactionRequest): boolean {
if (args.type === 'cip64') return true
if (args.type) return false
return (
'feeCurrency' in args &&
args.gatewayFee === undefined &&
args.gatewayFeeRecipient === undefined
)
}

function isTransactionRequestCIP42(args: CeloTransactionRequest): boolean {
if (args.type === 'cip42') return true
if (args.type) return false
return args.gatewayFee !== undefined || args.gatewayFeeRecipient !== undefined
}
import { isCIP42, isCIP64 } from './utils.js'

export const formattersCelo = {
block: /*#__PURE__*/ defineBlock({
Expand Down Expand Up @@ -95,7 +80,7 @@ export const formattersCelo = {

transactionRequest: /*#__PURE__*/ defineTransactionRequest({
format(args: CeloTransactionRequest): CeloRpcTransactionRequest {
if (isTransactionRequestCIP64(args))
if (isCIP64(args))
return {
type: '0x7b',
feeCurrency: args.feeCurrency,
Expand All @@ -110,7 +95,7 @@ export const formattersCelo = {
gatewayFeeRecipient: args.gatewayFeeRecipient,
} as CeloRpcTransactionRequest

if (isTransactionRequestCIP42(args)) request.type = '0x7c'
if (isCIP42(args)) request.type = '0x7c'

return request
},
Expand Down