-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: CIP-64 are sent as EIP-1559 transactions (wevm#1499)
* fix: CIP-64 are sent as EIP-1559 transactions (#9) * fix: CIP-64 are sent as EIP-1559 transactions * fix: EIP-1159 -> EIP-1559 typo * chore: add test case for CIP-64 recognition when eip1559 type is provided * chore: introduce a sendTransaction Celo test to verify CIP-64 being sent instead of EIP-1559 * chore: refactor and simplify sendTransaction test * chore: DRY * chore: add a comment for CIP-64 check * chore: add changeset
- Loading branch information
Showing
6 changed files
with
163 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"viem": patch | ||
--- | ||
|
||
Fixes an issue where CIP-64 are sent as EIP-1559 transactions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import { describe, expect, test, vi } from 'vitest' | ||
import { accounts } from '~test/src/constants.js' | ||
import { privateKeyToAccount } from '~viem/accounts/privateKeyToAccount.js' | ||
import { | ||
type EIP1193RequestFn, | ||
type PublicRpcSchema, | ||
type WalletRpcSchema, | ||
createTransport, | ||
createWalletClient, | ||
} from '../../index.js' | ||
import { celo } from '../index.js' | ||
|
||
describe('sendTransaction()', () => { | ||
// We need a local account | ||
const account = privateKeyToAccount(accounts[0].privateKey) | ||
const toAddress = account.address | ||
const transactionHash = '0xtransaction-hash' | ||
const feeCurrencyAddress = '0x0000000000000000000000000000000000000fee' | ||
const transportRequestMock = vi.fn(async (request) => { | ||
if (request.method === 'eth_chainId') { | ||
return celo.id | ||
} | ||
|
||
if (request.method === 'eth_getBlockByNumber') { | ||
// We just need baseFeePerGas for gas estimation | ||
return { | ||
baseFeePerGas: '0x12a05f200', | ||
} | ||
} | ||
|
||
if (request.method === 'eth_maxPriorityFeePerGas') { | ||
return 1n | ||
} | ||
|
||
if (request.method === 'eth_estimateGas') { | ||
return 1n | ||
} | ||
|
||
if (request.method === 'eth_getTransactionCount') { | ||
return 0 | ||
} | ||
|
||
if (request.method === 'eth_sendRawTransaction') { | ||
return transactionHash | ||
} | ||
|
||
return null | ||
}) as EIP1193RequestFn<WalletRpcSchema & PublicRpcSchema> | ||
|
||
const mockTransport = () => | ||
createTransport({ | ||
key: 'mock', | ||
name: 'Mock Transport', | ||
request: transportRequestMock, | ||
type: 'mock', | ||
}) | ||
|
||
const client = createWalletClient({ | ||
transport: mockTransport, | ||
chain: celo, | ||
account, | ||
}) | ||
|
||
test('provides valid transaction params to sign for eth_sendRawTransaction (local account) for CIP-64', async () => { | ||
const hash = await client.sendTransaction({ | ||
value: 1n, | ||
to: toAddress, | ||
feeCurrency: feeCurrencyAddress, | ||
maxFeePerGas: 123n, | ||
maxPriorityFeePerGas: 123n, | ||
}) | ||
|
||
expect(hash).toEqual(transactionHash) | ||
expect(transportRequestMock).toHaveBeenLastCalledWith({ | ||
method: 'eth_sendRawTransaction', | ||
params: [ | ||
'0x7bf87782a4ec807b7b0194f39fd6e51aad88f6f4ce6ab8827279cfffb922660180c0940000000000000000000000000000000000000fee01a038c5dfc128d40b147544b13572dbb0462b9389a8a687d0fe32973e435d7de23aa03c01d6bff1279e94f53a1244302de288bd335bc3a1e61da73fd6215f6d67ccf2', | ||
], | ||
}) | ||
}) | ||
|
||
test('provides valid transaction params to sign for eth_sendRawTransaction (local account) for CIP-42', async () => { | ||
const hash = await client.sendTransaction({ | ||
value: 1n, | ||
to: toAddress, | ||
feeCurrency: feeCurrencyAddress, | ||
gatewayFee: 123n, | ||
gatewayFeeRecipient: '0x0000000000000000000000000000000000000001', | ||
}) | ||
|
||
expect(hash).toEqual(transactionHash) | ||
expect(transportRequestMock).toHaveBeenLastCalledWith({ | ||
method: 'eth_sendRawTransaction', | ||
params: [ | ||
'0x7cf89282a4ec8001850165a0bc0101940000000000000000000000000000000000000fee9400000000000000000000000000000000000000017b94f39fd6e51aad88f6f4ce6ab8827279cfffb922660180c080a004389976320970e0227b20df6f79f2f35a2832d18b9732cb017d15db9f80fb44a0735b9abf965b7f38d1c659527cc93a9fc37b3a3b7bd5910d0c7db4b740be860f', | ||
], | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters