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: #2696 #2790

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
{
"name": "import * from 'viem/chains'",
"path": "./src/_esm/chains/index.js",
"limit": "39 kB",
"limit": "39.04 kB",
"import": "*"
},
{
Expand Down
2 changes: 1 addition & 1 deletion src/accounts/utils/signTransaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ describe('with custom EIP2718 serializer', () => {

test('default', async () => {
const exampleSerializer: SerializeTransactionFn<ExampleTransaction> = vi.fn(
(transaction) => {
async (transaction) => {
const {
chainId,
nonce,
Expand Down
10 changes: 5 additions & 5 deletions src/accounts/utils/signTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ export async function signTransaction<
})()

const signature = await sign({
hash: keccak256(serializer(signableTransaction)),
hash: keccak256(await serializer(signableTransaction)),
privateKey,
})
return serializer(transaction, signature) as SignTransactionReturnType<
serializer,
transaction
>
return (await serializer(
transaction,
signature,
)) as SignTransactionReturnType<serializer, transaction>
}
22 changes: 11 additions & 11 deletions src/actions/wallet/sendTransaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ test('sends transaction (w/ serializer)', async () => {
})

const serializer = vi.fn(
(
async (
txn: TransactionSerializable & {
additionalField?: Hex
},
Expand Down Expand Up @@ -238,7 +238,7 @@ test('client chain mismatch', async () => {

Current Chain ID: 1
Expected Chain ID: 42220 – Celo

Request Arguments:
from: 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
to: 0x70997970c51812dc3a010c7d01b50e0d17dc79c8
Expand Down Expand Up @@ -366,12 +366,12 @@ describe('args: gasPrice', () => {
This error could arise when the account does not have enough funds to:
- pay for the total gas fee,
- pay for the value to send.

The cost of the transaction is calculated as \`gas * gas fee + value\`, where:
- \`gas\` is the amount of gas needed for transaction to execute,
- \`gas fee\` is the gas fee,
- \`value\` is the amount of ether to send to the recipient.

Request Arguments:
from: 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
to: 0x70997970c51812dc3a010c7d01b50e0d17dc79c8
Expand Down Expand Up @@ -440,12 +440,12 @@ describe('args: maxFeePerGas', () => {
This error could arise when the account does not have enough funds to:
- pay for the total gas fee,
- pay for the value to send.

The cost of the transaction is calculated as \`gas * gas fee + value\`, where:
- \`gas\` is the amount of gas needed for transaction to execute,
- \`gas fee\` is the gas fee,
- \`value\` is the amount of ether to send to the recipient.

Request Arguments:
from: 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
to: 0x70997970c51812dc3a010c7d01b50e0d17dc79c8
Expand Down Expand Up @@ -594,7 +594,7 @@ describe('args: chain', async () => {

Current Chain ID: 1
Expected Chain ID: 10 – OP Mainnet

Request Arguments:
chain: OP Mainnet (id: 10)
from: 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
Expand Down Expand Up @@ -811,12 +811,12 @@ describe('local account', () => {
This error could arise when the account does not have enough funds to:
- pay for the total gas fee,
- pay for the value to send.

The cost of the transaction is calculated as \`gas * gas fee + value\`, where:
- \`gas\` is the amount of gas needed for transaction to execute,
- \`gas fee\` is the gas fee,
- \`value\` is the amount of ether to send to the recipient.

Request Arguments:
from: 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
to: 0x70997970c51812dc3a010c7d01b50e0d17dc79c8
Expand Down Expand Up @@ -1323,12 +1323,12 @@ describe('errors', () => {
This error could arise when the account does not have enough funds to:
- pay for the total gas fee,
- pay for the value to send.

The cost of the transaction is calculated as \`gas * gas fee + value\`, where:
- \`gas\` is the amount of gas needed for transaction to execute,
- \`gas fee\` is the gas fee,
- \`value\` is the amount of ether to send to the recipient.

Request Arguments:
from: 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
to: 0x70997970c51812dc3a010c7d01b50e0d17dc79c8
Expand Down
20 changes: 10 additions & 10 deletions src/celo/parsers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ const transaction = {
value: parseEther('1'),
}

test('should return same result as standard parser when not CIP42 or CIP64', () => {
const serialized = serializeTransaction_(transaction)
test('should return same result as standard parser when not CIP42 or CIP64', async () => {
const serialized = await serializeTransaction_(transaction)

expect(parseTransaction(serialized)).toEqual(parseTransaction_(serialized))
})
Expand Down Expand Up @@ -206,15 +206,15 @@ describe('should parse a CIP64 transaction', () => {
type: 'cip64',
} as TransactionSerializableCIP64

test('when type is not specified, but the fields match CIP64', () => {
test('when type is not specified, but the fields match CIP64', async () => {
const transactionWithoutType = {
...transaction,
feeCurrency: '0x765de816845861e75a25fca122bb6898b8b1282a',
type: 'cip64',
chainId: 42270,
} as TransactionSerializableCIP64

const serialized = serializeTransaction(transactionWithoutType)
const serialized = await serializeTransaction(transactionWithoutType)

expect(parseTransaction(serialized)).toMatchInlineSnapshot(`
{
Expand All @@ -231,7 +231,7 @@ describe('should parse a CIP64 transaction', () => {
`)
})

test('with access list', () => {
test('with access list', async () => {
const transactionWithAccessList: TransactionSerializableCIP64 = {
...transactionCip64,
accessList: [
Expand All @@ -245,7 +245,7 @@ describe('should parse a CIP64 transaction', () => {
],
}

const serialized = serializeTransaction(transactionWithAccessList)
const serialized = await serializeTransaction(transactionWithAccessList)

expect(parseTransaction(serialized)).toMatchInlineSnapshot(`
{
Expand All @@ -270,13 +270,13 @@ describe('should parse a CIP64 transaction', () => {
}
`)
})
test('with data as 0x', () => {
test('with data as 0x', async () => {
const transactionWithData: TransactionSerializableCIP64 = {
...transactionCip64,
data: '0x',
}

const serialized = serializeTransaction(transactionWithData)
const serialized = await serializeTransaction(transactionWithData)

expect(parseTransaction(serialized)).toMatchInlineSnapshot(`
{
Expand All @@ -292,13 +292,13 @@ describe('should parse a CIP64 transaction', () => {
}
`)
})
test('with data', () => {
test('with data', async () => {
const transactionWithData: TransactionSerializableCIP64 = {
...transactionCip64,
data: '0x1234',
}

const serialized = serializeTransaction(transactionWithData)
const serialized = await serializeTransaction(transactionWithData)

expect(parseTransaction(serialized)).toMatchInlineSnapshot(`
{
Expand Down
58 changes: 30 additions & 28 deletions src/celo/serializers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ const baseCip64 = {
} as TransactionSerializableCIP64

describe('cip64', () => {
test('should be able to serialize a cip64 transaction', () => {
test('should be able to serialize a cip64 transaction', async () => {
// sanity checks the serialized value, but then rely on the parser
const serialized = serializeTransaction(baseCip64)
const serialized = await serializeTransaction(baseCip64)
const reparsed = parseTransaction(serialized)
const reserialized = serializeTransaction(reparsed)
expect(serialized).toEqual(
Expand All @@ -55,7 +55,7 @@ describe('cip64', () => {
expect(serialized).toEqual(reserialized)
})

test('args: accessList', () => {
test('args: accessList', async () => {
const transaction: TransactionSerializableCIP64 = {
...baseCip64,
accessList: [
Expand All @@ -69,109 +69,109 @@ describe('cip64', () => {
],
}

expect(parseTransaction(serializeTransaction(transaction))).toEqual({
expect(parseTransaction(await serializeTransaction(transaction))).toEqual({
...transaction,
type: 'cip64',
})
})

test('args: data', () => {
test('args: data', async () => {
const transaction: TransactionSerializableCIP64 = {
...baseCip64,
data: '0x1234',
}
expect(parseTransaction(serializeTransaction(transaction))).toEqual({
expect(parseTransaction(await serializeTransaction(transaction))).toEqual({
...transaction,
type: 'cip64',
})
})

test('args: gas', () => {
test('args: gas', async () => {
const transaction: TransactionSerializableCIP64 = {
...baseCip64,
gas: 69420n,
}
expect(parseTransaction(serializeTransaction(transaction))).toEqual({
expect(parseTransaction(await serializeTransaction(transaction))).toEqual({
...transaction,
type: 'cip64',
})
})

test('args: gas (absent)', () => {
test('args: gas (absent)', async () => {
const transaction: TransactionSerializableCIP64 = {
...baseCip64,
gas: undefined,
}
expect(parseTransaction(serializeTransaction(transaction))).toEqual({
expect(parseTransaction(await serializeTransaction(transaction))).toEqual({
...transaction,
type: 'cip64',
})
})

test('args: maxFeePerGas (absent)', () => {
test('args: maxFeePerGas (absent)', async () => {
const transaction: TransactionSerializableCIP64 = {
...baseCip64,
type: 'cip64',
maxFeePerGas: undefined,
}
expect(parseTransaction(serializeTransaction(transaction))).toEqual({
expect(parseTransaction(await serializeTransaction(transaction))).toEqual({
...transaction,
type: 'cip64',
})
})

test('args: maxPriorityFeePerGas (absent)', () => {
test('args: maxPriorityFeePerGas (absent)', async () => {
const transaction: TransactionSerializableCIP64 = {
...baseCip64,
type: 'cip64',
maxPriorityFeePerGas: undefined,
}
expect(parseTransaction(serializeTransaction(transaction))).toEqual({
expect(parseTransaction(await serializeTransaction(transaction))).toEqual({
...transaction,
type: 'cip64',
})
})

test('args: nonce (absent)', () => {
test('args: nonce (absent)', async () => {
const transaction: TransactionSerializableCIP64 = {
...baseCip64,
nonce: undefined,
}
expect(parseTransaction(serializeTransaction(transaction))).toEqual({
expect(parseTransaction(await serializeTransaction(transaction))).toEqual({
...transaction,
type: 'cip64',
})
})

test('args: to (absent)', () => {
test('args: to (absent)', async () => {
const transaction: TransactionSerializableCIP64 = {
...baseCip64,
to: undefined,
}
expect(parseTransaction(serializeTransaction(transaction))).toEqual({
expect(parseTransaction(await serializeTransaction(transaction))).toEqual({
...transaction,
type: 'cip64',
})
})

test('args: value (absent)', () => {
test('args: value (absent)', async () => {
const transaction: TransactionSerializableCIP64 = {
...baseCip64,
value: undefined,
}
expect(parseTransaction(serializeTransaction(transaction))).toEqual({
expect(parseTransaction(await serializeTransaction(transaction))).toEqual({
...transaction,
type: 'cip64',
})
})

test('type is undefined but has cip64 fields (feeCurrency, but not gateway*)', () => {
test('type is undefined but has cip64 fields (feeCurrency, but not gateway*)', async () => {
const transaction: TransactionSerializableCIP64 = {
...baseCip64,
feeCurrency: '0xd8763cba276a3738e6de85b4b3bf5fded6d6ca73',
type: undefined,
}
expect(parseTransaction(serializeTransaction(transaction))).toEqual({
expect(parseTransaction(await serializeTransaction(transaction))).toEqual({
...transaction,
type: 'cip64',
})
Expand Down Expand Up @@ -223,13 +223,15 @@ describe('cip64', () => {
expect(parseTransaction(tx1)).toEqual({ ...baseCip64, type: 'cip64' })
})

test('CIP-42 transaction should be discarded and sent as CIP-64', () => {
test('CIP-42 transaction should be discarded and sent as CIP-64', async () => {
const transaction: TransactionSerializableCIP42 = {
...baseCip42,
type: 'cip42',
}

expect(parseTransaction(serializeTransaction(transaction as any))).toEqual({
expect(
parseTransaction(await serializeTransaction(transaction as any)),
).toEqual({
...transaction,
gatewayFee: undefined,
gatewayFeeRecipient: undefined,
Expand Down Expand Up @@ -331,8 +333,8 @@ describe('not cip42', () => {
value: parseEther('1'),
}

test('it calls the standard serializeTransaction', () => {
const serialized = serializeTransaction(transaction)
test('it calls the standard serializeTransaction', async () => {
const serialized = await serializeTransaction(transaction)
expect(serialized).toEqual(
'0x02ed0180847735940084773594008094f39fd6e51aad88f6f4ce6ab8827279cfffb92266880de0b6b3a764000080c0',
)
Expand All @@ -348,15 +350,15 @@ describe('not cip42', () => {
})

describe('op-stack based transactions', () => {
test('serializes deposit transactions', () => {
test('serializes deposit transactions', async () => {
const opDepositTransaction = {
from: '0x977f82a600a1414e583f7f13623f1ac5d58b1c0b',
sourceHash:
'0x18040f35752170c3339ddcd850f185c9cc46bdef4d6e1f2ab323f4d3d7104319',
type: 'deposit',
} as const satisfies TransactionSerializableDeposit

const serialized = serializeTransaction(opDepositTransaction)
const serialized = await serializeTransaction(opDepositTransaction)
expect(serialized.startsWith('0x7e')).toBe(true)
expect(serialized).toEqual(
'0x7ef83ca018040f35752170c3339ddcd850f185c9cc46bdef4d6e1f2ab323f4d3d710431994977f82a600a1414e583f7f13623f1ac5d58b1c0b808080808080',
Expand Down
Loading